KDED
vfolder_menu.h
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 #ifndef _VFOLDER_MENU_H_
00021 #define _VFOLDER_MENU_H_
00022
00023 #include <qobject.h>
00024 #include <qdom.h>
00025 #include <qstringlist.h>
00026 #include <qptrdict.h>
00027 #include <qptrlist.h>
00028 #include <qvaluestack.h>
00029
00030 #include <kservice.h>
00031
00032 class VFolderMenu : public QObject
00033 {
00034 Q_OBJECT
00035 public:
00036 class appsInfo;
00037 class SubMenu {
00038 public:
00039 SubMenu() : items(43),isDeleted(false),apps_info(0) { }
00040 ~SubMenu() { subMenus.setAutoDelete(true); }
00041
00042 public:
00043 QString name;
00044 QString directoryFile;
00045 QPtrList<SubMenu> subMenus;
00046 QDict<KService> items;
00047 QDict<KService> excludeItems;
00048 QDomElement defaultLayoutNode;
00049 QDomElement layoutNode;
00050 bool isDeleted;
00051 QStringList layoutList;
00052 appsInfo *apps_info;
00053 };
00054
00055 VFolderMenu();
00056 ~VFolderMenu();
00057
00067 SubMenu *parseMenu(const QString &file, bool forceLegacyLoad=false);
00068
00076 QStringList allDirectories();
00077
00082 void setTrackId(const QString &id);
00083
00084 signals:
00085 void newService(const QString &path, KService **entry);
00086
00087 public:
00088 struct MenuItem
00089 {
00090 enum Type { MI_Service, MI_SubMenu, MI_Separator };
00091 Type type;
00092 union {
00093 KService *service;
00094 SubMenu *submenu;
00095 } data;
00096 };
00097
00098 public:
00099 QStringList m_allDirectories;
00100
00101 QStringList m_defaultDataDirs;
00102 QStringList m_defaultAppDirs;
00103 QStringList m_defaultDirectoryDirs;
00104 QStringList m_defaultMergeDirs;
00105 QStringList m_defaultLegacyDirs;
00106
00107 QStringList m_directoryDirs;
00108 QDict<SubMenu> m_legacyNodes;
00109
00110
00111 class docInfo {
00112 public:
00113 QString baseDir;
00114 QString baseName;
00115 QString path;
00116 };
00117
00118
00119 docInfo m_docInfo;
00120 QValueStack<VFolderMenu::docInfo> m_docInfoStack;
00121
00122 class appsInfo {
00123 public:
00124 appsInfo() : dictCategories(53), applications(997), appRelPaths(997)
00125 {
00126 dictCategories.setAutoDelete(true);
00127 }
00128
00129 QDict<KService::List> dictCategories;
00130 QDict<KService> applications;
00131 QPtrDict<QString> appRelPaths;
00132 };
00133
00134 appsInfo *m_appsInfo;
00135 QPtrList<appsInfo> m_appsInfoStack;
00136 QPtrList<appsInfo> m_appsInfoList;
00137 QDict<KService> m_usedAppsDict;
00138
00139 QDomDocument m_doc;
00140 SubMenu *m_rootMenu;
00141 SubMenu *m_currentMenu;
00142 bool m_forcedLegacyLoad;
00143 bool m_legacyLoaded;
00144 bool m_track;
00145 QString m_trackId;
00146
00147 private:
00151 KService *findApplication(const QString &relPath);
00152
00156 QPtrList<KService::List> findCategory(const QString &category);
00157
00161 void addApplication(const QString &id, KService *service);
00162
00166 void buildApplicationIndex(bool unusedOnly);
00167
00171 void createAppsInfo();
00172
00176 void loadAppsInfo();
00177
00181 void unloadAppsInfo();
00182
00183 QDomDocument loadDoc();
00184 void mergeMenus(QDomElement &docElem, QString &name);
00185 void mergeFile(QDomElement &docElem, const QDomNode &mergeHere);
00186 void loadMenu(const QString &filename);
00187
00191 void includeItems(QDict<KService> *items1, QDict<KService> *items2);
00192
00196 void matchItems(QDict<KService> *items1, QDict<KService> *items2);
00197
00201 void excludeItems(QDict<KService> *items1, QDict<KService> *items2);
00202
00210 SubMenu* takeSubMenu(SubMenu *parentMenu, const QString &menuName);
00211
00221 void insertSubMenu(VFolderMenu::SubMenu *parentMenu, const QString &menuName, VFolderMenu::SubMenu *newMenu, bool reversePriority=false);
00222
00228 void mergeMenu(SubMenu *menu1, SubMenu *menu2, bool reversePriority=false);
00229
00234 void insertService(SubMenu *parentMenu, const QString &name, KService *newService);
00235
00240 void registerFile(const QString &file);
00241
00245 void markUsedApplications(QDict<KService> *items);
00246
00251 void registerDirectory(const QString &directory);
00252
00253 void processKDELegacyDirs();
00254 void processLegacyDir(const QString &dir, const QString &relDir, const QString &prefix);
00255 void processMenu(QDomElement &docElem, int pass);
00256 void layoutMenu(VFolderMenu::SubMenu *menu, QStringList defaultLayout);
00257 void processCondition(QDomElement &docElem, QDict<KService> *items);
00258
00259 void initDirs();
00260
00261 void pushDocInfo(const QString &fileName, const QString &baseDir = QString::null);
00262 void pushDocInfoParent(const QString &basePath, const QString &baseDir);
00263 void popDocInfo();
00264
00265 QString absoluteDir(const QString &_dir, const QString &baseDir, bool keepRelativeToCfg=false);
00266 QString locateMenuFile(const QString &fileName);
00267 QString locateDirectoryFile(const QString &fileName);
00268 void loadApplications(const QString&, const QString&);
00269 };
00270
00271 #endif