not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kmenuedit / menuinfo.h
blobe6f251318c624bfba3bbb60c813017df5aaf4b5a
1 /*
2 * Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #ifndef __menuinfo_h__
21 #define __menuinfo_h__
24 //Added by qt3to4:
25 #include <Q3PtrList>
27 #include <kshortcut.h>
28 #include <kservice.h>
30 class MenuFile;
31 class MenuEntryInfo;
33 class MenuInfo
35 public:
36 MenuInfo() {}
37 virtual ~MenuInfo() {}
40 class MenuSeparatorInfo : public MenuInfo
42 public:
43 MenuSeparatorInfo() {}
46 class MenuFolderInfo : public MenuInfo
48 public:
49 MenuFolderInfo() : dirty(false), hidden(false) { subFolders.setAutoDelete(true); }
51 // Add separator
52 void add(MenuSeparatorInfo *, bool initial=false);
54 // Add sub menu
55 void add(MenuFolderInfo *, bool initial=false);
57 // Remove sub menu (without deleting it)
58 void take(MenuFolderInfo *);
60 // Remove sub menu (without deleting it)
61 // @return true if found
62 bool takeRecursive(MenuFolderInfo *info);
64 // Add entry
65 void add(MenuEntryInfo *, bool initial = false);
67 // Remove entry (without deleting it)
68 void take(MenuEntryInfo *);
70 // Return a unique sub-menu caption inspired by @p caption
71 QString uniqueMenuCaption(const QString &caption);
73 // Return a unique item caption inspired by @p caption but different
74 // from @p exclude
75 QString uniqueItemCaption(const QString &caption, const QString &exclude = QString());
77 // Update full id's for this item and all submenus
78 void updateFullId(const QString &parentId);
80 // Return a list of existing submenu ids
81 QStringList existingMenuIds();
83 void setCaption(const QString &_caption)
85 if (_caption == caption) return;
86 caption = _caption;
87 setDirty();
90 void setIcon(const QString &_icon)
92 if (_icon == icon) return;
93 icon = _icon;
94 setDirty();
97 void setGenericName(const QString &_description)
99 if (_description == genericname) return;
100 genericname = _description;
101 setDirty();
104 void setComment(const QString &_comment)
106 if (_comment == comment) return;
107 comment = _comment;
108 setDirty();
111 // Mark menu as dirty
112 void setDirty();
114 // Return whether this menu or any entry or submenu contained in it is dirty.
115 bool hasDirt();
117 // Return whether this menu should be explicitly added to its parent menu
118 bool needInsertion();
120 // Save menu and all its entries and submenus
121 void save(MenuFile *);
123 // Search service by shortcut
124 KService::Ptr findServiceShortcut(const KShortcut&);
126 // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
127 void setInUse(bool inUse);
129 public:
130 QString id; // Relative to parent
131 QString fullId; // Name in tree
132 QString caption; // Visible name
133 QString genericname; // Generic description
134 QString comment; // Comment
135 QString directoryFile; // File describing this folder.
136 QString icon; // Icon
137 Q3PtrList<MenuFolderInfo> subFolders; // Sub menus in this folder
138 Q3PtrList<MenuEntryInfo> entries; // Menu entries in this folder
139 Q3PtrList<MenuInfo> initialLayout; // Layout of menu entries according to sycoca
140 bool dirty;
141 bool hidden;
144 class MenuEntryInfo : public MenuInfo
146 public:
147 MenuEntryInfo(const KService::Ptr &_service, KDesktopFile *_df = 0)
148 : service(_service), m_desktopFile(_df),
149 shortcutLoaded(false), shortcutDirty(false), dirty(_df != 0), hidden(false)
151 caption = service->name();
152 description = service->genericName();
153 icon = service->icon();
155 ~MenuEntryInfo();
157 void setCaption(const QString &_caption);
158 void setDescription(const QString &_description);
159 void setIcon(const QString &_icon);
161 QString menuId() const { return service->menuId(); }
163 QString file() const { return service->entryPath(); }
165 KShortcut shortcut();
166 void setShortcut(const KShortcut &_shortcut);
167 bool isShortcutAvailable(const KShortcut &_shortcut);
169 void setDirty();
171 // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
172 void setInUse(bool inUse);
174 // Return whether this menu should be explicitly added to its parent menu
175 bool needInsertion();
177 void save();
179 KDesktopFile *desktopFile();
181 public:
182 QString caption;
183 QString description;
184 QString icon;
185 KService::Ptr service;
186 KDesktopFile *m_desktopFile;
187 KShortcut shortCut;
188 bool shortcutLoaded;
189 bool shortcutDirty;
190 bool dirty;
191 bool hidden;
194 #endif