• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Konsole

SessionController.h

Go to the documentation of this file.
00001 /*
00002     Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301  USA.
00018 */
00019 
00020 #ifndef SESSIONCONTROLLER_H
00021 #define SESSIONCONTROLLER_H
00022 
00023 // Qt
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 // KDE
00032 #include <KActionCollection>
00033 #include <KIcon>
00034 #include <KXMLGUIClient>
00035 
00036 // Konsole
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 // SaveHistoryTask
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     // reimplemented
00129     virtual KUrl url() const;
00130     virtual QString currentDir() const;
00131     virtual void rename();
00132     virtual bool confirmClose() const;
00133 
00134     // Reimplemented to watch for events happening to the view
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     // menu item handlers
00159     void openBrowser();
00160     void copy();
00161     void paste();
00162     void pasteSelection(); // shortcut only
00163     void clear();
00164     void clearAndReset();
00165     void copyInputTo();
00166     void editCurrentProfile();
00167     void changeCodec(QTextCodec* codec);
00168     //void searchHistory();
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     // other
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(); // called when the user clicks on the
00194                          // history search bar's close button 
00195 
00196     void snapshot(); // called periodically as the user types
00197                      // to take a snapshot of the state of the
00198                      // foreground process in the terminal
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);  // move view to end of current output
00208                                          // when a key press occurs in the 
00209                                          // display area
00210 
00211     void updateSearchFilter();
00212 
00213     // debugging slots
00214     void debugProcess();
00215 
00216 private:
00217     // begins the search
00218     // text - pattern to search for
00219     // direction - value from SearchHistoryTask::SearchDirection enum to specify
00220     //             the search direction
00221     void beginSearch(const QString& text , int direction);
00222     void setupActions();
00223     void removeSearchFilter(); // remove and delete the current search filter if set
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 // structure to keep information needed to process
00350                   // incoming data requests from jobs
00351     {
00352     public:
00353         SessionPtr session; // the session associated with a history save job
00354         int lastLineFetched; // the last line processed in the previous data request
00355                              // set this to -1 at the start of the save job
00356         
00357         TerminalCharacterDecoder* decoder;  // decoder used to convert terminal characters
00358                                             // into output
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

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal