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/>
23 #include <k3command.h>
24 #include <kbookmark.h>
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)
38 virtual ~IKEBCommand() {}
39 virtual QString
affectedBookmarks() const = 0;
42 class KEBMacroCommand
: public K3MacroCommand
, public IKEBCommand
45 KEBMacroCommand(const QString
&name
)
46 : K3MacroCommand(name
) {}
47 virtual ~KEBMacroCommand() {}
48 virtual QString
affectedBookmarks() const;
51 class DeleteManyCommand
: public KEBMacroCommand
54 DeleteManyCommand(const QString
&name
, const QList
<KBookmark
> & bookmarks
);
55 virtual ~DeleteManyCommand() {}
58 class CreateCommand
: public K3Command
, public IKEBCommand
62 CreateCommand(const QString
&address
)
63 : K3Command(), m_to(address
),
64 m_group(false), m_separator(true), m_originalBookmark(QDomElement())
68 CreateCommand(const QString
&address
,
69 const QString
&text
, const QString
&iconPath
,
71 : K3Command(), m_to(address
), m_text(text
), m_iconPath(iconPath
), m_url(url
),
72 m_group(false), m_separator(false), m_originalBookmark(QDomElement())
76 CreateCommand(const QString
&address
,
77 const QString
&text
, const QString
&iconPath
,
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;
105 KBookmark m_originalBookmark
;
109 class EditCommand
: public K3Command
, public IKEBCommand
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
);
129 class DeleteCommand
: public K3Command
, public IKEBCommand
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
142 virtual QString
affectedBookmarks() const;
143 static KEBMacroCommand
* deleteAll(const KBookmarkGroup
&parentGroup
);
147 KEBMacroCommand
*m_subCmd
;
151 class MoveCommand
: public K3Command
, public IKEBCommand
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;
167 CreateCommand
* m_cc
;
168 DeleteCommand
* m_dc
;
173 class SortCommand
: public KEBMacroCommand
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;
185 void moveAfter(const SortItem
&moveMe
, const SortItem
&afterMe
);
187 QString m_groupAddress
;
190 class KEBListViewItem
;
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
);