23 #include <tdefileitem.h>
27 #include <sys/types.h>
31 #include "tdefiletreeviewitem.h"
32 #include "tdefiletreebranch.h"
38 const TQPixmap& pix,
bool showHidden,
41 : KDirLister( false ),
46 m_openRootIcon( pix ),
47 m_recurseChildren(true),
48 m_showExtensions(true)
50 kdDebug( 250) <<
"Creating branch for url " << url.prettyURL() << endl;
56 new KFileItem( url,
"inode/directory",
61 m_root->setExpandable(
true );
62 m_root->setPixmap( 0, pix );
63 m_root->setText( 0,
name );
65 setShowingDotFiles( showHidden );
67 connect(
this, TQ_SIGNAL( refreshItems(
const KFileItemList&)),
68 this, TQ_SLOT ( slotRefreshItems(
const KFileItemList& )));
70 connect(
this, TQ_SIGNAL( newItems(
const KFileItemList&)),
71 this, TQ_SLOT ( addItems(
const KFileItemList& )));
73 connect(
this, TQ_SIGNAL( completed(
const KURL& )),
74 this, TQ_SLOT(slCompleted(
const KURL&)));
76 connect(
this, TQ_SIGNAL( started(
const KURL& )),
77 this, TQ_SLOT( slotListerStarted(
const KURL& )));
79 connect(
this, TQ_SIGNAL( deleteItem( KFileItem* )),
80 this, TQ_SLOT( slotDeleteItem( KFileItem* )));
82 connect(
this, TQ_SIGNAL( canceled(
const KURL&) ),
83 this, TQ_SLOT( slotCanceled(
const KURL&) ));
85 connect(
this, TQ_SIGNAL( clear()),
86 this, TQ_SLOT( slotDirlisterClear()));
88 connect(
this, TQ_SIGNAL( clear(
const KURL&)),
89 this, TQ_SLOT( slotDirlisterClearURL(
const KURL&)));
91 connect(
this, TQ_SIGNAL( redirection(
const KURL& ,
const KURL& ) ),
92 this, TQ_SLOT( slotRedirect(
const KURL&,
const KURL& )));
94 m_openChildrenURLs.append( url );
97 void KFileTreeBranch::setOpenPixmap(
const TQPixmap& pix )
101 if(
root()->isOpen())
103 root()->setPixmap( 0, pix );
107 void KFileTreeBranch::slotListerStarted(
const KURL &url )
110 kdDebug( 250) <<
"Starting to list " << url.prettyURL() << endl;
118 if( ! item )
return 0;
123 KURL url = item->
url();
126 dirUrl.setFileName( TQString::null );
135 void KFileTreeBranch::slotRefreshItems(
const KFileItemList& list )
137 KFileItemListIterator it( list );
138 kdDebug(250) <<
"Refreshing " << list.count() <<
" items !" << endl;
142 while ( (currItem = it.current()) != 0 )
146 item->setPixmap(0, item->
fileItem()->pixmap( TDEIcon::SizeSmall ));
147 item->setText( 0, item->
fileItem()->text());
153 void KFileTreeBranch::addItems(
const KFileItemList& list )
155 KFileItemListIterator it( list );
156 kdDebug(250) <<
"Adding " << list.count() <<
" items !" << endl;
158 KFileTreeViewItemList treeViewItList;
161 while ( (currItem = it.current()) != 0 )
163 parentItem = parentKFTVItem( currItem );
179 currItem->setExtraData(
this, newKFTVI );
182 if( !m_showExtensions && !currItem->isDir() )
184 TQString
name = currItem->text();
185 int mPoint =
name.findRev(
'.' );
188 newKFTVI->setText( 0,
name );
195 if( dirOnlyMode() && !m_recurseChildren && currItem->isLocalFile( ) && currItem->isDir() )
197 KURL url = currItem->
url();
198 TQString filename = url.directory(
false,
true ) + url.fileName();
202 kdDebug(250) <<
"Doing stat on " << filename << endl;
203 KDE_struct_stat statBuf;
204 if( KDE_stat( TQFile::encodeName( filename ), &statBuf ) == 0 )
206 int hardLinks = statBuf.st_nlink;
207 kdDebug(250) <<
"stat succeeded, hardlinks: " << hardLinks << endl;
214 newKFTVI->setExpandable(
true);
218 newKFTVI->setExpandable(
false);
222 kdDebug(250) <<
"Emitting for " << url.prettyURL() << endl;
228 kdDebug(250) <<
"stat of " << filename <<
" failed !" << endl;
233 treeViewItList.append( newKFTVI );
240 KFileItem *fileItem )
243 if( parent && fileItem )
251 kdDebug(250) <<
"createTreeViewItem: Have no parent" << endl;
258 m_recurseChildren = t;
260 m_openChildrenURLs.clear();
266 m_showExtensions = visible;
271 return( m_showExtensions );
279 void KFileTreeBranch::slotDeleteItem( KFileItem *it )
282 kdDebug(250) <<
"Slot Delete Item hitted for " << it->url().prettyURL() << endl;
288 kdDebug( 250 ) <<
"Child count: " << kfti->childCount() << endl;
289 if( kfti->childCount() > 0 )
295 kdDebug(250) <<
"Calling child to be deleted !" << endl;
302 kdDebug(250) <<
"Found corresponding KFileTreeViewItem" << endl;
303 if( m_lastFoundURL.equals(it->url(),
true ))
305 m_lastFoundURL = KURL();
306 m_lastFoundItem = 0L;
312 kdDebug(250) <<
"Error: tdefiletreeviewitem: "<< kfti << endl;
317 void KFileTreeBranch::slotCanceled(
const KURL& url )
321 m_openChildrenURLs.remove( url);
329 void KFileTreeBranch::slotDirlisterClear()
331 kdDebug(250)<<
"*** Clear all !" << endl;
334 deleteChildrenOf( m_root );
337 void KFileTreeBranch::slotDirlisterClearURL(
const KURL& url )
339 kdDebug(250)<<
"*** Clear for URL !" << url.prettyURL() << endl;
340 KFileItem *item = findByURL( url );
345 deleteChildrenOf( ftvi );
349 void KFileTreeBranch::deleteChildrenOf( TQListViewItem *parent )
356 while ( parent->firstChild() )
357 delete parent->firstChild();
360 void KFileTreeBranch::slotRedirect(
const KURL& oldUrl,
const KURL&newUrl )
362 if( oldUrl.equals( m_startURL,
true ))
372 if( m_startURL.equals(url,
true) )
374 kdDebug(250) <<
"findByURL: Returning root as a parent !" << endl;
377 else if( m_lastFoundURL.equals( url,
true ))
379 kdDebug(250) <<
"findByURL: Returning from lastFoundURL!" << endl;
380 resultItem = m_lastFoundItem;
384 kdDebug(250) <<
"findByURL: searching by dirlister: " << url.
url() << endl;
386 KFileItem *it = findByURL( url );
391 m_lastFoundItem = resultItem;
392 m_lastFoundURL = url;
396 return( resultItem );
400 void KFileTreeBranch::slCompleted(
const KURL& url )
402 kdDebug(250) <<
"SlotCompleted hit for " << url.prettyURL() << endl;
404 if( ! currParent )
return;
406 kdDebug(250) <<
"current parent " << currParent <<
" is already listed: "
422 kdDebug(250) <<
"recurseChildren: " << m_recurseChildren << endl;
423 kdDebug(250) <<
"isLocalFile: " << m_startURL.isLocalFile() << endl;
424 kdDebug(250) <<
"dirOnlyMode: " << dirOnlyMode() << endl;
427 if( m_recurseChildren && (!m_startURL.isLocalFile() || ! dirOnlyMode()) )
429 bool wantRecurseUrl =
false;
431 for ( KURL::List::Iterator it = m_openChildrenURLs.begin();
432 it != m_openChildrenURLs.end(); ++it )
435 if( (*it).equals( url,
true ) )
436 wantRecurseUrl =
true;
440 kdDebug(250) <<
"Recursing " << url.prettyURL() <<
"? " << wantRecurseUrl << endl;
442 if( wantRecurseUrl && currParent )
449 (
static_cast<TQListViewItem*
>(currParent)->firstChild());
454 kdDebug( 250 ) <<
"No children to recuse" << endl;
460 m_openChildrenURLs.remove(url);
475 KFileItem *kfi = nextChild->
fileItem();
476 if( kfi && kfi->isReadable())
478 KURL recurseUrl = kfi->url();
479 kdDebug(250) <<
"Starting to recurse NOW " << recurseUrl.prettyURL() << endl;
480 openURL( recurseUrl,
true );
483 nextChild =
static_cast<KFileTreeViewItem*
>(
static_cast<TQListViewItem*
>(nextChild->nextSibling()));
490 kdDebug(250) <<
"skipping to recurse in complete-slot" << endl;
501 kdDebug(250) <<
"Populating <" << url.prettyURL() <<
">" << endl;
504 if( m_recurseChildren )
506 m_openChildrenURLs.append( url );
507 kdDebug(250) <<
"Appending to list " << url.prettyURL() << endl;
513 ret = openURL( url,
true );
517 kdDebug(250) <<
"Children already existing in treeview!" << endl;
524 void KFileTreeBranch::virtual_hook(
int id,
void* data )
525 { KDirLister::virtual_hook(
id, data ); }
527 #include "tdefiletreebranch.moc"
virtual void setShowExtensions(bool visible=true)
sets printing of the file extensions on or off.
void newTreeViewItems(KFileTreeBranch *, const KFileTreeViewItemList &)
emitted with a list of new or updated KFileTreeViewItem which were found in a branch.
bool showExtensions() const
KFileTreeBranch(KFileTreeView *, const KURL &url, const TQString &name, const TQPixmap &pix, bool showHidden=false, KFileTreeViewItem *branchRoot=0)
constructs a branch for KFileTreeView.
KFileTreeViewItem * root()
virtual KFileTreeViewItem * findTVIByURL(const KURL &)
find the according KFileTreeViewItem by an url
virtual bool populate(const KURL &url, KFileTreeViewItem *currItem)
populates a branch.
void populateFinished(KFileTreeViewItem *)
emitted with the item of a directory which was finished to populate
virtual KFileTreeViewItem * createTreeViewItem(KFileTreeViewItem *parent, KFileItem *fileItem)
allocates a KFileTreeViewItem for the branch for new items.
void directoryChildCount(KFileTreeViewItem *item, int count)
emitted with the exact count of children for a directory.
void setChildRecurse(bool t=true)
sets if children recursion is wanted or not.
An item for a KFileTreeView that knows about its own KFileItem.
void setListed(bool wasListed)
set the flag if the directory was already listed.
KFileItem * fileItem() const
bool alreadyListed() const
The filetreeview offers a treeview on the file system which behaves like a QTreeView showing files an...