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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* This file is part of the KDE project
Copyright (C) 2000 David Faure <[email protected]>
Copyright (C) 2003 Waldo Bastian <[email protected]>
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 "dirtree_item.h"
#include "dirtree_module.h"
#include <konq_operations.h>
#include <konq_drag.h>
#include <kdebug.h>
#include <kglobalsettings.h>
#include <kuserprofile.h>
#include <tqapplication.h>
#include <tqclipboard.h>
#include <kio/paste.h>
#include <tqfile.h>
#include <tqpainter.h>
#include <kiconloader.h>
#include <tqcursor.h>
#define MYMODULE static_cast<KonqSidebarDirTreeModule*>(module())
KonqSidebarDirTreeItem::KonqSidebarDirTreeItem( KonqSidebarTreeItem *parentItem, KonqSidebarTreeTopLevelItem *topLevelItem, KFileItem *fileItem )
: KonqSidebarTreeItem( parentItem, topLevelItem ), m_fileItem( fileItem )
{
if ( m_topLevelItem )
MYMODULE->addSubDir( this );
reset();
}
KonqSidebarDirTreeItem::KonqSidebarDirTreeItem( KonqSidebarTree *parent, KonqSidebarTreeTopLevelItem *topLevelItem, KFileItem *fileItem )
: KonqSidebarTreeItem( parent, topLevelItem ), m_fileItem( fileItem )
{
if ( m_topLevelItem )
MYMODULE->addSubDir( this );
reset();
}
KonqSidebarDirTreeItem::~KonqSidebarDirTreeItem()
{
}
void KonqSidebarDirTreeItem::reset()
{
bool expandable = true;
// For local dirs, find out if they have no children, to remove the "+"
if ( m_fileItem->isDir() )
{
KURL url = m_fileItem->url();
if ( url.isLocalFile() )
{
TQCString path( TQFile::encodeName(url.path()));
struct stat buff;
if ( ::stat( path.data(), &buff ) != -1 )
{
//kdDebug() << "KonqSidebarDirTreeItem::init " << path << " : " << buff.st_nlink << endl;
// The link count for a directory is generally subdir_count + 2.
// One exception is if there are hard links to the directory, in this case
// the link count can be > 2 even if no subdirs exist.
// The other exception are smb (and maybe netware) mounted directories
// of which the link count is always 1. Therefore, we only set the item
// as non-expandable if it's exactly 2 (one link from the parent dir,
// plus one from the '.' entry).
if ( buff.st_nlink == 2 )
expandable = false;
}
}
}
setExpandable( expandable );
id = m_fileItem->url().url(-1);
}
void KonqSidebarDirTreeItem::setOpen( bool open )
{
kdDebug(1201) << "KonqSidebarDirTreeItem::setOpen " << open << endl;
if ( open && !childCount() && m_bListable )
MYMODULE->openSubFolder( this );
else if ( hasStandardIcon() )
{
int size = KGlobal::iconLoader()->currentSize( KIcon::Small );
if ( open )
setPixmap( 0, DesktopIcon( "folder_open", size ) );
else
setPixmap( 0, m_fileItem->pixmap( size ) );
}
KonqSidebarTreeItem::setOpen( open );
}
bool KonqSidebarDirTreeItem::hasStandardIcon()
{
// The reason why we can't use KFileItem::iconName() is that it doesn't
// take custom icons in .directory files into account
return m_fileItem->iconName() == "folder";
}
void KonqSidebarDirTreeItem::paintCell( TQPainter *_painter, const TQColorGroup & _cg, int _column, int _width, int _tqalignment )
{
if (m_fileItem->isLink())
{
TQFont f( _painter->font() );
f.setItalic( TRUE );
_painter->setFont( f );
}
TQListViewItem::paintCell( _painter, _cg, _column, _width, _tqalignment );
}
KURL KonqSidebarDirTreeItem::externalURL() const
{
return m_fileItem->url();
}
TQString KonqSidebarDirTreeItem::externalMimeType() const
{
if (m_fileItem->isMimeTypeKnown())
return m_fileItem->mimetype();
else
return TQString::null;
}
bool KonqSidebarDirTreeItem::acceptsDrops( const TQStrList & formats )
{
if ( formats.contains("text/uri-list") )
return m_fileItem->acceptsDrops();
return false;
}
void KonqSidebarDirTreeItem::drop( TQDropEvent * ev )
{
KonqOperations::doDrop( m_fileItem, externalURL(), ev, tree() );
}
TQDragObject * KonqSidebarDirTreeItem::dragObject( TQWidget * parent, bool move )
{
KURL::List lst;
lst.append( m_fileItem->url() );
KonqDrag * drag = KonqDrag::newDrag( lst, false, parent );
drag->setMoveSelection( move );
return drag;
}
void KonqSidebarDirTreeItem::itemSelected()
{
bool bInTrash = false;
if ( m_fileItem->url().directory(false) == KGlobalSettings::trashPath() )
bInTrash = true;
TQMimeSource *data = TQApplication::tqclipboard()->data();
bool paste = ( data->tqencodedData( data->format() ).size() != 0 );
tree()->enableActions( true, true, paste, true && !bInTrash, true, true );
}
void KonqSidebarDirTreeItem::middleButtonClicked()
{
// Duplicated from KonqDirPart :(
// Optimisation to avoid KRun to call kfmclient that then tells us
// to open a window :-)
KService::Ptr offer = KServiceTypeProfile::preferredService(m_fileItem->mimetype(), "Application");
if (offer) kdDebug(1201) << "KonqDirPart::mmbClicked: got service " << offer->desktopEntryName() << endl;
if ( offer && offer->desktopEntryName().startsWith("kfmclient") )
{
kdDebug(1201)<<"Emitting createNewWindow"<<endl;
KParts::URLArgs args;
args.serviceType = m_fileItem->mimetype();
emit tree()->createNewWindow( m_fileItem->url(), args );
}
else
m_fileItem->run();
}
void KonqSidebarDirTreeItem::rightButtonPressed()
{
KFileItemList lstItems;
lstItems.append( m_fileItem );
emit tree()->popupMenu( TQCursor::pos(), lstItems );
}
void KonqSidebarDirTreeItem::paste()
{
// move or not move ?
bool move = false;
TQMimeSource *data = TQApplication::tqclipboard()->data();
if ( data->provides( "application/x-kde-cutselection" ) ) {
move = KonqDrag::decodeIsCutSelection( data );
kdDebug(1201) << "move (from clipboard data) = " << move << endl;
}
KIO::pasteClipboard( m_fileItem->url(), move );
}
void KonqSidebarDirTreeItem::trash()
{
delOperation( KonqOperations::TRASH );
}
void KonqSidebarDirTreeItem::del()
{
delOperation( KonqOperations::DEL );
}
void KonqSidebarDirTreeItem::shred()
{
delOperation( KonqOperations::SHRED );
}
void KonqSidebarDirTreeItem::delOperation( int method )
{
KURL::List lst;
lst.append(m_fileItem->url());
KonqOperations::del(tree(), method, lst);
}
TQString KonqSidebarDirTreeItem::toolTipText() const
{
return m_fileItem->url().pathOrURL();
}
void KonqSidebarDirTreeItem::rename()
{
tree()->rename( this, 0 );
}
void KonqSidebarDirTreeItem::rename( const TQString & name )
{
KonqOperations::rename( tree(), m_fileItem->url(), name );
}
|