• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • sources
  • kde-4.12
  • applications
  • konsole
  • src
SessionController.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
3  Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301 USA.
19 */
20 
21 #ifndef SESSIONCONTROLLER_H
22 #define SESSIONCONTROLLER_H
23 
24 // Qt
25 #include <QtCore/QList>
26 #include <QtCore/QSet>
27 #include <QtCore/QPointer>
28 #include <QtCore/QString>
29 #include <QtCore/QHash>
30 
31 // KDE
32 #include <KIcon>
33 #include <KXMLGUIClient>
34 
35 // Konsole
36 #include "ViewProperties.h"
37 #include "Profile.h"
38 
39 namespace KIO
40 {
41 class Job;
42 }
43 
44 class QAction;
45 class QTextCodec;
46 class QKeyEvent;
47 class QTimer;
48 
49 class KCodecAction;
50 class KUrl;
51 class KJob;
52 class KAction;
53 class KActionMenu;
54 
55 namespace Konsole
56 {
57 class Session;
58 class SessionGroup;
59 class ScreenWindow;
60 class TerminalDisplay;
61 class IncrementalSearchBar;
62 class ProfileList;
63 class UrlFilter;
64 class RegExpFilter;
65 class EditProfileDialog;
66 
67 // SaveHistoryTask
68 class TerminalCharacterDecoder;
69 
70 typedef QPointer<Session> SessionPtr;
71 
85 class KONSOLEPRIVATE_EXPORT SessionController : public ViewProperties , public KXMLGUIClient
86 {
87  Q_OBJECT
88 
89 public:
90  enum CopyInputToEnum {
92  CopyInputToAllTabsMode = 0 ,
93 
95  CopyInputToSelectedTabsMode = 1 ,
96 
98  CopyInputToNoneMode = 2
99  };
100 
104  SessionController(Session* session , TerminalDisplay* view, QObject* parent);
105  ~SessionController();
106 
108  QPointer<Session> session() {
109  return _session;
110  }
112  QPointer<TerminalDisplay> view() {
113  return _view;
114  }
115 
119  QString userTitle() const;
120 
127  bool isValid() const;
128 
130  void setSearchStartTo(int line);
131 
134  void setSearchStartToWindowCurrentLine();
135 
143  void setSearchBar(IncrementalSearchBar* searchBar);
147  IncrementalSearchBar* searchBar() const;
148 
153  void setShowMenuAction(QAction* action);
154 
155  EditProfileDialog* profileDialogPointer();
156 
157  // reimplemented
158  virtual KUrl url() const;
159  virtual QString currentDir() const;
160  virtual void rename();
161  virtual bool confirmClose() const;
162  virtual bool confirmForceClose() const;
163 
164  // Reimplemented to watch for events happening to the view
165  virtual bool eventFilter(QObject* watched , QEvent* event);
166 
168  static QSet<SessionController*> allControllers() {
169  return _allControllers;
170  }
171 
172 signals:
178  void focused(SessionController* controller);
179 
180  void rawTitleChanged();
181 
186  void currentDirectoryChanged(const QString& dir);
187 
188 public slots:
198  void openUrl(const KUrl& url);
199 
203  void setupPrimaryScreenSpecificActions(bool use);
204 
208  void selectionChanged(const QString& selectedText);
209 
214  void closeSession();
215 
217  void increaseFontSize();
218 
220  void decreaseFontSize();
221 
222 private slots:
223  // menu item handlers
224  void openBrowser();
225  void copy();
226  void paste();
227  void selectAll();
228  void pasteFromX11Selection(); // shortcut only
229  void copyInputActionsTriggered(QAction* action);
230  void copyInputToAllTabs();
231  void copyInputToSelectedTabs();
232  void copyInputToNone();
233  void editCurrentProfile();
234  void changeCodec(QTextCodec* codec);
235  void enableSearchBar(bool showSearchBar);
236  void searchHistory(bool showSearchBar);
237  void searchBarEvent();
238  void searchFrom();
239  void findNextInHistory();
240  void findPreviousInHistory();
241  void changeSearchMatch();
242  void print_screen();
243  void saveHistory();
244  void showHistoryOptions();
245  void clearHistory();
246  void clearHistoryAndReset();
247  void monitorActivity(bool monitor);
248  void monitorSilence(bool monitor);
249  void renameSession();
250  void switchProfile(Profile::Ptr profile);
251  void handleWebShortcutAction();
252  void configureWebShortcuts();
253  void sendSignal(QAction* action);
254 
255  // other
256  void prepareSwitchProfileMenu();
257  void updateCodecAction();
258  void showDisplayContextMenu(const QPoint& position);
259  void movementKeyFromSearchBarReceived(QKeyEvent *event);
260  void sessionStateChanged(int state);
261  void sessionTitleChanged();
262  void searchTextChanged(const QString& text);
263  void searchCompleted(bool success);
264  void searchClosed(); // called when the user clicks on the
265  // history search bar's close button
266 
267  void interactionHandler();
268  void snapshot(); // called periodically as the user types
269  // to take a snapshot of the state of the
270  // foreground process in the terminal
271 
272  void requireUrlFilterUpdate();
273  void highlightMatches(bool highlight);
274  void scrollBackOptionsChanged(int mode , int lines);
275  void sessionResizeRequest(const QSize& size);
276  void trackOutput(QKeyEvent* event); // move view to end of current output
277  // when a key press occurs in the
278  // display area
279 
280  void updateSearchFilter();
281 
282  void zmodemDownload();
283  void zmodemUpload();
284 
285  /* Returns true if called within a KPart; false if called within Konsole. */
286  bool isKonsolePart() const;
287 
288  // update actions related with selected text
289  void updateCopyAction(const QString& selectedText);
290  void updateWebSearchMenu();
291 
292 private:
293  // begins the search
294  // text - pattern to search for
295  // direction - value from SearchHistoryTask::SearchDirection enum to specify
296  // the search direction
297  void beginSearch(const QString& text , int direction);
298  QRegExp regexpFromSearchBarOptions();
299  bool reverseSearchChecked() const;
300  void setupCommonActions();
301  void setupExtraActions();
302  void removeSearchFilter(); // remove and delete the current search filter if set
303  void setFindNextPrevEnabled(bool enabled);
304  void listenForScreenWindowUpdates();
305 
306 private:
307  void updateSessionIcon();
308 
309  QPointer<Session> _session;
310  QPointer<TerminalDisplay> _view;
311  SessionGroup* _copyToGroup;
312 
313  ProfileList* _profileList;
314 
315  KIcon _sessionIcon;
316  QString _sessionIconName;
317  int _previousState;
318 
319  UrlFilter* _viewUrlFilter;
320  RegExpFilter* _searchFilter;
321 
322  KAction* _copyInputToAllTabsAction;
323 
324  KAction* _findAction;
325  KAction* _findNextAction;
326  KAction* _findPreviousAction;
327 
328  QTimer* _interactionTimer;
329 
330  bool _urlFilterUpdateRequired;
331 
332  int _searchStartLine;
333  int _prevSearchResultLine;
334  QPointer<IncrementalSearchBar> _searchBar;
335 
336  KCodecAction* _codecAction;
337 
338  KActionMenu* _switchProfileMenu;
339  KActionMenu* _webSearchMenu;
340 
341  bool _listenForScreenWindowUpdates;
342  bool _preventClose;
343 
344  bool _keepIconUntilInteraction;
345 
346  QString _selectedText;
347 
348  QAction* _showMenuAction;
349 
350  static QSet<SessionController*> _allControllers;
351  static int _lastControllerId;
352  static const KIcon _activityIcon;
353  static const KIcon _silenceIcon;
354  static const KIcon _broadcastIcon;
355 
356  QStringList _bookmarkValidProgramsToClear;
357 
358  bool _isSearchBarEnabled;
359  QWeakPointer<EditProfileDialog> _editProfileDialog;
360 
361  QString _searchText;
362 };
363 inline bool SessionController::isValid() const
364 {
365  return !_session.isNull() && !_view.isNull();
366 }
367 
377 class SessionTask : public QObject
378 {
379  Q_OBJECT
380 
381 public:
382  explicit SessionTask(QObject* parent = 0);
383 
389  void setAutoDelete(bool enable);
391  bool autoDelete() const;
392 
394  void addSession(Session* session);
395 
401  virtual void execute() = 0;
402 
403 signals:
411  void completed(bool success);
412 
413 protected:
415  QList< SessionPtr > sessions() const;
416 
417 private:
418  bool _autoDelete;
419  QList< SessionPtr > _sessions;
420 };
421 
426 class SaveHistoryTask : public SessionTask
427 {
428  Q_OBJECT
429 
430 public:
432  explicit SaveHistoryTask(QObject* parent = 0);
433  virtual ~SaveHistoryTask();
434 
441  virtual void execute();
442 
443 private slots:
444  void jobDataRequested(KIO::Job* job , QByteArray& data);
445  void jobResult(KJob* job);
446 
447 private:
448  class SaveJob // structure to keep information needed to process
449  // incoming data requests from jobs
450  {
451  public:
452  SessionPtr session; // the session associated with a history save job
453  int lastLineFetched; // the last line processed in the previous data request
454  // set this to -1 at the start of the save job
455 
456  TerminalCharacterDecoder* decoder; // decoder used to convert terminal characters
457  // into output
458  };
459 
460  QHash<KJob*, SaveJob> _jobSession;
461 };
462 
463 //class SearchHistoryThread;
478 class SearchHistoryTask : public SessionTask
479 {
480  Q_OBJECT
481 
482 public:
487  enum SearchDirection {
489  ForwardsSearch,
491  BackwardsSearch
492  };
493 
497  explicit SearchHistoryTask(QObject* parent = 0);
498 
500  void addScreenWindow(Session* session , ScreenWindow* searchWindow);
501 
503  void setRegExp(const QRegExp& regExp);
505  QRegExp regExp() const;
506 
508  void setSearchDirection(SearchDirection direction);
510  SearchDirection searchDirection() const;
511 
513  void setStartLine(int startLine);
514 
525  virtual void execute();
526 
527 private:
528  typedef QPointer<ScreenWindow> ScreenWindowPtr;
529 
530  void executeOnScreenWindow(SessionPtr session , ScreenWindowPtr window);
531  void highlightResult(ScreenWindowPtr window , int position);
532 
533  QMap< SessionPtr , ScreenWindowPtr > _windows;
534  QRegExp _regExp;
535  SearchDirection _direction;
536  int _startLine;
537 
538  //static QPointer<SearchHistoryThread> _thread;
539 };
540 }
541 
542 #endif //SESSIONCONTROLLER_H
543 
Konsole::SaveHistoryTask::SaveHistoryTask
SaveHistoryTask(QObject *parent=0)
Constructs a new task to save session output to URLs.
Definition: SessionController.cpp:1662
Konsole::SessionTask::SessionTask
SessionTask(QObject *parent=0)
Definition: SessionController.cpp:1640
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:67
Konsole::SessionController
Provides the menu actions to manipulate a single terminal session and view pair.
Definition: SessionController.h:85
Konsole::SearchHistoryTask::setStartLine
void setStartLine(int startLine)
The line from which the search will be done.
Definition: SessionController.cpp:1958
Konsole::SearchHistoryTask::BackwardsSearch
Searches backwards through the output, starting at the current selection.
Definition: SessionController.h:491
KXMLGUIClient
Konsole::SearchHistoryTask::regExp
QRegExp regExp() const
Returns the regular expression which is searched for when execute() is called.
Definition: SessionController.cpp:1970
Konsole::SessionTask
Abstract class representing a task which can be performed on a group of sessions. ...
Definition: SessionController.h:377
Konsole::SessionController::view
QPointer< TerminalDisplay > view()
Returns the view associated with this controller.
Definition: SessionController.h:112
Konsole::ProfileList
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Definition: ProfileList.h:51
Konsole::SessionController::allControllers
static QSet< SessionController * > allControllers()
Returns the set of all controllers that exist.
Definition: SessionController.h:168
Konsole::SessionTask::execute
virtual void execute()=0
Executes the task on each of the sessions in the group.
Konsole::SearchHistoryTask::searchDirection
SearchDirection searchDirection() const
Returns the current search direction.
Definition: SessionController.cpp:1962
QObject
Konsole::SaveHistoryTask::~SaveHistoryTask
virtual ~SaveHistoryTask()
Definition: SessionController.cpp:1666
Konsole::EditProfileDialog
A dialog which allows the user to edit a profile.
Definition: EditProfileDialog.h:61
Konsole::SearchHistoryTask::setSearchDirection
void setSearchDirection(SearchDirection direction)
Specifies the direction to search in when execute() is called.
Definition: SessionController.cpp:1954
Konsole::TerminalCharacterDecoder
Base class for terminal character decoders.
Definition: TerminalCharacterDecoder.h:45
Konsole::SessionTask::sessions
QList< SessionPtr > sessions() const
Returns a list of sessions in the group.
Definition: SessionController.cpp:1657
Konsole::SessionGroup
Provides a group of sessions which is divided into master and slave sessions.
Definition: Session.h:759
Konsole::SearchHistoryTask::addScreenWindow
void addScreenWindow(Session *session, ScreenWindow *searchWindow)
Adds a screen window to the list to search when execute() is called.
Definition: SessionController.cpp:1793
Konsole::SessionTask::addSession
void addSession(Session *session)
Adds a new session to the group.
Definition: SessionController.cpp:1653
Konsole::ScreenWindow
Provides a window onto a section of a terminal screen.
Definition: ScreenWindow.h:52
Konsole::SearchHistoryTask::ForwardsSearch
Searches forwards through the output, starting at the current selection.
Definition: SessionController.h:489
Konsole::SearchHistoryTask::SearchHistoryTask
SearchHistoryTask(QObject *parent=0)
Constructs a new search task.
Definition: SessionController.cpp:1948
Konsole::SessionController::session
QPointer< Session > session()
Returns the session associated with this controller.
Definition: SessionController.h:108
Konsole::SearchHistoryTask
A task which searches through the output of sessions for matches for a given regular expression...
Definition: SessionController.h:478
Konsole::SearchHistoryTask::execute
virtual void execute()
Performs a search through the session's history, starting at the position of the current selection...
Definition: SessionController.cpp:1797
Konsole::ViewProperties
Encapsulates user-visible information about the terminal session currently being displayed in a view...
Definition: ViewProperties.h:44
Konsole::IncrementalSearchBar
A widget which allows users to search incrementally through a document for a a text string or regular...
Definition: IncrementalSearchBar.h:56
Konsole::RegExpFilter
A filter which searches for sections of text matching a regular expression and creates a new RegExpFi...
Definition: Filter.h:182
Konsole::SessionPtr
QPointer< Session > SessionPtr
Definition: SessionController.h:68
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
Konsole::UrlFilter
A filter which matches URLs in blocks of text.
Definition: Filter.h:239
Konsole::SaveHistoryTask::execute
virtual void execute()
Opens a save file dialog for each session in the group and begins saving each session's history to th...
Definition: SessionController.cpp:1670
Konsole::SearchHistoryTask::SearchDirection
SearchDirection
This enum describes the strategies available for searching through the session's output.
Definition: SessionController.h:487
KONSOLEPRIVATE_EXPORT
#define KONSOLEPRIVATE_EXPORT
Definition: konsole_export.h:33
Konsole::SaveHistoryTask
A task which prompts for a URL for each session and saves that session's output to the given URL...
Definition: SessionController.h:426
Konsole::SearchHistoryTask::setRegExp
void setRegExp(const QRegExp &regExp)
Sets the regular expression which is searched for when execute() is called.
Definition: SessionController.cpp:1966
Konsole::TerminalDisplay
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalDisplay.h:63
Konsole::SessionTask::setAutoDelete
void setAutoDelete(bool enable)
Sets whether the task automatically deletes itself when the task has been finished.
Definition: SessionController.cpp:1645
Konsole::SessionTask::autoDelete
bool autoDelete() const
Returns true if the task automatically deletes itself.
Definition: SessionController.cpp:1649
Konsole::SessionTask::completed
void completed(bool success)
Emitted when the task has completed.
Konsole::SessionController::CopyInputToEnum
CopyInputToEnum
Definition: SessionController.h:90
ViewProperties.h
Profile.h
Konsole::SessionController::isValid
bool isValid() const
Returns true if the controller is valid.
Definition: SessionController.h:363
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Applications
  •   Libraries
  •     libkonq
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal