/* * Copyright (C) 1999-2002 Bernd Gehrmann * bernd@mail.berlios.de * Copyright (c) 2002-2003 Christian Loose * * 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. */ #include "cervisiashell.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "cervisiapart.h" CervisiaShell::CervisiaShell( const char *name ) : KParts::MainWindow( name ) { setXMLFile( "cervisiashellui.rc" ); KLibFactory* factory = KLibLoader::self()->factory("libcervisiapart"); if( factory ) { part = static_cast(factory->create(this, "cervisiaview", "CervisiaPart")); if( part ) setCentralWidget(part->widget()); } else { KMessageBox::error(this, "Could not find our Part!"); kapp->quit(); return; } setupActions(); // 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) ) ); // // 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 ); // enable auto-save of toolbar/menubar/statusbar and window size settings // and apply the previously saved settings setAutoSaveSettings("MainWindow", true); } CervisiaShell::~CervisiaShell() { delete part; } void CervisiaShell::setupActions() { setStandardToolBarMenuEnabled( true ); KAction *action = KStdAction::configureToolbars( this, SLOT(slotConfigureToolBars()), actionCollection() ); QString hint = i18n("Allows you to configure the toolbar"); action->setToolTip( hint ); action->setWhatsThis( hint ); action = KStdAction::keyBindings( this, SLOT(slotConfigureKeys()), actionCollection() ); hint = i18n("Allows you to customize the keybindings"); action->setToolTip( hint ); action->setWhatsThis( hint ); action = KStdAction::quit( kapp, SLOT( quit() ), actionCollection() ); hint = i18n("Exits Cervisia"); action->setToolTip( hint ); action->setWhatsThis( hint ); setHelpMenuEnabled(false); (void) new KHelpMenu(this, instance()->aboutData(), false, actionCollection()); 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 ); } void CervisiaShell::openURL(const KURL& url) { part->openURL(url); } void CervisiaShell::slotConfigureKeys() { KKeyDialog::configureKeys( actionCollection(), xmlFile() ); } void CervisiaShell::slotConfigureToolBars() { saveMainWindowSettings( KGlobal::config(), autoSaveGroup() ); KEditToolbar dlg( factory() ); connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig())); dlg.exec(); } void CervisiaShell::slotNewToolbarConfig() { applyMainWindowSettings( KGlobal::config(), autoSaveGroup() ); } void CervisiaShell::slotChangeFilterStatus(QString status) { filterLabel->setText(status); } bool CervisiaShell::queryExit() { KConfig *config = part->config(); part->saveDialogProperties(config); config->setGroup("Session"); saveProperties(config); config->sync(); return true; } void CervisiaShell::restorePseudo(const QString &dirname) { KConfig *config = part->config(); part->readDialogProperties(config); config->setGroup("Session"); // Explicitly override the loaded directory if // a command line argument is given if (!dirname.isEmpty()) config->writeEntry("Current Directory", dirname); readProperties(config); } void CervisiaShell::readProperties(KConfig *config) { part->readProperties( config ); QString currentDir = config->readEntry("Current Directory"); if (!currentDir.isEmpty()) part->openURL( KURL::fromPathOrURL(currentDir) ); } void CervisiaShell::saveProperties(KConfig *config) { part->saveProperties(config); config->writeEntry("Current Directory", part->sandBox()); } #include "cervisiashell.moc" // Local Variables: // c-basic-offset: 4 // End: