it launches applications. it's an application launcher.
[kdebase.git] / apps / keditbookmarks / commands.h
blob9c4b2b0032365997af8a907a29f3cc72d415f494
1 // kate: space-indent on; indent-width 3; replace-tabs on;
2 /* This file is part of the KDE project
3 Copyright (C) 2000 David Faure <faure@kde.org>
4 Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) version 3.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>
20 #ifndef __commands_h
21 #define __commands_h
23 #include <k3command.h>
24 #include <kbookmark.h>
25 //Added by qt3to4:
26 #include <QtCore/QMap>
29 // Interface adds the affectedBookmarks method
30 // Any class should on call add those bookmarks which are
31 // affected by executing or unexecuting the command
32 // Or a common parent of the affected bookmarks
33 // see KBookmarkManager::notifyChange(KBookmarkGroup)
34 class IKEBCommand
36 public:
37 IKEBCommand() {}
38 virtual ~IKEBCommand() {}
39 virtual QString affectedBookmarks() const = 0;
42 class KEBMacroCommand : public K3MacroCommand, public IKEBCommand
44 public:
45 KEBMacroCommand(const QString &name)
46 : K3MacroCommand(name) {}
47 virtual ~KEBMacroCommand() {}
48 virtual QString affectedBookmarks() const;
51 class DeleteManyCommand : public KEBMacroCommand
53 public:
54 DeleteManyCommand(const QString &name, const QList<KBookmark> & bookmarks);
55 virtual ~DeleteManyCommand() {}
58 class CreateCommand : public K3Command, public IKEBCommand
60 public:
61 // separator
62 CreateCommand(const QString &address)
63 : K3Command(), m_to(address),
64 m_group(false), m_separator(true), m_originalBookmark(QDomElement())
67 // bookmark
68 CreateCommand(const QString &address,
69 const QString &text, const QString &iconPath,
70 const KUrl &url)
71 : K3Command(), m_to(address), m_text(text), m_iconPath(iconPath), m_url(url),
72 m_group(false), m_separator(false), m_originalBookmark(QDomElement())
75 // folder
76 CreateCommand(const QString &address,
77 const QString &text, const QString &iconPath,
78 bool open)
79 : K3Command(), m_to(address), m_text(text), m_iconPath(iconPath),
80 m_group(true), m_separator(false), m_open(open), m_originalBookmark(QDomElement())
83 // clone existing bookmark
84 CreateCommand(const QString &address,
85 const KBookmark &original, const QString &name = QString())
86 : K3Command(), m_to(address), m_group(false), m_separator(false),
87 m_open(false), m_originalBookmark(original), m_mytext(name)
90 QString finalAddress() const;
92 virtual ~CreateCommand() {}
93 virtual void execute();
94 virtual void unexecute();
95 virtual QString name() const;
96 virtual QString affectedBookmarks() const;
97 private:
98 QString m_to;
99 QString m_text;
100 QString m_iconPath;
101 KUrl m_url;
102 bool m_group:1;
103 bool m_separator:1;
104 bool m_open:1;
105 KBookmark m_originalBookmark;
106 QString m_mytext;
109 class EditCommand : public K3Command, public IKEBCommand
111 public:
112 EditCommand(const QString & address, int col, const QString & newValue);
113 virtual ~EditCommand() {}
114 virtual void execute();
115 virtual void unexecute();
116 virtual QString name() const;
117 virtual QString affectedBookmarks() const { return KBookmark::parentAddress(mAddress); }
118 static QString getNodeText(const KBookmark& bk, const QStringList &nodehier);
119 static QString setNodeText(const KBookmark& bk, const QStringList &nodehier,
120 const QString& newValue);
121 void modify(const QString &newValue);
122 private:
123 QString mAddress;
124 int mCol;
125 QString mNewValue;
126 QString mOldValue;
129 class DeleteCommand : public K3Command, public IKEBCommand
131 public:
132 explicit DeleteCommand(const QString &from, bool contentOnly = false)
133 : K3Command(), m_from(from), m_cmd(0), m_subCmd(0), m_contentOnly(contentOnly)
135 virtual ~DeleteCommand() { delete m_cmd; delete m_subCmd; }
136 virtual void execute();
137 virtual void unexecute();
138 virtual QString name() const {
139 // NOTE - DeleteCommand needs no name, it is always embedded in a macrocommand
140 return QString();
142 virtual QString affectedBookmarks() const;
143 static KEBMacroCommand* deleteAll(const KBookmarkGroup &parentGroup);
144 private:
145 QString m_from;
146 K3Command *m_cmd;
147 KEBMacroCommand *m_subCmd;
148 bool m_contentOnly;
151 class MoveCommand : public K3Command, public IKEBCommand
153 public:
154 MoveCommand(const QString &from, const QString &to, const QString &name = QString())
155 : K3Command(), m_from(from), m_to(to), m_mytext(name), m_cc(0), m_dc(0)
157 QString finalAddress() const;
158 virtual ~MoveCommand() {}
159 virtual void execute();
160 virtual void unexecute();
161 virtual QString name() const;
162 virtual QString affectedBookmarks() const;
163 private:
164 QString m_from;
165 QString m_to;
166 QString m_mytext;
167 CreateCommand * m_cc;
168 DeleteCommand * m_dc;
171 class SortItem;
173 class SortCommand : public KEBMacroCommand
175 public:
176 SortCommand(const QString &name, const QString &groupAddress)
177 : KEBMacroCommand(name), m_groupAddress(groupAddress)
179 virtual ~SortCommand()
181 virtual void execute();
182 virtual void unexecute();
183 virtual QString affectedBookmarks() const;
184 // internal
185 void moveAfter(const SortItem &moveMe, const SortItem &afterMe);
186 private:
187 QString m_groupAddress;
190 class KEBListViewItem;
192 class CmdGen {
193 public:
194 static KEBMacroCommand* setAsToolbar(const KBookmark &bk);
195 static KEBMacroCommand* deleteItems(const QString &commandName, const QMap<KEBListViewItem *, bool> & items);
196 static KEBMacroCommand* insertMimeSource(const QString &cmdName, const QMimeData *data, const QString &addr);
197 static KEBMacroCommand* itemsMoved(const QList<KBookmark> & items, const QString &newAddress, bool copy);
198 private:
199 CmdGen() {}
202 #endif