~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/kresources/kabc/resourceakonadi.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- c-basic-offset: 2 -*-
2
 
/*
3
 
    This file is part of libkabc.
4
 
    Copyright (c) 2008-2009 Kevin Krammer <kevin.krammer@gmx.at>
5
 
 
6
 
    This library is free software; you can redistribute it and/or
7
 
    modify it under the terms of the GNU Library General Public
8
 
    License as published by the Free Software Foundation; either
9
 
    version 2 of the License, or (at your option) any later version.
10
 
 
11
 
    This library is distributed in the hope that it will be useful,
12
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
    Library General Public License for more details.
15
 
 
16
 
    You should have received a copy of the GNU Library General Public License
17
 
    along with this library; see the file COPYING.LIB.  If not, write to
18
 
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 
    Boston, MA 02110-1301, USA.
20
 
*/
21
 
#include "resourceakonadi.h"
22
 
 
23
 
#include "resourceakonadi_p.h"
24
 
#include "resourceakonadiconfig.h"
25
 
 
26
 
using namespace KABC;
27
 
 
28
 
ResourceAkonadi::ResourceAkonadi()
29
 
  : ResourceABC(), d( new Private( this ) )
30
 
{
31
 
  KGlobal::locale()->insertCatalog("kresources_shared_akonadi");
32
 
}
33
 
 
34
 
ResourceAkonadi::ResourceAkonadi( const KConfigGroup &group )
35
 
  : ResourceABC( group ), d( new Private( group, this ) )
36
 
{
37
 
}
38
 
 
39
 
ResourceAkonadi::~ResourceAkonadi()
40
 
{
41
 
  delete d;
42
 
}
43
 
 
44
 
void ResourceAkonadi::clear()
45
 
{
46
 
  // clear local caches
47
 
  d->clear();
48
 
 
49
 
  ResourceABC::clear();
50
 
}
51
 
 
52
 
void ResourceAkonadi::writeConfig( KConfigGroup &group )
53
 
{
54
 
  kDebug(5700);
55
 
  ResourceABC::writeConfig( group );
56
 
 
57
 
  d->writeConfig( group );
58
 
}
59
 
 
60
 
bool ResourceAkonadi::doOpen()
61
 
{
62
 
  return d->doOpen();
63
 
}
64
 
 
65
 
void ResourceAkonadi::doClose()
66
 
{
67
 
  d->clear();
68
 
  d->doClose();
69
 
}
70
 
 
71
 
Ticket *ResourceAkonadi::requestSaveTicket()
72
 
{
73
 
  kDebug(5700);
74
 
  if ( !addressBook() ) {
75
 
    kDebug(5700) << "no addressbook";
76
 
    return 0;
77
 
  }
78
 
 
79
 
  return createTicket( this );
80
 
}
81
 
 
82
 
void ResourceAkonadi::releaseSaveTicket( Ticket *ticket )
83
 
{
84
 
  delete ticket;
85
 
}
86
 
 
87
 
bool ResourceAkonadi::load()
88
 
{
89
 
  kDebug(5700);
90
 
 
91
 
  d->clear();
92
 
  return d->doLoad();
93
 
}
94
 
 
95
 
bool ResourceAkonadi::asyncLoad()
96
 
{
97
 
  kDebug(5700);
98
 
 
99
 
  d->clear();
100
 
  return d->doAsyncLoad();
101
 
}
102
 
 
103
 
bool ResourceAkonadi::save( Ticket *ticket )
104
 
{
105
 
  Q_UNUSED( ticket );
106
 
  kDebug(5700);
107
 
 
108
 
  return d->doSave();
109
 
}
110
 
 
111
 
bool ResourceAkonadi::asyncSave( Ticket *ticket )
112
 
{
113
 
  Q_UNUSED( ticket );
114
 
  kDebug(5700);
115
 
 
116
 
  return d->doAsyncSave();
117
 
}
118
 
 
119
 
void ResourceAkonadi::insertAddressee( const Addressee &addr )
120
 
{
121
 
  kDebug(5700);
122
 
  if ( d->insertAddressee( addr ) ) {
123
 
    ResourceABC::insertAddressee( addr );
124
 
  }
125
 
}
126
 
 
127
 
void ResourceAkonadi::removeAddressee( const Addressee &addr )
128
 
{
129
 
  kDebug(5700);
130
 
  d->removeAddressee( addr );
131
 
 
132
 
  ResourceABC::removeAddressee( addr );
133
 
}
134
 
 
135
 
void ResourceAkonadi::insertDistributionList( DistributionList *list )
136
 
{
137
 
  kDebug(5700) << "identifier=" << list->identifier()
138
 
               << ", name=" << list->name();
139
 
 
140
 
  if ( d->insertDistributionList( list ) ) {
141
 
    ResourceABC::insertDistributionList( list );
142
 
  }
143
 
}
144
 
 
145
 
void ResourceAkonadi::removeDistributionList( DistributionList *list )
146
 
{
147
 
  kDebug(5700) << "identifier=" << list->identifier()
148
 
               << ", name=" << list->name();
149
 
 
150
 
  d->removeDistributionList( list );
151
 
 
152
 
  ResourceABC::removeDistributionList( list );
153
 
}
154
 
 
155
 
bool ResourceAkonadi::subresourceActive( const QString &subResource ) const
156
 
{
157
 
  kDebug(5700) << "subResource" << subResource;
158
 
 
159
 
  bool active = false;
160
 
  SubResource *resource = d->subResource( subResource );
161
 
  if ( resource != 0 ) {
162
 
    active = resource->isActive();
163
 
  }
164
 
 
165
 
  return active;
166
 
}
167
 
 
168
 
bool ResourceAkonadi::subresourceWritable( const QString &subResource ) const
169
 
{
170
 
  kDebug(5700) << "subResource" << subResource;
171
 
 
172
 
  bool writable = false;
173
 
  SubResource *resource = d->subResource( subResource );
174
 
  if ( resource != 0 ) {
175
 
    writable = resource->isWritable();
176
 
  }
177
 
 
178
 
  return writable;
179
 
}
180
 
 
181
 
QString ResourceAkonadi::subresourceLabel( const QString &subResource ) const
182
 
{
183
 
  kDebug(5700) << "subResource" << subResource;
184
 
 
185
 
  QString label;
186
 
  SubResource *resource = d->subResource( subResource );
187
 
  if ( resource != 0 ) {
188
 
    label = resource->label();
189
 
  }
190
 
 
191
 
  return label;
192
 
}
193
 
 
194
 
int ResourceAkonadi::subresourceCompletionWeight( const QString &subResource ) const
195
 
{
196
 
  kDebug(5700) << "subResource" << subResource;
197
 
 
198
 
  int weight = 80;
199
 
  SubResource *resource = d->subResource( subResource );
200
 
  if ( resource != 0 ) {
201
 
    weight = resource->completionWeight();
202
 
  }
203
 
 
204
 
  return weight;
205
 
}
206
 
 
207
 
QStringList ResourceAkonadi::subresources() const
208
 
{
209
 
  kDebug(5700) << d->subResourceIdentifiers();
210
 
  return d->subResourceIdentifiers();
211
 
}
212
 
 
213
 
QMap<QString, QString> ResourceAkonadi::uidToResourceMap() const
214
 
{
215
 
  return d->uidToResourceMap();
216
 
}
217
 
 
218
 
StoreConfigIface &ResourceAkonadi::storeConfig()
219
 
{
220
 
  return *d;
221
 
}
222
 
 
223
 
void ResourceAkonadi::setSubresourceActive( const QString &subResource, bool active )
224
 
{
225
 
  kDebug(5700) << "subResource" << subResource << ", active" << active;
226
 
 
227
 
  // TODO check if this check for change isn't already handled in the private
228
 
  bool changed = false;
229
 
 
230
 
  SubResource *resource = d->subResource( subResource );
231
 
  if ( resource != 0 ) {
232
 
    if ( active != resource->isActive() ) {
233
 
      resource->setActive( active );
234
 
      changed = true;
235
 
    }
236
 
  }
237
 
 
238
 
  if ( changed )
239
 
    addressBook()->emitAddressBookChanged();
240
 
}
241
 
 
242
 
void ResourceAkonadi::setSubresourceCompletionWeight( const QString &subResource, int weight )
243
 
{
244
 
  kDebug(5700) << "subResource" << subResource << ", weight" << weight;
245
 
 
246
 
  SubResource *resource = d->subResource( subResource );
247
 
  if ( resource != 0 ) {
248
 
    resource->setCompletionWeight( weight );
249
 
  }
250
 
}
251
 
 
252
 
#include "resourceakonadi.moc"
253
 
// kate: space-indent on; indent-width 2; replace-tabs on;