23 #include <config-enterprise.h>
30 using namespace Kontact;
38 #include <KontactInterface/Core>
39 #include <KontactInterface/Plugin>
41 #include <KPIMUtils/KFileIO>
43 #include <KActionCollection>
44 #include <KActionMenu>
45 #include <KApplication>
46 #include <KComponentData>
47 #include <KConfigGroup>
48 #include <KDBusServiceStarter>
50 #include <KEditToolBar>
53 #include <KMessageBox>
54 #include <KPluginInfo>
56 #include <KServiceTypeTrader>
57 #include <KShortcutsDialog>
58 #include <KSqueezedTextLabel>
59 #include <KStandardAction>
60 #include <KStandardDirs>
64 #include <KToolInvocation>
65 #include <KXMLGUIFactory>
66 #include <KParts/PartManager>
67 #include <KSettings/Dispatcher>
68 #include <KSettings/Dialog>
71 #include <QDBusConnection>
73 #include <QStackedWidget>
75 #include <QVBoxLayout>
76 #include <QWebSettings>
87 class ServiceStarter :
public KDBusServiceStarter
91 virtual int startServiceFor(
const QString &serviceType,
92 const QString &constraint = QString(),
93 QString *error = 0, QString *dbusService = 0,
100 mPlugins = pluginList;
103 static void setPluginList(
PluginList *pluginList ) {
104 mPlugins = pluginList;
109 virtual ~ServiceStarter() {}
115 int ServiceStarter::startServiceFor(
const QString &serviceType,
116 const QString &constraint,
117 QString *error, QString *dbusService,
121 PluginList::ConstIterator end = mPlugins->constEnd();
122 for ( PluginList::ConstIterator it = mPlugins->constBegin(); it != end; ++it ) {
123 if ( (*it)->createDBUSInterface( serviceType ) ) {
124 kDebug() <<
"found interface for" << serviceType;
126 *dbusService = (*it)->registerClient();
133 kDebug() <<
"Didn't find dbus interface, falling back to external process";
134 return KDBusServiceStarter::startServiceFor( serviceType, constraint,
135 error, dbusService, flags );
139 : KontactInterface::Core(), mSplitter( 0 ), mCurrentPlugin( 0 ), mAboutDialog( 0 ),
140 mReallyClose( false ), mSyncActionsEnabled( true )
144 new ServiceStarter( &mPlugins );
146 QDBusConnection::sessionBus().registerObject(
147 QLatin1String(
"/KontactInterface"),
this, QDBusConnection::ExportScriptableSlots );
151 setAttribute( Qt::WA_GroupLeader );
156 mSidePane->setMaximumWidth( mSidePane->sizeHint().width() );
157 mSidePane->setMinimumWidth( mSidePane->sizeHint().width() );
159 factory()->plugActionList(
this, QLatin1String(
"navigator_actionlist" ), mActionPlugins );
161 restoreWindowSize( KConfigGroup( KGlobal::config(),
"MainWindow" ) );
162 setAutoSaveSettings();
169 setHelpMenuEnabled(
false );
170 KHelpMenu *helpMenu =
new KHelpMenu(
this, 0,
true, actionCollection() );
171 connect( helpMenu, SIGNAL(showAboutApplication()), SLOT(
showAboutDialog()) );
173 KStandardAction::keyBindings(
this, SLOT(configureShortcuts()), actionCollection() );
174 KStandardAction::configureToolbars(
this, SLOT(configureToolbars()), actionCollection() );
175 setXMLFile( QLatin1String(
"kontactui.rc") );
177 setStandardToolBarMenuEnabled(
true );
181 KToolBar *navigatorToolBar = findToolBar(
"navigatorToolBar" );
182 if ( navigatorToolBar ) {
183 if ( layoutDirection() == Qt::LeftToRight ) {
184 navigatorToolBar->setLayoutDirection( Qt::RightToLeft );
186 navigatorToolBar->setLayoutDirection( Qt::LeftToRight );
188 Q_ASSERT( navigatorToolBar->sizeHint().isValid() );
189 navigatorToolBar->setMinimumWidth( navigatorToolBar->sizeHint().width() );
191 kError() <<
"Unable to find navigatorToolBar, probably kontactui.rc is missing";
195 void MainWindow::waitForKSycoca()
199 if ( KSycoca::isAvailable() ) {
208 kDebug() <<
"Waiting for KSycoca";
213 kFatal() <<
"KSycoca unavailable. Kontact will be unable to find plugins.";
218 if ( !KSycoca::isAvailable() ) {
221 KService::List offers = KServiceTypeTrader::self()->query(
222 QString::fromLatin1(
"Kontact/Plugin" ),
223 QString::fromLatin1(
"[X-KDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
224 mPluginInfos = KPluginInfo::fromServices(
225 offers, KConfigGroup(
Prefs::self()->config(),
"Plugins" ) );
227 KPluginInfo::List::Iterator it;
228 KPluginInfo::List::Iterator end( mPluginInfos.end() );
230 for ( it = mPluginInfos.begin(); it != end; ++it ) {
235 mPartManager =
new KParts::PartManager(
this );
236 connect( mPartManager, SIGNAL(activePartChanged(KParts::Part*)),
245 KSettings::Dispatcher::registerComponent( componentData(),
this,
"updateConfig" );
266 paintAboutScreen( introductionString() );
272 if ( mCurrentPlugin ) {
273 saveMainWindowSettings(
274 KGlobal::config()->group(
275 QString::fromLatin1(
"MainWindow%1" ).arg( mCurrentPlugin->identifier() ) ) );
279 ServiceStarter::setPluginList( 0 );
294 PluginList::ConstIterator end = mPlugins.constEnd();
295 for ( PluginList::ConstIterator it = mPlugins.constBegin(); it != end; ++it ) {
303 if (mInitialActiveModule != module) {
304 mInitialActiveModule = module;
315 right->data().value<KontactInterface::Plugin*>() );
319 const KontactInterface::Plugin *right )
321 return left->weight() < right->weight();
326 if ( !mInitialActiveModule.isEmpty() && !mPlugins.isEmpty() ) {
327 PluginList::ConstIterator end = mPlugins.constEnd();
328 for ( PluginList::ConstIterator it = mPlugins.constBegin(); it != end; ++it ) {
329 if ( !(*it)->identifier().isEmpty() &&
330 (*it)->identifier().contains( mInitialActiveModule ) ) {
338 void MainWindow::initWidgets()
341 QVBoxLayout *layout =
new QVBoxLayout;
342 layout->setMargin(0);
343 layout->setSpacing(0);
344 mTopWidget->setLayout( layout );
345 setCentralWidget( mTopWidget );
347 mSplitter =
new QSplitter( mTopWidget );
348 layout->addWidget( mSplitter );
357 connect( mSidePane, SIGNAL(pluginSelected(KontactInterface::Plugin*)),
360 mPartsStack =
new QStackedWidget( mSplitter );
361 mPartsStack->layout()->setSpacing( 0 );
365 const QString loading =
367 "<h2 style='text-align:center; margin-top: 0px; margin-bottom: 0px'>%1</h2>",
368 i18nc(
"@item:intext",
"Loading Kontact..." ) );
370 paintAboutScreen( loading );
374 progressDialog->hide();
379 new KSqueezedTextLabel( i18nc(
"@info:status",
" Initializing..." ), statusBar() );
380 mStatusMsgLabel->setTextElideMode( Qt::ElideRight );
381 mStatusMsgLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
383 statusBar()->addWidget( mStatusMsgLabel, 10 );
384 statusBar()->addPermanentWidget( mLittleProgress, 0 );
385 mLittleProgress->show();
387 mSplitter->setCollapsible( 1,
false );
390 void MainWindow::paintAboutScreen(
const QString &msg )
392 QString location = KStandardDirs::locate(
"data", QLatin1String(
"kontact/about/main.html") );
393 QString content = QLatin1String(KPIMUtils::kFileToByteArray( location ));
394 content = content.arg( QLatin1String(
"file:") + KStandardDirs::locate(
395 "data", QLatin1String(
"kdeui/about/kde_infopage.css") ) );
396 if ( QApplication::isRightToLeft() ) {
398 content.arg( QLatin1String(
"@import \"%1\";") ).
399 arg( QLatin1String(
"file:") + KStandardDirs::locate(
400 "data", QLatin1String(
"kdeui/about/kde_infopage_rtl.css") ) );
402 content = content.arg( QString() );
406 content.arg( QFont().pointSize() + 2 ).
407 arg( i18nc(
"@item:intext",
"KDE Kontact" ) ).
408 arg( i18nc(
"@item:intext",
"Get Organized!" ) ).
409 arg( i18nc(
"@item:intext",
"The KDE Personal Information Management Suite" ) ).
413 void MainWindow::initAboutScreen()
416 mPartsStack->addWidget( introbox );
417 mPartsStack->setCurrentWidget( introbox );
418 mIntroPart =
new KWebView( introbox );
419 mIntroPart->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
420 mIntroPart->setFocusPolicy( Qt::WheelFocus );
422 mIntroPart->settings()->setAttribute( QWebSettings::JavascriptEnabled,
false );
423 mIntroPart->settings()->setAttribute( QWebSettings::JavaEnabled,
false );
424 mIntroPart->settings()->setAttribute( QWebSettings::PluginsEnabled,
false );
426 connect( mIntroPart->page(), SIGNAL(linkClicked(QUrl)),
this,
430 void MainWindow::setupActions()
432 actionCollection()->addAction( KStandardAction::Quit,
this, SLOT(
slotQuit()) );
434 mNewActions =
new KActionMenu(
435 i18nc(
"@title:menu create new pim items (message,calendar,to-do,etc.)",
"New" ),
this );
436 actionCollection()->addAction( QLatin1String(
"action_new"), mNewActions );
437 mNewActions->setShortcut( KStandardShortcut::openNew() );
438 connect( mNewActions, SIGNAL(triggered(
bool)),
this, SLOT(
slotNewClicked()) );
443 KConfig _config( QLatin1String(
"kmail2rc") );
444 KConfigGroup config( &_config,
"Groupware" );
445 #if defined(KDEPIM_ENTERPRISE_BUILD)
446 bool defGW = config.readEntry(
"Enabled",
true );
448 bool defGW = config.readEntry(
"Enabled",
false );
451 KConfigGroup cfg( _cfg,
"Kontact Groupware Settings" );
452 mSyncActionsEnabled = cfg.readEntry(
"GroupwareMailFoldersEnabled", defGW );
454 if ( mSyncActionsEnabled ) {
455 mSyncActions =
new KActionMenu(
456 KIcon( QLatin1String(
"view-refresh") ),
457 i18nc(
"@title:menu synchronize pim items (message,calendar,to-do,etc.)",
"Sync" ),
this );
458 actionCollection()->addAction( QLatin1String(
"action_sync"), mSyncActions );
459 mSyncActions->setShortcut( KStandardShortcut::reload() );
460 connect( mSyncActions, SIGNAL(triggered(
bool)),
this, SLOT(
slotSyncClicked()) );
464 new KAction( KIcon( QLatin1String(
"configure") ),
465 i18nc(
"@action:inmenu",
"Configure Kontact..." ),
this );
467 i18nc(
"@info:status",
"Configure Kontact" ) );
468 action->setWhatsThis(
469 i18nc(
"@info:whatsthis",
470 "You will be presented with a dialog where you can configure Kontact." ) );
471 actionCollection()->addAction( QLatin1String(
"settings_configure_kontact"), action );
475 new KAction( KIcon( QLatin1String(
"kontact") ),
476 i18nc(
"@action:inmenu",
"&Kontact Introduction" ),
this );
478 i18nc(
"@info:status",
"Show the Kontact Introduction page" ) );
479 action->setWhatsThis(
480 i18nc(
"@info:whatsthis",
481 "Choose this option to see the Kontact Introduction page." ) );
482 actionCollection()->addAction( QLatin1String(
"help_introduction"), action );
486 new KAction( KIcon( QLatin1String(
"ktip") ),
487 i18nc(
"@action:inmenu",
"&Tip of the Day" ),
this );
489 i18nc(
"@info:status",
"Show the Tip-of-the-Day dialog" ) );
490 action->setWhatsThis(
491 i18nc(
"@info:whatsthis",
492 "You will be presented with a dialog showing small tips to help "
493 "you use this program more effectively." ) );
494 actionCollection()->addAction( QLatin1String(
"help_tipofday"), action );
495 connect( action, SIGNAL(triggered(
bool)), SLOT(
slotShowTip()) );
497 QShortcut *shortcut =
new QShortcut( QKeySequence(Qt::Key_F9),
this );
498 connect(shortcut, SIGNAL(activated()),
this, SLOT(slotShowHideSideBar()));
501 bool MainWindow::isPluginLoaded(
const KPluginInfo &info )
503 return ( pluginFromInfo( info ) != 0 );
506 KontactInterface::Plugin *MainWindow::pluginFromInfo(
const KPluginInfo &info )
508 PluginList::ConstIterator end = mPlugins.constEnd();
509 for ( PluginList::ConstIterator it = mPlugins.constBegin(); it != end; ++it ) {
510 if ( (*it)->identifier() == info.pluginName() ) {
517 void MainWindow::loadPlugins()
522 KPluginInfo::List::ConstIterator it;
523 KPluginInfo::List::ConstIterator end( mPluginInfos.constEnd() );
524 for ( it = mPluginInfos.constBegin(); it != end; ++it ) {
525 if ( !it->isPluginEnabled() ) {
529 KontactInterface::Plugin *plugin = 0;
530 if ( isPluginLoaded( *it ) ) {
531 plugin = pluginFromInfo( *it );
533 plugin->configUpdated();
538 kDebug() <<
"Loading Plugin:" << it->name();
541 it->service()->createInstance<KontactInterface::Plugin>(
this, QVariantList(), &error );
544 kDebug() <<
"Unable to create plugin for" << it->name() << error;
548 plugin->setIdentifier( it->pluginName() );
549 plugin->setTitle( it->name() );
550 plugin->setIcon( it->icon() );
552 QVariant libNameProp = it->property( QLatin1String(
"X-KDE-KontactPartLibraryName") );
553 QVariant exeNameProp = it->property( QLatin1String(
"X-KDE-KontactPartExecutableName") );
554 QVariant loadOnStart = it->property( QLatin1String(
"X-KDE-KontactPartLoadOnStart") );
555 QVariant hasPartProp = it->property( QLatin1String(
"X-KDE-KontactPluginHasPart") );
557 if ( !loadOnStart.isNull() && loadOnStart.toBool() ) {
558 mDelayedPreload.append( plugin );
561 kDebug() <<
"LIBNAMEPART:" << libNameProp.toString();
563 plugin->setPartLibraryName( libNameProp.toString().toUtf8() );
564 plugin->setExecutableName( exeNameProp.toString() );
565 if ( hasPartProp.isValid() ) {
566 plugin->setShowInSideBar( hasPartProp.toBool() );
569 for ( i = 0; i < plugins.count(); ++i ) {
570 KontactInterface::Plugin *p = plugins.at( i );
571 if ( plugin->weight() < p->weight() ) {
575 plugins.insert( i, plugin );
579 const int numberOfPlugins( plugins.count() );
580 for ( i = 0; i < numberOfPlugins; ++i ) {
581 KontactInterface::Plugin *plugin = plugins.at( i );
587 for ( listIt = actionList.begin(); listIt != end; ++listIt ) {
588 kDebug() << QLatin1String(
"Plugging New actions") << (*listIt)->objectName();
589 mNewActions->addAction( (*listIt) );
592 if ( mSyncActionsEnabled ) {
593 Q_FOREACH ( KAction *listIt, plugin->syncActions() ) {
594 kDebug() << QLatin1String(
"Plugging Sync actions") << listIt->objectName();
595 mSyncActions->addAction( listIt );
601 const bool state = ( !mPlugins.isEmpty() );
602 mNewActions->setEnabled( state );
603 if ( mSyncActionsEnabled ) {
604 mSyncActions->setEnabled( state );
608 void MainWindow::unloadPlugins()
610 KPluginInfo::List::ConstIterator end = mPluginInfos.constEnd();
611 KPluginInfo::List::ConstIterator it;
612 for ( it = mPluginInfos.constBegin(); it != end; ++it ) {
613 if ( !it->isPluginEnabled() ) {
619 void MainWindow::updateShortcuts()
621 ActionPluginList::ConstIterator end = mActionPlugins.constEnd();
622 ActionPluginList::ConstIterator it;
624 for ( it = mActionPlugins.constBegin(); it != end; ++it ) {
625 KAction *action =
static_cast<KAction*
>( *it );
626 const QString shortcut = QString::fromLatin1(
"Ctrl+%1" ).arg( mActionPlugins.count() - i );
627 action->setShortcut( KShortcut( shortcut ) );
630 factory()->plugActionList(
this, QLatin1String(
"navigator_actionlist" ), mActionPlugins );
633 bool MainWindow::removePlugin(
const KPluginInfo &info )
635 PluginList::Iterator end = mPlugins.end();
636 for ( PluginList::Iterator it = mPlugins.begin(); it != end; ++it ) {
637 KontactInterface::Plugin *plugin = *it;
638 if ( ( *it )->identifier() == info.pluginName() ) {
642 for ( listIt = actionList.constBegin(); listIt != listEnd; ++listIt ) {
643 kDebug() << QLatin1String(
"Unplugging New actions") << (*listIt)->objectName();
644 mNewActions->removeAction( *listIt );
647 if ( mSyncActionsEnabled ) {
648 actionList = plugin->syncActions();
649 for ( listIt = actionList.constBegin(); listIt != actionList.constEnd(); ++listIt ) {
650 kDebug() << QLatin1String(
"Unplugging Sync actions") << (*listIt)->objectName();
651 mSyncActions->removeAction( *listIt );
654 removeChildClient( plugin );
656 if ( mCurrentPlugin == plugin ) {
661 plugin->deleteLater();
662 mPlugins.erase( it );
663 if ( plugin->showInSideBar() ) {
664 QAction *q = mPluginAction[plugin];
665 mActionPlugins.removeAll( q );
666 mPluginAction.remove(plugin);
670 if ( mCurrentPlugin == 0 ) {
671 PluginList::Iterator it;
672 PluginList::Iterator pluginEnd( mPlugins.end() );
673 for ( it = mPlugins.begin(); it != pluginEnd; ++it ) {
674 if ( (*it)->showInSideBar() ) {
688 void MainWindow::addPlugin( KontactInterface::Plugin *plugin )
692 mPlugins.append( plugin );
694 if ( plugin->showInSideBar() ) {
695 KAction *action =
new KAction( KIcon( plugin->icon() ), plugin->title(), this );
697 i18nc(
"@info:status",
"Plugin %1", plugin->title() ) );
698 action->setWhatsThis(
699 i18nc(
"@info:whatsthis",
700 "Switch to plugin %1", plugin->title() ) );
701 action->setCheckable(
true );
702 action->setData( QVariant::fromValue( plugin ) );
705 actionCollection()->addAction( plugin->title(), action );
706 mActionPlugins.append( action );
707 mPluginAction.insert( plugin, action );
711 insertChildClient( plugin );
718 foreach ( QAction *qaction, mActionPlugins ) {
719 KAction *action =
static_cast<KAction*
>( qaction );
720 QString shortcut = QString::fromLatin1(
"Ctrl+%1" ).arg( mActionPlugins.count() - i );
721 action->setShortcut( KShortcut( shortcut ) );
726 void MainWindow::partLoaded( KontactInterface::Plugin *plugin, KParts::ReadOnlyPart *part )
731 if ( mPartsStack->indexOf( part->widget() ) != -1 ) {
735 mPartsStack->addWidget( part->widget() );
737 mPartManager->addPart( part,
false );
739 part->widget()->hide();
749 kDebug() << QLatin1String(
"Part activated:") << part
750 << QLatin1String(
"with stack id.")<< mPartsStack->indexOf( part->widget() );
752 statusBar()->clearMessage();
757 if ( !mCurrentPlugin->newActions().isEmpty() ) {
758 mCurrentPlugin->newActions().first()->trigger();
760 PluginList::Iterator it;
761 PluginList::Iterator end( mPlugins.end() );
762 for ( it = mPlugins.begin(); it != end; ++it ) {
763 if ( !(*it)->newActions().isEmpty() ) {
764 (*it)->newActions().first()->trigger();
773 if ( !mCurrentPlugin->syncActions().isEmpty() ) {
774 mCurrentPlugin->syncActions().first()->trigger();
776 PluginList::Iterator it;
777 PluginList::Iterator end( mPlugins.end() );
778 for ( it = mPlugins.begin(); it != end; ++it ) {
779 if ( !(*it)->syncActions().isEmpty() ) {
780 (*it)->syncActions().first()->trigger();
787 KToolBar *MainWindow::findToolBar(
const char *name )
790 return findChild<KToolBar *>( QLatin1String(name) );
799 if ( plugin->isRunningStandalone() ) {
800 statusBar()->showMessage(
801 i18nc(
"@info:status",
802 "Application is running standalone. Foregrounding..." ), 1000 );
803 plugin->bringToForeground();
807 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
809 if ( mCurrentPlugin ) {
810 saveMainWindowSettings(
811 KGlobal::config()->group(
812 QString::fromLatin1(
"MainWindow%1" ).arg( mCurrentPlugin->identifier() ) ) );
815 KParts::Part *part = plugin->part();
818 QApplication::restoreOverrideCursor();
822 "Cannot load part for %1.",
823 plugin->title() ) + QLatin1Char(
'\n') + lastErrorMessage() );
824 plugin->setDisabled(
true );
829 if ( mCurrentPlugin ) {
830 KAction *action = mPluginAction[ mCurrentPlugin ];
832 action->setChecked(
false );
835 KAction *selectedPluginAction = mPluginAction[ plugin ];
836 if ( selectedPluginAction ) {
837 selectedPluginAction->setChecked(
true );
841 QWidget *focusWidget = kapp->focusWidget();
842 if ( mCurrentPlugin && focusWidget ) {
844 QWidget *parent = focusWidget->parentWidget();
846 if ( parent == mCurrentPlugin->part()->widget() ) {
847 mFocusWidgets.insert( mCurrentPlugin->identifier(), QPointer<QWidget>( focusWidget ) );
849 parent = parent->parentWidget();
857 plugin->aboutToSelect();
859 mPartManager->setActivePart( part );
860 QWidget *view = part->widget();
864 mPartsStack->setCurrentWidget( view );
867 if ( !mFocusWidgets.isEmpty() && mFocusWidgets.contains( plugin->identifier() ) ) {
868 focusWidget = mFocusWidgets[ plugin->identifier() ];
870 focusWidget->setFocus();
876 mCurrentPlugin = plugin;
878 QAction *newAction = 0;
879 if ( !plugin->newActions().isEmpty() ) {
880 newAction = plugin->newActions().first();
883 QAction *syncAction = 0;
884 if ( !plugin->syncActions().isEmpty() ) {
885 syncAction = plugin->syncActions().first();
888 createGUI( plugin->part() );
890 setCaption( i18nc(
"@title:window Plugin dependent window title",
891 "%1 - Kontact", plugin->title() ) );
894 mNewActions->setIcon( newAction->icon() );
895 static_cast<QAction*
>( mNewActions )->setText( newAction->text() );
896 mNewActions->setWhatsThis( newAction->whatsThis() );
898 PluginList::Iterator it;
899 PluginList::Iterator end(mPlugins.end());
900 for ( it = mPlugins.begin(); it != end; ++it ) {
901 if ( !(*it)->newActions().isEmpty() ) {
902 newAction = (*it)->newActions().first();
905 static_cast<QAction*
>( mNewActions )->setIcon( newAction->icon() );
906 mNewActions->setText( newAction->text() );
907 mNewActions->setWhatsThis( newAction->whatsThis() );
913 if ( mSyncActionsEnabled ) {
915 mSyncActions->setIcon( syncAction->icon() );
916 static_cast<QAction*
>( mSyncActions )->setText( syncAction->text() );
918 PluginList::Iterator it;
919 PluginList::Iterator end(mPlugins.end());
920 for ( it = mPlugins.begin(); it != end; ++it ) {
921 if ( !(*it)->syncActions().isEmpty() ) {
922 syncAction = (*it)->syncActions().first();
925 static_cast<QAction*
>( mSyncActions )->setIcon( syncAction->icon() );
926 mSyncActions->setText( syncAction->text() );
934 KToolBar *navigatorToolBar = findToolBar(
"navigatorToolBar" );
935 if ( navigatorToolBar && !navigatorToolBar->isHidden() &&
936 ( toolBarArea( navigatorToolBar ) == Qt::TopToolBarArea ||
937 toolBarArea( navigatorToolBar ) == Qt::BottomToolBarArea ) ) {
938 addToolBar( toolBarArea( navigatorToolBar ), navigatorToolBar );
941 applyMainWindowSettings( KGlobal::config()->group(
942 QString::fromLatin1(
"MainWindow%1" ).arg( plugin->identifier() ) ) );
944 QApplication::restoreOverrideCursor();
949 KAction *actionSender =
static_cast<KAction*
>( sender() );
950 actionSender->setChecked(
true );
951 KontactInterface::Plugin *plugin = actionSender->data().value<KontactInterface::Plugin*>();
960 PluginList::ConstIterator end = mPlugins.constEnd();
961 for ( PluginList::ConstIterator it = mPlugins.constBegin(); it != end; ++it ) {
962 if ( ( *it )->identifier() == pluginName ) {
969 void MainWindow::loadSettings()
975 if ( sizes.count() == mSplitter->count() ) {
976 mSplitter->setSizes( sizes );
981 PluginList::ConstIterator it;
982 PluginList::ConstIterator end( mDelayedPreload.constEnd() );
983 for ( it = mDelayedPreload.constBegin(); it != end; ++it ) {
989 void MainWindow::saveSettings()
995 if ( mCurrentPlugin ) {
1012 mPartsStack->setCurrentIndex( 0 );
1015 void MainWindow::showTip(
bool force )
1018 PluginList::ConstIterator end = mPlugins.constEnd();
1019 for ( PluginList::ConstIterator it = mPlugins.constBegin(); it != end; ++it ) {
1020 const QString file = (*it)->tipFile();
1021 if ( !file.isEmpty() ) {
1022 tips.append( file );
1026 KTipDialog::showMultiTip(
this, tips, force );
1031 mReallyClose =
true;
1040 dlg->setAllowComponentSelection(
true );
1043 KPluginInfo::List filteredPlugins = mPluginInfos;
1044 PluginList::ConstIterator it;
1045 PluginList::ConstIterator end(mPlugins.constEnd());
1046 for ( it = mPlugins.constBegin(); it != end; ++it ) {
1047 if ( (*it)->isRunningStandalone() ) {
1048 KPluginInfo::List::ConstIterator infoIt;
1049 KPluginInfo::List::ConstIterator infoEnd(filteredPlugins.constEnd());
1050 for ( infoIt = filteredPlugins.constBegin();
1051 infoIt != infoEnd; ++infoIt ) {
1052 if ( infoIt->pluginName() == (*it)->identifier() ) {
1053 filteredPlugins.removeAll( *infoIt );
1060 dlg->setHelp( QLatin1String(
"main-config"), QLatin1String(
"kontact") );
1061 dlg->addPluginInfos( filteredPlugins );
1062 connect( dlg, SIGNAL(pluginSelectionChanged()), SLOT(pluginsChanged()) );
1068 void MainWindow::pluginsChanged()
1070 unplugActionList( QLatin1String(
"navigator_actionlist") );
1087 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1089 if ( !mAboutDialog ) {
1093 mAboutDialog->show();
1094 mAboutDialog->raise();
1095 QApplication::restoreOverrideCursor();
1098 void MainWindow::configureShortcuts()
1100 KShortcutsDialog dialog(
1101 KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed,
this );
1102 dialog.addCollection( actionCollection() );
1104 if ( mCurrentPlugin && mCurrentPlugin->part() ) {
1105 dialog.addCollection( mCurrentPlugin->part()->actionCollection() );
1111 void MainWindow::configureToolbars()
1113 if ( mCurrentPlugin ) {
1114 saveMainWindowSettings(
1115 KGlobal::config()->group(
1116 QString::fromLatin1(
"MainWindow%1" ).arg( mCurrentPlugin->identifier() ) ) );
1118 QPointer<KEditToolBar> edit =
new KEditToolBar( factory() );
1126 if ( mCurrentPlugin && mCurrentPlugin->part() ) {
1127 createGUI( mCurrentPlugin->part() );
1129 if ( mCurrentPlugin ) {
1130 applyMainWindowSettings(
1131 KGlobal::config()->group(
1132 QString::fromLatin1(
"MainWindow%1" ).arg( mCurrentPlugin->identifier() ) ) );
1144 if ( url.protocol() == QLatin1String(
"exec" ) ) {
1145 const QString path( url.path() );
1146 if ( path == QLatin1String(
"/switch" ) ) {
1147 if ( mCurrentPlugin ) {
1148 mPartsStack->setCurrentIndex( mPartsStack->indexOf( mCurrentPlugin->part()->widget() ) );
1151 else if ( path == QLatin1String(
"/accountwizard" ) ) {
1152 KRun::runCommand( QLatin1String(
"accountwizard" ),
this );
1155 else if ( path.startsWith( QLatin1String(
"/help" ) ) ) {
1156 QString app( QLatin1String(
"kontact") );
1157 if ( !url.query().isEmpty() ) {
1158 app = url.query().mid( 1 );
1160 KToolInvocation::invokeHelp( QString(), app );
1163 new KRun( url,
this );
1167 void MainWindow::readProperties(
const KConfigGroup &config )
1169 Core::readProperties( config );
1171 QSet<QString> activePlugins =
1172 QSet<QString>::fromList( config.readEntry(
"ActivePlugins", QStringList() ) );
1174 if ( !activePlugins.isEmpty() ) {
1175 foreach ( KontactInterface::Plugin *plugin, mPlugins ) {
1176 if ( !plugin->isRunningStandalone() && activePlugins.contains( plugin->identifier() ) ) {
1177 plugin->readProperties( config );
1183 void MainWindow::saveProperties( KConfigGroup &config )
1185 Core::saveProperties( config );
1187 QStringList activePlugins;
1189 foreach (
const KPluginInfo &pluginInfo, mPluginInfos ) {
1190 if ( pluginInfo.isPluginEnabled() ) {
1191 KontactInterface::Plugin *plugin = pluginFromInfo( pluginInfo );
1193 activePlugins.append( plugin->identifier() );
1194 plugin->saveProperties( config );
1199 config.writeEntry(
"ActivePlugins", activePlugins );
1202 bool MainWindow::queryClose()
1204 if ( kapp->sessionSaving() || mReallyClose ) {
1208 foreach ( KontactInterface::Plugin *plugin, mPlugins ) {
1209 if ( !plugin->isRunningStandalone() ) {
1210 if ( !plugin->queryClose() ) {
1220 if ( !statusBar() || !mStatusMsgLabel ) {
1224 mStatusMsgLabel->setText( msg );
1227 QString MainWindow::introductionString()
1229 KIconLoader *iconloader = KIconLoader::global();
1230 const int iconSize = iconloader->currentSize( KIconLoader::Desktop );
1232 const QString handbook_icon_path = iconloader->iconPath( QLatin1String(
"help-contents"), KIconLoader::Desktop );
1233 const QString html_icon_path = iconloader->iconPath( QLatin1String(
"kontact"), KIconLoader::Desktop );
1234 const QString wizard_icon_path = iconloader->iconPath( QLatin1String(
"tools-wizard"), KIconLoader::Desktop );
1239 "<h2 style='text-align:center; margin-top: 0px;'>Welcome to Kontact %1</h2>"
1240 "<p align=\"center\">%2</p>"
1241 "<table align=\"center\">"
1242 "<tr><td><a href=\"%3\"><img width=\"%4\" height=\"%5\" src=\"%6\" /></a></td>"
1243 "<td><a href=\"%7\">%8</a><br /><span id=\"subtext\"><nobr>%9</nobr></span></td></tr>"
1244 "<tr><td><a href=\"%10\"><img width=\"%11\" height=\"%12\" src=\"%13\" /></a></td>"
1245 "<td><a href=\"%14\">%15</a><br /><span id=\"subtext\"><nobr>%16</nobr></span></td></tr>"
1246 "<tr><td><a href=\"%17\"><img width=\"%18\" height=\"%19\" src=\"%20\" /></a></td>"
1247 "<td><a href=\"%21\">%22</a><br /><span id=\"subtext\"><nobr>%23</nobr></span></td></tr>"
1249 "<p style=\"margin-bottom: 0px\"> <a href=\"%24\">Skip this introduction</a></p>" ).
1250 subs( KGlobal::mainComponent().aboutData()->
version() ).
1251 subs( i18nc(
"@item:intext",
1252 "Kontact handles your e-mail, address book, calendar, to-do list and more." ) ).
1253 subs( QLatin1String(
"exec:/help?kontact") ).
1256 subs( QLatin1String(
"file:") + handbook_icon_path ).
1257 subs( QLatin1String(
"exec:/help?kontact") ).
1258 subs( i18nc(
"@item:intext",
"Read Manual" ) ).
1259 subs( i18nc(
"@item:intext",
"Learn more about Kontact and its components" ) ).
1260 subs( QLatin1String(
"http://kontact.org") ).
1263 subs( QLatin1String(
"file:") + html_icon_path ).
1264 subs( QLatin1String(
"http://kontact.org") ).
1265 subs( i18nc(
"@item:intext",
"Visit Kontact Website" ) ).
1266 subs( i18nc(
"@item:intext",
"Access online resources and tutorials" ) ).
1267 subs( QLatin1String(
"exec:/accountwizard") ).
1270 subs( QLatin1String(
"file:") + wizard_icon_path ).
1271 subs( QLatin1String(
"exec:/accountwizard") ).
1272 subs( i18nc(
"@item:intext",
"Setup your Accounts" ) ).
1273 subs( i18nc(
"@item:intext",
"Prepare Kontact for use" ) ).
1274 subs( QLatin1String(
"exec:/switch") ).
1279 void MainWindow::slotShowHideSideBar()
1282 if (!sizes.isEmpty()) {
1283 if (sizes.at(0) != 0) {
1288 mSplitter->setSizes(sizes);
1292 #include "mainwindow.moc"
static bool pluginActionWeightLessThan(const QAction *left, const QAction *right)
void slotOpenUrl(const KUrl &url)
virtual void setCurrentPlugin(const QString &)=0
static BroadcastStatus * instance()
void slotActivePartChanged(KParts::Part *part)
void slotShowStatusMsg(const QString &)
void setInitialActivePluginModule(const QString &)
void slotNewToolbarConfig()
QList< int > mSidePaneSplitter
static void setLastVersionSeen(const QString &v)
Set LastVersionSeen.
void slotShowTipOnStart()
static const int KSYCOCA_WAIT_TIMEOUT
virtual void selectPlugin(KontactInterface::Plugin *plugin)
void activateInitialPluginModule()
static bool pluginWeightLessThan(const KontactInterface::Plugin *left, const KontactInterface::Plugin *right)
static QString lastVersionSeen()
Get LastVersionSeen.
virtual void updatePlugins()=0
This method is called by the core whenever the count of plugins has changed.
void slotShowIntroduction()
void slotActionTriggered()
static const char version[]
static QList< int > sidePaneSplitter()
Get SidePaneSplitter.