cervisiashell.cpp 5.2 KB
Newer Older
1 2
#include "cervisiashell.h"

Gioele Barabucci's avatar
Gioele Barabucci committed
3
#include <kapplication.h>
4 5 6
#include <kconfig.h>
#include <kedittoolbar.h>
#include <kfiledialog.h>
7
#include <khelpmenu.h>
8 9 10
#include <kkeydialog.h>
#include <klocale.h>
#include <kstdaction.h>
Werner Trobin's avatar
Werner Trobin committed
11
#include <kstatusbar.h>
12 13 14 15 16 17 18 19 20

#include "cervisiapart.h"


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

21
    part = new CervisiaPart( this, "cervisiaview", this, "cervisiapart" );
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    setCentralWidget( part->widget() );

    setupActions();

    //
    // 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 );
}

CervisiaShell::~CervisiaShell()
{
45
    delete part;
46 47 48 49
}

void CervisiaShell::setupActions()
{
Bernd Gehrmann's avatar
Bernd Gehrmann committed
50 51 52 53
    KAction *action = KStdAction::showToolbar( 0, 0, actionCollection() );
    QString hint = i18n("Shows or hides the toolbar");
    action->setToolTip( hint );
    action->setWhatsThis( hint );
54 55
    connect( action, SIGNAL(toggled(bool)),
             this,   SLOT(slotToggleToolbar( bool )) );
56 57

    action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
58
                                            actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
59 60 61 62
    hint = i18n("Allows you to configure the toolbar");
    action->setToolTip( hint );
    action->setWhatsThis( hint );
    
63
    action = KStdAction::keyBindings( this, SLOT(slotConfigureKeys()),
64
                                      actionCollection() );
Bernd Gehrmann's avatar
Bernd Gehrmann committed
65 66 67 68 69 70 71 72 73 74 75
    hint = i18n("Allows you to customize the keybindings");
    action->setToolTip( hint );
    action->setWhatsThis( hint );

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

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

Bernd Gehrmann's avatar
Bernd Gehrmann committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    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 );
96 97 98 99 100
}

void CervisiaShell::slotOpenSandbox()
{
    QString dirname = KFileDialog::getExistingDirectory(QDir::homeDirPath(), this,
Laurent Montel's avatar
Laurent Montel committed
101
                                                        i18n("Open Sandbox"));
102 103 104 105 106 107 108 109 110 111
    if (dirname.isEmpty())
        return;

    part->openSandbox(dirname);
}

void CervisiaShell::slotToggleToolbar( bool visible )
{
    KToolBar *tb = toolBar( "mainToolBar" );
    if ( visible )
112
        tb->show();
113
    else
114
        tb->hide();
115 116 117 118 119 120 121 122 123 124 125
}

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

void CervisiaShell::slotConfigureToolBars()
{
    KEditToolbar dlg( actionCollection() );
    if ( dlg.exec() )
126
        createGUI( part );
127 128 129 130 131 132 133 134 135 136
}

void CervisiaShell::slotExit()
{
    (void) queryExit();
    kapp->quit();
}

bool CervisiaShell::queryExit()
{
Laurent Montel's avatar
Laurent Montel committed
137 138
    KConfig *config = part->config();

139 140 141 142
    config->setGroup("Main window");
    config->writeEntry("Customized", true);
    config->writeEntry("Size", size());

143 144 145 146
    part->saveDialogProperties(config);

    config->setGroup("Session");
    saveProperties(config);
147 148 149 150 151

    config->sync();
    return true;
}

152
void CervisiaShell::restorePseudo(const QString &dirname)
153
{
Laurent Montel's avatar
Laurent Montel committed
154
    KConfig *config = part->config();
155 156 157 158 159

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

160
    part->readDialogProperties(config);
161 162

    config->setGroup("Session");
163 164
    // Explicitly override the loaded directory if
    // a command line argument is given
165 166 167 168 169
    if (!dirname.isEmpty())
        config->writeEntry("Current Directory", dirname);
    readProperties(config);
}

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
void CervisiaShell::readProperties(KConfig *config)
{
    part->readProperties( config );

    QString currentDir = config->readEntry("Current Directory");
    if (!currentDir.isEmpty())
        part->openSandbox(currentDir);
}

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

185 186 187
#include "cervisiashell.moc"


188 189 190
// Local Variables:
// c-basic-offset: 4
// End: