forked from victorzhao/lxpanel-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappletmanager.cpp
More file actions
133 lines (107 loc) · 4.58 KB
/
appletmanager.cpp
File metadata and controls
133 lines (107 loc) · 4.58 KB
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
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2013 PCMan <email>
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.
*/
#include "appletmanager.h"
#include <QDir>
// built-in applets
#include "appletplugininfo.h"
#include "applets/appmenu/appmenuapplet.h"
#include "applets/clock/clockapplet.h"
#include "applets/showdesktop/showdesktopapplet.h"
#include "applets/launcher/launcherapplet.h"
#include "applets/netstatus/netstatusapplet.h"
#include "applets/blank/blankapplet.h"
#include "applets/pager/pagerapplet.h"
#include "applets/task/taskapplet.h"
#include "applets/systray/systrayapplet.h"
#include "applets/volume/volumeapplet.h"
using namespace Lxpanel;
#define LXPANEL_DECLARE_BUILTIN_APPLET(appletClass, id, name, desc) \
namespace Lxpanel { \
class appletClass##Info: public AppletInfo { \
public: \
appletClass##Info(): \
AppletInfo(id) { \
setName(name); \
setDescription(desc); \
} \
virtual ~appletClass##Info() {} \
virtual Applet* create(QWidget* parent) { \
return new appletClass(this, parent); \
} \
}; \
};
LXPANEL_DECLARE_BUILTIN_APPLET(AppMenuApplet, "appmenu", QObject::tr("Application menu"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(ClockApplet, "clock", QObject::tr("Clock"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(LauncherApplet, "launcher", QObject::tr("Application Launcher"), QObject::tr("Launch applications"))
LXPANEL_DECLARE_BUILTIN_APPLET(ShowDesktopApplet, "showdesktop", QObject::tr("Show desktop"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(NetStatusApplet, "netstatus", QObject::tr("Network status monitor"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(BlankApplet, "blank", QObject::tr("Blank space"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(PagerApplet, "pager", QObject::tr("Pager"), QObject::tr("Switch among different desktops"))
LXPANEL_DECLARE_BUILTIN_APPLET(TaskApplet, "task", QObject::tr("Task list"), QObject::tr("Task buttons"))
LXPANEL_DECLARE_BUILTIN_APPLET(SysTrayApplet, "systray", QObject::tr("System tray (notification area)"), "")
LXPANEL_DECLARE_BUILTIN_APPLET(VolumeApplet, "volume", QObject::tr("Volume controller"), QObject::tr("Adjust volume"))
AppletManager::AppletManager() {
}
AppletManager::~AppletManager() {
}
void AppletManager::init() {
// register built-in applets
AppletInfo* info;
info = new AppMenuAppletInfo();
knownApplets_.insert(info->id(), info);
info = new ClockAppletInfo();
knownApplets_.insert(info->id(), info);
info = new ShowDesktopAppletInfo();
knownApplets_.insert(info->id(), info);
info = new LauncherAppletInfo();
knownApplets_.insert(info->id(), info);
info = new NetStatusAppletInfo();
knownApplets_.insert(info->id(), info);
info = new BlankAppletInfo();
knownApplets_.insert(info->id(), info);
info = new PagerAppletInfo();
knownApplets_.insert(info->id(), info);
info = new TaskAppletInfo();
knownApplets_.insert(info->id(), info);
info = new SysTrayAppletInfo();
knownApplets_.insert(info->id(), info);
info = new VolumeAppletInfo();
knownApplets_.insert(info->id(), info);
// Find dynamically loaded applets
// By default, load the deaktop entry files from /usr/share/lxpanel-qt/applets
QDir dir;
dir.cd(LXPANEL_DATA_DIR "/applets");
qDebug("loading: %s", LXPANEL_DATA_DIR "/applets");
QStringList files = dir.entryList();
Q_FOREACH(QString file, files) {
if(file[0] != '.' && file.endsWith(".desktop")) {
qDebug("find applet: %s", qPrintable(file));
QString id = file.left(file.length() - 8);
QString soPath = LXPANEL_LIB_DIR "/applets/" + id + ".so";
AppletPluginInfo* info = new AppletPluginInfo(id, soPath, dir.absoluteFilePath(file));
knownApplets_.insert(info->id(), info);
}
}
}
Applet* AppletManager::createApplet(QString typeName) {
AppletInfo* appletInfo = knownApplets_.value(typeName, NULL);
if(appletInfo)
return appletInfo->create(NULL);
return NULL;
}
void AppletManager::destroyApplet(Applet* applet) {
delete applet;
}