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

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
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 (!KonsoleSettings::saveGeometryOnExit()) {
81  // If we are not using the global Konsole save geometry on exit,
82  // remove all Height and Width from [MainWindow] from konsolerc
83  // Each screen resolution will have entries (Width 1280=619)
84  KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig("konsolerc");
85  KConfigGroup group = konsoleConfig->group("MainWindow");
86  QMap<QString, QString> configEntries = group.entryMap();
87  QMapIterator<QString, QString> i(configEntries);
88  while (i.hasNext()) {
89  i.next();
90  if (i.key().startsWith(QLatin1String("Width"))
91  || i.key().startsWith(QLatin1String("Height"))) {
92  group.deleteEntry(i.key());
93  }
94  }
95  }
96 
97  if (useTransparency()) {
98  // It is useful to have translucent terminal area
99  setAttribute(Qt::WA_TranslucentBackground, true);
100  // But it is mostly annoying to have translucent menubar and tabbar
101  setAttribute(Qt::WA_NoSystemBackground, false);
102  }
103 
104  // create actions for menus
105  setupActions();
106 
107  // create view manager
108  _viewManager = new ViewManager(this, actionCollection());
109  connect(_viewManager, SIGNAL(empty()), this, SLOT(close()));
110  connect(_viewManager, SIGNAL(activeViewChanged(SessionController*)), this,
111  SLOT(activeViewChanged(SessionController*)));
112  connect(_viewManager, SIGNAL(unplugController(SessionController*)), this,
113  SLOT(disconnectController(SessionController*)));
114  connect(_viewManager, SIGNAL(viewPropertiesChanged(QList<ViewProperties*>)),
115  bookmarkHandler(), SLOT(setViews(QList<ViewProperties*>)));
116 
117  connect(_viewManager, SIGNAL(updateWindowIcon()), this,
118  SLOT(updateWindowIcon()));
119  connect(_viewManager, SIGNAL(newViewRequest(Profile::Ptr)),
120  this, SLOT(newFromProfile(Profile::Ptr)));
121  connect(_viewManager, SIGNAL(newViewRequest()),
122  this, SLOT(newTab()));
123  connect(_viewManager, SIGNAL(viewDetached(Session*)),
124  this, SIGNAL(viewDetached(Session*)));
125 
126  // create the main widget
127  setupMainWidget();
128 
129  // disable automatically generated accelerators in top-level
130  // menu items - to avoid conflicting with Alt+[Letter] shortcuts
131  // in terminal applications
132  KAcceleratorManager::setNoAccel(menuBar());
133 
134  // create menus
135  createGUI();
136 
137  // remember the original menu accelerators for later use
138  rememberMenuAccelerators();
139 
140  // replace standard shortcuts which cannot be used in a terminal
141  // emulator (as they are reserved for use by terminal applications)
142  correctStandardShortcuts();
143 
144  setProfileList(new ProfileList(true, this));
145 
146  // this must come at the end
147  applyKonsoleSettings();
148  connect(KonsoleSettings::self(), SIGNAL(configChanged()), this, SLOT(applyKonsoleSettings()));
149 }
150 
151 void MainWindow::rememberMenuAccelerators()
152 {
153  foreach(QAction* menuItem, menuBar()->actions()) {
154  QString itemText = menuItem->text();
155  menuItem->setData(itemText);
156  }
157 }
158 
159 // remove accelerators for standard menu items (eg. &File, &View, &Edit)
160 // etc. which are defined in kdelibs/kdeui/xmlgui/ui_standards.rc, again,
161 // to avoid conflicting with Alt+[Letter] terminal shortcuts
162 //
163 // TODO - Modify XMLGUI so that it allows the text for standard actions
164 // defined in ui_standards.rc to be re-defined in the local application
165 // XMLGUI file (konsoleui.rc in this case) - the text for standard items
166 // can then be redefined there to exclude the standard accelerators
167 void MainWindow::removeMenuAccelerators()
168 {
169  foreach(QAction* menuItem, menuBar()->actions()) {
170  QString itemText = menuItem->text();
171  itemText = KGlobal::locale()->removeAcceleratorMarker(itemText);
172  menuItem->setText(itemText);
173  }
174 }
175 
176 void MainWindow::restoreMenuAccelerators()
177 {
178  foreach(QAction* menuItem, menuBar()->actions()) {
179  QString itemText = menuItem->data().toString();
180  menuItem->setText(itemText);
181  }
182 }
183 
184 void MainWindow::correctStandardShortcuts()
185 {
186  // replace F1 shortcut for help contents
187  QAction* helpAction = actionCollection()->action("help_contents");
188  if (helpAction) {
189  helpAction->setShortcut(QKeySequence());
190  }
191 
192  // replace Ctrl+B shortcut for bookmarks only if user hasn't already
193  // changed the shortcut; however, if the user changed it to Ctrl+B
194  // this will still get changed to Ctrl+Shift+B
195  QAction* bookmarkAction = actionCollection()->action("add_bookmark");
196  if (bookmarkAction && bookmarkAction->shortcut() == QKeySequence(Qt::CTRL + Qt::Key_B)) {
197  bookmarkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
198  }
199 }
200 
201 ViewManager* MainWindow::viewManager() const
202 {
203  return _viewManager;
204 }
205 
206 void MainWindow::disconnectController(SessionController* controller)
207 {
208  disconnect(controller, SIGNAL(titleChanged(ViewProperties*)),
209  this, SLOT(activeViewTitleChanged(ViewProperties*)));
210  disconnect(controller, SIGNAL(rawTitleChanged()),
211  this, SLOT(updateWindowCaption()));
212 
213  // KXmlGuiFactory::removeClient() will try to access actions associated
214  // with the controller internally, which may not be valid after the controller
215  // itself is no longer valid (after the associated session and or view have
216  // been destroyed)
217  if (controller->isValid())
218  guiFactory()->removeClient(controller);
219 
220  controller->setSearchBar(0);
221 }
222 
223 void MainWindow::activeViewChanged(SessionController* controller)
224 {
225  // associate bookmark menu with current session
226  bookmarkHandler()->setActiveView(controller);
227  disconnect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), 0, 0);
228  connect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), controller,
229  SLOT(openUrl(KUrl)));
230 
231  if (_pluggedController)
232  disconnectController(_pluggedController);
233 
234  Q_ASSERT(controller);
235  _pluggedController = controller;
236 
237  // listen for title changes from the current session
238  connect(controller, SIGNAL(titleChanged(ViewProperties*)),
239  this, SLOT(activeViewTitleChanged(ViewProperties*)));
240  connect(controller, SIGNAL(rawTitleChanged()),
241  this, SLOT(updateWindowCaption()));
242 
243  controller->setShowMenuAction(_toggleMenuBarAction);
244 
245  const bool isMenuBarVisible = menuBar()->isVisible();
246  guiFactory()->addClient(controller);
247  menuBar()->setVisible(isMenuBarVisible);
248 
249  // set the current session's search bar
250  controller->setSearchBar(searchBar());
251 
252  // update session title to match newly activated session
253  activeViewTitleChanged(controller);
254 
255  // Update window icon to newly activated session's icon
256  updateWindowIcon();
257 }
258 
259 void MainWindow::activeViewTitleChanged(ViewProperties* properties)
260 {
261  Q_UNUSED(properties);
262  updateWindowCaption();
263 }
264 
265 void MainWindow::updateWindowCaption()
266 {
267  if (!_pluggedController)
268  return;
269 
270  const QString& title = _pluggedController->title();
271  const QString& userTitle = _pluggedController->userTitle();
272 
273  // use tab title as caption by default
274  QString caption = title;
275 
276  // use window title as caption only when enabled and it is not empty
277  if (KonsoleSettings::showWindowTitleOnTitleBar() && !userTitle.isEmpty()) {
278  caption = userTitle;
279  }
280 
281  if (KonsoleSettings::showAppNameOnTitleBar()) {
282  setCaption(caption);
283  } else {
284  setPlainCaption(caption);
285  }
286 }
287 
288 void MainWindow::updateWindowIcon()
289 {
290  if (_pluggedController)
291  setWindowIcon(_pluggedController->icon());
292 }
293 
294 IncrementalSearchBar* MainWindow::searchBar() const
295 {
296  return _viewManager->searchBar();
297 }
298 
299 void MainWindow::setupActions()
300 {
301  KActionCollection* collection = actionCollection();
302  KAction* menuAction = 0;
303 
304  // File Menu
305  _newTabMenuAction = new KActionMenu(KIcon("tab-new"), i18nc("@action:inmenu", "&New Tab"), collection);
306  _newTabMenuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
307  _newTabMenuAction->setShortcutConfigurable(true);
308  _newTabMenuAction->setAutoRepeat(false);
309  connect(_newTabMenuAction, SIGNAL(triggered()), this, SLOT(newTab()));
310  collection->addAction("new-tab", _newTabMenuAction);
311 
312  menuAction = collection->addAction("clone-tab");
313  menuAction->setIcon(KIcon("tab-duplicate"));
314  menuAction->setText(i18nc("@action:inmenu", "&Clone Tab"));
315  menuAction->setShortcut(QKeySequence());
316  menuAction->setAutoRepeat(false);
317  connect(menuAction, SIGNAL(triggered()), this, SLOT(cloneTab()));
318 
319  menuAction = collection->addAction("new-window");
320  menuAction->setIcon(KIcon("window-new"));
321  menuAction->setText(i18nc("@action:inmenu", "New &Window"));
322  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_N));
323  menuAction->setAutoRepeat(false);
324  connect(menuAction, SIGNAL(triggered()), this, SLOT(newWindow()));
325 
326  menuAction = collection->addAction("close-window");
327  menuAction->setIcon(KIcon("window-close"));
328  menuAction->setText(i18nc("@action:inmenu", "Close Window"));
329  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Q));
330  connect(menuAction, SIGNAL(triggered()), this, SLOT(close()));
331 
332  // Bookmark Menu
333  KActionMenu* bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), collection);
334  _bookmarkHandler = new BookmarkHandler(collection, bookmarkMenu->menu(), true, this);
335  collection->addAction("bookmark", bookmarkMenu);
336  connect(_bookmarkHandler, SIGNAL(openUrls(QList<KUrl>)), this, SLOT(openUrls(QList<KUrl>)));
337 
338  // Settings Menu
339  _toggleMenuBarAction = KStandardAction::showMenubar(menuBar(), SLOT(setVisible(bool)), collection);
340  _toggleMenuBarAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
341 
342  // Full Screen
343  menuAction = KStandardAction::fullScreen(this, SLOT(viewFullScreen(bool)), this, collection);
344  menuAction->setShortcut(QKeySequence(Qt::Key_F11));
345 
346  KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
347  KStandardAction::keyBindings(this, SLOT(showShortcutsDialog()), collection);
348  KStandardAction::preferences(this, SLOT(showSettingsDialog()), collection);
349 
350  menuAction = collection->addAction("manage-profiles");
351  menuAction->setText(i18nc("@action:inmenu", "Manage Profiles..."));
352  menuAction->setIcon(KIcon("configure"));
353  connect(menuAction, SIGNAL(triggered()), this, SLOT(showManageProfilesDialog()));
354 
355  // Set up an shortcut-only action for activating menu bar.
356  menuAction = collection->addAction("activate-menu");
357  menuAction->setText(i18nc("@item", "Activate Menu"));
358  menuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_F10));
359  connect(menuAction, SIGNAL(triggered()), this, SLOT(activateMenuBar()));
360 }
361 
362 void MainWindow::viewFullScreen(bool fullScreen)
363 {
364  if (fullScreen)
365  setWindowState(windowState() | Qt::WindowFullScreen);
366  else
367  setWindowState(windowState() & ~Qt::WindowFullScreen);
368 }
369 
370 BookmarkHandler* MainWindow::bookmarkHandler() const
371 {
372  return _bookmarkHandler;
373 }
374 
375 void MainWindow::setProfileList(ProfileList* list)
376 {
377  profileListChanged(list->actions());
378 
379  connect(list, SIGNAL(profileSelected(Profile::Ptr)), this,
380  SLOT(newFromProfile(Profile::Ptr)));
381 
382  connect(list, SIGNAL(actionsChanged(QList<QAction*>)), this,
383  SLOT(profileListChanged(QList<QAction*>)));
384 }
385 
386 void MainWindow::profileListChanged(const QList<QAction*>& sessionActions)
387 {
388  // If only 1 profile is to be shown in the menu, only display
389  // it if it is the non-default profile.
390  if (sessionActions.size() > 2) {
391  // Update the 'New Tab' KActionMenu
392  KMenu* newTabMenu = _newTabMenuAction->menu();
393  newTabMenu->clear();
394  foreach(QAction* sessionAction, sessionActions) {
395  newTabMenu->addAction(sessionAction);
396 
397  // NOTE: defaultProfile seems to not work here, sigh.
398  Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
399  if (profile && profile->name() == sessionAction->text().remove('&')) {
400  sessionAction->setIcon(KIcon(profile->icon(), 0, QStringList("emblem-favorite")));
401  newTabMenu->setDefaultAction(sessionAction);
402  QFont actionFont = sessionAction->font();
403  actionFont.setBold(true);
404  sessionAction->setFont(actionFont);
405  }
406  }
407  } else {
408  KMenu* newTabMenu = _newTabMenuAction->menu();
409  newTabMenu->clear();
410  Profile::Ptr profile = ProfileManager::instance()->defaultProfile();
411 
412  // NOTE: Compare names w/o any '&'
413  if (sessionActions.size() == 2 && sessionActions[1]->text().remove('&') != profile->name()) {
414  newTabMenu->addAction(sessionActions[1]);
415  } else {
416  delete newTabMenu;
417  }
418  }
419 }
420 
421 QString MainWindow::activeSessionDir() const
422 {
423  if (_pluggedController) {
424  if (Session* session = _pluggedController->session()) {
425  // For new tabs to get the correct working directory,
426  // force the updating of the currentWorkingDirectory.
427  session->getDynamicTitle();
428  }
429  return _pluggedController->currentDir();
430  } else {
431  return QString();
432  }
433 }
434 
435 void MainWindow::openUrls(const QList<KUrl>& urls)
436 {
437  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
438 
439  foreach(const KUrl& url, urls) {
440  if (url.isLocalFile())
441  createSession(defaultProfile, url.path());
442 
443  else if (url.protocol() == "ssh")
444  createSSHSession(defaultProfile, url);
445  }
446 }
447 
448 void MainWindow::newTab()
449 {
450  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
451  createSession(defaultProfile, activeSessionDir());
452 }
453 
454 void MainWindow::cloneTab()
455 {
456  Q_ASSERT(_pluggedController);
457 
458  Session* session = _pluggedController->session();
459  Profile::Ptr profile = SessionManager::instance()->sessionProfile(session);
460  if (profile) {
461  createSession(profile, activeSessionDir());
462  } else {
463  // something must be wrong: every session should be associated with profile
464  Q_ASSERT(false);
465  newTab();
466  }
467 }
468 
469 Session* MainWindow::createSession(Profile::Ptr profile, const QString& directory)
470 {
471  if (!profile)
472  profile = ProfileManager::instance()->defaultProfile();
473 
474  Session* session = SessionManager::instance()->createSession(profile);
475 
476  if (!directory.isEmpty() && profile->startInCurrentSessionDir())
477  session->setInitialWorkingDirectory(directory);
478 
479  session->addEnvironmentEntry(QString("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId()));
480 
481  // create view before starting the session process so that the session
482  // doesn't suffer a change in terminal size right after the session
483  // starts. Some applications such as GNU Screen and Midnight Commander
484  // don't like this happening
485  createView(session);
486 
487  return session;
488 }
489 
490 Session* MainWindow::createSSHSession(Profile::Ptr profile, const KUrl& url)
491 {
492  if (!profile)
493  profile = ProfileManager::instance()->defaultProfile();
494 
495  Session* session = SessionManager::instance()->createSession(profile);
496 
497  QString sshCommand = "ssh ";
498  if (url.port() > -1) {
499  sshCommand += QString("-p %1 ").arg(url.port());
500  }
501  if (url.hasUser()) {
502  sshCommand += (url.user() + '@');
503  }
504  if (url.hasHost()) {
505  sshCommand += url.host();
506  }
507 
508  session->sendText(sshCommand + '\r');
509 
510  // create view before starting the session process so that the session
511  // doesn't suffer a change in terminal size right after the session
512  // starts. some applications such as GNU Screen and Midnight Commander
513  // don't like this happening
514  createView(session);
515 
516  return session;
517 }
518 
519 void MainWindow::createView(Session* session)
520 {
521  _viewManager->createView(session);
522 }
523 
524 void MainWindow::setFocus()
525 {
526  _viewManager->activeView()->setFocus();
527 }
528 
529 void MainWindow::newWindow()
530 {
531  Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile();
532  emit newWindowRequest(defaultProfile, activeSessionDir());
533 }
534 
535 bool MainWindow::queryClose()
536 {
537  // Do not ask for confirmation during log out and power off
538  // TODO: rework the dealing of this case to make it has its own confirmation
539  // dialog.
540  if (kapp->sessionSaving()) {
541  return true;
542  }
543 
544  // Check what processes are running,
545  // if just the default shell is running don't ask for confirmation
546 
547  QStringList processesRunning;
548  foreach(Session *session, _viewManager->sessions()) {
549  if (!session)
550  continue;
551 
552  const QString defaultProc = session->program().split('/').last();
553  const QString currentProc = session->foregroundProcessName().split('/').last();
554 
555  if (currentProc.isEmpty())
556  continue;
557 
558  if (defaultProc != currentProc) {
559  processesRunning.append(currentProc);
560  }
561  }
562  if (processesRunning.count() == 0) {
563  return true;
564  }
565 
566  // NOTE: Some, if not all, of the below KWindowSystem calls are only
567  // implemented under x11 (KDE4.8 kdelibs/kdeui/windowmanagement).
568 
569  // make sure the window is shown on current desktop and is not minimized
570  KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
571  if (isMinimized()) {
572  KWindowSystem::unminimizeWindow(winId(), true);
573  }
574 
575  int result = KMessageBox::warningYesNoCancelList(this,
576  i18ncp("@info", "There is a process running in this window. "
577  "Do you still want to quit?",
578  "There are %1 processes running in this window. "
579  "Do you still want to quit?",
580  processesRunning.count()),
581  processesRunning,
582  i18nc("@title", "Confirm Close"),
583  KGuiItem(i18nc("@action:button", "Close &Window"), "window-close"),
584  KGuiItem(i18nc("@action:button", "Close Current &Tab"), "tab-close"),
585  KStandardGuiItem::cancel(),
586  "CloseAllTabs");
587 
588  switch (result) {
589  case KMessageBox::Yes:
590  return true;
591  case KMessageBox::No:
592  if (_pluggedController && _pluggedController->session()) {
593  disconnectController(_pluggedController);
594  _pluggedController->closeSession();
595  }
596  return false;
597  case KMessageBox::Cancel:
598  return false;
599  }
600 
601  return true;
602 }
603 
604 void MainWindow::saveProperties(KConfigGroup& group)
605 {
606  _viewManager->saveSessions(group);
607 }
608 
609 void MainWindow::readProperties(const KConfigGroup& group)
610 {
611  _viewManager->restoreSessions(group);
612 }
613 
614 void MainWindow::saveGlobalProperties(KConfig* config)
615 {
616  SessionManager::instance()->saveSessions(config);
617 }
618 
619 void MainWindow::readGlobalProperties(KConfig* config)
620 {
621  SessionManager::instance()->restoreSessions(config);
622 }
623 
624 void MainWindow::syncActiveShortcuts(KActionCollection* dest, const KActionCollection* source)
625 {
626  foreach(QAction * qAction, source->actions()) {
627  if (KAction* kAction = qobject_cast<KAction*>(qAction)) {
628  if (KAction* destKAction = qobject_cast<KAction*>(dest->action(kAction->objectName())))
629  destKAction->setShortcut(kAction->shortcut(KAction::ActiveShortcut), KAction::ActiveShortcut);
630  }
631  }
632 }
633 void MainWindow::showShortcutsDialog()
634 {
635  KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
636 
637  // add actions from this window and the current session controller
638  foreach(KXMLGUIClient * client, guiFactory()->clients()) {
639  dialog.addCollection(client->actionCollection());
640  }
641 
642  if (dialog.configure()) {
643  // sync shortcuts for non-session actions (defined in "konsoleui.rc") in other main windows
644  foreach(QWidget* mainWindowWidget, QApplication::topLevelWidgets()) {
645  MainWindow* mainWindow = qobject_cast<MainWindow*>(mainWindowWidget);
646  if (mainWindow && mainWindow != this)
647  syncActiveShortcuts(mainWindow->actionCollection(), actionCollection());
648  }
649  // sync shortcuts for session actions (defined in "sessionui.rc") in other session controllers.
650  // Controllers which are currently plugged in (ie. their actions are part of the current menu)
651  // must be updated immediately via syncActiveShortcuts(). Other controllers will be updated
652  // when they are plugged into a main window.
653  foreach(SessionController * controller, SessionController::allControllers()) {
654  controller->reloadXML();
655  if (controller->factory() && controller != _pluggedController)
656  syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection());
657  }
658  }
659 }
660 
661 void MainWindow::newFromProfile(Profile::Ptr profile)
662 {
663  createSession(profile, activeSessionDir());
664 }
665 void MainWindow::showManageProfilesDialog()
666 {
667  ManageProfilesDialog* dialog = new ManageProfilesDialog(this);
668  dialog->show();
669 }
670 
671 void MainWindow::showSettingsDialog()
672 {
673  if (KConfigDialog::showDialog("settings"))
674  return;
675 
676  KConfigDialog* settingsDialog = new KConfigDialog(this, "settings", KonsoleSettings::self());
677  settingsDialog->setFaceType(KPageDialog::List);
678 
679  GeneralSettings* generalSettings = new GeneralSettings(settingsDialog);
680  settingsDialog->addPage(generalSettings,
681  i18nc("@title Preferences page name", "General"),
682  "utilities-terminal");
683 
684  TabBarSettings* tabBarSettings = new TabBarSettings(settingsDialog);
685  settingsDialog->addPage(tabBarSettings,
686  i18nc("@title Preferences page name", "TabBar"),
687  "system-run");
688 
689  settingsDialog->show();
690 }
691 
692 void MainWindow::applyKonsoleSettings()
693 {
694  setMenuBarInitialVisibility(KonsoleSettings::showMenuBarByDefault());
695 
696  if (KonsoleSettings::allowMenuAccelerators()) {
697  restoreMenuAccelerators();
698  } else {
699  removeMenuAccelerators();
700  }
701 
702  setNavigationVisibility(KonsoleSettings::tabBarVisibility());
703  setNavigationPosition(KonsoleSettings::tabBarPosition());
704  setNavigationBehavior(KonsoleSettings::newTabBehavior());
705  setShowQuickButtons(KonsoleSettings::showQuickButtons());
706 
707  if (KonsoleSettings::tabBarUseUserStyleSheet()) {
708  setNavigationStyleSheetFromFile(KonsoleSettings::tabBarUserStyleSheetFile());
709  } else {
710  // Apply default values
711  setNavigationStyleSheet(KonsoleSettings::tabBarStyleSheet());
712  }
713 
714  setAutoSaveSettings("MainWindow", KonsoleSettings::saveGeometryOnExit());
715 
716  updateWindowCaption();
717 }
718 
719 void MainWindow::setNavigationVisibility(int visibility)
720 {
721  _viewManager->setNavigationVisibility(visibility);
722 }
723 
724 void MainWindow::setNavigationPosition(int position)
725 {
726  _viewManager->setNavigationPosition(position);
727 }
728 
729 void MainWindow::setNavigationStyleSheet(const QString& styleSheet)
730 {
731  _viewManager->setNavigationStyleSheet(styleSheet);
732 }
733 
734 void MainWindow::setNavigationBehavior(int behavior)
735 {
736  _viewManager->setNavigationBehavior(behavior);
737 }
738 
739 void MainWindow::setNavigationStyleSheetFromFile(const KUrl& styleSheetFile)
740 {
741  // Let's only deal w/ local files for now
742  if (!styleSheetFile.isLocalFile()) {
743  setNavigationStyleSheet(KonsoleSettings::tabBarStyleSheet());
744  }
745 
746  QFile file(styleSheetFile.toLocalFile());
747  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
748  setNavigationStyleSheet(KonsoleSettings::tabBarStyleSheet());
749  }
750 
751  QString styleSheetText;
752  QTextStream in(&file);
753  while (!in.atEnd()) {
754  styleSheetText.append(in.readLine());
755  }
756 
757  // Replace current style sheet w/ loaded file
758  setNavigationStyleSheet(styleSheetText);
759 }
760 
761 void MainWindow::setShowQuickButtons(bool show)
762 {
763  _viewManager->setShowQuickButtons(show);
764 }
765 
766 void MainWindow::activateMenuBar()
767 {
768  const QList<QAction*> menuActions = menuBar()->actions();
769 
770  if (menuActions.isEmpty())
771  return;
772 
773  // Show menubar if it is hidden at the moment
774  if (menuBar()->isHidden()) {
775  menuBar()->setVisible(true);
776  _toggleMenuBarAction->setChecked(true);
777  }
778 
779  // First menu action should be 'File'
780  QAction* menuAction = menuActions.first();
781 
782  // TODO: Handle when menubar is top level (MacOS)
783  menuBar()->setActiveAction(menuAction);
784 }
785 
786 void MainWindow::setupMainWidget()
787 {
788  QWidget* mainWindowWidget = new QWidget(this);
789  QVBoxLayout* mainWindowLayout = new QVBoxLayout();
790 
791  mainWindowLayout->addWidget(_viewManager->widget());
792  mainWindowLayout->setContentsMargins(0, 0, 0, 0);
793  mainWindowLayout->setSpacing(0);
794 
795  mainWindowWidget->setLayout(mainWindowLayout);
796 
797  setCentralWidget(mainWindowWidget);
798 }
799 
800 void MainWindow::configureNotifications()
801 {
802  KNotifyConfigWidget::configure(this);
803 }
804 
805 void MainWindow::setMenuBarInitialVisibility(bool visible)
806 {
807  _menuBarInitialVisibility = visible;
808 }
809 void MainWindow::showEvent(QShowEvent* aEvent)
810 {
811  // Make sure the 'initial' visibility is applied only once.
812  if (!_menuBarInitialVisibilityApplied) {
813  // the initial visibility of menubar should be applied at this last
814  // moment. Otherwise, the initial visibility will be determined by
815  // what KMainWindow has automatically stored in konsolerc, but not by
816  // what users has explicitly configured .
817  menuBar()->setVisible(_menuBarInitialVisibility);
818  _toggleMenuBarAction->setChecked(_menuBarInitialVisibility);
819  _menuBarInitialVisibilityApplied = true;
820  }
821 
822  // Call parent method
823  KXmlGuiWindow::showEvent(aEvent);
824 }
825 
826 bool MainWindow::focusNextPrevChild(bool)
827 {
828  // In stand-alone konsole, always disable implicit focus switching
829  // through 'Tab' and 'Shift+Tab'
830  //
831  // Kpart is another different story
832  return false;
833 }
834 
835 #include "MainWindow.moc"
836 
Konsole::ManageProfilesDialog
A dialog which lists the available types of profiles and allows the user to add new profiles...
Definition: ManageProfilesDialog.h:50
QAction::text
text
Session.h
Konsole::MainWindow::saveGlobalProperties
virtual void saveGlobalProperties(KConfig *config)
Definition: MainWindow.cpp:614
Konsole::SessionManager::instance
static SessionManager * instance()
Returns the session manager instance.
Definition: SessionManager.cpp:69
QWidget
Konsole::MainWindow::showEvent
virtual void showEvent(QShowEvent *event)
Definition: MainWindow.cpp:809
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:78
Konsole::SessionController
Provides the menu actions to manipulate a single terminal session and view pair.
Definition: SessionController.h:85
QString::append
QString & append(QChar ch)
Konsole::KonsoleSettings::tabBarPosition
static int tabBarPosition()
Get Control the position of the tab bar.
Definition: KonsoleSettings.h:224
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
Konsole::ViewManager::activeView
QWidget * activeView() const
Returns the view manager's active view.
Definition: ViewManager.cpp:118
QList::remove
iterator remove(iterator pos)
Konsole::MainWindow::focusNextPrevChild
virtual bool focusNextPrevChild(bool next)
Definition: MainWindow.cpp:826
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:550
Konsole::TabBarSettings
Definition: TabBarSettings.h:29
QAction::font
font
QTextStream::readLine
QString readLine(qint64 maxlen)
Konsole::ViewManager::saveSessions
void saveSessions(KConfigGroup &group)
Session management.
Definition: ViewManager.cpp:932
Konsole::ViewManager::managerId
int managerId() const
Definition: ViewManager.cpp:113
Konsole::MainWindow::setNavigationPosition
void setNavigationPosition(int position)
Definition: MainWindow.cpp:724
TabBarSettings.h
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QAction::data
QVariant data() const
QFont
QAction::setIcon
void setIcon(const QIcon &icon)
QMap< QString, QString >
Konsole::MainWindow::setMenuBarInitialVisibility
void setMenuBarInitialVisibility(bool visible)
Set the initial visibility of the menubar.
Definition: MainWindow.cpp:805
Konsole::KonsoleSettings::tabBarUseUserStyleSheet
static bool tabBarUseUserStyleSheet()
Get Use a user-defined .css file for the tab bar.
Definition: KonsoleSettings.h:278
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:490
Konsole::ViewManager::setShowQuickButtons
void setShowQuickButtons(bool show)
Definition: ViewManager.cpp:1123
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:332
Konsole::KonsoleSettings::tabBarStyleSheet
static QString tabBarStyleSheet()
Get Control the visual style of the tab bar.
Definition: KonsoleSettings.h:251
Konsole::SessionManager::sessionProfile
Profile::Ptr sessionProfile(Session *session) const
Returns the profile associated with a session.
Definition: SessionManager.cpp:141
QFile
Konsole::SessionManager::saveSessions
void saveSessions(KConfig *config)
Definition: SessionManager.cpp:273
QTextStream
QList::size
int size() const
Konsole::MainWindow::setNavigationStyleSheetFromFile
void setNavigationStyleSheetFromFile(const KUrl &stylesheetfile)
Definition: MainWindow.cpp:739
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:1103
Konsole::ProfileManager::defaultProfile
Profile::Ptr defaultProfile() const
Returns a Profile object describing the default profile.
Definition: ProfileManager.cpp:308
QFont::setBold
void setBold(bool enable)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QList::count
int count(const T &value) const
Konsole::MainWindow::createView
void createView(Session *session)
create view for the specified session
Definition: MainWindow.cpp:519
QList::append
void append(const T &value)
Konsole::ProfileManager::instance
static ProfileManager * instance()
Returns the profile manager instance.
Definition: ProfileManager.cpp:114
QMapIterator
KXmlGuiWindow
Konsole::MainWindow::readProperties
virtual void readProperties(const KConfigGroup &group)
Definition: MainWindow.cpp:609
QTextStream::atEnd
bool atEnd() const
QWidget::setLayout
void setLayout(QLayout *layout)
Konsole::ViewManager::restoreSessions
void restoreSessions(const KConfigGroup &group)
Definition: ViewManager.cpp:967
ProfileList.h
QMapIterator::next
Item next()
QShowEvent
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
QWidget::setFocus
void setFocus()
Konsole::MainWindow::viewManager
ViewManager * viewManager() const
Returns the view manager associated with this window.
Definition: MainWindow.cpp:201
QList::isEmpty
bool isEmpty() const
Konsole::ViewManager::setNavigationVisibility
void setNavigationVisibility(int visibility)
Definition: ViewManager.cpp:1093
Konsole::KonsoleSettings::tabBarUserStyleSheetFile
static KUrl tabBarUserStyleSheetFile()
Get The .css file to use for the tab bar style.
Definition: KonsoleSettings.h:305
Konsole::ViewManager::setNavigationStyleSheet
void setNavigationStyleSheet(const QString &styleSheet)
Definition: ViewManager.cpp:1114
QString::isEmpty
bool isEmpty() const
Konsole::KonsoleSettings::self
static KonsoleSettings * self()
Definition: KonsoleSettings.cpp:25
Konsole::MainWindow::MainWindow
MainWindow()
Constructs a new main window.
Definition: MainWindow.cpp:73
QVBoxLayout
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:604
Konsole::MainWindow::viewDetached
void viewDetached(Session *session)
Emitted when a view for one session is detached from this window.
QList::first
T & first()
Konsole::MainWindow::viewFullScreen
void viewFullScreen(bool fullScreen)
Definition: MainWindow.cpp:362
QString
QList
QMapIterator::key
const Key & key() const
Konsole::MainWindow
The main window.
Definition: MainWindow.h:57
QStringList
Konsole::ViewProperties
Encapsulates user-visible information about the terminal session currently being displayed in a view...
Definition: ViewProperties.h:44
Konsole::IncrementalSearchBar
A widget which allows users to search incrementally through a document for a a text string or regular...
Definition: IncrementalSearchBar.h:56
QAction::setData
void setData(const QVariant &userData)
Konsole::KonsoleSettings::showAppNameOnTitleBar
static bool showAppNameOnTitleBar()
Get Show "- Konsole" on the titlebar.
Definition: KonsoleSettings.h:89
QAction::setShortcut
void setShortcut(const QKeySequence &shortcut)
Konsole::ViewManager::setNavigationBehavior
void setNavigationBehavior(int behavior)
Definition: ViewManager.cpp:1141
Konsole::KonsoleSettings::newTabBehavior
static int newTabBehavior()
Get Control where to put the new tab.
Definition: KonsoleSettings.h:359
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:587
Konsole::MainWindow::setNavigationBehavior
void setNavigationBehavior(int behavior)
Definition: MainWindow.cpp:734
Konsole::SessionController::setSearchBar
void setSearchBar(IncrementalSearchBar *searchBar)
Sets the widget used for searches through the session's output.
Definition: SessionController.cpp:521
QLatin1String
QKeySequence
Konsole::KonsoleSettings::allowMenuAccelerators
static bool allowMenuAccelerators()
Get Enable menu accelerators.
Definition: KonsoleSettings.h:116
Konsole::MainWindow::readGlobalProperties
virtual void readGlobalProperties(KConfig *config)
Definition: MainWindow.cpp:619
ProfileManager.h
ViewManager.h
useTransparency
static bool useTransparency()
Definition: MainWindow.cpp:66
QAction
QList::last
T & last()
Konsole::MainWindow::setFocus
void setFocus()
Helper method to make this window get input focus.
Definition: MainWindow.cpp:524
BookmarkHandler.h
SessionManager.h
Konsole::KonsoleSettings::tabBarVisibility
static int tabBarVisibility()
Get Control the visibility of the whole tab bar.
Definition: KonsoleSettings.h:197
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:894
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:761
Konsole::Session::foregroundProcessName
QString foregroundProcessName()
Returns the name of the current foreground process.
Definition: Session.cpp:1411
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::KonsoleSettings::saveGeometryOnExit
static bool saveGeometryOnExit()
Get Use current window size on next startup.
Definition: KonsoleSettings.h:170
Konsole::MainWindow::setNavigationVisibility
void setNavigationVisibility(int visibility)
Definition: MainWindow.cpp:719
Konsole::MainWindow::createSession
Session * createSession(Profile::Ptr profile, const QString &directory)
Create a new session.
Definition: MainWindow.cpp:469
Konsole::MainWindow::queryClose
virtual bool queryClose()
Definition: MainWindow.cpp:535
Konsole::Session::sendText
Q_SCRIPTABLE void sendText(const QString &text) const
Sends text to the current foreground terminal program.
Definition: Session.cpp:819
KonsoleSettings.h
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
SessionController.h
QApplication::topLevelWidgets
QWidgetList topLevelWidgets()
QBoxLayout::setSpacing
void setSpacing(int spacing)
Konsole::Session::program
QString program() const
Returns the program name of the shell process started when run() is called.
Definition: Session.cpp:1087
Konsole::KonsoleSettings::showMenuBarByDefault
static bool showMenuBarByDefault()
Get Show menubar by default.
Definition: KonsoleSettings.h:35
QMapIterator::hasNext
bool hasNext() const
Konsole::SessionController::isValid
bool isValid() const
Returns true if the controller is valid.
Definition: SessionController.h:364
Konsole::MainWindow::setNavigationStyleSheet
void setNavigationStyleSheet(const QString &stylesheet)
Definition: MainWindow.cpp:729
Konsole::SessionManager::restoreSessions
void restoreSessions(KConfig *config)
Definition: SessionManager.cpp:300
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

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

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



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

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