~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kmenuedit/menuinfo.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

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
//Added by qt3to4:
 
25
#include <Q3PtrList>
 
26
 
 
27
#include <kshortcut.h>
 
28
#include <kservice.h>
 
29
 
 
30
class MenuFile;
 
31
class MenuEntryInfo;
 
32
 
 
33
class MenuInfo
 
34
{
 
35
public:
 
36
    MenuInfo() {}
 
37
    virtual ~MenuInfo() {}
 
38
};
 
39
 
 
40
class MenuSeparatorInfo : public MenuInfo
 
41
{
 
42
public:
 
43
    MenuSeparatorInfo() {}
 
44
};
 
45
 
 
46
class MenuFolderInfo : public MenuInfo
 
47
{
 
48
public:
 
49
    MenuFolderInfo() : dirty(false), hidden(false) { subFolders.setAutoDelete(true); }
 
50
 
 
51
    // Add separator
 
52
    void add(MenuSeparatorInfo *, bool initial=false);
 
53
 
 
54
    // Add sub menu
 
55
    void add(MenuFolderInfo *, bool initial=false);
 
56
 
 
57
    // Remove sub menu (without deleting it)
 
58
    void take(MenuFolderInfo *);
 
59
 
 
60
    // Remove sub menu (without deleting it)
 
61
    // @return true if found
 
62
    bool takeRecursive(MenuFolderInfo *info);
 
63
 
 
64
    // Add entry
 
65
    void add(MenuEntryInfo *, bool initial = false);
 
66
 
 
67
    // Remove entry (without deleting it)
 
68
    void take(MenuEntryInfo *);
 
69
 
 
70
    // Return a unique sub-menu caption inspired by @p caption
 
71
    QString uniqueMenuCaption(const QString &caption);
 
72
 
 
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());
 
76
 
 
77
    // Update full id's for this item and all submenus
 
78
    void updateFullId(const QString &parentId);
 
79
 
 
80
    // Return a list of existing submenu ids
 
81
    QStringList existingMenuIds();
 
82
 
 
83
    void setCaption(const QString &_caption)
 
84
    {
 
85
       if (_caption == caption) return;
 
86
       caption = _caption;
 
87
       setDirty();
 
88
    }
 
89
 
 
90
    void setIcon(const QString &_icon)
 
91
    {
 
92
       if (_icon == icon) return;
 
93
       icon = _icon;
 
94
       setDirty();
 
95
    }
 
96
 
 
97
    void setGenericName(const QString &_description)
 
98
    {
 
99
       if (_description == genericname) return;
 
100
       genericname = _description;
 
101
       setDirty();
 
102
    }
 
103
 
 
104
    void setComment(const QString &_comment)
 
105
    {
 
106
       if (_comment == comment) return;
 
107
       comment = _comment;
 
108
       setDirty();
 
109
    }
 
110
 
 
111
    // Mark menu as dirty
 
112
    void setDirty();
 
113
 
 
114
    // Return whether this menu or any entry or submenu contained in it is dirty.
 
115
    bool hasDirt();
 
116
 
 
117
    // Return whether this menu should be explicitly added to its parent menu
 
118
    bool needInsertion();
 
119
 
 
120
    // Save menu and all its entries and submenus
 
121
    void save(MenuFile *);
 
122
 
 
123
    // Search service by shortcut
 
124
    KService::Ptr findServiceShortcut(const KShortcut&);
 
125
 
 
126
    // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
 
127
    void setInUse(bool inUse);
 
128
 
 
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;
 
142
};
 
143
 
 
144
class MenuEntryInfo : public MenuInfo
 
145
{
 
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)
 
150
    {
 
151
       caption = service->name();
 
152
       description = service->genericName();
 
153
       icon = service->icon();
 
154
    }
 
155
    ~MenuEntryInfo();
 
156
 
 
157
    void setCaption(const QString &_caption);
 
158
    void setDescription(const QString &_description);
 
159
    void setIcon(const QString &_icon);
 
160
 
 
161
    QString menuId() const { return service->menuId(); }
 
162
 
 
163
    QString file() const { return service->entryPath(); }
 
164
 
 
165
    KShortcut shortcut();
 
166
    void setShortcut(const KShortcut &_shortcut);
 
167
    bool isShortcutAvailable(const KShortcut &_shortcut);
 
168
 
 
169
    void setDirty();
 
170
 
 
171
    // Set whether the entry is in active use (as opposed to in the clipboard/deleted)
 
172
    void setInUse(bool inUse);
 
173
 
 
174
    // Return whether this menu should be explicitly added to its parent menu
 
175
    bool needInsertion();
 
176
 
 
177
    void save();
 
178
 
 
179
    KDesktopFile *desktopFile();
 
180
 
 
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;
 
192
};
 
193
 
 
194
#endif