cervisiashell.cpp 6.29 KB
Newer Older
1
/*
Bernd Gehrmann's avatar
Bernd Gehrmann committed
2 3 4 5 6 7 8 9 10 11 12 13 14
 *  Copyright (C) 1999-2002 Bernd Gehrmann
 *                          bernd@mail.berlios.de
 *
 * 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.
 */


15 16
#include "cervisiashell.h"

17 18
#include <qlabel.h>
#include <qtooltip.h>
Gioele Barabucci's avatar
Gioele Barabucci committed
19
#include <kapplication.h>
20 21 22
#include <kconfig.h>
#include <kedittoolbar.h>
#include <kfiledialog.h>
23
#include <khelpmenu.h>
24 25
#include <kkeydialog.h>
#include <klocale.h>
26
#include <kmessagebox.h>
27
#include <kstdaction.h>
Werner Trobin's avatar
Werner Trobin committed
28
#include <kstatusbar.h>
Christian Loose's avatar
Christian Loose committed
29
#include <kurl.h>
30 31 32 33 34 35 36 37 38

#include "cervisiapart.h"


CervisiaShell::CervisiaShell( const char *name )
  : KParts::MainWindow( name )
{
    setXMLFile( "cervisiashellui.rc" );

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

    setupActions();
56

57 58 59 60 61 62 63 64 65 66
    // create the active filter indicator and add it to the statusbar
    filterLabel = new QLabel("UR", statusBar());
    filterLabel->setFixedSize(filterLabel->sizeHint());
    filterLabel->setText("");
    QToolTip::add(filterLabel, i18n("F - All files are hidden, the tree shows only directories\n"
                                    "N - All up-to-date files are hidden\n"
                                    "R - All removed files are hidden"));
    statusBar()->addWidget(filterLabel, 0, true);
    connect( part, SIGNAL( filterStatusChanged(QString) ),
             this, SLOT( slotChangeFilterStatus(QString) ) );
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    //
    // 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 );
83 84

    setAutoSaveSettings();
85 86 87 88
}

CervisiaShell::~CervisiaShell()
{
89
    delete part;
90 91 92 93
}

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

96
    KAction *action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
97
                                            actionCollection() );
98
    QString hint = i18n("Allows you to configure the toolbar");
Bernd Gehrmann's avatar
Bernd Gehrmann committed
99 100
    action->setToolTip( hint );
    action->setWhatsThis( hint );
101

102
    action = KStdAction::keyBindings( this, SLOT(slotConfigureKeys()),
103
                                      actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
104 105 106 107
    hint = i18n("Allows you to customize the keybindings");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

108
    action = KStdAction::quit( kapp, SLOT( quit() ), actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
109 110 111 112 113 114
    hint = i18n("Exits Cervisia");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

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

Bernd Gehrmann's avatar
Bernd Gehrmann committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    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 );
135 136 137 138 139 140 141 142 143
}

void CervisiaShell::slotConfigureKeys()
{
    KKeyDialog::configureKeys( actionCollection(), xmlFile() );
}

void CervisiaShell::slotConfigureToolBars()
{
144 145 146 147 148 149 150 151 152
    saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
    KEditToolbar dlg( factory() );
    connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
    dlg.exec();
}

void CervisiaShell::slotNewToolbarConfig()
{
    applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
153 154
}

155 156 157 158 159
void CervisiaShell::slotChangeFilterStatus(QString status)
{
    filterLabel->setText(status);
}

160 161
bool CervisiaShell::queryExit()
{
Laurent Montel's avatar
Laurent Montel committed
162 163
    KConfig *config = part->config();

164 165 166 167
    config->setGroup("Main window");
    config->writeEntry("Customized", true);
    config->writeEntry("Size", size());

168 169 170 171
    part->saveDialogProperties(config);

    config->setGroup("Session");
    saveProperties(config);
172 173 174 175 176

    config->sync();
    return true;
}

177
void CervisiaShell::restorePseudo(const QString &dirname)
178
{
Laurent Montel's avatar
Laurent Montel committed
179
    KConfig *config = part->config();
180 181 182 183 184

    config->setGroup("Main window");
    if (config->readBoolEntry("Customized"))
        resize(config->readSizeEntry("Size"));

185
    part->readDialogProperties(config);
186 187

    config->setGroup("Session");
188 189
    // Explicitly override the loaded directory if
    // a command line argument is given
190 191 192 193 194
    if (!dirname.isEmpty())
        config->writeEntry("Current Directory", dirname);
    readProperties(config);
}

195 196 197 198 199 200
void CervisiaShell::readProperties(KConfig *config)
{
    part->readProperties( config );

    QString currentDir = config->readEntry("Current Directory");
    if (!currentDir.isEmpty())
Christian Loose's avatar
Christian Loose committed
201
        part->openURL( KURL::fromPathOrURL(currentDir) );
202 203 204 205 206 207 208 209
}

void CervisiaShell::saveProperties(KConfig *config)
{
    part->saveProperties(config);
    config->writeEntry("Current Directory", part->sandBox());
}

210 211 212
#include "cervisiashell.moc"


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