TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kdedmodule.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. This file is part of the KDE libraries
  3. Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tqtimer.h>
  18. #include "kded.h"
  19. #include "kdedmodule.h"
  20. #include "tdeconfigdata.h"
  21. typedef TQMap<KEntryKey, TDESharedPtr<TDEShared> > KDEDObjectMap;
  22. class KDEDModulePrivate
  23. {
  24. public:
  25. KDEDObjectMap *objMap;
  26. int timeout;
  27. TQTimer timer;
  28. };
  29. KDEDModule::KDEDModule(const TQCString &name) : TQObject(), DCOPObject(name)
  30. {
  31. d = new KDEDModulePrivate;
  32. d->objMap = 0;
  33. d->timeout = 0;
  34. connect(&(d->timer), TQT_SIGNAL(timeout()), this, TQT_SLOT(idle()));
  35. }
  36. KDEDModule::~KDEDModule()
  37. {
  38. emit moduleDeleted(this);
  39. delete d; d = 0;
  40. }
  41. void KDEDModule::setIdleTimeout(int secs)
  42. {
  43. d->timeout = secs*1000;
  44. }
  45. void KDEDModule::resetIdle()
  46. {
  47. d->timer.stop();
  48. if (!d->objMap || d->objMap->isEmpty())
  49. d->timer.start(d->timeout, true);
  50. }
  51. void KDEDModule::insert(const TQCString &app, const TQCString &key, TDEShared *obj)
  52. {
  53. if (!d->objMap)
  54. d->objMap = new KDEDObjectMap;
  55. // appKey acts as a placeholder
  56. KEntryKey appKey(app, 0);
  57. d->objMap->replace(appKey, 0);
  58. KEntryKey indexKey(app, key);
  59. // Prevent deletion in case the same object is inserted again.
  60. TDESharedPtr<TDEShared> _obj = obj;
  61. d->objMap->replace(indexKey, _obj);
  62. resetIdle();
  63. }
  64. TDEShared * KDEDModule::find(const TQCString &app, const TQCString &key)
  65. {
  66. if (!d->objMap)
  67. return 0;
  68. KEntryKey indexKey(app, key);
  69. KDEDObjectMap::Iterator it = d->objMap->find(indexKey);
  70. if (it == d->objMap->end())
  71. return 0;
  72. return it.data().data();
  73. }
  74. void KDEDModule::remove(const TQCString &app, const TQCString &key)
  75. {
  76. if (!d->objMap)
  77. return;
  78. KEntryKey indexKey(app, key);
  79. d->objMap->remove(indexKey);
  80. resetIdle();
  81. }
  82. void KDEDModule::removeAll(const TQCString &app)
  83. {
  84. if (!d->objMap)
  85. return;
  86. KEntryKey indexKey(app, 0);
  87. // Search for placeholder.
  88. KDEDObjectMap::Iterator it = d->objMap->find(indexKey);
  89. while (it != d->objMap->end())
  90. {
  91. KDEDObjectMap::Iterator it2 = it++;
  92. if (it2.key().mGroup != app)
  93. break; // All keys for this app have been removed.
  94. d->objMap->remove(it2);
  95. }
  96. resetIdle();
  97. }
  98. bool KDEDModule::isWindowRegistered(long windowId)
  99. {
  100. return Kded::self()->isWindowRegistered(windowId);
  101. }
  102. #include "kdedmodule.moc"