~ubuntu-branches/ubuntu/wily/kmenuedit/wily

« back to all changes in this revision

Viewing changes to menuinfo.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-10-14 13:48:27 UTC
  • Revision ID: package-import@ubuntu.com-20141014134827-c4gvv92bbv7zww8j
Tags: upstream-5.1.0.1
ImportĀ upstreamĀ versionĀ 5.1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#ifndef menuinfo_h
 
21
#define menuinfo_h
 
22
 
 
23
 
 
24
#include <QList>
 
25
 
 
26
#include <KShortcut>
 
27
#include <KService>
 
28
 
 
29
class MenuFile;
 
30
class MenuEntryInfo;
 
31
 
 
32
class MenuInfo
 
33
{
 
34
public:
 
35
    MenuInfo() {}
 
36
    virtual ~MenuInfo() {}
 
37
};
 
38
 
 
39
class MenuSeparatorInfo : public MenuInfo
 
40
{
 
41
public:
 
42
    MenuSeparatorInfo() {}
 
43
};
 
44
 
 
45
class MenuFolderInfo : public MenuInfo
 
46
{
 
47
public:
 
48
    MenuFolderInfo() : dirty(false), hidden(false) { }
 
49
    ~MenuFolderInfo() { qDeleteAll(subFolders); subFolders.clear(); }
 
50
    // Add separator
 
51
    void add(MenuSeparatorInfo *, bool initial=false);
 
52
 
 
53
    // Add sub menu
 
54
    void add(MenuFolderInfo *, bool initial=false);
 
55
 
 
56
    // Remove sub menu (without deleting it)
 
57
    void take(MenuFolderInfo *);
 
58
 
 
59
    // Remove sub menu (without deleting it)
 
60
    // @return true if found
 
61
    bool takeRecursive(MenuFolderInfo *info);
 
62
 
 
63
    // Add entry
 
64
    void add(MenuEntryInfo *, bool initial = false);
 
65
 
 
66
    // Remove entry (without deleting it)
 
67
    void take(MenuEntryInfo *);
 
68
 
 
69
    // Return a unique sub-menu caption inspired by @p caption
 
70
    QString uniqueMenuCaption(const QString &caption);
 
71
 
 
72
    // Return a unique item caption inspired by @p caption but different
 
73
    // from @p exclude
 
74
    QString uniqueItemCaption(const QString &caption, const QString &exclude = QString());
 
75
 
 
76
    // Update full id's for this item and all submenus
 
77
    void updateFullId(const QString &parentId);
 
78
 
 
79
    // Return a list of existing submenu ids
 
80
    QStringList existingMenuIds();
 
81
 
 
82
    void setCaption(const QString &_caption)
 
83
    {
 
84
       if (_caption == caption) return;
 
85
       caption = _caption;
 
86
       setDirty();
 
87
    }
 
88
 
 
89
    void setIcon(const QString &_icon)
 
90
    {
 
91
       if (_icon == icon) return;
 
92
       icon = _icon;
 
93
       setDirty();
 
94
    }
 
95
 
 
96
    void setGenericName(const QString &_description)
 
97
    {
 
98
       if (_description == genericname) return;
 
99
       genericname = _description;
 
100
       setDirty();
 
101
    }
 
102
 
 
103
    void setComment(const QString &_comment)
 
104
    {
 
105
       if (_comment == comment) return;
 
106
       comment = _comment;
 
107
       setDirty();
 
108
    }
 
109
 
 
110
    // Mark menu as dirty
 
111
    void setDirty();
 
112
 
 
113
    // Return whether this menu or any entry or submenu contained in it is dirty.
 
114
    bool hasDirt();
 
115
 
 
116
    // Return whether this menu should be explicitly added to its parent menu
 
117
    bool needInsertion();
 
118
 
 
119
    // Save menu and all its entries and submenus
 
120
    void save(MenuFile *);
 
121
 
 
122
    // Search service by shortcut
 
123
    KService::Ptr findServiceShortcut(const KShortcut&);
 
124
 
 
125
    // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
 
126
    void setInUse(bool inUse);
 
127
 
 
128
public:
 
129
    QString id; // Relative to parent
 
130
    QString fullId; // Name in tree
 
131
    QString caption; // Visible name
 
132
    QString genericname; // Generic description
 
133
    QString comment; // Comment
 
134
    QString directoryFile; // File describing this folder.
 
135
    QString icon; // Icon
 
136
    QList<MenuFolderInfo *> subFolders; // Sub menus in this folder
 
137
    QList<MenuEntryInfo *> entries; // Menu entries in this folder
 
138
    QList<MenuInfo *> initialLayout; // Layout of menu entries according to sycoca
 
139
    bool dirty;
 
140
    bool hidden;
 
141
};
 
142
 
 
143
class MenuEntryInfo : public MenuInfo
 
144
{
 
145
public:
 
146
    explicit MenuEntryInfo(const KService::Ptr &_service, KDesktopFile *_df = 0)
 
147
     : service(_service), m_desktopFile(_df),
 
148
       shortcutLoaded(false), shortcutDirty(false), dirty(_df != 0), hidden(false)
 
149
    {
 
150
       caption = service->name();
 
151
       description = service->genericName();
 
152
       icon = service->icon();
 
153
    }
 
154
    ~MenuEntryInfo();
 
155
 
 
156
    void setCaption(const QString &_caption);
 
157
    void setDescription(const QString &_description);
 
158
    void setIcon(const QString &_icon);
 
159
 
 
160
    QString menuId() const { return service->menuId(); }
 
161
 
 
162
    QString file() const { return service->entryPath(); }
 
163
 
 
164
    KShortcut shortcut();
 
165
    void setShortcut(const KShortcut &_shortcut);
 
166
    bool isShortcutAvailable(const KShortcut &_shortcut);
 
167
 
 
168
    void setDirty();
 
169
 
 
170
    // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
 
171
    void setInUse(bool inUse);
 
172
 
 
173
    // Return whether this menu should be explicitly added to its parent menu
 
174
    bool needInsertion();
 
175
 
 
176
    void save();
 
177
 
 
178
    KDesktopFile *desktopFile();
 
179
 
 
180
public:
 
181
    QString caption;
 
182
    QString description;
 
183
    QString icon;
 
184
    KService::Ptr service;
 
185
    KDesktopFile *m_desktopFile;
 
186
    KShortcut shortCut;
 
187
    bool shortcutLoaded;
 
188
    bool shortcutDirty;
 
189
    bool dirty;
 
190
    bool hidden;
 
191
};
 
192
 
 
193
#endif