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.

vfolder_menu.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. This file is part of the KDE libraries
  3. Copyright (c) 2003 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 version 2 as published by the Free Software Foundation.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #ifndef _VFOLDER_MENU_H_
  17. #define _VFOLDER_MENU_H_
  18. #include <tqobject.h>
  19. #include <tqdom.h>
  20. #include <tqstringlist.h>
  21. #include <tqptrdict.h>
  22. #include <tqptrlist.h>
  23. #include <tqvaluestack.h>
  24. #include <kservice.h>
  25. class VFolderMenu : public TQObject
  26. {
  27. Q_OBJECT
  28. public:
  29. class appsInfo;
  30. class SubMenu {
  31. public:
  32. SubMenu() : items(43),isDeleted(false),apps_info(0) { }
  33. ~SubMenu() { subMenus.setAutoDelete(true); }
  34. public:
  35. TQString name;
  36. TQString directoryFile;
  37. TQPtrList<SubMenu> subMenus;
  38. TQDict<KService> items;
  39. TQDict<KService> excludeItems; // Needed when merging due to Move.
  40. TQDomElement defaultLayoutNode;
  41. TQDomElement layoutNode;
  42. bool isDeleted;
  43. TQStringList layoutList;
  44. appsInfo *apps_info;
  45. };
  46. VFolderMenu();
  47. ~VFolderMenu();
  48. /**
  49. * Parses VFolder menu defintion and generates a menu layout.
  50. * The newService signals is used as callback to load
  51. * a specific service description.
  52. *
  53. * @param file Menu file to load
  54. * @param forceLegacyLoad flag indicating whether the KDE "applnk"
  55. * directory should be processed at least once.
  56. */
  57. SubMenu *parseMenu(const TQString &file, bool forceLegacyLoad=false);
  58. /**
  59. * Returns a list of all directories involved in the last call to
  60. * parseMenu(), excluding the KDE Legacy directories.
  61. *
  62. * A change in any of these directories or in any of their child-
  63. * directories can result in changes to the menu.
  64. */
  65. TQStringList allDirectories();
  66. /**
  67. * Debug function to enable tracking of what happens with a specific
  68. * menu item id
  69. */
  70. void setTrackId(const TQString &id);
  71. signals:
  72. void newService(const TQString &path, KService **entry);
  73. public:
  74. struct MenuItem
  75. {
  76. enum Type { MI_Service, MI_SubMenu, MI_Separator };
  77. Type type;
  78. union {
  79. KService *service;
  80. SubMenu *submenu;
  81. } data;
  82. };
  83. public:
  84. TQStringList m_allDirectories; // A list of all the directories that we touch
  85. TQStringList m_defaultDataDirs;
  86. TQStringList m_defaultAppDirs;
  87. TQStringList m_defaultDirectoryDirs;
  88. TQStringList m_defaultMergeDirs;
  89. TQStringList m_defaultLegacyDirs;
  90. TQStringList m_directoryDirs; // Current set of applicable <DirectoryDir> dirs
  91. TQDict<SubMenu> m_legacyNodes; // Dictionary that stores Menu nodes
  92. // associated with legacy tree.
  93. class docInfo {
  94. public:
  95. TQString baseDir; // Relative base dir of current menu file
  96. TQString baseName; // Filename of current menu file without ".menu"
  97. TQString path; // Full path of current menu file including ".menu"
  98. };
  99. docInfo m_docInfo; // docInfo for current doc
  100. TQValueStack<VFolderMenu::docInfo> m_docInfoStack;
  101. class appsInfo {
  102. public:
  103. appsInfo() : dictCategories(53), applications(997), appRelPaths(997)
  104. {
  105. dictCategories.setAutoDelete(true);
  106. }
  107. TQDict<KService::List> dictCategories; // category -> apps
  108. TQDict<KService> applications; // rel path -> service
  109. TQPtrDict<TQString> appRelPaths; // service -> rel path
  110. };
  111. appsInfo *m_appsInfo; // appsInfo for current menu
  112. TQPtrList<appsInfo> m_appsInfoStack; // All applicable appsInfo for current menu
  113. TQPtrList<appsInfo> m_appsInfoList; // List of all appsInfo objects.
  114. TQDict<KService> m_usedAppsDict; // all applications that have been allocated
  115. TQDomDocument m_doc;
  116. SubMenu *m_rootMenu;
  117. SubMenu *m_currentMenu;
  118. bool m_forcedLegacyLoad;
  119. bool m_legacyLoaded;
  120. bool m_track;
  121. TQString m_trackId;
  122. private:
  123. /**
  124. * Lookup application by relative path
  125. */
  126. KService *findApplication(const TQString &relPath);
  127. /**
  128. * Lookup applications by category
  129. */
  130. TQPtrList<KService::List> findCategory(const TQString &category);
  131. /**
  132. * Add new application
  133. */
  134. void addApplication(const TQString &id, KService *service);
  135. /**
  136. * Build application indices
  137. */
  138. void buildApplicationIndex(bool unusedOnly);
  139. /**
  140. * Create a appsInfo frame for current menu
  141. */
  142. void createAppsInfo();
  143. /**
  144. * Load additional appsInfo frame for current menu
  145. */
  146. void loadAppsInfo();
  147. /**
  148. * Unload additional appsInfo frame for current menu
  149. */
  150. void unloadAppsInfo();
  151. TQDomDocument loadDoc();
  152. void mergeMenus(TQDomElement &docElem, TQString &name);
  153. void mergeFile(TQDomElement &docElem, const TQDomNode &mergeHere);
  154. void loadMenu(const TQString &filename);
  155. /**
  156. * Merge the items2 set into the items1 set
  157. */
  158. void includeItems(TQDict<KService> *items1, TQDict<KService> *items2);
  159. /**
  160. * Remove all items from the items1 set that aren't also in the items2 set
  161. */
  162. void matchItems(TQDict<KService> *items1, TQDict<KService> *items2);
  163. /**
  164. * Remove all items in the items2 set from the items1 set
  165. */
  166. void excludeItems(TQDict<KService> *items1, TQDict<KService> *items2);
  167. /**
  168. * Search the parentMenu tree for the menu menuName and takes it
  169. * out.
  170. *
  171. * This function returns a pointer to the menu if it was found
  172. * or 0 if it was not found.
  173. */
  174. SubMenu* takeSubMenu(SubMenu *parentMenu, const TQString &menuName);
  175. /**
  176. * Insert the menu newMenu with name menuName into the parentMenu.
  177. * If such menu already exist the result is merged, if any additional
  178. * submenus are required they are created.
  179. * If reversePriority is false, newMenu has priority over the existing
  180. * menu during merging.
  181. * If reversePriority is true, the existing menu has priority over newMenu
  182. * during merging.
  183. */
  184. void insertSubMenu(VFolderMenu::SubMenu *parentMenu, const TQString &menuName, VFolderMenu::SubMenu *newMenu, bool reversePriority=false);
  185. /**
  186. * Merge menu2 and it's submenus into menu1 and it's submenus
  187. * If reversePriority is false, menu2 has priority over menu1
  188. * If reversePriority is true, menu1 has priority over menu2
  189. */
  190. void mergeMenu(SubMenu *menu1, SubMenu *menu2, bool reversePriority=false);
  191. /**
  192. * Inserts service into the menu using name relative to parentMenu
  193. * Any missing sub-menus are created.
  194. */
  195. void insertService(SubMenu *parentMenu, const TQString &name, KService *newService);
  196. /**
  197. * Register the directory that @p file is in.
  198. * @see allDirectories()
  199. */
  200. void registerFile(const TQString &file);
  201. /**
  202. * Fill m_usedAppsDict with all applications from @p items
  203. */
  204. void markUsedApplications(TQDict<KService> *items);
  205. /**
  206. * Register @p directory
  207. * @see allDirectories()
  208. */
  209. void registerDirectory(const TQString &directory);
  210. void processKDELegacyDirs();
  211. void processLegacyDir(const TQString &dir, const TQString &relDir, const TQString &prefix);
  212. void processMenu(TQDomElement &docElem, int pass);
  213. void layoutMenu(VFolderMenu::SubMenu *menu, TQStringList defaultLayout);
  214. void processCondition(TQDomElement &docElem, TQDict<KService> *items);
  215. void initDirs();
  216. void pushDocInfo(const TQString &fileName, const TQString &baseDir = TQString::null);
  217. void pushDocInfoParent(const TQString &basePath, const TQString &baseDir);
  218. void popDocInfo();
  219. TQString absoluteDir(const TQString &_dir, const TQString &baseDir, bool keepRelativeToCfg=false);
  220. TQString locateMenuFile(const TQString &fileName);
  221. TQString locateDirectoryFile(const TQString &fileName);
  222. void loadApplications(const TQString&, const TQString&);
  223. };
  224. #endif