• 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
MainWindow.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA.
18 */
19 
20 // Own
21 #include "MainWindow.h"
22 
23 // Qt
24 #include <QVBoxLayout>
25 
26 // KDE
27 #include <KAcceleratorManager>
28 #include <KAction>
29 #include <KActionCollection>
30 #include <KActionMenu>
31 #include <KCmdLineArgs>
32 #include <KShortcutsDialog>
33 #include <KLocale>
34 #include <KMenu>
35 #include <KMenuBar>
36 #include <KMessageBox>
37 #include <KToggleFullScreenAction>
38 #include <KStandardAction>
39 #include <KStandardGuiItem>
40 #include <KWindowSystem>
41 #include <KXMLGUIFactory>
42 #include <KNotifyConfigWidget>
43 #include <KConfigDialog>
44 #include <KApplication>
45 
46 // Konsole
47 #include "BookmarkHandler.h"
48 #include "SessionController.h"
49 #include "ProfileList.h"
50 #include "ManageProfilesDialog.h"
51 #include "Session.h"
52 #include "ViewManager.h"
53 #include "SessionManager.h"
54 #include "ProfileManager.h"
55 #include "KonsoleSettings.h"
56 #include "settings/GeneralSettings.h"
57 #include "settings/TabBarSettings.h"
58 
59 using namespace Konsole;
60 
61 /* Normally it would be enough to just have this determined via the window
62  manager. But there exist GPU drivers (NVIDIA) that have serious performance
63  issues if transparency is enabled inside Konsole. The rest of the system
64  works fine. NVIDIA users might want to use --notransparency to work
65  around such issues. */
66 static bool useTransparency()
67 {
68  const KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
69  const bool compositingAvailable = KWindowSystem::compositingActive();
70  return compositingAvailable && args->isSet("transparency");
71 }
72 
73 MainWindow::MainWindow()
74  : KXmlGuiWindow()
75  , _bookmarkHandler(0)
76  , _pluggedController(0)
77  , _menuBarInitialVisibility(true)
78  , _menuBarInitialVisibilityApplied(false)
79 {
80  if (useTransparency()) {
81  // It is useful to have translucent terminal area
82  setAttribute(Qt::WA_TranslucentBackground, true);
83  // But it is mostly annoying to have translucent menubar and tabbar
84  setAttribute(Qt::WA_NoSystemBackground, false);
85  }
86 
87  // create actions for menus
88  setupActions();
89 
90  // create view manager
91  _viewManager = new ViewManager(this, actionCollection());
92  connect(_viewManager, SIGNAL(empty()), this, SLOT(close()));
93  connect(_viewManager, SIGNAL(activeViewChanged(SessionController*)), this,
94  SLOT(activeViewChanged(SessionController*)));
95  connect(_viewManager, SIGNAL(unplugController(SessionController*)), this,
96  SLOT(disconnectController(SessionController*)));
97  connect(_viewManager, SIGNAL(viewPropertiesChanged(QList<ViewProperties*>)),
98  bookmarkHandler(), SLOT(setViews(QList<ViewProperties*>)));
99 
100  connect(_viewManager, SIGNAL(setSaveGeometryOnExitRequest(bool)), this,
101  SLOT(setSaveGeometryOnExit(bool)));
102  connect(_viewManager, SIGNAL(updateWindowIcon()), this,
103  SLOT(updateWindowIcon()));
104  connect(_viewManager, SIGNAL(newViewRequest(Profile::Ptr)),
105  this, SLOT(newFromProfile(Profile::Ptr)));
106  connect(_viewManager, SIGNAL(newViewRequest()),
107  this, SLOT(newTab()));
108  connect(_viewManager, SIGNAL(viewDetached(Session*)),
109  this, SIGNAL(viewDetached(Session*)));
110 
111  // create the main widget
112  setupMainWidget();
113 
114  // disable automatically generated accelerators in top-level
115  // menu items - to avoid conflicting with Alt+[Letter] shortcuts
116  // in terminal applications
117  KAcceleratorManager::setNoAccel(menuBar());
118 
119  // create menus
120  createGUI();
121 
122  // remember the original menu accelerators for later use
123  rememberMenuAccelerators();
124 
125  // replace standard shortcuts which cannot be used in a terminal
126  // emulator (as they are reserved for use by terminal applications)
127  correctStandardShortcuts();
128 
129  setProfileList(new ProfileList(true, this));
130 
131  // this must come at the end
132  applyKonsoleSettings();
133  connect(KonsoleSettings::self(), SIGNAL(configChanged()), this, SLOT(applyKonsoleSettings()));
134 }
135 
136 void MainWindow::rememberMenuAccelerators()
137 {
138  foreach(QAction* menuItem, menuBar()->actions()) {
139  QString itemText = menuItem->text();
140  menuItem->setData(itemText);
141  }
142 }
143 
144 // remove accelerators for standard menu items (eg. &File, &View, &Edit)
145 // etc. which are defined in kdelibs/kdeui/xmlgui/ui_standards.rc, again,
146 // to avoid conflicting with Alt+[Letter] terminal shortcuts
147 //
148 // TODO - Modify XMLGUI so that it allows the text for standard actions
149 // defined in ui_standards.rc to be re-defined in the local application
150 // XMLGUI file (konsoleui.rc in this case) - the text for standard items
151 // can then be redefined there to exclude the standard accelerators
152 void MainWindow::removeMenuAccelerators()
153 {
154  foreach(QAction* menuItem, menuBar()->actions()) {
155  QString itemText = menuItem->text();
156  itemText = KGlobal::locale()->removeAcceleratorMarker(itemText);
157  menuItem->setText(itemText);
158  }
159 }
160 
161 void MainWindow::restoreMenuAccelerators()
162 {
163  foreach(QAction* menuItem, menuBar()->actions()) {
164  QString itemText = menuItem->data().toString();
165  menuItem->setText(itemText);
166  }
167 }
168 
169 void MainWindow::setSaveGeometryOnExit(bool save)
170 {
171  // enable save and restore of window size
172  setAutoSaveSettings("MainWindow", save);
173 }
174 
175 void MainWindow::correctStandardShortcuts()
176 {
177  // replace F1 shortcut for help contents
178  QAction* helpAction = actionCollection()->action("help_contents");
179  if (helpAction) {
180  helpAction->setShortcut(QKeySequence());
181  }
182 
183  // replace Ctrl+B shortcut for bookmarks only if user hasn't already
184  // changed the shortcut; however, if the user changed it to Ctrl+B
185  // this will still get changed to Ctrl+Shift+B
186  QAction* bookmarkAction = actionCollection()->action("add_bookmark");
187  if (bookmarkAction && bookmarkAction->shortcut() == QKeySequence(Qt::CTRL + Qt::Key_B)) {
188  bookmarkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
189  }
190 }
191 
192 ViewManager* MainWindow::viewManager() const
193 {
194  return _viewManager;
195 }
196 
197 void MainWindow::disconnectController(SessionController* controller)
198 {
199  disconnect(controller, SIGNAL(titleChanged(ViewProperties*)),
200  this, SLOT(activeViewTitleChanged(ViewProperties*)));
201  disconnect(controller, SIGNAL(rawTitleChanged()),
202  this, SLOT(updateWindowCaption()));
203 
204  // KXmlGuiFactory::removeClient() will try to access actions associated
205  // with the controller internally, which may not be valid after the controller
206  // itself is no longer valid (after the associated session and or view have
207  // been destroyed)
208  if (controller->isValid())
209  guiFactory()->removeClient(controller);
210 
211  controller->setSearchBar(0);
212 }
213 
214 void MainWindow::activeViewChanged(SessionController* controller)
215 {
216  // associate bookmark menu with current session
217  bookmarkHandler()->setActiveView(controller);
218  disconnect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), 0, 0);
219  connect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), controller,
220  SLOT(openUrl(KUrl)));
221 
222  if (_pluggedController)
223  disconnectController(_pluggedController);
224 
225  Q_ASSERT(controller);
226  _pluggedController = controller;
227 
228  // listen for title changes from the current session
229  connect(controller, SIGNAL(titleChanged(ViewProperties*)),
230  this, SLOT(activeViewTitleChanged(ViewProperties*)));
231  connect(controller, SIGNAL(rawTitleChanged()),
232  this, SLOT(updateWindowCaption()));
233 
234  controller->setShowMenuAction(_toggleMenuBarAction);
235  guiFactory()->addClient(controller);
236 
237  // set the current session's search bar
238  controller->setSearchBar(searchBar());
239 
240  // update session title to match newly activated session
241  activeViewTitleChanged(controller);
242 
243  // Update window icon to newly activated session's icon
244  updateWindowIcon();
245 }
246 
247 void MainWindow::activeViewTitleChanged(ViewProperties* properties)
248 {
249  Q_UNUSED(properties);
250  updateWindowCaption();
251 }
252 
253 void MainWindow::updateWindowCaption()
254 {
255  if (!_pluggedController)
256  return;
257 
258  const QString& title = _pluggedController->title();
259  const QString& userTitle = _pluggedController->userTitle();
260 
261  // use tab title as caption by default
262  QString caption = title;
263 
264  // use window title as caption only when enabled and it is not empty
265  if (KonsoleSettings::showWindowTitleOnTitleBar() && !userTitle.isEmpty()) {
266  caption = userTitle;
267  }
268 
269  setCaption(caption);
270 }
271 
272 void MainWindow::updateWindowIcon()
273 {
274  if (_pluggedController)
275  setWindowIcon(_pluggedController->icon());
276 }
277 
278 IncrementalSearchBar* MainWindow::searchBar() const
279 {
280  return _viewManager->searchBar();
281 }
282 
283 void MainWindow::setupActions()
284 {
285  KActionCollection* collection = actionCollection();
286  KAction* menuAction = 0;
287 
288  // File Menu
289  _newTabMenuAction = new KActionMenu(KIcon("tab-new"), i18nc("@action:inmenu", "&New Tab"), collection);
290  _newTabMenuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
291  _newTabMenuAction->setShortcutConfigurable(true);
292  _newTabMenuAction->setAutoRepeat(false);
293  connect(_newTabMenuAction, SIGNAL(triggered()), this, SLOT(newTab()));
294  collection->addAction("new-tab", _newTabMenuAction);
295 
296  menuAction = collection->addAction("clone-tab");
297  menuAction->setIcon(KIcon("tab-duplicate"));
298  menuAction->setText(i18nc("@action:inmenu", "&Clone Tab"));
299  menuAction->setShortcut(QKeySequence());
300  menuAction->setAutoRepeat(false);
301  connect(menuAction, SIGNAL(triggered()), this, SLOT(cloneTab()));
302 
303  menuAction = collection->addAction("new-window");
304  menuAction->setIcon(KIcon("window-new"));
305  menuAction->setText(i18nc("@action:inmenu", "New &Window"));
306  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_N));
307  menuAction->setAutoRepeat(false);
308  connect(menuAction, SIGNAL(triggered()), this, SLOT(newWindow()));
309 
310  menuAction = collection->addAction("close-window");
311  menuAction->setIcon(KIcon("window-close"));
312  menuAction->setText(i18nc("@action:inmenu", "Close Window"));
313  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Q));
314  connect(menuAction, SIGNAL(triggered()), this, SLOT(close()));
315 
316  // Bookmark Menu
317  KActionMenu* bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), collection);
318  _bookmarkHandler = new BookmarkHandler(collection, bookmarkMenu->menu(), true, this);
319  collection->addAction("bookmark", bookmarkMenu);
320  connect(_bookmarkHandler, SIGNAL(openUrls(QList<KUrl>)), this, SLOT(openUrls(QList<KUrl>)));
321 
322  // Settings Menu
323  _toggleMenuBarAction = KStandardAction::showMenubar(menuBar(), SLOT(setVisible(bool)), collection);
324  _toggleMenuBarAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
325 
326  // Full Screen
327  menuAction = KStandardAction::fullScreen(this, SLOT(viewFullScreen(bool)), this, collection);
328  menuAction->setShortcut(QKeySequence());
329 
330  KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
331  KStandardAction::keyBindings(this, SLOT(showShortcutsDialog()), collection);
332  KStandardAction::preferences(this, SLOT(showSettingsDialog()), collection);
333 
334  menuAction = collection->addAction("manage-profiles");
335  menuAction->setText(i18nc("@action:inmenu", "Manage Profiles..."));
336  menuAction->setIcon(KIcon("configure"));
337  connect(menuAction, SIGNAL(triggered()), this, SLOT(showManageProfilesDialog()));
338 
339  // Set up an shortcut-only action for activating menu bar.
340  menuAction = collection->addAction("activate-menu");
341  menuAction->setText(i18nc("@item", "Activate Menu"));
342  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_F10));
343  connect(menuAction, SIGNAL(triggered()), this, SLOT(activateMenuBar()));
344 }
345 
346 void MainWindow::viewFullScreen(bool fullScreen)
347 {
348  if (fullScreen)
349  setWindowState(windowState() | Qt::WindowFullScreen);
350  else
351  setWindowState(windowState() & ~Qt::WindowFullScreen);
352 }
353 
354 BookmarkHandler* MainWindow::bookmarkHandler() const
355 {
356  return _bookmarkHandler;
357 }
358 
359 void MainWindow::setProfileList(ProfileList* list)
360 {
361  profileListChanged(list->actions());
362 
363  connect(list, SIGNAL(profileSelected(Profile::Ptr)), this,
364  SLOT(newFromProfile(Profile::Ptr)));
365 
366  connect(list, SIGNAL(actionsChanged(QList<QAction*>)), this,
367  SLOT(profileListChanged(QList<QAction*>)));
368 }
369 
370 void MainWindow::profileListChanged(const QList<QAction*>& sessionActions)
371 {
372  // If only 1 profile is to be shown in the menu, only display
373  // it if it is the non-default profile.
374  if (sessionActions.size() > 2) {
375  // Update the 'New Tab' KActionMenu
376  KMenu* newTabMenu = _newTabMenuAction->menu();
377  newTabMenu->clear();
378  foreach(QAction* sessionAction, sessionActions) {
379  newTabMenu->addAction(sessionAction);
380 
381  // NOTE: defaultProfile seems to not work here, sigh.
382  Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
383  if (profile && profile->name() == sessionAction->text().remove('&')) {
384  sessionAction->setIcon(KIcon(profile->icon(), 0, QStringList("emblem-favorite")));
385  newTabMenu->setDefaultAction(sessionAction);
386  QFont actionFont = sessionAction->font();
387  actionFont.setBold(true);
388  sessionAction->setFont(actionFont);
389  }
390  }
391  } else {
392  KMenu* newTabMenu = _newTabMenuAction->menu();
393  newTabMenu->clear();
394  Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
395 
396  // NOTE: Compare names w/o any '&'
397  if (sessionActions.size() == 2 && sessionActions[1]->text().remove('&') != profile->name()) {
398  newTabMenu->addAction(sessionActions[1]);
399  } else {
400  delete newTabMenu;
401  }
402  }
403 }
404 
405 QString MainWindow::activeSessionDir() const
406 {
407  if (_pluggedController) {
408  if (Session* session = _pluggedController->session()) {
409  // For new tabs to get the correct working directory,
410  // force the updating of the currentWorkingDirectory.
411  session->getDynamicTitle();
412  }
413  return _pluggedController->currentDir();
414  } else {
415  return QString();
416  }
417 }
418 
419 void MainWindow::openUrls(const QList<KUrl>& urls)
420 {
421  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
422 
423  foreach(const KUrl& url, urls) {
424  if (url.isLocalFile())
425  createSession(defaultProfile, url.path());
426 
427  else if (url.protocol() == "ssh")
428  createSSHSession(defaultProfile, url);
429  }
430 }
431 
432 void MainWindow::newTab()
433 {
434  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
435  createSession(defaultProfile, activeSessionDir());
436 }
437 
438 void MainWindow::cloneTab()
439 {
440  Q_ASSERT(_pluggedController);
441 
442  Session* session = _pluggedController->session();
443  Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
444  if (profile) {
445  createSession(profile, activeSessionDir());
446  } else {
447  // something must be wrong: every session should be associated with profile
448  Q_ASSERT(false);
449  newTab();
450  }
451 }
452 
453 Session* MainWindow::createSession(Profile::Ptr profile, const QString& directory)
454 {
455  if (!profile)
456  profile = ProfileManager::instance()->defaultProfile();
457 
458  Session* session = SessionManager::instance()->createSession(profile);
459 
460  if (!directory.isEmpty() && profile->startInCurrentSessionDir())
461  session->setInitialWorkingDirectory(directory);
462 
463  session->addEnvironmentEntry(QString("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId()));
464 
465  // create view before starting the session process so that the session
466  // doesn't suffer a change in terminal size right after the session
467  // starts. Some applications such as GNU Screen and Midnight Commander
468  // don't like this happening
469  createView(session);
470 
471  return session;
472 }
473 
474 Session* MainWindow::createSSHSession(Profile::Ptr profile, const KUrl& url)
475 {
476  if (!profile)
477  profile = ProfileManager::instance()->defaultProfile();
478 
479  Session* session = SessionManager::instance()->createSession(profile);
480 
481  QString sshCommand = "ssh ";
482  if (url.port() > -1) {
483  sshCommand += QString("-p %1 ").arg(url.port());
484  }
485  if (url.hasUser()) {
486  sshCommand += (url.user() + '@');
487  }
488  if (url.hasHost()) {
489  sshCommand += url.host();
490  }
491 
492  session->sendText(sshCommand + '\r');
493 
494  // create view before starting the session process so that the session
495  // doesn't suffer a change in terminal size right after the session
496  // starts. some applications such as GNU Screen and Midnight Commander
497  // don't like this happening
498  createView(session);
499 
500  return session;
501 }
502 
503 void MainWindow::createView(Session* session)
504 {
505  _viewManager->createView(session);
506 }
507 
508 void MainWindow::setFocus()
509 {
510  _viewManager->activeView()->setFocus();
511 }
512 
513 void MainWindow::newWindow()
514 {
515  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
516  emit newWindowRequest(defaultProfile, activeSessionDir());
517 }
518 
519 bool MainWindow::queryClose()
520 {
521  // Do not ask for confirmation during log out and power off
522  // TODO: rework the dealing of this case to make it has its own confirmation
523  // dialog.
524  if (kapp->sessionSaving()) {
525  return true;
526  }
527 
528  // Check what processes are running,
529  // if just the default shell is running don't ask for confirmation
530 
531  QStringList processesRunning;
532  foreach(Session *session, _viewManager->sessions()) {
533  if (!session)
534  continue;
535 
536  const QString defaultProc = session->program().split('/').last();
537  const QString currentProc = session->foregroundProcessName().split('/').last();
538 
539  if (currentProc.isEmpty())
540  continue;
541 
542  if (defaultProc != currentProc) {
543  processesRunning.append(currentProc);
544  }
545  }
546  if (processesRunning.count() == 0) {
547  return true;
548  }
549 
550  // NOTE: Some, if not all, of the below KWindowSystem calls are only
551  // implemented under x11 (KDE4.8 kdelibs/kdeui/windowmanagement).
552 
553  // make sure the window is shown on current desktop and is not minimized
554  KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
555  if (isMinimized()) {
556  KWindowSystem::unminimizeWindow(winId(), true);
557  }
558 
559  int result = KMessageBox::warningYesNoCancelList(this,
560  i18ncp("@info", "There is a process running in this window. "
561  "Do you still want to quit?",
562  "There are %1 processes running in this window. "
563  "Do you still want to quit?",
564  processesRunning.count()),
565  processesRunning,
566  i18nc("@title", "Confirm Close"),
567  KGuiItem(i18nc("@action:button", "Close &Window"), "window-close"),
568  KGuiItem(i18nc("@action:button", "Close Current &Tab"), "tab-close"),
569  KStandardGuiItem::cancel(),
570  "CloseAllTabs");
571 
572  switch (result) {
573  case KMessageBox::Yes:
574  return true;
575  case KMessageBox::No:
576  if (_pluggedController && _pluggedController->session()) {
577  disconnectController(_pluggedController);
578  _pluggedController->closeSession();
579  }
580  return false;
581  case KMessageBox::Cancel:
582  return false;
583  }
584 
585  return true;
586 }
587 
588 void MainWindow::saveProperties(KConfigGroup& group)
589 {
590  _viewManager->saveSessions(group);
591 }
592 
593 void MainWindow::readProperties(const KConfigGroup& group)
594 {
595  _viewManager->restoreSessions(group);
596 }
597 
598 void MainWindow::saveGlobalProperties(KConfig* config)
599 {
600  SessionManager::instance()->saveSessions(config);
601 }
602 
603 void MainWindow::readGlobalProperties(KConfig* config)
604 {
605  SessionManager::instance()->restoreSessions(config);
606 }
607 
608 void MainWindow::syncActiveShortcuts(KActionCollection* dest, const KActionCollection* source)
609 {
610  foreach(QAction * qAction, source->actions()) {
611  if (KAction* kAction = qobject_cast<KAction*>(qAction)) {
612  if (KAction* destKAction = qobject_cast<KAction*>(dest->action(kAction->objectName())))
613  destKAction->setShortcut(kAction->shortcut(KAction::ActiveShortcut), KAction::ActiveShortcut);
614  }
615  }
616 }
617 void MainWindow::showShortcutsDialog()
618 {
619  KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
620 
621  // add actions from this window and the current session controller
622  foreach(KXMLGUIClient * client, guiFactory()->clients()) {
623  dialog.addCollection(client->actionCollection());
624  }
625 
626  if (dialog.configure()) {
627  // sync shortcuts for non-session actions (defined in "konsoleui.rc") in other main windows
628  foreach(QWidget* mainWindowWidget, QApplication::topLevelWidgets()) {
629  MainWindow* mainWindow = qobject_cast<MainWindow*>(mainWindowWidget);
630  if (mainWindow && mainWindow != this)
631  syncActiveShortcuts(mainWindow->actionCollection(), actionCollection());
632  }
633  // sync shortcuts for session actions (defined in "sessionui.rc") in other session controllers.
634  // Controllers which are currently plugged in (ie. their actions are part of the current menu)
635  // must be updated immediately via syncActiveShortcuts(). Other controllers will be updated
636  // when they are plugged into a main window.
637  foreach(SessionController * controller, SessionController::allControllers()) {
638  controller->reloadXML();
639  if (controller->factory() && controller != _pluggedController)
640  syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection());
641  }
642  }
643 }
644 
645 void MainWindow::newFromProfile(Profile::Ptr profile)
646 {
647  createSession(profile, activeSessionDir());
648 }
649 void MainWindow::showManageProfilesDialog()
650 {
651  ManageProfilesDialog* dialog = new ManageProfilesDialog(this);
652  dialog->show();
653 }
654 
655 void MainWindow::showSettingsDialog()
656 {
657  if (KConfigDialog::showDialog("settings"))
658  return;
659 
660  KConfigDialog* settingsDialog = new KConfigDialog(this, "settings", KonsoleSettings::self());
661  settingsDialog->setFaceType(KPageDialog::List);
662 
663  GeneralSettings* generalSettings = new GeneralSettings(settingsDialog);
664  settingsDialog->addPage(generalSettings,
665  i18nc("@title Preferences page name", "General"),
666  "utilities-terminal");
667 
668  TabBarSettings* tabBarSettings = new TabBarSettings(settingsDialog);
669  settingsDialog->addPage(tabBarSettings,
670  i18nc("@title Preferences page name", "TabBar"),
671  "system-run");
672 
673  settingsDialog->show();
674 }
675 
676 void MainWindow::applyKonsoleSettings()
677 {
678  setMenuBarInitialVisibility(KonsoleSettings::showMenuBarByDefault());
679 
680  if (KonsoleSettings::allowMenuAccelerators()) {
681  restoreMenuAccelerators();
682  } else {
683  removeMenuAccelerators();
684  }
685 
686  setNavigationVisibility(KonsoleSettings::tabBarVisibility());
687  setNavigationPosition(KonsoleSettings::tabBarPosition());
688  setNavigationStyleSheet(KonsoleSettings::tabBarStyleSheet());
689  setNavigationBehavior(KonsoleSettings::newTabBehavior());
690  setShowQuickButtons(KonsoleSettings::showQuickButtons());
691 
692  // setAutoSaveSettings("MainWindow", KonsoleSettings::saveGeometryOnExit());
693 
694  updateWindowCaption();
695 }
696 
697 void MainWindow::setNavigationVisibility(int visibility)
698 {
699  _viewManager->setNavigationVisibility(visibility);
700 }
701 
702 void MainWindow::setNavigationPosition(int position)
703 {
704  _viewManager->setNavigationPosition(position);
705 }
706 
707 void MainWindow::setNavigationStyleSheet(const QString& styleSheet)
708 {
709  _viewManager->setNavigationStyleSheet(styleSheet);
710 }
711 
712 void MainWindow::setNavigationBehavior(int behavior)
713 {
714  _viewManager->setNavigationBehavior(behavior);
715 }
716 
717 void MainWindow::setShowQuickButtons(bool show)
718 {
719  _viewManager->setShowQuickButtons(show);
720 }
721 
722 void MainWindow::activateMenuBar()
723 {
724  const QList<QAction*> menuActions = menuBar()->actions();
725 
726  if (menuActions.isEmpty())
727  return;
728 
729  // Show menubar if it is hidden at the moment
730  if (menuBar()->isHidden()) {
731  menuBar()->setVisible(true);
732  _toggleMenuBarAction->setChecked(true);
733  }
734 
735  // First menu action should be 'File'
736  QAction* menuAction = menuActions.first();
737 
738  // TODO: Handle when menubar is top level (MacOS)
739  menuBar()->setActiveAction(menuAction);
740 }
741 
742 void MainWindow::setupMainWidget()
743 {
744  QWidget* mainWindowWidget = new QWidget(this);
745  QVBoxLayout* mainWindowLayout = new QVBoxLayout();
746 
747  mainWindowLayout->addWidget(_viewManager->widget());
748  mainWindowLayout->setContentsMargins(0, 0, 0, 0);
749  mainWindowLayout->setSpacing(0);
750 
751  mainWindowWidget->setLayout(mainWindowLayout);
752 
753  setCentralWidget(mainWindowWidget);
754 }
755 
756 void MainWindow::configureNotifications()
757 {
758  KNotifyConfigWidget::configure(this);
759 }
760 
761 void MainWindow::setMenuBarInitialVisibility(bool visible)
762 {
763  _menuBarInitialVisibility = visible;
764 }
765 void MainWindow::showEvent(QShowEvent* aEvent)
766 {
767  // Make sure the 'initial' visibility is applied only once.
768  if (!_menuBarInitialVisibilityApplied) {
769  // the initial visibility of menubar should be applied at this last
770  // moment. Otherwise, the initial visibility will be determined by
771  // what KMainWindow has automatically stored in konsolerc, but not by
772  // what users has explicitly configured .
773  menuBar()->setVisible(_menuBarInitialVisibility);
774  _toggleMenuBarAction->setChecked(_menuBarInitialVisibility);
775  _menuBarInitialVisibilityApplied = true;
776  }
777 
778  // Call parent method
779  KXmlGuiWindow::showEvent(aEvent);
780 }
781 
782 bool MainWindow::focusNextPrevChild(bool)
783 {
784  // In stand-alone konsole, always disable implicit focus switching
785  // through 'Tab' and 'Shift+Tab'
786  //
787  // Kpart is another different story
788  return false;
789 }
790 
791 #include "MainWindow.moc"
792 
Konsole::ManageProfilesDialog
A dialog which lists the available types of profiles and allows the user to add new profiles...
Definition: ManageProfilesDialog.h:50
Session.h
Konsole::MainWindow::saveGlobalProperties
virtual void saveGlobalProperties(KConfig *config)
Definition: MainWindow.cpp:598
Konsole::SessionManager::instance
static SessionManager * instance()
Returns the session manager instance.
Definition: SessionManager.cpp:69
Konsole::MainWindow::showEvent
virtual void showEvent(QShowEvent *event)
Definition: MainWindow.cpp:765
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::KonsoleSettings::tabBarPosition
static int tabBarPosition()
Get Control the position of the tab bar.
Definition: KonsoleSettings.h:197
Konsole::ViewManager::activeView
QWidget * activeView() const
Returns the view manager's active view.
Definition: ViewManager.cpp:118
Konsole::MainWindow::focusNextPrevChild
virtual bool focusNextPrevChild(bool next)
Definition: MainWindow.cpp:782
Konsole::ProfileList::actions
QList< QAction * > actions()
Returns a list of actions representing profiles.
Definition: ProfileList.cpp:167
KXMLGUIClient
Konsole::MainWindow::newWindowRequest
void newWindowRequest(Profile::Ptr profile, const QString &directory)
Emitted by the main window to request the creation of a new session in a new window.
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::TabBarSettings
Definition: TabBarSettings.h:29
Konsole::ViewManager::saveSessions
void saveSessions(KConfigGroup &group)
Session management.
Definition: ViewManager.cpp:924
Konsole::ViewManager::managerId
int managerId() const
Definition: ViewManager.cpp:113
Konsole::MainWindow::setNavigationPosition
void setNavigationPosition(int position)
Definition: MainWindow.cpp:702
TabBarSettings.h
QWidget
Konsole::MainWindow::setMenuBarInitialVisibility
void setMenuBarInitialVisibility(bool visible)
Set the initial visibility of the menubar.
Definition: MainWindow.cpp:761
Konsole::BookmarkHandler::setActiveView
void setActiveView(ViewProperties *view)
Definition: BookmarkHandler.cpp:149
Konsole::ProfileList
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Definition: ProfileList.h:51
Konsole::MainWindow::createSSHSession
Session * createSSHSession(Profile::Ptr profile, const KUrl &url)
create a new SSH session.
Definition: MainWindow.cpp:474
Konsole::ViewManager::setShowQuickButtons
void setShowQuickButtons(bool show)
Definition: ViewManager.cpp:1115
Konsole::SessionController::allControllers
static QSet< SessionController * > allControllers()
Returns the set of all controllers that exist.
Definition: SessionController.h:168
Konsole::ViewManager::sessions
QList< Session * > sessions()
Returns a list of sessions in this ViewManager.
Definition: ViewManager.h:178
GeneralSettings.h
MainWindow.h
Konsole::KonsoleSettings::showQuickButtons
static bool showQuickButtons()
Get Control the visibility of quick buttons on the tab bar.
Definition: KonsoleSettings.h:251
Konsole::KonsoleSettings::tabBarStyleSheet
static QString tabBarStyleSheet()
Get Control the visual style of the tab bar.
Definition: KonsoleSettings.h:224
Konsole::SessionManager::sessionProfile
Profile::Ptr sessionProfile(Session *session) const
Returns the profile associated with a session.
Definition: SessionManager.cpp:141
Konsole::SessionManager::saveSessions
void saveSessions(KConfig *config)
Definition: SessionManager.cpp:273
Konsole::GeneralSettings
Definition: GeneralSettings.h:29
Konsole::KonsoleSettings::showWindowTitleOnTitleBar
static bool showWindowTitleOnTitleBar()
Get Show window title on the titlebar.
Definition: KonsoleSettings.h:62
Konsole::ViewManager
Manages the terminal display widgets in a Konsole window or part.
Definition: ViewManager.h:66
Konsole::ViewManager::setNavigationPosition
void setNavigationPosition(int position)
Definition: ViewManager.cpp:1095
Konsole::ProfileManager::defaultProfile
Profile::Ptr defaultProfile() const
Returns a Profile object describing the default profile.
Definition: ProfileManager.cpp:308
Konsole::MainWindow::createView
void createView(Session *session)
create view for the specified session
Definition: MainWindow.cpp:503
Konsole::ProfileManager::instance
static ProfileManager * instance()
Returns the profile manager instance.
Definition: ProfileManager.cpp:114
KXmlGuiWindow
Konsole::MainWindow::readProperties
virtual void readProperties(const KConfigGroup &group)
Definition: MainWindow.cpp:593
Konsole::ViewManager::restoreSessions
void restoreSessions(const KConfigGroup &group)
Definition: ViewManager.cpp:959
ProfileList.h
Konsole::BookmarkHandler
This class handles the communication between the bookmark menu and the active session, providing a suggested title and URL when the user clicks the "Add Bookmark" item in the bookmarks menu.
Definition: BookmarkHandler.h:52
Konsole::MainWindow::viewManager
ViewManager * viewManager() const
Returns the view manager associated with this window.
Definition: MainWindow.cpp:192
Konsole::ViewManager::setNavigationVisibility
void setNavigationVisibility(int visibility)
Definition: ViewManager.cpp:1085
Konsole::ViewManager::setNavigationStyleSheet
void setNavigationStyleSheet(const QString &styleSheet)
Definition: ViewManager.cpp:1106
Konsole::KonsoleSettings::self
static KonsoleSettings * self()
Definition: KonsoleSettings.cpp:25
Konsole::MainWindow::MainWindow
MainWindow()
Constructs a new main window.
Definition: MainWindow.cpp:73
Konsole::Session::setInitialWorkingDirectory
void setInitialWorkingDirectory(const QString &dir)
Sets the initial working directory for the session when it is run This has no effect once the session...
Definition: Session.cpp:277
ManageProfilesDialog.h
Konsole::MainWindow::saveProperties
virtual void saveProperties(KConfigGroup &group)
Definition: MainWindow.cpp:588
Konsole::MainWindow::viewDetached
void viewDetached(Session *session)
Emitted when a view for one session is detached from this window.
Konsole::MainWindow::viewFullScreen
void viewFullScreen(bool fullScreen)
Definition: MainWindow.cpp:346
Konsole::MainWindow
The main window.
Definition: MainWindow.h:57
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::ViewManager::setNavigationBehavior
void setNavigationBehavior(int behavior)
Definition: ViewManager.cpp:1133
Konsole::KonsoleSettings::newTabBehavior
static int newTabBehavior()
Get Control where to put the new tab.
Definition: KonsoleSettings.h:278
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
Konsole::ViewManager::createView
void createView(Session *session)
Creates a new view to display the output from and deliver input to session.
Definition: ViewManager.cpp:577
Konsole::MainWindow::setNavigationBehavior
void setNavigationBehavior(int behavior)
Definition: MainWindow.cpp:712
Konsole::SessionController::setSearchBar
void setSearchBar(IncrementalSearchBar *searchBar)
Sets the widget used for searches through the session's output.
Definition: SessionController.cpp:519
Konsole::KonsoleSettings::allowMenuAccelerators
static bool allowMenuAccelerators()
Get Enable menu accelerators.
Definition: KonsoleSettings.h:89
Konsole::MainWindow::readGlobalProperties
virtual void readGlobalProperties(KConfig *config)
Definition: MainWindow.cpp:603
ProfileManager.h
ViewManager.h
useTransparency
static bool useTransparency()
Definition: MainWindow.cpp:66
Konsole::MainWindow::setFocus
void setFocus()
Helper method to make this window get input focus.
Definition: MainWindow.cpp:508
BookmarkHandler.h
SessionManager.h
Konsole::KonsoleSettings::tabBarVisibility
static int tabBarVisibility()
Get Control the visibility of the whole tab bar.
Definition: KonsoleSettings.h:170
Konsole::ViewManager::searchBar
IncrementalSearchBar * searchBar() const
Returns the search bar.
Definition: ViewManager.cpp:538
Konsole::Session::addEnvironmentEntry
void addEnvironmentEntry(const QString &entry)
Adds one entry for the environment of this session entry should be like VARIABLE=VALUE.
Definition: Session.cpp:888
Konsole::SessionManager::createSession
Session * createSession(Profile::Ptr profile=Profile::Ptr())
Creates a new session using the settings specified by the specified profile.
Definition: SessionManager.cpp:88
Konsole::MainWindow::setShowQuickButtons
void setShowQuickButtons(bool show)
Definition: MainWindow.cpp:717
Konsole::Session::foregroundProcessName
QString foregroundProcessName()
Returns the name of the current foreground process.
Definition: Session.cpp:1404
Konsole::ViewManager::widget
QWidget * widget() const
Return the main widget for the view manager which holds all of the views managed by this ViewManager ...
Definition: ViewManager.cpp:128
Konsole::MainWindow::setNavigationVisibility
void setNavigationVisibility(int visibility)
Definition: MainWindow.cpp:697
Konsole::MainWindow::createSession
Session * createSession(Profile::Ptr profile, const QString &directory)
Create a new session.
Definition: MainWindow.cpp:453
Konsole::MainWindow::queryClose
virtual bool queryClose()
Definition: MainWindow.cpp:519
Konsole::Session::sendText
Q_SCRIPTABLE void sendText(const QString &text) const
Sends text to the current foreground terminal program.
Definition: Session.cpp:813
KonsoleSettings.h
SessionController.h
Konsole::Session::program
QString program() const
Returns the program name of the shell process started when run() is called.
Definition: Session.cpp:1080
Konsole::KonsoleSettings::showMenuBarByDefault
static bool showMenuBarByDefault()
Get Show menubar by default.
Definition: KonsoleSettings.h:35
Konsole::SessionController::isValid
bool isValid() const
Returns true if the controller is valid.
Definition: SessionController.h:363
QList
Konsole::MainWindow::setNavigationStyleSheet
void setNavigationStyleSheet(const QString &stylesheet)
Definition: MainWindow.cpp:707
Konsole::SessionManager::restoreSessions
void restoreSessions(KConfig *config)
Definition: SessionManager.cpp:300
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