add more spacing
[personal-kdebase.git] / workspace / kmenuedit / menufile.h
blobe9edbcee09837dbe92c3ae1ec333af825055580b
1 /*
2 * Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __menufile_h__
20 #define __menufile_h__
22 #include <QtXml/qdom.h>
24 //Added by qt3to4:
25 #include <QList>
27 class MenuFile
29 public:
30 MenuFile(const QString &file);
31 ~MenuFile();
33 bool load();
34 bool save();
35 void create();
36 QString error() const { return m_error; } // Returns the last error message
38 void restoreMenuSystem(const QString &);
40 enum ActionType {
41 ADD_ENTRY = 0,
42 REMOVE_ENTRY,
43 ADD_MENU,
44 REMOVE_MENU,
45 MOVE_MENU
48 struct ActionAtom
50 ActionType action;
51 QString arg1;
52 QString arg2;
55 /**
56 * Create action atom and push it on the stack
58 ActionAtom *pushAction(ActionType action, const QString &arg1, const QString &arg2);
60 /**
61 * Pop @p atom from the stack.
62 * @p atom must be last item on the stack
64 void popAction(ActionAtom *atom);
66 /**
67 * Perform the specified action
69 void performAction(const ActionAtom *);
71 /**
72 * Perform all actions currently on the stack, remove them from the stack and
73 * save result
74 * @return whether save was successful
76 bool performAllActions();
78 /**
79 * Returns whether the stack contains any actions
81 bool dirty();
83 void addEntry(const QString &menuName, const QString &menuId);
84 void removeEntry(const QString &menuName, const QString &menuId);
86 void addMenu(const QString &menuName, const QString &menuFile);
87 void moveMenu(const QString &oldMenu, const QString &newMenu);
88 void removeMenu(const QString &menuName);
90 void setLayout(const QString &menuName, const QStringList &layout);
92 /**
93 * Returns a unique menu-name for a new menu under @p menuName
94 * inspired by @p newMenu and not part of @p excludeList
96 QString uniqueMenuName(const QString &menuName, const QString &newMenu, const QStringList &excludeList);
98 protected:
99 /**
100 * Finds menu @p menuName in @p elem.
101 * If @p create is true, the menu is created if it doesn't exist yet.
102 * @return The menu dom-node of @p menuName
104 QDomElement findMenu(QDomElement elem, const QString &menuName, bool create);
106 private:
107 QString m_error;
108 QString m_fileName;
110 QDomDocument m_doc;
111 bool m_bDirty;
113 QList<ActionAtom*> m_actionList;
114 QStringList m_removedEntries;
118 #endif