cervisiashell.cpp 5.71 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 25
#include <kactioncollection.h>
#include <kapplication.h>
26
#include <kconfig.h>
André Wöbbeking's avatar
André Wöbbeking committed
27
#include <kedittoolbar.h>
28
#include <khelpmenu.h>
29
#include <klocale.h>
André Wöbbeking's avatar
André Wöbbeking committed
30 31
#include <kpluginfactory.h>
#include <kpluginloader.h>
32
#include <kmessagebox.h>
André Wöbbeking's avatar
André Wöbbeking committed
33
#include <kshortcutsdialog.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
34
#include <kstandardaction.h>
André Wöbbeking's avatar
André Wöbbeking committed
35
#include <kstatusbar.h>
Christian Loose's avatar
Christian Loose committed
36
#include <kurl.h>
37 38 39


CervisiaShell::CervisiaShell( const char *name )
André Wöbbeking's avatar
André Wöbbeking committed
40
  : m_part(0)
41
{
André Wöbbeking's avatar
André Wöbbeking committed
42
    setObjectName( name );
43 44
    setXMLFile( "cervisiashellui.rc" );

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

63
    setupActions();
Stephan Kulow's avatar
Stephan Kulow committed
64

65 66 67
    //
    // Magic needed for status texts
    //
Christian Loose's avatar
Christian Loose committed
68
    createGUI( m_part );
69

70 71 72
    // 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
73

Christian Loose's avatar
Christian Loose committed
74
    // if the session is restoring, we already read the settings
Laurent Montel's avatar
Laurent Montel committed
75
    if( !kapp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
76
        readSettings();
77 78 79 80
}

CervisiaShell::~CervisiaShell()
{
Christian Loose's avatar
Christian Loose committed
81
    delete m_part;
82 83 84 85
}

void CervisiaShell::setupActions()
{
86
    setStandardToolBarMenuEnabled( true );
87

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

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

100
    action = KStandardAction::quit( this, SLOT( close() ), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
101 102 103 104 105
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    setHelpMenuEnabled(false);
Matthias Kretz's avatar
Matthias Kretz committed
106
    (void) new KHelpMenu(this, componentData().aboutData(), false, actionCollection());
107

Bernd Gehrmann's avatar
Bernd Gehrmann committed
108 109 110 111 112 113
    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");
114
    hint = i18n("Opens the bug report dialog");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
115 116 117 118 119 120 121 122 123 124 125 126
    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 );
127 128
}

129

130 131 132
void CervisiaShell::openURL()
{
    if( !m_lastOpenDir.isEmpty() )
André Wöbbeking's avatar
André Wöbbeking committed
133
        m_part->openUrl( KUrl( m_lastOpenDir ) );
134 135 136
}


Laurent Montel's avatar
Laurent Montel committed
137
void CervisiaShell::openURL(const KUrl& url)
138
{
Laurent Montel's avatar
Port++  
Laurent Montel committed
139
    m_part->openUrl(url);
140 141 142
}


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

Christian Loose's avatar
Christian Loose committed
150
    dlg.configure();
151 152 153 154
}

void CervisiaShell::slotConfigureToolBars()
{
Stephan Kulow's avatar
Stephan Kulow committed
155
    saveMainWindowSettings( KGlobal::config()->group( autoSaveGroup() ) );
Aaron J. Seigo's avatar
Aaron J. Seigo committed
156
    KEditToolBar dlg( factory() );
157 158 159 160 161 162
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
Stephan Kulow's avatar
Stephan Kulow committed
163
    applyMainWindowSettings( KGlobal::config()->group( autoSaveGroup() ) );
164 165 166 167
}

bool CervisiaShell::queryExit()
{
168
    writeSettings();
169 170 171 172
    return true;
}


Stephan Kulow's avatar
Stephan Kulow committed
173 174
void CervisiaShell::readProperties(const KConfigGroup& config)
{
175
    m_lastOpenDir = config.readPathEntry("Current Directory", QString());
Stephan Kulow's avatar
Stephan Kulow committed
176 177

    // if the session is restoring, make sure we open the URL
Christian Loose's avatar
Christian Loose committed
178
    // since it's not handled by main()
Laurent Montel's avatar
Laurent Montel committed
179
    if( kapp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
180
        openURL();
181 182
}

183

Stephan Kulow's avatar
Stephan Kulow committed
184
void CervisiaShell::saveProperties(KConfigGroup & config)
185
{
186
    // Save current working directory (if part was created)
Christian Loose's avatar
Christian Loose committed
187
    if( m_part )
188
    {
Stephan Kulow's avatar
Stephan Kulow committed
189 190
        config.writePathEntry("Current Directory", m_part->url().path());

191
        // write to disk
Stephan Kulow's avatar
Stephan Kulow committed
192
        config.sync();
193
    }
194 195
}

196

Christian Loose's avatar
Christian Loose committed
197 198
void CervisiaShell::readSettings()
{
Stephan Kulow's avatar
Stephan Kulow committed
199 200 201
    KConfigGroup cg( KGlobal::config(), "Session");

    readProperties(cg);
Christian Loose's avatar
Christian Loose committed
202 203 204 205 206
}


void CervisiaShell::writeSettings()
{
Stephan Kulow's avatar
Stephan Kulow committed
207 208
    KConfigGroup cg( KGlobal::config(), "Session");
    saveProperties(cg);
Christian Loose's avatar
Christian Loose committed
209 210 211
}


212 213 214
#include "cervisiashell.moc"


215 216 217
// Local Variables:
// c-basic-offset: 4
// End: