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

KDED

Skip menu "KDED"
  • Main Page
  • Namespace List
  • 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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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