summaryrefslogtreecommitdiffstats
path: root/konqueror/keditbookmarks/commands.h
blob: 3df5d3acf10c81357405f86263b3458e6e50a8a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// kate: space-indent on; indent-width 3; replace-tabs on;
/* This file is part of the KDE project
   Copyright (C) 2000 David Faure <faure@kde.org>
   Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __commands_h
#define __commands_h

#include <kcommand.h>
#include <kbookmark.h>
#include <tqvaluevector.h>

// Interface adds the affectedBookmarks method
// Any class should on call add those bookmarks which are 
// affected by executing or unexecuting the command
// Or a common parent of the affected bookmarks
// see KBookmarkManager::notifyChange(KBookmarkGroup)
class IKEBCommand
{
public:
   IKEBCommand() {};
   virtual ~IKEBCommand() {};
   virtual TQString affectedBookmarks() const = 0;
   virtual TQString currentAddress() const { return TQString::null; }
};

class KEBMacroCommand : public KMacroCommand, public IKEBCommand
{
public:
   KEBMacroCommand(const TQString &name)
      : KMacroCommand(name) {};
   virtual ~KEBMacroCommand() {};
   virtual TQString affectedBookmarks() const;
};

class DeleteManyCommand : public KEBMacroCommand
{
public:
   DeleteManyCommand(const TQString &name, const TQValueList<TQString>  & addresses);
   virtual ~DeleteManyCommand() {};
   virtual TQString currentAddress() const;
private:
   TQString prevOrParentAddress(TQString addr);
   TQString preOrderNextAddress(TQString addr);
   bool isConsecutive(const TQValueList<TQString> & addresses);
   TQString m_currentAddress;
};

class CreateCommand : public KCommand, public IKEBCommand
{
public:
   // separator
   CreateCommand(const TQString &address)
      : KCommand(), m_to(address),
        m_group(false), m_separator(true), m_originalBookmark(TQDomElement())
   { ; }

   // bookmark
   CreateCommand(const TQString &address,
                 const TQString &text, const TQString &iconPath, 
                 const KURL &url)
      : KCommand(), m_to(address), m_text(text), m_iconPath(iconPath), m_url(url),
        m_group(false), m_separator(false), m_originalBookmark(TQDomElement())
   { ; }

   // folder
   CreateCommand(const TQString &address,
                 const TQString &text, const TQString &iconPath, 
                 bool open)
      : KCommand(), m_to(address), m_text(text), m_iconPath(iconPath),
        m_group(true), m_separator(false), m_open(open), m_originalBookmark(TQDomElement())
   { ; }

   // clone existing bookmark
   CreateCommand(const TQString &address,
                 const KBookmark &original, const TQString &name = TQString::null)
      : KCommand(), m_to(address), m_group(false), m_separator(false),
        m_open(false), m_originalBookmark(original), m_mytext(name)
   { ; }

   TQString finalAddress() const;

   virtual ~CreateCommand() { ; }
   virtual void execute();
   virtual void unexecute();
   virtual TQString name() const;
   virtual TQString affectedBookmarks() const;
   virtual TQString currentAddress() const;
private:
   TQString m_to;
   TQString m_text;
   TQString m_iconPath;
   KURL m_url;
   bool m_group:1;
   bool m_separator:1;
   bool m_open:1;
   KBookmark m_originalBookmark;
   TQString m_mytext;
};

class EditCommand : public KCommand, public IKEBCommand
{
public:

   struct Edition {
      Edition() { ; } // needed for QValueList
      Edition(const TQString &a, const TQString &v) : attr(a), value(v) {}
      TQString attr;
      TQString value;
   };

   // change one attribute
   EditCommand(const TQString &address, Edition edition, const TQString &name = TQString::null) 
      : KCommand(), m_address(address), m_mytext(name)
   {
      m_editions.append(edition);
   }

   // change multiple attributes
   EditCommand(const TQString &address,
               const TQValueList<Edition> &editions, 
               const TQString &name = TQString::null)
      : KCommand(), m_address(address), m_editions(editions), m_mytext(name)
   { ; }

   void modify(const TQString & a, const TQString & v);

   virtual ~EditCommand() { ; }
   virtual void execute();
   virtual void unexecute();
   virtual TQString name() const;
   virtual TQString affectedBookmarks() const;
private:
   TQString m_address;
   TQValueList<Edition> m_editions;
   TQValueList<Edition> m_reverseEditions;
   TQString m_mytext;
};

class NodeEditCommand : public KCommand, public IKEBCommand
{
public:
   NodeEditCommand(const TQString &address, 
                   const TQString &newText, 
                   const TQString &nodeName)
      : KCommand(), m_address(address), m_newText(newText), m_nodename(nodeName)
   { ; }

   void modify(const TQString & newText);

   virtual ~NodeEditCommand() { ; }
   virtual void execute();
   virtual void unexecute();
   virtual TQString affectedBookmarks() const;
   virtual TQString name() const;
   static TQString getNodeText(KBookmark bk, const TQStringList &nodehier);
   static TQString setNodeText(KBookmark bk, const TQStringList &nodehier, 
                              TQString newValue);
private:
   TQString m_address;
   TQString m_newText;
   TQString m_oldText;
   TQString m_nodename;
};

class DeleteCommand : public KCommand, public IKEBCommand
{
public:
   DeleteCommand(const TQString &from, bool contentOnly = false)
      : KCommand(), m_from(from), m_cmd(0L), m_subCmd(0L), m_contentOnly(contentOnly)
   { ; }
   virtual ~DeleteCommand() { delete m_cmd; delete m_subCmd;}
   virtual void execute();
   virtual void unexecute();
   virtual TQString name() const { 
      // NOTE - DeleteCommand needs no name, its always embedded in a macrocommand
      return ""; 
   };
   virtual TQString affectedBookmarks() const;
   static KEBMacroCommand* deleteAll(const KBookmarkGroup &parentGroup);
private:
   TQString m_from;
   KCommand *m_cmd;
   KEBMacroCommand *m_subCmd;
   bool m_contentOnly;
};

class MoveCommand : public KCommand, public IKEBCommand
{
public:
   // "Create it with itemsAlreadyMoved=true since 
   // "KListView moves the item before telling us about it."
   MoveCommand(const TQString &from, const TQString &to, const TQString &name = TQString::null)
      : KCommand(), m_from(from), m_to(to), m_mytext(name)
   { ; }
   TQString finalAddress() const;
   virtual ~MoveCommand() { ; }
   virtual void execute();
   virtual void unexecute();
   virtual TQString name() const;
   virtual TQString affectedBookmarks() const;
private:
   TQString m_from;
   TQString m_to;
   TQString m_mytext;
};

class SortItem;

class SortCommand : public KEBMacroCommand
{
public:
   SortCommand(const TQString &name, const TQString &groupAddress)
      : KEBMacroCommand(name), m_groupAddress(groupAddress) 
   { ; }
   virtual ~SortCommand() 
   { ; }
   virtual void execute();
   virtual void unexecute();
   virtual TQString affectedBookmarks() const;
   // internal
   void moveAfter(const SortItem &moveMe, const SortItem &afterMe);
private:
   TQString m_groupAddress;
};

class KEBListViewItem;

class CmdGen {
public:
   static KEBMacroCommand* setAsToolbar(const KBookmark &bk);
   static KEBMacroCommand* setShownInToolbar(const TQValueList<KBookmark> &bk, bool show);
   static bool shownInToolbar(const KBookmark &bk);
   static KEBMacroCommand* deleteItems(const TQString &commandName, const TQValueVector<KEBListViewItem *> & items);
   static KEBMacroCommand* insertMimeSource(const TQString &cmdName, TQMimeSource *data, const TQString &addr);
   static KEBMacroCommand* itemsMoved(const TQValueVector<KEBListViewItem *> & items, const TQString &newAddress, bool copy);
private:
   CmdGen() { ; }
};

#endif