cervisiashell.cpp 5.66 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"

24
#include <kconfig.h>
André Wöbbeking's avatar
André Wöbbeking committed
25
#include <kedittoolbar.h>
26
#include <khelpmenu.h>
Laurent Montel's avatar
Laurent Montel committed
27
#include <kapplication.h>
David Faure's avatar
compile  
David Faure committed
28
#include <kshortcutsdialog.h>
Christian Loose's avatar
 
Christian Loose committed
29
#include <klibloader.h>
30
#include <klocale.h>
31
#include <kmessagebox.h>
Werner Trobin's avatar
Werner Trobin committed
32
#include <kstatusbar.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
33
#include <kstandardaction.h>
Christian Loose's avatar
Christian Loose committed
34
#include <kurl.h>
35
#include <kactioncollection.h>
36 37 38


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

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

61
    setupActions();
Stephan Kulow's avatar
Stephan Kulow committed
62

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

68 69 70
    // 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
71

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

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

void CervisiaShell::setupActions()
{
84
    setStandardToolBarMenuEnabled( true );
85

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

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

Aaron J. Seigo's avatar
Aaron J. Seigo committed
98
    action = KStandardAction::quit( kapp, SLOT( quit() ), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
99 100 101 102 103
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

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

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

127

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


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


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

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

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

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

bool CervisiaShell::queryExit()
{
166
    writeSettings();
167 168 169 170
    return true;
}


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

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

181

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

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

194

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

    readProperties(cg);
Christian Loose's avatar
Christian Loose committed
200 201 202 203 204
}


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


210 211 212
#include "cervisiashell.moc"


213 214 215
// Local Variables:
// c-basic-offset: 4
// End: