/** Called for: double click, return, Open */ void BaseTreeView::slotSelectFile(QListViewItem *item) { KFileTreeViewItem* kftvi = currentKFileTreeViewItem(); if (!kftvi || kftvi->isDir()) return; KURL urlToOpen = kftvi->url(); if (!urlToOpen.isEmpty()) { if ( QuantaCommon::checkMimeGroup(urlToOpen,"text") ) { emit openFile(urlToOpen); item->repaint(); } else if ( QuantaCommon::checkMimeGroup(urlToOpen, "image") ) //it may be an image { emit openImage( urlToOpen); } else if ( expandArchiv(kftvi)) //it may be an archiv { } else //it is an unknown type, maybe binary { if (QuantaCommon::denyBinaryInsert(this) == KMessageBox::Yes) { emit openFile(urlToOpen); item->repaint(); } } } }
void BaseTreeView::slotPropertiesApplied() { if (! propDlg) return; // check if renamed KURL url = currentURL(); if (url != propDlg->kurl()) { itemRenamed(url, propDlg->kurl()); } KFileTreeViewItem *kftvi = currentKFileTreeViewItem(); if (fileInfoDlg && kftvi) { // has description changed? QString newDesc = fileInfoDlg->fileDesc->text(); if (kftvi->text(1) != newDesc) itemDescChanged(kftvi, newDesc); } BaseTreeViewItem * btvi = dynamic_cast<BaseTreeViewItem *> (kftvi); if (btvi) { btvi->refreshIcon(); } /* not working as expected if (kftvi && kftvi->url().isLocalFile()) { slotReloadAllTrees(); // refresh the icons for local url's, they might have changed }*/ }
KURL K3bFileTreeView::selectedUrl() const { KFileTreeViewItem* treeItem = dynamic_cast<KFileTreeViewItem*>(selectedItem()); if( treeItem ) { if( !d->branchDeviceMap.contains( treeItem->branch() ) ) return treeItem->url(); } return KURL(); }
K3bDevice::Device* K3bFileTreeView::selectedDevice() const { KFileTreeViewItem* treeItem = dynamic_cast<KFileTreeViewItem*>(selectedItem()); if( treeItem ) { if( d->branchDeviceMap.contains( treeItem->branch() ) ) return d->branchDeviceMap[treeItem->branch()]; } return 0; }
bool BaseTreeView::acceptDrag(QDropEvent* e ) const { QPoint p (contentsToViewport(e->pos())); QListViewItem *atpos = itemAt(p); KFileTreeViewItem *kftvi = dynamic_cast <KFileTreeViewItem *> (atpos); if (kftvi) return (KFileTreeView::acceptDrag(e) && kftvi->isDir()); // accept only on folders else return (KFileTreeView::acceptDrag(e)); }
void K3bFileTreeView::slotItemExecuted( QListViewItem* item ) { KFileTreeViewItem* treeItem = static_cast<KFileTreeViewItem*>(item); if( d->branchDeviceMap.contains( treeItem->branch() ) && treeItem == treeItem->branch()->root() ) { K3bDevice::Device* dev = d->branchDeviceMap[treeItem->branch()]; k3bappcore->appDeviceManager()->setCurrentDevice( dev ); emit deviceExecuted( dev ); } else emit urlExecuted( treeItem->url() ); }
void BaseTreeBranch::addOpenFolder(QStringList* openFolder) { if (! openFolder) // just in case return; KFileTreeViewItem *newItem; KFileTreeViewItem *item = root(); while (item) { if (item->isDir() && item->isOpen()) { openFolder->append( item->url().url() ); // dive into the tree first newItem = dynamic_cast<KFileTreeViewItem *>(item->firstChild()); if (newItem) { // found child go ahead item = newItem; continue; }; }; // move up in the tree while (item && item != root()) { if (item->nextSibling()) { item = dynamic_cast<KFileTreeViewItem *>(item->nextSibling()); break; } else { item = dynamic_cast<KFileTreeViewItem *>(item->parent()); } } if (item == root()) break; }; }
void BaseTreeBranch::updateOpenFolder() { KFileTreeViewItem *newItem; KFileTreeViewItem *item = root(); while (item) { if (item->isDir() && item->isOpen()) { updateDirectory( item->url() ); kapp->processEvents(QEventLoop::ExcludeUserInput | QEventLoop::ExcludeSocketNotifiers); // dive into the tree first newItem = dynamic_cast<KFileTreeViewItem *>(item->firstChild()); if (newItem) { // found child go ahead item = newItem; continue; }; }; // go up if no sibling available if (! item->nextSibling()) item = dynamic_cast<KFileTreeViewItem *>(item->parent()); if (item == root()) break; if (item) item = dynamic_cast<KFileTreeViewItem *>(item->nextSibling()); }; }
void KFileTreeBranch::slotRefreshItems( const KFileItemList& list ) { KFileItemListIterator it( list ); kdDebug(250) << "Refreshing " << list.count() << " items !" << endl; KFileItem *currItem; KFileTreeViewItem *item = 0; while ( (currItem = it.current()) != 0 ) { item = findTVIByURL(currItem->url()); if (item) { item->setPixmap(0, item->fileItem()->pixmap( TDEIcon::SizeSmall )); item->setText( 0, item->fileItem()->text()); } ++it; } }
void BaseTreeBranch::reopenFolder() { if (folderToOpen.isEmpty()) return; KFileTreeViewItem *item; for (QStringList::Iterator it = folderToOpen.begin(); it != folderToOpen.end(); ++it) { KURL url( (*it) ); item = findTVIByURL(url); if (item) { // erase the url in the list (*it) = ""; // open the folder item->setExpandable(true); item->setOpen(true); } } }
void BaseTreeView::slotDocumentClosed(const KURL& url) { KFileTreeViewItem * item; KFileTreeBranchIterator it( branches() ); for ( ; it.current(); ++it) { item = (*it)->findTVIByURL(url); if (item) { item->repaint(); } } /* QListViewItemIterator iter(this); for ( ; iter.current(); ++iter ) { iter.current()->repaint(); }*/ }
void BaseTreeView::itemRenamed(const KURL& oldURL, const KURL& newURL) { KFileTreeViewItem *curItem = currentKFileTreeViewItem(); if (! curItem) return; if (curItem->isDir()) { KURL n = newURL; n.adjustPath(1); KURL o = oldURL; o.adjustPath(1); emit renamed(o, n); } else { emit renamed(oldURL, newURL); } }
void K3bFileTreeView::slotContextMenu( KListView*, QListViewItem* item, const QPoint& p ) { KFileTreeViewItem* treeItem = dynamic_cast<KFileTreeViewItem*>(item); if( treeItem ) { K3bDevice::Device* device = 0; QMap<KFileTreeBranch*, K3bDevice::Device*>::iterator devIt = d->branchDeviceMap.find( treeItem->branch() ); if( devIt != d->branchDeviceMap.end() ) device = devIt.data(); setCurrentItem( treeItem ); setSelected( treeItem, true); if( device ) { k3bappcore->appDeviceManager()->setCurrentDevice( device ); emit contextMenu( device, p ); } else emit contextMenu( treeItem->url(), p ); } else kdWarning() << "(K3bFileTreeView) found viewItem that is no KFileTreeViewItem!" << endl; }
void BaseTreeViewToolTip::maybeTip( const QPoint &pos ) { if ( !parentWidget() || !m_view || !m_view->showToolTips() ) return; QListViewItem *item = m_view->itemAt(pos); if (!item) return; QString text; KFileTreeViewItem * kftvi = dynamic_cast<BaseTreeViewItem *> (item); if (kftvi) { QString desc = kftvi->text(1); text = kftvi->fileItem()->getToolTipText(); if ( !desc.isEmpty() ) text.prepend(" <i>" + desc + "</i><br>"); } else { // show something for the branchroot text = item->text(0); if ( ! item->text(1).isEmpty() ) text.append( "<br>" + item->text(1)); } if ( !text.isEmpty() ) tip(m_view->itemRect(item), text); }
/* * The signal that tells that a directory was deleted may arrive before the signal * for its children arrive. Thus, we must walk through the children of a dir and * remove them before removing the dir itself. */ void KFileTreeBranch::slotDeleteItem( KFileItem *it ) { if( !it ) return; kdDebug(250) << "Slot Delete Item hitted for " << it->url().prettyURL() << endl; KFileTreeViewItem *kfti = static_cast<KFileTreeViewItem*>(it->extraData(this)); if( kfti ) { kdDebug( 250 ) << "Child count: " << kfti->childCount() << endl; if( kfti->childCount() > 0 ) { KFileTreeViewItem *child = static_cast<KFileTreeViewItem*>(kfti->firstChild()); while( child ) { kdDebug(250) << "Calling child to be deleted !" << endl; KFileTreeViewItem *nextChild = static_cast<KFileTreeViewItem*>(child->nextSibling()); slotDeleteItem( child->fileItem()); child = nextChild; } } kdDebug(250) << "Found corresponding KFileTreeViewItem" << endl; if( m_lastFoundURL.equals(it->url(), true )) { m_lastFoundURL = KURL(); m_lastFoundItem = 0L; } delete( kfti ); } else { kdDebug(250) << "Error: tdefiletreeviewitem: "<< kfti << endl; } }
void KFileTreeBranch::slCompleted( const KURL& url ) { kdDebug(250) << "SlotCompleted hit for " << url.prettyURL() << endl; KFileTreeViewItem *currParent = findTVIByURL( url ); if( ! currParent ) return; kdDebug(250) << "current parent " << currParent << " is already listed: " << currParent->alreadyListed() << endl; emit( populateFinished(currParent)); emit( directoryChildCount(currParent, currParent->childCount())); /* This is a walk through the children of the last populated directory. * Here we start the dirlister on every child of the dir and wait for its * finish. When it has finished, we go to the next child. * This must be done for non local file systems in dirOnly- and Full-Mode * and for local file systems only in full mode, because the stat trick * (see addItem-Method) does only work for dirs, not for files in the directory. */ /* Set bit that the parent dir was listed completely */ currParent->setListed(true); kdDebug(250) << "recurseChildren: " << m_recurseChildren << endl; kdDebug(250) << "isLocalFile: " << m_startURL.isLocalFile() << endl; kdDebug(250) << "dirOnlyMode: " << dirOnlyMode() << endl; if( m_recurseChildren && (!m_startURL.isLocalFile() || ! dirOnlyMode()) ) { bool wantRecurseUrl = false; /* look if the url is in the list for url to recurse */ for ( KURL::List::Iterator it = m_openChildrenURLs.begin(); it != m_openChildrenURLs.end(); ++it ) { /* it is only interesting that the url _is_in_ the list. */ if( (*it).equals( url, true ) ) wantRecurseUrl = true; } KFileTreeViewItem *nextChild = 0; kdDebug(250) << "Recursing " << url.prettyURL() << "? " << wantRecurseUrl << endl; if( wantRecurseUrl && currParent ) { /* now walk again through the tree and populate the children to get +-signs */ /* This is the starting point. The visible folder has finished, processing the children has not yet started */ nextChild = static_cast<KFileTreeViewItem*> (static_cast<TQListViewItem*>(currParent)->firstChild()); if( ! nextChild ) { /* This happens if there is no child at all */ kdDebug( 250 ) << "No children to recuse" << endl; } /* Since we have listed the children to recurse, we can remove the entry * in the list of the URLs to see the children. */ m_openChildrenURLs.remove(url); } if( nextChild ) /* This implies that idx > -1 */ { /* Next child is defined. We start a dirlister job on every child item * which is a directory to find out how much children are in the child * of the last opened dir */ /* Skip non directory entries */ while( nextChild ) { if( nextChild->isDir() && ! nextChild->alreadyListed()) { KFileItem *kfi = nextChild->fileItem(); if( kfi && kfi->isReadable()) { KURL recurseUrl = kfi->url(); kdDebug(250) << "Starting to recurse NOW " << recurseUrl.prettyURL() << endl; openURL( recurseUrl, true ); } } nextChild = static_cast<KFileTreeViewItem*>(static_cast<TQListViewItem*>(nextChild->nextSibling())); // kdDebug(250) << "Next child " << m_nextChild << endl; } } } else { kdDebug(250) << "skipping to recurse in complete-slot" << endl; } }
void KFileTreeBranch::addItems( const KFileItemList& list ) { KFileItemListIterator it( list ); kdDebug(250) << "Adding " << list.count() << " items !" << endl; KFileItem *currItem; KFileTreeViewItemList treeViewItList; KFileTreeViewItem *parentItem = 0; while ( (currItem = it.current()) != 0 ) { parentItem = parentKFTVItem( currItem ); /* Only create a new KFileTreeViewItem if it does not yet exist */ KFileTreeViewItem *newKFTVI = static_cast<KFileTreeViewItem *>(currItem->extraData( this )); if( ! newKFTVI ) { newKFTVI = createTreeViewItem( parentItem, currItem ); if (!newKFTVI) { // TODO: Don't fail if parentItem == 0 ++it; continue; } currItem->setExtraData( this, newKFTVI ); /* Cut off the file extension in case it is not a directory */ if( !m_showExtensions && !currItem->isDir() ) /* Need to cut the extension */ { TQString name = currItem->text(); int mPoint = name.findRev( '.' ); if( mPoint > 0 ) name = name.left( mPoint ); newKFTVI->setText( 0, name ); } } /* Now try to find out if there are children for dirs in the treeview */ /* This stats a directory on the local file system and checks the */ /* hardlink entry in the stat-buf. This works only for local directories. */ if( dirOnlyMode() && !m_recurseChildren && currItem->isLocalFile( ) && currItem->isDir() ) { KURL url = currItem->url(); TQString filename = url.directory( false, true ) + url.fileName(); /* do the stat trick of Carsten. The problem is, that the hardlink * count only contains directory links. Thus, this method only seem * to work in dir-only mode */ kdDebug(250) << "Doing stat on " << filename << endl; KDE_struct_stat statBuf; if( KDE_stat( TQFile::encodeName( filename ), &statBuf ) == 0 ) { int hardLinks = statBuf.st_nlink; /* Count of dirs */ kdDebug(250) << "stat succeeded, hardlinks: " << hardLinks << endl; // If the link count is > 2, the directory likely has subdirs. If it's < 2 // it's something weird like a mounted SMB share. In that case we don't know // if there are subdirs, thus show it as expandable. if( hardLinks != 2 ) { newKFTVI->setExpandable(true); } else { newKFTVI->setExpandable(false); } if( hardLinks >= 2 ) // "Normal" directory with subdirs { kdDebug(250) << "Emitting for " << url.prettyURL() << endl; emit( directoryChildCount( newKFTVI, hardLinks-2)); // parentItem, hardLinks-1 )); } } else { kdDebug(250) << "stat of " << filename << " failed !" << endl; } } ++it; treeViewItList.append( newKFTVI ); } emit newTreeViewItems( this, treeViewItList ); }
void BaseTreeView::slotReload() { KFileTreeViewItem *curItem = currentKFileTreeViewItem(); if (curItem) reload(dynamic_cast<BaseTreeBranch *>(curItem->branch())); }