~ubuntu-branches/ubuntu/precise/konsole/precise-proposed

« back to all changes in this revision

Viewing changes to src/SessionController.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:43 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111216131443-rhdplbmmuxntat3k
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
// Qt
25
25
#include <QtGui/QIcon>
26
26
#include <QtCore/QList>
 
27
#include <QtCore/QSet>
27
28
#include <QtCore/QPointer>
28
29
#include <QtCore/QString>
29
30
#include <QtCore/QThread>
30
31
#include <QtCore/QHash>
31
32
 
32
33
// KDE
33
 
#include <KActionCollection>
34
 
#include <KActionMenu>
35
34
#include <KIcon>
36
35
#include <KXMLGUIClient>
37
36
 
38
37
// Konsole
39
 
#include "HistorySizeDialog.h"
40
38
#include "ViewProperties.h"
41
39
#include "Profile.h"
42
40
 
47
45
 
48
46
class QAction;
49
47
class QTextCodec;
 
48
class QKeyEvent;
 
49
 
50
50
class KCodecAction;
51
51
class KUrl;
52
52
class KJob;
 
53
class KAction;
 
54
class KActionMenu;
53
55
 
54
56
namespace Konsole
55
57
{
62
64
class ProfileList;
63
65
class UrlFilter;
64
66
class RegExpFilter;
 
67
class HistorySizeDialog;
65
68
 
66
69
// SaveHistoryTask
67
70
class TerminalCharacterDecoder;
74
77
 * The actions provided by this class are defined in the sessionui.rc XML file.
75
78
 *
76
79
 * SessionController monitors the session and provides access to basic information
77
 
 * about the session such as title(), icon() and currentDir().  SessionController 
 
80
 * about the session such as title(), icon() and currentDir().  SessionController
78
81
 * provides notifications of activity in the session via the activity() signal.
79
82
 *
80
83
 * When the controlled view receives the focus, the focused() signal is emitted
85
88
class KONSOLEPRIVATE_EXPORT SessionController : public ViewProperties , public KXMLGUIClient
86
89
{
87
90
Q_OBJECT
88
 
    
 
91
 
89
92
public:
90
93
    /**
91
94
     * Constructs a new SessionController which operates on @p session and @p view.
92
95
     */
93
96
    SessionController(Session* session , TerminalDisplay* view, QObject* parent);
94
97
    ~SessionController();
95
 
    
 
98
 
96
99
    /** Returns the session associated with this controller */
97
100
    QPointer<Session> session() { return _session; }
98
101
    /** Returns the view associated with this controller */
99
102
    QPointer<TerminalDisplay>  view()    { return _view;    }
100
 
    
101
 
    /** 
 
103
 
 
104
    /**
102
105
     * Returns true if the controller is valid.
103
106
     * A valid controller is one which has a non-null session() and view().
104
107
     *
106
109
     */
107
110
    bool isValid() const;
108
111
 
109
 
    /** 
 
112
    /**
110
113
     * Sets the widget used for searches through the session's output.
111
114
     *
112
 
     * When the user clicks on the "Search Output" menu action the @p searchBar 's 
113
 
     * show() method will be called.  The SessionController will then connect to the search 
 
115
     * When the user clicks on the "Search Output" menu action the @p searchBar 's
 
116
     * show() method will be called.  The SessionController will then connect to the search
114
117
     * bar's signals to update the search when the widget's controls are pressed.
115
118
     */
116
119
    void setSearchBar( IncrementalSearchBar* searchBar );
117
 
    /** 
 
120
    /**
118
121
     * see setSearchBar()
119
122
     */
120
123
    IncrementalSearchBar* searchBar() const;
121
124
 
122
125
    /**
123
126
     * Sets the action displayed in the session's context menu to hide or
124
 
     * show the menu bar. 
 
127
     * show the menu bar.
125
128
     */
126
129
    void setShowMenuAction(QAction* action);
127
130
 
130
133
    virtual QString currentDir() const;
131
134
    virtual void rename();
132
135
    virtual bool confirmClose() const;
 
136
    virtual bool confirmForceClose() const;
133
137
 
134
138
    // Reimplemented to watch for events happening to the view
135
139
    virtual bool eventFilter(QObject* watched , QEvent* event);
140
144
 
141
145
signals:
142
146
    /**
143
 
     * Emitted when the view associated with the controller is focused.  
 
147
     * Emitted when the view associated with the controller is focused.
144
148
     * This can be used by other classes to plug the controller's actions into a window's
145
 
     * menus. 
 
149
     * menus.
146
150
     */
147
151
    void focused( SessionController* controller );
148
152
 
149
153
public slots:
150
154
    /**
151
155
     * Issues a command to the session to navigate to the specified URL.
152
 
     * This may not succeed if the foreground program does not understand 
153
 
     * the command sent to it ( 'cd path' for local URLs ) or is not 
 
156
     * This may not succeed if the foreground program does not understand
 
157
     * the command sent to it ( 'cd path' for local URLs ) or is not
154
158
     * responding to input.
155
159
     *
156
160
     * openUrl() currently supports urls for local paths and those
158
162
     */
159
163
    void openUrl( const KUrl& url ); 
160
164
 
 
165
    /**
 
166
     * update actions which are meaningful only when rimary screen is in use.
 
167
     */
 
168
    void setupPrimaryScreenSpecificActions( bool use);
 
169
 
 
170
    /**
 
171
     * close the associated session. This might involve user interaction for
 
172
     * confirmation.
 
173
     */
 
174
    void closeSession();
 
175
 
 
176
    /**
 
177
     * enable or disable the copy action
 
178
     */
 
179
    void updateCopyAction( const QString & text );
 
180
 
 
181
    /**  Increase font size */
 
182
    void increaseTextSize();
 
183
 
 
184
    /**  Decrease font size */
 
185
    void decreaseTextSize();
 
186
 
161
187
private slots:
162
188
    // menu item handlers
163
189
    void openBrowser();
164
190
    void copy();
165
191
    void paste();
166
 
    void pasteSelection(); // shortcut only
 
192
    void selectAll();
 
193
    void pasteFromXSelection(); // shortcut only
167
194
    void copyInputToAllTabs();
168
195
    void copyInputToSelectedTabs();
169
196
    void copyInputToNone();
172
199
    void searchHistory(bool showSearchBar);
173
200
    void findNextInHistory();
174
201
    void findPreviousInHistory();
 
202
    void changeSearchMatch();
175
203
    void saveHistory();
176
204
    void showHistoryOptions();
177
205
    void clearHistory();
178
206
    void clearHistoryAndReset();
179
 
    void closeSession();
180
207
    void monitorActivity(bool monitor);
181
208
    void monitorSilence(bool monitor);
182
 
    void increaseTextSize();
183
 
    void decreaseTextSize();
184
209
    void renameSession();
185
 
    void saveSession();
186
 
    void changeProfile(Profile::Ptr profile);
 
210
    void switchProfile(Profile::Ptr profile);
187
211
 
188
212
    // other
189
 
    void prepareChangeProfileMenu();
 
213
    void prepareSwitchProfileMenu();
190
214
    void updateCodecAction();
191
215
    void showDisplayContextMenu(const QPoint& position);
192
216
    void sessionStateChanged(int state);
202
226
 
203
227
    void requireUrlFilterUpdate();
204
228
    void highlightMatches(bool highlight);
205
 
    void scrollBackOptionsChanged(int mode , int lines, bool saveToCurrentProfile);
 
229
    void scrollBackOptionsChanged(int mode , int lines);
206
230
    void sessionResizeRequest(const QSize& size);
207
231
    void trackOutput(QKeyEvent* event);  // move view to end of current output
208
232
                                         // when a key press occurs in the 
209
233
                                         // display area
210
234
 
211
235
    void updateSearchFilter();
212
 
    
 
236
 
213
237
    void zmodemDownload();
214
238
    void zmodemUpload();
215
239
 
216
240
    /* Returns true if called within a KPart; false if called within Konsole. */
217
241
    bool isKonsolePart() const;
218
242
 
 
243
 
219
244
private:
220
245
    // begins the search
221
246
    // text - pattern to search for
229
254
 
230
255
private:
231
256
    void updateSessionIcon();
232
 
  
 
257
 
233
258
    QPointer<Session>         _session;
234
259
    QPointer<TerminalDisplay> _view;
235
260
    SessionGroup*               _copyToGroup;
236
 
    
 
261
 
237
262
    ProfileList* _profileList;
238
263
 
239
264
    KIcon      _sessionIcon;
246
271
    KAction* _copyToAllTabsAction;
247
272
    KAction* _copyToSelectedAction;
248
273
    KAction* _copyToNoneAction;
249
 
    
 
274
 
250
275
    KAction* _searchToggleAction;
251
276
    KAction* _findNextAction;
252
277
    KAction* _findPreviousAction;
253
 
    
254
 
    
 
278
 
 
279
 
255
280
    bool _urlFilterUpdateRequired;
256
281
 
257
282
    QPointer<IncrementalSearchBar> _searchBar;
258
283
 
259
284
    KCodecAction* _codecAction;
260
285
 
261
 
    KActionMenu* _changeProfileMenu;
 
286
    KActionMenu* _switchProfileMenu;
262
287
 
263
288
    bool _listenForScreenWindowUpdates;
264
289
    bool _preventClose;
273
298
    return !_session.isNull() && !_view.isNull();
274
299
}
275
300
 
276
 
/** 
 
301
/**
277
302
 * Abstract class representing a task which can be performed on a group of sessions.
278
303
 *
279
304
 * Create a new instance of the appropriate sub-class for the task you want to perform and
289
314
public:
290
315
   SessionTask(QObject* parent = 0);
291
316
 
292
 
   /** 
 
317
   /**
293
318
    * Sets whether the task automatically deletes itself when the task has been finished.
294
319
    * Depending on whether the task operates synchronously or asynchronously, the deletion
295
320
    * may be scheduled immediately after execute() returns or it may happen some time later.
301
326
   /** Adds a new session to the group */
302
327
   void addSession(Session* session);
303
328
 
304
 
   /** 
 
329
   /**
305
330
    * Executes the task on each of the sessions in the group.
306
331
    * The completed() signal is emitted when the task is finished, depending on the specific sub-class
307
332
    * execute() may be synchronous or asynchronous
309
334
   virtual void execute() = 0;
310
335
 
311
336
signals:
312
 
   /** 
313
 
    * Emitted when the task has completed.  
 
337
   /**
 
338
    * Emitted when the task has completed.
314
339
    * Depending on the task this may occur just before execute() returns, or it
315
340
    * may occur later
316
341
    *
336
361
class SaveHistoryTask : public SessionTask
337
362
{
338
363
Q_OBJECT
339
 
  
 
364
 
340
365
public:
341
366
    /** Constructs a new task to save session output to URLs */
342
367
    SaveHistoryTask(QObject* parent = 0);
362
387
        SessionPtr session; // the session associated with a history save job
363
388
        int lastLineFetched; // the last line processed in the previous data request
364
389
                             // set this to -1 at the start of the save job
365
 
        
 
390
 
366
391
        TerminalCharacterDecoder* decoder;  // decoder used to convert terminal characters
367
392
                                            // into output
368
393
 
371
396
    QHash<KJob*,SaveJob> _jobSession;
372
397
};
373
398
 
374
 
class SearchHistoryThread;
 
399
//class SearchHistoryThread;
375
400
/**
376
401
 * A task which searches through the output of sessions for matches for a given regular expression.
377
402
 * SearchHistoryTask operates on ScreenWindow instances rather than sessions added by addSession().
391
416
Q_OBJECT
392
417
 
393
418
public:
394
 
    /** 
395
 
     * This enum describes the strategies available for searching through the 
 
419
    /**
 
420
     * This enum describes the strategies available for searching through the
396
421
     * session's output.
397
422
     */
398
423
    enum SearchDirection
399
424
    {
400
425
        /** Searches forwards through the output, starting at the current selection. */
401
426
        ForwardsSearch,
402
 
        /** Searches backwars through the output, starting at the current selection. */
403
 
        BackwardsSearch  
 
427
        /** Searches backwards through the output, starting at the current selection. */
 
428
        BackwardsSearch
404
429
    };
405
430
 
406
 
    /** 
407
 
     * Constructs a new search task. 
 
431
    /**
 
432
     * Constructs a new search task.
408
433
     */
409
434
    explicit SearchHistoryTask(QObject* parent = 0);
410
435
 
415
440
    void setRegExp(const QRegExp& regExp);
416
441
    /** Returns the regular expression which is searched for when execute() is called */
417
442
    QRegExp regExp() const;
418
 
   
419
 
    /** Specifies the direction to search in when execute() is called. */ 
 
443
 
 
444
    /** Specifies the direction to search in when execute() is called. */
420
445
    void setSearchDirection( SearchDirection direction );
421
446
    /** Returns the current search direction.  See setSearchDirection(). */
422
447
    SearchDirection searchDirection() const;
423
448
 
424
 
    /** 
 
449
    /**
425
450
     * Performs a search through the session's history, starting at the position
426
451
     * of the current selection, in the direction specified by setSearchDirection().
427
452
     *
428
 
     * If it finds a match, the ScreenWindow specified in the constructor is 
429
 
     * scrolled to the position where the match occurred and the selection 
 
453
     * If it finds a match, the ScreenWindow specified in the constructor is
 
454
     * scrolled to the position where the match occurred and the selection
430
455
     * is set to the matching text.  execute() then returns immediately.
431
456
     *
432
457
     * To continue the search looking for further matches, call execute() again.
435
460
 
436
461
private:
437
462
    typedef QPointer<ScreenWindow> ScreenWindowPtr;
438
 
    
 
463
 
439
464
    void executeOnScreenWindow( SessionPtr session , ScreenWindowPtr window );
440
465
    void highlightResult( ScreenWindowPtr window , int position);
441
466
 
443
468
    QRegExp _regExp;
444
469
    SearchDirection _direction;
445
470
 
446
 
    static QPointer<SearchHistoryThread> _thread;
 
471
    //static QPointer<SearchHistoryThread> _thread;
447
472
};
448
473
 
449
474
}