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, 0, 
00043                                    0, 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   if ( account == i18n("All") ) {
00072     doSync();
00073   } else {
00074     DCOPRef ref( "kmail", "KMailIface" );
00075     ref.send( "checkAccount", account );
00076   }
00077   fillSyncActionSubEntries();
00078 }
00079 
00080 SummaryView::~SummaryView()
00081 {
00082 }
00083 
00084 void SummaryView::doSync()
00085 {
00086   if ( mPart )
00087     mPart->updateSummaries();
00088 
00089   const QValueList<Kontact::Plugin*> pluginList = core()->pluginList();
00090   for ( QValueList<Kontact::Plugin*>::ConstIterator it = pluginList.begin(), end = pluginList.end();
00091         it != end; ++it ) {
00092     // execute all sync actions but our own
00093     QPtrList<KAction> *actions = (*it)->syncActions();
00094     for ( QPtrList<KAction>::Iterator jt = actions->begin(), end = actions->end(); jt != end; ++jt ) {
00095       if ( *jt != mSyncAction )
00096         (*jt)->activate();
00097     }
00098   }
00099   fillSyncActionSubEntries();
00100 }
00101 
00102 KParts::ReadOnlyPart *SummaryView::createPart()
00103 {
00104   mPart = new SummaryViewPart( core(), "summarypartframe", aboutData(),
00105                                this, "summarypart" );
00106   return mPart;
00107 }
00108 
00109 const KAboutData *SummaryView::aboutData()
00110 {
00111   if ( !mAboutData ) {
00112     mAboutData = new KAboutData( "kontactsummary", I18N_NOOP("Kontact Summary"),
00113                                  "1.1",
00114                                  I18N_NOOP("Kontact Summary View"),
00115                                  KAboutData::License_LGPL,
00116                                  I18N_NOOP("(c) 2003 The Kontact developers" ) );
00117     mAboutData->addAuthor( "Sven Lueppken", "", "sven@kde.org" );
00118     mAboutData->addAuthor( "Cornelius Schumacher", "", "schumacher@kde.org" );
00119     mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
00120     mAboutData->setProductName( "kontact/summary" );
00121   }
00122 
00123   return mAboutData;
00124 }
00125 
00126 #include "summaryview_plugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys