~ubuntu-branches/ubuntu/vivid/krusader/vivid-proposed

« back to all changes in this revision

Viewing changes to krusader/UserAction/kraction.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: kraction
3
 
//
4
 
// Description: 
5
 
//
6
 
//
7
 
// Author: Krusader Krew <http://www.krusader.org>, (C) 2004, 2006
8
 
//
9
 
// Copyright: See COPYING file that comes with this distribution
10
 
//
11
 
//
 
1
/*****************************************************************************
 
2
 * Copyright (C) 2004 Shie Erlich <erlich@users.sourceforge.net>             *
 
3
 * Copyright (C) 2004 Rafi Yanai <yanai@users.sourceforge.net>               *
 
4
 * Copyright (C) 2006 Jonas Bähr <jonas.baehr@web.de>                        *
 
5
 *                                                                           *
 
6
 * This program is free software; you can redistribute it and/or modify      *
 
7
 * it under the terms of the GNU General Public License as published by      *
 
8
 * the Free Software Foundation; either version 2 of the License, or         *
 
9
 * (at your option) any later version.                                       *
 
10
 *                                                                           *
 
11
 * This package 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.                              *
 
15
 *                                                                           *
 
16
 * You should have received a copy of the GNU General Public License         *
 
17
 * along with this package; if not, write to the Free Software               *
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA *
 
19
 *****************************************************************************/
12
20
 
13
21
#ifndef KRACTION_H
14
22
#define KRACTION_H
15
23
 
16
 
#include <kaction.h>
17
 
#include <kprocess.h>
18
 
#include <kdialog.h>
19
 
#include <qbytearray.h>
 
24
#include <QtCore/QByteArray>
 
25
 
 
26
#include <KAction>
 
27
#include <KProcess>
 
28
#include <KDialog>
 
29
#include <KTextEdit>
 
30
 
20
31
#include "kractionbase.h"
21
32
 
22
33
class UserActionProperties;
23
 
class QTextEdit;
 
34
class QDomDocument;
 
35
class QDomElement;
24
36
class KActionCollection;
25
 
class QDomElement;
26
 
class QDomDocument;
27
37
 
28
38
/**
29
 
 * This subclass of KAction extends it with an individual executor and a struct UserActionProperties. It is used to integrate useractions into KDE's KAction-System
30
 
 * @author Jonas Bähr (http://www.jonas-baehr.de)
 
39
 * This subclass of KAction extends it with an individual executor and
 
40
 * a struct UserActionProperties.
 
41
 * It is used to integrate useractions into KDE's KAction-System
31
42
 */
32
 
class KrAction: public KAction, public KrActionBase {
33
 
   Q_OBJECT
34
 
   public:
35
 
      KrAction( KActionCollection *parent, QString name = QString::null );
36
 
      ~KrAction();
37
 
 
38
 
      /**
39
 
       * This chekcs if the KrAction is for a specific file / location available
40
 
       * @param currentURL Check for this file
41
 
       * @return true if the KrAction if available
42
 
       */
43
 
      bool isAvailable( const KUrl& currentURL );
44
 
 
45
 
      const QString& iconName() const { return _iconName; } // TODO: added for kde4 porting (functionality is missing)
46
 
      void setIconName( const QString& name ) { _iconName = name; }
47
 
 
48
 
      bool xmlRead( const QDomElement& element );
49
 
      QDomElement xmlDump( QDomDocument& doc ) const;
50
 
 
51
 
      void setName( const char* ) { /* empty reimplementation to prevent a name-change */ };
52
 
      const QString & getName()   { return _name; }
53
 
 
54
 
      QString category() const { return _category; };
55
 
      void setCategory( const QString& category ) { _category = category; };
56
 
 
57
 
      QString command() const { return _command; };
58
 
      void setCommand( const QString& command ) { _command = command; };
59
 
 
60
 
      QString user() const { return _user; };
61
 
      void setUser( const QString& user ) { _user = user; };
62
 
 
63
 
      QString startpath() const { return _startpath; };
64
 
      void setStartpath( const QString& startpath ) { _startpath = startpath; };
65
 
 
66
 
      ExecType execType() const { return _execType; };
67
 
      void setExecType( ExecType execType ) { _execType = execType; };
68
 
 
69
 
      bool acceptURLs() const { return _acceptURLs; };
70
 
      void setAcceptURLs(const bool& acceptURLs) { _acceptURLs = acceptURLs; };
71
 
 
72
 
      bool confirmExecution() const { return _confirmExecution; };
73
 
      void setConfirmExecution(const bool& confirmExecution) { _confirmExecution = confirmExecution; };
74
 
 
75
 
      QStringList showonlyProtocol() const { return _showonlyProtocol; };
76
 
      void setShowonlyProtocol( const QStringList& showonlyProtocol ) { _showonlyProtocol = showonlyProtocol; };
77
 
 
78
 
      QStringList showonlyPath() const { return _showonlyPath; };
79
 
      void setShowonlyPath( const QStringList& showonlyPath ) { _showonlyPath = showonlyPath; };
80
 
 
81
 
      QStringList showonlyMime() const { return _showonlyMime; };
82
 
      void setShowonlyMime( const QStringList& showonlyMime ) { _showonlyMime = showonlyMime; };
83
 
 
84
 
      QStringList showonlyFile() const { return _showonlyFile; };
85
 
      void setShowonlyFile( const QStringList& showonlyFile ) { _showonlyFile = showonlyFile; };
86
 
 
87
 
      bool doSubstitution() const {
 
43
class KrAction: public KAction, public KrActionBase
 
44
{
 
45
    Q_OBJECT
 
46
public:
 
47
    KrAction(KActionCollection *parent, QString name = QString());
 
48
    ~KrAction();
 
49
 
 
50
    /**
 
51
     * This chekcs if the KrAction is for a specific file / location available
 
52
     * @param currentURL Check for this file
 
53
     * @return true if the KrAction if available
 
54
     */
 
55
    bool isAvailable(const KUrl& currentURL);
 
56
 
 
57
    const QString& iconName() const {
 
58
        return _iconName;
 
59
    } // TODO: added for kde4 porting (functionality is missing)
 
60
    void setIconName(const QString& name) {
 
61
        _iconName = name;
 
62
    }
 
63
 
 
64
    bool xmlRead(const QDomElement& element);
 
65
    QDomElement xmlDump(QDomDocument& doc) const;
 
66
 
 
67
    void setName(const char*) { /* empty reimplementation to prevent a name-change */ };
 
68
    const QString & getName()   {
 
69
        return _name;
 
70
    }
 
71
 
 
72
    QString category() const {
 
73
        return _category;
 
74
    };
 
75
    void setCategory(const QString& category) {
 
76
        _category = category;
 
77
    };
 
78
 
 
79
    QString command() const {
 
80
        return _command;
 
81
    };
 
82
    void setCommand(const QString& command) {
 
83
        _command = command;
 
84
    };
 
85
 
 
86
    QString user() const {
 
87
        return _user;
 
88
    };
 
89
    void setUser(const QString& user) {
 
90
        _user = user;
 
91
    };
 
92
 
 
93
    QString startpath() const {
 
94
        return _startpath;
 
95
    };
 
96
    void setStartpath(const QString& startpath) {
 
97
        _startpath = startpath;
 
98
    };
 
99
 
 
100
    ExecType execType() const {
 
101
        return _execType;
 
102
    };
 
103
    void setExecType(ExecType execType) {
 
104
        _execType = execType;
 
105
    };
 
106
 
 
107
    bool acceptURLs() const {
 
108
        return _acceptURLs;
 
109
    };
 
110
    void setAcceptURLs(const bool& acceptURLs) {
 
111
        _acceptURLs = acceptURLs;
 
112
    };
 
113
 
 
114
    bool confirmExecution() const {
 
115
        return _confirmExecution;
 
116
    };
 
117
    void setConfirmExecution(const bool& confirmExecution) {
 
118
        _confirmExecution = confirmExecution;
 
119
    };
 
120
 
 
121
    QStringList showonlyProtocol() const {
 
122
        return _showonlyProtocol;
 
123
    };
 
124
    void setShowonlyProtocol(const QStringList& showonlyProtocol) {
 
125
        _showonlyProtocol = showonlyProtocol;
 
126
    };
 
127
 
 
128
    QStringList showonlyPath() const {
 
129
        return _showonlyPath;
 
130
    };
 
131
    void setShowonlyPath(const QStringList& showonlyPath) {
 
132
        _showonlyPath = showonlyPath;
 
133
    };
 
134
 
 
135
    QStringList showonlyMime() const {
 
136
        return _showonlyMime;
 
137
    };
 
138
    void setShowonlyMime(const QStringList& showonlyMime) {
 
139
        _showonlyMime = showonlyMime;
 
140
    };
 
141
 
 
142
    QStringList showonlyFile() const {
 
143
        return _showonlyFile;
 
144
    };
 
145
    void setShowonlyFile(const QStringList& showonlyFile) {
 
146
        _showonlyFile = showonlyFile;
 
147
    };
 
148
 
 
149
    bool doSubstitution() const {
88
150
        return true;
89
 
      }
 
151
    }
90
152
 
91
 
      QString text() const {
 
153
    QString text() const {
92
154
        return KAction::text();
93
 
      }
 
155
    }
94
156
 
95
 
   public slots:
 
157
public slots:
96
158
    void exec() {
97
 
      KrActionBase::exec();
 
159
        KrActionBase::exec();
98
160
    }
99
161
 
100
162
 
101
 
   private:
102
 
      void readCommand( const QDomElement& element );
103
 
      QDomElement dumpCommand( QDomDocument& doc ) const;
104
 
 
105
 
      void readAvailability( const QDomElement& element );
106
 
      QDomElement dumpAvailability( QDomDocument& doc ) const;
107
 
 
108
 
      QString _iconName;
109
 
      QString _category;
110
 
      QString _command;
111
 
      QString _user;
112
 
      QString _startpath;
113
 
      ExecType _execType;
114
 
      bool _acceptURLs;
115
 
      bool _confirmExecution;
116
 
      QStringList _showonlyProtocol;
117
 
      QStringList _showonlyPath;
118
 
      QStringList _showonlyMime;
119
 
      QStringList _showonlyFile;
120
 
 
121
 
      QString  _name;
 
163
private:
 
164
    void readCommand(const QDomElement& element);
 
165
    QDomElement dumpCommand(QDomDocument& doc) const;
 
166
 
 
167
    void readAvailability(const QDomElement& element);
 
168
    QDomElement dumpAvailability(QDomDocument& doc) const;
 
169
 
 
170
    QString _iconName;
 
171
    QString _category;
 
172
    QString _command;
 
173
    QString _user;
 
174
    QString _startpath;
 
175
    ExecType _execType;
 
176
    bool _acceptURLs;
 
177
    bool _confirmExecution;
 
178
    QStringList _showonlyProtocol;
 
179
    QStringList _showonlyPath;
 
180
    QStringList _showonlyMime;
 
181
    QStringList _showonlyFile;
 
182
 
 
183
    QString  _name;
122
184
};
123
185
 
124
186
class QFont;
125
187
/**
126
188
 * This displays the output of a process
127
 
 * @author Shie Erlich, Jonas Bähr
128
189
 */
129
 
class KrActionProcDlg: public KDialog {
130
 
      Q_OBJECT
131
 
   public:
132
 
      KrActionProcDlg( QString caption, bool enableStderr = false, QWidget *parent = 0 );
133
 
 
134
 
   public slots:
135
 
      void addStderr(const QString& str);
136
 
      void addStdout(const QString& str);
137
 
 
138
 
   protected slots:
139
 
      void toggleFixedFont( bool state );
140
 
      void slotUser1(); ///< This is used to save the buffer to disc
141
 
 
142
 
   private:
143
 
      QTextEdit *_stdout, *_stderr, *_currentTextEdit;
144
 
      QFont normalFont, fixedFont;
145
 
   private slots:
146
 
      void currentTextEditChanged();
 
190
class KrActionProcDlg: public KDialog
 
191
{
 
192
    Q_OBJECT
 
193
public:
 
194
    KrActionProcDlg(QString caption, bool enableStderr = false, QWidget *parent = 0);
 
195
 
 
196
public slots:
 
197
    void addStderr(const QString& str);
 
198
    void addStdout(const QString& str);
 
199
 
 
200
protected slots:
 
201
    void toggleFixedFont(bool state);
 
202
    void slotUser1(); ///< This is used to save the buffer to disc
 
203
 
 
204
private:
 
205
    KTextEdit *_stdout;
 
206
    KTextEdit *_stderr;
 
207
    KTextEdit *_currentTextEdit;
 
208
    QFont normalFont;
 
209
    QFont fixedFont;
 
210
private slots:
 
211
    void currentTextEditChanged();
147
212
};
148
213
 
149
214
/**
150
215
 * This executes a command of a UserAction
151
 
 * @author Shie Erlich, Jonas Bähr
152
 
 * @todo jonas: call a list of commands separately (I began it but it doesn't work)
153
216
 */
154
 
class KrActionProc: public QObject {
155
 
      Q_OBJECT
156
 
   public:
157
 
 
158
 
      KrActionProc( KrActionBase* action );
159
 
      virtual ~KrActionProc();
160
 
      void start( QString cmdLine );
161
 
      void start( QStringList cmdLineList );
162
 
 
163
 
   protected slots:
164
 
      void kill() { _proc->kill(); }
165
 
      void processExited( int exitCode, QProcess::ExitStatus exitStatus );
166
 
      void addStderr();
167
 
      void addStdout();
168
 
 
169
 
   private:
170
 
      KrActionBase* _action;
171
 
      KProcess *_proc;
172
 
      QString _stdout;
173
 
      QString _stderr;
174
 
      KrActionProcDlg *_output;
 
217
// TODO jonas: call a list of commands separately (I began it but it doesn't work)
 
218
class KrActionProc: public QObject
 
219
{
 
220
    Q_OBJECT
 
221
public:
 
222
 
 
223
    KrActionProc(KrActionBase* action);
 
224
    virtual ~KrActionProc();
 
225
    void start(QString cmdLine);
 
226
    void start(QStringList cmdLineList);
 
227
 
 
228
protected slots:
 
229
    void kill() {
 
230
        _proc->kill();
 
231
    }
 
232
    void processExited(int exitCode, QProcess::ExitStatus exitStatus);
 
233
    void addStderr();
 
234
    void addStdout();
 
235
 
 
236
private:
 
237
    KrActionBase* _action;
 
238
    KProcess *_proc;
 
239
    QString _stdout;
 
240
    QString _stderr;
 
241
    KrActionProcDlg *_output;
175
242
};
176
243
 
177
 
 
178
244
#endif //KRACTION_H