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 
00220   if ( mSidePaneType == Prefs::SidePaneBars ) {
00221     mSplitter = new QSplitter( mTopWidget );
00222     mSidePane = new SidePane( this, mSplitter );
00223     mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum,
00224                                            QSizePolicy::Preferred ) );
00225     mSplitter->setResizeMode( mSidePane, QSplitter::KeepSize );
00226   } else {
00227     mSplitter = 0;
00228     mBox = new QHBox( mTopWidget );
00229     mSidePane = new IconSidePane( this, mBox );
00230     mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum,
00231                                            QSizePolicy::Preferred ) );
00232   }
00233 
00234   mSidePane->setActionCollection( actionCollection() );
00235 
00236   connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ),
00237            SLOT( selectPlugin( Kontact::Plugin * ) ) );
00238 
00239   QVBox *vBox;
00240   if ( mSplitter ) {
00241     vBox = new QVBox( mSplitter );
00242   } else {
00243     vBox = new QVBox( mBox );
00244   }
00245 
00246   initHeaderWidget( vBox );
00247   if ( mSidePaneType != Prefs::SidePaneBars )
00248     mHeaderFrame->hide();
00249 
00250   vBox->setSpacing( 0 );
00251 
00252   mStack = new QWidgetStack( vBox );
00253 
00254   /* Create a progress dialog and hide it. */
00255   KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( statusBar(), this );
00256   progressDialog->hide();
00257 
00258   mLittleProgress = new KPIM::StatusbarProgressWidget( progressDialog, statusBar() );
00259 
00260   mStatusMsgLabel = new KStatusBarLabel( i18n( " Initializing..." ), 1, statusBar() );
00261   mStatusMsgLabel->setAlignment( AlignLeft | AlignVCenter );
00262 
00263   statusBar()->addWidget( mStatusMsgLabel, 1 , false );
00264   statusBar()->addWidget( mLittleProgress, 0 , true );
00265   mLittleProgress->show();
00266 }
00267 
00268 void MainWindow::setupActions()
00269 {
00270   KStdAction::quit( this, SLOT( slotQuit() ), actionCollection() );
00271   mNewActions = new KToolBarPopupAction( KGuiItem(i18n( "New" ), ""),
00272                                          KShortcut(), this, SLOT( slotNewClicked() ),
00273                                          actionCollection(), "action_new" );
00274 
00275   new KAction( i18n( "Select Components..." ), "configure", 0, this,
00276                SLOT( slotSelectComponents() ),
00277                actionCollection(), "settings_select_components" );
00278 
00279   new KAction( i18n( "Configure Kontact..." ), "configure", 0, this, SLOT( slotPreferences() ),
00280                actionCollection(), "settings_configure_kontact" );
00281 
00282   new KAction( i18n( "&Tip of the Day" ), 0, this, SLOT( slotShowTip() ),
00283                actionCollection(), "help_tipofday" );
00284   new KAction( i18n( "&Request Feature..." ), 0, this, SLOT( slotRequestFeature() ),
00285                actionCollection(), "help_requestfeature" );
00286 
00287 }
00288 
00289 void MainWindow::initHeaderWidget( QVBox *vBox )
00290 {
00291   // Initiate the headerWidget
00292   mHeaderFrame = new QHBox( vBox );
00293   mHeaderFrame->setSizePolicy( QSizePolicy::MinimumExpanding,
00294                                QSizePolicy::Maximum );
00295   mHeaderFrame->setSpacing( 0 );
00296   mHeaderFrame->setFixedHeight( 22 );
00297 
00298   mHeaderText = new QLabel( mHeaderFrame );
00299   mHeaderText->setSizePolicy( QSizePolicy::MinimumExpanding,
00300                               QSizePolicy::Preferred );
00301   mHeaderText->setPaletteForegroundColor( colorGroup().light() );
00302   mHeaderText->setPaletteBackgroundColor( colorGroup().dark() );
00303 
00304   mHeaderPixmap = new QLabel( mHeaderFrame );
00305   mHeaderPixmap->setSizePolicy( QSizePolicy::Maximum,
00306                                 QSizePolicy::Preferred );
00307   mHeaderPixmap->setAlignment( AlignRight|AlignVCenter );
00308   mHeaderPixmap->setPaletteBackgroundColor( colorGroup().dark() );
00309 
00310   connect( this, SIGNAL( textChanged( const QString& ) ),
00311            this, SLOT( setHeaderText( const QString& ) ) );
00312   connect( this, SIGNAL( iconChanged( const QPixmap& ) ),
00313            this, SLOT( setHeaderPixmap( const QPixmap& ) ) );
00314 
00315   QFont fnt( mSidePane->font() );
00316   fnt.setBold( true );
00317   fnt.setPointSize( mSidePane->font().pointSize() + 3 );
00318   mHeaderText->setFont( fnt );
00319 }
00320 
00321 bool MainWindow::isPluginLoaded( const KPluginInfo * info )
00322 {
00323   return ( pluginFromInfo( info ) != 0 );
00324 }
00325 
00326 Plugin *MainWindow::pluginFromInfo( const KPluginInfo *info )
00327 {
00328   PluginList::ConstIterator end = mPlugins.end();
00329   for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it )
00330     if ( ( *it )->identifier() == info->pluginName() )
00331       return *it;
00332 
00333   return 0;
00334 }
00335 
00336 void MainWindow::loadPlugins()
00337 {
00338   QPtrList<Plugin> plugins;
00339   QPtrList<KParts::Part> loadDelayed;
00340 
00341   uint i;
00342   KPluginInfo::List::ConstIterator it;
00343   for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) {
00344     if ( ! ( *it )->isPluginEnabled() )
00345       continue;
00346     if ( isPluginLoaded( *it ) ) {
00347       Plugin *plugin = pluginFromInfo( *it );
00348       if ( plugin )
00349         plugin->configUpdated();
00350       continue;
00351     }
00352 
00353     kdDebug(5600) << "Loading Plugin: " << ( *it )->name() << endl;
00354     Kontact::Plugin *plugin =
00355       KParts::ComponentFactory::createInstanceFromService<Kontact::Plugin>(
00356           ( *it )->service(), this );
00357 
00358     if ( !plugin )
00359       continue;
00360 
00361     plugin->setIdentifier( ( *it )->pluginName() );
00362     plugin->setTitle( ( *it )->name() );
00363     plugin->setIcon( ( *it )->icon() );
00364 
00365     QVariant libNameProp = ( *it )->property( "X-KDE-KontactPartLibraryName" );
00366     QVariant exeNameProp = ( *it )->property( "X-KDE-KontactPartExecutableName" );
00367     QVariant loadOnStart = ( *it )->property( "X-KDE-KontactPartLoadOnStart" );
00368 
00369     if ( !loadOnStart.isNull() && loadOnStart.toBool() )
00370       mDelayedPreload.append( plugin );
00371 
00372     kdDebug(5600) << "LIBNAMEPART: " << libNameProp.toString() << endl;
00373 
00374     plugin->setPartLibraryName( libNameProp.toString().utf8() );
00375     plugin->setExecutableName( exeNameProp.toString() );
00376 
00377     for ( i = 0; i < plugins.count(); ++i ) {
00378       Plugin *p = plugins.at( i );
00379       if ( plugin->weight() < p->weight() ) break;
00380     }
00381 
00382     plugins.insert( i, plugin );
00383   }
00384 
00385   for ( i = 0; i < plugins.count(); ++ i ) {
00386     Plugin *plugin = plugins.at( i );
00387 
00388     KAction *action;
00389     QPtrList<KAction> *actionList = plugin->newActions();
00390 
00391     for ( action = actionList->first(); action; action = actionList->next() ) {
00392       kdDebug(5600) << "Plugging " << action->name() << endl;
00393       action->plug( mNewActions->popupMenu() );
00394     }
00395 
00396     addPlugin( plugin );
00397   }
00398 
00399   mLastInfoExtension = 0;
00400 
00401   mNewActions->setEnabled( mPlugins.size() != 0 );
00402 }
00403 
00404 void MainWindow::unloadPlugins()
00405 {
00406   KPluginInfo::List::ConstIterator end = mPluginInfos.end();
00407   KPluginInfo::List::ConstIterator it;
00408   for ( it = mPluginInfos.begin(); it != end; ++it ) {
00409     if ( ! ( *it )->isPluginEnabled() )
00410       removePlugin( *it );
00411   }
00412 }
00413 
00414 bool MainWindow::removePlugin( const KPluginInfo * info )
00415 {
00416   PluginList::Iterator end = mPlugins.end();
00417   for ( PluginList::Iterator it = mPlugins.begin(); it != end; ++it )
00418     if ( ( *it )->identifier() == info->pluginName() ) {
00419       Plugin *plugin = *it;
00420 
00421       KAction *action;
00422       QPtrList<KAction> *actionList = plugin->newActions();
00423 
00424       for ( action = actionList->first(); action; action = actionList->next() ) {
00425         kdDebug(5600) << "Unplugging " << action->name() << endl;
00426         action->unplug( mNewActions->popupMenu() );
00427       }
00428 
00429       removeChildClient( plugin );
00430 
00431       if ( mCurrentPlugin == plugin )
00432         mCurrentPlugin = 0;
00433 
00434       delete plugin; // removes the part automatically
00435       mPlugins.remove( it );
00436 
00437       return true;
00438     }
00439 
00440   return false;
00441 }
00442 
00443 void MainWindow::addPlugin( Kontact::Plugin *plugin )
00444 {
00445   kdDebug(5600) << "Added plugin" << endl;
00446 
00447   mPlugins.append( plugin );
00448 
00449   // merge the plugins GUI into the main window
00450   insertChildClient( plugin );
00451 }
00452 
00453 void MainWindow::partLoaded( Kontact::Plugin * /*plugin*/, KParts::Part *part )
00454 {
00455   // See if we have this part already (e.g. due to two plugins sharing it)
00456   if ( mStack->id( part->widget() ) != -1 )
00457     return;
00458 
00459   mStack->addWidget( part->widget(), 0 );
00460 
00461   mPartManager->addPart( part, false );
00462   // Workaround for KParts misbehavior: addPart calls show!
00463   part->widget()->hide();
00464 }
00465 
00466 void MainWindow::slotActivePartChanged( KParts::Part *part )
00467 {
00468   if ( !part ) {
00469     createGUI( 0 );
00470     return;
00471   }
00472 
00473   if ( mLastInfoExtension ) {
00474     disconnect( mLastInfoExtension, SIGNAL( textChanged( const QString& ) ),
00475                 this, SLOT( setHeaderText( const QString& ) ) );
00476     disconnect( mLastInfoExtension, SIGNAL( iconChanged( const QPixmap& ) ),
00477                 this, SLOT( setHeaderPixmap( const QPixmap& ) ) );
00478   }
00479 
00480   kdDebug(5600) << "Part activated: " << part << " with stack id. "
00481       << mStack->id( part->widget() )<< endl;
00482   QObjectList *l = part->queryList( "KParts::InfoExtension" );
00483   KParts::InfoExtension *ie = 0;
00484   if ( l )
00485     ie = static_cast<KParts::InfoExtension*>( l->first() );
00486   delete l;
00487 
00488   if ( ie ) {
00489     connect( ie, SIGNAL( textChanged( const QString& ) ),
00490              SLOT( setHeaderText( const QString& ) ) );
00491     connect( ie, SIGNAL( iconChanged( const QPixmap& ) ),
00492              SLOT( setHeaderPixmap( const QPixmap& ) ) );
00493   }
00494 
00495   mLastInfoExtension = ie;
00496 
00497   InfoExtData data = mInfoExtCache[ ie ];
00498   setHeaderPixmap( data.pixmap );
00499   setHeaderText( data.text );
00500 
00501   createGUI( part );
00502 
00503   statusBar()->clear();
00504 }
00505 
00506 void MainWindow::slotNewClicked()
00507 {
00508   KAction *action = mCurrentPlugin->newActions()->first();
00509   if ( action ) {
00510     action->activate();
00511   } else {
00512     PluginList::Iterator it;
00513     for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
00514       action = (*it)->newActions()->first();
00515       if ( action ) {
00516         action->activate();
00517         return;
00518       }
00519     }
00520   }
00521 }
00522 
00523 void MainWindow::selectPlugin( Kontact::Plugin *plugin )
00524 {
00525   if ( !plugin )
00526     return;
00527 
00528   if ( plugin->isRunningStandalone() ) {
00529     statusBar()->message( i18n( "Application is running standalone. Foregrounding..." ), 1000 );
00530     plugin->bringToForeground();
00531     return;
00532   }
00533 
00534   KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
00535 
00536   if ( mSidePane )
00537     mSidePane->selectPlugin( plugin );
00538 
00539   KParts::Part *part = plugin->part();
00540 
00541   if ( !part ) {
00542     KMessageBox::error( this, i18n( "Cannot load part for %1." )
00543                               .arg( plugin->title() ) );
00544     KApplication::restoreOverrideCursor();
00545     return;
00546   }
00547 
00548   plugin->select();
00549 
00550   mPartManager->setActivePart( part );
00551   QWidget *view = part->widget();
00552   Q_ASSERT( view );
00553 
00554   if ( view ) {
00555     mStack->raiseWidget( view );
00556     view->show();
00557     view->setFocus();
00558     mCurrentPlugin = plugin;
00559     KAction *action = plugin->newActions()->first();
00560     setCaption( i18n( "Plugin dependent window title" ,"%1 - Kontact" ).arg( plugin->title() ) );
00561     if ( action ) {
00562       mNewActions->setIcon( action->icon() );
00563       mNewActions->setText( action->text() );
00564     } else { // we'll use the action of the first plugin which offers one
00565       PluginList::Iterator it;
00566       for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
00567         action = (*it)->newActions()->first();
00568         if ( action ) {
00569           mNewActions->setIcon( action->icon() );
00570           mNewActions->setText( action->text() );
00571           break;
00572         }
00573       }
00574     }
00575   }
00576 
00577   QStringList invisibleActions = plugin->invisibleToolbarActions();
00578 
00579   QStringList::ConstIterator it;
00580   for ( it = invisibleActions.begin(); it != invisibleActions.end(); ++it ) {
00581     KAction *action = part->actionCollection()->action( (*it).latin1() );
00582     if ( action )
00583       action->unplug( toolBar() );
00584   }
00585 
00586   KApplication::restoreOverrideCursor();
00587 }
00588 
00589 void MainWindow::selectPlugin( const QString &pluginName )
00590 {
00591   PluginList::ConstIterator end = mPlugins.end();
00592   for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it )
00593     if ( ( *it )->identifier() == pluginName ) {
00594       selectPlugin( *it );
00595       return;
00596     }
00597 }
00598 
00599 void MainWindow::loadSettings()
00600 {
00601   if ( mSplitter )
00602     mSplitter->setSizes( Prefs::self()->mSidePaneSplitter );
00603 
00604   // Preload Plugins. This _must_ happen before the default part is loaded
00605   PluginList::ConstIterator it;
00606   for ( it = mDelayedPreload.begin(); it != mDelayedPreload.end(); ++it )
00607     selectPlugin( *it );
00608 
00609   selectPlugin( Prefs::self()->mActivePlugin );
00610 }
00611 
00612 void MainWindow::saveSettings()
00613 {
00614   if ( mSplitter )
00615     Prefs::self()->mSidePaneSplitter = mSplitter->sizes();
00616 
00617   if ( mCurrentPlugin )
00618     Prefs::self()->mActivePlugin = mCurrentPlugin->identifier();
00619 }
00620 
00621 void MainWindow::slotShowTip()
00622 {
00623   showTip( true );
00624 }
00625 
00626 void MainWindow::slotRequestFeature()
00627 {
00628   if ( kapp )
00629     kapp->invokeBrowser( "http://kontact.org/shopping" );
00630 }
00631 
00632 void MainWindow::showTip(bool force)
00633 {
00634   QStringList tips;
00635   PluginList::ConstIterator end = mPlugins.end();
00636   for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) {
00637     QString file = ( *it )->tipFile();
00638     if ( !file.isEmpty() )
00639       tips.append( file );
00640   }
00641 
00642   KTipDialog::showMultiTip(this, tips, force);
00643 }
00644 
00645 void MainWindow::slotQuit()
00646 {
00647   mReallyClose=true;
00648   close();
00649 }
00650 
00651 void MainWindow::slotPreferences()
00652 {
00653   static KSettings::Dialog *dlg = 0;
00654   if( !dlg ) {
00655     dlg = new KSettings::Dialog( KSettings::Dialog::Configurable, this );
00656     dlg->addPluginInfos( mPluginInfos );
00657     dlg->dialog()->setInitialSize( QSize( 900, 600 ) );
00658     connect( dlg, SIGNAL( pluginSelectionChanged() ),
00659          SLOT( pluginsChanged() ) );
00660 //    connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) );
00661 //    connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) );
00662   }
00663 
00664   dlg->show();
00665 }
00666 
00667 void MainWindow::slotSelectComponents()
00668 {
00669   static KSettings::ComponentsDialog *dlg = 0;
00670   if ( !dlg ) {
00671     dlg = new KSettings::ComponentsDialog( this );
00672     dlg->setPluginInfos( mPluginInfos );
00673     connect( dlg, SIGNAL( okClicked() ), SLOT( pluginsChanged() ) );
00674     connect( dlg, SIGNAL( applyClicked() ), SLOT( pluginsChanged() ) );
00675   }
00676 
00677   dlg->show();
00678 }
00679 
00680 int MainWindow::startServiceFor( const QString& serviceType,
00681                                  const QString& constraint,
00682                                  const QString& preferences,
00683                                  QString *error, QCString* dcopService,
00684                                  int flags )
00685 {
00686   PluginList::ConstIterator end = mPlugins.end();
00687   for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) {
00688     if ( ( *it )->createDCOPInterface( serviceType ) ) {
00689       kdDebug(5600) << "found interface for " << serviceType << endl;
00690       if ( dcopService )
00691         *dcopService = ( *it )->dcopClient()->appId();
00692       kdDebug(5600) << "appId=" << ( *it )->dcopClient()->appId() << endl;
00693       return 0; // success
00694     }
00695   }
00696   kdDebug(5600) <<
00697     "Didn't find dcop interface, falling back to external process" << endl;
00698   return KDCOPServiceStarter::startServiceFor( serviceType, constraint,
00699       preferences, error, dcopService, flags );
00700 }
00701 
00702 void MainWindow::setHeaderText( const QString &text )
00703 {
00704   mInfoExtCache[ mLastInfoExtension ].text = text;
00705   mHeaderText->setText( text );
00706 }
00707 
00708 void MainWindow::setHeaderPixmap( const QPixmap &pixmap )
00709 {
00710   QPixmap pm( pixmap );
00711 
00712   if ( pm.height() > 22 || pm.width() > 22 ) {
00713     QImage img;
00714     img = pixmap;
00715     pm = img.smoothScale( 22, 22, QImage::ScaleMin );
00716   }
00717 
00718   mInfoExtCache[ mLastInfoExtension ].pixmap = pm;
00719   mHeaderPixmap->setPixmap( pm );
00720 }
00721 
00722 void MainWindow::pluginsChanged()
00723 {
00724   unloadPlugins();
00725   loadPlugins();
00726   mSidePane->updatePlugins();
00727 }
00728 
00729 void MainWindow::updateConfig()
00730 {
00731   kdDebug( 5600 ) << k_funcinfo << endl;
00732 
00733   saveSettings();
00734 
00735 #if 0
00736   bool sidePaneChanged = ( Prefs::self()->mSidePaneType != mSidePaneType );
00737 
00738   if ( sidePaneChanged ) {
00739     mSidePaneType = Prefs::self()->mSidePaneType;
00740 
00741     delete mSidePane;
00742 
00743     switch ( mSidePaneType ) {
00744       case Prefs::SidePaneIcons:
00745         mSidePane = new IconSidePane( this, mSplitter );
00746         mHeaderFrame->hide();
00747         break;
00748       default:
00749         kdError() << "Invalid SidePaneType: " << mSidePaneType << endl;
00750       case Prefs::SidePaneBars:
00751         mSidePane = new SidePane( this, mSplitter );
00752         mHeaderFrame->show();
00753         break;
00754     }
00755 
00756     mSplitter->setResizeMode( mSidePane, QSplitter::KeepSize );
00757 
00758     mSidePane->setSizePolicy( QSizePolicy( QSizePolicy::Maximum,
00759                                QSizePolicy::Preferred ) );
00760 
00761     connect( mSidePane, SIGNAL( pluginSelected( Kontact::Plugin * ) ),
00762              SLOT( selectPlugin( Kontact::Plugin * ) ) );
00763 
00764     mSplitter->moveToFirst( mSidePane );
00765 
00766     mSidePane->show();
00767   }
00768 
00769   if ( sidePaneChanged )
00770     mSidePane->updatePlugins();
00771 #endif
00772 
00773   loadSettings();
00774 }
00775 
00776 void MainWindow::showAboutDialog()
00777 {
00778   KApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
00779 
00780   if ( !mAboutDialog )
00781     mAboutDialog = new AboutDialog( this );
00782 
00783   mAboutDialog->show();
00784   mAboutDialog->raise();
00785   KApplication::restoreOverrideCursor();
00786 }
00787 
00788 void MainWindow::configureShortcuts()
00789 {
00790   KKeyDialog dialog( true, this );
00791   dialog.insert( actionCollection() );
00792 
00793   if ( mCurrentPlugin && mCurrentPlugin->part() )
00794     dialog.insert( mCurrentPlugin->part()->actionCollection() );
00795 
00796   dialog.configure();
00797 }
00798 
00799 void MainWindow::configureToolbars()
00800 {
00801   saveMainWindowSettings( KGlobal::config(), "MainWindow" );
00802 
00803   KEditToolbar edit( factory() );
00804   connect( &edit, SIGNAL( newToolbarConfig() ),
00805            this, SLOT( slotNewToolbarConfig() ) );
00806   edit.exec();
00807 }
00808 
00809 void MainWindow::slotNewToolbarConfig()
00810 {
00811   createGUI( mCurrentPlugin->part() );
00812   applyMainWindowSettings( KGlobal::config(), "MainWindow" );
00813 }
00814 
00815 bool MainWindow::queryClose()
00816 {
00817   if ( kapp->sessionSaving() || mReallyClose )
00818     return true;
00819 
00820   bool localClose = true;
00821   QValueList<Plugin*>::ConstIterator end = mPlugins.end();
00822   QValueList<Plugin*>::ConstIterator it = mPlugins.begin();
00823   for ( ; it != end; ++it ) {
00824     Plugin *plugin = *it;
00825     if ( !plugin->isRunningStandalone() )
00826       if ( !plugin->queryClose() )
00827         localClose = false;
00828   }
00829 
00830   return localClose;
00831 }
00832 
00833 
00834 void MainWindow::slotShowStatusMsg( const QString &msg )
00835 {
00836   if ( !statusBar() || !mStatusMsgLabel ) return;
00837   int statusWidth = mStatusMsgLabel->width() - fontMetrics().maxWidth();
00838   QString text = KStringHandler::rPixelSqueeze( " " + msg, fontMetrics(),
00839                                                 statusWidth );
00840   mStatusMsgLabel->setText( text );
00841 }
00842 #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 Wed Mar 23 22:46:48 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003