cervisiashell.cpp 3.88 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 45 46 47 48 49
    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()
{
50 51 52
    setHelpMenuEnabled(false);
    (void) new KHelpMenu(this, instance()->aboutData(), false, actionCollection());

53 54 55
    KAction* action = KStdAction::showToolbar( 0, 0, actionCollection() );
    connect( action, SIGNAL(toggled(bool)),
             this,   SLOT(slotToggleToolbar( bool )) );
56 57

    action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()),
58
                                            actionCollection() );
59
    action = KStdAction::keyBindings( this, SLOT(slotConfigureKeys()),
60
                                      actionCollection() );
61 62 63 64 65 66 67

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

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

    part->openSandbox(dirname);
}

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

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

void CervisiaShell::slotConfigureToolBars()
{
    KEditToolbar dlg( actionCollection() );
    if ( dlg.exec() )
93
        createGUI( part );
94 95 96 97 98 99 100 101 102 103
}

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

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

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
    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
135
    KConfig *config = part->config();
136 137 138 139 140 141 142 143 144 145 146 147 148

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

149 150 151
#include "cervisiashell.moc"


152 153 154
// Local Variables:
// c-basic-offset: 4
// End: