summaryview_plugin.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Sven Lüppken <sven@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20#include "summaryview_plugin.h"
21#include "core.h"
22#include "summaryview_part.h"
23
24#include <dcopref.h>
25#include <kgenericfactory.h>
26#include <tdeparts/componentfactory.h>
27#include <tdeaboutdata.h>
28#include <tdeaction.h>
29
30#include <tqpopupmenu.h>
31
32typedef KGenericFactory< SummaryView, Kontact::Core > SummaryViewFactory;
33K_EXPORT_COMPONENT_FACTORY( libkontact_summaryplugin,
34 SummaryViewFactory( "kontact_summaryplugin" ) )
35
36SummaryView::SummaryView( Kontact::Core *core, const char *name, const TQStringList& )
37 : Kontact::Plugin( core, core, name),
38 mAboutData( 0 ), mPart( 0 )
39{
40 setInstance( SummaryViewFactory::instance() );
41
42 mSyncAction = new TDESelectAction( i18n( "Synchronize All" ), "reload", 0, 0,
43 0, actionCollection(),
44 "kontact_summary_sync" );
45 connect( mSyncAction, TQ_SIGNAL( activated( const TQString& ) ), this, TQ_SLOT( syncAccount( const TQString& ) ) );
46 connect( mSyncAction->popupMenu(), TQ_SIGNAL( aboutToShow() ), this, TQ_SLOT( fillSyncActionSubEntries() ) );
47
48 insertSyncAction( mSyncAction );
49 fillSyncActionSubEntries();
50}
51
52void SummaryView::fillSyncActionSubEntries()
53{
54 TQStringList menuItems;
55 menuItems.append( i18n("All") );
56
57 DCOPRef ref( "kmail", "KMailIface" );
58 DCOPReply reply = ref.call( "accounts" );
59
60 if ( reply.isValid() )
61 {
62 const TQStringList accounts = reply;
63 menuItems += accounts;
64 }
65 mSyncAction->clear();
66 mSyncAction->setItems( menuItems );
67}
68
69void SummaryView::syncAccount( const TQString& account )
70{
71 if ( account == i18n("All") ) {
72 doSync();
73 } else {
74 DCOPRef ref( "kmail", "KMailIface" );
75 ref.send( "checkAccount", account );
76 }
77 fillSyncActionSubEntries();
78}
79
80SummaryView::~SummaryView()
81{
82}
83
84void SummaryView::doSync()
85{
86 if ( mPart )
87 mPart->updateSummaries();
88
89 const TQValueList<Kontact::Plugin*> pluginList = core()->pluginList();
90 for ( TQValueList<Kontact::Plugin*>::ConstIterator it = pluginList.begin(), end = pluginList.end();
91 it != end; ++it ) {
92 // execute all sync actions but our own
93 TQPtrList<TDEAction> *actions = (*it)->syncActions();
94 for ( TQPtrList<TDEAction>::Iterator jt = actions->begin(), end = actions->end(); jt != end; ++jt ) {
95 if ( *jt != mSyncAction )
96 (*jt)->activate();
97 }
98 }
99 fillSyncActionSubEntries();
100}
101
102KParts::ReadOnlyPart *SummaryView::createPart()
103{
104 mPart = new SummaryViewPart( core(), "summarypartframe", aboutData(),
105 this, "summarypart" );
106 return mPart;
107}
108
109const TDEAboutData *SummaryView::aboutData()
110{
111 if ( !mAboutData ) {
112 mAboutData = new TDEAboutData( "kontactsummary", I18N_NOOP("Kontact Summary"),
113 "1.1",
114 I18N_NOOP("Kontact Summary View"),
115 TDEAboutData::License_LGPL,
116 I18N_NOOP("(c) 2003 The Kontact developers" ) );
117 mAboutData->addAuthor( "Sven Lueppken", "", "sven@kde.org" );
118 mAboutData->addAuthor( "Cornelius Schumacher", "", "schumacher@kde.org" );
119 mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
120 mAboutData->setProductName( "kontact/summary" );
121 }
122
123 return mAboutData;
124}
125
126#include "summaryview_plugin.moc"