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 } 00455 00456 void MainWindow::slotActivePartChanged( KParts::Part *part ) 00457 { 00458 if ( !part ) { 00459 createGUI( 0 ); 00460 return; 00461 } 00462 00463 if ( mLastInfoExtension ) { 00464 disconnect( mLastInfoExtension, SIGNAL( textChanged( const QString& ) ), 00465 this, SLOT( setHeaderText( const QString& ) ) ); 00466 disconnect( mLastInfoExtension, SIGNAL( iconChanged( const QPixmap& ) ), 00467 this, SLOT( setHeaderPixmap( const QPixmap& ) ) ); 00468 } 00469 00470 kdDebug(5600) << "Part activated: " << part << " with stack id. " 00471 << mStack->id( part->widget() )<< endl; 00472 QObjectList *l = part->queryList( "KParts::InfoExtension" ); 00473 KParts::InfoExtension *ie = 0; 00474 if ( l ) 00475 ie = static_cast<KParts::InfoExtension*>( l->first() ); 00476 delete l; 00477 00478 if ( ie ) { 00479 connect( ie, SIGNAL( textChanged( const QString& ) ), 00480 SLOT( setHeaderText( const QString& ) ) ); 00481 connect( ie, SIGNAL( iconChanged( const QPixmap& ) ), 00482 SLOT( setHeaderPixmap( const QPixmap& ) ) ); 00483 } 00484 00485 mLastInfoExtension = ie; 00486 00487 InfoExtData data = mInfoExtCache[ ie ]; 00488 setHeaderPixmap( data.pixmap ); 00489 setHeaderText( data.text ); 00490 00491 createGUI( part ); 00492 00493 statusBar()->clear(); 00494 } 00495 00496 void MainWindow::slotNewClicked() 00497 { 00498 KAction *action = mCurrentPlugin->newActions()->first(); 00499 if ( action ) { 00500 action->activate(); 00501 } else { 00502 PluginList::Iterator it; 00503 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) { 00504 action = (*it)->newActions()->first(); 00505 if ( action ) { 00506 action->activate(); 00507 return; 00508 } 00509 } 00510 } 00511 } 00512 00513 void MainWindow::selectPlugin( Kontact::Plugin *plugin ) 00514 { 00515 if ( !plugin ) 00516 return; 00517 00518 if ( plugin->isRunningStandalone() ) { 00519 statusBar()->message( i18n( "Application is running standalone. Foregrounding..." ), 1000 ); 00520 plugin->bringToForeground(); 00521 return; 00522 } 00523 00524 KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); 00525 00526 if ( mSidePane ) 00527 mSidePane->selectPlugin( plugin ); 00528 00529 KParts::Part *part = plugin->part(); 00530 00531 if ( !part ) { 00532 KMessageBox::error( this, i18n( "Cannot load part for %1." ) 00533 .arg( plugin->title() ) ); 00534 KApplication::restoreOverrideCursor(); 00535 return; 00536 } 00537 00538 plugin->select(); 00539 00540 mPartManager->setActivePart( part ); 00541 QWidget *view = part->widget(); 00542 Q_ASSERT( view ); 00543 00544 if ( view ) { 00545 mStack->raiseWidget( view ); 00546 view->show(); 00547 view->setFocus(); 00548 mCurrentPlugin = plugin; 00549 KAction *action = plugin->newActions()->first(); 00550 setCaption( i18n( "Plugin dependent window title" ,"%1 - Kontact" ).arg( plugin->title() ) ); 00551 if ( action ) { 00552 mNewActions->setIcon( action->icon() ); 00553 mNewActions->setText( action->text() ); 00554 } else { // we'll use the action of the first plugin which offers one 00555 PluginList::Iterator it; 00556 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) { 00557 action = (*it)->newActions()->first(); 00558 if ( action ) { 00559 mNewActions->setIcon( action->icon() ); 00560 mNewActions->setText( action->text() ); 00561 break; 00562 } 00563 } 00564 } 00565 } 00566 00567 QStringList invisibleActions = plugin->invisibleToolbarActions(); 00568 00569 QStringList::ConstIterator it; 00570 for ( it = invisibleActions.begin(); it != invisibleActions.end(); ++it ) { 00571 KAction *action = part->actionCollection()->action( (*it).latin1() ); 00572 if ( action ) 00573 action->unplug( toolBar() ); 00574 } 00575 00576 KApplication::restoreOverrideCursor(); 00577 } 00578 00579 void MainWindow::selectPlugin( const QString &pluginName ) 00580 { 00581 PluginList::ConstIterator end = mPlugins.end(); 00582 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) 00583 if ( ( *it )->identifier() == pluginName ) { 00584 selectPlugin( *it ); 00585 return; 00586 } 00587 } 00588 00589 void MainWindow::loadSettings() 00590 { 00591 if ( mSplitter ) 00592 mSplitter->setSizes( Prefs::self()->mSidePaneSplitter ); 00593 00594 // Preload Plugins. This _must_ happen before the default part is loaded 00595 PluginList::ConstIterator it; 00596 for ( it = mDelayedPreload.begin(); it != mDelayedPreload.end(); ++it ) 00597 selectPlugin( *it ); 00598 00599 selectPlugin( Prefs::self()->mActivePlugin ); 00600 } 00601 00602 void MainWindow::saveSettings() 00603 { 00604 if ( mSplitter ) 00605 Prefs::self()->mSidePaneSplitter = mSplitter->sizes(); 00606 00607 if ( mCurrentPlugin ) 00608 Prefs::self()->mActivePlugin = mCurrentPlugin->identifier(); 00609 } 00610 00611 void MainWindow::slotShowTip() 00612 { 00613 showTip( true ); 00614 } 00615 00616 void MainWindow::slotRequestFeature() 00617 { 00618 if ( kapp ) 00619 kapp->invokeBrowser( "http://kontact.org/shopping" ); 00620 } 00621 00622 void MainWindow::showTip(bool force) 00623 { 00624 QStringList tips; 00625 PluginList::ConstIterator end = mPlugins.end(); 00626 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) { 00627 QString file = ( *it )->tipFile(); 00628 if ( !file.isEmpty() ) 00629 tips.append( file ); 00630 } 00631 00632 KTipDialog::showMultiTip(this, tips, force); 00633 } 00634 00635 void MainWindow::slotQuit() 00636 { 00637 mReallyClose=true; 00638 close(); 00639 } 00640 00641 void MainWindow::slotPreferences() 00642 { 00643 static KSettings::Dialog *dlg = 0; 00644 if( !dlg ) { 00645 dlg = new KSettings::Dialog( KSettings::Dialog::Configurable, this ); 00646 dlg->addPluginInfos( mPluginInfos ); 00647 connect( dlg, SIGNAL( pluginSelectionChanged() ), 00648 SLOT( pluginsChanged() ) ); 00649 // connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) ); 00650 // connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) ); 00651 } 00652 00653 dlg->show(); 00654 } 00655 00656 void MainWindow::slotSelectComponents() 00657 { 00658 static KSettings::ComponentsDialog *dlg = 0; 00659 if ( !dlg ) { 00660 dlg = new KSettings::ComponentsDialog( this ); 00661 dlg->setPluginInfos( mPluginInfos ); 00662 connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) ); 00663 connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) ); 00664 } 00665 00666 dlg->show(); 00667 } 00668 00669 int MainWindow::startServiceFor( const QString& serviceType, 00670 const QString& constraint, 00671 const QString& preferences, 00672 QString *error, QCString* dcopService, 00673 int flags ) 00674 { 00675 PluginList::ConstIterator end = mPlugins.end(); 00676 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) { 00677 if ( ( *it )->createDCOPInterface( serviceType ) ) { 00678 kdDebug(5600) << "found interface for " << serviceType << endl; 00679 if ( dcopService ) 00680 *dcopService = ( *it )->dcopClient()->appId(); 00681 kdDebug(5600) << "appId=" << ( *it )->dcopClient()->appId() << endl; 00682 return 0; // success 00683 } 00684 } 00685 kdDebug(5600) << 00686 "Didn't find dcop interface, falling back to external process" << endl; 00687 return KDCOPServiceStarter::startServiceFor( serviceType, constraint, 00688 preferences, error, dcopService, flags ); 00689 } 00690 00691 void MainWindow::setHeaderText( const QString &text ) 00692 { 00693 mInfoExtCache[ mLastInfoExtension ].text = text; 00694 mHeaderText->setText( text ); 00695 } 00696 00697 void MainWindow::setHeaderPixmap( const QPixmap &pixmap ) 00698 { 00699 QPixmap pm( pixmap ); 00700 00701 if ( pm.height() > 22 || pm.width() > 22 ) { 00702 QImage img; 00703 img = pixmap; 00704 pm = img.smoothScale( 22, 22, QImage::ScaleMin ); 00705 } 00706 00707 mInfoExtCache[ mLastInfoExtension ].pixmap = pm; 00708 mHeaderPixmap->setPixmap( pm ); 00709 } 00710 00711 void MainWindow::pluginsChanged() 00712 { 00713 unloadPlugins(); 00714 loadPlugins(); 00715 mSidePane->updatePlugins(); 00716 } 00717 00718 void MainWindow::updateConfig() 00719 { 00720 kdDebug( 5600 ) << k_funcinfo << endl; 00721 00722 saveSettings(); 00723 00724 #if 0 00725 bool sidePaneChanged = ( Prefs::self()->mSidePaneType != mSidePaneType ); 00726 00727 if ( sidePaneChanged ) { 00728 mSidePaneType = Prefs::self()->mSidePaneType; 00729 00730 delete mSidePane; 00731 00732 switch ( mSidePaneType ) { 00733 case Prefs::SidePaneIcons: 00734 mSidePane = new IconSidePane( this, mSplitter ); 00735 mHeaderFrame->hide(); 00736 break; 00737 default: 00738 kdError() << "Invalid SidePaneType: " << mSidePaneType << endl; 00739 case Prefs::SidePaneBars: 00740 mSidePane = new SidePane( this, mSplitter ); 00741 mHeaderFrame->show(); 00742 break; 00743 } 00744 00745 mSplitter->setResizeMode( mSidePane, QSplitter::KeepSize ); 00746 00747 mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, 00748 QSizePolicy::Preferred ) ); 00749 00750 connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ), 00751 SLOT( selectPlugin( Kontact::Plugin * ) ) ); 00752 00753 mSplitter->moveToFirst( mSidePane ); 00754 00755 mSidePane->show(); 00756 } 00757 00758 if ( sidePaneChanged ) 00759 mSidePane->updatePlugins(); 00760 #endif 00761 00762 loadSettings(); 00763 } 00764 00765 void MainWindow::showAboutDialog() 00766 { 00767 KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) ); 00768 00769 if ( !mAboutDialog ) 00770 mAboutDialog = new AboutDialog( this ); 00771 00772 mAboutDialog->show(); 00773 mAboutDialog->raise(); 00774 KApplication::restoreOverrideCursor(); 00775 } 00776 00777 void MainWindow::configureShortcuts() 00778 { 00779 KKeyDialog dialog( true, this ); 00780 dialog.insert( actionCollection() ); 00781 00782 if ( mCurrentPlugin && mCurrentPlugin->part() ) 00783 dialog.insert( mCurrentPlugin->part()->actionCollection() ); 00784 00785 dialog.configure(); 00786 } 00787 00788 void MainWindow::configureToolbars() 00789 { 00790 saveMainWindowSettings( KGlobal::config(), "MainWindow" ); 00791 00792 KEditToolbar edit( factory() ); 00793 connect( &edit, SIGNAL( newToolbarConfig() ), 00794 this, SLOT( slotNewToolbarConfig() ) ); 00795 edit.exec(); 00796 } 00797 00798 void MainWindow::slotNewToolbarConfig() 00799 { 00800 createGUI( mCurrentPlugin->part() ); 00801 applyMainWindowSettings( KGlobal::config(), "MainWindow" ); 00802 } 00803 00804 bool MainWindow::queryClose() 00805 { 00806 if ( kapp->sessionSaving() || mReallyClose ) 00807 return true; 00808 00809 bool localClose = true; 00810 QValueList<Plugin*>::ConstIterator end = mPlugins.end(); 00811 QValueList<Plugin*>::ConstIterator it = mPlugins.begin(); 00812 for ( ; it != end; ++it ) { 00813 Plugin *plugin = *it; 00814 if ( !plugin->isRunningStandalone() ) 00815 if ( !plugin->queryClose() ) 00816 localClose = false; 00817 } 00818 00819 return localClose; 00820 } 00821 00822 00823 void MainWindow::slotShowStatusMsg( const QString &msg ) 00824 { 00825 if ( !statusBar() || !mStatusMsgLabel ) return; 00826 int statusWidth = mStatusMsgLabel->width() - fontMetrics().maxWidth(); 00827 QString text = KStringHandler::rPixelSqueeze( " " + msg, fontMetrics(), 00828 statusWidth ); 00829 mStatusMsgLabel->setText( text ); 00830 } 00831 #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 Aug 27 12:53:45 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003