home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfiletreebranch.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  7.5 KB  |  243 lines

  1.  
  2. /* This file is part of the KDE project
  3.    Copyright (C) 2000 David Faure <faure@kde.org>
  4.                  2000 Carsten Pfeiffer <pfeiffer@kde.org>
  5.                  2001 Klaas Freitag <freitag@suse.de>
  6.  
  7.    This library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU Library General Public
  9.    License version 2 as published by the Free Software Foundation.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.    Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef kfile_tree_branch_h
  23. #define kfile_tree_branch_h
  24.  
  25. #include <qdict.h>
  26. #include <qlistview.h>
  27.  
  28. #include <kfileitem.h>
  29. #include <kio/global.h>
  30. #include <kdirlister.h>
  31. #include <kio/job.h>
  32. #include <kfiletreeviewitem.h>
  33.  
  34. class KURL;
  35. class KFileTreeView;
  36.  
  37.  
  38. /**
  39.  * This is the branch class of the KFileTreeView, which represents one
  40.  * branch in the treeview. Every branch has a root which is an url. The branch
  41.  * lists the files under the root. Every branch uses its own dirlister and can
  42.  * have its own filter etc.
  43.  *
  44.  * @short Branch object for KFileTreeView object.
  45.  *
  46.  */
  47.  
  48. class KIO_EXPORT KFileTreeBranch : public KDirLister
  49. {
  50.    Q_OBJECT
  51. public:
  52.    /**
  53.     * constructs a branch for KFileTreeView. Does not yet start to list it.
  54.     * @param url start url of the branch.
  55.     * @param name the name of the branch, which is displayed in the first column of the treeview.
  56.     * @param pix is a pixmap to display as an icon of the branch.
  57.     * @param showHidden flag to make hidden files visible or not.
  58.     * @param branchRoot is the KFileTreeViewItem to use as the root of the
  59.     *        branch, with the default 0 meaning to let KFileTreeBranch create
  60.     *        it for you.
  61.     */
  62.    KFileTreeBranch( KFileTreeView*, const KURL& url, const QString& name,
  63.                     const QPixmap& pix, bool showHidden = false,
  64.             KFileTreeViewItem *branchRoot = 0 );
  65.  
  66.    /**
  67.     * @returns the root url of the branch.
  68.     */
  69.    KURL     rootUrl() const { return( m_startURL ); }
  70.  
  71.    /**
  72.     * sets a KFileTreeViewItem as root widget for the branch.
  73.     * That must be created outside of the branch. All KFileTreeViewItems
  74.     * the branch is allocating will become children of that object.
  75.     * @param r the KFileTreeViewItem to become the root item.
  76.     */
  77.    virtual void     setRoot( KFileTreeViewItem *r ){ m_root = r; };
  78.  
  79.    /**
  80.     * @returns the root item.
  81.     */
  82.    KFileTreeViewItem *root( ) { return( m_root );}
  83.  
  84.    /**
  85.     * @returns the name of the branch.
  86.     */
  87.    QString      name() const { return( m_name ); }
  88.  
  89.    /**
  90.     * sets the name of the branch.
  91.     */
  92.    virtual void         setName( const QString n ) { m_name = n; };
  93.  
  94.    /*
  95.     * returns the current root item pixmap set in the constructor. The root
  96.     * item pixmap defaults to the icon for directories.
  97.     * @see openPixmap()
  98.     */
  99.    const QPixmap& pixmap(){ return(m_rootIcon); }
  100.  
  101.    /*
  102.     * returns the current root item pixmap set by setOpenPixmap()
  103.     * which is displayed if the branch is expanded.
  104.     * The root item pixmap defaults to the icon for directories.
  105.     * @see pixmap()
  106.     * Note that it depends on KFileTreeView::showFolderOpenPximap weather
  107.     * open pixmap are displayed or not.
  108.     */
  109.    const QPixmap& openPixmap() { return(m_openRootIcon); }
  110.  
  111.    /**
  112.     * @returns whether the items in the branch show their file extensions in the
  113.     * tree or not. See setShowExtensions for more information.
  114.     */
  115.    bool showExtensions( ) const;
  116.  
  117.    /**
  118.     * sets the root of the branch open or closed.
  119.     */
  120.    void setOpen( bool setopen = true )
  121.       { if( root() ) root()->setOpen( setopen ); }
  122.  
  123.    /**
  124.     * sets if children recursion is wanted or not. If this is switched off, the
  125.     * child directories of a just opened directory are not listed internally.
  126.     * That means that it can not be determined if the sub directories are
  127.     * expandable or not. If this is switched off there will be no call to
  128.     * setExpandable.
  129.     * @param t set to true to switch on child recursion
  130.     */
  131.    void setChildRecurse( bool t=true );
  132.  
  133.    /**
  134.     * @returns if child recursion is on or off.
  135.     * @see setChildRecurse
  136.     */
  137.    bool childRecurse()
  138.       { return m_recurseChildren; }
  139.  
  140. public slots:
  141.    /**
  142.     * populates a branch. This method must be called after a branch was added
  143.     * to  a KFileTreeView using method addBranch.
  144.     * @param url is the url of the root item where the branch starts.
  145.     * @param currItem is the current parent.
  146.     */
  147.    virtual bool populate( const KURL &url, KFileTreeViewItem* currItem );
  148.  
  149.    /**
  150.     * sets printing of the file extensions on or off. If you pass false to this
  151.     * slot, all items of this branch will not show their file extensions in the
  152.     * tree.
  153.     * @param visible flags if the extensions should be visible or not.
  154.     */
  155.    virtual void setShowExtensions( bool visible = true );
  156.  
  157.    void setOpenPixmap( const QPixmap& pix );
  158.  
  159. protected:
  160.    /**
  161.     * allocates a KFileTreeViewItem for the branch
  162.     * for new items.
  163.     */
  164.    virtual KFileTreeViewItem *createTreeViewItem( KFileTreeViewItem *parent,
  165.                           KFileItem *fileItem );
  166.  
  167. public:
  168.    /**
  169.     * find the according KFileTreeViewItem by an url
  170.     */
  171.    virtual KFileTreeViewItem *findTVIByURL( const KURL& );
  172.  
  173. signals:
  174.    /**
  175.     * emitted with the item of a directory which was finished to populate
  176.     */
  177.    void populateFinished( KFileTreeViewItem * );
  178.  
  179.    /**
  180.     * emitted with a list of new or updated KFileTreeViewItem which were
  181.     * found in a branch. Note that this signal is emitted very often and may slow
  182.     * down the performance of the treeview !
  183.     */
  184.    void newTreeViewItems( KFileTreeBranch*, const KFileTreeViewItemList& );
  185.  
  186.    /**
  187.     * emitted with the exact count of children for a directory.
  188.     */
  189.    void directoryChildCount( KFileTreeViewItem* item, int count );
  190.  
  191. private slots:
  192.    void slotRefreshItems( const KFileItemList& );
  193.    void addItems( const KFileItemList& );
  194.    void slCompleted( const KURL& );
  195.    void slotCanceled( const KURL& );
  196.    void slotListerStarted( const KURL& );
  197.    void slotDeleteItem( KFileItem* );
  198.    void slotDirlisterClear();
  199.    void slotDirlisterClearURL( const KURL& url );
  200.    void slotRedirect( const KURL& oldUrl, const KURL&newUrl );
  201.  
  202. private:
  203.    KFileTreeViewItem    *parentKFTVItem( KFileItem *item );
  204.    static void           deleteChildrenOf( QListViewItem *parent );
  205.  
  206.    KFileTreeViewItem     *m_root;
  207.    KURL         m_startURL;
  208.    QString         m_name;
  209.    QPixmap         m_rootIcon;
  210.    QPixmap              m_openRootIcon;
  211.  
  212.    /* this list holds the url's which children are opened. */
  213.    KURL::List           m_openChildrenURLs;
  214.  
  215.  
  216.    /* The next two members are used for caching purposes in findTVIByURL. */
  217.    KURL                 m_lastFoundURL;
  218.    KFileTreeViewItem   *m_lastFoundItem;
  219.  
  220.    bool                 m_recurseChildren :1;
  221.    bool                 m_showExtensions  :1;
  222.  
  223. protected:
  224.    virtual void virtual_hook( int id, void* data );
  225. private:
  226.    class KFileTreeBranchPrivate;
  227.    KFileTreeBranchPrivate *d;
  228. };
  229.  
  230.  
  231. /**
  232.  * List of KFileTreeBranches
  233.  */
  234. typedef QPtrList<KFileTreeBranch> KFileTreeBranchList;
  235.  
  236. /**
  237.  * Iterator for KFileTreeBranchLists
  238.  */
  239. typedef QPtrListIterator<KFileTreeBranch> KFileTreeBranchIterator;
  240.  
  241. #endif
  242.  
  243.