~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kicker/libkicker/kpanelmenu.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
 
4
          (c) 2001 Michael Goffioul <kdeprint@swing.be>
 
5
 
 
6
Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
of this software and associated documentation files (the "Software"), to deal
 
8
in the Software without restriction, including without limitation the rights
 
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
copies of the Software, and to permit persons to whom the Software is
 
11
furnished to do so, subject to the following conditions:
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
******************************************************************/
 
24
 
 
25
#ifndef __KPANELMENU_H__
 
26
#define __KPANELMENU_H__
 
27
 
 
28
 
 
29
#include <kmenu.h>
 
30
#include <kgenericfactory.h>
 
31
 
 
32
/**
 
33
 * @short Base class to build dynamically loaded menu entries for the K-menu, or the panel.
 
34
 *
 
35
 * This class allows to build menu entries that will be dynamically added either to
 
36
 * the K-menu, or to the panel as a normal button. These dynamic menus are located
 
37
 * in shared libraries that will be loaded at runtime by Kicker (the %KDE panel).
 
38
 *
 
39
 * To build such a menu, you have to inherit this class and implement the pure virtual
 
40
 * functions #initialize() and slotExec(). You also have to provide a factory
 
41
 * object in your library, see KLibFactory. This factory is only used to construct
 
42
 * the menu object.
 
43
 *
 
44
 * Finally, you also have to provide a desktop file describing your dynamic menu. The
 
45
 * relevant entries are: Name, Comment, Icon and X-KDE-Library (which contains the
 
46
 * library name without any extension). This desktop file has to be installed in
 
47
 * $KDEDIR/share/apps/kicker/menuext/.
 
48
 *
 
49
 * @author The kicker maintainers, Michael Goffioul <kdeprint@swing.be>
 
50
 */
 
51
class KDE_EXPORT KPanelMenu : public KMenu
 
52
{
 
53
    Q_OBJECT
 
54
 
 
55
public:
 
56
    /**
 
57
     * Construct a KPanelMenu object. This is the normal constructor to use when
 
58
     * building extrernal menu entries.
 
59
     */
 
60
    KPanelMenu(QWidget *parent);
 
61
    /**
 
62
     * Constructor used internally by Kicker. You don't really want to use it.
 
63
     * @param startDir a directory to associate with this menu
 
64
     * @param parent parent object
 
65
     * @param name name of the object
 
66
     * @see path(), setPath()
 
67
     */
 
68
    KPanelMenu(const QString &startDir, QWidget *parent);
 
69
    /**
 
70
     * Destructor.
 
71
     */
 
72
    virtual ~KPanelMenu();
 
73
 
 
74
    /**
 
75
     * Get the directory path associated with this menu, or QString() if
 
76
     * there's no such associated path.
 
77
     * @return the associated directory path
 
78
     * @see setPath()
 
79
     */
 
80
    const QString& path() const;
 
81
    /**
 
82
     * Set a directory path to be associated with this menu.
 
83
     * @param p the directory path
 
84
     * @see path()
 
85
     */
 
86
    void setPath(const QString &p);
 
87
    /**
 
88
     * Tell if the menu has been initialized, that is it already contains items.
 
89
     * This is useful when you need to know if you have to clear the menu, or to
 
90
     * fill it.
 
91
     * @return the initial state
 
92
     * @see setInitialized(), initialize()
 
93
     */
 
94
    bool initialized() const;
 
95
    /**
 
96
     * Set the initial state. Set it to true when you menu is filled with the items
 
97
     * you want.
 
98
     * @param on the initial state
 
99
     * @see initialized(), initialize()
 
100
     */
 
101
    void setInitialized(bool on);
 
102
 
 
103
    /**
 
104
     * Disable the automatic clearing of the menu. Kicker uses a cache system for
 
105
     * its menus. After a specific configurable delay, the menu will be cleared.
 
106
     * Use this function if you want to disable kicker's cache system, and avoid
 
107
     * the clearing of your menu.
 
108
     */
 
109
    void disableAutoClear();
 
110
 
 
111
public Q_SLOTS:
 
112
    /**
 
113
     * Reinitialize the menu: the menu is first cleared, the initial state is set
 
114
     * to false, and finally #initialize() is called. Use this if you want to
 
115
     * refill your menu immediately.
 
116
     */
 
117
    void reinitialize();
 
118
    /**
 
119
     * Deinitialize the menu: the menu is cleared and the initialized state is set to
 
120
     * false. #initialize() is NOT called. It will be called before the menu is
 
121
     * next shown, however. Use this slot if you want a delayed reinitialization.
 
122
     */
 
123
    void deinitialize();
 
124
 
 
125
protected Q_SLOTS:
 
126
    /**
 
127
     * This slot is called just before the menu is shown. This allows your menu
 
128
     * to update itself if needed. However you should instead re-implement
 
129
     * #initialize to provide this feature. This function is responsible for
 
130
     * the cache system handling, so if you re-implement it, you should call
 
131
     * the base function also. Calls #initialize().
 
132
     * @see disableAutoClear()
 
133
     */
 
134
    virtual void slotAboutToShow();
 
135
    /**
 
136
     * This is slot is called when an item from the menu has been selected. Your
 
137
     * applet is then supposed to perform some action. You must re-implement this
 
138
     * function.
 
139
     * @param id the ID associated with the selected item
 
140
     */
 
141
    virtual void slotExec(int id) = 0;
 
142
    /**
 
143
     * This slots is called to initialize the menu. It is called automatically by
 
144
     * slotAboutToShow(). By re-implementing this functions, you can reconstruct
 
145
     * the menu before it is being shown. At the end of this function, you should
 
146
     * call setInitialize() with true to tell the system that the menu is OK.
 
147
     * You applet must re-implement this function.
 
148
     * @see slotAboutToShow(), initialized(), setInitialized()
 
149
     */
 
150
    virtual void initialize() = 0;
 
151
    /**
 
152
     * Clears the menu, and update the initial state accordingly.
 
153
     * @see initialized()
 
154
     */
 
155
    void slotClear();
 
156
 
 
157
protected:
 
158
    /**
 
159
     * Re-implemented for internal reasons.
 
160
     */
 
161
    virtual void hideEvent(QHideEvent *ev);
 
162
    /**
 
163
     * For internal use only. Used by constructors.
 
164
     */
 
165
    void init(const QString& path = QString());
 
166
 
 
167
private:
 
168
    void internalInitialize();
 
169
    class Private;
 
170
    Private *d;
 
171
};
 
172
 
 
173
#define K_EXPORT_KICKER_MENUEXT( libname, classname )                       \
 
174
    K_EXPORT_COMPONENT_FACTORY(                                             \
 
175
        kickermenu_##libname,                                               \
 
176
        KGenericFactory<classname>("libkickermenu_" #libname) )
 
177
 
 
178
#endif