1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/* This file is part of the KDE project
Copyright (C) 2000 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
//#include "konq_treepart.h"
#include "konq_sidebartreemodule.h"
#include <kdebug.h>
#include <kdirnotify_stub.h>
#include <tdeio/paste.h>
#include <konq_operations.h>
#include <kprotocolinfo.h>
#include <kurldrag.h>
#include <kmimetype.h>
#include <tqapplication.h>
#include <tqclipboard.h>
#include <tqcursor.h>
#include <konq_drag.h>
void KonqSidebarTreeTopLevelItem::init()
{
TQString desktopFile = m_path;
if ( isTopLevelGroup() )
desktopFile += "/.directory";
KSimpleConfig cfg( desktopFile, true );
cfg.setDesktopGroup();
m_comment = cfg.readEntry( "Comment" );
}
void KonqSidebarTreeTopLevelItem::setOpen( bool open )
{
if (open && module())
module()->openTopLevelItem( this );
KonqSidebarTreeItem::setOpen( open );
}
void KonqSidebarTreeTopLevelItem::itemSelected()
{
kdDebug() << "KonqSidebarTreeTopLevelItem::itemSelected" << endl;
TQMimeSource *data = TQApplication::clipboard()->data();
bool paste = m_bTopLevelGroup && data->provides("text/uri-list");
tree()->enableActions( true, true, paste, true, true, true /*rename*/ );
}
bool KonqSidebarTreeTopLevelItem::acceptsDrops( const TQStrList & formats )
{
return formats.contains("text/uri-list") &&
( m_bTopLevelGroup || !externalURL().isEmpty() );
}
void KonqSidebarTreeTopLevelItem::drop( TQDropEvent * ev )
{
if ( m_bTopLevelGroup )
{
// When dropping something to "Network" or its subdirs, we want to create
// a desktop link, not to move/copy/link - except for .desktop files :-}
KURL::List lst;
if ( KURLDrag::decode( ev, lst ) && !lst.isEmpty() ) // Are they urls ?
{
KURL::List::Iterator it = lst.begin();
for ( ; it != lst.end() ; it++ )
{
tree()->addURL(this, *it);
}
} else
kdError(1202) << "No URL !? " << endl;
}
else // Top level item, not group
{
if ( !externalURL().isEmpty() )
KonqOperations::doDrop( 0L, externalURL(), ev, tree() );
}
}
TQDragObject * KonqSidebarTreeTopLevelItem::dragObject( TQWidget * parent, bool move )
{
// 100% duplicated from KonqDirTreeItem::dragObject :(
KURL::List lst;
KURL url;
url.setPath( path() );
lst.append( url );
KonqDrag * drag = KonqDrag::newDrag( lst, false, parent );
const TQPixmap * pix = pixmap(0);
if (pix)
{
TQPoint hotspot( pix->width() / 2, pix->height() / 2 );
drag->setPixmap( *pix, hotspot );
}
drag->setMoveSelection( move );
return drag;
}
void KonqSidebarTreeTopLevelItem::middleButtonClicked()
{
if ( !m_bTopLevelGroup )
emit tree()->createNewWindow( m_externalURL );
// Do nothing for toplevel groups
}
void KonqSidebarTreeTopLevelItem::rightButtonPressed()
{
KURL url;
url.setPath( m_path );
// We don't show "edit file type" (useless here) and "properties" (shows the wrong name,
// i.e. the filename instead of the Name field). There's the Rename item for that.
// Only missing thing is changing the URL of a link. Hmm...
if ( !module() || !module()->handleTopLevelContextMenu( this, TQCursor::pos() ) )
{
tree()->showToplevelContextMenu();
}
}
void KonqSidebarTreeTopLevelItem::trash()
{
delOperation( KonqOperations::TRASH );
}
void KonqSidebarTreeTopLevelItem::del()
{
delOperation( KonqOperations::DEL );
}
void KonqSidebarTreeTopLevelItem::shred()
{
delOperation( KonqOperations::SHRED );
}
void KonqSidebarTreeTopLevelItem::delOperation( int method )
{
KURL url;
url.setPath( m_path );
KURL::List lst;
lst.append(url);
KonqOperations::del(tree(), method, lst);
}
void KonqSidebarTreeTopLevelItem::paste()
{
// move or not move ?
bool move = false;
TQMimeSource *data = TQApplication::clipboard()->data();
if ( data->provides( "application/x-kde-cutselection" ) ) {
move = KonqDrag::decodeIsCutSelection( data );
kdDebug(1201) << "move (from clipboard data) = " << move << endl;
}
KURL destURL;
if ( m_bTopLevelGroup )
destURL.setPath( m_path );
else
destURL = m_externalURL;
TDEIO::pasteClipboard( destURL, move );
}
void KonqSidebarTreeTopLevelItem::rename()
{
tree()->rename( this, 0 );
}
void KonqSidebarTreeTopLevelItem::rename( const TQString & name )
{
KURL url;
url.setPath( m_path );
// Well, it's not really the file we want to rename, it's the Name field
// of the .directory or desktop file
//KonqOperations::rename( tree(), url, name );
TQString desktopFile = m_path;
if ( isTopLevelGroup() )
desktopFile += "/.directory";
KSimpleConfig cfg( desktopFile );
cfg.setDesktopGroup();
cfg.writeEntry( "Name", name );
cfg.sync();
// Notify about the change
KURL::List lst;
lst.append(url);
KDirNotify_stub allDirNotify("*", "KDirNotify*");
allDirNotify.FilesChanged( lst );
}
TQString KonqSidebarTreeTopLevelItem::toolTipText() const
{
return m_comment;
}
|