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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* This file is part of the KDE libraries
  2. * Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
  3. *
  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 version 2 as published by the Free Software Foundation.
  7. *
  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. *
  13. * You should have received a copy of the GNU Library General Public License
  14. * along with this library; see the file COPYING.LIB. If not, write to
  15. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. **/
  18. #include "kbuildservicegroupfactory.h"
  19. #include "tdesycoca.h"
  20. #include "tdesycocadict.h"
  21. #include "kresourcelist.h"
  22. #include <tdeglobal.h>
  23. #include <kstandarddirs.h>
  24. #include <kmessageboxwrapper.h>
  25. #include <kdebug.h>
  26. #include <tdelocale.h>
  27. #include <assert.h>
  28. KBuildServiceGroupFactory::KBuildServiceGroupFactory() :
  29. KServiceGroupFactory()
  30. {
  31. m_resourceList = new KSycocaResourceList();
  32. // m_resourceList->add( "apps", "*.directory" );
  33. }
  34. // return all service types for this factory
  35. // i.e. first arguments to m_resourceList->add() above
  36. TQStringList KBuildServiceGroupFactory::resourceTypes()
  37. {
  38. return TQStringList(); // << "apps";
  39. }
  40. KBuildServiceGroupFactory::~KBuildServiceGroupFactory()
  41. {
  42. delete m_resourceList;
  43. }
  44. KServiceGroup *
  45. KBuildServiceGroupFactory::createEntry( const TQString&, const char * )
  46. {
  47. // Unused
  48. kdWarning("!!!! KBuildServiceGroupFactory::createEntry called!");
  49. return 0;
  50. }
  51. void KBuildServiceGroupFactory::addNewEntryTo( const TQString &menuName, KService *newEntry)
  52. {
  53. KServiceGroup *entry = 0;
  54. KSycocaEntry::Ptr *ptr = m_entryDict->find(menuName);
  55. if (ptr)
  56. entry = dynamic_cast<KServiceGroup *>(ptr->data());
  57. if (!entry)
  58. {
  59. kdWarning(7021) << "KBuildServiceGroupFactory::addNewEntryTo( " << menuName << ", " << newEntry->name() << " ): menu does not exists!" << endl;
  60. return;
  61. }
  62. entry->addEntry( newEntry );
  63. }
  64. KServiceGroup *
  65. KBuildServiceGroupFactory::addNew( const TQString &menuName, const TQString& file, KServiceGroup *entry, bool isDeleted)
  66. {
  67. KSycocaEntry::Ptr *ptr = m_entryDict->find(menuName);
  68. if (ptr)
  69. {
  70. kdWarning(7021) << "KBuildServiceGroupFactory::addNew( " << menuName << ", " << file << " ): menu already exists!" << endl;
  71. return static_cast<KServiceGroup *>(static_cast<KSycocaEntry *>(*ptr));
  72. }
  73. // Create new group entry
  74. if (!entry)
  75. entry = new KServiceGroup(file, menuName);
  76. entry->m_childCount = -1; // Recalculate
  77. addEntry( entry, "apps" ); // "vfolder" ??
  78. if (menuName != "/")
  79. {
  80. // Make sure parent dir exists.
  81. KServiceGroup *parentEntry = 0;
  82. TQString parent = menuName.left(menuName.length()-1);
  83. int i = parent.findRev('/');
  84. if (i > 0) {
  85. parent = parent.left(i+1);
  86. } else {
  87. parent = "/";
  88. }
  89. parentEntry = 0;
  90. ptr = m_entryDict->find(parent);
  91. if (ptr)
  92. parentEntry = dynamic_cast<KServiceGroup *>(ptr->data());
  93. if (!parentEntry)
  94. {
  95. kdWarning(7021) << "KBuildServiceGroupFactory::addNew( " << menuName << ", " << file << " ): parent menu does not exist!" << endl;
  96. }
  97. else
  98. {
  99. if (!isDeleted && !entry->isDeleted())
  100. parentEntry->addEntry( entry );
  101. }
  102. }
  103. return entry;
  104. }
  105. KServiceGroup *
  106. KBuildServiceGroupFactory::addNewChild( const TQString &parent, const char *resource, KSycocaEntry *newEntry)
  107. {
  108. TQString name = "#parent#"+parent;
  109. KServiceGroup *entry = 0;
  110. KSycocaEntry::Ptr *ptr = m_entryDict->find(name);
  111. if (ptr)
  112. entry = dynamic_cast<KServiceGroup *>(ptr->data());
  113. if (!entry)
  114. {
  115. entry = new KServiceGroup(name);
  116. addEntry( entry, resource );
  117. }
  118. if (newEntry)
  119. entry->addEntry( newEntry );
  120. return entry;
  121. }
  122. void
  123. KBuildServiceGroupFactory::addEntry( KSycocaEntry *newEntry, const char *resource)
  124. {
  125. KSycocaFactory::addEntry(newEntry, resource);
  126. KServiceGroup * serviceGroup = (KServiceGroup *) newEntry;
  127. serviceGroup->m_serviceList.clear();
  128. if ( !serviceGroup->baseGroupName().isEmpty() )
  129. {
  130. m_baseGroupDict->add( serviceGroup->baseGroupName(), newEntry );
  131. }
  132. }
  133. void
  134. KBuildServiceGroupFactory::saveHeader(TQDataStream &str)
  135. {
  136. KSycocaFactory::saveHeader(str);
  137. str << (TQ_INT32) m_baseGroupDictOffset;
  138. }
  139. void
  140. KBuildServiceGroupFactory::save(TQDataStream &str)
  141. {
  142. KSycocaFactory::save(str);
  143. m_baseGroupDictOffset = str.device()->at();
  144. m_baseGroupDict->save(str);
  145. int endOfFactoryData = str.device()->at();
  146. // Update header (pass #3)
  147. saveHeader(str);
  148. // Seek to end.
  149. str.device()->at(endOfFactoryData);
  150. }