2
// C++ Interface: useraction
4
// Description: This manages all useractions
7
// Author: Jonas Bähr (C) 2004
9
// Copyright: See COPYING file that comes with this distribution
1
/*****************************************************************************
2
* Copyright (C) 2004 Jonas Bähr <jonas.baehr@web.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This package is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this package; if not, write to the Free Software *
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
17
*****************************************************************************/
13
19
#ifndef USERACTION_H
14
20
#define USERACTION_H
22
#include <QtCore/QList>
23
#include <QtCore/QSet>
24
#include <QtCore/QString>
18
26
class QDomDocument;
27
* Useractions are Krusaders backend for user-defined actions on current/selected files in its panels
28
* and for krusader's internal actions which need some parameter. @n
35
* Useractions are Krusaders backend for user-defined actions on
36
* current/selected files in its panels and for krusader's internal actions
37
* which need some parameter.
29
39
* There are several komponents:
30
40
* - The UserAction class as a Manager
31
41
* - The interface to KDE's action-system (the KrAction)
32
* - The Expander, which parses the commandline for placeholders and calls the internal actions
33
* - A widget to manipulate the UserAction's Properties via GUI (ActionProperty)
35
* The Useractions are stored in XML-files. Currently there are two main files. The first is a global example-file
36
* which is read only (read after the other actionfiles, doublicates are ignored) and a local file where the actions are saved.
37
* This class reads only the container and passes each action-tag to the new KrAction, which reads it's data itself.
42
* - The Expander, which parses the commandline for placeholders and calls
43
* the internal actions
44
* - A widget to manipulate the UserAction's Properties via GUI
39
* @author Jonas Bähr (http://www.jonas-baehr.de)
47
* The Useractions are stored in XML-files. Currently there are two main files.
48
* The first is a global example-file which is read only (read after the other
49
* actionfiles, doublicates are ignored) and a local file where the actions are
51
* This class reads only the container and passes each action-tag to the new
52
* KrAction, which reads it's data itself.
45
typedef QList<KrAction *> KrActionList;
47
enum ReadMode { renameDoublicated, ignoreDoublicated };
50
* The constructor reads all useractions, see readAllFiles()
56
* adds an action to the collection.
58
void addKrAction( KrAction* action ) { _actions.append( action ); };
61
* Use this to access the whole list of registerd KrActions.
62
* currently only used to fill the usermenu with all available actions. This should change...
63
* @return A reference to the internal KrActionList
65
const KrActionList &actionList() { return _actions; };
68
* @return how many useractions exist
70
int count() const { return _actions.count(); };
73
* removes a KrAction from the internal list but does not delete it.
74
* @param action the KrAction which should be removed
76
void removeKrAction( KrAction* action );
79
* check for each KrAction if it is available for the currend location / file and disables it if not
81
void setAvailability();
83
* same as above but check for a specitic file
84
* @param currentURL Check for this file
86
void setAvailability(const KUrl& currentURL);
89
* Fills a KActionMenu with all available UserActions in the list
90
* @param popupmenu to populate
92
void populateMenu(KActionMenu* menu, const KUrl *currentURL);
94
QStringList allCategories();
95
QStringList allNames();
98
* reads all predefined useractionfiles.
102
* writes all actions to the local actionfile
104
bool writeActionFile();
106
* Reads UserActions from a xml-file.
107
* @param list If provided, all new actions will also be added to this list
109
void readFromFile( const QString& filename, ReadMode mode = renameDoublicated, KrActionList* list = 0 );
111
* Reads UserActions from a XML-Element.
112
* @param element a container with action-elements
113
* @param list If provided, all new actions will also be added to this list
115
void readFromElement( const QDomElement& element, ReadMode mode = renameDoublicated, KrActionList* list = 0 );
118
* creates an empty QDomDocument for the UserActions
120
static QDomDocument createEmptyDoc();
122
* Writes a QDomDocument to an UTF-8 encodes text-file
123
* @param doc the XML-Tree
124
* @param filename the filename where to save
125
* @return true on success, false otherwise
126
* @warning any existing file will get overwritten!
128
static bool writeToFile( const QDomDocument& doc, const QString& filename );
59
typedef QList<KrAction *> KrActionList;
61
enum ReadMode { renameDoublicated, ignoreDoublicated };
64
* The constructor reads all useractions, see readAllFiles()
70
* adds an action to the collection.
72
void addKrAction(KrAction* action) {
73
_actions.append(action);
77
* Use this to access the whole list of registerd KrActions.
78
* currently only used to fill the usermenu with all available actions. This should change...
79
* @return A reference to the internal KrActionList
81
const KrActionList &actionList() {
86
* @return how many useractions exist
89
return _actions.count();
93
* removes a KrAction from the internal list but does not delete it.
94
* @param action the KrAction which should be removed
96
void removeKrAction(KrAction* action);
99
* check for each KrAction if it is available for the currend location / file and disables it if not
101
void setAvailability();
103
* same as above but check for a specitic file
104
* @param currentURL Check for this file
106
void setAvailability(const KUrl& currentURL);
109
* Fills a KActionMenu with all available UserActions in the list
110
* @param popupmenu to populate
112
void populateMenu(KActionMenu* menu, const KUrl *currentURL);
114
QStringList allCategories();
115
QStringList allNames();
118
* reads all predefined useractionfiles.
122
* writes all actions to the local actionfile
124
bool writeActionFile();
126
* Reads UserActions from a xml-file.
127
* @param list If provided, all new actions will also be added to this list
129
void readFromFile(const QString& filename, ReadMode mode = renameDoublicated, KrActionList* list = 0);
131
* Reads UserActions from a XML-Element.
132
* @param element a container with action-elements
133
* @param list If provided, all new actions will also be added to this list
135
void readFromElement(const QDomElement& element, ReadMode mode = renameDoublicated, KrActionList* list = 0);
138
* creates an empty QDomDocument for the UserActions
140
static QDomDocument createEmptyDoc();
142
* Writes a QDomDocument to an UTF-8 encodes text-file
143
* @param doc the XML-Tree
144
* @param filename the filename where to save
145
* @return true on success, false otherwise
146
* @warning any existing file will get overwritten!
148
static bool writeToFile(const QDomDocument& doc, const QString& filename);
131
KrActionList _actions;
132
QSet<QString> _defaultActions;
133
QSet<QString> _deletedActions;
151
KrActionList _actions;
152
QSet<QString> _defaultActions;
153
QSet<QString> _deletedActions;
137
#define ACTION_XML "krusader/useractions.xml"
138
#define ACTION_XML_EXAMPLES "krusader/useraction_examples.xml"
140
#define ACTION_DOCTYPE "KrusaderUserActions"
156
#define ACTION_XML "krusader/useractions.xml"
157
#define ACTION_XML_EXAMPLES "krusader/useraction_examples.xml"
159
#define ACTION_DOCTYPE "KrusaderUserActions"
141
160
// in well formed XML the root-element has to have the same name then the doctype:
142
#define ACTION_ROOT ACTION_DOCTYPE
143
#define ACTION_PROCESSINSTR "version=\"1.0\" encoding=\"UTF-8\" "
161
#define ACTION_ROOT ACTION_DOCTYPE
162
#define ACTION_PROCESSINSTR "version=\"1.0\" encoding=\"UTF-8\" "
147
164
#endif // ifndef USERACTION_H