MainWindow.cpp 20.3 KB
Newer Older
1
/*
2
    Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

20
21
22
// Own
#include "MainWindow.h"

23
// Qt
Dirk Mueller's avatar
Dirk Mueller committed
24
#include <QtGui/QBoxLayout>
25

26
// KDE
27
#include <KAcceleratorManager>
28
29
30
#include <KAction>
#include <KActionCollection>
#include <KActionMenu>
31
#include <KApplication>
32
#include <KCmdLineArgs>
33
#include <KShortcutsDialog>
34
35
#include <KLocale>
#include <KMenu>
36
#include <KMenuBar>
37
#include <KMessageBox>
38
#include <KService>
39
#include <KToggleAction>
40
#include <KToggleFullScreenAction>
41
#include <KToolInvocation>
42
43
#include <KStandardAction>
#include <KStandardGuiItem>
44
#include <KWindowSystem>
45
#include <KXMLGUIFactory>
46
#include <KNotifyConfigWidget>
Jekyll Wu's avatar
Jekyll Wu committed
47
#include <KConfigDialog>
48
49

// Konsole
50
#include "BookmarkHandler.h"
51
#include "IncrementalSearchBar.h"
52
#include "SessionController.h"
53
54
#include "ProfileList.h"
#include "ManageProfilesDialog.h"
55
#include "Session.h"
56
#include "ViewManager.h"
Jekyll Wu's avatar
Jekyll Wu committed
57
#include "SessionManager.h"
Jekyll Wu's avatar
Jekyll Wu committed
58
#include "KonsoleSettings.h"
Jekyll Wu's avatar
Jekyll Wu committed
59
#include "settings/GeneralSettings.h"
Jekyll Wu's avatar
Jekyll Wu committed
60
#include "settings/TabBarSettings.h"
61

62
63
using namespace Konsole;

64
65
static bool useTransparency()
{
66
67
68
    const KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
    const bool compositingAvailable = KWindowSystem::compositingActive() ||
                                      args->isSet("force-transparency");
69
70
71
    return compositingAvailable && args->isSet("transparency");
}

72
MainWindow::MainWindow()
Kurt Hindenburg's avatar
Kurt Hindenburg committed
73
74
75
76
77
78
    : KXmlGuiWindow() ,
      _bookmarkHandler(0),
      _pluggedController(0),
      _menuBarInitialVisibilityApplied(false)
{
    if (useTransparency()) {
79
80
81
82
        setAttribute(Qt::WA_TranslucentBackground);
        setAttribute(Qt::WA_NoSystemBackground, false);
    }

83
84
85
86
    // create actions for menus
    setupActions();

    // create view manager
Kurt Hindenburg's avatar
Kurt Hindenburg committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
    _viewManager = new ViewManager(this, actionCollection());
    connect(_viewManager , SIGNAL(empty()) , this , SLOT(close()));
    connect(_viewManager , SIGNAL(activeViewChanged(SessionController*)) , this ,
            SLOT(activeViewChanged(SessionController*)));
    connect(_viewManager , SIGNAL(unplugController(SessionController*)) , this ,
            SLOT(disconnectController(SessionController*)));
    connect(_viewManager , SIGNAL(viewPropertiesChanged(QList<ViewProperties*>)) ,
            bookmarkHandler() , SLOT(setViews(QList<ViewProperties*>)));

    connect(_viewManager , SIGNAL(setSaveGeometryOnExitRequest(bool)) , this ,
            SLOT(setSaveGeometryOnExit(bool)));
    connect(_viewManager , SIGNAL(updateWindowIcon()) , this ,
            SLOT(updateWindowIcon()));
    connect(_viewManager , SIGNAL(newViewRequest(Profile::Ptr)) ,
            this , SLOT(newFromProfile(Profile::Ptr)));
    connect(_viewManager , SIGNAL(newViewRequest()) ,
            this , SLOT(newTab()));
104

105
106
107
    // create main window widgets
    setupWidgets();

108
109
110
111
    // disable automatically generated accelerators in top-level
    // menu items - to avoid conflicting with Alt+[Letter] shortcuts
    // in terminal applications
    KAcceleratorManager::setNoAccel(menuBar());
112

113
114
    // create menus
    createGUI();
115

116
    // rememebr the original menu accelerators for later use
117
118
    rememberMenuAccelerators();

119
    // replace standard shortcuts which cannot be used in a terminal
120
    // emulator (as they are reserved for use by terminal applications)
121
    correctShortcuts();
122
123

    // enable save and restore of window size
Kurt Hindenburg's avatar
Kurt Hindenburg committed
124
    setAutoSaveSettings("MainWindow", true);
125
126

    // this must come at the end
Jekyll Wu's avatar
Jekyll Wu committed
127
128
    applyKonsoleSettings();
    connect(KonsoleSettings::self(), SIGNAL(configChanged()), this, SLOT(applyKonsoleSettings()));
129
}
130
131
132

void MainWindow::rememberMenuAccelerators()
{
133
    foreach(QAction* menuItem, menuBar()->actions()) {
134
135
136
137
138
        QString itemText = menuItem->text();
        menuItem->setData(itemText);
    }
}

139
140
141
142
143
144
145
146
// remove accelerators for standard menu items (eg. &File, &View, &Edit)
// etc. which are defined in kdelibs/kdeui/xmlgui/ui_standards.rc, again,
// to avoid conflicting with Alt+[Letter] terminal shortcuts
//
// TODO - Modify XMLGUI so that it allows the text for standard actions
// defined in ui_standards.rc to be re-defined in the local application
// XMLGUI file (konsoleui.rc in this case) - the text for standard items
// can then be redefined there to exclude the standard accelerators
147
148
void MainWindow::removeMenuAccelerators()
{
149
    foreach(QAction* menuItem, menuBar()->actions()) {
150
        QString itemText = menuItem->text();
151
        itemText = KGlobal::locale()->removeAcceleratorMarker(itemText);
152
153
154
        menuItem->setText(itemText);
    }
}
155

156
157
void MainWindow::recoverMenuAccelerators()
{
158
    foreach(QAction* menuItem, menuBar()->actions()) {
159
160
161
162
163
        QString itemText = menuItem->data().toString();
        menuItem->setText(itemText);
    }
}

164
165
void MainWindow::setSaveGeometryOnExit(bool save)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
166
    setAutoSaveSettings("MainWindow", save);
167
168
}

169
170
171
172
void MainWindow::correctShortcuts()
{
    // replace F1 shortcut for help contents
    QAction* helpAction = actionCollection()->action("help_contents");
Kurt Hindenburg's avatar
Kurt Hindenburg committed
173
    Q_ASSERT(helpAction);
174
    helpAction->setShortcut(QKeySequence());
175

176
177
178
    // replace Ctrl+B shortcut for bookmarks
    QAction* bookmarkAction = actionCollection()->action("add_bookmark");
    Q_ASSERT(bookmarkAction);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
179
    bookmarkAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
180
181
}

182
ViewManager* MainWindow::viewManager() const
183
184
185
186
{
    return _viewManager;
}

187
188
void MainWindow::disconnectController(SessionController* controller)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
189
190
    disconnect(controller , SIGNAL(titleChanged(ViewProperties*))
               , this , SLOT(activeViewTitleChanged(ViewProperties*)));
Robert Knight's avatar
   
Robert Knight committed
191

192
193
194
195
196
197
    // KXmlGuiFactory::removeClient() will try to access actions associated
    // with the controller internally, which may not be valid after the controller
    // itself is no longer valid (after the associated session and or view have
    // been destroyed)
    if (controller->isValid())
        guiFactory()->removeClient(controller);
Robert Knight's avatar
   
Robert Knight committed
198

199
200
201
    controller->setSearchBar(0);
}

202
203
void MainWindow::activeViewChanged(SessionController* controller)
{
204
    // associate bookmark menu with current session
205
    bookmarkHandler()->setActiveView(controller);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
206
207
208
    disconnect(bookmarkHandler() , SIGNAL(openUrl(KUrl)) , 0 , 0);
    connect(bookmarkHandler() , SIGNAL(openUrl(KUrl)) , controller ,
            SLOT(openUrl(KUrl)));
209

Kurt Hindenburg's avatar
Kurt Hindenburg committed
210
    if (_pluggedController)
211
        disconnectController(_pluggedController);
212

213
    // listen for title changes from the current session
Kurt Hindenburg's avatar
Kurt Hindenburg committed
214
    Q_ASSERT(controller);
215

Kurt Hindenburg's avatar
Kurt Hindenburg committed
216
217
    connect(controller , SIGNAL(titleChanged(ViewProperties*)) ,
            this , SLOT(activeViewTitleChanged(ViewProperties*)));
218

Kurt Hindenburg's avatar
Kurt Hindenburg committed
219
    controller->setShowMenuAction(_toggleMenuBarAction);
220
221
    guiFactory()->addClient(controller);

222
    // set the current session's search bar
Kurt Hindenburg's avatar
Kurt Hindenburg committed
223
    controller->setSearchBar(searchBar());
224

225
226
227
228
    // update session title to match newly activated session
    activeViewTitleChanged(controller);

    _pluggedController = controller;
229
230
231

    // Update window icon to newly activated session's icon
    updateWindowIcon();
232
233
234
235
236
237
238
}

void MainWindow::activeViewTitleChanged(ViewProperties* properties)
{
    setPlainCaption(properties->title());
}

239
240
241
242
243
244
void MainWindow::updateWindowIcon()
{
    if (_pluggedController)
        setWindowIcon(_pluggedController->icon());
}

245
IncrementalSearchBar* MainWindow::searchBar() const
246
{
247
    return _viewManager->searchBar();
248
249
}

250
void MainWindow::setupActions()
251
{
252
    KActionCollection* collection = actionCollection();
Jekyll Wu's avatar
Jekyll Wu committed
253
    KAction* action = 0;
254

255
    // File Menu
256
    _newTabMenuAction = new KActionMenu(KIcon("tab-new"), i18n("&New Tab"), collection);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
257
    _newTabMenuAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
258
    _newTabMenuAction->setShortcutConfigurable(true);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
259
    _newTabMenuAction->setAutoRepeat(false);
260
    connect(_newTabMenuAction, SIGNAL(triggered()), this, SLOT(newTab()));
261
262
    collection->addAction("new-tab", _newTabMenuAction);

Jekyll Wu's avatar
Jekyll Wu committed
263
    action = collection->addAction("new-window");
Kurt Hindenburg's avatar
Kurt Hindenburg committed
264
265
266
267
268
    action->setIcon(KIcon("window-new"));
    action->setText(i18n("New &Window"));
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_N));
    action->setAutoRepeat(false);
    connect(action , SIGNAL(triggered()) , this , SLOT(newWindow()));
269

Kurt Hindenburg's avatar
Kurt Hindenburg committed
270
    action = KStandardAction::quit(this , SLOT(close()) , collection);
271
272
    // the default shortcut for quit is typically Ctrl+[Some Letter, usually Q]
    // but that is reserved for use by terminal applications
Kurt Hindenburg's avatar
Kurt Hindenburg committed
273
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Q));
274
275

    // Bookmark Menu
Kurt Hindenburg's avatar
Kurt Hindenburg committed
276
277
    KActionMenu* bookmarkMenu = new KActionMenu(i18n("&Bookmarks") , collection);
    _bookmarkHandler = new BookmarkHandler(collection , bookmarkMenu->menu() , true , this);
278
    collection->addAction("bookmark" , bookmarkMenu);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
279
    connect(_bookmarkHandler , SIGNAL(openUrls(QList<KUrl>)) , this , SLOT(openUrls(QList<KUrl>)));
280

Jekyll Wu's avatar
Jekyll Wu committed
281
    // Settings Menu
282
    _toggleMenuBarAction = KStandardAction::showMenubar(menuBar(), SLOT(setVisible(bool)), collection);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
283
    _toggleMenuBarAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_M));
284

285
    // Full Screen
286
    action = KStandardAction::fullScreen(this, SLOT(viewFullScreen(bool)), this, collection);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
287
    action->setShortcut(QKeySequence());
288

Kurt Hindenburg's avatar
Kurt Hindenburg committed
289
290
    KStandardAction::configureNotifications(this , SLOT(configureNotifications()) , collection);
    KStandardAction::keyBindings(this , SLOT(showShortcutsDialog()) , collection);
Jekyll Wu's avatar
Jekyll Wu committed
291
    KStandardAction::preferences(this, SLOT(showSettingsDialog()), collection);
292

293
    action = collection->addAction("manage-profiles");
Kurt Hindenburg's avatar
Kurt Hindenburg committed
294
295
296
    action->setText(i18n("Manage Profiles..."));
    action->setIcon(KIcon("configure"));
    connect(action, SIGNAL(triggered()) , this , SLOT(showManageProfilesDialog()));
297

298
    // Set up an shortcut-only action for activating menu bar.
Jekyll Wu's avatar
Jekyll Wu committed
299
300
    action = collection->addAction("activate-menu");
    action->setText(i18n("Activate Menu"));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
301
    action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_F10));
Jekyll Wu's avatar
Jekyll Wu committed
302
    connect(action, SIGNAL(triggered()), this, SLOT(activateMenuBar()));
303
304
}

305
void MainWindow::viewFullScreen(bool fullScreen)
306
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
307
308
    if (fullScreen)
        setWindowState(windowState() | Qt::WindowFullScreen);
309
    else
Kurt Hindenburg's avatar
Kurt Hindenburg committed
310
        setWindowState(windowState() & ~Qt::WindowFullScreen);
311
}
312

313
BookmarkHandler* MainWindow::bookmarkHandler() const
314
315
316
317
{
    return _bookmarkHandler;
}

Jekyll Wu's avatar
Jekyll Wu committed
318
void MainWindow::setProfileList(ProfileList* list)
319
{
320
    sessionListChanged(list->actions());
321

Kurt Hindenburg's avatar
Kurt Hindenburg committed
322
323
    connect(list , SIGNAL(profileSelected(Profile::Ptr)) , this ,
            SLOT(newFromProfile(Profile::Ptr)));
324

Kurt Hindenburg's avatar
Kurt Hindenburg committed
325
326
    connect(list , SIGNAL(actionsChanged(QList<QAction*>)) , this ,
            SLOT(sessionListChanged(QList<QAction*>)));
327
328
329
330
}

void MainWindow::sessionListChanged(const QList<QAction*>& actions)
{
331
332
    // If only 1 profile is to be shown in the menu, only display
    // it if it is the non-default profile.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
333
    if (actions.size() > 2) {
334
        // Update the 'New Tab' KActionMenu
335
        KMenu* newTabMenu = _newTabMenuAction->menu();
336
        newTabMenu->clear();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
337
        foreach(QAction * action, actions) {
338
339
            newTabMenu->addAction(action);

340
            // NOTE: defaultProfile seems to not work here, sigh.
341
342
343
344
345
346
347
348
            Profile::Ptr profile = SessionManager::instance()->defaultProfile();
            if (profile && profile->name() == action->text().remove('&')) {
                action->setIcon(KIcon(profile->icon(), NULL, QStringList("emblem-favorite")));
                newTabMenu->setDefaultAction(action);
                QFont font = action->font();
                font.setBold(true);
                action->setFont(font);
            }
349
        }
Kurt Hindenburg's avatar
Kurt Hindenburg committed
350
    } else {
351
        KMenu* newTabMenu = _newTabMenuAction->menu();
352
353
        newTabMenu->clear();
        Profile::Ptr profile = SessionManager::instance()->defaultProfile();
354

355
        // NOTE: Compare names w/o any '&'
Kurt Hindenburg's avatar
Kurt Hindenburg committed
356
        if (actions.size() == 2 &&  actions[1]->text().remove('&') != profile->name()) {
357
            newTabMenu->addAction(actions[1]);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
358
        } else {
359
360
361
            delete newTabMenu;
        }
    }
362
363
}

364
365
QString MainWindow::activeSessionDir() const
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
366
367
    if (_pluggedController) {
        if (Session* session = _pluggedController->session()) {
368
369
370
371
            // For new tabs to get the correct working directory,
            // force the updating of the currentWorkingDirectory.
            session->getDynamicTitle();
        }
372
        return _pluggedController->currentDir();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
373
    } else {
374
        return QString();
375
    }
376
377
}

378
379
void MainWindow::openUrls(const QList<KUrl>& urls)
{
380
381
    Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile();

382
    foreach(const KUrl& url , urls) {
Kurt Hindenburg's avatar
Kurt Hindenburg committed
383
        if (url.isLocalFile())
384
            emit newSessionRequest(defaultProfile , url.path() , _viewManager);
385

Kurt Hindenburg's avatar
Kurt Hindenburg committed
386
        else if (url.protocol() == "ssh")
387
            emit newSSHSessionRequest(defaultProfile , url , _viewManager);
388
    }
389
390
}

391
void MainWindow::newTab()
392
{
393
394
    Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile();
    emit newSessionRequest(defaultProfile , activeSessionDir() , _viewManager);
395
396
}

397
void MainWindow::newWindow()
398
{
399
400
    Profile::Ptr defaultProfile = SessionManager::instance()->defaultProfile();
    emit newWindowRequest(defaultProfile , activeSessionDir());
401
402
}

403
404
bool MainWindow::queryClose()
{
405
406
407
408
    // TODO: Ideally, we should check what process is running instead
    //       of just how many sessions are running.
    // If only 1 session is running, don't ask user to confirm close.
    if (_viewManager->viewProperties().count() < 2)
409
410
        return true;

411
    int result = KMessageBox::warningYesNoCancel(this,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
412
413
414
415
416
417
418
419
420
                 i18n("You have multiple tabs in this window, "
                      "are you sure you want to quit?"),
                 i18n("Confirm Close"),
                 KStandardGuiItem::quit(),
                 KGuiItem(i18n("Close Current Tab"), "tab-close"),
                 KStandardGuiItem::cancel(),
                 "CloseAllTabs");

    switch (result) {
421
422
423
    case KMessageBox::Yes:
        return true;
    case KMessageBox::No:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
424
        if (_pluggedController && _pluggedController->session()) {
425
            disconnectController(_pluggedController);
426
            _pluggedController->closeSession();
427
        }
428
429
430
        return false;
    case KMessageBox::Cancel:
        return false;
431
432
433
434
    }

    return true;
}
Robert Knight's avatar
   
Robert Knight committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455

void MainWindow::saveProperties(KConfigGroup& group)
{
    _viewManager->saveSessions(group);
}

void MainWindow::readProperties(const KConfigGroup& group)
{
    _viewManager->restoreSessions(group);
}

void MainWindow::saveGlobalProperties(KConfig* config)
{
    SessionManager::instance()->saveSessions(config);
}

void MainWindow::readGlobalProperties(KConfig* config)
{
    SessionManager::instance()->restoreSessions(config);
}

456
457
void MainWindow::syncActiveShortcuts(KActionCollection* dest, const KActionCollection* source)
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
458
459
460
461
    foreach(QAction * qAction, source->actions()) {
        if (KAction* kAction = qobject_cast<KAction*>(qAction)) {
            if (KAction* destKAction = qobject_cast<KAction*>(dest->action(kAction->objectName())))
                destKAction->setShortcut(kAction->shortcut(KAction::ActiveShortcut), KAction::ActiveShortcut);
462
463
464
        }
    }
}
465
void MainWindow::showShortcutsDialog()
466
{
467
468
469
    KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);

    // add actions from this window and the current session controller
Jekyll Wu's avatar
Jekyll Wu committed
470
471
472
    foreach(KXMLGUIClient * client, guiFactory()->clients()) {
        dialog.addCollection(client->actionCollection());
    }
473

Kurt Hindenburg's avatar
Kurt Hindenburg committed
474
    if (dialog.configure()) {
475
        // sync shortcuts for non-session actions (defined in "konsoleui.rc") in other main windows
Kurt Hindenburg's avatar
Kurt Hindenburg committed
476
        foreach(QWidget * widget, QApplication::topLevelWidgets()) {
Robert Knight's avatar
Robert Knight committed
477
478
            MainWindow* window = qobject_cast<MainWindow*>(widget);
            if (window && window != this)
Kurt Hindenburg's avatar
Kurt Hindenburg committed
479
                syncActiveShortcuts(window->actionCollection(), actionCollection());
480
        }
481
        // sync shortcuts for session actions (defined in "sessionui.rc") in other session controllers.
482
483
484
        // Controllers which are currently plugged in (ie. their actions are part of the current menu)
        // must be updated immediately via syncActiveShortcuts().  Other controllers will be updated
        // when they are plugged into a main window.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
485
        foreach(SessionController * controller, SessionController::allControllers()) {
486
487
            controller->reloadXML();
            if (controller->factory() && controller != _pluggedController)
Kurt Hindenburg's avatar
Kurt Hindenburg committed
488
                syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection());
489
490
        }
    }
491
492
}

493
void MainWindow::newFromProfile(Profile::Ptr profile)
494
{
495
    emit newSessionRequest(profile, activeSessionDir(), _viewManager);
496
}
497
void MainWindow::showManageProfilesDialog()
498
{
499
500
    ManageProfilesDialog* dialog = new ManageProfilesDialog(this);
    dialog->show();
501
}
502

Jekyll Wu's avatar
Jekyll Wu committed
503
504
505
506
507
void MainWindow::showSettingsDialog()
{
    if (KConfigDialog::showDialog("settings"))
        return;

Jekyll Wu's avatar
Jekyll Wu committed
508
    KConfigDialog* settingsDialog = new KConfigDialog(this, "settings", KonsoleSettings::self());
Jekyll Wu's avatar
Jekyll Wu committed
509
510
511
512
513
    settingsDialog->setFaceType(KPageDialog::List);

    GeneralSettings* generalSettings = new GeneralSettings(settingsDialog);
    settingsDialog->addPage(generalSettings,
                            i18nc("@title Preferences page name", "General"),
514
                            "utilities-terminal");
Jekyll Wu's avatar
Jekyll Wu committed
515
516
517
518
519

    TabBarSettings* tabBarSettings = new TabBarSettings(settingsDialog);
    settingsDialog->addPage(tabBarSettings,
                            i18nc("@title Preferences page name", "TabBar"),
                            "system-run");
Jekyll Wu's avatar
Jekyll Wu committed
520
521
522
523

    settingsDialog->show();
}

Jekyll Wu's avatar
Jekyll Wu committed
524
void MainWindow::applyKonsoleSettings()
525
{
Jekyll Wu's avatar
Jekyll Wu committed
526
    if ( KonsoleSettings::allowMenuAccelerators() ) {
527
528
529
        recoverMenuAccelerators();
    }
    else {
530
531
        removeMenuAccelerators();
    }
532

533
    ViewManager::NavigationOptions options;
Jekyll Wu's avatar
Jekyll Wu committed
534
535
536
537
    options.visibility       = KonsoleSettings::tabBarVisibility();
    options.position         = KonsoleSettings::tabBarPosition();
    options.newTabBehavior   = KonsoleSettings::newTabBehavior();
    options.showQuickButtons = KonsoleSettings::showQuickButtons();
538
539
540

    _viewManager->updateNavigationOptions(options);

Jekyll Wu's avatar
Jekyll Wu committed
541
    // setAutoSaveSettings("MainWindow", KonsoleSettings::saveGeometryOnExit());
542
543
}

544
545
void MainWindow::activateMenuBar()
{
546
    const QList<QAction*> menuActions = menuBar()->actions();
547

548
549
550
    if (menuActions.isEmpty())
        return;

551
552
    // Show menubar if it is hidden at the moment
    if (menuBar()->isHidden()) {
553
        menuBar()->setVisible(true);
554
        _toggleMenuBarAction->setChecked(true);
555
556
    }

557
558
559
    // First menu action should be 'File'
    QAction* menuAction = menuActions.first();

560
    // TODO: Handle when menubar is top level (MacOS)
561
    menuBar()->setActiveAction(menuAction);
562
563
}

564
void MainWindow::setupWidgets()
565
{
566
567
568
    QWidget* widget = new QWidget(this);
    QVBoxLayout* layout = new QVBoxLayout();

Kurt Hindenburg's avatar
Kurt Hindenburg committed
569
    layout->addWidget(_viewManager->widget());
570
    layout->setContentsMargins(0, 0, 0, 0);
571
    layout->setSpacing(0);
572

573
    widget->setLayout(layout);
574

575
    setCentralWidget(widget);
576
}
577

578
579
void MainWindow::configureNotifications()
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
580
    KNotifyConfigWidget::configure(this);
581
582
}

583
void MainWindow::showEvent(QShowEvent* event)
584
{
585
    // Make sure the 'initial' visibility is applied only once.
Kurt Hindenburg's avatar
Kurt Hindenburg committed
586
    if (! _menuBarInitialVisibilityApplied) {
587
588
589
590
591

        // the initial visibility of menubar should be applied at this last
        // moment. Otherwise, the initial visibility will be determined by
        // what KMainWindow has automatically stored in konsolerc, but not by
        // what users has explicitly configured .
Jekyll Wu's avatar
Jekyll Wu committed
592
593
        menuBar()->setVisible(KonsoleSettings::showMenuBar());
        _toggleMenuBarAction->setChecked(KonsoleSettings::showMenuBar());
594
595
596
597

        _menuBarInitialVisibilityApplied = true;
    }

598
599
600
601
    // Call parent method
    KXmlGuiWindow::showEvent(event);
}

Kurt Hindenburg's avatar
Kurt Hindenburg committed
602
bool MainWindow::focusNextPrevChild(bool)
603
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
604
605
    // In stand-alone konsole, always disable implicit focus switching
    // through 'Tab' and 'Shift+Tab'
606
607
608
609
610
    //
    // Kpart is another different story
    return false;
}

Jekyll Wu's avatar
Jekyll Wu committed
611

612
#include "MainWindow.moc"
Robert Knight's avatar
   
Robert Knight committed
613