1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* Copyright (C) 2000 Matthias Elter <elter@kde.org>
* Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
* Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef __treeview_h__
#define __treeview_h__
#include <qstring.h>
#include <klistview.h>
#include <kservice.h>
#include <kservicegroup.h>
class QPopupMenu;
class KActionCollection;
class KDesktopFile;
class MenuFile;
class MenuFolderInfo;
class MenuEntryInfo;
class MenuSeparatorInfo;
class KShortcut;
class TreeItem : public QListViewItem
{
public:
TreeItem(QListViewItem *parent, QListViewItem *after, const QString &menuIdn, bool __init = false);
TreeItem(QListView *parent, QListViewItem* after, const QString &menuId, bool __init = false);
QString menuId() const { return _menuId; }
QString directory() const { return _directoryPath; }
void setDirectoryPath(const QString& path) { _directoryPath = path; }
MenuFolderInfo *folderInfo() { return m_folderInfo; }
void setMenuFolderInfo(MenuFolderInfo *folderInfo) { m_folderInfo = folderInfo; }
MenuEntryInfo *entryInfo() { return m_entryInfo; }
void setMenuEntryInfo(MenuEntryInfo *entryInfo) { m_entryInfo = entryInfo; }
QString name() const { return _name; }
void setName(const QString &name);
bool isDirectory() const { return m_folderInfo; }
bool isEntry() const { return m_entryInfo; }
bool isHidden() const { return _hidden; }
void setHidden(bool b);
bool isLayoutDirty() { return _layoutDirty; }
void setLayoutDirty() { _layoutDirty = true; }
QStringList layout();
virtual void setOpen(bool o);
void load();
virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
virtual void setup();
private:
void update();
bool _hidden : 1;
bool _init : 1;
bool _layoutDirty : 1;
QString _menuId;
QString _name;
QString _directoryPath;
MenuFolderInfo *m_folderInfo;
MenuEntryInfo *m_entryInfo;
};
class TreeView : public KListView
{
friend class TreeItem;
Q_OBJECT
public:
TreeView(bool controlCenter, KActionCollection *ac, QWidget *parent=0, const char *name=0);
~TreeView();
void readMenuFolderInfo(MenuFolderInfo *folderInfo=0, KServiceGroup::Ptr folder=0, const QString &prefix=QString::null);
void setViewMode(bool showHidden);
bool save();
bool dirty();
void selectMenu(const QString &menu);
void selectMenuEntry(const QString &menuEntry);
public slots:
void currentChanged(MenuFolderInfo *folderInfo);
void currentChanged(MenuEntryInfo *entryInfo);
void findServiceShortcut(const KShortcut&, KService::Ptr &);
signals:
void entrySelected(MenuFolderInfo *folderInfo);
void entrySelected(MenuEntryInfo *entryInfo);
void disableAction();
protected slots:
void itemSelected(QListViewItem *);
void slotDropped(QDropEvent *, QListViewItem *, QListViewItem *);
void slotRMBPressed(QListViewItem*, const QPoint&);
void newsubmenu();
void newitem();
void newsep();
void cut();
void copy();
void paste();
void del();
protected:
TreeItem *createTreeItem(TreeItem *parent, QListViewItem *after, MenuFolderInfo *folderInfo, bool _init = false);
TreeItem *createTreeItem(TreeItem *parent, QListViewItem *after, MenuEntryInfo *entryInfo, bool _init = false);
TreeItem *createTreeItem(TreeItem *parent, QListViewItem *after, MenuSeparatorInfo *sepInfo, bool _init = false);
void del(TreeItem *, bool deleteInfo);
void fill();
void fillBranch(MenuFolderInfo *folderInfo, TreeItem *parent);
QString findName(KDesktopFile *df, bool deleted);
void closeAllItems(QListViewItem *item);
// moving = src will be removed later
void copy( bool moving );
void cleanupClipboard();
bool isLayoutDirty();
void setLayoutDirty(TreeItem *);
void saveLayout();
QStringList fileList(const QString& relativePath);
QStringList dirList(const QString& relativePath);
virtual bool acceptDrag(QDropEvent* event) const;
virtual QDragObject *dragObject();
virtual void startDrag();
private:
KActionCollection *m_ac;
QPopupMenu *m_rmb;
int m_clipboard;
MenuFolderInfo *m_clipboardFolderInfo;
MenuEntryInfo *m_clipboardEntryInfo;
int m_drag;
MenuFolderInfo *m_dragInfo;
TreeItem *m_dragItem;
QString m_dragPath;
bool m_showHidden;
bool m_controlCenter;
MenuFile *m_menuFile;
MenuFolderInfo *m_rootFolder;
MenuSeparatorInfo *m_separator;
QStringList m_newMenuIds;
QStringList m_newDirectoryList;
bool m_detailedMenuEntries;
bool m_detailedEntriesNamesFirst;
bool m_layoutDirty;
};
#endif
|