24 #include <QVBoxLayout>
27 #include <KAcceleratorManager>
29 #include <KActionCollection>
30 #include <KActionMenu>
31 #include <KCmdLineArgs>
32 #include <KShortcutsDialog>
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>
59 using namespace Konsole;
68 const KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
69 const bool compositingAvailable = KWindowSystem::compositingActive();
70 return compositingAvailable && args->isSet(
"transparency");
76 , _pluggedController(0)
77 , _menuBarInitialVisibility(true)
78 , _menuBarInitialVisibilityApplied(false)
82 setAttribute(Qt::WA_TranslucentBackground,
true);
84 setAttribute(Qt::WA_NoSystemBackground,
false);
91 _viewManager =
new ViewManager(
this, actionCollection());
92 connect(_viewManager, SIGNAL(empty()),
this, SLOT(close()));
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)),
106 connect(_viewManager, SIGNAL(newViewRequest()),
107 this, SLOT(newTab()));
117 KAcceleratorManager::setNoAccel(menuBar());
123 rememberMenuAccelerators();
127 correctStandardShortcuts();
132 applyKonsoleSettings();
136 void MainWindow::rememberMenuAccelerators()
138 foreach(QAction* menuItem, menuBar()->actions()) {
139 QString itemText = menuItem->text();
140 menuItem->setData(itemText);
152 void MainWindow::removeMenuAccelerators()
154 foreach(QAction* menuItem, menuBar()->actions()) {
155 QString itemText = menuItem->text();
156 itemText = KGlobal::locale()->removeAcceleratorMarker(itemText);
157 menuItem->setText(itemText);
161 void MainWindow::restoreMenuAccelerators()
163 foreach(QAction* menuItem, menuBar()->actions()) {
164 QString itemText = menuItem->data().toString();
165 menuItem->setText(itemText);
169 void MainWindow::setSaveGeometryOnExit(
bool save)
172 setAutoSaveSettings(
"MainWindow", save);
175 void MainWindow::correctStandardShortcuts()
178 QAction* helpAction = actionCollection()->action(
"help_contents");
180 helpAction->setShortcut(QKeySequence());
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));
201 disconnect(controller, SIGNAL(rawTitleChanged()),
202 this, SLOT(updateWindowCaption()));
209 guiFactory()->removeClient(controller);
218 disconnect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), 0, 0);
219 connect(bookmarkHandler(), SIGNAL(openUrl(KUrl)), controller,
220 SLOT(openUrl(KUrl)));
222 if (_pluggedController)
223 disconnectController(_pluggedController);
225 Q_ASSERT(controller);
226 _pluggedController = controller;
231 connect(controller, SIGNAL(rawTitleChanged()),
232 this, SLOT(updateWindowCaption()));
235 guiFactory()->addClient(controller);
241 activeViewTitleChanged(controller);
247 void MainWindow::activeViewTitleChanged(
ViewProperties* properties)
249 Q_UNUSED(properties);
250 updateWindowCaption();
253 void MainWindow::updateWindowCaption()
255 if (!_pluggedController)
258 const QString& title = _pluggedController->title();
259 const QString& userTitle = _pluggedController->userTitle();
262 QString caption = title;
272 void MainWindow::updateWindowIcon()
274 if (_pluggedController)
275 setWindowIcon(_pluggedController->icon());
283 void MainWindow::setupActions()
285 KActionCollection* collection = actionCollection();
286 KAction* menuAction = 0;
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);
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()));
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()));
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()));
317 KActionMenu* bookmarkMenu =
new KActionMenu(i18nc(
"@title:menu",
"&Bookmarks"), collection);
318 _bookmarkHandler =
new BookmarkHandler(collection, bookmarkMenu->menu(),
true,
this);
319 collection->addAction(
"bookmark", bookmarkMenu);
323 _toggleMenuBarAction = KStandardAction::showMenubar(menuBar(), SLOT(setVisible(
bool)), collection);
324 _toggleMenuBarAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
327 menuAction = KStandardAction::fullScreen(
this, SLOT(
viewFullScreen(
bool)),
this, collection);
328 menuAction->setShortcut(QKeySequence());
330 KStandardAction::configureNotifications(
this, SLOT(configureNotifications()), collection);
331 KStandardAction::keyBindings(
this, SLOT(showShortcutsDialog()), collection);
332 KStandardAction::preferences(
this, SLOT(showSettingsDialog()), collection);
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()));
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()));
349 setWindowState(windowState() | Qt::WindowFullScreen);
351 setWindowState(windowState() & ~Qt::WindowFullScreen);
356 return _bookmarkHandler;
361 profileListChanged(list->
actions());
363 connect(list, SIGNAL(profileSelected(
Profile::Ptr)),
this,
370 void MainWindow::profileListChanged(
const QList<QAction*>& sessionActions)
374 if (sessionActions.size() > 2) {
376 KMenu* newTabMenu = _newTabMenuAction->menu();
378 foreach(QAction* sessionAction, sessionActions) {
379 newTabMenu->addAction(sessionAction);
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);
392 KMenu* newTabMenu = _newTabMenuAction->menu();
397 if (sessionActions.size() == 2 && sessionActions[1]->text().remove(
'&') != profile->name()) {
398 newTabMenu->addAction(sessionActions[1]);
405 QString MainWindow::activeSessionDir()
const
407 if (_pluggedController) {
408 if (
Session* session = _pluggedController->session()) {
411 session->getDynamicTitle();
413 return _pluggedController->currentDir();
423 foreach(
const KUrl& url, urls) {
424 if (url.isLocalFile())
427 else if (url.protocol() ==
"ssh")
432 void MainWindow::newTab()
438 void MainWindow::cloneTab()
440 Q_ASSERT(_pluggedController);
442 Session* session = _pluggedController->session();
460 if (!directory.isEmpty() && profile->startInCurrentSessionDir())
481 QString sshCommand =
"ssh ";
482 if (url.port() > -1) {
483 sshCommand += QString(
"-p %1 ").arg(url.port());
486 sshCommand += (url.user() +
'@');
489 sshCommand += url.host();
492 session->
sendText(sshCommand +
'\r');
513 void MainWindow::newWindow()
524 if (kapp->sessionSaving()) {
531 QStringList processesRunning;
536 const QString defaultProc = session->
program().split(
'/').last();
539 if (currentProc.isEmpty())
542 if (defaultProc != currentProc) {
543 processesRunning.append(currentProc);
546 if (processesRunning.count() == 0) {
554 KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
556 KWindowSystem::unminimizeWindow(winId(),
true);
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()),
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(),
573 case KMessageBox::Yes:
575 case KMessageBox::No:
576 if (_pluggedController && _pluggedController->session()) {
577 disconnectController(_pluggedController);
578 _pluggedController->closeSession();
581 case KMessageBox::Cancel:
608 void MainWindow::syncActiveShortcuts(KActionCollection* dest,
const KActionCollection* source)
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);
617 void MainWindow::showShortcutsDialog()
619 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed,
this);
623 dialog.addCollection(client->actionCollection());
626 if (dialog.configure()) {
628 foreach(
QWidget* mainWindowWidget, QApplication::topLevelWidgets()) {
630 if (mainWindow && mainWindow !=
this)
631 syncActiveShortcuts(mainWindow->actionCollection(), actionCollection());
638 controller->reloadXML();
639 if (controller->factory() && controller != _pluggedController)
640 syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection());
649 void MainWindow::showManageProfilesDialog()
655 void MainWindow::showSettingsDialog()
657 if (KConfigDialog::showDialog(
"settings"))
661 settingsDialog->setFaceType(KPageDialog::List);
664 settingsDialog->addPage(generalSettings,
665 i18nc(
"@title Preferences page name",
"General"),
666 "utilities-terminal");
669 settingsDialog->addPage(tabBarSettings,
670 i18nc(
"@title Preferences page name",
"TabBar"),
673 settingsDialog->show();
676 void MainWindow::applyKonsoleSettings()
681 restoreMenuAccelerators();
683 removeMenuAccelerators();
694 updateWindowCaption();
722 void MainWindow::activateMenuBar()
726 if (menuActions.isEmpty())
730 if (menuBar()->isHidden()) {
731 menuBar()->setVisible(
true);
732 _toggleMenuBarAction->setChecked(
true);
736 QAction* menuAction = menuActions.first();
739 menuBar()->setActiveAction(menuAction);
742 void MainWindow::setupMainWidget()
745 QVBoxLayout* mainWindowLayout =
new QVBoxLayout();
747 mainWindowLayout->addWidget(_viewManager->
widget());
748 mainWindowLayout->setContentsMargins(0, 0, 0, 0);
749 mainWindowLayout->setSpacing(0);
751 mainWindowWidget->setLayout(mainWindowLayout);
753 setCentralWidget(mainWindowWidget);
756 void MainWindow::configureNotifications()
758 KNotifyConfigWidget::configure(
this);
763 _menuBarInitialVisibility = visible;
768 if (!_menuBarInitialVisibilityApplied) {
773 menuBar()->setVisible(_menuBarInitialVisibility);
774 _toggleMenuBarAction->setChecked(_menuBarInitialVisibility);
775 _menuBarInitialVisibilityApplied =
true;
779 KXmlGuiWindow::showEvent(aEvent);
791 #include "MainWindow.moc"
A dialog which lists the available types of profiles and allows the user to add new profiles...
virtual void saveGlobalProperties(KConfig *config)
static SessionManager * instance()
Returns the session manager instance.
virtual void showEvent(QShowEvent *event)
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Provides the menu actions to manipulate a single terminal session and view pair.
static int tabBarPosition()
Get Control the position of the tab bar.
QWidget * activeView() const
Returns the view manager's active view.
virtual bool focusNextPrevChild(bool next)
QList< QAction * > actions()
Returns a list of actions representing profiles.
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.
void setShowMenuAction(QAction *action)
Sets the action displayed in the session's context menu to hide or show the menu bar.
void saveSessions(KConfigGroup &group)
Session management.
void setNavigationPosition(int position)
void setMenuBarInitialVisibility(bool visible)
Set the initial visibility of the menubar.
void setActiveView(ViewProperties *view)
ProfileList provides a list of actions which represent session profiles that a SessionManager can cre...
Session * createSSHSession(Profile::Ptr profile, const KUrl &url)
create a new SSH session.
void setShowQuickButtons(bool show)
static QSet< SessionController * > allControllers()
Returns the set of all controllers that exist.
QList< Session * > sessions()
Returns a list of sessions in this ViewManager.
static bool showQuickButtons()
Get Control the visibility of quick buttons on the tab bar.
static QString tabBarStyleSheet()
Get Control the visual style of the tab bar.
Profile::Ptr sessionProfile(Session *session) const
Returns the profile associated with a session.
void saveSessions(KConfig *config)
static bool showWindowTitleOnTitleBar()
Get Show window title on the titlebar.
Manages the terminal display widgets in a Konsole window or part.
void setNavigationPosition(int position)
Profile::Ptr defaultProfile() const
Returns a Profile object describing the default profile.
void createView(Session *session)
create view for the specified session
static ProfileManager * instance()
Returns the profile manager instance.
virtual void readProperties(const KConfigGroup &group)
void restoreSessions(const KConfigGroup &group)
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.
ViewManager * viewManager() const
Returns the view manager associated with this window.
void setNavigationVisibility(int visibility)
void setNavigationStyleSheet(const QString &styleSheet)
static KonsoleSettings * self()
MainWindow()
Constructs a new main window.
void setInitialWorkingDirectory(const QString &dir)
Sets the initial working directory for the session when it is run This has no effect once the session...
virtual void saveProperties(KConfigGroup &group)
void viewDetached(Session *session)
Emitted when a view for one session is detached from this window.
void viewFullScreen(bool fullScreen)
Encapsulates user-visible information about the terminal session currently being displayed in a view...
A widget which allows users to search incrementally through a document for a a text string or regular...
void setNavigationBehavior(int behavior)
static int newTabBehavior()
Get Control where to put the new tab.
KSharedPtr< Profile > Ptr
void createView(Session *session)
Creates a new view to display the output from and deliver input to session.
void setNavigationBehavior(int behavior)
void setSearchBar(IncrementalSearchBar *searchBar)
Sets the widget used for searches through the session's output.
static bool allowMenuAccelerators()
Get Enable menu accelerators.
virtual void readGlobalProperties(KConfig *config)
static bool useTransparency()
void setFocus()
Helper method to make this window get input focus.
static int tabBarVisibility()
Get Control the visibility of the whole tab bar.
IncrementalSearchBar * searchBar() const
Returns the search bar.
void addEnvironmentEntry(const QString &entry)
Adds one entry for the environment of this session entry should be like VARIABLE=VALUE.
Session * createSession(Profile::Ptr profile=Profile::Ptr())
Creates a new session using the settings specified by the specified profile.
void setShowQuickButtons(bool show)
QString foregroundProcessName()
Returns the name of the current foreground process.
QWidget * widget() const
Return the main widget for the view manager which holds all of the views managed by this ViewManager ...
void setNavigationVisibility(int visibility)
Session * createSession(Profile::Ptr profile, const QString &directory)
Create a new session.
virtual bool queryClose()
Q_SCRIPTABLE void sendText(const QString &text) const
Sends text to the current foreground terminal program.
QString program() const
Returns the program name of the shell process started when run() is called.
static bool showMenuBarByDefault()
Get Show menubar by default.
bool isValid() const
Returns true if the controller is valid.
void setNavigationStyleSheet(const QString &stylesheet)
void restoreSessions(KConfig *config)