Warning, file /sdk/cervisia/cervisiashell.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 1999-2002 Bernd Gehrmann 0003 * bernd@mail.berlios.de 0004 * Copyright (c) 2002-2004 Christian Loose <christian.loose@kdemail.net> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation; either version 2 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "cervisiashell.h" 0022 0023 #include <KConfigGroup> 0024 #include <KLocalizedString> 0025 #include <KSharedConfig> 0026 #include <kactioncollection.h> 0027 #include <kconfig.h> 0028 #include <kedittoolbar.h> 0029 #include <khelpmenu.h> 0030 #include <kmessagebox.h> 0031 #include <kpluginfactory.h> 0032 #include <kpluginloader.h> 0033 #include <kshortcutsdialog.h> 0034 #include <kstandardaction.h> 0035 0036 #include <QAction> 0037 #include <QApplication> 0038 0039 CervisiaShell::CervisiaShell(const char *name) 0040 : m_part(0) 0041 { 0042 setObjectName(name); 0043 setXMLFile("cervisiashellui.rc"); 0044 0045 KPluginLoader loader("cervisiapart5"); 0046 if (KPluginFactory *factory = loader.factory()) { 0047 m_part = factory->create<KParts::ReadOnlyPart>(this); 0048 if (m_part) { 0049 m_part->setObjectName("cervisiaview"); 0050 setCentralWidget(m_part->widget()); 0051 } 0052 } else { 0053 KMessageBox::detailedError(this, 0054 i18n("The Cervisia library could not be loaded."), 0055 loader.errorString() + QLatin1String("\n") + loader.pluginName() + QLatin1String("\n") + loader.fileName()); 0056 qApp->quit(); 0057 return; 0058 } 0059 0060 setupActions(); 0061 0062 // 0063 // Magic needed for status texts 0064 // 0065 createGUI(m_part); 0066 0067 // enable auto-save of toolbar/menubar/statusbar and window size settings 0068 // and apply the previously saved settings 0069 setAutoSaveSettings("MainWindow", true); 0070 0071 // if the session is restoring, we already read the settings 0072 if (!qApp->isSessionRestored()) 0073 readSettings(); 0074 } 0075 0076 CervisiaShell::~CervisiaShell() 0077 { 0078 delete m_part; 0079 } 0080 0081 void CervisiaShell::setupActions() 0082 { 0083 setStandardToolBarMenuEnabled(true); 0084 0085 QAction *action = KStandardAction::configureToolbars(this, SLOT(slotConfigureToolBars()), actionCollection()); 0086 QString hint = i18n("Allows you to configure the toolbar"); 0087 action->setToolTip(hint); 0088 action->setWhatsThis(hint); 0089 0090 action = KStandardAction::keyBindings(this, SLOT(slotConfigureKeys()), actionCollection()); 0091 hint = i18n("Allows you to customize the keybindings"); 0092 action->setToolTip(hint); 0093 action->setWhatsThis(hint); 0094 0095 action = KStandardAction::quit(this, SLOT(close()), actionCollection()); 0096 hint = i18n("Exits Cervisia"); 0097 action->setToolTip(hint); 0098 action->setWhatsThis(hint); 0099 0100 setHelpMenuEnabled(true); 0101 } 0102 0103 void CervisiaShell::openURL() 0104 { 0105 if (m_part && !m_lastOpenDir.isEmpty()) 0106 m_part->openUrl(QUrl::fromLocalFile(m_lastOpenDir)); 0107 } 0108 0109 void CervisiaShell::openURL(const QUrl &url) 0110 { 0111 if (m_part) 0112 m_part->openUrl(url); 0113 } 0114 0115 void CervisiaShell::slotConfigureKeys() 0116 { 0117 KShortcutsDialog dlg; 0118 dlg.addCollection(actionCollection()); 0119 if (m_part) 0120 dlg.addCollection(m_part->actionCollection()); 0121 0122 dlg.configure(); 0123 } 0124 0125 void CervisiaShell::slotConfigureToolBars() 0126 { 0127 KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup()); 0128 saveMainWindowSettings(cg); 0129 KEditToolBar dlg(factory()); 0130 connect(&dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig())); 0131 dlg.exec(); 0132 } 0133 0134 void CervisiaShell::slotNewToolbarConfig() 0135 { 0136 KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup()); 0137 applyMainWindowSettings(cg); 0138 } 0139 0140 void CervisiaShell::closeEvent(QCloseEvent *event) 0141 { 0142 writeSettings(); 0143 KParts::MainWindow::closeEvent(event); 0144 } 0145 0146 void CervisiaShell::readProperties(const KConfigGroup &config) 0147 { 0148 m_lastOpenDir = config.readPathEntry("Current Directory", QString()); 0149 0150 // if the session is restoring, make sure we open the URL 0151 // since it's not handled by main() 0152 if (qApp->isSessionRestored()) 0153 openURL(); 0154 } 0155 0156 void CervisiaShell::saveProperties(KConfigGroup &config) 0157 { 0158 // Save current working directory (if part was created) 0159 if (m_part) { 0160 config.writePathEntry("Current Directory", m_part->url().path()); 0161 0162 // write to disk 0163 config.sync(); 0164 } 0165 } 0166 0167 void CervisiaShell::readSettings() 0168 { 0169 KConfigGroup cg(KSharedConfig::openConfig(), "Session"); 0170 0171 readProperties(cg); 0172 } 0173 0174 void CervisiaShell::writeSettings() 0175 { 0176 KConfigGroup cg(KSharedConfig::openConfig(), "Session"); 0177 saveProperties(cg); 0178 } 0179 0180 // Local Variables: 0181 // c-basic-offset: 4 0182 // End: