Konsole
SessionController.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SESSIONCONTROLLER_H
00021 #define SESSIONCONTROLLER_H
00022
00023
00024 #include <QtGui/QIcon>
00025 #include <QtCore/QList>
00026 #include <QtCore/QPointer>
00027 #include <QtCore/QString>
00028 #include <QtCore/QThread>
00029 #include <QtCore/QHash>
00030
00031
00032 #include <KActionCollection>
00033 #include <KIcon>
00034 #include <KXMLGUIClient>
00035
00036
00037 #include "HistorySizeDialog.h"
00038 #include "ViewProperties.h"
00039 #include "Profile.h"
00040
00041 namespace KIO
00042 {
00043 class Job;
00044 }
00045
00046 class QAction;
00047 class QTextCodec;
00048 class KCodecAction;
00049 class KMenu;
00050 class KUrl;
00051 class KJob;
00052
00053 namespace Konsole
00054 {
00055
00056 class Session;
00057 class SessionGroup;
00058 class ScreenWindow;
00059 class TerminalDisplay;
00060 class IncrementalSearchBar;
00061 class ProfileList;
00062 class UrlFilter;
00063 class RegExpFilter;
00064
00065
00066 class TerminalCharacterDecoder;
00067
00068
00069 typedef QPointer<Session> SessionPtr;
00070
00084 class SessionController : public ViewProperties , public KXMLGUIClient
00085 {
00086 Q_OBJECT
00087
00088 public:
00092 SessionController(Session* session , TerminalDisplay* view, QObject* parent);
00093 ~SessionController();
00094
00095
00097 QPointer<Session> session() { return _session; }
00099 QPointer<TerminalDisplay> view() { return _view; }
00100
00107 bool isValid() const;
00108
00116 void setSearchBar( IncrementalSearchBar* searchBar );
00120 IncrementalSearchBar* searchBar() const;
00121
00126 void setShowMenuAction(QAction* action);
00127
00128
00129 virtual KUrl url() const;
00130 virtual QString currentDir() const;
00131 virtual void rename();
00132 virtual bool confirmClose() const;
00133
00134
00135 virtual bool eventFilter(QObject* watched , QEvent* event);
00136
00137 signals:
00143 void focused( SessionController* controller );
00144
00145 public slots:
00155 void openUrl( const KUrl& url );
00156
00157 private slots:
00158
00159 void openBrowser();
00160 void copy();
00161 void paste();
00162 void pasteSelection();
00163 void clear();
00164 void clearAndReset();
00165 void copyInputTo();
00166 void editCurrentProfile();
00167 void changeCodec(QTextCodec* codec);
00168
00169 void searchHistory(bool showSearchBar);
00170 void findNextInHistory();
00171 void findPreviousInHistory();
00172 void saveHistory();
00173 void showHistoryOptions();
00174 void clearHistory();
00175 void clearHistoryAndReset();
00176 void closeSession();
00177 void monitorActivity(bool monitor);
00178 void monitorSilence(bool monitor);
00179 void increaseTextSize();
00180 void decreaseTextSize();
00181 void renameSession();
00182 void saveSession();
00183 void changeProfile(Profile::Ptr profile);
00184
00185
00186 void prepareChangeProfileMenu();
00187 void updateCodecAction();
00188 void showDisplayContextMenu(TerminalDisplay* display , int state , const QPoint& position);
00189 void sessionStateChanged(int state);
00190 void sessionTitleChanged();
00191 void searchTextChanged(const QString& text);
00192 void searchCompleted(bool success);
00193 void searchClosed();
00194
00195
00196 void snapshot();
00197
00198
00199
00200 void requireUrlFilterUpdate();
00201 void highlightMatches(bool highlight);
00202
00203 void scrollBackOptionsChanged(int mode , int lines);
00204
00205 void sessionResizeRequest(const QSize& size);
00206
00207 void trackOutput(QKeyEvent* event);
00208
00209
00210
00211 void updateSearchFilter();
00212
00213
00214 void debugProcess();
00215
00216 private:
00217
00218
00219
00220
00221 void beginSearch(const QString& text , int direction);
00222 void setupActions();
00223 void removeSearchFilter();
00224 void setFindNextPrevEnabled(bool enabled);
00225 void listenForScreenWindowUpdates();
00226
00227 private:
00228 static KIcon _activityIcon;
00229 static KIcon _silenceIcon;
00230
00231 QPointer<Session> _session;
00232 QPointer<TerminalDisplay> _view;
00233 SessionGroup* _copyToGroup;
00234
00235 ProfileList* _profileList;
00236
00237 KIcon _sessionIcon;
00238 QString _sessionIconName;
00239 int _previousState;
00240
00241 UrlFilter* _viewUrlFilter;
00242 RegExpFilter* _searchFilter;
00243
00244 KAction* _searchToggleAction;
00245 KAction* _findNextAction;
00246 KAction* _findPreviousAction;
00247
00248
00249 bool _urlFilterUpdateRequired;
00250
00251 QPointer<IncrementalSearchBar> _searchBar;
00252
00253 KCodecAction* _codecAction;
00254
00255 KMenu* _changeProfileMenu;
00256
00257 bool _listenForScreenWindowUpdates;
00258 bool _preventClose;
00259
00260 static int _lastControllerId;
00261 };
00262 inline bool SessionController::isValid() const
00263 {
00264 return !_session.isNull() && !_view.isNull();
00265 }
00266
00276 class SessionTask : public QObject
00277 {
00278 Q_OBJECT
00279
00280 public:
00281 SessionTask(QObject* parent = 0);
00282
00288 void setAutoDelete(bool enable);
00290 bool autoDelete() const;
00291
00293 void addSession(Session* session);
00294
00300 virtual void execute() = 0;
00301
00302 signals:
00310 void completed(bool success);
00311
00312 protected:
00313
00315 QList< SessionPtr > sessions() const;
00316
00317 private:
00318
00319 bool _autoDelete;
00320 QList< SessionPtr > _sessions;
00321 };
00322
00327 class SaveHistoryTask : public SessionTask
00328 {
00329 Q_OBJECT
00330
00331 public:
00333 SaveHistoryTask(QObject* parent = 0);
00334 virtual ~SaveHistoryTask();
00335
00342 virtual void execute();
00343
00344 private slots:
00345 void jobDataRequested(KIO::Job* job , QByteArray& data);
00346 void jobResult(KJob* job);
00347
00348 private:
00349 class SaveJob
00350
00351 {
00352 public:
00353 SessionPtr session;
00354 int lastLineFetched;
00355
00356
00357 TerminalCharacterDecoder* decoder;
00358
00359
00360 };
00361
00362 QHash<KJob*,SaveJob> _jobSession;
00363 };
00364
00365 class SearchHistoryThread;
00380 class SearchHistoryTask : public SessionTask
00381 {
00382 Q_OBJECT
00383
00384 public:
00389 enum SearchDirection
00390 {
00392 ForwardsSearch,
00394 BackwardsSearch
00395 };
00396
00400 explicit SearchHistoryTask(QObject* parent = 0);
00401
00403 void addScreenWindow( Session* session , ScreenWindow* searchWindow);
00404
00406 void setRegExp(const QRegExp& regExp);
00408 QRegExp regExp() const;
00409
00411 void setSearchDirection( SearchDirection direction );
00413 SearchDirection searchDirection() const;
00414
00425 virtual void execute();
00426
00427 private:
00428 typedef QPointer<ScreenWindow> ScreenWindowPtr;
00429
00430 void executeOnScreenWindow( SessionPtr session , ScreenWindowPtr window );
00431 void highlightResult( ScreenWindowPtr window , int position);
00432
00433 QMap< SessionPtr , ScreenWindowPtr > _windows;
00434 QRegExp _regExp;
00435 SearchDirection _direction;
00436
00437 static QPointer<SearchHistoryThread> _thread;
00438 };
00439
00440 }
00441
00442 #endif //SESSIONCONTROLLER_H