2000-03-24 22:23:02 +00:00
|
|
|
/*****************************************************************
|
|
|
|
kwin - the KDE window manager
|
2000-07-29 01:55:29 +00:00
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
Copyright (C) 1999, 2000 Daniel M. Duley <mosfet@kde.org>
|
|
|
|
******************************************************************/
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kstddirs.h>
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#include <ksimpleconfig.h>
|
|
|
|
#include <klocale.h>
|
2000-04-20 17:37:33 +00:00
|
|
|
|
|
|
|
// X11/Qt conflict
|
|
|
|
#undef Unsorted
|
|
|
|
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <qdir.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
|
|
|
|
#include "plugins.h"
|
2000-08-14 18:49:44 +00:00
|
|
|
#include "kdedefault.h"
|
1999-12-24 01:36:47 +00:00
|
|
|
|
|
|
|
PluginMenu::PluginMenu(PluginMgr *manager, QWidget *parent, const char *name)
|
|
|
|
: QPopupMenu(parent, name)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
|
|
|
|
connect(this, SIGNAL(activated(int)), SLOT(slotActivated(int)));
|
|
|
|
mgr = manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginMenu::slotAboutToShow()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
fileList.clear();
|
2000-07-16 10:20:29 +00:00
|
|
|
insertItem(i18n("KDE 2"), 0);
|
1999-12-24 01:36:47 +00:00
|
|
|
idCount = 1;
|
2000-09-11 05:30:24 +00:00
|
|
|
idCurrent = 0;
|
2000-03-24 22:23:02 +00:00
|
|
|
|
1999-12-24 01:36:47 +00:00
|
|
|
QDir dir;
|
|
|
|
dir.setFilter(QDir::Files);
|
|
|
|
const QFileInfoList *list;
|
|
|
|
int count = KGlobal::dirs()->findDirs("data", "kwin").count();
|
|
|
|
if(count){
|
|
|
|
dir.setPath(KGlobal::dirs()->findDirs("data", "kwin")
|
|
|
|
[count > 1 ? 1 : 0]);
|
|
|
|
if(dir.exists()){
|
|
|
|
list = dir.entryInfoList();
|
|
|
|
if(list){
|
|
|
|
QFileInfoListIterator it(*list);
|
|
|
|
QFileInfo *fi;
|
|
|
|
for(; (fi = it.current()) != NULL; ++it){
|
|
|
|
if(KDesktopFile::isDesktopFile(fi->absFilePath()))
|
|
|
|
parseDesktop(fi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(count > 1){
|
|
|
|
dir.setPath(KGlobal::dirs()->findDirs("data", "kwin")[0]);
|
|
|
|
if(dir.exists()){
|
|
|
|
list = dir.entryInfoList();
|
|
|
|
if(list){
|
|
|
|
QFileInfoListIterator it(*list);
|
|
|
|
QFileInfo *fi;
|
|
|
|
for(; (fi = it.current()) != NULL; ++it){
|
|
|
|
if(KDesktopFile::isDesktopFile(fi->absFilePath()))
|
|
|
|
parseDesktop(fi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-11 05:30:24 +00:00
|
|
|
setItemChecked(idCurrent, true);
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginMenu::parseDesktop(QFileInfo *fi)
|
|
|
|
{
|
|
|
|
QString tmpStr;
|
|
|
|
KSimpleConfig config(fi->absFilePath(), true);
|
|
|
|
config.setDesktopGroup();
|
|
|
|
tmpStr = config.readEntry("X-KDE-Library", "");
|
|
|
|
if(tmpStr.isEmpty()){
|
2000-07-29 01:55:29 +00:00
|
|
|
qWarning("KWin: Invalid plugin: %s", fi->absFilePath().latin1());
|
1999-12-24 01:36:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fileList.append(tmpStr);
|
2000-09-11 05:30:24 +00:00
|
|
|
if (tmpStr == mgr->currentPlugin())
|
|
|
|
idCurrent = idCount;
|
1999-12-24 01:36:47 +00:00
|
|
|
tmpStr = config.readEntry("Name", "");
|
|
|
|
if(tmpStr.isEmpty())
|
|
|
|
tmpStr = fi->baseName();
|
|
|
|
insertItem(tmpStr, idCount);
|
|
|
|
++idCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginMenu::slotActivated(int id)
|
|
|
|
{
|
|
|
|
if(id == 0)
|
|
|
|
mgr->loadPlugin(QString::null);
|
|
|
|
else
|
|
|
|
mgr->loadPlugin(fileList[id-1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginMgr::PluginMgr()
|
|
|
|
: QObject()
|
|
|
|
{
|
|
|
|
alloc_ptr = NULL;
|
|
|
|
handle = 0;
|
|
|
|
|
|
|
|
KConfig *config = KGlobal::config();
|
|
|
|
config->setGroup("Style");
|
2000-07-16 10:20:29 +00:00
|
|
|
pluginStr = config->readEntry("PluginLib", "default");
|
1999-12-24 01:36:47 +00:00
|
|
|
if(pluginStr.isEmpty() || pluginStr == "standard")
|
2000-09-11 05:30:24 +00:00
|
|
|
pluginStr = "standard";
|
1999-12-24 01:36:47 +00:00
|
|
|
else
|
|
|
|
loadPlugin(pluginStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginMgr::~PluginMgr()
|
|
|
|
{
|
|
|
|
if(handle)
|
|
|
|
lt_dlclose(handle);
|
|
|
|
}
|
|
|
|
|
2000-09-25 15:30:51 +00:00
|
|
|
Client* PluginMgr::allocateClient(Workspace *ws, WId w, bool tool)
|
1999-12-24 01:36:47 +00:00
|
|
|
{
|
|
|
|
if(alloc_ptr)
|
2000-09-25 15:30:51 +00:00
|
|
|
return(alloc_ptr(ws, w, tool));
|
1999-12-24 01:36:47 +00:00
|
|
|
else
|
2000-08-14 18:49:44 +00:00
|
|
|
return(new KDEClient(ws, w));
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PluginMgr::loadPlugin(QString nameStr)
|
|
|
|
{
|
|
|
|
static bool dlregistered = false;
|
|
|
|
static lt_dlhandle oldHandle = 0;
|
|
|
|
|
2000-09-11 05:30:24 +00:00
|
|
|
pluginStr = nameStr;
|
2000-09-25 15:30:51 +00:00
|
|
|
|
1999-12-24 01:36:47 +00:00
|
|
|
oldHandle = handle;
|
|
|
|
|
2000-07-16 10:20:29 +00:00
|
|
|
// Rikkus: temporary change in semantics.
|
|
|
|
|
|
|
|
if (!nameStr)
|
|
|
|
nameStr = "default";
|
|
|
|
|
|
|
|
if(!dlregistered){
|
|
|
|
dlregistered = true;
|
|
|
|
lt_dlinit();
|
|
|
|
}
|
|
|
|
nameStr += ".la";
|
|
|
|
nameStr = KGlobal::dirs()->findResource("lib", nameStr);
|
|
|
|
|
|
|
|
if(!nameStr){
|
2000-07-29 01:55:29 +00:00
|
|
|
qWarning("KWin: cannot find client plugin.");
|
1999-12-24 01:36:47 +00:00
|
|
|
handle = 0;
|
|
|
|
alloc_ptr = NULL;
|
2000-09-11 05:30:24 +00:00
|
|
|
pluginStr = "standard";
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-07-16 10:20:29 +00:00
|
|
|
handle = lt_dlopen(nameStr.latin1());
|
|
|
|
if(!handle){
|
2000-07-29 01:55:29 +00:00
|
|
|
qWarning("KWin: cannot load client plugin %s.", nameStr.latin1());
|
1999-12-24 01:36:47 +00:00
|
|
|
handle = 0;
|
|
|
|
alloc_ptr = NULL;
|
2000-09-11 05:30:24 +00:00
|
|
|
pluginStr = "standard";
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
else{
|
2000-07-16 10:20:29 +00:00
|
|
|
lt_ptr_t alloc_func = lt_dlsym(handle, "allocate");
|
|
|
|
if(alloc_func)
|
2000-09-25 15:30:51 +00:00
|
|
|
alloc_ptr = (Client* (*)(Workspace *ws, WId w, int tool))alloc_func;
|
2000-07-16 10:20:29 +00:00
|
|
|
else{
|
2000-07-29 01:55:29 +00:00
|
|
|
qWarning("KWin: %s is not a KWin plugin.", nameStr.latin1());
|
2000-07-16 10:20:29 +00:00
|
|
|
lt_dlclose(handle);
|
1999-12-24 01:36:47 +00:00
|
|
|
handle = 0;
|
|
|
|
alloc_ptr = NULL;
|
2000-09-11 05:30:24 +00:00
|
|
|
pluginStr = "standard";
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-11 05:30:24 +00:00
|
|
|
KConfig *config = KGlobal::config();
|
|
|
|
config->setGroup("Style");
|
|
|
|
config->writeEntry("PluginLib", pluginStr);
|
1999-12-24 01:36:47 +00:00
|
|
|
config->sync();
|
|
|
|
emit resetAllClients();
|
|
|
|
if(oldHandle)
|
|
|
|
lt_dlclose(oldHandle);
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:20:21 +00:00
|
|
|
#include "plugins.moc"
|
1999-12-24 01:36:47 +00:00
|
|
|
|