20 #include <tqapplication.h>
24 #include <kdirnotify_stub.h>
25 #include <tdeglobalsettings.h>
26 #include <tdefileitem.h>
27 #include <tdefileview.h>
28 #include <kmimetype.h>
29 #include <kstandarddirs.h>
32 #include <tdeio/job.h>
33 #include <tdeio/global.h>
35 #include <kiconloader.h>
38 #include "tdefiletreeview.h"
39 #include "tdefiletreebranch.h"
40 #include "tdefiletreeviewitem.h"
42 KFileTreeView::KFileTreeView( TQWidget *parent,
const char *name )
43 : TDEListView( parent, name ),
44 m_wantOpenFolderPixmaps( true ),
48 setSelectionModeExt( TDEListView::Single );
50 m_animationTimer =
new TQTimer(
this );
51 connect( m_animationTimer, TQ_SIGNAL( timeout() ),
52 this, TQ_SLOT( slotAnimation() ) );
54 m_currentBeforeDropItem = 0;
57 m_autoOpenTimer =
new TQTimer(
this );
58 connect( m_autoOpenTimer, TQ_SIGNAL( timeout() ),
59 this, TQ_SLOT( slotAutoOpenFolder() ) );
62 connect(
this, TQ_SIGNAL( executed( TQListViewItem * ) ),
63 this, TQ_SLOT( slotExecuted( TQListViewItem * ) ) );
64 connect(
this, TQ_SIGNAL( expanded ( TQListViewItem *) ),
65 this, TQ_SLOT( slotExpanded( TQListViewItem *) ));
66 connect(
this, TQ_SIGNAL( collapsed( TQListViewItem *) ),
67 this, TQ_SLOT( slotCollapsed( TQListViewItem* )));
71 connect(
this, TQ_SIGNAL( selectionChanged() ),
72 this, TQ_SLOT( slotSelectionChanged() ) );
73 connect(
this, TQ_SIGNAL( onItem( TQListViewItem * )),
74 this, TQ_SLOT( slotOnItem( TQListViewItem * ) ) );
75 connect(
this, TQ_SIGNAL(itemRenamed(TQListViewItem*,
const TQString &,
int)),
76 this, TQ_SLOT(slotItemRenamed(TQListViewItem*,
const TQString &,
int)));
80 m_branches.setAutoDelete(
true );
82 m_openFolderPixmap = DesktopIcon(
"folder_open",TDEIcon::SizeSmall,TDEIcon::ActiveState );
85 KFileTreeView::~KFileTreeView()
96 bool KFileTreeView::isValidItem( TQListViewItem *item)
100 TQPtrList<TQListViewItem> lst;
101 TQListViewItemIterator it(
this );
102 while ( it.current() )
104 if ( it.current() == item )
111 void KFileTreeView::contentsDragEnterEvent( TQDragEnterEvent *ev )
119 m_currentBeforeDropItem = selectedItem();
121 TQListViewItem *item = itemAt( contentsToViewport( ev->pos() ) );
125 m_autoOpenTimer->start( KFileView::autoOpenDelay() );
133 void KFileTreeView::contentsDragMoveEvent( TQDragMoveEvent *e )
143 TQListViewItem *afterme;
144 TQListViewItem *parent;
146 findDrop( e->pos(), parent, afterme );
149 TQListViewItem *item = afterme ? afterme : parent;
151 if( item && item->isSelectable() )
153 setSelected( item,
true );
154 if( item != m_dropItem ) {
155 m_autoOpenTimer->stop();
157 m_autoOpenTimer->start( KFileView::autoOpenDelay() );
162 m_autoOpenTimer->stop();
167 void KFileTreeView::contentsDragLeaveEvent( TQDragLeaveEvent * )
170 if ( isValidItem(m_currentBeforeDropItem) )
172 setSelected( m_currentBeforeDropItem,
true );
173 ensureItemVisible( m_currentBeforeDropItem );
175 else if ( isValidItem(m_dropItem) )
176 setSelected( m_dropItem,
false );
177 m_currentBeforeDropItem = 0;
182 void KFileTreeView::contentsDropEvent( TQDropEvent *e )
185 m_autoOpenTimer->stop();
188 kdDebug(250) <<
"contentsDropEvent !" << endl;
195 TQListViewItem *afterme;
196 TQListViewItem *parent;
197 findDrop(e->pos(), parent, afterme);
202 if (e->source() == viewport() && itemsMovable())
203 movableDropEvent(parent, afterme);
206 emit dropped(e, afterme);
207 emit dropped(
this, e, afterme);
208 emit dropped(e, parent, afterme);
209 emit dropped(
this, e, parent, afterme);
212 KURLDrag::decode( e, urls );
213 emit dropped(
this, e, urls );
223 emit dropped( urls, parentURL );
224 emit dropped(
this , e, urls, parentURL );
231 bool ancestOK= acceptDrops();
233 ancestOK = ancestOK && itemsMovable();
243 return ancestOK && KURLDrag::canDecode( e ) &&
245 ( e->action() == TQDropEvent::Copy
246 || e->action() == TQDropEvent::Move
247 || e->action() == TQDropEvent::Link );
252 TQDragObject * KFileTreeView::dragObject()
256 const TQPtrList<TQListViewItem> fileList = selectedItems();
257 TQPtrListIterator<TQListViewItem> it( fileList );
258 for ( ; it.current(); ++it )
264 if( urls.count() > 1 ){
265 pixmap = DesktopIcon(
"application-vnd.tde.tdemultiple", 16 );
267 if( pixmap.isNull() )
269 hotspot.setX( pixmap.width() / 2 );
270 hotspot.setY( pixmap.height() / 2 );
271 TQDragObject* dragObject =
new KURLDrag( urls,
this );
273 dragObject->setPixmap( pixmap, hotspot );
279 void KFileTreeView::slotCollapsed( TQListViewItem *item )
282 kdDebug(250) <<
"hit slotCollapsed" << endl;
283 if( kftvi && kftvi->
isDir())
285 item->setPixmap( 0, itemIcon(kftvi));
289 void KFileTreeView::slotExpanded( TQListViewItem *item )
291 kdDebug(250) <<
"slotExpanded here !" << endl;
299 if( it->
isDir() &&
branch && item->childCount() == 0 )
302 kdDebug(250 ) <<
"starting to open " << it->
url().prettyURL() << endl;
303 startAnimation( it );
305 kdDebug(250) <<
"Branches answer: " << branchAnswer << endl;
308 kdDebug(250) <<
"ERR: Could not populate!" << endl;
314 if( it->
isDir() && isOpen( item ) )
316 kdDebug(250)<<
"Setting open Pixmap" << endl;
317 item->setPixmap( 0, itemIcon( it ));
323 void KFileTreeView::slotExecuted( TQListViewItem *item )
332 item->setOpen( !item->isOpen() );
337 void KFileTreeView::slotAutoOpenFolder()
339 m_autoOpenTimer->stop();
341 if ( !isValidItem(m_dropItem) || m_dropItem->isOpen() )
344 m_dropItem->setOpen(
true );
345 m_dropItem->repaint();
349 void KFileTreeView::slotSelectionChanged()
360 const TQPixmap& folderPix = KMimeType::mimeType(
"inode/directory")->pixmap( TDEIcon::Desktop,TDEIcon::SizeSmall );
362 return addBranch( path, name, folderPix, showHidden);
366 const TQPixmap& pix,
bool showHidden )
368 kdDebug(250) <<
"adding another root " << path.prettyURL() << endl;
382 const KFileTreeViewItemList& )),
384 const KFileTreeViewItemList& )));
386 m_branches.append( newBranch );
393 TQPtrListIterator<KFileTreeBranch> it( m_branches );
395 while ( (
branch = it.current()) != 0 ) {
398 kdDebug(250) <<
"This is the branches name: " << bname << endl;
399 if( bname == searchName )
401 kdDebug(250) <<
"Found branch " << bname <<
" and return ptr" << endl;
410 return( m_branches );
416 if(m_branches.contains(
branch))
419 m_branches.remove(
branch );
432 branch->setDirOnlyMode( bom );
439 if( it && it->
isDir())
443 void KFileTreeView::slotNewTreeViewItems(
KFileTreeBranch* branch,
const KFileTreeViewItemList& itemList )
446 kdDebug(250) <<
"hitting slotNewTreeViewItems" << endl;
455 if( ! m_nextUrlToSelect.isEmpty() )
457 KFileTreeViewItemListIterator it( itemList );
460 for( ; !end && it.current(); ++it )
462 KURL url = (*it)->url();
464 if( m_nextUrlToSelect.equals(url,
true ))
466 setCurrentItem(
static_cast<TQListViewItem*
>(*it) );
467 m_nextUrlToSelect = KURL();
477 kdDebug(250) <<
"Setting icon for column " << gap << endl;
483 if( item == brnch->
root() )
485 pix = brnch->pixmap();
486 if( m_wantOpenFolderPixmaps && brnch->
root()->isOpen() )
488 pix = brnch->openPixmap();
494 pix = item->
fileItem()->pixmap( TDEIcon::SizeSmall );
498 if( item->
isDir() && m_wantOpenFolderPixmaps )
500 if( isOpen(
static_cast<TQListViewItem*
>(item)))
501 pix = m_openFolderPixmap;
510 void KFileTreeView::slotAnimation()
512 MapCurrentOpeningFolders::Iterator it = m_mapCurrentOpeningFolders.begin();
513 MapCurrentOpeningFolders::Iterator end = m_mapCurrentOpeningFolders.end();
517 if (!isValidItem(item))
520 m_mapCurrentOpeningFolders.remove(item);
524 uint & iconNumber = it.data().iconNumber;
525 TQString icon = TQString::fromLatin1( it.data().iconBaseName ).append( TQString::number( iconNumber ) );
527 item->setPixmap( 0, DesktopIcon( icon,TDEIcon::SizeSmall,TDEIcon::ActiveState ));
530 if ( iconNumber > it.data().iconCount )
538 void KFileTreeView::startAnimation(
KFileTreeViewItem * item,
const char * iconBaseName, uint iconCount )
543 kdDebug(250) <<
" startAnimation Got called without valid item !" << endl;
547 m_mapCurrentOpeningFolders.insert( item,
548 AnimationInfo( iconBaseName,
550 itemIcon(item, 0) ) );
551 if ( !m_animationTimer->isActive() )
552 m_animationTimer->start( 50 );
559 kdDebug(250) <<
"Stoping Animation !" << endl;
561 MapCurrentOpeningFolders::Iterator it = m_mapCurrentOpeningFolders.find(item);
562 if ( it != m_mapCurrentOpeningFolders.end() )
564 if( item->
isDir() && isOpen( item) )
566 kdDebug(250) <<
"Setting folder open pixmap !" << endl;
567 item->setPixmap( 0, itemIcon( item ));
571 item->setPixmap( 0, it.data().originalPixmap );
573 m_mapCurrentOpeningFolders.remove( item );
578 kdDebug(250)<<
"StopAnimation - could not find item " << item->
url().prettyURL()<< endl;
580 kdDebug(250)<<
"StopAnimation - item is zero !" << endl;
582 if (m_mapCurrentOpeningFolders.isEmpty())
583 m_animationTimer->stop();
600 void KFileTreeView::slotOnItem( TQListViewItem *item )
605 const KURL url = i->
url();
606 if ( url.isLocalFile() )
607 emit onItem( url.path() );
609 emit onItem( url.prettyURL() );
613 void KFileTreeView::slotItemRenamed(TQListViewItem* item,
const TQString &name,
int col)
616 kdDebug(250) <<
"Do not bother: " << name << col << endl;
632 if( ! relUrl.isEmpty() && TQDir::isRelativePath(relUrl) )
634 TQString partUrl( relUrl );
636 if( partUrl.endsWith(
"/"))
637 partUrl.truncate( relUrl.length()-1 );
639 url.addPath( partUrl );
641 kdDebug(250) <<
"assembled complete dir string " << url.prettyURL() << endl;
643 KFileItem *fi = brnch->findByURL( url );
647 kdDebug(250) <<
"Found item !" <<ret << endl;
662 void KFileTreeViewToolTip::maybeTip(
const TQPoint & )
665 TQListViewItem *item = m_view->itemAt( point );
667 TQString text =
static_cast<KFileViewItem*
>( item )->toolTipText();
668 if ( !text.isEmpty() )
669 tip ( m_view->itemRect( item ), text );
674 void KFileTreeView::virtual_hook(
int id,
void* data )
675 { TDEListView::virtual_hook(
id, data ); }
677 #include "tdefiletreeview.moc"
This is the branch class of the KFileTreeView, which represents one branch in the treeview.
KFileTreeViewItem * root()
virtual bool populate(const KURL &url, KFileTreeViewItem *currItem)
populates a branch.
An item for a KFileTreeView that knows about its own KFileItem.
KFileTreeBranch * branch() const
KFileItem * fileItem() const
KFileTreeViewItem * findItem(KFileTreeBranch *brnch, const TQString &relUrl)
searches a branch for a KFileTreeViewItem identified by the relative url given as second parameter.
virtual void setDirOnlyMode(KFileTreeBranch *branch, bool)
set the directory mode for branches.
virtual bool removeBranch(KFileTreeBranch *branch)
removes the branch from the treeview.
KFileTreeBranch * branch(const TQString &searchName)
KFileTreeBranch * addBranch(const KURL &path, const TQString &name, bool showHidden=false)
Adds a branch to the treeview item.
KFileTreeBranchList & branches()
KFileTreeViewItem * currentKFileTreeViewItem() const
virtual bool acceptDrag(TQDropEvent *event) const