2 * Copyright (C) 2000 Matthias Elter <elter@kde.org>
3 * Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
4 * Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
5 * Copyright (C) 2008 Laurent Montel <montel@kde.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef __treeview_h__
24 #define __treeview_h__
30 #include <k3listview.h>
32 #include <kservicegroup.h>
35 class KActionCollection
;
40 class MenuSeparatorInfo
;
43 class TreeItem
: public Q3ListViewItem
46 TreeItem(Q3ListViewItem
*parent
, Q3ListViewItem
*after
, const QString
&menuIdn
, bool __init
= false);
47 TreeItem(Q3ListView
*parent
, Q3ListViewItem
* after
, const QString
&menuId
, bool __init
= false);
49 QString
menuId() const { return _menuId
; }
51 QString
directory() const { return _directoryPath
; }
52 void setDirectoryPath(const QString
& path
) { _directoryPath
= path
; }
54 MenuFolderInfo
*folderInfo() { return m_folderInfo
; }
55 void setMenuFolderInfo(MenuFolderInfo
*folderInfo
) { m_folderInfo
= folderInfo
; }
57 MenuEntryInfo
*entryInfo() { return m_entryInfo
; }
58 void setMenuEntryInfo(MenuEntryInfo
*entryInfo
) { m_entryInfo
= entryInfo
; }
60 QString
name() const { return _name
; }
61 void setName(const QString
&name
);
63 bool isDirectory() const { return m_folderInfo
; }
64 bool isEntry() const { return m_entryInfo
; }
66 bool isHidden() const { return _hidden
; }
67 void setHidden(bool b
);
69 bool isLayoutDirty() { return _layoutDirty
; }
70 void setLayoutDirty() { _layoutDirty
= true; }
73 virtual void setOpen(bool o
);
76 virtual void paintCell(QPainter
* p
, const QColorGroup
& cg
, int column
, int width
, int align
);
84 bool _layoutDirty
: 1;
87 QString _directoryPath
;
88 MenuFolderInfo
*m_folderInfo
;
89 MenuEntryInfo
*m_entryInfo
;
92 class TreeView
: public K3ListView
94 friend class TreeItem
;
97 TreeView(KActionCollection
*ac
, QWidget
*parent
=0, const char *name
=0);
100 void readMenuFolderInfo(MenuFolderInfo
*folderInfo
=0, KServiceGroup::Ptr folder
=KServiceGroup::Ptr(), const QString
&prefix
=QString());
101 void setViewMode(bool showHidden
);
106 void selectMenu(const QString
&menu
);
107 void selectMenuEntry(const QString
&menuEntry
);
109 void restoreMenuSystem();
111 void updateTreeView(bool showHidden
);
114 void currentChanged(MenuFolderInfo
*folderInfo
);
115 void currentChanged(MenuEntryInfo
*entryInfo
);
116 void findServiceShortcut(const KShortcut
&, KService::Ptr
&);
119 void entrySelected(MenuFolderInfo
*folderInfo
);
120 void entrySelected(MenuEntryInfo
*entryInfo
);
121 void disableAction();
123 void itemSelected(Q3ListViewItem
*);
124 void slotDropped(QDropEvent
*, Q3ListViewItem
*, Q3ListViewItem
*);
125 void slotRMBPressed(Q3ListViewItem
*, const QPoint
&);
137 TreeItem
*createTreeItem(TreeItem
*parent
, Q3ListViewItem
*after
, MenuFolderInfo
*folderInfo
, bool _init
= false);
138 TreeItem
*createTreeItem(TreeItem
*parent
, Q3ListViewItem
*after
, MenuEntryInfo
*entryInfo
, bool _init
= false);
139 TreeItem
*createTreeItem(TreeItem
*parent
, Q3ListViewItem
*after
, MenuSeparatorInfo
*sepInfo
, bool _init
= false);
141 void del(TreeItem
*, bool deleteInfo
);
143 void fillBranch(MenuFolderInfo
*folderInfo
, TreeItem
*parent
);
144 QString
findName(KDesktopFile
*df
, bool deleted
);
146 void closeAllItems(Q3ListViewItem
*item
);
148 // moving = src will be removed later
149 void copy( bool moving
);
151 void cleanupClipboard();
153 bool isLayoutDirty();
154 void setLayoutDirty(TreeItem
*);
157 QStringList
fileList(const QString
& relativePath
);
158 QStringList
dirList(const QString
& relativePath
);
160 virtual bool acceptDrag(QDropEvent
* event
) const;
161 virtual Q3DragObject
*dragObject();
162 virtual void startDrag();
164 void sendReloadMenu();
167 KActionCollection
*m_ac
;
170 MenuFolderInfo
*m_clipboardFolderInfo
;
171 MenuEntryInfo
*m_clipboardEntryInfo
;
173 MenuFolderInfo
*m_dragInfo
;
174 TreeItem
*m_dragItem
;
177 MenuFile
*m_menuFile
;
178 MenuFolderInfo
*m_rootFolder
;
179 MenuSeparatorInfo
*m_separator
;
180 QStringList m_newMenuIds
;
181 QStringList m_newDirectoryList
;
182 bool m_detailedMenuEntries
;
183 bool m_detailedEntriesNamesFirst
;