~ubuntu-branches/ubuntu/precise/krusader/precise

« back to all changes in this revision

Viewing changes to krusader/UserAction/useraction.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// C++ Interface: useraction
3
 
//
4
 
// Description: This manages all useractions
5
 
//
6
 
//
7
 
// Author: Jonas Bähr (C) 2004
8
 
//
9
 
// Copyright: See COPYING file that comes with this distribution
10
 
//
11
 
//
 
1
/*****************************************************************************
 
2
 * Copyright (C) 2004 Jonas Bähr <jonas.baehr@web.de>                        *
 
3
 *                                                                           *
 
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.                                       *
 
8
 *                                                                           *
 
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.                              *
 
13
 *                                                                           *
 
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
 *****************************************************************************/
12
18
 
13
19
#ifndef USERACTION_H
14
20
#define USERACTION_H
15
21
 
16
 
#include <qlist.h>
 
22
#include <QtCore/QList>
 
23
#include <QtCore/QSet>
 
24
#include <QtCore/QString>
17
25
 
18
26
class QDomDocument;
19
27
class QDomElement;
24
32
class KActionMenu;
25
33
 
26
34
/**
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.
 
38
 *
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)
34
 
 * .
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
 
45
 *   (ActionProperty)
38
46
 *
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
 
50
 * saved.
 
51
 * This class reads only the container and passes each action-tag to the new
 
52
 * KrAction, which reads it's data itself.
40
53
 */
41
54
 
42
 
class UserAction {
 
55
class UserAction
 
56
{
43
57
public:
44
58
 
45
 
  typedef QList<KrAction *> KrActionList;
46
 
 
47
 
  enum ReadMode { renameDoublicated, ignoreDoublicated };
48
 
 
49
 
  /**
50
 
   * The constructor reads all useractions, see readAllFiles()
51
 
   */
52
 
  UserAction();
53
 
  ~UserAction();
54
 
  
55
 
  /**
56
 
   * adds an action to the collection.
57
 
   */
58
 
  void addKrAction( KrAction* action ) { _actions.append( action ); };
59
 
  
60
 
  /**
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
64
 
   */
65
 
   const KrActionList &actionList() { return _actions; };
66
 
 
67
 
  /**
68
 
   * @return how many useractions exist
69
 
   */
70
 
  int count() const { return _actions.count(); };
71
 
 
72
 
  /**
73
 
   * removes a KrAction from the internal list but does not delete it.
74
 
   * @param action the KrAction which should be removed
75
 
   */
76
 
  void removeKrAction( KrAction* action );
77
 
  
78
 
  /**
79
 
   * check for each KrAction if it is available for the currend location / file and disables it if not
80
 
   */
81
 
  void setAvailability();
82
 
  /**
83
 
   * same as above but check for a specitic file
84
 
   * @param currentURL Check for this file
85
 
   */
86
 
  void setAvailability(const KUrl& currentURL);
87
 
  
88
 
  /**
89
 
   * Fills a KActionMenu with all available UserActions in the list
90
 
   * @param  popupmenu to populate
91
 
   */
92
 
  void populateMenu(KActionMenu* menu, const KUrl *currentURL);
93
 
 
94
 
   QStringList allCategories();
95
 
   QStringList allNames();
96
 
 
97
 
   /**
98
 
    * reads all predefined useractionfiles. 
99
 
    */
100
 
   void readAllFiles();
101
 
   /**
102
 
    * writes all actions to the local actionfile
103
 
    */
104
 
   bool writeActionFile();
105
 
   /**
106
 
    * Reads UserActions from a xml-file.
107
 
    * @param list If provided, all new actions will also be added to this list
108
 
    */
109
 
   void readFromFile( const QString& filename, ReadMode mode = renameDoublicated, KrActionList* list = 0 );
110
 
   /**
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
114
 
    */
115
 
   void readFromElement( const QDomElement& element, ReadMode mode = renameDoublicated, KrActionList* list = 0 );
116
 
 
117
 
   /**
118
 
    * creates an empty QDomDocument for the UserActions
119
 
    */
120
 
   static QDomDocument createEmptyDoc();
121
 
   /**
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!
127
 
    */
128
 
   static bool writeToFile( const QDomDocument& doc, const QString& filename );
 
59
    typedef QList<KrAction *> KrActionList;
 
60
 
 
61
    enum ReadMode { renameDoublicated, ignoreDoublicated };
 
62
 
 
63
    /**
 
64
     * The constructor reads all useractions, see readAllFiles()
 
65
     */
 
66
    UserAction();
 
67
    ~UserAction();
 
68
 
 
69
    /**
 
70
     * adds an action to the collection.
 
71
     */
 
72
    void addKrAction(KrAction* action) {
 
73
        _actions.append(action);
 
74
    };
 
75
 
 
76
    /**
 
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
 
80
     */
 
81
    const KrActionList &actionList() {
 
82
        return _actions;
 
83
    };
 
84
 
 
85
    /**
 
86
     * @return how many useractions exist
 
87
     */
 
88
    int count() const {
 
89
        return _actions.count();
 
90
    };
 
91
 
 
92
    /**
 
93
     * removes a KrAction from the internal list but does not delete it.
 
94
     * @param action the KrAction which should be removed
 
95
     */
 
96
    void removeKrAction(KrAction* action);
 
97
 
 
98
    /**
 
99
     * check for each KrAction if it is available for the currend location / file and disables it if not
 
100
     */
 
101
    void setAvailability();
 
102
    /**
 
103
     * same as above but check for a specitic file
 
104
     * @param currentURL Check for this file
 
105
     */
 
106
    void setAvailability(const KUrl& currentURL);
 
107
 
 
108
    /**
 
109
     * Fills a KActionMenu with all available UserActions in the list
 
110
     * @param  popupmenu to populate
 
111
     */
 
112
    void populateMenu(KActionMenu* menu, const KUrl *currentURL);
 
113
 
 
114
    QStringList allCategories();
 
115
    QStringList allNames();
 
116
 
 
117
    /**
 
118
     * reads all predefined useractionfiles.
 
119
     */
 
120
    void readAllFiles();
 
121
    /**
 
122
     * writes all actions to the local actionfile
 
123
     */
 
124
    bool writeActionFile();
 
125
    /**
 
126
     * Reads UserActions from a xml-file.
 
127
     * @param list If provided, all new actions will also be added to this list
 
128
     */
 
129
    void readFromFile(const QString& filename, ReadMode mode = renameDoublicated, KrActionList* list = 0);
 
130
    /**
 
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
 
134
     */
 
135
    void readFromElement(const QDomElement& element, ReadMode mode = renameDoublicated, KrActionList* list = 0);
 
136
 
 
137
    /**
 
138
     * creates an empty QDomDocument for the UserActions
 
139
     */
 
140
    static QDomDocument createEmptyDoc();
 
141
    /**
 
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!
 
147
     */
 
148
    static bool writeToFile(const QDomDocument& doc, const QString& filename);
129
149
 
130
150
private:
131
 
  KrActionList _actions;
132
 
  QSet<QString>  _defaultActions;
133
 
  QSet<QString>  _deletedActions;
 
151
    KrActionList _actions;
 
152
    QSet<QString>  _defaultActions;
 
153
    QSet<QString>  _deletedActions;
134
154
};
135
155
 
136
 
 
137
 
#define ACTION_XML                              "krusader/useractions.xml"
138
 
#define ACTION_XML_EXAMPLES     "krusader/useraction_examples.xml"
139
 
 
140
 
#define ACTION_DOCTYPE          "KrusaderUserActions"
 
156
#define ACTION_XML    "krusader/useractions.xml"
 
157
#define ACTION_XML_EXAMPLES "krusader/useraction_examples.xml"
 
158
 
 
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\" "
144
 
 
145
 
 
 
161
#define ACTION_ROOT ACTION_DOCTYPE
 
162
#define ACTION_PROCESSINSTR "version=\"1.0\" encoding=\"UTF-8\" "
146
163
 
147
164
#endif // ifndef USERACTION_H