cervisiashell.cpp 5.55 KB
Newer Older
1
/*
Bernd Gehrmann's avatar
Bernd Gehrmann committed
2 3
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
4
 *  Copyright (c) 2002-2003 Christian Loose <christian.loose@hamburg.de>
Bernd Gehrmann's avatar
Bernd Gehrmann committed
5 6 7 8 9 10 11 12 13 14 15
 *
 * This program may be distributed under the terms of the Q Public
 * License as defined by Trolltech AS of Norway and appearing in the
 * file LICENSE.QPL included in the packaging of this file.
 *
 * 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.
 */


16 17
#include "cervisiashell.h"

Gioele Barabucci's avatar
Gioele Barabucci committed
18
#include <kapplication.h>
19
#include <kconfig.h>
Helge Deller's avatar
Helge Deller committed
20
#include <kdeversion.h>
André Wöbbeking's avatar
André Wöbbeking committed
21
#include <kedittoolbar.h>
22
#include <khelpmenu.h>
23
#include <kkeydialog.h>
Christian Loose's avatar
 
Christian Loose committed
24
#include <klibloader.h>
25
#include <klocale.h>
26
#include <kmessagebox.h>
Werner Trobin's avatar
Werner Trobin committed
27
#include <kstatusbar.h>
André Wöbbeking's avatar
André Wöbbeking committed
28
#include <kstdaction.h>
Christian Loose's avatar
Christian Loose committed
29
#include <kurl.h>
30 31 32 33


CervisiaShell::CervisiaShell( const char *name )
  : KParts::MainWindow( name )
34
  , part(0)
35 36 37
{
    setXMLFile( "cervisiashellui.rc" );

38 39 40
    KLibFactory* factory = KLibLoader::self()->factory("libcervisiapart");
    if( factory )
    {
Christian Loose's avatar
 
Christian Loose committed
41 42
        part = static_cast<KParts::ReadOnlyPart*>(factory->create(this,
                                      "cervisiaview", "KParts::ReadOnlyPart"));
43 44 45 46 47 48 49 50 51 52
        if( part )
            setCentralWidget(part->widget());
    }
    else
    {
        KMessageBox::error(this, "Could not find our Part!");
        kapp->quit();
        return;
    }
    
53 54

    setupActions();
Christian Loose's avatar
 
Christian Loose committed
55
    
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    //
    // Magic needed for status texts
    //
    actionCollection()->setHighlightingEnabled(true);
    connect( actionCollection(), SIGNAL( actionStatusText(const QString &) ),
             statusBar(), SLOT( message(const QString &) ) );
    connect( actionCollection(), SIGNAL( clearStatusText() ),
             statusBar(), SLOT( clear() ) );
    part->actionCollection()->setHighlightingEnabled(true);
    connect( part->actionCollection(), SIGNAL( actionStatusText(const QString &) ),
             statusBar(), SLOT( message(const QString &) ) );
    connect( part->actionCollection(), SIGNAL( clearStatusText() ),
             statusBar(), SLOT( clear() ) );

    createGUI( part );
71

72 73 74
    // enable auto-save of toolbar/menubar/statusbar and window size settings
    // and apply the previously saved settings
    setAutoSaveSettings("MainWindow", true);
75 76
    
    readSettings();
77 78 79 80
}

CervisiaShell::~CervisiaShell()
{
81
    delete part;
82 83 84 85
}

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

88
    KAction *action = KStdAction::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

94
    action = KStdAction::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 = KStdAction::quit( kapp, SLOT( quit() ), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
101 102 103 104 105 106
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    setHelpMenuEnabled(false);
    (void) new KHelpMenu(this, instance()->aboutData(), false, actionCollection());
107

Bernd Gehrmann's avatar
Bernd Gehrmann committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    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");
    hint = i18n("Opens the Bug report dialog");
    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 133 134 135 136
void CervisiaShell::openURL()
{
    if( !m_lastOpenDir.isEmpty() )
        part->openURL(KURL::fromPathOrURL(m_lastOpenDir));
}


137 138 139 140 141 142
void CervisiaShell::openURL(const KURL& url)
{
    part->openURL(url);
}


143 144
void CervisiaShell::slotConfigureKeys()
{
Christian Loose's avatar
Christian Loose committed
145 146 147 148 149 150
    KKeyDialog dlg;
    dlg.insert(actionCollection());
    if( part )
        dlg.insert(part->actionCollection());
        
    dlg.configure();
151 152 153 154
}

void CervisiaShell::slotConfigureToolBars()
{
155 156 157 158 159 160 161 162 163
    saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
    KEditToolbar dlg( factory() );
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
    applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
164 165 166 167
}

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


173 174
void CervisiaShell::readSettings()
{   
Christian Loose's avatar
Christian Loose committed
175
    KConfig* config = KGlobal::config();
176
    
177
    config->setGroup("Session");
178
    m_lastOpenDir = config->readPathEntry("Current Directory");
179 180
}

181 182

void CervisiaShell::writeSettings()
183
{
Christian Loose's avatar
Christian Loose committed
184
    KConfig* config = KGlobal::config();
185 186
    
    config->setGroup("Session");
187 188 189 190

    // Save current working directory (if part was created)
    if( part )
    {
Helge Deller's avatar
Helge Deller committed
191 192 193
#if KDE_IS_VERSION(3,1,3)
        config->writePathEntry("Current Directory", part->url().path());
#else
194
        config->writeEntry("Current Directory", part->url().path());
Helge Deller's avatar
Helge Deller committed
195
#endif
196
    
197 198 199
        // write to disk
        config->sync();
    }
200 201
}

202

203 204 205
#include "cervisiashell.moc"


206 207 208
// Local Variables:
// c-basic-offset: 4
// End: