2 This file is part of KAddressBook.
4 Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "mainwindow.h"
22 #include "mainwidget.h"
24 #include "xxport/xxportmanager.h"
26 #include <KConfigGroup>
29 #include <KActionCollection>
30 #include <KEditToolBar>
31 #include <KShortcutsDialog>
32 #include <KStandardAction>
33 #include <KLocalizedString>
34 #include <KSharedConfig>
35 #include <KMessageBox>
36 #include <KToggleAction>
39 MainWindow::MainWindow()
40 : KXmlGuiWindow(Q_NULLPTR
)
42 mMainWidget
= new MainWidget(this, this);
44 setCentralWidget(mMainWidget
);
48 setStandardToolBarMenuEnabled(true);
50 toolBar()->setToolButtonStyle(Qt::ToolButtonTextUnderIcon
);
52 setupGUI(Save
| Create
, QStringLiteral("kaddressbookui.rc"));
54 setAutoSaveSettings();
55 slotToggleMenubar(true);
58 MainWindow::~MainWindow()
62 MainWidget
*MainWindow::mainWidget() const
67 void MainWindow::initActions()
69 KStandardAction::quit(this, SLOT(close()), actionCollection());
70 mHideMenuBarAction
= KStandardAction::showMenubar(this, SLOT(slotToggleMenubar()), actionCollection());
73 KStandardAction::keyBindings(this, SLOT(configureKeyBindings()), actionCollection());
75 i18nc("@info:whatsthis",
76 "You will be presented with a dialog where you can configure "
77 "the application-wide shortcuts."));
78 KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
79 KStandardAction::preferences(this, SLOT(configure()), actionCollection());
82 void MainWindow::configure()
84 mMainWidget
->configure();
87 void MainWindow::configureKeyBindings()
89 if (KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed
, this)) {
90 mMainWidget
->updateQuickSearchText();
94 void MainWindow::configureToolbars()
96 KConfigGroup grp
= KSharedConfig::openConfig()->group("MainWindow");
97 saveMainWindowSettings(grp
);
99 KEditToolBar
dlg(factory());
100 connect(&dlg
, &KEditToolBar::newToolBarConfig
, this, &MainWindow::newToolbarConfig
);
104 void MainWindow::newToolbarConfig()
106 createGUI(QStringLiteral("kaddressbookui.rc"));
108 applyMainWindowSettings(KSharedConfig::openConfig()->group("MainWindow"));
111 void MainWindow::slotToggleMenubar(bool dontShowWarning
)
114 if (mHideMenuBarAction
->isChecked()) {
117 if (!dontShowWarning
) {
118 const QString accel
= mHideMenuBarAction
->shortcut().toString();
119 KMessageBox::information(this,
120 i18n("<qt>This will hide the menu bar completely."
121 " You can show it again by typing %1.</qt>", accel
),
122 i18n("Hide menu bar"), QStringLiteral("HideMenuBarWarning"));
126 Settings::self()->setShowMenuBar(mHideMenuBarAction
->isChecked());