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