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
00096 QPointer<Session> session() { return _session; }
00098 QPointer<TerminalDisplay> view() { return _view; }
00099
00106 bool isValid() const;
00107
00115 void setSearchBar( IncrementalSearchBar* searchBar );
00119 IncrementalSearchBar* searchBar() const;
00120
00125 void setShowMenuAction(QAction* action);
00126
00127
00128 virtual KUrl url() const;
00129 virtual QString currentDir() const;
00130 virtual void rename();
00131 virtual bool confirmClose() const;
00132
00133
00134 virtual bool eventFilter(QObject* watched , QEvent* event);
00135
00137 static QSet<SessionController*> allControllers()
00138 { return _allControllers; }
00139
00140 signals:
00146 void focused( SessionController* controller );
00147
00148 public slots:
00158 void openUrl( const KUrl& url );
00159
00160 private slots:
00161
00162 void openBrowser();
00163 void copy();
00164 void paste();
00165 void pasteSelection();
00166 void clear();
00167 void clearAndReset();
00168 void copyInputTo();
00169 void editCurrentProfile();
00170 void changeCodec(QTextCodec* codec);
00171 void searchHistory(bool showSearchBar);
00172 void findNextInHistory();
00173 void findPreviousInHistory();
00174 void saveHistory();
00175 void showHistoryOptions();
00176 void clearHistory();
00177 void clearHistoryAndReset();
00178 void closeSession();
00179 void monitorActivity(bool monitor);
00180 void monitorSilence(bool monitor);
00181 void increaseTextSize();
00182 void decreaseTextSize();
00183 void renameSession();
00184 void saveSession();
00185 void changeProfile(Profile::Ptr profile);
00186
00187
00188 void prepareChangeProfileMenu();
00189 void updateCodecAction();
00190 void showDisplayContextMenu(const QPoint& position);
00191 void sessionStateChanged(int state);
00192 void sessionTitleChanged();
00193 void searchTextChanged(const QString& text);
00194 void searchCompleted(bool success);
00195 void searchClosed();
00196
00197
00198 void snapshot();
00199
00200
00201
00202 void requireUrlFilterUpdate();
00203 void highlightMatches(bool highlight);
00204 void scrollBackOptionsChanged(int mode , int lines);
00205 void sessionResizeRequest(const QSize& size);
00206 void trackOutput(QKeyEvent* event);
00207
00208
00209
00210 void updateSearchFilter();
00211
00212 private:
00213
00214
00215
00216
00217 void beginSearch(const QString& text , int direction);
00218 void setupActions();
00219 void removeSearchFilter();
00220 void setFindNextPrevEnabled(bool enabled);
00221 void listenForScreenWindowUpdates();
00222
00223 private:
00224 QPointer<Session> _session;
00225 QPointer<TerminalDisplay> _view;
00226 SessionGroup* _copyToGroup;
00227
00228 ProfileList* _profileList;
00229
00230 KIcon _sessionIcon;
00231 QString _sessionIconName;
00232 int _previousState;
00233
00234 UrlFilter* _viewUrlFilter;
00235 RegExpFilter* _searchFilter;
00236
00237 KAction* _searchToggleAction;
00238 KAction* _findNextAction;
00239 KAction* _findPreviousAction;
00240
00241
00242 bool _urlFilterUpdateRequired;
00243
00244 QPointer<IncrementalSearchBar> _searchBar;
00245
00246 KCodecAction* _codecAction;
00247
00248 KMenu* _changeProfileMenu;
00249
00250 bool _listenForScreenWindowUpdates;
00251 bool _preventClose;
00252
00253 static QSet<SessionController*> _allControllers;
00254 static int _lastControllerId;
00255 static KIcon _activityIcon;
00256 static KIcon _silenceIcon;
00257 };
00258 inline bool SessionController::isValid() const
00259 {
00260 return !_session.isNull() && !_view.isNull();
00261 }
00262
00272 class SessionTask : public QObject
00273 {
00274 Q_OBJECT
00275
00276 public:
00277 SessionTask(QObject* parent = 0);
00278
00284 void setAutoDelete(bool enable);
00286 bool autoDelete() const;
00287
00289 void addSession(Session* session);
00290
00296 virtual void execute() = 0;
00297
00298 signals:
00306 void completed(bool success);
00307
00308 protected:
00309
00311 QList< SessionPtr > sessions() const;
00312
00313 private:
00314
00315 bool _autoDelete;
00316 QList< SessionPtr > _sessions;
00317 };
00318
00323 class SaveHistoryTask : public SessionTask
00324 {
00325 Q_OBJECT
00326
00327 public:
00329 SaveHistoryTask(QObject* parent = 0);
00330 virtual ~SaveHistoryTask();
00331
00338 virtual void execute();
00339
00340 private slots:
00341 void jobDataRequested(KIO::Job* job , QByteArray& data);
00342 void jobResult(KJob* job);
00343
00344 private:
00345 class SaveJob
00346
00347 {
00348 public:
00349 SessionPtr session;
00350 int lastLineFetched;
00351
00352
00353 TerminalCharacterDecoder* decoder;
00354
00355
00356 };
00357
00358 QHash<KJob*,SaveJob> _jobSession;
00359 };
00360
00361 class SearchHistoryThread;
00376 class SearchHistoryTask : public SessionTask
00377 {
00378 Q_OBJECT
00379
00380 public:
00385 enum SearchDirection
00386 {
00388 ForwardsSearch,
00390 BackwardsSearch
00391 };
00392
00396 explicit SearchHistoryTask(QObject* parent = 0);
00397
00399 void addScreenWindow( Session* session , ScreenWindow* searchWindow);
00400
00402 void setRegExp(const QRegExp& regExp);
00404 QRegExp regExp() const;
00405
00407 void setSearchDirection( SearchDirection direction );
00409 SearchDirection searchDirection() const;
00410
00421 virtual void execute();
00422
00423 private:
00424 typedef QPointer<ScreenWindow> ScreenWindowPtr;
00425
00426 void executeOnScreenWindow( SessionPtr session , ScreenWindowPtr window );
00427 void highlightResult( ScreenWindowPtr window , int position);
00428
00429 QMap< SessionPtr , ScreenWindowPtr > _windows;
00430 QRegExp _regExp;
00431 SearchDirection _direction;
00432
00433 static QPointer<SearchHistoryThread> _thread;
00434 };
00435
00436 }
00437
00438 #endif //SESSIONCONTROLLER_H
00439
00440
00441
00442
00443
00444
00445
00446
00447