cervisiashell.cpp 5.97 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 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>
André Wöbbeking's avatar
André Wöbbeking committed
20
#include <kedittoolbar.h>
21
#include <khelpmenu.h>
22
#include <kkeydialog.h>
Christian Loose's avatar
 
Christian Loose committed
23
#include <klibloader.h>
24
#include <klocale.h>
25
#include <kmessagebox.h>
Werner Trobin's avatar
Werner Trobin committed
26
#include <kstatusbar.h>
André Wöbbeking's avatar
André Wöbbeking committed
27
#include <kstdaction.h>
Christian Loose's avatar
Christian Loose committed
28
#include <kurl.h>
29 30 31 32


CervisiaShell::CervisiaShell( const char *name )
  : KParts::MainWindow( name )
Christian Loose's avatar
Christian Loose committed
33
  , m_part(0)
34 35 36
{
    setXMLFile( "cervisiashellui.rc" );

37 38 39
    KLibFactory* factory = KLibLoader::self()->factory("libcervisiapart");
    if( factory )
    {
Christian Loose's avatar
Christian Loose committed
40
        m_part = static_cast<KParts::ReadOnlyPart*>(factory->create(this,
Christian Loose's avatar
 
Christian Loose committed
41
                                      "cervisiaview", "KParts::ReadOnlyPart"));
Christian Loose's avatar
Christian Loose committed
42 43
        if( m_part )
            setCentralWidget(m_part->widget());
44 45 46
    }
    else
    {
Christian Loose's avatar
Christian Loose committed
47 48
        KMessageBox::detailedError(this, i18n("The Cervisia library could not be loaded."), 
                                   KLibLoader::self()->lastErrorMessage());
49 50 51 52
        kapp->quit();
        return;
    }
    
53
    setupActions();
Christian Loose's avatar
 
Christian Loose committed
54
    
55 56 57 58 59 60 61 62
    //
    // 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() ) );
Christian Loose's avatar
Christian Loose committed
63 64
    m_part->actionCollection()->setHighlightingEnabled(true);
    connect( m_part->actionCollection(), SIGNAL( actionStatusText(const QString &) ),
65
             statusBar(), SLOT( message(const QString &) ) );
Christian Loose's avatar
Christian Loose committed
66
    connect( m_part->actionCollection(), SIGNAL( clearStatusText() ),
67 68
             statusBar(), SLOT( clear() ) );

Christian Loose's avatar
Christian Loose committed
69
    createGUI( m_part );
70

71 72 73
    // enable auto-save of toolbar/menubar/statusbar and window size settings
    // and apply the previously saved settings
    setAutoSaveSettings("MainWindow", true);
74
    
Christian Loose's avatar
Christian Loose committed
75 76 77
    // if the session is restoring, we already read the settings
    if( !kapp->isRestored() )
        readSettings();
78 79 80 81
}

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

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

89
    KAction *action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
90
                                            actionCollection() );
91
    QString hint = i18n("Allows you to configure the toolbar");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
92 93
    action->setToolTip( hint );
    action->setWhatsThis( hint );
94

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

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

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

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

130

131 132 133
void CervisiaShell::openURL()
{
    if( !m_lastOpenDir.isEmpty() )
Christian Loose's avatar
Christian Loose committed
134
        m_part->openURL(KURL::fromPathOrURL(m_lastOpenDir));
135 136 137
}


138 139
void CervisiaShell::openURL(const KURL& url)
{
Christian Loose's avatar
Christian Loose committed
140
    m_part->openURL(url);
141 142 143
}


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

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

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

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


Christian Loose's avatar
Christian Loose committed
174
void CervisiaShell::readProperties(KConfig* config)
175
{   
176
    m_lastOpenDir = config->readPathEntry("Current Directory");
Christian Loose's avatar
Christian Loose committed
177 178 179 180 181
    
    // if the session is restoring, make sure we open the URL 
    // since it's not handled by main()
    if( kapp->isRestored() )
        openURL();
182 183
}

184

Christian Loose's avatar
Christian Loose committed
185
void CervisiaShell::saveProperties(KConfig* config)
186
{
187
    // Save current working directory (if part was created)
Christian Loose's avatar
Christian Loose committed
188
    if( m_part )
189
    {
Christian Loose's avatar
Christian Loose committed
190
        config->writePathEntry("Current Directory", m_part->url().path());
191
    
192 193 194
        // write to disk
        config->sync();
    }
195 196
}

197

Christian Loose's avatar
Christian Loose committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
void CervisiaShell::readSettings()
{
    KConfig* config = KGlobal::config(); 
    config->setGroup("Session");
    
    readProperties(config);
}


void CervisiaShell::writeSettings()
{
    KConfig* config = KGlobal::config();  
    config->setGroup("Session");
    
    saveProperties(config);
}


216 217 218
#include "cervisiashell.moc"


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