cervisiashell.cpp 5.85 KB
Newer Older
1
/*
Bernd Gehrmann's avatar
Bernd Gehrmann committed
2 3
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
Christian Loose's avatar
Christian Loose committed
4
 *  Copyright (c) 2002-2004 Christian Loose <christian.loose@kdemail.net>
Bernd Gehrmann's avatar
Bernd Gehrmann committed
5
 *
6 7 8 9
 * 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.
Bernd Gehrmann's avatar
Bernd Gehrmann committed
10 11 12
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 14 15 16 17
 * 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
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Bernd Gehrmann's avatar
Bernd Gehrmann committed
19 20 21
 */


22 23
#include "cervisiashell.h"

André Wöbbeking's avatar
André Wöbbeking committed
24
#include <kactioncollection.h>
25
#include <kconfig.h>
Martin Koller's avatar
Martin Koller committed
26
#include <KSharedConfig>
André Wöbbeking's avatar
André Wöbbeking committed
27
#include <kedittoolbar.h>
28
#include <khelpmenu.h>
André Wöbbeking's avatar
André Wöbbeking committed
29 30
#include <kpluginfactory.h>
#include <kpluginloader.h>
31
#include <kmessagebox.h>
André Wöbbeking's avatar
André Wöbbeking committed
32
#include <kshortcutsdialog.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
33
#include <kstandardaction.h>
André Wöbbeking's avatar
André Wöbbeking committed
34
#include <kstatusbar.h>
Martin Koller's avatar
Martin Koller committed
35 36 37 38 39 40
#include <KLocalizedString>
#include <KAboutData>
#include <KConfigGroup>

#include <QApplication>
#include <QAction>
41 42 43


CervisiaShell::CervisiaShell( const char *name )
André Wöbbeking's avatar
André Wöbbeking committed
44
  : m_part(0)
45
{
André Wöbbeking's avatar
André Wöbbeking committed
46
    setObjectName( name );
47 48
    setXMLFile( "cervisiashellui.rc" );

49
    KPluginLoader loader("cervisiapart");
André Wöbbeking's avatar
André Wöbbeking committed
50
    if( KPluginFactory *factory = loader.factory() )
51
    {
Laurent Montel's avatar
Laurent Montel committed
52
        m_part = factory->create< KParts::ReadOnlyPart >(this);
André Wöbbeking's avatar
André Wöbbeking committed
53 54 55
        if( m_part )
        {
            m_part->setObjectName( "cervisiaview" );
Christian Loose's avatar
Christian Loose committed
56
            setCentralWidget(m_part->widget());
André Wöbbeking's avatar
André Wöbbeking committed
57
        }
58 59 60
    }
    else
    {
Stephan Kulow's avatar
Stephan Kulow committed
61
        KMessageBox::detailedError(this, i18n("The Cervisia library could not be loaded."),
André Wöbbeking's avatar
André Wöbbeking committed
62
                                   loader.errorString());
Laurent Montel's avatar
Laurent Montel committed
63
        qApp->quit();
64 65
        return;
    }
Stephan Kulow's avatar
Stephan Kulow committed
66

67
    setupActions();
Stephan Kulow's avatar
Stephan Kulow committed
68

69 70 71
    //
    // Magic needed for status texts
    //
Christian Loose's avatar
Christian Loose committed
72
    createGUI( m_part );
73

74 75 76
    // enable auto-save of toolbar/menubar/statusbar and window size settings
    // and apply the previously saved settings
    setAutoSaveSettings("MainWindow", true);
Stephan Kulow's avatar
Stephan Kulow committed
77

Christian Loose's avatar
Christian Loose committed
78
    // if the session is restoring, we already read the settings
Martin Koller's avatar
Martin Koller committed
79
    if( !qApp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
80
        readSettings();
81 82 83 84
}

CervisiaShell::~CervisiaShell()
{
Christian Loose's avatar
Christian Loose committed
85
    delete m_part;
86 87 88 89
}

void CervisiaShell::setupActions()
{
90
    setStandardToolBarMenuEnabled( true );
91

Laurent Montel's avatar
Port++  
Laurent Montel committed
92
    QAction *action = KStandardAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
93
                                            actionCollection() );
94
    QString hint = i18n("Allows you to configure the toolbar");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
95 96
    action->setToolTip( hint );
    action->setWhatsThis( hint );
97

Aaron J. Seigo's avatar
Aaron J. Seigo committed
98
    action = KStandardAction::keyBindings( this, SLOT(slotConfigureKeys()),
99
                                      actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
100 101 102 103
    hint = i18n("Allows you to customize the keybindings");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

104
    action = KStandardAction::quit( this, SLOT(close()), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
105 106 107 108 109
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    setHelpMenuEnabled(false);
Martin Koller's avatar
Martin Koller committed
110
    (void) new KHelpMenu(this, componentData(), false);
111

Bernd Gehrmann's avatar
Bernd Gehrmann committed
112 113 114 115 116 117
    action = actionCollection()->action("help_contents");
    hint = i18n("Invokes the KDE help system with the Cervisia documentation");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = actionCollection()->action("help_report_bug");
118
    hint = i18n("Opens the bug report dialog");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
119 120 121 122 123 124 125 126 127 128 129 130
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = actionCollection()->action("help_about_app");
    hint = i18n("Displays the version number and copyright information");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = actionCollection()->action("help_about_kde");
    hint = i18n("Displays the information about KDE and its version number");
    action->setToolTip( hint );
    action->setWhatsThis( hint );
131 132
}

133

134 135 136
void CervisiaShell::openURL()
{
    if( !m_lastOpenDir.isEmpty() )
Martin Koller's avatar
Martin Koller committed
137
        m_part->openUrl( QUrl::fromLocalFile( m_lastOpenDir ) );
138 139 140
}


Martin Koller's avatar
Martin Koller committed
141
void CervisiaShell::openURL(const QUrl& url)
142
{
Laurent Montel's avatar
Port++  
Laurent Montel committed
143
    m_part->openUrl(url);
144 145 146
}


147 148
void CervisiaShell::slotConfigureKeys()
{
David Faure's avatar
compile  
David Faure committed
149
    KShortcutsDialog dlg;
Laurent Montel's avatar
Laurent Montel committed
150
    dlg.addCollection(actionCollection());
Christian Loose's avatar
Christian Loose committed
151
    if( m_part )
Laurent Montel's avatar
Laurent Montel committed
152
        dlg.addCollection(m_part->actionCollection());
Stephan Kulow's avatar
Stephan Kulow committed
153

Christian Loose's avatar
Christian Loose committed
154
    dlg.configure();
155 156 157 158
}

void CervisiaShell::slotConfigureToolBars()
{
Martin Koller's avatar
Martin Koller committed
159 160
    KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
    saveMainWindowSettings(cg);
Aaron J. Seigo's avatar
Aaron J. Seigo committed
161
    KEditToolBar dlg( factory() );
162 163 164 165 166 167
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
Martin Koller's avatar
Martin Koller committed
168 169
    KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
    applyMainWindowSettings(cg);
170 171
}

172
void CervisiaShell::closeEvent(QCloseEvent *event)
173
{
174
    writeSettings();
175
    KParts::MainWindow::closeEvent(event);
176 177 178
}


Stephan Kulow's avatar
Stephan Kulow committed
179 180
void CervisiaShell::readProperties(const KConfigGroup& config)
{
181
    m_lastOpenDir = config.readPathEntry("Current Directory", QString());
Stephan Kulow's avatar
Stephan Kulow committed
182 183

    // if the session is restoring, make sure we open the URL
Christian Loose's avatar
Christian Loose committed
184
    // since it's not handled by main()
Martin Koller's avatar
Martin Koller committed
185
    if( qApp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
186
        openURL();
187 188
}

189

Stephan Kulow's avatar
Stephan Kulow committed
190
void CervisiaShell::saveProperties(KConfigGroup & config)
191
{
192
    // Save current working directory (if part was created)
Christian Loose's avatar
Christian Loose committed
193
    if( m_part )
194
    {
Stephan Kulow's avatar
Stephan Kulow committed
195 196
        config.writePathEntry("Current Directory", m_part->url().path());

197
        // write to disk
Stephan Kulow's avatar
Stephan Kulow committed
198
        config.sync();
199
    }
200 201
}

202

Christian Loose's avatar
Christian Loose committed
203 204
void CervisiaShell::readSettings()
{
Martin Koller's avatar
Martin Koller committed
205
    KConfigGroup cg(KSharedConfig::openConfig(), "Session");
Stephan Kulow's avatar
Stephan Kulow committed
206 207

    readProperties(cg);
Christian Loose's avatar
Christian Loose committed
208 209 210 211 212
}


void CervisiaShell::writeSettings()
{
Martin Koller's avatar
Martin Koller committed
213
    KConfigGroup cg(KSharedConfig::openConfig(), "Session");
Stephan Kulow's avatar
Stephan Kulow committed
214
    saveProperties(cg);
Christian Loose's avatar
Christian Loose committed
215 216 217
}


218 219


220 221 222
// Local Variables:
// c-basic-offset: 4
// End: