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

Gioele Barabucci's avatar
Gioele Barabucci committed
24
#include <kapplication.h>
25
#include <kconfig.h>
André Wöbbeking's avatar
André Wöbbeking committed
26
#include <kedittoolbar.h>
27
#include <khelpmenu.h>
28
#include <kkeydialog.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" );

44 45 46
    KLibFactory* factory = KLibLoader::self()->factory("libcervisiapart");
    if( factory )
    {
Christian Loose's avatar
Christian Loose committed
47
        m_part = static_cast<KParts::ReadOnlyPart*>(factory->create(this,
48 49 50
                                      "KParts::ReadOnlyPart"));
        if( m_part ) {
	    m_part->setObjectName( "cervisiaview" );
Christian Loose's avatar
Christian Loose committed
51
            setCentralWidget(m_part->widget());
52
	}
53 54 55
    }
    else
    {
Christian Loose's avatar
Christian Loose committed
56 57
        KMessageBox::detailedError(this, i18n("The Cervisia library could not be loaded."), 
                                   KLibLoader::self()->lastErrorMessage());
58 59 60 61
        kapp->quit();
        return;
    }
    
62
    setupActions();
Christian Loose's avatar
 
Christian Loose committed
63
    
64 65 66
    //
    // Magic needed for status texts
    //
Laurent Montel's avatar
Laurent Montel committed
67
#ifdef __GNUC__
Laurent Montel's avatar
Laurent Montel committed
68
#warning "kde4: port it actionCollection()->setHighlightingEnabled(true);";
Laurent Montel's avatar
Laurent Montel committed
69
#endif
Laurent Montel's avatar
Laurent Montel committed
70
    //actionCollection()->setHighlightingEnabled(true);
71 72 73 74
    connect( actionCollection(), SIGNAL( actionStatusText(const QString &) ),
             statusBar(), SLOT( message(const QString &) ) );
    connect( actionCollection(), SIGNAL( clearStatusText() ),
             statusBar(), SLOT( clear() ) );
Laurent Montel's avatar
Laurent Montel committed
75
#ifdef __GNUC__
Laurent Montel's avatar
Laurent Montel committed
76
#warning "kde4: port it m_part->actionCollection()->setHighlightingEnabled(true);";
Laurent Montel's avatar
Laurent Montel committed
77
#endif
Laurent Montel's avatar
Laurent Montel committed
78
    //m_part->actionCollection()->setHighlightingEnabled(true);
Christian Loose's avatar
Christian Loose committed
79
    connect( m_part->actionCollection(), SIGNAL( actionStatusText(const QString &) ),
80
             statusBar(), SLOT( message(const QString &) ) );
Christian Loose's avatar
Christian Loose committed
81
    connect( m_part->actionCollection(), SIGNAL( clearStatusText() ),
82 83
             statusBar(), SLOT( clear() ) );

Christian Loose's avatar
Christian Loose committed
84
    createGUI( m_part );
85

86 87 88
    // enable auto-save of toolbar/menubar/statusbar and window size settings
    // and apply the previously saved settings
    setAutoSaveSettings("MainWindow", true);
89
    
Christian Loose's avatar
Christian Loose committed
90
    // if the session is restoring, we already read the settings
Laurent Montel's avatar
Laurent Montel committed
91
    if( !kapp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
92
        readSettings();
93 94 95 96
}

CervisiaShell::~CervisiaShell()
{
Christian Loose's avatar
Christian Loose committed
97
    delete m_part;
98 99 100 101
}

void CervisiaShell::setupActions()
{
102
    setStandardToolBarMenuEnabled( true );
103

Laurent Montel's avatar
Port++  
Laurent Montel committed
104
    QAction *action = KStandardAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
105
                                            actionCollection() );
106
    QString hint = i18n("Allows you to configure the toolbar");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
107 108
    action->setToolTip( hint );
    action->setWhatsThis( hint );
109

Aaron J. Seigo's avatar
Aaron J. Seigo committed
110
    action = KStandardAction::keyBindings( this, SLOT(slotConfigureKeys()),
111
                                      actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
112 113 114 115
    hint = i18n("Allows you to customize the keybindings");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

Aaron J. Seigo's avatar
Aaron J. Seigo committed
116
    action = KStandardAction::quit( kapp, SLOT( quit() ), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
117 118 119 120 121 122
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

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

Bernd Gehrmann's avatar
Bernd Gehrmann committed
124 125 126 127 128 129
    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");
130
    hint = i18n("Opens the bug report dialog");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
131 132 133 134 135 136 137 138 139 140 141 142
    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 );
143 144
}

145

146 147 148
void CervisiaShell::openURL()
{
    if( !m_lastOpenDir.isEmpty() )
André Wöbbeking's avatar
André Wöbbeking committed
149
        m_part->openUrl( KUrl( m_lastOpenDir ) );
150 151 152
}


Laurent Montel's avatar
Laurent Montel committed
153
void CervisiaShell::openURL(const KUrl& url)
154
{
Laurent Montel's avatar
Port++  
Laurent Montel committed
155
    m_part->openUrl(url);
156 157 158
}


159 160
void CervisiaShell::slotConfigureKeys()
{
Christian Loose's avatar
Christian Loose committed
161 162
    KKeyDialog dlg;
    dlg.insert(actionCollection());
Christian Loose's avatar
Christian Loose committed
163 164
    if( m_part )
        dlg.insert(m_part->actionCollection());
Christian Loose's avatar
Christian Loose committed
165 166
        
    dlg.configure();
167 168 169 170
}

void CervisiaShell::slotConfigureToolBars()
{
171 172 173 174 175 176 177 178 179
    saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
    KEditToolbar dlg( factory() );
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
    applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
180 181 182 183
}

bool CervisiaShell::queryExit()
{
184
    writeSettings();
185 186 187 188
    return true;
}


Christian Loose's avatar
Christian Loose committed
189
void CervisiaShell::readProperties(KConfig* config)
190
{   
191
    m_lastOpenDir = config->readPathEntry("Current Directory");
Christian Loose's avatar
Christian Loose committed
192 193 194
    
    // if the session is restoring, make sure we open the URL 
    // since it's not handled by main()
Laurent Montel's avatar
Laurent Montel committed
195
    if( kapp->isSessionRestored() )
Christian Loose's avatar
Christian Loose committed
196
        openURL();
197 198
}

199

Christian Loose's avatar
Christian Loose committed
200
void CervisiaShell::saveProperties(KConfig* config)
201
{
202
    // Save current working directory (if part was created)
Christian Loose's avatar
Christian Loose committed
203
    if( m_part )
204
    {
Christian Loose's avatar
Christian Loose committed
205
        config->writePathEntry("Current Directory", m_part->url().path());
206
    
207 208 209
        // write to disk
        config->sync();
    }
210 211
}

212

Christian Loose's avatar
Christian Loose committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
void CervisiaShell::readSettings()
{
    KConfig* config = KGlobal::config(); 
    config->setGroup("Session");
    
    readProperties(config);
}


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


231 232 233
#include "cervisiashell.moc"


234 235 236
// Local Variables:
// c-basic-offset: 4
// End: