kontact Library API Documentation

mainwindow.cpp

00001 /* 00002 This file is part of KDE Kontact. 00003 00004 Copyright (c) 2001 Matthias Hoelzer-Kluepfel <mhk@kde.org> 00005 Copyright (c) 2002-2003 Daniel Molkentin <molkentin@kde.org> 00006 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 #include <qcombobox.h> 00025 #include <qhbox.h> 00026 #include <qimage.h> 00027 #include <qobjectlist.h> 00028 #include <qsplitter.h> 00029 #include <qwhatsthis.h> 00030 #include <qtimer.h> 00031 #include <qprogressbar.h> 00032 00033 #include <dcopclient.h> 00034 #include <kapplication.h> 00035 #include <kconfig.h> 00036 #include <kdebug.h> 00037 #include <kedittoolbar.h> 00038 #include <kguiitem.h> 00039 #include <khelpmenu.h> 00040 #include <kiconloader.h> 00041 #include <kkeydialog.h> 00042 #include <klibloader.h> 00043 #include <klistbox.h> 00044 #include <klocale.h> 00045 #include <kmessagebox.h> 00046 #include <kparts/componentfactory.h> 00047 #include <kplugininfo.h> 00048 #include <kpopupmenu.h> 00049 #include <ksettings/dialog.h> 00050 #include <ksettings/dispatcher.h> 00051 #include <kshortcut.h> 00052 #include <kstandarddirs.h> 00053 #include <kstatusbar.h> 00054 #include <kstdaction.h> 00055 #include <ktip.h> 00056 #include <ktrader.h> 00057 #include <ksettings/componentsdialog.h> 00058 #include <kstringhandler.h> 00059 00060 #include <infoextension.h> 00061 00062 #include "aboutdialog.h" 00063 #include "iconsidepane.h" 00064 #include "mainwindow.h" 00065 #include "plugin.h" 00066 #include "prefs.h" 00067 #include "sidepane.h" 00068 #include "progressdialog.h" 00069 #include "statusbarprogresswidget.h" 00070 #include "broadcaststatus.h" 00071 #include "splash.h" 00072 00073 using namespace Kontact; 00074 00075 MainWindow::MainWindow(Kontact::Splash *splash) 00076 : Kontact::Core(), mTopWidget( 0 ), mHeaderText( 0 ), mHeaderPixmap( 0 ), mSplitter( 0 ), 00077 mSplash( splash ), mCurrentPlugin( 0 ), mLastInfoExtension( 0 ), mAboutDialog( 0 ), 00078 mReallyClose( false ) 00079 { 00080 initGUI(); 00081 QTimer::singleShot( 0, this, SLOT(initObject()) ); 00082 } 00083 00084 void MainWindow::initGUI() 00085 { 00086 initWidgets(); 00087 setupActions(); 00088 setHelpMenuEnabled( false ); 00089 KHelpMenu *helpMenu = new KHelpMenu( this, 0, true, actionCollection() ); 00090 connect( helpMenu, SIGNAL( showAboutApplication() ), 00091 SLOT( showAboutDialog() ) ); 00092 00093 KStdAction::keyBindings( this, SLOT( configureShortcuts() ), actionCollection() ); 00094 KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() ); 00095 setXMLFile( "kontactui.rc" ); 00096 00097 setStandardToolBarMenuEnabled( true ); 00098 00099 createGUI( 0 ); 00100 00101 resize( 700, 520 ); // initial size to prevent a scrollbar in sidepane 00102 setAutoSaveSettings(); 00103 00104 } 00105 00106 00107 void MainWindow::initObject() 00108 { 00109 KTrader::OfferList offers = KTrader::self()->query( 00110 QString::fromLatin1( "Kontact/Plugin" ), 00111 QString( "[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) ); 00112 mPluginInfos = KPluginInfo::fromServices( offers, Prefs::self()->config(), "Plugins" ); 00113 00114 QProgressBar *bar = mSplash->progressBar(); 00115 int count = 3; 00116 count += mPluginInfos.count(); 00117 bar->setTotalSteps( count ); 00118 00119 KPluginInfo::List::Iterator it; 00120 for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) { 00121 ( *it )->load(); 00122 bar->setProgress( bar->progress() + 1 ); 00123 } 00124 00125 00126 // prepare the part manager 00127 mPartManager = new KParts::PartManager( this ); 00128 connect( mPartManager, SIGNAL( activePartChanged( KParts::Part* ) ), 00129 this, SLOT( slotActivePartChanged( KParts::Part* ) ) ); 00130 00131 loadPlugins(); 00132 00133 bar->setProgress( bar->progress() + 1 ); 00134 00135 if ( mSidePane ) 00136 mSidePane->updatePlugins(); 00137 00138 // flush paint events 00139 kapp->processEvents(); 00140 00141 bar->setProgress( bar->progress() + 1 ); 00142 00143 KSettings::Dispatcher::self()->registerInstance( instance(), this, 00144 SLOT( updateConfig() ) ); 00145 00146 loadSettings(); 00147 00148 bar->setProgress( bar->progress() + 1 ); 00149 00150 statusBar()->show(); 00151 00152 // we are done - remove splash 00153 delete mSplash; 00154 mSplash=0; 00155 00156 showTip( false ); 00157 00158 // done initializing 00159 slotShowStatusMsg( QString::null ); 00160 00161 connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ), 00162 this, SLOT( slotShowStatusMsg( const QString& ) ) ); 00163 00164 // launch commandline specified module if any 00165 // TODO: GUI Option 00166 activatePluginModule(); 00167 00168 } 00169 00170 MainWindow::~MainWindow() 00171 { 00172 saveSettings(); 00173 00174 QPtrList<KParts::Part> parts = *mPartManager->parts(); 00175 00176 for ( KParts::Part *p = parts.last(); p; p = parts.prev() ) { 00177 delete p; 00178 p = 0; 00179 } 00180 00181 Prefs::self()->writeConfig(); 00182 } 00183 00184 void MainWindow::activePluginModule( const QString &_module ) 00185 { 00186 mActiveModule = _module; 00187 } 00188 00189 void MainWindow::activatePluginModule() 00190 { 00191 if ( !mActiveModule.isEmpty() ) 00192 { 00193 PluginList::ConstIterator end = mPlugins.end(); 00194 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) 00195 if ( ( *it )->identifier().contains( mActiveModule ) ) { 00196 selectPlugin( *it ); 00197 return; 00198 } 00199 } 00200 } 00201 00202 void MainWindow::initWidgets() 00203 { 00204 QHBox *topWidget = new QHBox( this ); 00205 topWidget->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 00206 00207 mTopWidget = topWidget; 00208 00209 setCentralWidget( mTopWidget ); 00210 00211 mSidePaneType = Prefs::self()->mSidePaneType; 00212 00213 QHBox *mBox = 0; 00214 00215 if ( mSidePaneType == Prefs::SidePaneBars ) { 00216 mSplitter = new QSplitter( mTopWidget ); 00217 mSidePane = new SidePane( this, mSplitter ); 00218 mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, 00219 QSizePolicy::Preferred ) ); 00220 mSplitter->setResizeMode( mSidePane, QSplitter::KeepSize ); 00221 } else { 00222 mSplitter = 0; 00223 mBox = new QHBox( mTopWidget ); 00224 mSidePane = new IconSidePane( this, mBox ); 00225 mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, 00226 QSizePolicy::Preferred ) ); 00227 } 00228 00229 mSidePane->setActionCollection( actionCollection() ); 00230 00231 connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ), 00232 SLOT( selectPlugin( Kontact::Plugin * ) ) ); 00233 00234 QVBox *vBox; 00235 if ( mSplitter ) { 00236 vBox = new QVBox( mSplitter ); 00237 } else { 00238 vBox = new QVBox( mBox ); 00239 } 00240 00241 initHeaderWidget( vBox ); 00242 if ( mSidePaneType != Prefs::SidePaneBars ) 00243 mHeaderFrame->hide(); 00244 00245 vBox->setSpacing( 0 ); 00246 00247 mStack = new QWidgetStack( vBox ); 00248 00249 /* Create a progress dialog and hide it. */ 00250 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( statusBar(), this ); 00251 progressDialog->hide(); 00252 00253 mLittleProgress = new KPIM::StatusbarProgressWidget( progressDialog, statusBar() ); 00254 00255 mStatusMsgLabel = new KStatusBarLabel( i18n( " Initializing..." ), 1, statusBar() ); 00256 mStatusMsgLabel->setAlignment( AlignLeft | AlignVCenter ); 00257 00258 statusBar()->addWidget( mStatusMsgLabel, 1 , false ); 00259 statusBar()->addWidget( mLittleProgress, 0 , true ); 00260 mLittleProgress->show(); 00261 } 00262 00263 void MainWindow::setupActions() 00264 { 00265 KStdAction::quit( this, SLOT( slotQuit() ), actionCollection() ); 00266 mNewActions = new KToolBarPopupAction( KGuiItem(i18n( "New" ), ""), 00267 KShortcut(), this, SLOT( slotNewClicked() ), 00268 actionCollection(), "action_new" ); 00269 00270 new KAction( i18n( "Select Components..." ), "configure", 0, this, 00271 SLOT( slotSelectComponents() ), 00272 actionCollection(), "settings_select_components" ); 00273 00274 new KAction( i18n( "Configure Kontact..." ), "configure", 0, this, SLOT( slotPreferences() ), 00275 actionCollection(), "settings_configure_kontact" ); 00276 00277 new KAction( i18n( "&Tip of the Day" ), 0, this, SLOT( slotShowTip() ), 00278 actionCollection(), "help_tipofday" ); 00279 new KAction( i18n( "&Request Feature..." ), 0, this, SLOT( slotRequestFeature() ), 00280 actionCollection(), "help_requestfeature" ); 00281 00282 } 00283 00284 void MainWindow::initHeaderWidget( QVBox *vBox ) 00285 { 00286 // Initiate the headerWidget 00287 mHeaderFrame = new QHBox( vBox ); 00288 mHeaderFrame->setSizePolicy( QSizePolicy::MinimumExpanding, 00289 QSizePolicy::Maximum ); 00290 mHeaderFrame->setSpacing( 0 ); 00291 mHeaderFrame->setFixedHeight( 22 ); 00292 00293 mHeaderText = new QLabel( mHeaderFrame ); 00294 mHeaderText->setSizePolicy( QSizePolicy::MinimumExpanding, 00295 QSizePolicy::Preferred ); 00296 mHeaderText->setPaletteForegroundColor( colorGroup().light() ); 00297 mHeaderText->setPaletteBackgroundColor( colorGroup().dark() ); 00298 00299 mHeaderPixmap = new QLabel( mHeaderFrame ); 00300 mHeaderPixmap->setSizePolicy( QSizePolicy::Maximum, 00301 QSizePolicy::Preferred ); 00302 mHeaderPixmap->setAlignment( AlignRight|AlignVCenter ); 00303 mHeaderPixmap->setPaletteBackgroundColor( colorGroup().dark() ); 00304 00305 connect( this, SIGNAL( textChanged( const QString& ) ), 00306 this, SLOT( setHeaderText( const QString& ) ) ); 00307 connect( this, SIGNAL( iconChanged( const QPixmap& ) ), 00308 this, SLOT( setHeaderPixmap( const QPixmap& ) ) ); 00309 00310 QFont fnt( mSidePane->font() ); 00311 fnt.setBold( true ); 00312 fnt.setPointSize( mSidePane->font().pointSize() + 3 ); 00313 mHeaderText->setFont( fnt ); 00314 } 00315 00316 bool MainWindow::isPluginLoaded( const KPluginInfo * info ) 00317 { 00318 return ( pluginFromInfo( info ) != 0 ); 00319 } 00320 00321 Plugin *MainWindow::pluginFromInfo( const KPluginInfo *info ) 00322 { 00323 PluginList::ConstIterator end = mPlugins.end(); 00324 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) 00325 if ( ( *it )->identifier() == info->pluginName() ) 00326 return *it; 00327 00328 return 0; 00329 } 00330 00331 void MainWindow::loadPlugins() 00332 { 00333 QPtrList<Plugin> plugins; 00334 QPtrList<KParts::Part> loadDelayed; 00335 00336 uint i; 00337 KPluginInfo::List::ConstIterator it; 00338 for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) { 00339 if ( ! ( *it )->isPluginEnabled() ) 00340 continue; 00341 if ( isPluginLoaded( *it ) ) { 00342 Plugin *plugin = pluginFromInfo( *it ); 00343 if ( plugin ) 00344 plugin->configUpdated(); 00345 continue; 00346 } 00347 00348 kdDebug(5600) << "Loading Plugin: " << ( *it )->name() << endl; 00349 Kontact::Plugin *plugin = 00350 KParts::ComponentFactory::createInstanceFromService<Kontact::Plugin>( 00351 ( *it )->service(), this ); 00352 00353 if ( !plugin ) 00354 continue; 00355 00356 plugin->setIdentifier( ( *it )->pluginName() ); 00357 plugin->setTitle( ( *it )->name() ); 00358 plugin->setIcon( ( *it )->icon() ); 00359 00360 QVariant libNameProp = ( *it )->property( "X-KDE-KontactPartLibraryName" ); 00361 QVariant exeNameProp = ( *it )->property( "X-KDE-KontactPartExecutableName" ); 00362 QVariant loadOnStart = ( *it )->property( "X-KDE-KontactPartLoadOnStart" ); 00363 00364 if ( !loadOnStart.isNull() && loadOnStart.toBool() ) 00365 mDelayedPreload.append( plugin ); 00366 00367 kdDebug(5600) << "LIBNAMEPART: " << libNameProp.toString() << endl; 00368 00369 plugin->setPartLibraryName( libNameProp.toString().utf8() ); 00370 plugin->setExecutableName( exeNameProp.toString() ); 00371 00372 for ( i = 0; i < plugins.count(); ++i ) { 00373 Plugin *p = plugins.at( i ); 00374 if ( plugin->weight() < p->weight() ) break; 00375 } 00376 00377 plugins.insert( i, plugin ); 00378 } 00379 00380 for ( i = 0; i < plugins.count(); ++ i ) { 00381 Plugin *plugin = plugins.at( i ); 00382 00383 KAction *action; 00384 QPtrList<KAction> *actionList = plugin->newActions(); 00385 00386 for ( action = actionList->first(); action; action = actionList->next() ) { 00387 kdDebug(5600) << "Plugging " << action->name() << endl; 00388 action->plug( mNewActions->popupMenu() ); 00389 } 00390 00391 addPlugin( plugin ); 00392 } 00393 00394 mLastInfoExtension = 0; 00395 00396 mNewActions->setEnabled( mPlugins.size() != 0 ); 00397 } 00398 00399 void MainWindow::unloadPlugins() 00400 { 00401 KPluginInfo::List::ConstIterator end = mPluginInfos.end(); 00402 KPluginInfo::List::ConstIterator it; 00403 for ( it = mPluginInfos.begin(); it != end; ++it ) { 00404 if ( ! ( *it )->isPluginEnabled() ) 00405 removePlugin( *it ); 00406 } 00407 } 00408 00409 bool MainWindow::removePlugin( const KPluginInfo * info ) 00410 { 00411 PluginList::Iterator end = mPlugins.end(); 00412 for ( PluginList::Iterator it = mPlugins.begin(); it != end; ++it ) 00413 if ( ( *it )->identifier() == info->pluginName() ) { 00414 Plugin *plugin = *it; 00415 00416 KAction *action; 00417 QPtrList<KAction> *actionList = plugin->newActions(); 00418 00419 for ( action = actionList->first(); action; action = actionList->next() ) { 00420 kdDebug(5600) << "Unplugging " << action->name() << endl; 00421 action->unplug( mNewActions->popupMenu() ); 00422 } 00423 00424 removeChildClient( plugin ); 00425 00426 if ( mCurrentPlugin == plugin ) 00427 mCurrentPlugin = 0; 00428 00429 delete plugin; // removes the part automatically 00430 mPlugins.remove( it ); 00431 00432 return true; 00433 } 00434 00435 return false; 00436 } 00437 00438 void MainWindow::addPlugin( Kontact::Plugin *plugin ) 00439 { 00440 kdDebug(5600) << "Added plugin" << endl; 00441 00442 mPlugins.append( plugin ); 00443 00444 // merge the plugins GUI into the main window 00445 insertChildClient( plugin ); 00446 } 00447 00448 void MainWindow::partLoaded( Kontact::Plugin * /*plugin*/, KParts::Part *part ) 00449 { 00450 if ( part->widget() ) 00451 mStack->addWidget( part->widget(), 0 ); 00452 00453 mPartManager->addPart( part, false ); 00454 // Workaround for KParts misbehavior: addPart calls show! 00455 part->widget()->hide(); 00456 } 00457 00458 void MainWindow::slotActivePartChanged( KParts::Part *part ) 00459 { 00460 if ( !part ) { 00461 createGUI( 0 ); 00462 return; 00463 } 00464 00465 if ( mLastInfoExtension ) { 00466 disconnect( mLastInfoExtension, SIGNAL( textChanged( const QString& ) ), 00467 this, SLOT( setHeaderText( const QString& ) ) ); 00468 disconnect( mLastInfoExtension, SIGNAL( iconChanged( const QPixmap& ) ), 00469 this, SLOT( setHeaderPixmap( const QPixmap& ) ) ); 00470 } 00471 00472 kdDebug(5600) << "Part activated: " << part << " with stack id. " 00473 << mStack->id( part->widget() )<< endl; 00474 QObjectList *l = part->queryList( "KParts::InfoExtension" ); 00475 KParts::InfoExtension *ie = 0; 00476 if ( l ) 00477 ie = static_cast<KParts::InfoExtension*>( l->first() ); 00478 delete l; 00479 00480 if ( ie ) { 00481 connect( ie, SIGNAL( textChanged( const QString& ) ), 00482 SLOT( setHeaderText( const QString& ) ) ); 00483 connect( ie, SIGNAL( iconChanged( const QPixmap& ) ), 00484 SLOT( setHeaderPixmap( const QPixmap& ) ) ); 00485 } 00486 00487 mLastInfoExtension = ie; 00488 00489 InfoExtData data = mInfoExtCache[ ie ]; 00490 setHeaderPixmap( data.pixmap ); 00491 setHeaderText( data.text ); 00492 00493 createGUI( part ); 00494 00495 statusBar()->clear(); 00496 } 00497 00498 void MainWindow::slotNewClicked() 00499 { 00500 KAction *action = mCurrentPlugin->newActions()->first(); 00501 if ( action ) { 00502 action->activate(); 00503 } else { 00504 PluginList::Iterator it; 00505 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) { 00506 action = (*it)->newActions()->first(); 00507 if ( action ) { 00508 action->activate(); 00509 return; 00510 } 00511 } 00512 } 00513 } 00514 00515 void MainWindow::selectPlugin( Kontact::Plugin *plugin ) 00516 { 00517 if ( !plugin ) 00518 return; 00519 00520 if ( plugin->isRunningStandalone() ) { 00521 statusBar()->message( i18n( "Application is running standalone. Foregrounding..." ), 1000 ); 00522 plugin->bringToForeground(); 00523 return; 00524 } 00525 00526 KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); 00527 00528 if ( mSidePane ) 00529 mSidePane->selectPlugin( plugin ); 00530 00531 KParts::Part *part = plugin->part(); 00532 00533 if ( !part ) { 00534 KMessageBox::error( this, i18n( "Cannot load part for %1." ) 00535 .arg( plugin->title() ) ); 00536 KApplication::restoreOverrideCursor(); 00537 return; 00538 } 00539 00540 plugin->select(); 00541 00542 mPartManager->setActivePart( part ); 00543 QWidget *view = part->widget(); 00544 Q_ASSERT( view ); 00545 00546 if ( view ) { 00547 mStack->raiseWidget( view ); 00548 view->show(); 00549 view->setFocus(); 00550 mCurrentPlugin = plugin; 00551 KAction *action = plugin->newActions()->first(); 00552 setCaption( i18n( "Plugin dependent window title" ,"%1 - Kontact" ).arg( plugin->title() ) ); 00553 if ( action ) { 00554 mNewActions->setIcon( action->icon() ); 00555 mNewActions->setText( action->text() ); 00556 } else { // we'll use the action of the first plugin which offers one 00557 PluginList::Iterator it; 00558 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) { 00559 action = (*it)->newActions()->first(); 00560 if ( action ) { 00561 mNewActions->setIcon( action->icon() ); 00562 mNewActions->setText( action->text() ); 00563 break; 00564 } 00565 } 00566 } 00567 } 00568 00569 QStringList invisibleActions = plugin->invisibleToolbarActions(); 00570 00571 QStringList::ConstIterator it; 00572 for ( it = invisibleActions.begin(); it != invisibleActions.end(); ++it ) { 00573 KAction *action = part->actionCollection()->action( (*it).latin1() ); 00574 if ( action ) 00575 action->unplug( toolBar() ); 00576 } 00577 00578 KApplication::restoreOverrideCursor(); 00579 } 00580 00581 void MainWindow::selectPlugin( const QString &pluginName ) 00582 { 00583 PluginList::ConstIterator end = mPlugins.end(); 00584 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) 00585 if ( ( *it )->identifier() == pluginName ) { 00586 selectPlugin( *it ); 00587 return; 00588 } 00589 } 00590 00591 void MainWindow::loadSettings() 00592 { 00593 if ( mSplitter ) 00594 mSplitter->setSizes( Prefs::self()->mSidePaneSplitter ); 00595 00596 // Preload Plugins. This _must_ happen before the default part is loaded 00597 PluginList::ConstIterator it; 00598 for ( it = mDelayedPreload.begin(); it != mDelayedPreload.end(); ++it ) 00599 selectPlugin( *it ); 00600 00601 selectPlugin( Prefs::self()->mActivePlugin ); 00602 } 00603 00604 void MainWindow::saveSettings() 00605 { 00606 if ( mSplitter ) 00607 Prefs::self()->mSidePaneSplitter = mSplitter->sizes(); 00608 00609 if ( mCurrentPlugin ) 00610 Prefs::self()->mActivePlugin = mCurrentPlugin->identifier(); 00611 } 00612 00613 void MainWindow::slotShowTip() 00614 { 00615 showTip( true ); 00616 } 00617 00618 void MainWindow::slotRequestFeature() 00619 { 00620 if ( kapp ) 00621 kapp->invokeBrowser( "http://kontact.org/shopping" ); 00622 } 00623 00624 void MainWindow::showTip(bool force) 00625 { 00626 QStringList tips; 00627 PluginList::ConstIterator end = mPlugins.end(); 00628 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) { 00629 QString file = ( *it )->tipFile(); 00630 if ( !file.isEmpty() ) 00631 tips.append( file ); 00632 } 00633 00634 KTipDialog::showMultiTip(this, tips, force); 00635 } 00636 00637 void MainWindow::slotQuit() 00638 { 00639 mReallyClose=true; 00640 close(); 00641 } 00642 00643 void MainWindow::slotPreferences() 00644 { 00645 static KSettings::Dialog *dlg = 0; 00646 if( !dlg ) { 00647 dlg = new KSettings::Dialog( KSettings::Dialog::Configurable, this ); 00648 dlg->addPluginInfos( mPluginInfos ); 00649 connect( dlg, SIGNAL( pluginSelectionChanged() ), 00650 SLOT( pluginsChanged() ) ); 00651 // connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) ); 00652 // connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) ); 00653 } 00654 00655 dlg->show(); 00656 } 00657 00658 void MainWindow::slotSelectComponents() 00659 { 00660 static KSettings::ComponentsDialog *dlg = 0; 00661 if ( !dlg ) { 00662 dlg = new KSettings::ComponentsDialog( this ); 00663 dlg->setPluginInfos( mPluginInfos ); 00664 connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) ); 00665 connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) ); 00666 } 00667 00668 dlg->show(); 00669 } 00670 00671 int MainWindow::startServiceFor( const QString& serviceType, 00672 const QString& constraint, 00673 const QString& preferences, 00674 QString *error, QCString* dcopService, 00675 int flags ) 00676 { 00677 PluginList::ConstIterator end = mPlugins.end(); 00678 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) { 00679 if ( ( *it )->createDCOPInterface( serviceType ) ) { 00680 kdDebug(5600) << "found interface for " << serviceType << endl; 00681 if ( dcopService ) 00682 *dcopService = ( *it )->dcopClient()->appId(); 00683 kdDebug(5600) << "appId=" << ( *it )->dcopClient()->appId() << endl; 00684 return 0; // success 00685 } 00686 } 00687 kdDebug(5600) << 00688 "Didn't find dcop interface, falling back to external process" << endl; 00689 return KDCOPServiceStarter::startServiceFor( serviceType, constraint, 00690 preferences, error, dcopService, flags ); 00691 } 00692 00693 void MainWindow::setHeaderText( const QString &text ) 00694 { 00695 mInfoExtCache[ mLastInfoExtension ].text = text; 00696 mHeaderText->setText( text ); 00697 } 00698 00699 void MainWindow::setHeaderPixmap( const QPixmap &pixmap ) 00700 { 00701 QPixmap pm( pixmap ); 00702 00703 if ( pm.height() > 22 || pm.width() > 22 ) { 00704 QImage img; 00705 img = pixmap; 00706 pm = img.smoothScale( 22, 22, QImage::ScaleMin ); 00707 } 00708 00709 mInfoExtCache[ mLastInfoExtension ].pixmap = pm; 00710 mHeaderPixmap->setPixmap( pm ); 00711 } 00712 00713 void MainWindow::pluginsChanged() 00714 { 00715 unloadPlugins(); 00716 loadPlugins(); 00717 mSidePane->updatePlugins(); 00718 } 00719 00720 void MainWindow::updateConfig() 00721 { 00722 kdDebug( 5600 ) << k_funcinfo << endl; 00723 00724 saveSettings(); 00725 00726 #if 0 00727 bool sidePaneChanged = ( Prefs::self()->mSidePaneType != mSidePaneType ); 00728 00729 if ( sidePaneChanged ) { 00730 mSidePaneType = Prefs::self()->mSidePaneType; 00731 00732 delete mSidePane; 00733 00734 switch ( mSidePaneType ) { 00735 case Prefs::SidePaneIcons: 00736 mSidePane = new IconSidePane( this, mSplitter ); 00737 mHeaderFrame->hide(); 00738 break; 00739 default: 00740 kdError() << "Invalid SidePaneType: " << mSidePaneType << endl; 00741 case Prefs::SidePaneBars: 00742 mSidePane = new SidePane( this, mSplitter ); 00743 mHeaderFrame->show(); 00744 break; 00745 } 00746 00747 mSplitter->setResizeMode( mSidePane, QSplitter::KeepSize ); 00748 00749 mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, 00750 QSizePolicy::Preferred ) ); 00751 00752 connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ), 00753 SLOT( selectPlugin( Kontact::Plugin * ) ) ); 00754 00755 mSplitter->moveToFirst( mSidePane ); 00756 00757 mSidePane->show(); 00758 } 00759 00760 if ( sidePaneChanged ) 00761 mSidePane->updatePlugins(); 00762 #endif 00763 00764 loadSettings(); 00765 } 00766 00767 void MainWindow::showAboutDialog() 00768 { 00769 KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); 00770 00771 if ( !mAboutDialog ) 00772 mAboutDialog = new AboutDialog( this ); 00773 00774 mAboutDialog->show(); 00775 mAboutDialog->raise(); 00776 KApplication::restoreOverrideCursor(); 00777 } 00778 00779 void MainWindow::configureShortcuts() 00780 { 00781 KKeyDialog dialog( true, this ); 00782 dialog.insert( actionCollection() ); 00783 00784 if ( mCurrentPlugin && mCurrentPlugin->part() ) 00785 dialog.insert( mCurrentPlugin->part()->actionCollection() ); 00786 00787 dialog.configure(); 00788 } 00789 00790 void MainWindow::configureToolbars() 00791 { 00792 saveMainWindowSettings( KGlobal::config(), "MainWindow" ); 00793 00794 KEditToolbar edit( factory() ); 00795 connect( &edit, SIGNAL( newToolbarConfig() ), 00796 this, SLOT( slotNewToolbarConfig() ) ); 00797 edit.exec(); 00798 } 00799 00800 void MainWindow::slotNewToolbarConfig() 00801 { 00802 createGUI( mCurrentPlugin->part() ); 00803 applyMainWindowSettings( KGlobal::config(), "MainWindow" ); 00804 } 00805 00806 bool MainWindow::queryClose() 00807 { 00808 if ( kapp->sessionSaving() || mReallyClose ) 00809 return true; 00810 00811 bool localClose = true; 00812 QValueList<Plugin*>::ConstIterator end = mPlugins.end(); 00813 QValueList<Plugin*>::ConstIterator it = mPlugins.begin(); 00814 for ( ; it != end; ++it ) { 00815 Plugin *plugin = *it; 00816 if ( !plugin->isRunningStandalone() ) 00817 if ( !plugin->queryClose() ) 00818 localClose = false; 00819 } 00820 00821 return localClose; 00822 } 00823 00824 00825 void MainWindow::slotShowStatusMsg( const QString &msg ) 00826 { 00827 if ( !statusBar() || !mStatusMsgLabel ) return; 00828 int statusWidth = mStatusMsgLabel->width() - fontMetrics().maxWidth(); 00829 QString text = KStringHandler::rPixelSqueeze( " " + msg, fontMetrics(), 00830 statusWidth ); 00831 mStatusMsgLabel->setText( text ); 00832 } 00833 #include "mainwindow.moc"
KDE Logo
This file is part of the documentation for kontact Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:35 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003