Example #1
0
KFileTreeViewItem* KFileTreeBranch::findTVIByURL( const KURL& url )
{
    KFileTreeViewItem *resultItem = 0;

    if( m_startURL.equals(url, true) )
    {
        kdDebug(250) << "findByURL: Returning root as a parent !" << endl;
        resultItem = m_root;
    }
    else if( m_lastFoundURL.equals( url, true ))
    {
        kdDebug(250) << "findByURL: Returning from lastFoundURL!" << endl;
        resultItem = m_lastFoundItem;
    }
    else
    {
        kdDebug(250) << "findByURL: searching by dirlister: " << url.url() << endl;

        KFileItem *it = findByURL( url );

        if( it )
        {
            resultItem = static_cast<KFileTreeViewItem*>(it->extraData(this));
            m_lastFoundItem = resultItem;
            m_lastFoundURL = url;
        }
    }

    return( resultItem );
}
Example #2
0
void KFileTreeBranch::slotDirlisterClearURL( const KURL& url )
{
    kdDebug(250)<< "*** Clear for URL !" << url.prettyURL() << endl;
    KFileItem *item = findByURL( url );
    if( item )
    {
        KFileTreeViewItem *ftvi =
            static_cast<KFileTreeViewItem *>(item->extraData( this ));
        deleteChildrenOf( ftvi );
    }
}
Example #3
0
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 );
}