vfolder_menu.h
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright (c) 2003 Waldo Bastian <bastian@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 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; // Needed when merging due to Move. 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; // A list of all the directories that we touch 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; // Current set of applicable <DirectoryDir> dirs 00108 QDict<SubMenu> m_legacyNodes; // Dictionary that stores Menu nodes 00109 // associated with legacy tree. 00110 00111 class docInfo { 00112 public: 00113 QString baseDir; // Relative base dir of current menu file 00114 QString baseName; // Filename of current menu file without ".menu" 00115 QString path; // Full path of current menu file including ".menu" 00116 }; 00117 00118 00119 docInfo m_docInfo; // docInfo for current doc 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; // category -> apps 00130 QDict<KService> applications; // rel path -> service 00131 QPtrDict<QString> appRelPaths; // service -> rel path 00132 }; 00133 00134 appsInfo *m_appsInfo; // appsInfo for current menu 00135 QPtrList<appsInfo> m_appsInfoStack; // All applicable appsInfo for current menu 00136 QPtrList<appsInfo> m_appsInfoList; // List of all appsInfo objects. 00137 QDict<KService> m_usedAppsDict; // all applications that have been allocated 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