File indexing completed on 2024-05-12 05:46:29
0001 /* 0002 * Copyright (C) 2003 Waldo Bastian <bastian@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License version 2 as 0006 * published by the Free Software Foundation. 0007 * 0008 * This program is distributed in the hope that it will be useful, 0009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0011 * GNU General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU General Public License 0014 * along with this program; if not, write to the Free Software 0015 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0016 * 0017 */ 0018 0019 #ifndef menufile_h 0020 #define menufile_h 0021 0022 #include <qdom.h> 0023 0024 #include <QList> 0025 #include <QStringList> 0026 0027 class MenuFile 0028 { 0029 public: 0030 static const QString MF_MENU, MF_PUBLIC_ID, MF_SYSTEM_ID, MF_NAME, MF_INCLUDE, MF_EXCLUDE, MF_FILENAME, MF_DELETED, MF_NOTDELETED, MF_MOVE, MF_OLD, MF_NEW, 0031 MF_DIRECTORY, MF_LAYOUT, MF_MENUNAME, MF_SEPARATOR, MF_MERGE; 0032 0033 explicit MenuFile(const QString &file); 0034 ~MenuFile(); 0035 0036 bool load(); 0037 bool save(); 0038 void create(); 0039 QString error() const 0040 { 0041 return m_error; 0042 } // Returns the last error message 0043 0044 void restoreMenuSystem(const QString &); 0045 0046 enum ActionType { 0047 ADD_ENTRY = 0, 0048 REMOVE_ENTRY, 0049 ADD_MENU, 0050 REMOVE_MENU, 0051 MOVE_MENU, 0052 }; 0053 0054 struct ActionAtom { 0055 ActionType action; 0056 QString arg1; 0057 QString arg2; 0058 }; 0059 0060 /** 0061 * Create action atom and push it on the stack 0062 */ 0063 ActionAtom *pushAction(ActionType action, const QString &arg1, const QString &arg2); 0064 0065 /** 0066 * Pop @p atom from the stack. 0067 * @p atom must be last item on the stack 0068 */ 0069 void popAction(ActionAtom *atom); 0070 0071 /** 0072 * Perform the specified action 0073 */ 0074 void performAction(const ActionAtom *); 0075 0076 /** 0077 * Perform all actions currently on the stack, remove them from the stack and 0078 * save result 0079 * @return whether save was successful 0080 */ 0081 bool performAllActions(); 0082 0083 /** 0084 * Returns whether the stack contains any actions 0085 */ 0086 bool dirty() const; 0087 0088 void addEntry(const QString &menuName, const QString &menuId); 0089 void removeEntry(const QString &menuName, const QString &menuId); 0090 0091 void addMenu(const QString &menuName, const QString &menuFile); 0092 void moveMenu(const QString &oldMenu, const QString &newMenu); 0093 void removeMenu(const QString &menuName); 0094 0095 void setLayout(const QString &menuName, const QStringList &layout); 0096 0097 /** 0098 * Returns a unique menu-name for a new menu under @p menuName 0099 * inspired by @p newMenu and not part of @p excludeList 0100 */ 0101 QString uniqueMenuName(const QString &menuName, const QString &newMenu, const QStringList &excludeList); 0102 0103 protected: 0104 /** 0105 * Finds menu @p menuName in @p elem. 0106 * If @p create is true, the menu is created if it doesn't exist yet. 0107 * @return The menu dom-node of @p menuName 0108 */ 0109 QDomElement findMenu(QDomElement elem, const QString &menuName, bool create); 0110 0111 private: 0112 QString m_error; 0113 QString m_fileName; 0114 0115 QDomDocument m_doc; 0116 bool m_bDirty; 0117 0118 QList<ActionAtom *> m_actionList; 0119 QStringList m_removedEntries; 0120 }; 0121 0122 #endif 0123