File: cervisiashell.cpp

package info (click to toggle)
cervisia 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 7,548 kB
  • sloc: cpp: 14,364; xml: 393; makefile: 3; sh: 3
file content (202 lines) | stat: -rw-r--r-- 5,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
 *  Copyright (c) 2002-2004 Christian Loose <christian.loose@kdemail.net>
 *
 * 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.
 *
 * 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.  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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


#include "cervisiashell.h"

#include <kactioncollection.h>
#include <kconfig.h>
#include <KSharedConfig>
#include <kedittoolbar.h>
#include <khelpmenu.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kmessagebox.h>
#include <kshortcutsdialog.h>
#include <kstandardaction.h>
#include <KLocalizedString>
#include <KAboutData>
#include <KConfigGroup>

#include <QApplication>
#include <QAction>


CervisiaShell::CervisiaShell( const char *name )
  : m_part(0)
{
    setObjectName( name );
    setXMLFile( "cervisiashellui.rc" );

    KPluginLoader loader("cervisiapart5");
    if( KPluginFactory *factory = loader.factory() )
    {
        m_part = factory->create< KParts::ReadOnlyPart >(this);
        if( m_part )
        {
            m_part->setObjectName( "cervisiaview" );
            setCentralWidget(m_part->widget());
        }
    }
    else
    {
        KMessageBox::detailedError(this, i18n("The Cervisia library could not be loaded."),
                                   loader.errorString() +
                                   QLatin1String("\n") + loader.pluginName() +
                                   QLatin1String("\n") + loader.fileName());
        qApp->quit();
        return;
    }

    setupActions();

    //
    // Magic needed for status texts
    //
    createGUI( m_part );

    // enable auto-save of toolbar/menubar/statusbar and window size settings
    // and apply the previously saved settings
    setAutoSaveSettings("MainWindow", true);

    // if the session is restoring, we already read the settings
    if( !qApp->isSessionRestored() )
        readSettings();
}

CervisiaShell::~CervisiaShell()
{
    delete m_part;
}

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

    QAction *action = KStandardAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
                                            actionCollection() );
    QString hint = i18n("Allows you to configure the toolbar");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = KStandardAction::keyBindings( this, SLOT(slotConfigureKeys()), actionCollection() );
    hint = i18n("Allows you to customize the keybindings");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    action = KStandardAction::quit( this, SLOT(close()), actionCollection() );
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

    setHelpMenuEnabled(true);
}


void CervisiaShell::openURL()
{
    if ( m_part && !m_lastOpenDir.isEmpty() )
        m_part->openUrl( QUrl::fromLocalFile( m_lastOpenDir ) );
}


void CervisiaShell::openURL(const QUrl& url)
{
    if ( m_part )
        m_part->openUrl(url);
}


void CervisiaShell::slotConfigureKeys()
{
    KShortcutsDialog dlg;
    dlg.addCollection(actionCollection());
    if ( m_part )
        dlg.addCollection(m_part->actionCollection());

    dlg.configure();
}

void CervisiaShell::slotConfigureToolBars()
{
    KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
    saveMainWindowSettings(cg);
    KEditToolBar dlg( factory() );
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
    KConfigGroup cg(KSharedConfig::openConfig(), autoSaveGroup());
    applyMainWindowSettings(cg);
}

void CervisiaShell::closeEvent(QCloseEvent *event)
{
    writeSettings();
    KParts::MainWindow::closeEvent(event);
}


void CervisiaShell::readProperties(const KConfigGroup& config)
{
    m_lastOpenDir = config.readPathEntry("Current Directory", QString());

    // if the session is restoring, make sure we open the URL
    // since it's not handled by main()
    if( qApp->isSessionRestored() )
        openURL();
}


void CervisiaShell::saveProperties(KConfigGroup & config)
{
    // Save current working directory (if part was created)
    if ( m_part )
    {
        config.writePathEntry("Current Directory", m_part->url().path());

        // write to disk
        config.sync();
    }
}


void CervisiaShell::readSettings()
{
    KConfigGroup cg(KSharedConfig::openConfig(), "Session");

    readProperties(cg);
}


void CervisiaShell::writeSettings()
{
    KConfigGroup cg(KSharedConfig::openConfig(), "Session");
    saveProperties(cg);
}




// Local Variables:
// c-basic-offset: 4
// End: