• Skip to content
  • Skip to link menu
KDE 4.2 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     
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     // reimplemented
00128     virtual KUrl url() const;
00129     virtual QString currentDir() const;
00130     virtual void rename();
00131     virtual bool confirmClose() const;
00132 
00133     // Reimplemented to watch for events happening to the view
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     // menu item handlers
00162     void openBrowser();
00163     void copy();
00164     void paste();
00165     void pasteSelection(); // shortcut only
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     // other
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(); // called when the user clicks on the
00196                          // history search bar's close button 
00197 
00198     void snapshot(); // called periodically as the user types
00199                      // to take a snapshot of the state of the
00200                      // foreground process in the terminal
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);  // move view to end of current output
00207                                          // when a key press occurs in the 
00208                                          // display area
00209 
00210     void updateSearchFilter();
00211 
00212 private:
00213     // begins the search
00214     // text - pattern to search for
00215     // direction - value from SearchHistoryTask::SearchDirection enum to specify
00216     //             the search direction
00217     void beginSearch(const QString& text , int direction);
00218     void setupActions();
00219     void removeSearchFilter(); // remove and delete the current search filter if set
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 // structure to keep information needed to process
00346                   // incoming data requests from jobs
00347     {
00348     public:
00349         SessionPtr session; // the session associated with a history save job
00350         int lastLineFetched; // the last line processed in the previous data request
00351                              // set this to -1 at the start of the save job
00352         
00353         TerminalCharacterDecoder* decoder;  // decoder used to convert terminal characters
00354                                             // into output
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   Local Variables:
00442   mode: c++
00443   c-file-style: "stroustrup"
00444   indent-tabs-mode: nil
00445   tab-width: 4
00446   End:
00447 */

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.7
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