1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/*
* Copyright (C) 1999-2002 Bernd Gehrmann
* bernd@mail.berlios.de
* Copyright (c) 2002-2004 Christian Loose <christian.loose@kdemail.net>
*
* 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.
*/
#include "cervisiashell.h"
#include <KConfigGroup>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KPluginMetaData>
#include <KSharedConfig>
#include <kactioncollection.h>
#include <kconfig.h>
#include <kedittoolbar.h>
#include <khelpmenu.h>
#include <kmessagebox.h>
#include <kshortcutsdialog.h>
#include <kstandardaction.h>
#include <QAction>
#include <QApplication>
CervisiaShell::CervisiaShell(const char *name)
: m_part(0)
{
setObjectName(name);
setXMLFile("cervisiashellui.rc");
KPluginMetaData md(QStringLiteral("kf5/parts/cervisiapart"));
const auto result = KPluginFactory::instantiatePlugin<KParts::ReadOnlyPart>(md, this);
if (result) {
m_part = result.plugin;
m_part->setObjectName("cervisiaview");
setCentralWidget(m_part->widget());
} else {
KMessageBox::detailedError(this,
i18n("The Cervisia library could not be loaded."),
result.errorString + QLatin1String("\n") + md.pluginId() + QLatin1String("\n") + md.fileName());
qApp->quit();
return;
}
setupActions();
//
// Magic needed for status texts
//
createGUI(m_part);
// enable auto-save of toolbar/menubar/statusbar and window size settings
// and apply the previously saved settings
setAutoSaveSettings("MainWindow", true);
// if the session is restoring, we already read the settings
if (!qApp->isSessionRestored())
readSettings();
}
CervisiaShell::~CervisiaShell()
{
delete m_part;
}
void CervisiaShell::setupActions()
{
setStandardToolBarMenuEnabled(true);
QAction *action = KStandardAction::configureToolbars(this, SLOT(slotConfigureToolBars()), actionCollection());
QString hint = i18n("Allows you to configure the toolbar");
action->setToolTip(hint);
action->setWhatsThis(hint);
action = KStandardAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection());
hint = i18n("Allows you to customize the keybindings");
action->setToolTip(hint);
action->setWhatsThis(hint);
action = KStandardAction::quit(this, SLOT(close()), actionCollection());
hint = i18n("Exits Cervisia");
action->setToolTip(hint);
action->setWhatsThis(hint);
setHelpMenuEnabled(true);
}
void CervisiaShell::openURL()
{
if (m_part && !m_lastOpenDir.isEmpty())
m_part->openUrl(QUrl::fromLocalFile(m_lastOpenDir));
}
void CervisiaShell::openURL(const QUrl &url)
{
if (m_part)
m_part->openUrl(url);
}
void CervisiaShell::slotConfigureKeys()
{
KShortcutsDialog dlg;
dlg.addCollection(actionCollection());
if (m_part)
dlg.addCollection(m_part->actionCollection());
dlg.configure();
}
void CervisiaShell::slotConfigureToolBars()
{
KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
saveMainWindowSettings(cg);
KEditToolBar dlg(factory());
connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()));
dlg.exec();
}
void CervisiaShell::slotNewToolbarConfig()
{
KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
applyMainWindowSettings(cg);
}
void CervisiaShell::closeEvent(QCloseEvent *event)
{
writeSettings();
KParts::MainWindow::closeEvent(event);
}
void CervisiaShell::readProperties(const KConfigGroup &config)
{
m_lastOpenDir = config.readPathEntry("Current Directory", QString());
// if the session is restoring, make sure we open the URL
// since it's not handled by main()
if (qApp->isSessionRestored())
openURL();
}
void CervisiaShell::saveProperties(KConfigGroup &config)
{
// Save current working directory (if part was created)
if (m_part) {
config.writePathEntry("Current Directory", m_part->url().path());
// write to disk
config.sync();
}
}
void CervisiaShell::readSettings()
{
KConfigGroup cg(KSharedConfig::openConfig(), "Session");
readProperties(cg);
}
void CervisiaShell::writeSettings()
{
KConfigGroup cg(KSharedConfig::openConfig(), "Session");
saveProperties(cg);
}
// Local Variables:
// c-basic-offset: 4
// End:
|