contacteditorwidget.cpp 26.8 KB
Newer Older
1
/*
Tobias Koenig's avatar
Tobias Koenig committed
2
    This file is part of Akonadi Contact.
3
4
5

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

Tobias Koenig's avatar
Tobias Koenig committed
6
7
8
9
    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.
10

Tobias Koenig's avatar
Tobias Koenig committed
11
12
13
14
    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.
15

Tobias Koenig's avatar
Tobias Koenig committed
16
17
18
19
    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.
20
21
*/

22
#include "contacteditorwidget.h"
23
24

#include "addresseditwidget.h"
Tobias Koenig's avatar
Tobias Koenig committed
25
#include "categorieseditwidget.h"
26
#include "contacteditorpageplugin.h"
27
#include "contactmetadata_p.h"
28
#include "customfieldseditwidget.h"
29
#include "dateeditwidget.h"
30
#include "displaynameeditwidget.h"
31
#include "emaileditwidget.h"
32
#include "freebusyeditwidget.h"
33
#include "geoeditwidget.h"
34
#include "imagewidget.h"
Tobias Koenig's avatar
Tobias Koenig committed
35
#include "imeditwidget.h"
36
#include "nameeditwidget.h"
37
#include "phoneeditwidget.h"
38
#include "soundeditwidget.h"
39

40
41
#include <kconfig.h>
#include <kconfiggroup.h>
42
43
#include <klineedit.h>
#include <klocale.h>
44
#include <kstandarddirs.h>
45
46
#include <ktabwidget.h>
#include <ktextedit.h>
47
#include <kurlrequester.h>
48

49
50
#include <Nepomuk/ResourceManager>

51
52
#include <QtCore/QDirIterator>
#include <QtCore/QPluginLoader>
53
54
55
56
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QCheckBox>
57

58
class ContactEditorWidget::Private
59
60
{
  public:
61
62
    Private( ContactEditorWidget::DisplayMode displayMode, ContactEditorWidget *parent )
      : mDisplayMode(displayMode), mParent( parent ), mCustomFieldsWidget(0)
63
64
65
66
67
68
69
70
    {
    }

    void initGui();
    void initGuiContactTab();
    void initGuiLocationTab();
    void initGuiBusinessTab();
    void initGuiPersonalTab();
71
    void initGuiNotesTab();
72
    void initGuiCustomFieldsTab();
73

74
75
    void loadCustomPages();

76
77
78
    QString loadCustom( const KABC::Addressee &contact, const QString &key ) const;
    void storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const;

79
    ContactEditorWidget::DisplayMode mDisplayMode;
80
    ContactEditorWidget *mParent;
81
82
83
    KTabWidget *mTabWidget;

    // widgets from name group
84
    NameEditWidget *mNameWidget;
85
    ImageWidget *mPhotoWidget;
86
    DisplayNameEditWidget *mDisplayNameWidget;
87
    KLineEdit *mNickNameWidget;
88
    SoundEditWidget *mPronunciationWidget;
89

Allen Winter's avatar
Allen Winter committed
90
    // widgets from Internet group
91
    EmailEditWidget *mEmailWidget;
92
93
    KLineEdit *mHomepageWidget;
    KLineEdit *mBlogWidget;
Tobias Koenig's avatar
Tobias Koenig committed
94
    IMEditWidget *mIMWidget;
95
96

    // widgets from phones group
97
    PhoneEditWidget *mPhonesWidget;
98

Tobias Koenig's avatar
Tobias Koenig committed
99
100
    CategoriesEditWidget *mCategoriesWidget;

101
102
103
104
    KComboBox* mMailPreferFormatting;
    QCheckBox *mAllowRemoteContent;


105
106
107
108
    // widgets from addresses group
    AddressEditWidget *mAddressesWidget;

    // widgets from coordinates group
109
    GeoEditWidget *mCoordinatesWidget;
110
111

    // widgets from general group
112
    ImageWidget *mLogoWidget;
113
    KLineEdit *mOrganizationWidget;
114
115
116
117
118
119
120
121
    KLineEdit *mProfessionWidget;
    KLineEdit *mTitleWidget;
    KLineEdit *mDepartmentWidget;
    KLineEdit *mOfficeWidget;
    KLineEdit *mManagerWidget;
    KLineEdit *mAssistantWidget;

    // widgets from groupware group
122
    FreeBusyEditWidget *mFreeBusyWidget;
123
124
125
126
127

    // widgets from notes group
    KTextEdit *mNotesWidget;

    // widgets from dates group
128
129
    DateEditWidget *mBirthdateWidget;
    DateEditWidget *mAnniversaryWidget;
130
131
132

    // widgets from family group
    KLineEdit *mPartnerWidget;
133

134
135
136
    // widgets from custom fields group
    CustomFieldsEditWidget *mCustomFieldsWidget;

137
138
    // custom editor pages
    QList<Akonadi::ContactEditorPagePlugin*> mCustomPages;
139
140
};

141
void ContactEditorWidget::Private::initGui()
142
143
144
145
146
147
148
149
150
151
152
{
  QVBoxLayout *layout = new QVBoxLayout( mParent );
  layout->setMargin( 0 );

  mTabWidget = new KTabWidget( mParent );
  layout->addWidget( mTabWidget );

  initGuiContactTab();
  initGuiLocationTab();
  initGuiBusinessTab();
  initGuiPersonalTab();
153
  initGuiNotesTab();
154
155
156
157
  if(mDisplayMode == FullMode) {
    initGuiCustomFieldsTab();
    loadCustomPages();
  }
158
159
}

160
void ContactEditorWidget::Private::initGuiContactTab()
161
162
{
  QWidget *widget = new QWidget;
163
  QGridLayout *layout = new QGridLayout( widget );
164

Tobias Koenig's avatar
Tobias Koenig committed
165
  mTabWidget->addTab( widget, i18nc( "@title:tab", "Contact" ) );
166

Tobias Koenig's avatar
Tobias Koenig committed
167
  QGroupBox *nameGroupBox = new QGroupBox( i18nc( "@title:group Name related properties of a contact", "Name" ) );
Tobias Koenig's avatar
Tobias Koenig committed
168
169
  QGroupBox *internetGroupBox = new QGroupBox( i18nc( "@title:group", "Internet" ) );
  QGroupBox *phonesGroupBox = new QGroupBox( i18nc( "@title:group", "Phones" ) );
170

171
172
  layout->addWidget( nameGroupBox, 0, 0 );
  layout->addWidget( internetGroupBox, 0, 1 );
173
  layout->addWidget( phonesGroupBox, 1, 0, 4, 1 );
174
175
176
177
178
179
180
181

  QGridLayout *nameLayout = new QGridLayout( nameGroupBox );
  QGridLayout *internetLayout = new QGridLayout( internetGroupBox );
  QGridLayout *phonesLayout = new QGridLayout( phonesGroupBox );

  QLabel *label = 0;

  // setup name group box
Tobias Koenig's avatar
Tobias Koenig committed
182
  label = new QLabel( i18nc( "@label The name of a contact", "Name:" ) );
183
184
185
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  nameLayout->addWidget( label, 0, 0 );

186
  mNameWidget = new NameEditWidget;
187
188
189
  label->setBuddy( mNameWidget );
  nameLayout->addWidget( mNameWidget, 0, 1 );

190
  mPhotoWidget = new ImageWidget( ImageWidget::Photo );
191
192
193
  mPhotoWidget->setMinimumSize( QSize( 100, 140 ) );
  nameLayout->addWidget( mPhotoWidget, 0, 2, 4, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
194
  label = new QLabel( i18nc( "@label The display name of a contact", "Display:" ) );
195
196
197
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  nameLayout->addWidget( label, 1, 0 );

198
  mDisplayNameWidget = new DisplayNameEditWidget;
199
200
201
  label->setBuddy( mDisplayNameWidget );
  nameLayout->addWidget( mDisplayNameWidget, 1, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
202
  label = new QLabel( i18nc( "@label The nickname of a contact", "Nickname:" ) );
203
204
205
206
207
208
209
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  nameLayout->addWidget( label, 2, 0 );

  mNickNameWidget = new KLineEdit;
  label->setBuddy( mNickNameWidget );
  nameLayout->addWidget( mNickNameWidget, 2, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
210
  label = new QLabel( i18nc( "@label The pronunciation of a contact's name", "Pronunciation:" ) );
211
212
213
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  nameLayout->addWidget( label, 3, 0 );

214
215
216
  mPronunciationWidget = new SoundEditWidget;
  label->setBuddy( mPronunciationWidget );
  nameLayout->addWidget( mPronunciationWidget, 3, 1 );
217
218
219

  nameLayout->setRowStretch( 4, 1 );

Allen Winter's avatar
Allen Winter committed
220
  // setup Internet group box
Tobias Koenig's avatar
Tobias Koenig committed
221
  label = new QLabel( i18nc( "@label The email address of a contact", "Email:" ) );
222
223
224
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  internetLayout->addWidget( label, 0, 0 );

225
  mEmailWidget = new EmailEditWidget;
226
227
228
  label->setBuddy( mEmailWidget );
  internetLayout->addWidget( mEmailWidget, 0, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
229
  label = new QLabel( i18nc( "@label The homepage URL of a contact", "Homepage:" ) );
230
231
232
233
234
235
236
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  internetLayout->addWidget( label, 1, 0 );

  mHomepageWidget = new KLineEdit;
  label->setBuddy( mHomepageWidget );
  internetLayout->addWidget( mHomepageWidget, 1, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
237
  label = new QLabel( i18nc( "@label The blog URL of a contact", "Blog:" ) );
238
239
240
241
242
243
244
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  internetLayout->addWidget( label, 2, 0 );

  mBlogWidget = new KLineEdit;
  label->setBuddy( mBlogWidget );
  internetLayout->addWidget( mBlogWidget, 2, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
245
  label = new QLabel( i18nc( "@label The instant messaging address of a contact", "Messaging:" ) );
246
247
248
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  internetLayout->addWidget( label, 3, 0 );

Tobias Koenig's avatar
Tobias Koenig committed
249
  mIMWidget = new IMEditWidget;
250
251
252
253
254
255
  label->setBuddy( mIMWidget );
  internetLayout->addWidget( mIMWidget, 3, 1 );

  internetLayout->setRowStretch( 4, 1 );

  // setup phones group box
256
  mPhonesWidget = new PhoneEditWidget;
257
258
  phonesLayout->addWidget( mPhonesWidget, 0, 0 );

259
  //phonesLayout->setRowStretch( 1, 1 );
Tobias Koenig's avatar
Tobias Koenig committed
260
261

  // setup categories section
262
  const bool nepomukInitialized( Nepomuk::ResourceManager::instance()->initialized() );
Tobias Koenig's avatar
Tobias Koenig committed
263
  QHBoxLayout *categoriesLayout = new QHBoxLayout;
Tobias Koenig's avatar
Tobias Koenig committed
264
  label = new QLabel( i18nc( "@label The categories of a contact", "Categories:" ) );
Tobias Koenig's avatar
Tobias Koenig committed
265
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
266
  label->setVisible( nepomukInitialized );
Tobias Koenig's avatar
Tobias Koenig committed
267
268

  mCategoriesWidget = new CategoriesEditWidget;
269
  mCategoriesWidget->setVisible( nepomukInitialized );
Tobias Koenig's avatar
Tobias Koenig committed
270
271
272
273
274
  label->setBuddy( mCategoriesWidget );

  categoriesLayout->addWidget( label );
  categoriesLayout->addWidget( mCategoriesWidget );

275
  layout->addLayout( categoriesLayout, 1, 1 );
276
277
278
279
280
281

  QHBoxLayout *mailPreferFormattingLayout = new QHBoxLayout;
  label = new QLabel( i18n( "Prefers to receive messages formatted as:" ) );
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  mMailPreferFormatting = new KComboBox;
  QStringList listFormat;
282
  listFormat << i18n( "Unknown" ) << i18n( "Plain Text" ) << i18n( "HTML" );
283
284
285
286
287
288
289
290
291
  mMailPreferFormatting->addItems( listFormat );
  mailPreferFormattingLayout->addWidget( label );
  mailPreferFormattingLayout->addWidget( mMailPreferFormatting );
  layout->addLayout( mailPreferFormattingLayout, 2, 1 );

  mAllowRemoteContent = new QCheckBox( i18n( "Allow remote content." ) );
  layout->addWidget( mAllowRemoteContent, 3,1 );

  layout->setRowStretch( 4,1 );
292
293
}

294
void ContactEditorWidget::Private::initGuiLocationTab()
295
296
{
  QWidget *widget = new QWidget;
297
  QHBoxLayout *layout = new QHBoxLayout( widget );
298

Tobias Koenig's avatar
Tobias Koenig committed
299
  mTabWidget->addTab( widget, i18nc( "@title:tab", "Location" ) );
300

Tobias Koenig's avatar
Tobias Koenig committed
301
302
  QGroupBox *addressesGroupBox = new QGroupBox( i18nc( "@title:group", "Addresses" ) );
  QGroupBox *coordinatesGroupBox = new QGroupBox( i18nc( "@title:group", "Coordinates" ) );
303
304
305
306
307
308
309
310
311
312
313
314
315
316

  layout->addWidget( addressesGroupBox );
  layout->addWidget( coordinatesGroupBox );

  QGridLayout *addressesLayout = new QGridLayout( addressesGroupBox );
  QGridLayout *coordinatesLayout = new QGridLayout( coordinatesGroupBox );

  // setup addresses group box
  mAddressesWidget = new AddressEditWidget( addressesGroupBox );
  mAddressesWidget->setMinimumHeight( 200 );
  addressesLayout->addWidget( mAddressesWidget, 0, 0 );
  addressesLayout->setRowStretch( 1, 1 );

  // setup coordinates group box
317
  mCoordinatesWidget = new GeoEditWidget;
318
319
320
321
  coordinatesLayout->addWidget( mCoordinatesWidget, 0, 0 );
  coordinatesLayout->setRowStretch( 1, 1 );
}

322
void ContactEditorWidget::Private::initGuiBusinessTab()
323
324
325
326
{
  QWidget *widget = new QWidget;
  QVBoxLayout *layout = new QVBoxLayout( widget );

Tobias Koenig's avatar
Tobias Koenig committed
327
  mTabWidget->addTab( widget, i18nc( "@title:tab", "Business" ) );
328

Tobias Koenig's avatar
Tobias Koenig committed
329
  QGroupBox *generalGroupBox = new QGroupBox( i18nc( "@title:group General properties of a contact", "General" ) );
Tobias Koenig's avatar
Tobias Koenig committed
330
  QGroupBox *groupwareGroupBox = new QGroupBox( i18nc( "@title:group", "Groupware" ) );
331
332
333
334
335
336
337
338
339
340

  layout->addWidget( generalGroupBox );
  layout->addWidget( groupwareGroupBox );

  QGridLayout *generalLayout = new QGridLayout( generalGroupBox );
  QGridLayout *groupwareLayout = new QGridLayout( groupwareGroupBox );

  QLabel *label = 0;

  // setup general group box
341
342
343
  mLogoWidget = new ImageWidget( ImageWidget::Logo );
  generalLayout->addWidget( mLogoWidget, 0, 2, 6, 1, Qt::AlignTop );

Tobias Koenig's avatar
Tobias Koenig committed
344
  label = new QLabel( i18nc( "@label The organization of a contact", "Organization:" ) );
345
346
347
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  generalLayout->addWidget( label, 0, 0 );

348
349
350
351
  mOrganizationWidget = new KLineEdit;
  label->setBuddy( mOrganizationWidget );
  generalLayout->addWidget( mOrganizationWidget, 0, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
352
  label = new QLabel( i18nc( "@label The profession of a contact", "Profession:" ) );
353
354
355
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  generalLayout->addWidget( label, 1, 0 );

356
357
  mProfessionWidget = new KLineEdit;
  label->setBuddy( mProfessionWidget );
358
  generalLayout->addWidget( mProfessionWidget, 1, 1 );
359

Tobias Koenig's avatar
Tobias Koenig committed
360
  label = new QLabel( i18nc( "@label The title of a contact", "Title:" ) );
361
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
362
  generalLayout->addWidget( label, 2, 0 );
363
364
365

  mTitleWidget = new KLineEdit;
  label->setBuddy( mTitleWidget );
366
  generalLayout->addWidget( mTitleWidget , 2, 1 );
367

Tobias Koenig's avatar
Tobias Koenig committed
368
  label = new QLabel( i18nc( "@label The department of a contact", "Department:" ) );
369
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
370
  generalLayout->addWidget( label, 3, 0 );
371
372
373

  mDepartmentWidget = new KLineEdit;
  label->setBuddy( mDepartmentWidget );
374
  generalLayout->addWidget( mDepartmentWidget, 3, 1 );
375

Tobias Koenig's avatar
Tobias Koenig committed
376
  label = new QLabel( i18nc( "@label The office of a contact", "Office:" ) );
377
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
378
  generalLayout->addWidget( label, 4, 0 );
379
380
381

  mOfficeWidget = new KLineEdit;
  label->setBuddy( mOfficeWidget );
382
  generalLayout->addWidget( mOfficeWidget, 4, 1 );
383

Tobias Koenig's avatar
Tobias Koenig committed
384
  label = new QLabel( i18nc( "@label The manager's name of a contact", "Manager's name:" ) );
385
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
386
  generalLayout->addWidget( label, 5, 0 );
387
388
389

  mManagerWidget = new KLineEdit;
  label->setBuddy( mManagerWidget );
390
  generalLayout->addWidget( mManagerWidget, 5, 1 );
391

Tobias Koenig's avatar
Tobias Koenig committed
392
  label = new QLabel( i18nc( "@label The assistant's name of a contact", "Assistant's name:" ) );
393
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
394
  generalLayout->addWidget( label, 6, 0 );
395
396
397

  mAssistantWidget = new KLineEdit;
  label->setBuddy( mAssistantWidget );
398
  generalLayout->addWidget( mAssistantWidget, 6, 1 );
399
400

  // setup groupware group box
Tobias Koenig's avatar
Tobias Koenig committed
401
  label = new QLabel( i18nc( "@label The free/busy information of a contact", "Free/Busy:" ) );
402
403
404
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  groupwareLayout->addWidget( label, 0, 0 );

405
  mFreeBusyWidget = new FreeBusyEditWidget;
406
407
  label->setBuddy( mFreeBusyWidget );
  groupwareLayout->addWidget( mFreeBusyWidget, 0, 1 );
408
  groupwareLayout->setRowStretch( 1, 1 );
409
410
}

411
void ContactEditorWidget::Private::initGuiPersonalTab()
412
413
414
415
{
  QWidget *widget = new QWidget;
  QVBoxLayout *layout = new QVBoxLayout( widget );

Tobias Koenig's avatar
Tobias Koenig committed
416
  mTabWidget->addTab( widget, i18nc( "@title:tab Personal properties of a contact", "Personal" ) );
417

Tobias Koenig's avatar
Tobias Koenig committed
418
419
  QGroupBox *datesGroupBox = new QGroupBox( i18nc( "@title:group Date related properties of a contact", "Dates" ) );
  QGroupBox *familyGroupBox = new QGroupBox( i18nc( "@title:group Family related properties of a contact", "Family" ) );
420
421
422
423
424
425
426
427
428
429

  layout->addWidget( datesGroupBox );
  layout->addWidget( familyGroupBox );

  QGridLayout *datesLayout = new QGridLayout( datesGroupBox );
  QGridLayout *familyLayout = new QGridLayout( familyGroupBox );

  QLabel *label = 0;

  // setup dates group box
Tobias Koenig's avatar
Tobias Koenig committed
430
  label = new QLabel( i18nc( "@label The birthdate of a contact", "Birthdate:" ) );
431
432
433
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  datesLayout->addWidget( label, 0, 0 );

434
  mBirthdateWidget = new DateEditWidget( DateEditWidget::Birthday );
435
436
437
  label->setBuddy( mBirthdateWidget );
  datesLayout->addWidget( mBirthdateWidget, 0, 1 );

Tobias Koenig's avatar
Tobias Koenig committed
438
  label = new QLabel( i18nc( "@label The anniversary of a contact", "Anniversary:" ) );
439
440
441
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  datesLayout->addWidget( label, 1, 0 );

442
  mAnniversaryWidget = new DateEditWidget( DateEditWidget::Anniversary );
443
444
445
446
  label->setBuddy( mAnniversaryWidget );
  datesLayout->addWidget( mAnniversaryWidget, 1, 1 );

  datesLayout->setRowStretch( 2, 1 );
447
  datesLayout->setColumnStretch( 1, 1 );
448
449

  // widgets from family group
Tobias Koenig's avatar
Tobias Koenig committed
450
  label = new QLabel( i18nc( "@label The partner's name of a contact", "Partner's name:" ) );
451
452
453
454
455
456
457
458
459
460
  label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
  familyLayout->addWidget( label, 0, 0 );

  mPartnerWidget = new KLineEdit;
  label->setBuddy( mPartnerWidget );
  familyLayout->addWidget( mPartnerWidget, 0, 1 );

  familyLayout->setRowStretch( 1, 1 );
}

461
462
463
464
465
466
467
468
void ContactEditorWidget::Private::initGuiNotesTab()
{
  QWidget *widget = new QWidget;
  QVBoxLayout *layout = new QVBoxLayout( widget );

  mTabWidget->addTab( widget, i18nc( "@title:tab", "Notes" ) );

  mNotesWidget = new KTextEdit;
469
  mNotesWidget->setAcceptRichText(false);
470
471
472
  layout->addWidget( mNotesWidget );
}

473
474
475
476
477
void ContactEditorWidget::Private::initGuiCustomFieldsTab()
{
  QWidget *widget = new QWidget;
  QVBoxLayout *layout = new QVBoxLayout( widget );

Tobias Koenig's avatar
Tobias Koenig committed
478
  mTabWidget->addTab( widget, i18nc( "@title:tab", "Custom Fields" ) );
479
480
481
482
483

  mCustomFieldsWidget = new CustomFieldsEditWidget;
  layout->addWidget( mCustomFieldsWidget );
}

484
485
486
487
488
void ContactEditorWidget::Private::loadCustomPages()
{
  qDeleteAll( mCustomPages );
  mCustomPages.clear();

489
  const QString pluginDirectory = KStandardDirs::locate( "lib", QLatin1String( "akonadi/contact/editorpageplugins/" ) );
490
491
492
  QDirIterator it( pluginDirectory, QDir::Files );
  while ( it.hasNext() ) {
    QPluginLoader loader( it.next() );
493
    if ( !loader.load() ) {
494
      continue;
495
    }
496
497

    Akonadi::ContactEditorPagePlugin *plugin = qobject_cast<Akonadi::ContactEditorPagePlugin*>( loader.instance() );
498
    if ( !plugin ) {
499
      continue;
500
    }
501
502
503
504

    mCustomPages.append( plugin );
  }

505
  foreach ( Akonadi::ContactEditorPagePlugin *plugin, mCustomPages ) {
506
    mTabWidget->addTab( plugin, plugin->title() );
507
  }
508
509
}

510
QString ContactEditorWidget::Private::loadCustom( const KABC::Addressee &contact, const QString &key ) const
511
{
512
  return contact.custom( QLatin1String( "KADDRESSBOOK" ), key );
513
514
}

515
void ContactEditorWidget::Private::storeCustom( KABC::Addressee &contact, const QString &key, const QString &value ) const
516
{
517
  if ( value.isEmpty() ) {
518
    contact.removeCustom( QLatin1String( "KADDRESSBOOK" ), key );
519
  } else {
520
    contact.insertCustom( QLatin1String( "KADDRESSBOOK" ), key, value );
521
  }
522
}
523

524
ContactEditorWidget::ContactEditorWidget( QWidget* )
525
526
527
528
529
530
531
532
533
534
535
536
  : d( new Private( FullMode, this ) )
{
  d->initGui();

  connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
           d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
  connect( d->mOrganizationWidget, SIGNAL(textChanged(QString)),
           d->mDisplayNameWidget, SLOT(changeOrganization(QString)) );
}

ContactEditorWidget::ContactEditorWidget( ContactEditorWidget::DisplayMode displayMode, QWidget * )
  : d( new Private( displayMode, this ) )
537
538
{
  d->initGui();
539

Laurent Montel's avatar
Laurent Montel committed
540
541
542
543
  connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
           d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
  connect( d->mOrganizationWidget, SIGNAL(textChanged(QString)),
           d->mDisplayNameWidget, SLOT(changeOrganization(QString)) );
544
545
}

546
ContactEditorWidget::~ContactEditorWidget()
547
{
Laurent Montel's avatar
Laurent Montel committed
548
  delete d;
549
550
}

551
void ContactEditorWidget::loadContact( const KABC::Addressee &contact, const Akonadi::ContactMetaData &metaData )
552
{
553
  // name group
554
  d->mPhotoWidget->loadContact( contact );
555
556
  d->mNameWidget->loadContact( contact );
  d->mDisplayNameWidget->loadContact( contact );
557
  d->mNickNameWidget->setText( contact.nickName() );
558
  d->mPronunciationWidget->loadContact( contact );
559

Allen Winter's avatar
Allen Winter committed
560
  // Internet group
561
  d->mEmailWidget->loadContact( contact );
562
  d->mHomepageWidget->setUrl( contact.url() );
563
  d->mBlogWidget->setText( d->loadCustom( contact, QLatin1String( "BlogFeed" ) ) );
Tobias Koenig's avatar
Tobias Koenig committed
564
  d->mIMWidget->loadContact( contact );
565
566

  // phones group
567
  d->mPhonesWidget->loadContact( contact );
568

Tobias Koenig's avatar
Tobias Koenig committed
569
570
571
  // categories section
  d->mCategoriesWidget->loadContact( contact );

572
573

  const QString mailPreferedFormatting = d->loadCustom( contact, QLatin1String( "MailPreferedFormatting" ) );
574
  if ( mailPreferedFormatting.isEmpty() ) {
575
    d->mMailPreferFormatting->setCurrentIndex( 0 );
576
  } else if ( mailPreferedFormatting == QLatin1String( "TEXT" ) ) {
577
    d->mMailPreferFormatting->setCurrentIndex( 1 );
578
  } else if ( mailPreferedFormatting == QLatin1String( "HTML" ) ) {
579
    d->mMailPreferFormatting->setCurrentIndex( 2 );
580
  } else {
581
    d->mMailPreferFormatting->setCurrentIndex( 0 );
582
  }
583
584
585
586

  const QString mailAllowToRemoteContent = d->loadCustom( contact, QLatin1String( "MailAllowToRemoteContent" ) );
  d->mAllowRemoteContent->setChecked( mailAllowToRemoteContent == QLatin1String( "TRUE" ) );

587
  // address group
588
  d->mAddressesWidget->loadContact( contact );
589
590

  // coordinates group
591
  d->mCoordinatesWidget->loadContact( contact );
592
593

  // general group
594
  d->mLogoWidget->loadContact( contact );
595
  d->mOrganizationWidget->setText( contact.organization() );
596
  d->mProfessionWidget->setText( d->loadCustom( contact, QLatin1String( "X-Profession" ) ) );
597
598
  d->mTitleWidget->setText( contact.title() );
  d->mDepartmentWidget->setText( contact.department() );
599
600
601
  d->mOfficeWidget->setText( d->loadCustom( contact, QLatin1String( "X-Office" ) ) );
  d->mManagerWidget->setText( d->loadCustom( contact, QLatin1String( "X-ManagersName" ) ) );
  d->mAssistantWidget->setText( d->loadCustom( contact, QLatin1String( "X-AssistantsName" ) ) );
602
603

  // groupware group
604
  d->mFreeBusyWidget->loadContact( contact );
605
606
607
608
609

  // notes group
  d->mNotesWidget->setPlainText( contact.note() );

  // dates group
610
  d->mBirthdateWidget->setDate( contact.birthday().date() );
611
612
  d->mAnniversaryWidget->setDate( QDate::fromString( d->loadCustom( contact, QLatin1String( "X-Anniversary" ) ),
                                                     Qt::ISODate ) );
613
614

  // family group
615
  d->mPartnerWidget->setText( d->loadCustom( contact, QLatin1String( "X-SpousesName" ) ) );
616
617

  d->mDisplayNameWidget->setDisplayType( (DisplayNameEditWidget::DisplayType)metaData.displayNameMode() );
618

619
620
621
622
  if(d->mDisplayMode == FullMode) {
    // custom fields group
    d->mCustomFieldsWidget->setLocalCustomFieldDescriptions( metaData.customFieldDescriptions() );
    d->mCustomFieldsWidget->loadContact( contact );
623

624
625
626
627
    // custom pages
    foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
      plugin->loadContact( contact );
    }
628
  }
629
630
}

631
void ContactEditorWidget::storeContact( KABC::Addressee &contact, Akonadi::ContactMetaData &metaData ) const
632
{
633
  // name group
634
  d->mPhotoWidget->storeContact( contact );
635
636
  d->mNameWidget->storeContact( contact );
  d->mDisplayNameWidget->storeContact( contact );
637
  contact.setNickName( d->mNickNameWidget->text().trimmed() );
638
  d->mPronunciationWidget->storeContact( contact );
639

Allen Winter's avatar
Allen Winter committed
640
  // Internet group
641
  d->mEmailWidget->storeContact( contact );
642
  contact.setUrl( KUrl( d->mHomepageWidget->text().trimmed() ) );
643
  d->storeCustom( contact, QLatin1String( "BlogFeed" ), d->mBlogWidget->text().trimmed() );
Tobias Koenig's avatar
Tobias Koenig committed
644
  d->mIMWidget->storeContact( contact );
645
646

  // phones group
647
  d->mPhonesWidget->storeContact( contact );
648

Tobias Koenig's avatar
Tobias Koenig committed
649
650
651
  // categories section
  d->mCategoriesWidget->storeContact( contact );

652
653
654
655
656
657
658
659
660
661
662
663
664
665


  QString mailPreferedFormatting;
  const int index = d->mMailPreferFormatting->currentIndex();
  if ( index == 0 ) {
    //Nothing => remove custom variable
  } else if ( index == 1 ) {
    mailPreferedFormatting = QLatin1String( "TEXT" );
  } else if ( index == 2 ) {
    mailPreferedFormatting = QLatin1String( "HTML" );
  }
  d->storeCustom( contact, QLatin1String( "MailPreferedFormatting" ), mailPreferedFormatting );

  QString mailAllowToRemoteContent;
666
  if ( d->mAllowRemoteContent->isChecked() ) {
667
    mailAllowToRemoteContent = QLatin1String( "TRUE" );
668
  }
669
670
  d->storeCustom( contact, QLatin1String( "MailAllowToRemoteContent" ), mailAllowToRemoteContent );

671
  // address group
672
  d->mAddressesWidget->storeContact( contact );
673
674

  // coordinates group
675
  d->mCoordinatesWidget->storeContact( contact );
676
677

  // general group
678
  d->mLogoWidget->storeContact( contact );
679
  contact.setOrganization( d->mOrganizationWidget->text() );
680
  d->storeCustom( contact, QLatin1String( "X-Profession" ), d->mProfessionWidget->text().trimmed() );
681
682
  contact.setTitle( d->mTitleWidget->text().trimmed() );
  contact.setDepartment( d->mDepartmentWidget->text().trimmed() );
683
684
685
  d->storeCustom( contact, QLatin1String( "X-Office" ), d->mOfficeWidget->text().trimmed() );
  d->storeCustom( contact, QLatin1String( "X-ManagersName" ), d->mManagerWidget->text().trimmed() );
  d->storeCustom( contact, QLatin1String( "X-AssistantsName" ), d->mAssistantWidget->text().trimmed() );
686
687

  // groupware group
688
  d->mFreeBusyWidget->storeContact( contact );
689
690
691
692
693

  // notes group
  contact.setNote( d->mNotesWidget->toPlainText() );

  // dates group
694
695
696
697
698
699
  QDateTime birthday = QDateTime( d->mBirthdateWidget->date(), QTime(), contact.birthday().timeSpec() );
  // This is needed because the constructor above sets the time component
  // of the QDateTime to midnight.  We want it to stay invalid.
  birthday.setTime( QTime() );

  contact.setBirthday( birthday );
700
  d->storeCustom( contact, QLatin1String( "X-Anniversary" ), d->mAnniversaryWidget->date().toString( Qt::ISODate ) );
701
702

  // family group
703
  d->storeCustom( contact, QLatin1String( "X-SpousesName" ), d->mPartnerWidget->text().trimmed() );
704

705
706
707
708
  if(d->mDisplayMode == FullMode) {
    // custom fields group
    d->mCustomFieldsWidget->storeContact( contact );
    metaData.setCustomFieldDescriptions( d->mCustomFieldsWidget->localCustomFieldDescriptions() );
709

710
    metaData.setDisplayNameMode( d->mDisplayNameWidget->displayType() );
711

712
713
714
715
    // custom pages
    foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
      plugin->storeContact( contact );
    }
716
  }
717
}
718
719
720
721
722
723
724
725
726
727

void ContactEditorWidget::setReadOnly( bool readOnly )
{
  // widgets from name group
  d->mNameWidget->setReadOnly( readOnly );
  d->mPhotoWidget->setReadOnly( readOnly );
  d->mDisplayNameWidget->setReadOnly( readOnly );
  d->mNickNameWidget->setReadOnly( readOnly );
  d->mPronunciationWidget->setReadOnly( readOnly );

Allen Winter's avatar
Allen Winter committed
728
  // widgets from Internet group
729
730
731
732
733
734
735
736
  d->mEmailWidget->setReadOnly( readOnly );
  d->mHomepageWidget->setReadOnly( readOnly );
  d->mBlogWidget->setReadOnly( readOnly );
  d->mIMWidget->setReadOnly( readOnly );

  // widgets from phones group
  d->mPhonesWidget->setReadOnly( readOnly );

Tobias Koenig's avatar
Tobias Koenig committed
737
738
739
  // widgets from categories section
  d->mCategoriesWidget->setReadOnly( readOnly );

740
  // Preferred Mail formatting option
741
742
743
  d->mMailPreferFormatting->setEnabled( !readOnly );
  d->mAllowRemoteContent->setEnabled( !readOnly );

744
745
746
747
  // widgets from addresses group
  d->mAddressesWidget->setReadOnly( readOnly );

  // widgets from coordinates group
748
  d->mCoordinatesWidget->setReadOnly( readOnly );
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

  // widgets from general group
  d->mLogoWidget->setReadOnly( readOnly );
  d->mOrganizationWidget->setReadOnly( readOnly );
  d->mProfessionWidget->setReadOnly( readOnly );
  d->mTitleWidget->setReadOnly( readOnly );
  d->mDepartmentWidget->setReadOnly( readOnly );
  d->mOfficeWidget->setReadOnly( readOnly );
  d->mManagerWidget->setReadOnly( readOnly );
  d->mAssistantWidget->setReadOnly( readOnly );

  // widgets from groupware group
  d->mFreeBusyWidget->setReadOnly( readOnly );

  // widgets from notes group
  d->mNotesWidget->setReadOnly( readOnly );

  // widgets from dates group
  d->mBirthdateWidget->setReadOnly( readOnly );
  d->mAnniversaryWidget->setReadOnly( readOnly );

  // widgets from family group
  d->mPartnerWidget->setReadOnly( readOnly );
772

773
774
775
  if(d->mDisplayMode == FullMode) {
    // widgets from custom fields group
    d->mCustomFieldsWidget->setReadOnly( readOnly );
776

777
778
779
780
    // custom pages
    foreach ( Akonadi::ContactEditorPagePlugin *plugin, d->mCustomPages ) {
      plugin->setReadOnly( readOnly );
    }
781
  }
782
}