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

Konsole

  • kde-4.14
  • 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 selectLine();
229  void pasteFromX11Selection(); // shortcut only
230  void copyInputActionsTriggered(QAction* action);
231  void copyInputToAllTabs();
232  void copyInputToSelectedTabs();
233  void copyInputToNone();
234  void editCurrentProfile();
235  void changeCodec(QTextCodec* codec);
236  void enableSearchBar(bool showSearchBar);
237  void searchHistory(bool showSearchBar);
238  void searchBarEvent();
239  void searchFrom();
240  void findNextInHistory();
241  void findPreviousInHistory();
242  void changeSearchMatch();
243  void print_screen();
244  void saveHistory();
245  void showHistoryOptions();
246  void clearHistory();
247  void clearHistoryAndReset();
248  void monitorActivity(bool monitor);
249  void monitorSilence(bool monitor);
250  void renameSession();
251  void switchProfile(Profile::Ptr profile);
252  void handleWebShortcutAction();
253  void configureWebShortcuts();
254  void sendSignal(QAction* action);
255 
256  // other
257  void prepareSwitchProfileMenu();
258  void updateCodecAction();
259  void showDisplayContextMenu(const QPoint& position);
260  void movementKeyFromSearchBarReceived(QKeyEvent *event);
261  void sessionStateChanged(int state);
262  void sessionTitleChanged();
263  void searchTextChanged(const QString& text);
264  void searchCompleted(bool success);
265  void searchClosed(); // called when the user clicks on the
266  // history search bar's close button
267 
268  void interactionHandler();
269  void snapshot(); // called periodically as the user types
270  // to take a snapshot of the state of the
271  // foreground process in the terminal
272 
273  void requireUrlFilterUpdate();
274  void highlightMatches(bool highlight);
275  void scrollBackOptionsChanged(int mode , int lines);
276  void sessionResizeRequest(const QSize& size);
277  void trackOutput(QKeyEvent* event); // move view to end of current output
278  // when a key press occurs in the
279  // display area
280 
281  void updateSearchFilter();
282 
283  void zmodemDownload();
284  void zmodemUpload();
285 
286  /* Returns true if called within a KPart; false if called within Konsole. */
287  bool isKonsolePart() const;
288 
289  // update actions related with selected text
290  void updateCopyAction(const QString& selectedText);
291  void updateWebSearchMenu();
292 
293 private:
294  // begins the search
295  // text - pattern to search for
296  // direction - value from SearchHistoryTask::SearchDirection enum to specify
297  // the search direction
298  void beginSearch(const QString& text , int direction);
299  QRegExp regexpFromSearchBarOptions();
300  bool reverseSearchChecked() const;
301  void setupCommonActions();
302  void setupExtraActions();
303  void removeSearchFilter(); // remove and delete the current search filter if set
304  void setFindNextPrevEnabled(bool enabled);
305  void listenForScreenWindowUpdates();
306 
307 private:
308  void updateSessionIcon();
309 
310  QPointer<Session> _session;
311  QPointer<TerminalDisplay> _view;
312  SessionGroup* _copyToGroup;
313 
314  ProfileList* _profileList;
315 
316  KIcon _sessionIcon;
317  QString _sessionIconName;
318  int _previousState;
319 
320  UrlFilter* _viewUrlFilter;
321  RegExpFilter* _searchFilter;
322 
323  KAction* _copyInputToAllTabsAction;
324 
325  KAction* _findAction;
326  KAction* _findNextAction;
327  KAction* _findPreviousAction;
328 
329  QTimer* _interactionTimer;
330 
331  bool _urlFilterUpdateRequired;
332 
333  int _searchStartLine;
334  int _prevSearchResultLine;
335  QPointer<IncrementalSearchBar> _searchBar;
336 
337  KCodecAction* _codecAction;
338 
339  KActionMenu* _switchProfileMenu;
340  KActionMenu* _webSearchMenu;
341 
342  bool _listenForScreenWindowUpdates;
343  bool _preventClose;
344 
345  bool _keepIconUntilInteraction;
346 
347  QString _selectedText;
348 
349  QAction* _showMenuAction;
350 
351  static QSet<SessionController*> _allControllers;
352  static int _lastControllerId;
353  static const KIcon _activityIcon;
354  static const KIcon _silenceIcon;
355  static const KIcon _broadcastIcon;
356 
357  QStringList _bookmarkValidProgramsToClear;
358 
359  bool _isSearchBarEnabled;
360  QWeakPointer<EditProfileDialog> _editProfileDialog;
361 
362  QString _searchText;
363 };
364 inline bool SessionController::isValid() const
365 {
366  return !_session.isNull() && !_view.isNull();
367 }
368 
378 class SessionTask : public QObject
379 {
380  Q_OBJECT
381 
382 public:
383  explicit SessionTask(QObject* parent = 0);
384 
390  void setAutoDelete(bool enable);
392  bool autoDelete() const;
393 
395  void addSession(Session* session);
396 
402  virtual void execute() = 0;
403 
404 signals:
412  void completed(bool success);
413 
414 protected:
416  QList< SessionPtr > sessions() const;
417 
418 private:
419  bool _autoDelete;
420  QList< SessionPtr > _sessions;
421 };
422 
427 class SaveHistoryTask : public SessionTask
428 {
429  Q_OBJECT
430 
431 public:
433  explicit SaveHistoryTask(QObject* parent = 0);
434  virtual ~SaveHistoryTask();
435 
442  virtual void execute();
443 
444 private slots:
445  void jobDataRequested(KIO::Job* job , QByteArray& data);
446  void jobResult(KJob* job);
447 
448 private:
449  class SaveJob // structure to keep information needed to process
450  // incoming data requests from jobs
451  {
452  public:
453  SessionPtr session; // the session associated with a history save job
454  int lastLineFetched; // the last line processed in the previous data request
455  // set this to -1 at the start of the save job
456 
457  TerminalCharacterDecoder* decoder; // decoder used to convert terminal characters
458  // into output
459  };
460 
461  QHash<KJob*, SaveJob> _jobSession;
462 };
463 
464 //class SearchHistoryThread;
479 class SearchHistoryTask : public SessionTask
480 {
481  Q_OBJECT
482 
483 public:
488  enum SearchDirection {
490  ForwardsSearch,
492  BackwardsSearch
493  };
494 
498  explicit SearchHistoryTask(QObject* parent = 0);
499 
501  void addScreenWindow(Session* session , ScreenWindow* searchWindow);
502 
504  void setRegExp(const QRegExp& regExp);
506  QRegExp regExp() const;
507 
509  void setSearchDirection(SearchDirection direction);
511  SearchDirection searchDirection() const;
512 
514  void setStartLine(int startLine);
515 
526  virtual void execute();
527 
528 private:
529  typedef QPointer<ScreenWindow> ScreenWindowPtr;
530 
531  void executeOnScreenWindow(SessionPtr session , ScreenWindowPtr window);
532  void highlightResult(ScreenWindowPtr window , int position);
533 
534  QMap< SessionPtr , ScreenWindowPtr > _windows;
535  QRegExp _regExp;
536  SearchDirection _direction;
537  int _startLine;
538 
539  //static QPointer<SearchHistoryThread> _thread;
540 };
541 }
542 
543 #endif //SESSIONCONTROLLER_H
544 
Konsole::SaveHistoryTask::SaveHistoryTask
SaveHistoryTask(QObject *parent=0)
Constructs a new task to save session output to URLs.
Definition: SessionController.cpp:1671
Konsole::SessionTask::SessionTask
SessionTask(QObject *parent=0)
Definition: SessionController.cpp:1649
QEvent
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:78
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:1967
Konsole::SearchHistoryTask::BackwardsSearch
Searches backwards through the output, starting at the current selection.
Definition: SessionController.h:492
KXMLGUIClient
Konsole::SearchHistoryTask::regExp
QRegExp regExp() const
Returns the regular expression which is searched for when execute() is called.
Definition: SessionController.cpp:1979
Konsole::SessionTask
Abstract class representing a task which can be performed on a group of sessions. ...
Definition: SessionController.h:378
QByteArray
QMap
QPointer< Session >
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.
QPoint
Konsole::SearchHistoryTask::searchDirection
SearchDirection searchDirection() const
Returns the current search direction.
Definition: SessionController.cpp:1971
Konsole::SaveHistoryTask::~SaveHistoryTask
virtual ~SaveHistoryTask()
Definition: SessionController.cpp:1675
Konsole::EditProfileDialog
A dialog which allows the user to edit a profile.
Definition: EditProfileDialog.h:61
QRegExp
Konsole::SearchHistoryTask::setSearchDirection
void setSearchDirection(SearchDirection direction)
Specifies the direction to search in when execute() is called.
Definition: SessionController.cpp:1963
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:1666
QTimer
Konsole::SessionGroup
Provides a group of sessions which is divided into master and slave sessions.
Definition: Session.h:770
QHash< KJob *, SaveJob >
QObject
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:1802
QPointer::isNull
bool isNull() const
Konsole::SessionTask::addSession
void addSession(Session *session)
Adds a new session to the group.
Definition: SessionController.cpp:1662
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:490
Konsole::SearchHistoryTask::SearchHistoryTask
SearchHistoryTask(QObject *parent=0)
Constructs a new search task.
Definition: SessionController.cpp:1957
Konsole::SessionController::session
QPointer< Session > session()
Returns the session associated with this controller.
Definition: SessionController.h:108
QSet
QString
QList
QTextCodec
Konsole::SearchHistoryTask
A task which searches through the output of sessions for matches for a given regular expression...
Definition: SessionController.h:479
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:1806
QStringList
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
QSize
Konsole::SessionPtr
QPointer< Session > SessionPtr
Definition: SessionController.h:68
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
QKeyEvent
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:1679
Konsole::SearchHistoryTask::SearchDirection
SearchDirection
This enum describes the strategies available for searching through the session's output.
Definition: SessionController.h:488
QAction
KONSOLEPRIVATE_EXPORT
#define KONSOLEPRIVATE_EXPORT
Definition: konsole_export.h:33
QWeakPointer
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:427
Konsole::SearchHistoryTask::setRegExp
void setRegExp(const QRegExp &regExp)
Sets the regular expression which is searched for when execute() is called.
Definition: SessionController.cpp:1975
QObject::parent
QObject * parent() const
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:1654
Konsole::SessionTask::autoDelete
bool autoDelete() const
Returns true if the task automatically deletes itself.
Definition: SessionController.cpp:1658
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:364
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 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
  • 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