• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDED

kdedmodule.cpp

Go to the documentation of this file.
00001 /*
00002    This file is part of the KDE libraries
00003 
00004    Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
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    // appKey acts as a placeholder
00071    KEntryKey appKey(app, 0);
00072    d->objMap->replace(appKey, 0);
00073 
00074    KEntryKey indexKey(app, key);
00075 
00076    // Prevent deletion in case the same object is inserted again.
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    // Search for placeholder.
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; // All keys for this app have been removed.
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"

KDED

Skip menu "KDED"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal