KDED
kdedmodule.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qtimer.h>
00024
00025 #include "kded.h"
00026 #include "kdedmodule.h"
00027 #include "kconfigdata.h"
00028
00029 typedef QMap<KEntryKey, KSharedPtr<KShared> > KDEDObjectMap;
00030
00031 class KDEDModulePrivate
00032 {
00033 public:
00034 KDEDObjectMap *objMap;
00035 int timeout;
00036 QTimer timer;
00037 };
00038
00039 KDEDModule::KDEDModule(const QCString &name) : QObject(), DCOPObject(name)
00040 {
00041 d = new KDEDModulePrivate;
00042 d->objMap = 0;
00043 d->timeout = 0;
00044 connect(&(d->timer), SIGNAL(timeout()), this, SLOT(idle()));
00045 }
00046
00047 KDEDModule::~KDEDModule()
00048 {
00049 emit moduleDeleted(this);
00050 delete d; d = 0;
00051 }
00052
00053 void KDEDModule::setIdleTimeout(int secs)
00054 {
00055 d->timeout = secs*1000;
00056 }
00057
00058 void KDEDModule::resetIdle()
00059 {
00060 d->timer.stop();
00061 if (!d->objMap || d->objMap->isEmpty())
00062 d->timer.start(d->timeout, true);
00063 }
00064
00065 void KDEDModule::insert(const QCString &app, const QCString &key, KShared *obj)
00066 {
00067 if (!d->objMap)
00068 d->objMap = new KDEDObjectMap;
00069
00070
00071 KEntryKey appKey(app, 0);
00072 d->objMap->replace(appKey, 0);
00073
00074 KEntryKey indexKey(app, key);
00075
00076
00077 KSharedPtr<KShared> _obj = obj;
00078
00079 d->objMap->replace(indexKey, _obj);
00080 resetIdle();
00081 }
00082
00083 KShared * KDEDModule::find(const QCString &app, const QCString &key)
00084 {
00085 if (!d->objMap)
00086 return 0;
00087 KEntryKey indexKey(app, key);
00088
00089 KDEDObjectMap::Iterator it = d->objMap->find(indexKey);
00090 if (it == d->objMap->end())
00091 return 0;
00092
00093 return it.data().data();
00094 }
00095
00096 void KDEDModule::remove(const QCString &app, const QCString &key)
00097 {
00098 if (!d->objMap)
00099 return;
00100 KEntryKey indexKey(app, key);
00101
00102 d->objMap->remove(indexKey);
00103 resetIdle();
00104 }
00105
00106 void KDEDModule::removeAll(const QCString &app)
00107 {
00108 if (!d->objMap)
00109 return;
00110
00111 KEntryKey indexKey(app, 0);
00112
00113
00114 KDEDObjectMap::Iterator it = d->objMap->find(indexKey);
00115 while (it != d->objMap->end())
00116 {
00117 KDEDObjectMap::Iterator it2 = it++;
00118 if (it2.key().mGroup != app)
00119 break;
00120 d->objMap->remove(it2);
00121 }
00122 resetIdle();
00123 }
00124
00125 bool KDEDModule::isWindowRegistered(long windowId)
00126 {
00127 return Kded::self()->isWindowRegistered(windowId);
00128 }
00129 #include "kdedmodule.moc"