• 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.cpp
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 // Own
22 #include "SessionController.h"
23 
24 // Qt
25 #include <QApplication>
26 #include <QMenu>
27 #include <QtGui/QKeyEvent>
28 #include <QPrinter>
29 #include <QPrintDialog>
30 #include <QPainter>
31 
32 // KDE
33 #include <KAction>
34 #include <KActionMenu>
35 #include <KActionCollection>
36 #include <KIcon>
37 #include <KLocalizedString>
38 #include <KMenu>
39 #include <KMessageBox>
40 #include <KRun>
41 #include <KShell>
42 #include <KToolInvocation>
43 #include <KStandardDirs>
44 #include <KToggleAction>
45 #include <KSelectAction>
46 #include <KUrl>
47 #include <KXmlGuiWindow>
48 #include <KXMLGUIFactory>
49 #include <KXMLGUIBuilder>
50 #include <KDebug>
51 #include <KUriFilter>
52 #include <KStringHandler>
53 #include <KConfigGroup>
54 #include <KGlobal>
55 
56 #include <kdeversion.h>
57 #if KDE_IS_VERSION(4, 9, 1)
58 #include <KCodecAction>
59 #else
60 #include <kcodecaction.h>
61 #endif
62 
63 // Konsole
64 #include "EditProfileDialog.h"
65 #include "CopyInputDialog.h"
66 #include "Emulation.h"
67 #include "Filter.h"
68 #include "History.h"
69 #include "HistorySizeDialog.h"
70 #include "IncrementalSearchBar.h"
71 #include "RenameTabDialog.h"
72 #include "ScreenWindow.h"
73 #include "Session.h"
74 #include "ProfileList.h"
75 #include "TerminalDisplay.h"
76 #include "SessionManager.h"
77 #include "Enumeration.h"
78 #include "PrintOptions.h"
79 
80 // for SaveHistoryTask
81 #include <KFileDialog>
82 #include <KIO/Job>
83 #include <KJob>
84 #include "TerminalCharacterDecoder.h"
85 
86 // For Unix signal names
87 #include <signal.h>
88 
89 using namespace Konsole;
90 
91 // TODO - Replace the icon choices below when suitable icons for silence and
92 // activity are available
93 const KIcon SessionController::_activityIcon("dialog-information");
94 const KIcon SessionController::_silenceIcon("dialog-information");
95 const KIcon SessionController::_broadcastIcon("emblem-important");
96 
97 QSet<SessionController*> SessionController::_allControllers;
98 int SessionController::_lastControllerId;
99 
100 SessionController::SessionController(Session* session , TerminalDisplay* view, QObject* parent)
101  : ViewProperties(parent)
102  , KXMLGUIClient()
103  , _session(session)
104  , _view(view)
105  , _copyToGroup(0)
106  , _profileList(0)
107  , _previousState(-1)
108  , _viewUrlFilter(0)
109  , _searchFilter(0)
110  , _copyInputToAllTabsAction(0)
111  , _findAction(0)
112  , _findNextAction(0)
113  , _findPreviousAction(0)
114  , _urlFilterUpdateRequired(false)
115  , _searchStartLine(0)
116  , _prevSearchResultLine(0)
117  , _searchBar(0)
118  , _codecAction(0)
119  , _switchProfileMenu(0)
120  , _webSearchMenu(0)
121  , _listenForScreenWindowUpdates(false)
122  , _preventClose(false)
123  , _keepIconUntilInteraction(false)
124  , _showMenuAction(0)
125  , _isSearchBarEnabled(false)
126 {
127  Q_ASSERT(session);
128  Q_ASSERT(view);
129 
130  // handle user interface related to session (menus etc.)
131  if (isKonsolePart()) {
132  setXMLFile("konsole/partui.rc");
133  setupCommonActions();
134  } else {
135  setXMLFile("konsole/sessionui.rc");
136  setupCommonActions();
137  setupExtraActions();
138  }
139 
140  actionCollection()->addAssociatedWidget(view);
141  foreach(QAction * action, actionCollection()->actions()) {
142  action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
143  }
144 
145  setIdentifier(++_lastControllerId);
146  sessionTitleChanged();
147 
148  view->installEventFilter(this);
149  view->setSessionController(this);
150 
151  // listen for session resize requests
152  connect(_session, SIGNAL(resizeRequest(QSize)), this,
153  SLOT(sessionResizeRequest(QSize)));
154 
155  // listen for popup menu requests
156  connect(_view, SIGNAL(configureRequest(QPoint)), this,
157  SLOT(showDisplayContextMenu(QPoint)));
158 
159  // move view to newest output when keystrokes occur
160  connect(_view, SIGNAL(keyPressedSignal(QKeyEvent*)), this,
161  SLOT(trackOutput(QKeyEvent*)));
162 
163  // listen to activity / silence notifications from session
164  connect(_session, SIGNAL(stateChanged(int)), this,
165  SLOT(sessionStateChanged(int)));
166  // listen to title and icon changes
167  connect(_session, SIGNAL(titleChanged()), this, SLOT(sessionTitleChanged()));
168 
169  connect(_session , SIGNAL(currentDirectoryChanged(QString)) ,
170  this , SIGNAL(currentDirectoryChanged(QString)));
171 
172  // listen for color changes
173  connect(_session, SIGNAL(changeBackgroundColorRequest(QColor)), _view, SLOT(setBackgroundColor(QColor)));
174  connect(_session, SIGNAL(changeForegroundColorRequest(QColor)), _view, SLOT(setForegroundColor(QColor)));
175 
176  // update the title when the session starts
177  connect(_session, SIGNAL(started()), this, SLOT(snapshot()));
178 
179  // listen for output changes to set activity flag
180  connect(_session->emulation(), SIGNAL(outputChanged()), this,
181  SLOT(fireActivity()));
182 
183  // listen for detection of ZModem transfer
184  connect(_session, SIGNAL(zmodemDetected()), this, SLOT(zmodemDownload()));
185 
186  // listen for flow control status changes
187  connect(_session, SIGNAL(flowControlEnabledChanged(bool)), _view,
188  SLOT(setFlowControlWarningEnabled(bool)));
189  _view->setFlowControlWarningEnabled(_session->flowControlEnabled());
190 
191  // take a snapshot of the session state every so often when
192  // user activity occurs
193  //
194  // the timer is owned by the session so that it will be destroyed along
195  // with the session
196  _interactionTimer = new QTimer(_session);
197  _interactionTimer->setSingleShot(true);
198  _interactionTimer->setInterval(500);
199  connect(_interactionTimer, SIGNAL(timeout()), this, SLOT(snapshot()));
200  connect(_view, SIGNAL(keyPressedSignal(QKeyEvent*)), this, SLOT(interactionHandler()));
201 
202  // take a snapshot of the session state periodically in the background
203  QTimer* backgroundTimer = new QTimer(_session);
204  backgroundTimer->setSingleShot(false);
205  backgroundTimer->setInterval(2000);
206  connect(backgroundTimer, SIGNAL(timeout()), this, SLOT(snapshot()));
207  backgroundTimer->start();
208 
209  _allControllers.insert(this);
210 
211  // A list of programs that accept Ctrl+C to clear command line used
212  // before outputting bookmark.
213  _bookmarkValidProgramsToClear << "bash" << "fish" << "sh";
214  _bookmarkValidProgramsToClear << "tcsh" << "zsh";
215 }
216 
217 SessionController::~SessionController()
218 {
219  if (_view)
220  _view->setScreenWindow(0);
221 
222  _allControllers.remove(this);
223 
224  if (!_editProfileDialog.isNull()) {
225  delete _editProfileDialog.data();
226  }
227 }
228 void SessionController::trackOutput(QKeyEvent* event)
229 {
230  Q_ASSERT(_view->screenWindow());
231 
232  // jump to the end of the history buffer unless the key pressed
233  // is one of the three main modifiers, as these are used to select
234  // the selection mode (eg. Ctrl+Alt+<Left Click> for column/block selection)
235  switch (event->key()) {
236  case Qt::Key_Shift:
237  case Qt::Key_Control:
238  case Qt::Key_Alt:
239  break;
240  default:
241  _view->screenWindow()->setTrackOutput(true);
242  }
243 }
244 void SessionController::interactionHandler()
245 {
246  // This flag is used to make sure those special icons indicating interest
247  // events (activity/silence/bell?) remain in the tab until user interaction
248  // happens. Otherwise, those special icons will quickly be replaced by
249  // normal icon when ::snapshot() is triggered
250  _keepIconUntilInteraction = false;
251  _interactionTimer->start();
252 }
253 
254 void SessionController::requireUrlFilterUpdate()
255 {
256  // this method is called every time the screen window's output changes, so do not
257  // do anything expensive here.
258 
259  _urlFilterUpdateRequired = true;
260 }
261 void SessionController::snapshot()
262 {
263  Q_ASSERT(_session != 0);
264 
265  QString title = _session->getDynamicTitle();
266  title = title.simplified();
267 
268  // Visualize that the session is broadcasting to others
269  if (_copyToGroup && _copyToGroup->sessions().count() > 1) {
270  title.append('*');
271  }
272 
273  // use the fallback title if needed
274  if (title.isEmpty()) {
275  title = _session->title(Session::NameRole);
276  }
277 
278  // apply new title
279  _session->setTitle(Session::DisplayedTitleRole, title);
280 
281  // do not forget icon
282  updateSessionIcon();
283 }
284 
285 QString SessionController::currentDir() const
286 {
287  return _session->currentWorkingDirectory();
288 }
289 
290 KUrl SessionController::url() const
291 {
292  return _session->getUrl();
293 }
294 
295 void SessionController::rename()
296 {
297  renameSession();
298 }
299 
300 void SessionController::openUrl(const KUrl& url)
301 {
302  // Clear shell's command line
303  if (!_session->isForegroundProcessActive()
304  && _bookmarkValidProgramsToClear.contains(_session->foregroundProcessName())) {
305  _session->emulation()->sendText(QChar(0x03)); // Ctrl+C
306  _session->emulation()->sendText(QChar('\n'));
307  }
308 
309  // handle local paths
310  if (url.isLocalFile()) {
311  QString path = url.toLocalFile();
312  _session->emulation()->sendText("cd " + KShell::quoteArg(path) + '\r');
313  } else if (url.protocol().isEmpty()) {
314  // KUrl couldn't parse what the user entered into the URL field
315  // so just dump it to the shell
316  QString command = url.prettyUrl();
317  if (!command.isEmpty())
318  _session->emulation()->sendText(command + '\r');
319  } else if (url.protocol() == "ssh") {
320  QString sshCommand = "ssh ";
321 
322  if (url.port() > -1) {
323  sshCommand += QString("-p %1 ").arg(url.port());
324  }
325  if (url.hasUser()) {
326  sshCommand += (url.user() + '@');
327  }
328  if (url.hasHost()) {
329  sshCommand += url.host();
330  }
331 
332  _session->sendText(sshCommand + '\r');
333 
334  } else if (url.protocol() == "telnet") {
335  QString telnetCommand = "telnet ";
336 
337  if (url.hasUser()) {
338  telnetCommand += QString("-l %1 ").arg(url.user());
339  }
340  if (url.hasHost()) {
341  telnetCommand += (url.host() + ' ');
342  }
343  if (url.port() > -1) {
344  telnetCommand += QString::number(url.port());
345  }
346 
347  _session->sendText(telnetCommand + '\r');
348 
349  } else {
350  //TODO Implement handling for other Url types
351 
352  KMessageBox::sorry(_view->window(),
353  i18n("Konsole does not know how to open the bookmark: ") +
354  url.prettyUrl());
355 
356  kWarning() << "Unable to open bookmark at url" << url << ", I do not know"
357  << " how to handle the protocol " << url.protocol();
358  }
359 }
360 
361 void SessionController::setupPrimaryScreenSpecificActions(bool use)
362 {
363  KActionCollection* collection = actionCollection();
364  QAction* clearAction = collection->action("clear-history");
365  QAction* resetAction = collection->action("clear-history-and-reset");
366  QAction* selectAllAction = collection->action("select-all");
367 
368  // these actions are meaningful only when primary screen is used.
369  clearAction->setEnabled(use);
370  resetAction->setEnabled(use);
371  selectAllAction->setEnabled(use);
372 }
373 
374 void SessionController::selectionChanged(const QString& selectedText)
375 {
376  _selectedText = selectedText;
377  updateCopyAction(selectedText);
378 }
379 
380 void SessionController::updateCopyAction(const QString& selectedText)
381 {
382  QAction* copyAction = actionCollection()->action("edit_copy");
383 
384  // copy action is meaningful only when some text is selected.
385  copyAction->setEnabled(!selectedText.isEmpty());
386 }
387 
388 void SessionController::updateWebSearchMenu()
389 {
390  // reset
391  _webSearchMenu->setVisible(false);
392  _webSearchMenu->menu()->clear();
393 
394  if (_selectedText.isEmpty())
395  return;
396 
397  QString searchText = _selectedText;
398  searchText = searchText.replace('\n', ' ').replace('\r', ' ').simplified();
399 
400  if (searchText.isEmpty())
401  return;
402 
403  KUriFilterData filterData(searchText);
404  filterData.setSearchFilteringOptions(KUriFilterData::RetrievePreferredSearchProvidersOnly);
405 
406  if (KUriFilter::self()->filterSearchUri(filterData, KUriFilter::NormalTextFilter)) {
407  const QStringList searchProviders = filterData.preferredSearchProviders();
408  if (!searchProviders.isEmpty()) {
409  _webSearchMenu->setText(i18n("Search for '%1' with", KStringHandler::rsqueeze(searchText, 16)));
410 
411  KAction* action = 0;
412 
413  foreach(const QString& searchProvider, searchProviders) {
414  action = new KAction(searchProvider, _webSearchMenu);
415  action->setIcon(KIcon(filterData.iconNameForPreferredSearchProvider(searchProvider)));
416  action->setData(filterData.queryForPreferredSearchProvider(searchProvider));
417  connect(action, SIGNAL(triggered()), this, SLOT(handleWebShortcutAction()));
418  _webSearchMenu->addAction(action);
419  }
420 
421  _webSearchMenu->addSeparator();
422 
423  action = new KAction(i18n("Configure Web Shortcuts..."), _webSearchMenu);
424  action->setIcon(KIcon("configure"));
425  connect(action, SIGNAL(triggered()), this, SLOT(configureWebShortcuts()));
426  _webSearchMenu->addAction(action);
427 
428  _webSearchMenu->setVisible(true);
429  }
430  }
431 }
432 
433 void SessionController::handleWebShortcutAction()
434 {
435  KAction* action = qobject_cast<KAction*>(sender());
436  if (!action)
437  return;
438 
439  KUriFilterData filterData(action->data().toString());
440 
441  if (KUriFilter::self()->filterUri(filterData, QStringList() << "kurisearchfilter")) {
442  const KUrl& url = filterData.uri();
443  new KRun(url, QApplication::activeWindow());
444  }
445 }
446 
447 void SessionController::configureWebShortcuts()
448 {
449  KToolInvocation::kdeinitExec("kcmshell4", QStringList() << "ebrowsing");
450 }
451 
452 void SessionController::sendSignal(QAction* action)
453 {
454  const int signal = action->data().value<int>();
455  _session->sendSignal(signal);
456 }
457 
458 bool SessionController::eventFilter(QObject* watched , QEvent* event)
459 {
460  if (watched == _view) {
461  if (event->type() == QEvent::FocusIn) {
462  // notify the world that the view associated with this session has been focused
463  // used by the view manager to update the title of the MainWindow widget containing the view
464  emit focused(this);
465 
466  // when the view is focused, set bell events from the associated session to be delivered
467  // by the focused view
468 
469  // first, disconnect any other views which are listening for bell signals from the session
470  disconnect(_session, SIGNAL(bellRequest(QString)), 0, 0);
471  // second, connect the newly focused view to listen for the session's bell signal
472  connect(_session, SIGNAL(bellRequest(QString)),
473  _view, SLOT(bell(QString)));
474 
475  if (_copyInputToAllTabsAction && _copyInputToAllTabsAction->isChecked()) {
476  // A session with "Copy To All Tabs" has come into focus:
477  // Ensure that newly created sessions are included in _copyToGroup!
478  copyInputToAllTabs();
479  }
480  }
481  // when a mouse move is received, create the URL filter and listen for output changes if
482  // it has not already been created. If it already exists, then update only if the output
483  // has changed since the last update ( _urlFilterUpdateRequired == true )
484  //
485  // also check that no mouse buttons are pressed since the URL filter only applies when
486  // the mouse is hovering over the view
487  if (event->type() == QEvent::MouseMove &&
488  (!_viewUrlFilter || _urlFilterUpdateRequired) &&
489  ((QMouseEvent*)event)->buttons() == Qt::NoButton) {
490  if (_view->screenWindow() && !_viewUrlFilter) {
491  connect(_view->screenWindow(), SIGNAL(scrolled(int)), this,
492  SLOT(requireUrlFilterUpdate()));
493  connect(_view->screenWindow(), SIGNAL(outputChanged()), this,
494  SLOT(requireUrlFilterUpdate()));
495 
496  // install filter on the view to highlight URLs
497  _viewUrlFilter = new UrlFilter();
498  _view->filterChain()->addFilter(_viewUrlFilter);
499  }
500 
501  _view->processFilters();
502  _urlFilterUpdateRequired = false;
503  }
504  }
505 
506  return false;
507 }
508 
509 void SessionController::removeSearchFilter()
510 {
511  if (!_searchFilter)
512  return;
513 
514  _view->filterChain()->removeFilter(_searchFilter);
515  delete _searchFilter;
516  _searchFilter = 0;
517 }
518 
519 void SessionController::setSearchBar(IncrementalSearchBar* searchBar)
520 {
521  // disconnect the existing search bar
522  if (_searchBar) {
523  disconnect(this, 0, _searchBar, 0);
524  disconnect(_searchBar, 0, this, 0);
525  }
526 
527  // connect new search bar
528  _searchBar = searchBar;
529  if (_searchBar) {
530  connect(_searchBar, SIGNAL(unhandledMovementKeyPressed(QKeyEvent*)), this, SLOT(movementKeyFromSearchBarReceived(QKeyEvent*)));
531  connect(_searchBar, SIGNAL(closeClicked()), this, SLOT(searchClosed()));
532  connect(_searchBar, SIGNAL(searchFromClicked()), this, SLOT(searchFrom()));
533  connect(_searchBar, SIGNAL(findNextClicked()), this, SLOT(findNextInHistory()));
534  connect(_searchBar, SIGNAL(findPreviousClicked()), this, SLOT(findPreviousInHistory()));
535  connect(_searchBar, SIGNAL(highlightMatchesToggled(bool)) , this , SLOT(highlightMatches(bool)));
536  connect(_searchBar, SIGNAL(matchCaseToggled(bool)), this, SLOT(changeSearchMatch()));
537 
538  // if the search bar was previously active
539  // then re-enter search mode
540  enableSearchBar(_isSearchBarEnabled);
541  }
542 }
543 IncrementalSearchBar* SessionController::searchBar() const
544 {
545  return _searchBar;
546 }
547 
548 void SessionController::setShowMenuAction(QAction* action)
549 {
550  _showMenuAction = action;
551 }
552 
553 void SessionController::setupCommonActions()
554 {
555  KAction* action = 0;
556  KActionCollection* collection = actionCollection();
557 
558  // Close Session
559  action = collection->addAction("close-session", this, SLOT(closeSession()));
560  if (isKonsolePart())
561  action->setText(i18n("&Close Session"));
562  else
563  action->setText(i18n("&Close Tab"));
564 
565  action->setIcon(KIcon("tab-close"));
566  action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
567 
568  // Open Browser
569  action = collection->addAction("open-browser", this, SLOT(openBrowser()));
570  action->setText(i18n("Open File Manager"));
571  action->setIcon(KIcon("system-file-manager"));
572 
573  // Copy and Paste
574  action = KStandardAction::copy(this, SLOT(copy()), collection);
575  action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_C));
576  // disabled at first, since nothing has been selected now
577  action->setEnabled(false);
578 
579  action = KStandardAction::paste(this, SLOT(paste()), collection);
580  KShortcut pasteShortcut = action->shortcut();
581  pasteShortcut.setPrimary(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_V));
582  pasteShortcut.setAlternate(QKeySequence(Qt::SHIFT + Qt::Key_Insert));
583  action->setShortcut(pasteShortcut);
584 
585  action = collection->addAction("paste-selection", this, SLOT(pasteFromX11Selection()));
586  action->setText(i18n("Paste Selection"));
587  action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Insert));
588 
589  _webSearchMenu = new KActionMenu(i18n("Web Search"), this);
590  _webSearchMenu->setIcon(KIcon("preferences-web-browser-shortcuts"));
591  _webSearchMenu->setVisible(false);
592  collection->addAction("web-search", _webSearchMenu);
593 
594 
595  action = collection->addAction("select-all", this, SLOT(selectAll()));
596  action->setText(i18n("&Select All"));
597  action->setIcon(KIcon("edit-select-all"));
598 
599  action = KStandardAction::saveAs(this, SLOT(saveHistory()), collection);
600  action->setText(i18n("Save Output &As..."));
601 
602  action = KStandardAction::print(this, SLOT(print_screen()), collection);
603  action->setText(i18n("&Print Screen..."));
604  action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_P));
605 
606  action = collection->addAction("adjust-history", this, SLOT(showHistoryOptions()));
607  action->setText(i18n("Adjust Scrollback..."));
608  action->setIcon(KIcon("configure"));
609 
610  action = collection->addAction("clear-history", this, SLOT(clearHistory()));
611  action->setText(i18n("Clear Scrollback"));
612  action->setIcon(KIcon("edit-clear-history"));
613 
614  action = collection->addAction("clear-history-and-reset", this, SLOT(clearHistoryAndReset()));
615  action->setText(i18n("Clear Scrollback and Reset"));
616  action->setIcon(KIcon("edit-clear-history"));
617  action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_K));
618 
619  // Profile Options
620  action = collection->addAction("edit-current-profile", this, SLOT(editCurrentProfile()));
621  action->setText(i18n("Edit Current Profile..."));
622  action->setIcon(KIcon("document-properties"));
623 
624  _switchProfileMenu = new KActionMenu(i18n("Switch Profile"), this);
625  collection->addAction("switch-profile", _switchProfileMenu);
626  connect(_switchProfileMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(prepareSwitchProfileMenu()));
627 
628  // History
629  _findAction = KStandardAction::find(this, SLOT(searchBarEvent()), collection);
630  _findAction->setShortcut(QKeySequence());
631 
632  _findNextAction = KStandardAction::findNext(this, SLOT(findNextInHistory()), collection);
633  _findNextAction->setShortcut(QKeySequence());
634  _findNextAction->setEnabled(false);
635 
636  _findPreviousAction = KStandardAction::findPrev(this, SLOT(findPreviousInHistory()), collection);
637  _findPreviousAction->setShortcut(QKeySequence());
638  _findPreviousAction->setEnabled(false);
639 
640  // Character Encoding
641  _codecAction = new KCodecAction(i18n("Set &Encoding"), this);
642  _codecAction->setIcon(KIcon("character-set"));
643  collection->addAction("set-encoding", _codecAction);
644  connect(_codecAction->menu(), SIGNAL(aboutToShow()), this, SLOT(updateCodecAction()));
645  connect(_codecAction, SIGNAL(triggered(QTextCodec*)), this, SLOT(changeCodec(QTextCodec*)));
646 }
647 
648 void SessionController::setupExtraActions()
649 {
650  KAction* action = 0;
651  KToggleAction* toggleAction = 0;
652  KActionCollection* collection = actionCollection();
653 
654  // Rename Session
655  action = collection->addAction("rename-session", this, SLOT(renameSession()));
656  action->setText(i18n("&Rename Tab..."));
657  action->setIcon(KIcon("edit-rename"));
658  action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S));
659 
660  // Copy input to ==> all tabs
661  KToggleAction* copyInputToAllTabsAction = collection->add<KToggleAction>("copy-input-to-all-tabs");
662  copyInputToAllTabsAction->setText(i18n("&All Tabs in Current Window"));
663  copyInputToAllTabsAction->setData(CopyInputToAllTabsMode);
664  // this action is also used in other place, so remember it
665  _copyInputToAllTabsAction = copyInputToAllTabsAction;
666 
667  // Copy input to ==> selected tabs
668  KToggleAction* copyInputToSelectedTabsAction = collection->add<KToggleAction>("copy-input-to-selected-tabs");
669  copyInputToSelectedTabsAction->setText(i18n("&Select Tabs..."));
670  copyInputToSelectedTabsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Period));
671  copyInputToSelectedTabsAction->setData(CopyInputToSelectedTabsMode);
672 
673  // Copy input to ==> none
674  KToggleAction* copyInputToNoneAction = collection->add<KToggleAction>("copy-input-to-none");
675  copyInputToNoneAction->setText(i18nc("@action:inmenu Do not select any tabs", "&None"));
676  copyInputToNoneAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Slash));
677  copyInputToNoneAction->setData(CopyInputToNoneMode);
678  copyInputToNoneAction->setChecked(true); // the default state
679 
680  // The "Copy Input To" submenu
681  // The above three choices are represented as combo boxes
682  KSelectAction* copyInputActions = collection->add<KSelectAction>("copy-input-to");
683  copyInputActions->setText(i18n("Copy Input To"));
684  copyInputActions->addAction(copyInputToAllTabsAction);
685  copyInputActions->addAction(copyInputToSelectedTabsAction);
686  copyInputActions->addAction(copyInputToNoneAction);
687  connect(copyInputActions, SIGNAL(triggered(QAction*)), this, SLOT(copyInputActionsTriggered(QAction*)));
688 
689  action = collection->addAction("zmodem-upload", this, SLOT(zmodemUpload()));
690  action->setText(i18n("&ZModem Upload..."));
691  action->setIcon(KIcon("document-open"));
692  action->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_U));
693 
694  // Monitor
695  toggleAction = new KToggleAction(i18n("Monitor for &Activity"), this);
696  toggleAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_A));
697  action = collection->addAction("monitor-activity", toggleAction);
698  connect(action, SIGNAL(toggled(bool)), this, SLOT(monitorActivity(bool)));
699 
700  toggleAction = new KToggleAction(i18n("Monitor for &Silence"), this);
701  toggleAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
702  action = collection->addAction("monitor-silence", toggleAction);
703  connect(action, SIGNAL(toggled(bool)), this, SLOT(monitorSilence(bool)));
704 
705  // Text Size
706  action = collection->addAction("enlarge-font", this, SLOT(increaseFontSize()));
707  action->setText(i18n("Enlarge Font"));
708  action->setIcon(KIcon("format-font-size-more"));
709  KShortcut enlargeFontShortcut = action->shortcut();
710  enlargeFontShortcut.setPrimary(QKeySequence(Qt::CTRL + Qt::Key_Plus));
711  enlargeFontShortcut.setAlternate(QKeySequence(Qt::CTRL + Qt::Key_Equal));
712  action->setShortcut(enlargeFontShortcut);
713 
714  action = collection->addAction("shrink-font", this, SLOT(decreaseFontSize()));
715  action->setText(i18n("Shrink Font"));
716  action->setIcon(KIcon("format-font-size-less"));
717  action->setShortcut(KShortcut(Qt::CTRL | Qt::Key_Minus));
718 
719  // Send signal
720  KSelectAction* sendSignalActions = collection->add<KSelectAction>("send-signal");
721  sendSignalActions->setText(i18n("Send Signal"));
722  connect(sendSignalActions, SIGNAL(triggered(QAction*)), this, SLOT(sendSignal(QAction*)));
723 
724  action = collection->addAction("sigstop-signal");
725  action->setText(i18n("&Suspend Task") + " (STOP)");
726  action->setData(SIGSTOP);
727  sendSignalActions->addAction(action);
728 
729  action = collection->addAction("sigcont-signal");
730  action->setText(i18n("&Continue Task") + " (CONT)");
731  action->setData(SIGCONT);
732  sendSignalActions->addAction(action);
733 
734  action = collection->addAction("sighup-signal");
735  action->setText(i18n("&Hangup") + " (HUP)");
736  action->setData(SIGHUP);
737  sendSignalActions->addAction(action);
738 
739  action = collection->addAction("sigint-signal");
740  action->setText(i18n("&Interrupt Task") + " (INT)");
741  action->setData(SIGINT);
742  sendSignalActions->addAction(action);
743 
744  action = collection->addAction("sigterm-signal");
745  action->setText(i18n("&Terminate Task") + " (TERM)");
746  action->setData(SIGTERM);
747  sendSignalActions->addAction(action);
748 
749  action = collection->addAction("sigkill-signal");
750  action->setText(i18n("&Kill Task") + " (KILL)");
751  action->setData(SIGKILL);
752  sendSignalActions->addAction(action);
753 
754  action = collection->addAction("sigusr1-signal");
755  action->setText(i18n("User Signal &1") + " (USR1)");
756  action->setData(SIGUSR1);
757  sendSignalActions->addAction(action);
758 
759  action = collection->addAction("sigusr2-signal");
760  action->setText(i18n("User Signal &2") + " (USR2)");
761  action->setData(SIGUSR2);
762  sendSignalActions->addAction(action);
763 
764  _findAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_F));
765  _findNextAction->setShortcut(QKeySequence(Qt::Key_F3));
766  _findPreviousAction->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F3));
767 }
768 
769 void SessionController::switchProfile(Profile::Ptr profile)
770 {
771  SessionManager::instance()->setSessionProfile(_session, profile);
772 }
773 
774 void SessionController::prepareSwitchProfileMenu()
775 {
776  if (_switchProfileMenu->menu()->isEmpty()) {
777  _profileList = new ProfileList(false, this);
778  connect(_profileList, SIGNAL(profileSelected(Profile::Ptr)), this, SLOT(switchProfile(Profile::Ptr)));
779  }
780 
781  _switchProfileMenu->menu()->clear();
782  _switchProfileMenu->menu()->addActions(_profileList->actions());
783 }
784 void SessionController::updateCodecAction()
785 {
786  _codecAction->setCurrentCodec(QString(_session->codec()));
787 }
788 
789 void SessionController::changeCodec(QTextCodec* codec)
790 {
791  _session->setCodec(codec);
792 }
793 
794 EditProfileDialog* SessionController::profileDialogPointer()
795 {
796  return _editProfileDialog.data();
797 }
798 
799 void SessionController::editCurrentProfile()
800 {
801  // Searching for Edit profile dialog opened with the same profile
802  foreach (SessionController* session, _allControllers.values()) {
803  if (session->profileDialogPointer()
804  && session->profileDialogPointer()->isVisible()
805  && session->profileDialogPointer()->lookupProfile() == SessionManager::instance()->sessionProfile(_session)) {
806  session->profileDialogPointer()->close();
807  }
808  }
809 
810  // NOTE bug311270: For to prevent the crash, the profile must be reset.
811  if (!_editProfileDialog.isNull()) {
812  // exists but not visible
813  delete _editProfileDialog.data();
814  }
815 
816  _editProfileDialog = new EditProfileDialog(QApplication::activeWindow());
817  _editProfileDialog.data()->setProfile(SessionManager::instance()->sessionProfile(_session));
818  _editProfileDialog.data()->show();
819 }
820 
821 void SessionController::renameSession()
822 {
823  QScopedPointer<RenameTabDialog> dialog(new RenameTabDialog(QApplication::activeWindow()));
824  dialog->setTabTitleText(_session->tabTitleFormat(Session::LocalTabTitle));
825  dialog->setRemoteTabTitleText(_session->tabTitleFormat(Session::RemoteTabTitle));
826 
827  if (_session->isRemote()) {
828  dialog->focusRemoteTabTitleText();
829  } else {
830  dialog->focusTabTitleText();
831  }
832 
833  QPointer<Session> guard(_session);
834  int result = dialog->exec();
835  if (!guard)
836  return;
837 
838  if (result) {
839  QString tabTitle = dialog->tabTitleText();
840  QString remoteTabTitle = dialog->remoteTabTitleText();
841 
842  _session->setTabTitleFormat(Session::LocalTabTitle, tabTitle);
843  _session->setTabTitleFormat(Session::RemoteTabTitle, remoteTabTitle);
844 
845  // trigger an update of the tab text
846  snapshot();
847  }
848 }
849 
850 bool SessionController::confirmClose() const
851 {
852  if (_session->isForegroundProcessActive()) {
853  QString title = _session->foregroundProcessName();
854 
855  // hard coded for now. In future make it possible for the user to specify which programs
856  // are ignored when considering whether to display a confirmation
857  QStringList ignoreList;
858  ignoreList << QString(qgetenv("SHELL")).section('/', -1);
859  if (ignoreList.contains(title))
860  return true;
861 
862  QString question;
863  if (title.isEmpty())
864  question = i18n("A program is currently running in this session."
865  " Are you sure you want to close it?");
866  else
867  question = i18n("The program '%1' is currently running in this session."
868  " Are you sure you want to close it?", title);
869 
870  int result = KMessageBox::warningYesNo(_view->window(), question, i18n("Confirm Close"));
871  return (result == KMessageBox::Yes) ? true : false;
872  }
873  return true;
874 }
875 bool SessionController::confirmForceClose() const
876 {
877  if (_session->isRunning()) {
878  QString title = _session->program();
879 
880  // hard coded for now. In future make it possible for the user to specify which programs
881  // are ignored when considering whether to display a confirmation
882  QStringList ignoreList;
883  ignoreList << QString(qgetenv("SHELL")).section('/', -1);
884  if (ignoreList.contains(title))
885  return true;
886 
887  QString question;
888  if (title.isEmpty())
889  question = i18n("A program in this session would not die."
890  " Are you sure you want to kill it by force?");
891  else
892  question = i18n("The program '%1' is in this session would not die."
893  " Are you sure you want to kill it by force?", title);
894 
895  int result = KMessageBox::warningYesNo(_view->window(), question, i18n("Confirm Close"));
896  return (result == KMessageBox::Yes) ? true : false;
897  }
898  return true;
899 }
900 void SessionController::closeSession()
901 {
902  if (_preventClose)
903  return;
904 
905  if (confirmClose()) {
906  if (_session->closeInNormalWay()) {
907  return;
908  } else if (confirmForceClose()) {
909  if (_session->closeInForceWay())
910  return;
911  else
912  kWarning() << "Konsole failed to close a session in any way.";
913  }
914  }
915 }
916 
917 // Trying to open a remote Url may produce unexpected results.
918 // Therefore, if a remote url, open the user's home path.
919 // TODO consider: 1) disable menu upon remote session
920 // 2) transform url to get the desired result (ssh -> sftp, etc)
921 void SessionController::openBrowser()
922 {
923  KUrl currentUrl = url();
924 
925  if (currentUrl.isLocalFile())
926  new KRun(currentUrl, QApplication::activeWindow(), 0, true, true);
927  else
928  new KRun(KUrl(QDir::homePath()), QApplication::activeWindow(), 0, true, true);
929 }
930 
931 void SessionController::copy()
932 {
933  _view->copyToClipboard();
934 }
935 
936 void SessionController::paste()
937 {
938  _view->pasteFromClipboard();
939 }
940 void SessionController::pasteFromX11Selection()
941 {
942  _view->pasteFromX11Selection();
943 }
944 void SessionController::selectAll()
945 {
946  ScreenWindow * screenWindow = _view->screenWindow();
947  screenWindow->setSelectionByLineRange(0, _session->emulation()->lineCount());
948  _view->copyToX11Selection();
949 }
950 static const KXmlGuiWindow* findWindow(const QObject* object)
951 {
952  // Walk up the QObject hierarchy to find a KXmlGuiWindow.
953  while (object != 0) {
954  const KXmlGuiWindow* window = qobject_cast<const KXmlGuiWindow*>(object);
955  if (window != 0) {
956  return(window);
957  }
958  object = object->parent();
959  }
960  return(0);
961 }
962 
963 static bool hasTerminalDisplayInSameWindow(const Session* session, const KXmlGuiWindow* window)
964 {
965  // Iterate all TerminalDisplays of this Session ...
966  foreach(const TerminalDisplay* terminalDisplay, session->views()) {
967  // ... and check whether a TerminalDisplay has the same
968  // window as given in the parameter
969  if (window == findWindow(terminalDisplay)) {
970  return(true);
971  }
972  }
973  return(false);
974 }
975 
976 void SessionController::copyInputActionsTriggered(QAction* action)
977 {
978  const int mode = action->data().value<int>();
979 
980  switch (mode) {
981  case CopyInputToAllTabsMode:
982  copyInputToAllTabs();
983  break;
984  case CopyInputToSelectedTabsMode:
985  copyInputToSelectedTabs();
986  break;
987  case CopyInputToNoneMode:
988  copyInputToNone();
989  break;
990  default:
991  Q_ASSERT(false);
992  }
993 }
994 
995 void SessionController::copyInputToAllTabs()
996 {
997  if (!_copyToGroup) {
998  _copyToGroup = new SessionGroup(this);
999  }
1000 
1001  // Find our window ...
1002  const KXmlGuiWindow* myWindow = findWindow(_view);
1003 
1004  QSet<Session*> group =
1005  QSet<Session*>::fromList(SessionManager::instance()->sessions());
1006  for (QSet<Session*>::iterator iterator = group.begin();
1007  iterator != group.end(); ++iterator) {
1008  Session* session = *iterator;
1009 
1010  // First, ensure that the session is removed
1011  // (necessary to avoid duplicates on addSession()!)
1012  _copyToGroup->removeSession(session);
1013 
1014  // Add current session if it is displayed our window
1015  if (hasTerminalDisplayInSameWindow(session, myWindow)) {
1016  _copyToGroup->addSession(session);
1017  }
1018  }
1019  _copyToGroup->setMasterStatus(_session, true);
1020  _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
1021 
1022  snapshot();
1023 }
1024 
1025 void SessionController::copyInputToSelectedTabs()
1026 {
1027  if (!_copyToGroup) {
1028  _copyToGroup = new SessionGroup(this);
1029  _copyToGroup->addSession(_session);
1030  _copyToGroup->setMasterStatus(_session, true);
1031  _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
1032  }
1033 
1034  QPointer<CopyInputDialog> dialog = new CopyInputDialog(_view);
1035  dialog->setMasterSession(_session);
1036 
1037  QSet<Session*> currentGroup = QSet<Session*>::fromList(_copyToGroup->sessions());
1038  currentGroup.remove(_session);
1039 
1040  dialog->setChosenSessions(currentGroup);
1041 
1042  QPointer<Session> guard(_session);
1043  int result = dialog->exec();
1044  if (!guard)
1045  return;
1046 
1047  if (result == QDialog::Accepted) {
1048  QSet<Session*> newGroup = dialog->chosenSessions();
1049  newGroup.remove(_session);
1050 
1051  QSet<Session*> completeGroup = newGroup | currentGroup;
1052  foreach(Session * session, completeGroup) {
1053  if (newGroup.contains(session) && !currentGroup.contains(session))
1054  _copyToGroup->addSession(session);
1055  else if (!newGroup.contains(session) && currentGroup.contains(session))
1056  _copyToGroup->removeSession(session);
1057  }
1058 
1059  _copyToGroup->setMasterStatus(_session, true);
1060  _copyToGroup->setMasterMode(SessionGroup::CopyInputToAll);
1061  snapshot();
1062  }
1063 }
1064 
1065 void SessionController::copyInputToNone()
1066 {
1067  if (!_copyToGroup) // No 'Copy To' is active
1068  return;
1069 
1070  QSet<Session*> group =
1071  QSet<Session*>::fromList(SessionManager::instance()->sessions());
1072  for (QSet<Session*>::iterator iterator = group.begin();
1073  iterator != group.end(); ++iterator) {
1074  Session* session = *iterator;
1075 
1076  if (session != _session) {
1077  _copyToGroup->removeSession(*iterator);
1078  }
1079  }
1080  delete _copyToGroup;
1081  _copyToGroup = 0;
1082  snapshot();
1083 }
1084 
1085 void SessionController::searchClosed()
1086 {
1087  _isSearchBarEnabled = false;
1088  searchHistory(false);
1089 }
1090 
1091 void SessionController::setSearchStartToWindowCurrentLine()
1092 {
1093  setSearchStartTo(-1);
1094 }
1095 
1096 void SessionController::setSearchStartTo(int line)
1097 {
1098  _searchStartLine = line;
1099  _prevSearchResultLine = line;
1100 }
1101 
1102 void SessionController::listenForScreenWindowUpdates()
1103 {
1104  if (_listenForScreenWindowUpdates)
1105  return;
1106 
1107  connect(_view->screenWindow(), SIGNAL(outputChanged()), this,
1108  SLOT(updateSearchFilter()));
1109  connect(_view->screenWindow(), SIGNAL(scrolled(int)), this,
1110  SLOT(updateSearchFilter()));
1111  connect(_view->screenWindow(), SIGNAL(currentResultLineChanged()), _view,
1112  SLOT(update()));
1113 
1114  _listenForScreenWindowUpdates = true;
1115 }
1116 
1117 void SessionController::updateSearchFilter()
1118 {
1119  if (_searchFilter && _searchBar) {
1120  _view->processFilters();
1121  }
1122 }
1123 
1124 void SessionController::searchBarEvent()
1125 {
1126  QString selectedText = _view->screenWindow()->selectedText(true, true);
1127  if (!selectedText.isEmpty())
1128  _searchBar->setSearchText(selectedText);
1129 
1130  if (_searchBar->isVisible()) {
1131  _searchBar->focusLineEdit();
1132  } else {
1133  searchHistory(true);
1134  _isSearchBarEnabled = true;
1135  }
1136 }
1137 
1138 void SessionController::enableSearchBar(bool showSearchBar)
1139 {
1140  if (!_searchBar)
1141  return;
1142 
1143  if (showSearchBar && !_searchBar->isVisible()) {
1144  setSearchStartToWindowCurrentLine();
1145  }
1146 
1147  _searchBar->setVisible(showSearchBar);
1148  if (showSearchBar) {
1149  connect(_searchBar, SIGNAL(searchChanged(QString)), this,
1150  SLOT(searchTextChanged(QString)));
1151  connect(_searchBar, SIGNAL(searchReturnPressed(QString)), this,
1152  SLOT(findPreviousInHistory()));
1153  connect(_searchBar, SIGNAL(searchShiftPlusReturnPressed()), this,
1154  SLOT(findNextInHistory()));
1155  } else {
1156  disconnect(_searchBar, SIGNAL(searchChanged(QString)), this,
1157  SLOT(searchTextChanged(QString)));
1158  disconnect(_searchBar, SIGNAL(searchReturnPressed(QString)), this,
1159  SLOT(findPreviousInHistory()));
1160  disconnect(_searchBar, SIGNAL(searchShiftPlusReturnPressed()), this,
1161  SLOT(findNextInHistory()));
1162  if (_view && _view->screenWindow()) {
1163  _view->screenWindow()->setCurrentResultLine(-1);
1164  }
1165  }
1166 }
1167 
1168 
1169 bool SessionController::reverseSearchChecked() const
1170 {
1171  Q_ASSERT(_searchBar);
1172 
1173  QBitArray options = _searchBar->optionsChecked();
1174  return options.at(IncrementalSearchBar::ReverseSearch);
1175 }
1176 
1177 QRegExp SessionController::regexpFromSearchBarOptions()
1178 {
1179  QBitArray options = _searchBar->optionsChecked();
1180 
1181  Qt::CaseSensitivity caseHandling = options.at(IncrementalSearchBar::MatchCase) ? Qt::CaseSensitive : Qt::CaseInsensitive;
1182  QRegExp::PatternSyntax syntax = options.at(IncrementalSearchBar::RegExp) ? QRegExp::RegExp : QRegExp::FixedString;
1183 
1184  QRegExp regExp(_searchBar->searchText(), caseHandling , syntax);
1185  return regExp;
1186 }
1187 
1188 // searchHistory() may be called either as a result of clicking a menu item or
1189 // as a result of changing the search bar widget
1190 void SessionController::searchHistory(bool showSearchBar)
1191 {
1192  enableSearchBar(showSearchBar);
1193 
1194  if (_searchBar) {
1195  if (showSearchBar) {
1196  removeSearchFilter();
1197 
1198  listenForScreenWindowUpdates();
1199 
1200  _searchFilter = new RegExpFilter();
1201  _searchFilter->setRegExp(regexpFromSearchBarOptions());
1202  _view->filterChain()->addFilter(_searchFilter);
1203  _view->processFilters();
1204 
1205  setFindNextPrevEnabled(true);
1206  } else {
1207  setFindNextPrevEnabled(false);
1208 
1209  removeSearchFilter();
1210 
1211  _view->setFocus(Qt::ActiveWindowFocusReason);
1212  }
1213  }
1214 }
1215 
1216 void SessionController::setFindNextPrevEnabled(bool enabled)
1217 {
1218  _findNextAction->setEnabled(enabled);
1219  _findPreviousAction->setEnabled(enabled);
1220 }
1221 void SessionController::searchTextChanged(const QString& text)
1222 {
1223  Q_ASSERT(_view->screenWindow());
1224 
1225  if (_searchText == text)
1226  return;
1227 
1228  _searchText = text;
1229 
1230  if (text.isEmpty()) {
1231  _view->screenWindow()->clearSelection();
1232  _view->screenWindow()->scrollTo(_searchStartLine);
1233  }
1234 
1235  // update search. this is called even when the text is
1236  // empty to clear the view's filters
1237  beginSearch(text , reverseSearchChecked() ? SearchHistoryTask::BackwardsSearch : SearchHistoryTask::ForwardsSearch);
1238 }
1239 void SessionController::searchCompleted(bool success)
1240 {
1241  _prevSearchResultLine = _view->screenWindow()->currentResultLine();
1242 
1243  if (_searchBar)
1244  _searchBar->setFoundMatch(success);
1245 }
1246 
1247 void SessionController::beginSearch(const QString& text , int direction)
1248 {
1249  Q_ASSERT(_searchBar);
1250  Q_ASSERT(_searchFilter);
1251 
1252  QRegExp regExp = regexpFromSearchBarOptions();
1253  _searchFilter->setRegExp(regExp);
1254 
1255  if (_searchStartLine == -1) {
1256  if (direction == SearchHistoryTask::ForwardsSearch) {
1257  setSearchStartTo(_view->screenWindow()->currentLine());
1258  } else {
1259  setSearchStartTo(_view->screenWindow()->currentLine() + _view->screenWindow()->windowLines());
1260  }
1261  }
1262 
1263  if (!regExp.isEmpty()) {
1264  _view->screenWindow()->setCurrentResultLine(-1);
1265  SearchHistoryTask* task = new SearchHistoryTask(this);
1266 
1267  connect(task, SIGNAL(completed(bool)), this, SLOT(searchCompleted(bool)));
1268 
1269  task->setRegExp(regExp);
1270  task->setSearchDirection((SearchHistoryTask::SearchDirection)direction);
1271  task->setAutoDelete(true);
1272  task->setStartLine(_searchStartLine);
1273  task->addScreenWindow(_session , _view->screenWindow());
1274  task->execute();
1275  } else if (text.isEmpty()) {
1276  searchCompleted(false);
1277  }
1278 
1279  _view->processFilters();
1280 }
1281 void SessionController::highlightMatches(bool highlight)
1282 {
1283  if (highlight) {
1284  _view->filterChain()->addFilter(_searchFilter);
1285  _view->processFilters();
1286  } else {
1287  _view->filterChain()->removeFilter(_searchFilter);
1288  }
1289 
1290  _view->update();
1291 }
1292 
1293 void SessionController::searchFrom()
1294 {
1295  Q_ASSERT(_searchBar);
1296  Q_ASSERT(_searchFilter);
1297 
1298  if (reverseSearchChecked()) {
1299  setSearchStartTo(_view->screenWindow()->lineCount());
1300  } else {
1301  setSearchStartTo(0);
1302  }
1303 
1304 
1305  beginSearch(_searchBar->searchText(), reverseSearchChecked() ? SearchHistoryTask::BackwardsSearch : SearchHistoryTask::ForwardsSearch);
1306 }
1307 void SessionController::findNextInHistory()
1308 {
1309  Q_ASSERT(_searchBar);
1310  Q_ASSERT(_searchFilter);
1311 
1312  setSearchStartTo(_prevSearchResultLine);
1313 
1314  beginSearch(_searchBar->searchText(), reverseSearchChecked() ? SearchHistoryTask::BackwardsSearch : SearchHistoryTask::ForwardsSearch);
1315 }
1316 void SessionController::findPreviousInHistory()
1317 {
1318  Q_ASSERT(_searchBar);
1319  Q_ASSERT(_searchFilter);
1320 
1321  setSearchStartTo(_prevSearchResultLine);
1322 
1323  beginSearch(_searchBar->searchText(), reverseSearchChecked() ? SearchHistoryTask::ForwardsSearch : SearchHistoryTask::BackwardsSearch);
1324 }
1325 void SessionController::changeSearchMatch()
1326 {
1327  Q_ASSERT(_searchBar);
1328  Q_ASSERT(_searchFilter);
1329 
1330  // reset Selection for new case match
1331  _view->screenWindow()->clearSelection();
1332  beginSearch(_searchBar->searchText(), reverseSearchChecked() ? SearchHistoryTask::BackwardsSearch : SearchHistoryTask::ForwardsSearch);
1333 }
1334 void SessionController::showHistoryOptions()
1335 {
1336  QScopedPointer<HistorySizeDialog> dialog(new HistorySizeDialog(QApplication::activeWindow()));
1337  const HistoryType& currentHistory = _session->historyType();
1338 
1339  if (currentHistory.isEnabled()) {
1340  if (currentHistory.isUnlimited()) {
1341  dialog->setMode(Enum::UnlimitedHistory);
1342  } else {
1343  dialog->setMode(Enum::FixedSizeHistory);
1344  dialog->setLineCount(currentHistory.maximumLineCount());
1345  }
1346  } else {
1347  dialog->setMode(Enum::NoHistory);
1348  }
1349 
1350  QPointer<Session> guard(_session);
1351  int result = dialog->exec();
1352  if (!guard)
1353  return;
1354 
1355  if (result) {
1356  scrollBackOptionsChanged(dialog->mode(), dialog->lineCount());
1357  }
1358 }
1359 void SessionController::sessionResizeRequest(const QSize& size)
1360 {
1361  //kDebug() << "View resize requested to " << size;
1362  _view->setSize(size.width(), size.height());
1363 }
1364 void SessionController::scrollBackOptionsChanged(int mode, int lines)
1365 {
1366  switch (mode) {
1367  case Enum::NoHistory:
1368  _session->setHistoryType(HistoryTypeNone());
1369  break;
1370  case Enum::FixedSizeHistory:
1371  _session->setHistoryType(CompactHistoryType(lines));
1372  break;
1373  case Enum::UnlimitedHistory:
1374  _session->setHistoryType(HistoryTypeFile());
1375  break;
1376  }
1377 }
1378 
1379 void SessionController::print_screen()
1380 {
1381  QPrinter printer;
1382 
1383  QPointer<QPrintDialog> dialog = new QPrintDialog(&printer, _view);
1384  PrintOptions* options = new PrintOptions();
1385 
1386  dialog->setOptionTabs(QList<QWidget*>() << options);
1387  dialog->setWindowTitle(i18n("Print Shell"));
1388  connect(dialog, SIGNAL(accepted()), options, SLOT(saveSettings()));
1389  if (dialog->exec() != QDialog::Accepted)
1390  return;
1391 
1392  QPainter painter;
1393  painter.begin(&printer);
1394 
1395  KConfigGroup configGroup(KGlobal::config(), "PrintOptions");
1396 
1397  if (configGroup.readEntry("ScaleOutput", true)) {
1398  double scale = qMin(printer.pageRect().width() / static_cast<double>(_view->width()),
1399  printer.pageRect().height() / static_cast<double>(_view->height()));
1400  painter.scale(scale, scale);
1401  }
1402 
1403  _view->printContent(painter, configGroup.readEntry("PrinterFriendly", true));
1404 }
1405 
1406 void SessionController::saveHistory()
1407 {
1408  SessionTask* task = new SaveHistoryTask(this);
1409  task->setAutoDelete(true);
1410  task->addSession(_session);
1411  task->execute();
1412 }
1413 
1414 void SessionController::clearHistory()
1415 {
1416  _session->clearHistory();
1417  _view->updateImage(); // To reset view scrollbar
1418 }
1419 
1420 void SessionController::clearHistoryAndReset()
1421 {
1422  Profile::Ptr profile = SessionManager::instance()->sessionProfile(_session);
1423  QByteArray name = profile->defaultEncoding().toUtf8();
1424 
1425  Emulation* emulation = _session->emulation();
1426  emulation->reset();
1427  _session->refresh();
1428  _session->setCodec(QTextCodec::codecForName(name));
1429  clearHistory();
1430 }
1431 
1432 void SessionController::increaseFontSize()
1433 {
1434  _view->increaseFontSize();
1435 }
1436 
1437 void SessionController::decreaseFontSize()
1438 {
1439  _view->decreaseFontSize();
1440 }
1441 
1442 void SessionController::monitorActivity(bool monitor)
1443 {
1444  _session->setMonitorActivity(monitor);
1445 }
1446 void SessionController::monitorSilence(bool monitor)
1447 {
1448  _session->setMonitorSilence(monitor);
1449 }
1450 void SessionController::updateSessionIcon()
1451 {
1452  // Visualize that the session is broadcasting to others
1453  if (_copyToGroup && _copyToGroup->sessions().count() > 1) {
1454  // Master Mode: set different icon, to warn the user to be careful
1455  setIcon(_broadcastIcon);
1456  } else {
1457  if (!_keepIconUntilInteraction) {
1458  // Not in Master Mode: use normal icon
1459  setIcon(_sessionIcon);
1460  }
1461  }
1462 }
1463 void SessionController::sessionTitleChanged()
1464 {
1465  if (_sessionIconName != _session->iconName()) {
1466  _sessionIconName = _session->iconName();
1467  _sessionIcon = KIcon(_sessionIconName);
1468  updateSessionIcon();
1469  }
1470 
1471  QString title = _session->title(Session::DisplayedTitleRole);
1472 
1473  // special handling for the "%w" marker which is replaced with the
1474  // window title set by the shell
1475  title.replace("%w", _session->userTitle());
1476  // special handling for the "%#" marker which is replaced with the
1477  // number of the shell
1478  title.replace("%#", QString::number(_session->sessionId()));
1479 
1480  if (title.isEmpty())
1481  title = _session->title(Session::NameRole);
1482 
1483  setTitle(title);
1484  emit rawTitleChanged();
1485 }
1486 
1487 void SessionController::showDisplayContextMenu(const QPoint& position)
1488 {
1489  // needed to make sure the popup menu is available, even if a hosting
1490  // application did not merge our GUI.
1491  if (!factory()) {
1492  if (!clientBuilder()) {
1493  setClientBuilder(new KXMLGUIBuilder(_view));
1494  }
1495 
1496  KXMLGUIFactory* factory = new KXMLGUIFactory(clientBuilder(), this);
1497  factory->addClient(this);
1498  //kDebug() << "Created xmlgui factory" << factory;
1499  }
1500 
1501  QPointer<QMenu> popup = qobject_cast<QMenu*>(factory()->container("session-popup-menu", this));
1502  if (popup) {
1503  // prepend content-specific actions such as "Open Link", "Copy Email Address" etc.
1504  QList<QAction*> contentActions = _view->filterActions(position);
1505  QAction* contentSeparator = new QAction(popup);
1506  contentSeparator->setSeparator(true);
1507  contentActions << contentSeparator;
1508  popup->insertActions(popup->actions().value(0, 0), contentActions);
1509 
1510  // always update this submenu before showing the context menu,
1511  // because the available search services might have changed
1512  // since the context menu is shown last time
1513  updateWebSearchMenu();
1514 
1515  _preventClose = true;
1516 
1517  if (_showMenuAction) {
1518  if ( _showMenuAction->isChecked() ) {
1519  popup->removeAction( _showMenuAction);
1520  } else {
1521  popup->insertAction(_switchProfileMenu, _showMenuAction);
1522  }
1523  }
1524 
1525  QAction* chosen = popup->exec(_view->mapToGlobal(position));
1526 
1527  // check for validity of the pointer to the popup menu
1528  if (popup) {
1529  // Remove content-specific actions
1530  //
1531  // If the close action was chosen, the popup menu will be partially
1532  // destroyed at this point, and the rest will be destroyed later by
1533  // 'chosen->trigger()'
1534  foreach(QAction * action, contentActions) {
1535  popup->removeAction(action);
1536  }
1537 
1538  delete contentSeparator;
1539  }
1540 
1541  _preventClose = false;
1542 
1543  if (chosen && chosen->objectName() == "close-session")
1544  chosen->trigger();
1545  } else {
1546  kWarning() << "Unable to display popup menu for session"
1547  << _session->title(Session::NameRole)
1548  << ", no GUI factory available to build the popup.";
1549  }
1550 }
1551 
1552 void SessionController::movementKeyFromSearchBarReceived(QKeyEvent *event)
1553 {
1554  QCoreApplication::sendEvent(_view, event);
1555  setSearchStartToWindowCurrentLine();
1556 }
1557 
1558 void SessionController::sessionStateChanged(int state)
1559 {
1560  if (state == _previousState)
1561  return;
1562 
1563  if (state == NOTIFYACTIVITY) {
1564  setIcon(_activityIcon);
1565  _keepIconUntilInteraction = true;
1566  } else if (state == NOTIFYSILENCE) {
1567  setIcon(_silenceIcon);
1568  _keepIconUntilInteraction = true;
1569  } else if (state == NOTIFYNORMAL) {
1570  if (_sessionIconName != _session->iconName()) {
1571  _sessionIconName = _session->iconName();
1572  _sessionIcon = KIcon(_sessionIconName);
1573  }
1574 
1575  updateSessionIcon();
1576  }
1577 
1578  _previousState = state;
1579 }
1580 
1581 void SessionController::zmodemDownload()
1582 {
1583  QString zmodem = KStandardDirs::findExe("rz");
1584  if (zmodem.isEmpty()) {
1585  zmodem = KStandardDirs::findExe("lrz");
1586  }
1587  if (!zmodem.isEmpty()) {
1588  const QString path = KFileDialog::getExistingDirectory(
1589  QString(), _view,
1590  i18n("Save ZModem Download to..."));
1591 
1592  if (!path.isEmpty()) {
1593  _session->startZModem(zmodem, path, QStringList());
1594  return;
1595  }
1596  } else {
1597  KMessageBox::error(_view,
1598  i18n("<p>A ZModem file transfer attempt has been detected, "
1599  "but no suitable ZModem software was found on this system.</p>"
1600  "<p>You may wish to install the 'rzsz' or 'lrzsz' package.</p>"));
1601  }
1602  _session->cancelZModem();
1603  return;
1604 }
1605 
1606 void SessionController::zmodemUpload()
1607 {
1608  if (_session->isZModemBusy()) {
1609  KMessageBox::sorry(_view,
1610  i18n("<p>The current session already has a ZModem file transfer in progress.</p>"));
1611  return;
1612  }
1613  QString zmodem = KStandardDirs::findExe("sz");
1614  if (zmodem.isEmpty()) {
1615  zmodem = KStandardDirs::findExe("lsz");
1616  }
1617  if (zmodem.isEmpty()) {
1618  KMessageBox::sorry(_view,
1619  i18n("<p>No suitable ZModem software was found on this system.</p>"
1620  "<p>You may wish to install the 'rzsz' or 'lrzsz' package.</p>"));
1621  return;
1622  }
1623 
1624  QStringList files = KFileDialog::getOpenFileNames(KUrl(), QString(), _view,
1625  i18n("Select Files for ZModem Upload"));
1626  if (!files.isEmpty()) {
1627  _session->startZModem(zmodem, QString(), files);
1628  }
1629 }
1630 
1631 bool SessionController::isKonsolePart() const
1632 {
1633  // Check to see if we are being called from Konsole or a KPart
1634  if (QString(qApp->metaObject()->className()) == "Konsole::Application")
1635  return false;
1636  else
1637  return true;
1638 }
1639 
1640 SessionTask::SessionTask(QObject* parent)
1641  : QObject(parent)
1642  , _autoDelete(false)
1643 {
1644 }
1645 void SessionTask::setAutoDelete(bool enable)
1646 {
1647  _autoDelete = enable;
1648 }
1649 bool SessionTask::autoDelete() const
1650 {
1651  return _autoDelete;
1652 }
1653 void SessionTask::addSession(Session* session)
1654 {
1655  _sessions << session;
1656 }
1657 QList<SessionPtr> SessionTask::sessions() const
1658 {
1659  return _sessions;
1660 }
1661 
1662 SaveHistoryTask::SaveHistoryTask(QObject* parent)
1663  : SessionTask(parent)
1664 {
1665 }
1666 SaveHistoryTask::~SaveHistoryTask()
1667 {
1668 }
1669 
1670 void SaveHistoryTask::execute()
1671 {
1672  // TODO - think about the UI when saving multiple history sessions, if there are more than two or
1673  // three then providing a URL for each one will be tedious
1674 
1675  // TODO - show a warning ( preferably passive ) if saving the history output fails
1676  //
1677 
1678  KFileDialog* dialog = new KFileDialog(QString(":konsole") /* check this */,
1679  QString(), QApplication::activeWindow());
1680  dialog->setOperationMode(KFileDialog::Saving);
1681  dialog->setConfirmOverwrite(true);
1682 
1683  QStringList mimeTypes;
1684  mimeTypes << "text/plain";
1685  mimeTypes << "text/html";
1686  dialog->setMimeFilter(mimeTypes, "text/plain");
1687 
1688  // iterate over each session in the task and display a dialog to allow the user to choose where
1689  // to save that session's history.
1690  // then start a KIO job to transfer the data from the history to the chosen URL
1691  foreach(const SessionPtr& session, sessions()) {
1692  dialog->setCaption(i18n("Save Output From %1", session->title(Session::NameRole)));
1693 
1694  int result = dialog->exec();
1695 
1696  if (result != QDialog::Accepted)
1697  continue;
1698 
1699  KUrl url = dialog->selectedUrl();
1700 
1701  if (!url.isValid()) {
1702  // UI: Can we make this friendlier?
1703  KMessageBox::sorry(0 , i18n("%1 is an invalid URL, the output could not be saved.", url.url()));
1704  continue;
1705  }
1706 
1707  KIO::TransferJob* job = KIO::put(url,
1708  -1, // no special permissions
1709  // overwrite existing files
1710  // do not resume an existing transfer
1711  // show progress information only for remote
1712  // URLs
1713  KIO::Overwrite | (url.isLocalFile() ? KIO::HideProgressInfo : KIO::DefaultFlags)
1714  // a better solution would be to show progress
1715  // information after a certain period of time
1716  // instead, since the overall speed of transfer
1717  // depends on factors other than just the protocol
1718  // used
1719  );
1720 
1721  SaveJob jobInfo;
1722  jobInfo.session = session;
1723  jobInfo.lastLineFetched = -1; // when each request for data comes in from the KIO subsystem
1724  // lastLineFetched is used to keep track of how much of the history
1725  // has already been sent, and where the next request should continue
1726  // from.
1727  // this is set to -1 to indicate the job has just been started
1728 
1729  if (dialog->currentMimeFilter() == "text/html")
1730  jobInfo.decoder = new HTMLDecoder();
1731  else
1732  jobInfo.decoder = new PlainTextDecoder();
1733 
1734  _jobSession.insert(job, jobInfo);
1735 
1736  connect(job, SIGNAL(dataReq(KIO::Job*,QByteArray&)),
1737  this, SLOT(jobDataRequested(KIO::Job*,QByteArray&)));
1738  connect(job, SIGNAL(result(KJob*)),
1739  this, SLOT(jobResult(KJob*)));
1740  }
1741 
1742  dialog->deleteLater();
1743 }
1744 void SaveHistoryTask::jobDataRequested(KIO::Job* job , QByteArray& data)
1745 {
1746  // TODO - Report progress information for the job
1747 
1748  // PERFORMANCE: Do some tests and tweak this value to get faster saving
1749  const int LINES_PER_REQUEST = 500;
1750 
1751  SaveJob& info = _jobSession[job];
1752 
1753  // transfer LINES_PER_REQUEST lines from the session's history
1754  // to the save location
1755  if (info.session) {
1756  // note: when retrieving lines from the emulation,
1757  // the first line is at index 0.
1758 
1759  int sessionLines = info.session->emulation()->lineCount();
1760 
1761  if (sessionLines - 1 == info.lastLineFetched)
1762  return; // if there is no more data to transfer then stop the job
1763 
1764  int copyUpToLine = qMin(info.lastLineFetched + LINES_PER_REQUEST ,
1765  sessionLines - 1);
1766 
1767  QTextStream stream(&data, QIODevice::ReadWrite);
1768  info.decoder->begin(&stream);
1769  info.session->emulation()->writeToStream(info.decoder , info.lastLineFetched + 1 , copyUpToLine);
1770  info.decoder->end();
1771 
1772  info.lastLineFetched = copyUpToLine;
1773  }
1774 }
1775 void SaveHistoryTask::jobResult(KJob* job)
1776 {
1777  if (job->error()) {
1778  KMessageBox::sorry(0 , i18n("A problem occurred when saving the output.\n%1", job->errorString()));
1779  }
1780 
1781  TerminalCharacterDecoder * decoder = _jobSession[job].decoder;
1782 
1783  _jobSession.remove(job);
1784 
1785  delete decoder;
1786 
1787  // notify the world that the task is done
1788  emit completed(true);
1789 
1790  if (autoDelete())
1791  deleteLater();
1792 }
1793 void SearchHistoryTask::addScreenWindow(Session* session , ScreenWindow* searchWindow)
1794 {
1795  _windows.insert(session, searchWindow);
1796 }
1797 void SearchHistoryTask::execute()
1798 {
1799  QMapIterator< SessionPtr , ScreenWindowPtr > iter(_windows);
1800 
1801  while (iter.hasNext()) {
1802  iter.next();
1803  executeOnScreenWindow(iter.key() , iter.value());
1804  }
1805 }
1806 
1807 void SearchHistoryTask::executeOnScreenWindow(SessionPtr session , ScreenWindowPtr window)
1808 {
1809  Q_ASSERT(session);
1810  Q_ASSERT(window);
1811 
1812  Emulation* emulation = session->emulation();
1813 
1814  if (!_regExp.isEmpty()) {
1815  int pos = -1;
1816  const bool forwards = (_direction == ForwardsSearch);
1817  const int lastLine = window->lineCount() - 1;
1818 
1819  int startLine;
1820  if (forwards && (_startLine == lastLine)) {
1821  startLine = 0;
1822  } else if (!forwards && (_startLine == 0)) {
1823  startLine = lastLine;
1824  } else {
1825  startLine = _startLine + (forwards ? 1 : -1);
1826  }
1827 
1828  QString string;
1829 
1830  //text stream to read history into string for pattern or regular expression searching
1831  QTextStream searchStream(&string);
1832 
1833  PlainTextDecoder decoder;
1834  decoder.setRecordLinePositions(true);
1835 
1836  //setup first and last lines depending on search direction
1837  int line = startLine;
1838 
1839  //read through and search history in blocks of 10K lines.
1840  //this balances the need to retrieve lots of data from the history each time
1841  //(for efficient searching)
1842  //without using silly amounts of memory if the history is very large.
1843  const int maxDelta = qMin(window->lineCount(), 10000);
1844  int delta = forwards ? maxDelta : -maxDelta;
1845 
1846  int endLine = line;
1847  bool hasWrapped = false; // set to true when we reach the top/bottom
1848  // of the output and continue from the other
1849  // end
1850 
1851  //loop through history in blocks of <delta> lines.
1852  do {
1853  // ensure that application does not appear to hang
1854  // if searching through a lengthy output
1855  QApplication::processEvents();
1856 
1857  // calculate lines to search in this iteration
1858  if (hasWrapped) {
1859  if (endLine == lastLine)
1860  line = 0;
1861  else if (endLine == 0)
1862  line = lastLine;
1863 
1864  endLine += delta;
1865 
1866  if (forwards)
1867  endLine = qMin(startLine , endLine);
1868  else
1869  endLine = qMax(startLine , endLine);
1870  } else {
1871  endLine += delta;
1872 
1873  if (endLine > lastLine) {
1874  hasWrapped = true;
1875  endLine = lastLine;
1876  } else if (endLine < 0) {
1877  hasWrapped = true;
1878  endLine = 0;
1879  }
1880  }
1881 
1882  decoder.begin(&searchStream);
1883  emulation->writeToStream(&decoder, qMin(endLine, line) , qMax(endLine, line));
1884  decoder.end();
1885 
1886  // line number search below assumes that the buffer ends with a new-line
1887  string.append('\n');
1888 
1889  if (forwards)
1890  pos = string.indexOf(_regExp);
1891  else
1892  pos = string.lastIndexOf(_regExp);
1893 
1894  //if a match is found, position the cursor on that line and update the screen
1895  if (pos != -1) {
1896  int newLines = 0;
1897  QList<int> linePositions = decoder.linePositions();
1898  while (newLines < linePositions.count() && linePositions[newLines] <= pos)
1899  newLines++;
1900 
1901  // ignore the new line at the start of the buffer
1902  newLines--;
1903 
1904  int findPos = qMin(line, endLine) + newLines;
1905 
1906  highlightResult(window, findPos);
1907 
1908  emit completed(true);
1909 
1910  return;
1911  }
1912 
1913  //clear the current block of text and move to the next one
1914  string.clear();
1915  line = endLine;
1916  } while (startLine != endLine);
1917 
1918  // if no match was found, clear selection to indicate this
1919  window->clearSelection();
1920  window->notifyOutputChanged();
1921  }
1922 
1923  emit completed(false);
1924 }
1925 void SearchHistoryTask::highlightResult(ScreenWindowPtr window , int findPos)
1926 {
1927  //work out how many lines into the current block of text the search result was found
1928  //- looks a little painful, but it only has to be done once per search.
1929 
1930  //kDebug() << "Found result at line " << findPos;
1931 
1932  //update display to show area of history containing selection
1933  if ((findPos < window->currentLine()) ||
1934  (findPos >= (window->currentLine() + window->windowLines()))) {
1935  int centeredScrollPos = findPos - window->windowLines() / 2;
1936  if (centeredScrollPos < 0) {
1937  centeredScrollPos = 0;
1938  }
1939 
1940  window->scrollTo(centeredScrollPos);
1941  }
1942 
1943  window->setTrackOutput(false);
1944  window->notifyOutputChanged();
1945  window->setCurrentResultLine(findPos);
1946 }
1947 
1948 SearchHistoryTask::SearchHistoryTask(QObject* parent)
1949  : SessionTask(parent)
1950  , _direction(BackwardsSearch)
1951  , _startLine(0)
1952 {
1953 }
1954 void SearchHistoryTask::setSearchDirection(SearchDirection direction)
1955 {
1956  _direction = direction;
1957 }
1958 void SearchHistoryTask::setStartLine(int line)
1959 {
1960  _startLine = line;
1961 }
1962 SearchHistoryTask::SearchDirection SearchHistoryTask::searchDirection() const
1963 {
1964  return _direction;
1965 }
1966 void SearchHistoryTask::setRegExp(const QRegExp& expression)
1967 {
1968  _regExp = expression;
1969 }
1970 QRegExp SearchHistoryTask::regExp() const
1971 {
1972  return _regExp;
1973 }
1974 
1975 QString SessionController::userTitle() const
1976 {
1977  if (_session) {
1978  return _session->userTitle();
1979  } else {
1980  return QString();
1981  }
1982 }
1983 
1984 #include "SessionController.moc"
1985 
Konsole::HTMLDecoder
A terminal character decoder which produces pretty HTML markup.
Definition: TerminalCharacterDecoder.h:115
Konsole::SaveHistoryTask::SaveHistoryTask
SaveHistoryTask(QObject *parent=0)
Constructs a new task to save session output to URLs.
Definition: SessionController.cpp:1662
Session.h
Konsole::SessionTask::SessionTask
SessionTask(QObject *parent=0)
Definition: SessionController.cpp:1640
Konsole::NOTIFYSILENCE
Definition: Emulation.h:65
Konsole::PlainTextDecoder::end
virtual void end()
End decoding.
Definition: TerminalCharacterDecoder.cpp:55
Konsole::SessionManager::instance
static SessionManager * instance()
Returns the session manager instance.
Definition: SessionManager.cpp:69
Konsole::PlainTextDecoder::setRecordLinePositions
void setRecordLinePositions(bool record)
Enables recording of character positions at which new lines are added.
Definition: TerminalCharacterDecoder.cpp:60
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::ViewProperties::title
QString title() const
Returns the title associated with a view.
Definition: ViewProperties.cpp:85
Konsole::SessionManager::setSessionProfile
void setSessionProfile(Session *session, Profile::Ptr profile)
Sets the profile associated with a session.
Definition: SessionManager.cpp:145
Konsole::IncrementalSearchBar::MatchCase
Searches are case-sensitive or not.
Definition: IncrementalSearchBar.h:68
PrintOptions.h
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
Konsole::ProfileList::actions
QList< QAction * > actions()
Returns a list of actions representing profiles.
Definition: ProfileList.cpp:167
Konsole::HistoryType::isEnabled
virtual bool isEnabled() const =0
Returns true if the history is enabled ( can store lines of output ) or false otherwise.
Konsole::IncrementalSearchBar::RegExp
Searches use regular expressions.
Definition: IncrementalSearchBar.h:70
KXMLGUIClient
Konsole::SessionController::setShowMenuAction
void setShowMenuAction(QAction *action)
Sets the action displayed in the session's context menu to hide or show the menu bar.
Definition: SessionController.cpp:548
Konsole::SessionController::url
virtual KUrl url() const
Returns the URL current associated with a view.
Definition: SessionController.cpp:290
Konsole::SearchHistoryTask::regExp
QRegExp regExp() const
Returns the regular expression which is searched for when execute() is called.
Definition: SessionController.cpp:1970
Konsole::ViewProperties::setIdentifier
void setIdentifier(int id)
Subclasses may call this method to change the identifier.
Definition: ViewProperties.cpp:76
Konsole::SessionTask
Abstract class representing a task which can be performed on a group of sessions. ...
Definition: SessionController.h:377
Konsole::HistorySizeDialog
Definition: HistorySizeDialog.h:37
Konsole::HistoryType::maximumLineCount
virtual int maximumLineCount() const =0
Returns the maximum number of lines which this history type can store or -1 if the history can store ...
Konsole::HistoryTypeNone
Definition: History.h:348
Emulation.h
HistorySizeDialog.h
findWindow
static const KXmlGuiWindow * findWindow(const QObject *object)
Definition: SessionController.cpp:950
Konsole::SessionController::SessionController
SessionController(Session *session, TerminalDisplay *view, QObject *parent)
Constructs a new SessionController which operates on session and view.
Definition: SessionController.cpp:100
Konsole::ProfileList
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Definition: ProfileList.h:51
Konsole::SessionGroup::sessions
QList< Session * > sessions() const
Returns the list of sessions currently in the group.
Definition: Session.cpp:1454
Konsole::Session::DisplayedTitleRole
The title of the session which is displayed in tabs etc.
Definition: Session.h:244
Konsole::ViewProperties::setTitle
void setTitle(const QString &title)
Subclasses may call this method to change the title.
Definition: ViewProperties.cpp:59
Konsole::CompactHistoryType
Definition: History.h:373
Konsole::SessionTask::execute
virtual void execute()=0
Executes the task on each of the sessions in the group.
Konsole::ViewProperties::setIcon
void setIcon(const QIcon &icon)
Subclasses may call this method to change the icon.
Definition: ViewProperties.cpp:66
Konsole::RenameTabDialog
Definition: RenameTabDialog.h:33
Konsole::SearchHistoryTask::searchDirection
SearchDirection searchDirection() const
Returns the current search direction.
Definition: SessionController.cpp:1962
Konsole::ViewProperties::titleChanged
void titleChanged(ViewProperties *properties)
Emitted when the title for a view changes.
QObject
Konsole::SaveHistoryTask::~SaveHistoryTask
virtual ~SaveHistoryTask()
Definition: SessionController.cpp:1666
Konsole::Session::views
QList< TerminalDisplay * > views() const
Returns the views connected to this session.
Definition: Session.cpp:303
IncrementalSearchBar.h
Konsole::Emulation::reset
virtual void reset()=0
Resets the state of the terminal.
Konsole::SessionManager::sessionProfile
Profile::Ptr sessionProfile(Session *session) const
Returns the profile associated with a session.
Definition: SessionManager.cpp:141
Filter.h
hasTerminalDisplayInSameWindow
static bool hasTerminalDisplayInSameWindow(const Session *session, const KXmlGuiWindow *window)
Definition: SessionController.cpp:963
Konsole::Emulation::writeToStream
virtual void writeToStream(TerminalCharacterDecoder *decoder, int startLine, int endLine)
Copies the output history from startLine to endLine into stream, using decoder to convert the termina...
Definition: Emulation.cpp:284
Konsole::ScreenWindow::setSelectionByLineRange
void setSelectionByLineRange(int start, int end)
Sets the selection as the range specified by line start and line end in the whole history...
Definition: ScreenWindow.cpp:153
Konsole::EditProfileDialog
A dialog which allows the user to edit a profile.
Definition: EditProfileDialog.h:61
Konsole::SessionController::rename
virtual void rename()
Requests the renaming of this view.
Definition: SessionController.cpp:295
Konsole::PlainTextDecoder
A terminal character decoder which produces plain text, ignoring colors and other appearance-related ...
Definition: TerminalCharacterDecoder.h:72
Konsole::SessionController::increaseFontSize
void increaseFontSize()
Increase font size.
Definition: SessionController.cpp:1432
Konsole::SessionController::focused
void focused(SessionController *controller)
Emitted when the view associated with the controller is focused.
Konsole::NOTIFYACTIVITY
The emulation is currently receiving data from its terminal input.
Definition: Emulation.h:62
Konsole::SessionController::profileDialogPointer
EditProfileDialog * profileDialogPointer()
Definition: SessionController.cpp:794
Konsole::SessionController::CopyInputToNoneMode
Do not copy keyboard input to other tabs.
Definition: SessionController.h:98
History.h
Konsole::SearchHistoryTask::setSearchDirection
void setSearchDirection(SearchDirection direction)
Specifies the direction to search in when execute() is called.
Definition: SessionController.cpp:1954
CopyInputDialog.h
Konsole::TerminalCharacterDecoder
Base class for terminal character decoders.
Definition: TerminalCharacterDecoder.h:45
TerminalDisplay.h
KXmlGuiWindow
Konsole::SessionController::setSearchStartToWindowCurrentLine
void setSearchStartToWindowCurrentLine()
set start line to the first or last line (depending on the reverse search setting) in the terminal di...
Definition: SessionController.cpp:1091
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
ProfileList.h
Konsole::PrintOptions
Definition: PrintOptions.h:28
Konsole::SessionController::selectionChanged
void selectionChanged(const QString &selectedText)
update actions which are closely related with the selected text.
Definition: SessionController.cpp:374
Konsole::SessionController::confirmForceClose
virtual bool confirmForceClose() const
Definition: SessionController.cpp:875
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::SessionGroup::setMasterStatus
void setMasterStatus(Session *session, bool master)
Sets whether a particular session is a master within the group.
Definition: Session.cpp:1488
Konsole::SearchHistoryTask::SearchHistoryTask
SearchHistoryTask(QObject *parent=0)
Constructs a new search task.
Definition: SessionController.cpp:1948
Konsole::ViewProperties::fireActivity
void fireActivity()
Emits the activity() signal.
Definition: ViewProperties.cpp:50
Konsole::Emulation
Base class for terminal emulation back-ends.
Definition: Emulation.h:117
Konsole::NOTIFYNORMAL
The emulation is currently receiving user input.
Definition: Emulation.h:52
Konsole::SessionController::session
QPointer< Session > session()
Returns the session associated with this controller.
Definition: SessionController.h:108
Konsole::SessionController::setSearchStartTo
void setSearchStartTo(int line)
Set the start line from which the next search will be done.
Definition: SessionController.cpp:1096
EditProfileDialog.h
Konsole::Session::RemoteTabTitle
Tab title format used session currently contains a connection to a remote computer (via SSH) ...
Definition: Session.h:155
Konsole::SessionController::setupPrimaryScreenSpecificActions
void setupPrimaryScreenSpecificActions(bool use)
update actions which are meaningful only when primary screen is in use.
Definition: SessionController.cpp:361
Enumeration.h
Konsole::Enum::NoHistory
No output is remembered.
Definition: Enumeration.h:42
Konsole::SearchHistoryTask
A task which searches through the output of sessions for matches for a given regular expression...
Definition: SessionController.h:478
Konsole::TerminalDisplay::setSessionController
void setSessionController(SessionController *controller)
Definition: TerminalDisplay.cpp:3196
Konsole::Emulation::lineCount
int lineCount() const
Returns the total number of lines, including those stored in the history.
Definition: Emulation.cpp:291
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::SessionController::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Definition: SessionController.cpp:458
Konsole::ViewProperties
Encapsulates user-visible information about the terminal session currently being displayed in a view...
Definition: ViewProperties.h:44
Konsole::SessionGroup::setMasterMode
void setMasterMode(int mode)
Specifies which activity in the group's master sessions is propagated to all sessions in the group...
Definition: Session.cpp:1480
Konsole::SessionGroup::removeSession
void removeSession(Session *session)
Removes a session from the group.
Definition: Session.cpp:1468
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::setRegExp
void setRegExp(const QRegExp &text)
Sets the regular expression which the filter searches for in blocks of text.
Definition: Filter.cpp:316
Konsole::RegExpFilter
A filter which searches for sections of text matching a regular expression and creates a new RegExpFi...
Definition: Filter.h:182
Konsole::SessionController::CopyInputToAllTabsMode
Copy keyboard input to all the other tabs in current window.
Definition: SessionController.h:92
Konsole::PlainTextDecoder::linePositions
QList< int > linePositions() const
Returns of character positions in the output stream at which new lines where added.
Definition: TerminalCharacterDecoder.cpp:64
Konsole::HistoryTypeFile
Definition: History.h:359
Konsole::SessionPtr
QPointer< Session > SessionPtr
Definition: SessionController.h:68
Konsole::EditProfileDialog::lookupProfile
const Profile::Ptr lookupProfile() const
Definition: EditProfileDialog.cpp:197
Konsole::HistoryType
Definition: History.h:319
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
Konsole::PlainTextDecoder::begin
virtual void begin(QTextStream *output)
Begin decoding characters.
Definition: TerminalCharacterDecoder.cpp:49
Konsole::SessionController::openUrl
void openUrl(const KUrl &url)
Issues a command to the session to navigate to the specified URL.
Definition: SessionController.cpp:300
TerminalCharacterDecoder.h
Konsole::Session::NameRole
The name of the session.
Definition: Session.h:242
Konsole::SessionController::setSearchBar
void setSearchBar(IncrementalSearchBar *searchBar)
Sets the widget used for searches through the session's output.
Definition: SessionController.cpp:519
Konsole::Session::LocalTabTitle
Default tab title format.
Definition: Session.h:150
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::SessionController::closeSession
void closeSession()
close the associated session.
Definition: SessionController.cpp:900
Konsole::SearchHistoryTask::SearchDirection
SearchDirection
This enum describes the strategies available for searching through the session's output.
Definition: SessionController.h:487
Konsole::IncrementalSearchBar::ReverseSearch
Search from the bottom and up.
Definition: IncrementalSearchBar.h:72
Konsole::Enum::UnlimitedHistory
All output is remembered for the duration of the session.
Definition: Enumeration.h:51
Konsole::SessionGroup::addSession
void addSession(Session *session)
Adds a session to the group.
Definition: Session.cpp:1463
RenameTabDialog.h
Konsole::Enum::FixedSizeHistory
A fixed number of lines of output are remembered.
Definition: Enumeration.h:46
Konsole::HistoryType::isUnlimited
bool isUnlimited() const
Returns true if the history size is unlimited.
Definition: History.h:343
Konsole::SessionController::userTitle
QString userTitle() const
Returns the "window title" of the associated session.
Definition: SessionController.cpp:1975
Konsole::CopyInputDialog
Dialog which allows the user to mark a list of sessions to copy the input from the current session to...
Definition: CopyInputDialog.h:50
Konsole::SessionController::CopyInputToSelectedTabsMode
Copy keyboard input to user selected tabs in current window.
Definition: SessionController.h:95
SessionManager.h
Konsole::SessionGroup::CopyInputToAll
Any input key presses in the master sessions are sent to all sessions in the group.
Definition: Session.h:798
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
ScreenWindow.h
Konsole::SessionController::searchBar
IncrementalSearchBar * searchBar() const
see setSearchBar()
Definition: SessionController.cpp:543
Konsole::TerminalDisplay
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalDisplay.h:63
Konsole::SessionController::~SessionController
~SessionController()
Definition: SessionController.cpp:217
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::SessionController::confirmClose
virtual bool confirmClose() const
Sub-classes may re-implement this method to display a message to the user to allow them to confirm wh...
Definition: SessionController.cpp:850
Konsole::SessionTask::completed
void completed(bool success)
Emitted when the task has completed.
Konsole::SessionController::decreaseFontSize
void decreaseFontSize()
Decrease font size.
Definition: SessionController.cpp:1437
Konsole::SessionController::currentDir
virtual QString currentDir() const
Returns the current directory associated with a view.
Definition: SessionController.cpp:285
SessionController.h
Konsole::SessionController::currentDirectoryChanged
void currentDirectoryChanged(const QString &dir)
Emitted when the current working directory of the session associated with the controller is changed...
Konsole::SessionController::rawTitleChanged
void rawTitleChanged()
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