summaryrefslogtreecommitdiffstats
path: root/kontact/plugins/summary/summaryview_plugin.cpp
blob: a7bb8996030a59b2d498ecd5fc8cf19c71fdb6f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* This file is part of the KDE project
   Copyright (C) 2003 Sven L�ppken <sven@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
 */

#include "summaryview_plugin.h"
#include "core.h"
#include "summaryview_part.h"

#include <dcopref.h>
#include <kgenericfactory.h>
#include <tdeparts/componentfactory.h>
#include <kaboutdata.h>
#include <kaction.h>

#include <tqpopupmenu.h>

typedef KGenericFactory< SummaryView, Kontact::Core > SummaryViewFactory;
K_EXPORT_COMPONENT_FACTORY( libkontact_summaryplugin,
                            SummaryViewFactory( "kontact_summaryplugin" ) )

SummaryView::SummaryView( Kontact::Core *core, const char *name, const TQStringList& )
  : Kontact::Plugin( core, TQT_TQOBJECT(core), name),
    mAboutData( 0 ), mPart( 0 )
{
  setInstance( SummaryViewFactory::instance() );

  mSyncAction = new KSelectAction( i18n( "Synchronize All" ), "reload", 0, 0, 
                                   0, actionCollection(),
                                   "kontact_summary_sync" );
  connect( mSyncAction, TQT_SIGNAL( activated( const TQString& ) ), this, TQT_SLOT( syncAccount( const TQString& ) ) );
  connect( mSyncAction->popupMenu(), TQT_SIGNAL( aboutToShow() ), this, TQT_SLOT( fillSyncActionSubEntries() ) );

  insertSyncAction( mSyncAction );
  fillSyncActionSubEntries();
}

void SummaryView::fillSyncActionSubEntries()
{
  TQStringList menuItems;
  menuItems.append( i18n("All") );

  DCOPRef ref( "kmail", "KMailIface" );
  DCOPReply reply = ref.call( "accounts" );

  if ( reply.isValid() )
  {
    const TQStringList accounts = reply;
    menuItems += accounts;
  }
  mSyncAction->clear();
  mSyncAction->setItems( menuItems );
}

void SummaryView::syncAccount( const TQString& account )
{
  if ( account == i18n("All") ) {
    doSync();
  } else {
    DCOPRef ref( "kmail", "KMailIface" );
    ref.send( "checkAccount", account );
  }
  fillSyncActionSubEntries();
}

SummaryView::~SummaryView()
{
}

void SummaryView::doSync()
{
  if ( mPart )
    mPart->updateSummaries();

  const TQValueList<Kontact::Plugin*> pluginList = core()->pluginList();
  for ( TQValueList<Kontact::Plugin*>::ConstIterator it = pluginList.begin(), end = pluginList.end();
        it != end; ++it ) {
    // execute all sync actions but our own
    TQPtrList<KAction> *actions = (*it)->syncActions();
    for ( TQPtrList<KAction>::Iterator jt = actions->begin(), end = actions->end(); jt != end; ++jt ) {
      if ( *jt != mSyncAction )
        (*jt)->activate();
    }
  }
  fillSyncActionSubEntries();
}

KParts::ReadOnlyPart *SummaryView::createPart()
{
  mPart = new SummaryViewPart( core(), "summarypartframe", aboutData(),
                               this, "summarypart" );
  return mPart;
}

const TDEAboutData *SummaryView::aboutData()
{
  if ( !mAboutData ) {
    mAboutData = new TDEAboutData( "kontactsummary", I18N_NOOP("Kontact Summary"),
                                 "1.1",
                                 I18N_NOOP("Kontact Summary View"),
                                 TDEAboutData::License_LGPL,
                                 I18N_NOOP("(c) 2003 The Kontact developers" ) );
    mAboutData->addAuthor( "Sven Lueppken", "", "sven@kde.org" );
    mAboutData->addAuthor( "Cornelius Schumacher", "", "schumacher@kde.org" );
    mAboutData->addAuthor( "Tobias Koenig", "", "tokoe@kde.org" );
    mAboutData->setProductName( "kontact/summary" );
  }

  return mAboutData;
}

#include "summaryview_plugin.moc"