summaryrefslogtreecommitdiffstats
path: root/kontact/plugins/summary/kcmkontactsummary.cpp
blob: f3eae0121292af927380081814eccc2273f5c832 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
    This file is part of KDE Kontact.

    Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>

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

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/

#include <kaboutdata.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kdialog.h>
#include <kiconloader.h>
#include <kiconloader.h>
#include <klocale.h>
#include <plugin.h>
#include <kplugininfo.h>
#include <ktrader.h>

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqpixmap.h>

#include "kcmkontactsummary.h"

#include <tdepimmacros.h>

extern "C"
{
  KDE_EXPORT KCModule *create_kontactsummary( TQWidget *parent, const char * ) {
    return new KCMKontactSummary( parent, "kcmkontactsummary" );
  }
}

class PluginItem : public TQCheckListItem
{
  public:
    PluginItem( KPluginInfo *info, KListView *parent )
      : TQCheckListItem( parent, TQString(), TQCheckListItem::CheckBox ),
        mInfo( info )
    {
      TQPixmap pm = TDEGlobal::iconLoader()->loadIcon( mInfo->icon(), KIcon::Small );
      setPixmap( 0, pm );
    }

    KPluginInfo* pluginInfo() const
    {
      return mInfo;
    }

    virtual TQString text( int column ) const
    {
      if ( column == 0 )
        return mInfo->name();
      else if ( column == 1 )
        return mInfo->comment();
      else
        return TQString();
    }

  private:
    KPluginInfo *mInfo;
};

PluginView::PluginView( TQWidget *parent, const char *name )
  : KListView( parent, name )
{
  addColumn( i18n( "Name" ) );
  setAllColumnsShowFocus( true );
  setFullWidth( true );
}

PluginView::~PluginView()
{
}

KCMKontactSummary::KCMKontactSummary( TQWidget *parent, const char *name )
  : KCModule( parent, name )
{
  TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );

  TQLabel *label = new TQLabel( i18n( "Here you can select which summary plugins to have visible in your summary view." ), this );
  layout->addWidget( label );

  mPluginView = new PluginView( this );
  layout->addWidget( mPluginView );

  layout->setStretchFactor( mPluginView, 1 );

  connect( mPluginView, TQT_SIGNAL( clicked( TQListViewItem* ) ),
           this, TQT_SLOT( itemClicked( TQListViewItem* ) ) );
  load();

  TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kontactsummary" ),
                                      I18N_NOOP( "TDE Kontact Summary" ),
                                      0, 0, TDEAboutData::License_GPL,
                                      I18N_NOOP( "(c), 2004 Tobias Koenig" ) );

  about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
  setAboutData( about );
}

void KCMKontactSummary::load()
{
  KTrader::OfferList offers = KTrader::self()->query(
      TQString::fromLatin1( "Kontact/Plugin" ),
      TQString( "[X-TDE-KontactPluginVersion] == %1" ).arg( KONTACT_PLUGIN_VERSION ) );

  TQStringList activeSummaries;

  KConfig config( "kontact_summaryrc" );
  if ( !config.hasKey( "ActiveSummaries" ) ) {
    activeSummaries << "kontact_kaddressbookplugin";
    activeSummaries << "kontact_specialdatesplugin";
    activeSummaries << "kontact_korganizerplugin";
    activeSummaries << "kontact_todoplugin";
    activeSummaries << "kontact_kpilotplugin";
    activeSummaries << "kontact_weatherplugin";
    activeSummaries << "kontact_newstickerplugin";
  } else {
    activeSummaries = config.readListEntry( "ActiveSummaries" );
  }

  mPluginView->clear();
  mPluginList.clear();

  mPluginList = KPluginInfo::fromServices( offers, &config, "Plugins" );
  KPluginInfo::List::Iterator it;
  KConfig *conf = new KConfig("kontactrc");
  KConfigGroup *cg = new KConfigGroup( conf, "Plugins" );
  for ( it = mPluginList.begin(); it != mPluginList.end(); ++it ) {
      (*it)->load( cg );

    if ( !(*it)->isPluginEnabled() )
      continue;

    TQVariant var = (*it)->property( "X-TDE-KontactPluginHasSummary" );
    if ( !var.isValid() )
      continue;

    if ( var.toBool() == true ) {
      PluginItem *item = new PluginItem( *it, mPluginView );

      if ( activeSummaries.find( (*it)->pluginName() ) != activeSummaries.end() )
        item->setOn( true );
    }
  }
}

void KCMKontactSummary::save()
{
  TQStringList activeSummaries;

  TQListViewItemIterator it( mPluginView, TQListViewItemIterator::Checked );
  while ( it.current() ) {
    PluginItem *item = static_cast<PluginItem*>( it.current() );
    activeSummaries.append( item->pluginInfo()->pluginName() );
    ++it;
  }

  KConfig config( "kontact_summaryrc" );
  config.writeEntry( "ActiveSummaries", activeSummaries );
}

void KCMKontactSummary::defaults()
{
  emit changed( true );
}

void KCMKontactSummary::itemClicked( TQListViewItem* )
{
  emit changed( true );
}

#include "kcmkontactsummary.moc"