1 /* This file is part of the KDE project
2    Copyright (C) 2000 David Faure <faure@kde.org>
3                  2000 Carsten Pfeiffer <pfeiffer@kde.org>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License version 2 as published by the Free Software Foundation.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef FILETREEVIEWITEM_H
21 #define FILETREEVIEWITEM_H
22 
23 #include <qtreewidget.h>
24 
25 #include <kfileitem.h>
26 #include <kdirlister.h>
27 
28 #include <kio/global.h>
29 #include <kio/job.h>
30 
31 class QUrl;
32 
33 class FileTreeView;
34 class FileTreeBranch;
35 
36 /**
37  * An item for a FileTreeView that knows about its own KFileItem.
38  */
39 class FileTreeViewItem : public QTreeWidgetItem
40 {
41 public:
42     FileTreeViewItem(FileTreeViewItem *parent, const KFileItem &fi, FileTreeBranch *branch);
43     FileTreeViewItem(FileTreeView *parent, const KFileItem &fi, FileTreeBranch *branch);
44     ~FileTreeViewItem();
45 
46     /**
47      * @return the KFileTreeBranch the item is sorted in.
48      */
branch()49     FileTreeBranch *branch() const
50     {
51         return (m_branch);
52     }
53 
54     /**
55      * @return the KFileItem the viewitem is representing.
56      * A copy of the original (provided by the KDirLister), so not
57      * much point in trying to modify it.
58      */
fileItem()59     const KFileItem *fileItem() const
60     {
61         return (&m_kfileitem);
62     }
63 
64     /**
65      * @return the path of the item.
66      */
67     // TODO: is this simply equivalent to 'url().path()'?
68     QString path() const;
69 
70     /**
71      * @return the items QUrl
72      */
73     QUrl url() const;
74     void setUrl(const QUrl &url);
75 
76     /**
77      * @return if the item represents a directory
78      */
79     bool isDir() const;
80 
81     /**
82      * @return if the item represents the root of its branch
83      */
84     bool isRoot() const;
85 
86     /**
87      * @return if this directory was already seen by a KDirLister.
88      */
89     bool alreadyListed() const;
90 
91     /**
92      * set the flag if the directory was already listed.
93      */
94     void setListed(bool wasListed);
95 
96     /**
97      * substitute for the KFileItem's extra data, but only one of these
98      */
99     // TODO: use QTreeWidgetItem::data()
100     void setClientData(void *data);
101     void *clientData() const;
102 
103 private:
104     void init(const KFileItem &fi, FileTreeBranch *branch);
105 
106     KFileItem m_kfileitem;
107     FileTreeBranch *m_branch;
108     bool m_wasListed;
109     void *m_clientData;
110 
111     // TODO: not used
112     class FileTreeViewItemPrivate;
113     FileTreeViewItemPrivate *d;
114 };
115 
116 /**
117  * List of KFileTreeViewItems
118  */
119 typedef QList<FileTreeViewItem *> FileTreeViewItemList;
120 
121 #endif                          // FILETREEVIEWITEM_H
122