24 #include <tqcombobox.h>
25 #include <tqdockarea.h>
26 #include <tqguardedptr.h>
29 #include <tqobjectlist.h>
30 #include <tqprogressbar.h>
31 #include <tqpushbutton.h>
32 #include <tqsplitter.h>
34 #include <tqwhatsthis.h>
36 #include <dcopclient.h>
37 #include <tdeapplication.h>
38 #include <tdeconfig.h>
40 #include <kedittoolbar.h>
42 #include <khelpmenu.h>
43 #include <kiconloader.h>
44 #include <kkeydialog.h>
45 #include <klibloader.h>
46 #include <tdelistbox.h>
47 #include <tdelocale.h>
48 #include <tdemessagebox.h>
49 #include <tdeparts/componentfactory.h>
50 #include <kplugininfo.h>
51 #include <tdepopupmenu.h>
52 #include <ksettings/dialog.h>
53 #include <ksettings/dispatcher.h>
54 #include <tdeshortcut.h>
55 #include <kstandarddirs.h>
56 #include <kstatusbar.h>
57 #include <kstdaction.h>
60 #include <ksettings/componentsdialog.h>
61 #include <kstringhandler.h>
62 #include <krsqueezedtextlabel.h>
63 #include <tdehtml_part.h>
64 #include <tdehtmlview.h>
65 #include <libtdepim/tdefileio.h>
68 #include <tdeaboutdata.h>
69 #include <tdemenubar.h>
70 #include <tdestdaccel.h>
71 #include <kcmultidialog.h>
74 #include "aboutdialog.h"
75 #include "iconsidepane.h"
76 #include "mainwindow.h"
79 #include "profiledialog.h"
80 #include "profilemanager.h"
81 #include "progressdialog.h"
82 #include "statusbarprogresswidget.h"
83 #include "broadcaststatus.h"
85 using namespace Kontact;
87 class SettingsDialogWrapper :
public KSettings::Dialog
90 SettingsDialogWrapper( ContentInListView content, TQWidget * parent = 0 )
91 : KSettings::Dialog( content, parent, 0 )
96 void fixButtonLabel( TQWidget *widget )
98 TQObject *
object = widget->child(
"KJanusWidget::buttonBelowList" );
99 TQPushButton *button =
static_cast<TQPushButton*
>( object );
101 button->setText( i18n(
"Select Components ..." ) );
105 MainWindow::MainWindow()
106 : Kontact::
Core(), mTopWidget( 0 ), mSplitter( 0 ),
107 mCurrentPlugin( 0 ), mAboutDialog( 0 ), mReallyClose( false ), mSyncActionsEnabled( true )
111 setWFlags( getWFlags() | WGroupLeader );
117 void MainWindow::initGUI()
121 setHelpMenuEnabled(
false );
122 KHelpMenu *helpMenu =
new KHelpMenu(
this, 0,
true, actionCollection() );
123 connect( helpMenu, TQ_SIGNAL( showAboutApplication() ),
124 TQ_SLOT( showAboutDialog() ) );
126 TDETrader::OfferList offers = TDETrader::self()->query(
127 TQString::fromLatin1(
"Kontact/Plugin" ),
128 TQString(
"[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );
129 mPluginInfos = KPluginInfo::fromServices( offers, Prefs::self()->config(),
"Plugins" );
131 KPluginInfo::List::Iterator it;
132 for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) {
135 TDEAction *action =
new TDEAction( (*it)->name(), (*it)->icon(), TDEShortcut(),
136 this, TQ_SLOT(slotActionTriggered()),
137 actionCollection(), (*it)->pluginName().latin1() );
138 action->setName( (*it)->pluginName().latin1() );
139 action->setWhatsThis( i18n(
"Switch to plugin %1" ).arg( (*it)->name() ) );
141 TQVariant hasPartProp = (*it)->property(
"X-TDE-KontactPluginHasPart" );
142 if ( !hasPartProp.isValid() || hasPartProp.toBool() ) {
143 mActionPlugins.append( action );
147 KStdAction::keyBindings(
this, TQ_SLOT( configureShortcuts() ), actionCollection() );
148 KStdAction::configureToolbars(
this, TQ_SLOT( configureToolbars() ), actionCollection() );
149 setXMLFile(
"kontactui.rc" );
151 setStandardToolBarMenuEnabled(
true );
158 setAutoSaveSettings();
160 connect( Kontact::ProfileManager::self(), TQ_SIGNAL( profileLoaded(
const TQString& ) ),
161 this, TQ_SLOT( slotLoadProfile(
const TQString& ) ) );
162 connect( Kontact::ProfileManager::self(), TQ_SIGNAL( saveToProfileRequested(
const TQString& ) ),
163 this, TQ_SLOT( slotSaveToProfile(
const TQString& ) ) );
167 void MainWindow::initObject()
170 mPartManager =
new KParts::PartManager(
this );
171 connect( mPartManager, TQ_SIGNAL( activePartChanged( KParts::Part* ) ),
172 this, TQ_SLOT( slotActivePartChanged( KParts::Part* ) ) );
175 mSidePane->updatePlugins();
178 KSettings::Dispatcher::self()->registerInstance( instance(),
this,
179 TQ_SLOT( updateConfig() ) );
188 slotShowStatusMsg( TQString() );
190 connect( KPIM::BroadcastStatus::instance(), TQ_SIGNAL( statusMsg(
const TQString& ) ),
191 this, TQ_SLOT( slotShowStatusMsg(
const TQString& ) ) );
194 activatePluginModule();
196 if ( Prefs::lastVersionSeen() == kapp->aboutData()->version() ) {
197 selectPlugin( mCurrentPlugin );
200 paintAboutScreen( introductionString() );
201 Prefs::setLastVersionSeen( kapp->aboutData()->version() );
204 MainWindow::~MainWindow()
208 TQPtrList<KParts::Part> parts = *mPartManager->parts();
210 for ( KParts::Part *p = parts.last(); p; p = parts.prev() ) {
215 Prefs::self()->writeConfig();
218 void MainWindow::setActivePluginModule(
const TQString &module )
220 mActiveModule = module;
221 activatePluginModule();
224 void MainWindow::activatePluginModule()
226 if ( !mActiveModule.isEmpty() ) {
227 PluginList::ConstIterator end = mPlugins.end();
228 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it )
229 if ( ( *it )->identifier().contains( mActiveModule ) ) {
236 void MainWindow::initWidgets()
239 mTopWidget =
new TQHBox(
this );
240 mTopWidget->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
241 setCentralWidget( mTopWidget );
244 mSplitter =
new TQSplitter( mTopWidget );
245 mBox =
new TQHBox( mTopWidget );
246 mSidePane =
new IconSidePane(
this, mSplitter );
247 mSidePane->setSizePolicy( TQSizePolicy( TQSizePolicy::Maximum,
248 TQSizePolicy::Preferred ) );
250 TQValueList<int> sizes;
252 mSplitter->setSizes(sizes);
259 vBox =
new TQVBox( mSplitter );
261 vBox =
new TQVBox( mBox );
264 vBox->setSpacing( 0 );
266 mPartsStack =
new TQWidgetStack( vBox );
269 TQString loading = i18n(
"<h2 style='text-align:center; margin-top: 0px; margin-bottom: 0px'>%1</h2>" )
270 .arg( i18n(
"Loading Kontact...") );
272 paintAboutScreen( loading );
275 KPIM::ProgressDialog *progressDialog =
new KPIM::ProgressDialog( statusBar(),
this );
276 progressDialog->hide();
278 mLittleProgress =
new KPIM::StatusbarProgressWidget( progressDialog, statusBar() );
280 mStatusMsgLabel =
new KRSqueezedTextLabel( i18n(
" Initializing..." ), statusBar() );
281 mStatusMsgLabel->setAlignment( AlignLeft | AlignVCenter );
283 statusBar()->addWidget( mStatusMsgLabel, 10 ,
false );
284 statusBar()->addWidget( mLittleProgress, 0 ,
true );
285 mLittleProgress->show();
289 void MainWindow::paintAboutScreen(
const TQString& msg )
291 TQString location = locate(
"data",
"kontact/about/main.html" );
292 TQString content = KPIM::kFileToString( location );
293 content = content.arg( locate(
"data",
"libtdepim/about/kde_infopage.css" ) );
294 if ( kapp->reverseLayout() )
295 content = content.arg(
"@import \"%1\";" ).arg( locate(
"data",
"libtdepim/about/kde_infopage_rtl.css" ) );
297 content = content.arg(
"" );
299 mIntroPart->begin( KURL( location ) );
301 TQString appName( i18n(
"TDE Kontact" ) );
302 TQString catchPhrase( i18n(
"Get Organized!" ) );
303 TQString quickDescription( i18n(
"The TDE Personal Information Management Suite" ) );
305 mIntroPart->write( content.arg( TQFont().pointSize() + 2 ).arg( appName )
306 .arg( catchPhrase ).arg( quickDescription ).arg( msg ) );
310 void MainWindow::initAboutScreen()
312 TQHBox *introbox =
new TQHBox( mPartsStack );
313 mPartsStack->addWidget( introbox );
314 mPartsStack->raiseWidget( introbox );
315 mIntroPart =
new TDEHTMLPart( introbox );
316 mIntroPart->widget()->setFocusPolicy( TQWidget::WheelFocus );
318 mIntroPart->setPluginsEnabled(
false );
319 mIntroPart->setJScriptEnabled(
false );
320 mIntroPart->setJavaEnabled(
false );
321 mIntroPart->setMetaRefreshEnabled(
false );
322 mIntroPart->setURLCursor( KCursor::handCursor() );
323 mIntroPart->view()->setLineWidth( 0 );
325 connect( mIntroPart->browserExtension(),
326 TQ_SIGNAL( openURLRequest(
const KURL&,
const KParts::URLArgs& ) ),
327 TQ_SLOT( slotOpenUrl(
const KURL& ) ) );
329 connect( mIntroPart->browserExtension(),
330 TQ_SIGNAL( createNewWindow(
const KURL&,
const KParts::URLArgs& ) ),
331 TQ_SLOT( slotOpenUrl(
const KURL& ) ) );
334 void MainWindow::setupActions()
336 KStdAction::quit(
this, TQ_SLOT( slotQuit() ), actionCollection() );
337 mNewActions =
new TDEToolBarPopupAction( KGuiItem( i18n(
"New" ),
"" ),
338 TDEStdAccel::shortcut(TDEStdAccel::New),
this, TQ_SLOT( slotNewClicked() ),
339 actionCollection(),
"action_new" );
341 TDEConfig*
const cfg = Prefs::self()->config();
342 cfg->setGroup(
"Kontact Groupware Settings" );
343 mSyncActionsEnabled = cfg->readBoolEntry(
"GroupwareMailFoldersEnabled",
true );
345 if ( mSyncActionsEnabled ) {
346 mSyncActions =
new TDEToolBarPopupAction( KGuiItem( i18n(
"Synchronize" ),
"kitchensync" ),
347 TDEStdAccel::shortcut(TDEStdAccel::Reload),
this, TQ_SLOT( slotSyncClicked() ),
348 actionCollection(),
"action_sync" );
350 new TDEAction( i18n(
"Configure Kontact..." ),
"configure", 0,
this, TQ_SLOT( slotPreferences() ),
351 actionCollection(),
"settings_configure_kontact" );
353 new TDEAction( i18n(
"Configure &Profiles..." ), 0,
this, TQ_SLOT( slotConfigureProfiles() ),
354 actionCollection(),
"settings_configure_kontact_profiles" );
356 new TDEAction( i18n(
"&Kontact Introduction" ), 0,
this, TQ_SLOT( slotShowIntroduction() ),
357 actionCollection(),
"help_introduction" );
358 new TDEAction( i18n(
"&Tip of the Day" ), 0,
this, TQ_SLOT( slotShowTip() ),
359 actionCollection(),
"help_tipofday" );
361 KWidgetAction* spacerAction =
new KWidgetAction(
new TQWidget(
this ),
"SpacerAction",
"", 0, 0, actionCollection(),
"navigator_spacer_item" );
362 spacerAction->setAutoSized(
true );
365 void MainWindow::slotConfigureProfiles()
367 TQGuardedPtr<Kontact::ProfileDialog> dlg =
new Kontact::ProfileDialog(
this );
368 dlg->setModal(
true );
374 void copyConfigEntry( TDEConfig* source, TDEConfig* dest,
const TQString& group,
const TQString& key,
const TQString& defaultValue=TQString() )
376 source->setGroup( group );
377 dest->setGroup( group );
378 dest->writeEntry( key, source->readEntry( key, defaultValue ) );
382 void MainWindow::slotSaveToProfile(
const TQString&
id )
384 const TQString path = Kontact::ProfileManager::self()->profileById(
id ).saveLocation();
388 TDEConfig*
const cfg = Prefs::self()->config();
389 Prefs::self()->writeConfig();
390 saveMainWindowSettings( cfg );
393 TDEConfig profile( path+
"/kontactrc",
false,
false );
394 ::copyConfigEntry( cfg, &profile,
"MainWindow Toolbar navigatorToolBar",
"Hidden",
"true" );
395 ::copyConfigEntry( cfg, &profile,
"View",
"SidePaneSplitter" );
396 ::copyConfigEntry( cfg, &profile,
"Icons",
"Theme" );
398 for ( PluginList::Iterator it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
399 if ( !(*it)->isRunningStandalone() ) {
402 (*it)->saveToProfile( path );
406 void MainWindow::slotLoadProfile(
const TQString&
id )
408 const TQString path = Kontact::ProfileManager::self()->profileById(
id ).saveLocation();
412 TDEConfig*
const cfg = Prefs::self()->config();
413 Prefs::self()->writeConfig();
414 saveMainWindowSettings( cfg );
417 const TDEConfig profile( path+
"/kontactrc",
false,
false );
418 const TQStringList groups = profile.groupList();
419 for ( TQStringList::ConstIterator it = groups.begin(), end = groups.end(); it != end; ++it )
421 cfg->setGroup( *it );
422 typedef TQMap<TQString, TQString> StringMap;
423 const StringMap entries = profile.entryMap( *it );
424 for ( StringMap::ConstIterator it2 = entries.begin(), end = entries.end(); it2 != end; ++it2 )
426 if ( it2.data() ==
"KONTACT_PROFILE_DELETE_KEY" )
427 cfg->deleteEntry( it2.key() );
429 cfg->writeEntry( it2.key(), it2.data() );
434 Prefs::self()->readConfig();
435 applyMainWindowSettings( cfg );
436 TDEIconTheme::reconfigure();
437 const WId wid = winId();
438 KIPC::sendMessage( KIPC::PaletteChanged, wid );
439 KIPC::sendMessage( KIPC::FontChanged, wid );
440 KIPC::sendMessage( KIPC::StyleChanged, wid );
441 KIPC::sendMessage( KIPC::SettingsChanged, wid );
442 for (
int i = 0; i < TDEIcon::LastGroup; ++i )
443 KIPC::sendMessage( KIPC::IconChanged, wid, i );
447 for ( PluginList::Iterator it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
448 if ( !(*it)->isRunningStandalone() ) {
449 kdDebug() <<
"Ensure loaded: " << (*it)->identifier() << endl;
452 (*it)->loadProfile( path );
456 bool MainWindow::isPluginLoaded(
const KPluginInfo *info )
458 return (pluginFromInfo( info ) != 0);
461 Plugin *MainWindow::pluginFromInfo(
const KPluginInfo *info )
463 PluginList::ConstIterator end = mPlugins.end();
464 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it )
465 if ( (*it)->identifier() == info->pluginName() )
471 Plugin *MainWindow::pluginFromAction(
const TDEAction *action )
473 PluginList::ConstIterator end = mPlugins.end();
474 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) {
475 if ( (*it)->identifier() == action->name() ) {
482 bool MainWindow::isPluginLoadedByAction(
const TDEAction *action )
484 KPluginInfo::List::ConstIterator it;
485 for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) {
486 if ( !(*it)->isPluginEnabled() )
488 if ( isPluginLoaded( *it ) ) {
489 Plugin *plugin = pluginFromInfo( *it );
491 if ( plugin->
identifier() == action->name() ) {
500 void MainWindow::sortActionsByWeight()
502 TQPtrList<TDEAction> sorted;
504 TQPtrListIterator<TDEAction> eit( mActionPlugins );
506 while ( ( action = eit.current() ) != 0 ) {
508 TQPtrListIterator<TDEAction> sortIt( sorted );
511 Plugin *p1 = pluginFromAction( action );
512 while ( ( saction = sortIt.current() ) != 0 ) {
513 Plugin *p2 = pluginFromAction( saction );
521 sorted.insert( at, action );
523 mActionPlugins = sorted;
526 void MainWindow::loadPlugins()
528 TQPtrList<Plugin> plugins;
529 TQPtrList<KParts::Part> loadDelayed;
532 KPluginInfo::List::ConstIterator it;
533 for ( it = mPluginInfos.begin(); it != mPluginInfos.end(); ++it ) {
534 if ( !(*it)->isPluginEnabled() )
536 if ( isPluginLoaded( *it ) ) {
537 Plugin *plugin = pluginFromInfo( *it );
543 kdDebug(5600) <<
"Loading Plugin: " << (*it)->name() << endl;
545 KParts::ComponentFactory::createInstanceFromService<Kontact::Plugin>(
546 (*it)->service(),
this );
553 plugin->
setIcon( (*it)->icon() );
555 TQVariant libNameProp = (*it)->property(
"X-TDE-KontactPartLibraryName" );
556 TQVariant exeNameProp = (*it)->property(
"X-TDE-KontactPartExecutableName" );
557 TQVariant loadOnStart = (*it)->property(
"X-TDE-KontactPartLoadOnStart" );
558 TQVariant hasPartProp = (*it)->property(
"X-TDE-KontactPluginHasPart" );
560 if ( !loadOnStart.isNull() && loadOnStart.toBool() )
561 mDelayedPreload.append( plugin );
563 kdDebug(5600) <<
"LIBNAMEPART: " << libNameProp.toString() << endl;
567 if ( hasPartProp.isValid() )
570 for ( i = 0; i < plugins.count(); ++i ) {
571 Plugin *p = plugins.at( i );
576 plugins.insert( i, plugin );
579 for ( i = 0; i < plugins.count(); ++ i ) {
580 Plugin *plugin = plugins.at( i );
583 TQPtrList<TDEAction> *actionList = plugin->
newActions();
585 for ( action = actionList->first(); action; action = actionList->next() ) {
586 kdDebug(5600) <<
"Plugging " << action->name() << endl;
587 action->plug( mNewActions->popupMenu() );
588 if ( action->name() == plugin->
identifier() ) {
589 mPluginAction.insert( plugin, action );
593 if ( mSyncActionsEnabled ) {
595 for ( action = actionList->first(); action; action = actionList->next() ) {
596 kdDebug(5600) <<
"Plugging " << action->name() << endl;
597 action->plug( mSyncActions->popupMenu() );
604 mNewActions->setEnabled( mPlugins.size() != 0 );
605 if ( mSyncActionsEnabled )
606 mSyncActions->setEnabled( mPlugins.size() != 0 );
609 void MainWindow::unloadPlugins()
611 KPluginInfo::List::ConstIterator end = mPluginInfos.constEnd();
612 KPluginInfo::List::ConstIterator it;
613 for ( it = mPluginInfos.constBegin(); it != end; ++it ) {
614 if ( !(*it)->isPluginEnabled() )
619 void MainWindow::updateShortcuts()
621 TQPtrList<TDEAction> loadedActions;
623 sortActionsByWeight();
625 TQPtrListIterator<TDEAction> it( mActionPlugins );
628 while ( ( action = it.current() ) != 0 ) {
630 if ( isPluginLoadedByAction( action ) ) {
631 loadedActions.append( action );
632 TQString shortcut = TQString(
"CTRL+%1" ).arg( i );
633 action->setShortcut( TDEShortcut( shortcut ) );
636 action->setShortcut( TDEShortcut() );
639 unplugActionList(
"navigator_actionlist" );
640 factory()->plugActionList(
this, TQString(
"navigator_actionlist" ), loadedActions );
643 bool MainWindow::removePlugin(
const KPluginInfo *info )
645 PluginList::Iterator end = mPlugins.end();
646 for ( PluginList::Iterator it = mPlugins.begin(); it != end; ++it ) {
647 if ( ( *it )->identifier() == info->pluginName() ) {
651 TQPtrList<TDEAction> *actionList = plugin->
newActions();
652 for ( action = actionList->first(); action; action = actionList->next() ) {
653 kdDebug(5600) <<
"Unplugging " << action->name() << endl;
654 action->unplug( mNewActions->popupMenu() );
657 if ( mSyncActionsEnabled ) {
659 for ( action = actionList->first(); action; action = actionList->next() ) {
660 kdDebug(5600) <<
"Unplugging " << action->name() << endl;
661 action->unplug( mSyncActions->popupMenu() );
664 removeChildClient( plugin );
666 if ( mCurrentPlugin == plugin )
669 plugin->deleteLater();
670 mPlugins.remove( it );
673 mPluginAction.remove( plugin );
676 if ( mCurrentPlugin == 0 ) {
677 PluginList::Iterator it;
678 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
679 if ( (*it)->showInSideBar() ) {
693 kdDebug(5600) <<
"Added plugin" << endl;
695 mPlugins.append( plugin );
698 insertChildClient( plugin );
701 void MainWindow::partLoaded(
Kontact::Plugin*, KParts::ReadOnlyPart *part )
704 if ( mPartsStack->id( part->widget() ) != -1 )
707 mPartsStack->addWidget( part->widget() );
709 mPartManager->addPart( part,
false );
711 part->widget()->hide();
714 void MainWindow::slotActivePartChanged( KParts::Part *part )
721 kdDebug(5600) <<
"Part activated: " << part <<
" with stack id. "
722 << mPartsStack->id( part->widget() )<< endl;
726 statusBar()->clear();
729 void MainWindow::slotNewClicked()
731 TDEAction *action = mCurrentPlugin->newActions()->first();
735 PluginList::Iterator it;
736 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
737 action = (*it)->newActions()->first();
746 void MainWindow::slotSyncClicked()
748 TDEAction *action = mCurrentPlugin->syncActions()->first();
752 PluginList::Iterator it;
753 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
754 action = (*it)->syncActions()->first();
763 TDEToolBar* Kontact::MainWindow::findToolBar(
const char* name)
766 return static_cast<TDEToolBar *
>(child(name,
"TDEToolBar"));
769 void MainWindow::slotActionTriggered()
771 const TDEAction *actionSender =
static_cast<const TDEAction*
>( sender() );
772 TQString identifier = actionSender->name();
773 if ( !identifier.isEmpty() ) {
774 selectPlugin( identifier );
784 statusBar()->message( i18n(
"Application is running standalone. Foregrounding..." ), 1000 );
785 mSidePane->indicateForegrunding( plugin );
790 TDEApplication::setOverrideCursor( TQCursor( TQt::WaitCursor ) );
792 KParts::Part *part = plugin->
part();
795 TDEApplication::restoreOverrideCursor();
796 KMessageBox::error(
this, i18n(
"Cannot load part for %1." )
797 .arg( plugin->
title() )
798 +
"\n" + lastErrorMessage() );
799 plugin->setDisabled(
true );
800 mSidePane->updatePlugins();
805 TQWidget *focusWidget = kapp->focusWidget();
806 if ( mCurrentPlugin && focusWidget ) {
808 TQWidget *parent = focusWidget->parentWidget();
810 if ( parent == mCurrentPlugin->part()->widget() )
811 mFocusWidgets.insert( mCurrentPlugin->identifier(), TQGuardedPtr<TQWidget>( focusWidget ) );
813 parent = parent->parentWidget();
818 mSidePane->selectPlugin( plugin->
identifier() );
823 mPartManager->setActivePart( part );
824 TQWidget *
view = part->widget();
828 mPartsStack->raiseWidget( view );
831 if ( mFocusWidgets.contains( plugin->
identifier() ) ) {
832 focusWidget = mFocusWidgets[ plugin->
identifier() ];
834 focusWidget->setFocus();
838 mCurrentPlugin = plugin;
839 TDEAction *newAction = plugin->
newActions()->first();
840 TDEAction *syncAction = plugin->
syncActions()->first();
842 createGUI( plugin->
part() );
844 TDEToolBar* navigatorToolBar = findToolBar(
"navigatorToolBar" );
846 if ( navigatorToolBar && !navigatorToolBar->isHidden() &&
847 navigatorToolBar->barPos() == TDEToolBar::Top ) {
848 topDock()->moveDockWindow( navigatorToolBar, -1 );
851 setCaption( i18n(
"Plugin dependent window title" ,
"%1 - Kontact" ).arg( plugin->
title() ) );
854 mNewActions->setIcon( newAction->icon() );
855 mNewActions->setText( newAction->text() );
857 PluginList::Iterator it;
858 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
859 newAction = (*it)->newActions()->first();
861 mNewActions->setIcon( newAction->icon() );
862 mNewActions->setText( newAction->text() );
867 if ( mSyncActionsEnabled ) {
869 mSyncActions->setIcon( syncAction->icon() );
870 mSyncActions->setText( syncAction->text() );
872 PluginList::Iterator it;
873 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it ) {
874 syncAction = (*it)->syncActions()->first();
876 mSyncActions->setIcon( syncAction->icon() );
877 mSyncActions->setText( syncAction->text() );
886 TQStringList::ConstIterator it;
887 for ( it = invisibleActions.begin(); it != invisibleActions.end(); ++it ) {
888 TDEAction *action = part->actionCollection()->action( (*it).latin1() );
890 TQPtrListIterator<TDEToolBar> it( toolBarIterator() );
891 for ( ; it.current() ; ++it ) {
892 action->unplug( it.current() );
897 TDEApplication::restoreOverrideCursor();
900 void MainWindow::selectPlugin(
const TQString &pluginName )
902 PluginList::ConstIterator end = mPlugins.end();
903 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it )
904 if ( ( *it )->identifier() == pluginName ) {
910 void MainWindow::loadSettings()
913 mSplitter->setSizes( Prefs::self()->mSidePaneSplitter );
916 PluginList::ConstIterator it;
917 for ( it = mDelayedPreload.begin(); it != mDelayedPreload.end(); ++it )
920 selectPlugin( Prefs::self()->mActivePlugin );
923 void MainWindow::saveSettings()
926 Prefs::self()->mSidePaneSplitter = mSplitter->sizes();
928 if ( mCurrentPlugin )
929 Prefs::self()->mActivePlugin = mCurrentPlugin->identifier();
932 void MainWindow::slotShowTip()
937 void MainWindow::slotShowIntroduction()
939 mPartsStack->raiseWidget( 0 );
942 void MainWindow::showTip(
bool force )
945 PluginList::ConstIterator end = mPlugins.end();
946 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) {
947 TQString file = (*it)->tipFile();
948 if ( !file.isEmpty() )
952 KTipDialog::showMultiTip(
this, tips, force );
955 void MainWindow::slotQuit()
961 void MainWindow::slotPreferences()
963 static SettingsDialogWrapper *dlg = 0;
966 TQValueList<KPluginInfo*> filteredPlugins = mPluginInfos;
967 PluginList::ConstIterator it;
968 for ( it = mPlugins.begin(); it != mPlugins.end(); ++it )
969 if ( (*it)->isRunningStandalone() ) {
970 TQValueList<KPluginInfo*>::ConstIterator infoIt;
971 for ( infoIt = filteredPlugins.begin(); infoIt != filteredPlugins.end(); ++infoIt ) {
972 if ( (*infoIt)->pluginName() == (*it)->identifier() ) {
973 filteredPlugins.remove( *infoIt );
978 dlg =
new SettingsDialogWrapper( KSettings::Dialog::Configurable,
this );
979 dlg->addPluginInfos( filteredPlugins );
980 connect( dlg, TQ_SIGNAL( pluginSelectionChanged() ),
981 TQ_SLOT( pluginsChanged() ) );
985 dlg->fixButtonLabel(
this );
988 int MainWindow::startServiceFor(
const TQString& serviceType,
989 const TQString& constraint,
990 const TQString& preferences,
991 TQString *error, TQCString* dcopService,
994 PluginList::ConstIterator end = mPlugins.end();
995 for ( PluginList::ConstIterator it = mPlugins.begin(); it != end; ++it ) {
996 if ( (*it)->createDCOPInterface( serviceType ) ) {
997 kdDebug(5600) <<
"found interface for " << serviceType << endl;
999 *dcopService = (*it)->dcopClient()->appId();
1000 kdDebug(5600) <<
"appId=" << (*it)->dcopClient()->appId() << endl;
1006 "Didn't find dcop interface, falling back to external process" << endl;
1008 return KDCOPServiceStarter::startServiceFor( serviceType, constraint,
1009 preferences, error, dcopService, flags );
1012 void MainWindow::pluginsChanged()
1016 mSidePane->updatePlugins();
1020 void MainWindow::updateConfig()
1022 kdDebug( 5600 ) << k_funcinfo << endl;
1028 void MainWindow::showAboutDialog()
1030 TDEApplication::setOverrideCursor( TQCursor( TQt::WaitCursor ) );
1032 if ( !mAboutDialog )
1033 mAboutDialog =
new AboutDialog(
this );
1035 mAboutDialog->show();
1036 mAboutDialog->raise();
1037 TDEApplication::restoreOverrideCursor();
1040 void MainWindow::configureShortcuts()
1042 KKeyDialog dialog(
true,
this );
1043 dialog.insert( actionCollection() );
1045 if ( mCurrentPlugin && mCurrentPlugin->part() )
1046 dialog.insert( mCurrentPlugin->part()->actionCollection() );
1051 void MainWindow::configureToolbars()
1053 saveMainWindowSettings( TDEGlobal::config(),
"MainWindow" );
1055 KEditToolbar edit( factory() );
1056 connect( &edit, TQ_SIGNAL( newToolbarConfig() ),
1057 this, TQ_SLOT( slotNewToolbarConfig() ) );
1061 void MainWindow::slotNewToolbarConfig()
1063 if ( mCurrentPlugin && mCurrentPlugin->part() ) {
1064 createGUI( mCurrentPlugin->part() );
1066 if ( mCurrentPlugin ) {
1067 applyMainWindowSettings( TDEGlobal::config(),
"MainWindow" );
1072 void MainWindow::slotOpenUrl(
const KURL &url )
1074 if ( url.protocol() ==
"exec" ) {
1075 if ( url.path() ==
"/switch" ) {
1076 selectPlugin( mCurrentPlugin );
1078 if ( url.path() ==
"/gwwizard" ) {
1079 KRun::runCommand(
"groupwarewizard" );
1082 if ( url.path().startsWith(
"/help" ) ) {
1083 TQString app(
"kontact" );
1084 if ( !url.query().isEmpty() ) {
1085 app = url.query().mid( 1 );
1087 kapp->invokeHelp( TQString(), app );
1090 new KRun( url,
this );
1094 void MainWindow::readProperties( TDEConfig *config )
1096 Core::readProperties( config );
1098 TQStringList activePlugins = config->readListEntry(
"ActivePlugins" );
1099 TQValueList<Plugin*>::ConstIterator it = mPlugins.begin();
1100 TQValueList<Plugin*>::ConstIterator end = mPlugins.end();
1101 for ( ; it != end; ++it ) {
1104 TQStringList::ConstIterator activePlugin = activePlugins.find( plugin->
identifier() );
1105 if ( activePlugin != activePlugins.end() ) {
1112 void MainWindow::saveProperties( TDEConfig *config )
1114 Core::saveProperties( config );
1116 TQStringList activePlugins;
1118 KPluginInfo::List::Iterator it = mPluginInfos.begin();
1119 KPluginInfo::List::Iterator end = mPluginInfos.end();
1120 for ( ; it != end; ++it ) {
1121 KPluginInfo *info = *it;
1122 if ( info->isPluginEnabled() ) {
1123 Plugin *plugin = pluginFromInfo( info );
1125 activePlugins.append( plugin->
identifier() );
1131 config->writeEntry(
"ActivePlugins", activePlugins );
1134 bool MainWindow::queryClose()
1137 if ( kapp->sessionSaving() )
1140 bool localClose =
true;
1141 TQValueList<Plugin*>::ConstIterator end = mPlugins.end();
1142 TQValueList<Plugin*>::ConstIterator it = mPlugins.begin();
1143 for ( ; it != end; ++it ) {
1153 void MainWindow::slotShowStatusMsg(
const TQString &msg )
1155 if ( !statusBar() || !mStatusMsgLabel )
1158 mStatusMsgLabel->setText( msg );
1161 TQString MainWindow::introductionString()
1163 TDEIconLoader *iconloader = TDEGlobal::iconLoader();
1164 int iconSize = iconloader->currentSize( TDEIcon::Desktop );
1166 TQString handbook_icon_path = iconloader->iconPath(
"contents2", TDEIcon::Desktop );
1167 TQString html_icon_path = iconloader->iconPath(
"text-html", TDEIcon::Desktop );
1168 TQString wizard_icon_path = iconloader->iconPath(
"wizard", TDEIcon::Desktop );
1170 TQString info = i18n(
"<h2 style='text-align:center; margin-top: 0px;'>Welcome to Kontact %1</h2>"
1172 "<table align=\"center\">"
1173 "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>"
1174 "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>"
1175 "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>"
1176 "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>"
1177 "<tr><td><a href=\"%1\"><img width=\"%1\" height=\"%1\" src=\"%1\" /></a></td>"
1178 "<td><a href=\"%1\">%1</a><br><span id=\"subtext\"><nobr>%1</td></tr>"
1180 "<p style=\"margin-bottom: 0px\"> <a href=\"%1\">Skip this introduction</a></p>" )
1181 .arg( kapp->aboutData()->version() )
1182 .arg( i18n(
"Kontact handles your e-mail, addressbook, calendar, to-do list and more." ) )
1183 .arg(
"exec:/help?kontact" )
1186 .arg( handbook_icon_path )
1187 .arg(
"exec:/help?kontact" )
1188 .arg( i18n(
"Read Manual" ) )
1189 .arg( i18n(
"Learn more about Kontact and its components" ) )
1190 .arg(
"http://kontact.org" )
1193 .arg( html_icon_path )
1194 .arg(
"http://kontact.org" )
1195 .arg( i18n(
"Visit Kontact Website" ) )
1196 .arg( i18n(
"Access online resources and tutorials" ) )
1197 .arg(
"exec:/gwwizard" )
1200 .arg( wizard_icon_path )
1201 .arg(
"exec:/gwwizard" )
1202 .arg( i18n(
"Configure Kontact as Groupware Client" ) )
1203 .arg( i18n(
"Prepare Kontact for use in corporate networks" ) )
1204 .arg(
"exec:/switch" );
1208 #include "mainwindow.moc"