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
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*
* Copyright (C) 2003 Waldo Bastian <[email protected]>
*
* 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 __menuinfo_h__
#define __menuinfo_h__
#include <qstring.h>
#include <kshortcut.h>
#include <kservice.h>
class MenuFile;
class MenuEntryInfo;
class MenuInfo
{
public:
MenuInfo() {}
virtual ~MenuInfo() {}
};
class MenuSeparatorInfo : public MenuInfo
{
public:
MenuSeparatorInfo() {}
};
class MenuFolderInfo : public MenuInfo
{
public:
MenuFolderInfo() : dirty(false), hidden(false) { subFolders.setAutoDelete(true); }
// Add separator
void add(MenuSeparatorInfo *, bool initial=false);
// Add sub menu
void add(MenuFolderInfo *, bool initial=false);
// Remove sub menu (without deleting it)
void take(MenuFolderInfo *);
// Remove sub menu (without deleting it)
// @return true if found
bool takeRecursive(MenuFolderInfo *info);
// Add entry
void add(MenuEntryInfo *, bool initial = false);
// Remove entry (without deleteing it)
void take(MenuEntryInfo *);
// Return a unique sub-menu caption inspired by @p caption
QString uniqueMenuCaption(const QString &caption);
// Return a unique item caption inspired by @p caption but different
// from @p exclude
QString uniqueItemCaption(const QString &caption, const QString &exclude = QString::null);
// Update full id's for this item and all submenus
void updateFullId(const QString &parentId);
// Return a list of existing submenu ids
QStringList existingMenuIds();
void setCaption(const QString &_caption)
{
if (_caption == caption) return;
caption = _caption;
setDirty();
}
void setIcon(const QString &_icon)
{
if (_icon == icon) return;
icon = _icon;
setDirty();
}
void setGenericName(const QString &_description)
{
if (_description == genericname) return;
genericname = _description;
setDirty();
}
void setComment(const QString &_comment)
{
if (_comment == comment) return;
comment = _comment;
setDirty();
}
// Mark menu as dirty
void setDirty();
// Return whether this menu or any entry or submenu contained in it is dirty.
bool hasDirt();
// Return whether this menu should be explicitly added to its parent menu
bool needInsertion();
// Save menu and all its entries and submenus
void save(MenuFile *);
// Search service by shortcut
KService::Ptr findServiceShortcut(const KShortcut&);
// Set whether the entry is in active use (as opposed to in the clipboard/deleted)
void setInUse(bool inUse);
public:
QString id; // Relative to parent
QString fullId; // Name in tree
QString caption; // Visible name
QString genericname; // Generic description
QString comment; // Comment
QString directoryFile; // File describing this folder.
QString icon; // Icon
QPtrList<MenuFolderInfo> subFolders; // Sub menus in this folder
QPtrList<MenuEntryInfo> entries; // Menu entries in this folder
QPtrList<MenuInfo> initialLayout; // Layout of menu entries according to sycoca
bool dirty;
bool hidden;
};
class MenuEntryInfo : public MenuInfo
{
public:
MenuEntryInfo(const KService::Ptr &_service, KDesktopFile *_df = 0)
: service(_service), df(_df),
shortcutLoaded(false), shortcutDirty(false), dirty(_df != 0), hidden(false)
{
caption = service->name();
description = service->genericName();
icon = service->icon();
}
~MenuEntryInfo();
void setCaption(const QString &_caption);
void setDescription(const QString &_description);
void setIcon(const QString &_icon);
QString menuId() const { return service->menuId(); }
QString file() const { return service->desktopEntryPath(); }
KShortcut shortcut();
void setShortcut(const KShortcut &_shortcut);
bool isShortcutAvailable(const KShortcut &_shortcut);
void setDirty();
// Set whether the entry is in active use (as opposed to in the clipboard/deleted)
void setInUse(bool inUse);
// Return whether this menu should be explicitly added to its parent menu
bool needInsertion();
void save();
KDesktopFile *desktopFile();
public:
QString caption;
QString description;
QString icon;
KService::Ptr service;
KDesktopFile *df;
KShortcut shortCut;
bool shortcutLoaded;
bool shortcutDirty;
bool dirty;
bool hidden;
};
#endif
|