cervisiashell.cpp 3.74 KB
Newer Older
1 2 3 4 5 6 7
#include <kapp.h>
#include <kconfig.h>
#include <kedittoolbar.h>
#include <kfiledialog.h>
#include <kkeydialog.h>
#include <klocale.h>
#include <kstdaction.h>
Werner Trobin's avatar
Werner Trobin committed
8
#include <kstatusbar.h>
9 10 11 12 13 14 15 16 17 18 19

#include "cervisiapart.h"

#include "cervisiashell.h"
#include "cervisiashell.moc"

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

20
    part = new CervisiaPart( this, "cervisiaview", this, "cervisiapart" );
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
    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()
{

}

void CervisiaShell::setupActions()
{
49 50 51
    KAction* action = KStdAction::showToolbar( 0, 0, actionCollection() );
    connect( action, SIGNAL(toggled(bool)),
             this,   SLOT(slotToggleToolbar( bool )) );
52 53

    action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
54
                                            actionCollection() );
55
    action = KStdAction::keyBindings( this, SLOT(slotConfigureKeys()),
56
                                      actionCollection() );
57 58 59 60 61 62 63

    (void) KStdAction::quit( this, SLOT( slotExit() ), actionCollection() );
}

void CervisiaShell::slotOpenSandbox()
{
    QString dirname = KFileDialog::getExistingDirectory(QDir::homeDirPath(), this,
Laurent Montel's avatar
Laurent Montel committed
64
                                                        i18n("Open Sandbox"));
65 66 67 68 69 70 71 72 73 74
    if (dirname.isEmpty())
        return;

    part->openSandbox(dirname);
}

void CervisiaShell::slotToggleToolbar( bool visible )
{
    KToolBar *tb = toolBar( "mainToolBar" );
    if ( visible )
75
        tb->show();
76
    else
77
        tb->hide();
78 79 80 81 82 83 84 85 86 87 88
}

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

void CervisiaShell::slotConfigureToolBars()
{
    KEditToolbar dlg( actionCollection() );
    if ( dlg.exec() )
89
        createGUI( part );
90 91 92 93 94 95 96 97 98 99
}

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

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

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
    config->setGroup("Main window");
    config->writeEntry("Customized", true);
    config->writeEntry("Size", size());

    part->saveDialogProperties( config );
    config->setGroup( "Session" );
    part->saveProperties( config );

    config->sync();
    return true;
}

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

void CervisiaShell::restorePseudo( const QString &dirname )
{
Laurent Montel's avatar
Laurent Montel committed
131
    KConfig *config = part->config();
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

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

    part->readDialogProperties( config );

    config->setGroup("Session");
    if (!dirname.isEmpty())
        config->writeEntry("Current Directory", dirname);
    readProperties(config);
}

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