kontact

summaryview_plugin.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Sven L�ppken <sven@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "summaryview_plugin.h"
00021 #include "core.h"
00022 #include "summaryview_part.h"
00023 
00024 #include <dcopref.h>
00025 #include <kgenericfactory.h>
00026 #include <kparts/componentfactory.h>
00027 #include <kaboutdata.h>
00028 #include <kaction.h>
00029 
00030 #include <qpopupmenu.h>
00031 
00032 typedef KGenericFactory< SummaryView, Kontact::Core > SummaryViewFactory;
00033 K_EXPORT_COMPONENT_FACTORY( libkontact_summaryplugin,
00034                             SummaryViewFactory( "kontact_summaryplugin" ) )
00035 
00036 SummaryView::SummaryView( Kontact::Core *core, const char *name, const QStringList& )
00037   : Kontact::Plugin( core, core, name),
00038     mAboutData( 0 ), mPart( 0 )
00039 {
00040   setInstance( SummaryViewFactory::instance() );
00041 
00042   mSyncAction = new KSelectAction( i18n( "Synchronize All" ), "reload", 0, this,
00043                                    SLOT( doSync() ), actionCollection(),
00044                                    "kontact_summary_sync" );
00045   connect( mSyncAction, SIGNAL( activated( const QString& ) ), this, SLOT( syncAccount( const QString& ) ) );
00046   connect( mSyncAction->popupMenu(), SIGNAL( aboutToShow() ), this, SLOT( fillSyncActionSubEntries() ) );
00047 
00048   insertSyncAction( mSyncAction );
00049   fillSyncActionSubEntries();
00050 }
00051 
00052 void SummaryView::fillSyncActionSubEntries()
00053 {
00054   QStringList menuItems;
00055   menuItems.append( i18n("All") );
00056 
00057   DCOPRef ref( "kmail", "KMailIface" );
00058   DCOPReply reply = ref.call( "accounts" );
00059 
00060   if ( reply.isValid() )
00061   {
00062     const QStringList accounts = reply;
00063     menuItems += accounts;
00064   }
00065   mSyncAction->clear();
00066   mSyncAction->setItems( menuItems );
00067 }
00068 
00069 void SummaryView::syncAccount( const QString& account )
00070 {
00071   const QString acc = account == i18n("All") ? QString() : account;
00072   DCOPRef ref( "kmail", "KMailIface" );
00073   ref.send( "checkAccount", acc );
00074   fillSyncActionSubEntries();
00075 }
00076 
00077 SummaryView::~SummaryView()
00078 {
00079 }
00080 
00081 void SummaryView::doSync()
00082 {
00083   if ( mPart )
00084     mPart->updateSummaries();
00085 
00086   const QValueList<Kontact::Plugin*> pluginList = core()->pluginList();
00087   for ( QValueList<Kontact::Plugin*>::ConstIterator it = pluginList.begin(), end = pluginList.end();
00088         it != end; ++it ) {
00089     // execute all sync actions but our own
00090     QPtrList<KAction> *actions = (*it)->syncActions();
00091     for ( QPtrList<KAction>::Iterator jt = actions->begin(), end = actions->end(); jt != end; ++jt ) {
00092       if ( *jt != mSyncAction )
00093         (*jt)->activate();
00094     }
00095   }
00096   fillSyncActionSubEntries();
00097 }
00098 
00099 KParts::ReadOnlyPart *SummaryView::createPart()
00100 {
00101   mPart = new SummaryViewPart( core(), "summarypartframe", aboutData(),
00102                                this, "summarypart" );
00103   return mPart;
00104 }
00105 
00106 const KAboutData *SummaryView::aboutData()
00107 {
00108   if ( !mAboutData ) {
00109     mAboutData = new KAboutData( "kontactsummary", I18N_NOOP("Kontact Summary"),
00110                                  "1.1",
00111                                  I18N_NOOP("Kontact Summary View"),
00112                                  KAboutData::License_LGPL,
00113                                  I18N_NOOP("(c) 2003 The Kontact developers" ) );
00114     mAboutData->addAuthor( "Sven Lueppken", "", "sven@kde.org" );
00115     mAboutData->addAuthor( "Cornelius Schumacher", "", "schumacher@kde.org" );
00116     mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
00117     mAboutData->setProductName( "kontact/summary" );
00118   }
00119 
00120   return mAboutData;
00121 }
00122 
00123 #include "summaryview_plugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys