• Skip to content
  • Skip to link menu
KDE 4.2 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/QSet>
00028 #include <QtCore/QStack>
00029 
00030 #include <kservice.h>
00031 
00032 class KBuildServiceFactory;
00033 
00034 class VFolderMenu : public QObject
00035 {
00036   Q_OBJECT
00037 public:
00038   class AppsInfo;
00039   class SubMenu {
00040   public:
00041      SubMenu() : isDeleted(false),apps_info(0) { items.reserve(43); }
00042      ~SubMenu() { qDeleteAll(subMenus); }
00043 
00044   public:
00045      QString name;
00046      QString directoryFile;
00047      QList<SubMenu*> subMenus;
00048      QHash<QString,KService::Ptr> items;
00049      QHash<QString,KService::Ptr> excludeItems; // Needed when merging due to Move.
00050      QDomElement defaultLayoutNode;
00051      QDomElement layoutNode;
00052      bool isDeleted;
00053      QStringList layoutList;
00054      AppsInfo *apps_info;
00055   };
00056 
00057   VFolderMenu(KBuildServiceFactory* serviceFactory);
00058   ~VFolderMenu();
00059 
00069   SubMenu *parseMenu(const QString &file, bool forceLegacyLoad=false);
00070 
00078   QStringList allDirectories();
00079 
00084   void setTrackId(const QString &id);
00085 
00086 Q_SIGNALS:
00094   void newService(const QString &path, KService::Ptr *entry);
00095 
00096 public:
00097   struct MenuItem
00098   {
00099     enum Type { MI_Service, MI_SubMenu, MI_Separator };
00100     Type type;
00101     KService::Ptr service;
00102     SubMenu  *submenu;
00103   };
00104 
00105 public:
00106   QStringList m_allDirectories; // A list of all the directories that we touch
00107 
00108   QStringList m_defaultDataDirs;
00109   QStringList m_defaultAppDirs;
00110   QStringList m_defaultDirectoryDirs;
00111   QStringList m_defaultMergeDirs;
00112   QStringList m_defaultLegacyDirs;
00113 
00114   QStringList m_directoryDirs; // Current set of applicable <DirectoryDir> dirs
00115   QHash<QString, SubMenu*> m_legacyNodes; // Dictionary that stores Menu nodes
00116                                           // associated with legacy tree.
00117 
00118   class DocInfo {
00119   public:
00120      QString baseDir; // Relative base dir of current menu file
00121      QString baseName; // Filename of current menu file without ".menu"
00122      QString path; // Full path of current menu file including ".menu"
00123   };
00124 
00125 
00126   DocInfo m_docInfo; // DocInfo for current doc
00127   QStack<VFolderMenu::DocInfo> m_docInfoStack;
00128 
00129   class AppsInfo {
00130   public:
00131      AppsInfo()
00132      {
00133         dictCategories.reserve(53);
00134         applications.reserve(997);
00135         appRelPaths.reserve(997);
00136      }
00137 
00138      ~AppsInfo()
00139      {
00140      }
00141 
00142      QHash<QString,KService::List> dictCategories; // category -> apps
00143      QHash<QString,KService::Ptr> applications; // rel path -> service
00144      QHash<KService::Ptr,QString> appRelPaths; // service -> rel path
00145   };
00146 
00147   AppsInfo *m_appsInfo; // AppsInfo for current menu
00148   QList<AppsInfo*> m_appsInfoStack; // All applicable AppsInfo for current menu
00149   QList<AppsInfo*> m_appsInfoList; // List of all AppsInfo objects.
00150     QSet<QString /*menuId*/> m_usedAppsDict; // all applications that have been allocated
00151 
00152   QDomDocument m_doc;
00153   SubMenu *m_rootMenu;
00154   SubMenu *m_currentMenu;
00155   bool m_forcedLegacyLoad;
00156   bool m_legacyLoaded;
00157   bool m_track;
00158   QString m_trackId;
00159 
00160 private:
00164   KService::Ptr findApplication(const QString &relPath);
00165 
00169   QList<KService::List*> findCategory(const QString &category);
00170 
00174   void addApplication(const QString &id, KService::Ptr service);
00175 
00179   void buildApplicationIndex(bool unusedOnly);
00180 
00184   void createAppsInfo();
00185 
00189   void loadAppsInfo();
00190 
00194   void unloadAppsInfo();
00195 
00196   QDomDocument loadDoc();
00197   void mergeMenus(QDomElement &docElem, QString &name);
00198   void mergeFile(QDomElement &docElem, const QDomNode &mergeHere);
00199   void loadMenu(const QString &filename);
00200 
00204   void includeItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00205 
00209   void matchItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00210 
00214   void excludeItems(QHash<QString,KService::Ptr>& items1, const QHash<QString,KService::Ptr>& items2);
00215 
00223   SubMenu* takeSubMenu(SubMenu *parentMenu, const QString &menuName);
00224 
00234   void insertSubMenu(VFolderMenu::SubMenu *parentMenu, const QString &menuName, VFolderMenu::SubMenu *newMenu, bool reversePriority=false);
00235 
00241   void mergeMenu(SubMenu *menu1, SubMenu *menu2, bool reversePriority=false);
00242 
00247   void insertService(SubMenu *parentMenu, const QString &name, KService::Ptr newService);
00248 
00253   void registerFile(const QString &file);
00254 
00258   void markUsedApplications(const QHash<QString,KService::Ptr>& items);
00259 
00264   void registerDirectory(const QString &directory);
00265 
00266   void processKDELegacyDirs();
00267   void processLegacyDir(const QString &dir, const QString &relDir, const QString &prefix);
00268   void processMenu(QDomElement &docElem, int pass);
00269   void layoutMenu(VFolderMenu::SubMenu *menu, QStringList defaultLayout);
00270   void processCondition(QDomElement &docElem, QHash<QString,KService::Ptr>& items);
00271 
00272   void initDirs();
00273 
00274   void pushDocInfo(const QString &fileName, const QString &baseDir = QString());
00275   void pushDocInfoParent(const QString &basePath, const QString &baseDir);
00276   void popDocInfo();
00277 
00278   QString absoluteDir(const QString &_dir, const QString &baseDir, bool keepRelativeToCfg=false);
00279   QString locateMenuFile(const QString &fileName);
00280   QString locateDirectoryFile(const QString &fileName);
00281   void loadApplications(const QString&, const QString&);
00282 
00283 private:
00284     KBuildServiceFactory* m_serviceFactory;
00285 };
00286 
00287 #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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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