joachim99@69: /*************************************************************************** joachim99@77: * Copyright (C) 2003-2007 Joachim Eibl * joachim99@69: * * joachim99@69: * This program is free software; you can redistribute it and/or modify * joachim99@69: * it under the terms of the GNU General Public License as published by * joachim99@69: * the Free Software Foundation; either version 2 of the License, or * joachim99@69: * (at your option) any later version. * joachim99@69: * * joachim99@69: * This program is distributed in the hope that it will be useful, * joachim99@69: * but WITHOUT ANY WARRANTY; without even the implied warranty of * joachim99@69: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * joachim99@69: * GNU General Public License for more details. * joachim99@69: * * joachim99@69: * You should have received a copy of the GNU General Public License * joachim99@69: * along with this program; if not, write to the * joachim99@69: * Free Software Foundation, Inc., * joachim99@69: * 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. * joachim99@69: ***************************************************************************/ joachim99@8: joachim99@8: #include "kdiff3_shell.h" joachim99@8: #include "kdiff3.h" joachim99@80: #include "kdiff3_part.h" joachim99@8: joachim99@80: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: joachim99@8: #include joachim99@8: joachim99@8: #include joachim99@80: #include joachim99@8: joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: #include joachim99@8: joachim99@8: #include joachim99@75: joachim99@75: #include joachim99@70: #include joachim99@80: #include joachim99@8: joachim99@75: joachim99@80: KDiff3Shell::KDiff3Shell( bool bCompleteInit ) joachim99@80: : KParts::MainWindow( ) joachim99@8: { joachim99@8: m_bUnderConstruction = true; joachim99@8: // set the shell's ui resource file joachim99@8: setXMLFile("kdiff3_shell.rc"); joachim99@8: joachim99@8: // and a status bar joachim99@8: statusBar()->show(); joachim99@8: joachim99@80: // m_part = static_cast(factory->create(this, "KDiff3Part", QStringList("KParts::ReadWritePart"))); joachim99@80: m_part = new KDiff3Part( this, "KDiff3Part", this ); joachim99@8: joachim99@80: if (m_part) joachim99@80: { joachim99@80: // and integrate the part's GUI with the shell's joachim99@80: createGUI(m_part); joachim99@80: //toolBar()->setToolButtonStyle( Qt::ToolButtonIconOnly ); joachim99@8: joachim99@80: // tell the KParts::MainWindow that this is indeed the main widget joachim99@80: setCentralWidget(m_part->widget()); joachim99@8: joachim99@80: if (bCompleteInit) joachim99@80: ((KDiff3App*)m_part->widget())->completeInit(); joachim99@80: connect(((KDiff3App*)m_part->widget()), SIGNAL(createNewInstance(const QString&, const QString&, const QString&)), this, SLOT(slotNewInstance(const QString&, const QString&, const QString&))); joachim99@80: } joachim99@8: else joachim99@8: { joachim99@8: // if we couldn't find our Part, we exit since the Shell by joachim99@8: // itself can't do anything useful joachim99@80: KMessageBox::error(this, i18n("Could not initialize our part!\n" joachim99@8: "This usually happens due to an installation problem. " joachim99@8: "Please read the README-file in the source package for details.") joachim99@8: ); joachim99@66: //kapp->quit(); joachim99@80: joachim99@66: ::exit(-1); //kapp->quit() doesn't work here yet. joachim99@66: joachim99@8: // we return here, cause kapp->quit() only means "exit the joachim99@8: // next time we enter the event loop... joachim99@80: joachim99@8: return; joachim99@8: } joachim99@8: joachim99@8: // apply the saved mainwindow settings, if any, and ask the mainwindow joachim99@8: // to automatically save settings if changed: window size, toolbar joachim99@8: // position, icon size, etc. joachim99@8: setAutoSaveSettings(); joachim99@8: m_bUnderConstruction = false; joachim99@8: } joachim99@8: joachim99@8: KDiff3Shell::~KDiff3Shell() joachim99@8: { joachim99@8: } joachim99@8: joachim99@8: bool KDiff3Shell::queryClose() joachim99@8: { joachim99@8: if (m_part) joachim99@8: return ((KDiff3App*)m_part->widget())->queryClose(); joachim99@8: else joachim99@8: return true; joachim99@8: } joachim99@8: joachim99@8: bool KDiff3Shell::queryExit() joachim99@8: { joachim99@8: return true; joachim99@8: } joachim99@8: joachim99@69: void KDiff3Shell::closeEvent(QCloseEvent*e) joachim99@69: { joachim99@69: if ( queryClose() ) joachim99@69: { joachim99@69: e->accept(); joachim99@69: bool bFileSaved = ((KDiff3App*)m_part->widget())->isFileSaved(); joachim99@80: bool bDirCompare = ((KDiff3App*)m_part->widget())->isDirComparison(); joachim99@80: KApplication::exit( bFileSaved || bDirCompare ? 0 : 1 ); joachim99@69: } joachim99@69: else joachim99@69: e->ignore(); joachim99@69: } joachim99@8: joachim99@8: void KDiff3Shell::optionsShowToolbar() joachim99@8: { joachim99@8: // this is all very cut and paste code for showing/hiding the joachim99@8: // toolbar joachim99@8: if (m_toolbarAction->isChecked()) joachim99@8: toolBar()->show(); joachim99@8: else joachim99@8: toolBar()->hide(); joachim99@8: } joachim99@8: joachim99@8: void KDiff3Shell::optionsShowStatusbar() joachim99@8: { joachim99@8: // this is all very cut and paste code for showing/hiding the joachim99@8: // statusbar joachim99@8: if (m_statusbarAction->isChecked()) joachim99@8: statusBar()->show(); joachim99@8: else joachim99@8: statusBar()->hide(); joachim99@8: } joachim99@8: joachim99@8: void KDiff3Shell::optionsConfigureKeys() joachim99@8: { joachim99@80: KShortcutsDialog::configure(actionCollection() /*, "kdiff3_shell.rc" */ ); joachim99@8: } joachim99@8: joachim99@8: void KDiff3Shell::optionsConfigureToolbars() joachim99@8: { joachim99@80: KConfigGroup mainWindowGroup( KGlobal::config(), "MainWindow" ); joachim99@80: saveMainWindowSettings( mainWindowGroup ); joachim99@8: joachim99@8: // use the standard toolbar editor joachim99@80: KEditToolBar dlg(factory()); joachim99@8: connect(&dlg, SIGNAL(newToolbarConfig()), joachim99@8: this, SLOT(applyNewToolbarConfig())); joachim99@8: dlg.exec(); joachim99@8: } joachim99@8: joachim99@8: void KDiff3Shell::applyNewToolbarConfig() joachim99@8: { joachim99@80: KConfigGroup mainWindowGroup( KGlobal::config(), "MainWindow" ); joachim99@80: applyMainWindowSettings( mainWindowGroup ); joachim99@8: } joachim99@8: joachim99@69: void KDiff3Shell::slotNewInstance( const QString& fn1, const QString& fn2, const QString& fn3 ) joachim99@69: { joachim99@69: KDiff3Shell* pKDiff3Shell = new KDiff3Shell(false); joachim99@69: ((KDiff3App*)pKDiff3Shell->m_part->widget())->completeInit(fn1,fn2,fn3); joachim99@69: } joachim99@69: joachim99@70: //#include "kdiff3_shell.moc"