• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDED

vfolder_menu.h

Go to the documentation of this file.
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 KDED_VFOLDER_MENU_H
00021 #define KDED_VFOLDER_MENU_H
00022 
00023 #include <QtCore/QObject>
00024 #include <QtXml/QDomDocument>
00025 #include <QtCore/QStringList>
00026 #include <QtCore/QHash>
00027 #include <QtCore/QStack>
00028 
00029 #include <kservice.h>
00030 
00031 class VFolderMenu : public QObject
00032 {
00033   Q_OBJECT
00034 public:
00035   class appsInfo;
00036   class SubMenu {
00037   public:
00038      SubMenu() : isDeleted(false),apps_info(0) { items.reserve(43); }
00039      ~SubMenu() { qDeleteAll(subMenus); }
00040 
00041   public:
00042      QString name;
00043      QString directoryFile;
00044      QList<SubMenu*> subMenus;
00045      QHash<QString,KService::Ptr> items;
00046      QHash<QString,KService::Ptr> excludeItems; // Needed when merging due to Move.
00047      QDomElement defaultLayoutNode;
00048      QDomElement layoutNode;
00049      bool isDeleted;
00050      QStringList layoutList;
00051      appsInfo *apps_info;
00052   };
00053 
00054   VFolderMenu();
00055   ~VFolderMenu();
00056 
00066   SubMenu *parseMenu(const QString &file, bool forceLegacyLoad=false);
00067 
00075   QStringList allDirectories();
00076 
00081   void setTrackId(const QString &id);
00082 
00083 Q_SIGNALS:
00089   void newService(const QString &path, KService::Ptr *entry);
00090 
00091 public:
00092   struct MenuItem
00093   {
00094     enum Type { MI_Service, MI_SubMenu, MI_Separator };
00095     Type type;
00096     KService::Ptr service;
00097     SubMenu  *submenu;
00098   };
00099 
00100 public:
00101   QStringList m_allDirectories; // A list of all the directories that we touch
00102 
00103   QStringList m_defaultDataDirs;
00104   QStringList m_defaultAppDirs;
00105   QStringList m_defaultDirectoryDirs;
00106   QStringList m_defaultMergeDirs;
00107   QStringList m_defaultLegacyDirs;
00108 
00109   QStringList m_directoryDirs; // Current set of applicable <DirectoryDir> dirs
00110   QHash<QString, SubMenu*> m_legacyNodes; // Dictionary that stores Menu nodes
00111                                 // associated with legacy tree.
00112 
00113   class docInfo {
00114   public:
00115      QString baseDir; // Relative base dir of current menu file
00116      QString baseName; // Filename of current menu file without ".menu"
00117      QString path; // Full path of current menu file including ".menu"
00118   };
00119 
00120 
00121   docInfo m_docInfo; // docInfo for current doc
00122   QStack<VFolderMenu::docInfo> m_docInfoStack;
00123 
00124   class appsInfo {
00125   public:
00126      appsInfo()
00127      {
00128         dictCategories.reserve(53);
00129         applications.reserve(997);
00130         appRelPaths.reserve(997);
00131      }
00132 
00133      ~appsInfo()
00134      {
00135         qDeleteAll(dictCategories);
00136      }
00137 
00138      QHash<QString,KService::List*> dictCategories; // category -> apps
00139      QHash<QString,KService::Ptr> applications; // rel path -> service
00140      QHash<KService::Ptr,QString> appRelPaths; // service -> rel path
00141   };
00142 
00143   appsInfo *m_appsInfo; // appsInfo for current menu
00144   QList<appsInfo*> m_appsInfoStack; // All applicable appsInfo for current menu
00145   QList<appsInfo*> m_appsInfoList; // List of all appsInfo objects.
00146   QHash<QString,KService::Ptr> m_usedAppsDict; // all applications that have been allocated
00147 
00148   QDomDocument m_doc;
00149   SubMenu *m_rootMenu;
00150   SubMenu *m_currentMenu;
00151   bool m_forcedLegacyLoad;
00152   bool m_legacyLoaded;
00153   bool m_track;
00154   QString m_trackId;
00155 
00156 private:
00160   KService::Ptr findApplication(const QString &relPath);
00161 
00165   QList<KService::List*> findCategory(const QString &category);
00166 
00170   void addApplication(const QString &id, KService::Ptr service);
00171 
00175   void buildApplicationIndex(bool unusedOnly);
00176 
00180   void createAppsInfo();
00181 
00185   void loadAppsInfo();
00186 
00190   void unloadAppsInfo();
00191 
00192   QDomDocument loadDoc();
00193   void mergeMenus(QDomElement &docElem, QString &name);
00194   void mergeFile(QDomElement &docElem, const QDomNode &mergeHere);
00195   void loadMenu(const QString &filename);
00196 
00200   void includeItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00201 
00205   void matchItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00206 
00210   void excludeItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00211 
00219   SubMenu* takeSubMenu(SubMenu *parentMenu, const QString &menuName);
00220 
00230   void insertSubMenu(VFolderMenu::SubMenu *parentMenu, const QString &menuName, VFolderMenu::SubMenu *newMenu, bool reversePriority=false);
00231 
00237   void mergeMenu(SubMenu *menu1, SubMenu *menu2, bool reversePriority=false);
00238 
00243   void insertService(SubMenu *parentMenu, const QString &name, KService::Ptr newService);
00244 
00249   void registerFile(const QString &file);
00250 
00254   void markUsedApplications(const QHash<QString,KService::Ptr>& items);
00255 
00260   void registerDirectory(const QString &directory);
00261 
00262   void processKDELegacyDirs();
00263   void processLegacyDir(const QString &dir, const QString &relDir, const QString &prefix);
00264   void processMenu(QDomElement &docElem, int pass);
00265   void layoutMenu(VFolderMenu::SubMenu *menu, QStringList defaultLayout);
00266   void processCondition(QDomElement &docElem, QHash<QString,KService::Ptr>& items);
00267 
00268   void initDirs();
00269 
00270   void pushDocInfo(const QString &fileName, const QString &baseDir = QString());
00271   void pushDocInfoParent(const QString &basePath, const QString &baseDir);
00272   void popDocInfo();
00273 
00274   QString absoluteDir(const QString &_dir, const QString &baseDir, bool keepRelativeToCfg=false);
00275   QString locateMenuFile(const QString &fileName);
00276   QString locateDirectoryFile(const QString &fileName);
00277   void loadApplications(const QString&, const QString&);
00278 };
00279 
00280 #endif

KDED

Skip menu "KDED"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal