4
#include <ksimpleconfig.h>
6
#include <knotifyclient.h>
9
#include <pluginloader.h>
13
bool operator ==(const NoatunLibraryInfo &a, const NoatunLibraryInfo &b)
15
// Feels like cheating, doesn't it?
16
return a.specfile == b.specfile;
19
LibraryLoader::LibraryLoader() : mPlaylist(0)
23
LibraryLoader::~LibraryLoader()
25
QValueList<NoatunLibraryInfo> l;
28
for(QValueList<NoatunLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
30
if((*i).type != "userinterface" && (*i).type != "playlist" && (*i).type != "systray")
32
removeNow((*i).specfile);
37
for(QValueList<NoatunLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
39
if((*i).type == "userinterface")
41
removeNow((*i).specfile);
46
for(QValueList<NoatunLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
48
removeNow((*i).specfile);
52
QValueList<NoatunLibraryInfo> LibraryLoader::available() const
54
QValueList<NoatunLibraryInfo> items;
55
QStringList files=KGlobal::dirs()->findAllResources("appdata", "*.plugin", false, true);
56
for (QStringList::Iterator i=files.begin(); i!=files.end(); ++i)
57
items.append(getInfo(*i));
62
QList<Plugin> LibraryLoader::plugins() const
65
for (QDictIterator<LibraryLoader::PluginLibrary> i(mLibHash); i.current(); ++i)
66
list.append(i.current()->plugin);
70
bool LibraryLoader::loadAll(void)
72
KConfig *config=KGlobal::config();
74
QStringList modules = config->readListEntry("Modules");
75
return loadAll(modules);
78
bool LibraryLoader::loadAll(const QStringList &modules)
80
// Session management...
81
for(QStringList::ConstIterator i=modules.begin(); i!=modules.end(); ++i)
83
NoatunLibraryInfo info=getInfo(*i);
84
if (!info.type.contains("sm"))
90
// load all the playlists in the first
91
for(QStringList::ConstIterator i=modules.begin(); i!=modules.end(); ++i)
93
NoatunLibraryInfo info=getInfo(*i);
94
if (!info.type.contains("playlist"))
100
// load all the user interfaces now
101
for(QStringList::ConstIterator i=modules.begin(); i!=modules.end(); ++i)
103
NoatunLibraryInfo info=getInfo(*i);
104
if (!info.type.contains("userinterface"))
109
for(QStringList::ConstIterator i=modules.begin(); i!=modules.end(); ++i)
111
NoatunLibraryInfo info=getInfo(*i);
112
if((!info.type.contains("playlist"))
113
&& (!info.type.contains("userinterface"))
114
&& (!info.type.contains("sm")))
122
NoatunLibraryInfo LibraryLoader::getInfo(const QString &spec) const
124
NoatunLibraryInfo info;
125
QString specPath = (spec[0]=='/') ? spec : KGlobal::dirs()->findResource("appdata", spec);
126
if (!QFile::exists(specPath))
128
KSimpleConfig file(specPath);
129
if (spec.find('/')>=0)
130
info.specfile=KURL(spec).fileName();
133
info.filename=file.readEntry("Filename");
134
info.author=file.readEntry("Author");
135
info.site=file.readEntry("Site");
136
info.email=file.readEntry("Email");
137
info.type=file.readEntry("Type");
138
info.name=file.readEntry("Name");
139
info.comment=file.readEntry("Comment");
140
info.require=file.readListEntry("Require");
141
info.license=file.readEntry("License");
145
bool LibraryLoader::isLoaded(const QString &spec) const
147
PluginLibrary *lib=mLibHash[spec];
148
if (!lib) return false;
152
bool LibraryLoader::loadSO(const QString &spec)
156
NoatunLibraryInfo info = getInfo(spec);
157
if (info.specfile != spec)
160
for (QStringList::ConstIterator it = info.require.begin(); it != info.require.end(); ++it)
163
// get the library loader instance
164
KLibLoader *loader = KLibLoader::self();
166
PluginLibrary *listitem=mLibHash[spec];
170
KLibrary *lib = loader->library(QFile::encodeName(info.filename));
173
listitem=new PluginLibrary;
174
listitem->library=lib;
175
mLibHash.insert(spec, listitem);
178
void *create=listitem->library->symbol("create_plugin");
182
Plugin* (*plugInStart)();
183
plugInStart= (Plugin* (*)()) create;
184
listitem->plugin=plugInStart();
186
if (getInfo(spec).type=="playlist")
187
mPlaylist=listitem->plugin->playlist();
188
listitem->plugin->init();
196
void LibraryLoader::add(const QString &spec)
198
PluginLibrary *lib=mLibHash[spec];
200
if (lib->plugin) return;
205
void LibraryLoader::setModules(const QStringList &mods)
207
KConfig *config=KGlobal::config();
209
config->writeEntry("Modules", mods);
210
KGlobal::config()->sync();
213
bool LibraryLoader::remove(const QString &spec)
217
// exit if this is the last UI
218
if (getInfo(spec).type=="userinterface")
220
QValueList<NoatunLibraryInfo> l=loaded();
221
bool isanotherui=false;
222
for (QValueList<NoatunLibraryInfo>::Iterator i=l.begin(); i!=l.end(); ++i)
224
if ((*i).specfile!=spec && (*i).type=="userinterface")
234
bool LibraryLoader::remove(const PluginLibrary *pl)
236
for (QDictIterator<PluginLibrary> i(mLibHash); i.current(); ++i)
239
return remove(i.currentKey());
244
bool LibraryLoader::remove(const Plugin *plugin)
246
for (QDictIterator<PluginLibrary> i(mLibHash); i.current(); ++i)
248
if (i.current()->plugin==plugin)
249
return remove(i.currentKey());
255
Playlist *LibraryLoader::playlist() const
260
QValueList<NoatunLibraryInfo> LibraryLoader::loaded() const
262
QValueList<NoatunLibraryInfo> items;
264
for (QDictIterator<PluginLibrary> i(mLibHash); i.current(); ++i)
265
if (isLoaded(i.currentKey()))
266
items.append(getInfo(i.currentKey()));
271
void LibraryLoader::removeNow(const QString &spec)
273
NoatunLibraryInfo info = getInfo(spec);
274
if (info.specfile == spec)
276
QValueList<NoatunLibraryInfo> l = loaded();
277
for (QValueList<NoatunLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
279
for (QStringList::ConstIterator it = (*i).require.begin(); it != (*i).require.end(); ++it)
281
removeNow((*i).specfile);
285
PluginLibrary *lib=mLibHash[spec];
291
mLibHash.remove(spec);
292
// delete lib->library;