22 #include "contacteditorwidget.h"
24 #include "addresseditwidget.h"
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"
35 #include "imeditwidget.h"
36 #include "nameeditwidget.h"
37 #include "phoneeditwidget.h"
38 #include "soundeditwidget.h"
41 #include <kconfiggroup.h>
42 #include <klineedit.h>
43 #include <klocalizedstring.h>
44 #include <kstandarddirs.h>
45 #include <ktabwidget.h>
46 #include <ktextedit.h>
48 #include <QtCore/QDirIterator>
49 #include <QtCore/QPluginLoader>
53 #include <QVBoxLayout>
55 class ContactEditorWidget::Private
59 : mDisplayMode(displayMode), mParent( parent ), mCustomFieldsWidget(0)
64 void initGuiContactTab();
65 void initGuiLocationTab();
66 void initGuiBusinessTab();
67 void initGuiPersonalTab();
68 void initGuiNotesTab();
69 void initGuiCustomFieldsTab();
71 void loadCustomPages();
73 QString loadCustom(
const KABC::Addressee &contact,
const QString &key )
const;
74 void storeCustom( KABC::Addressee &contact,
const QString &key,
const QString &value )
const;
78 KTabWidget *mTabWidget;
82 ImageWidget *mPhotoWidget;
84 KLineEdit *mNickNameWidget;
85 SoundEditWidget *mPronunciationWidget;
89 KLineEdit *mHomepageWidget;
90 KLineEdit *mBlogWidget;
98 KComboBox* mMailPreferFormatting;
105 GeoEditWidget *mCoordinatesWidget;
108 ImageWidget *mLogoWidget;
109 KLineEdit *mOrganizationWidget;
110 KLineEdit *mProfessionWidget;
111 KLineEdit *mTitleWidget;
112 KLineEdit *mDepartmentWidget;
113 KLineEdit *mOfficeWidget;
114 KLineEdit *mManagerWidget;
115 KLineEdit *mAssistantWidget;
118 FreeBusyEditWidget *mFreeBusyWidget;
121 KTextEdit *mNotesWidget;
124 DateEditWidget *mBirthdateWidget;
125 DateEditWidget *mAnniversaryWidget;
128 KLineEdit *mPartnerWidget;
131 CustomFieldsEditWidget *mCustomFieldsWidget;
137 void ContactEditorWidget::Private::initGui()
142 mTabWidget =
new KTabWidget( mParent );
146 initGuiLocationTab();
147 initGuiBusinessTab();
148 initGuiPersonalTab();
150 if (mDisplayMode == FullMode) {
151 initGuiCustomFieldsTab();
156 void ContactEditorWidget::Private::initGuiContactTab()
161 mTabWidget->addTab( widget, i18nc(
"@title:tab",
"Contact" ) );
163 QGroupBox *nameGroupBox =
new QGroupBox( i18nc(
"@title:group Name related properties of a contact",
"Name" ) );
169 layout->
addWidget( internetGroupBox, 0, 1 );
170 layout->
addWidget( phonesGroupBox, 1, 0, 4, 1 );
179 label =
new QLabel( i18nc(
"@label The name of a contact",
"Name:" ) );
180 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
185 nameLayout->
addWidget( mNameWidget, 0, 1 );
187 mPhotoWidget =
new ImageWidget( ImageWidget::Photo );
188 nameLayout->
addWidget( mPhotoWidget, 0, 2, 4, 1 );
190 label =
new QLabel( i18nc(
"@label The display name of a contact",
"Display:" ) );
191 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
195 label->
setBuddy( mDisplayNameWidget );
196 nameLayout->
addWidget( mDisplayNameWidget, 1, 1 );
198 label =
new QLabel( i18nc(
"@label The nickname of a contact",
"Nickname:" ) );
199 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
202 mNickNameWidget =
new KLineEdit;
203 mNickNameWidget->setTrapReturnKey(
true);
205 nameLayout->
addWidget( mNickNameWidget, 2, 1 );
207 label =
new QLabel( i18nc(
"@label The pronunciation of a contact's name",
"Pronunciation:" ) );
208 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
211 mPronunciationWidget =
new SoundEditWidget;
212 label->
setBuddy( mPronunciationWidget );
213 nameLayout->
addWidget( mPronunciationWidget, 3, 1 );
218 label =
new QLabel( i18nc(
"@label The email address of a contact",
"Email:" ) );
219 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
220 internetLayout->
addWidget( label, 0, 0 );
224 internetLayout->
addWidget( mEmailWidget, 0, 1 );
226 label =
new QLabel( i18nc(
"@label The homepage URL of a contact",
"Homepage:" ) );
227 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
228 internetLayout->
addWidget( label, 1, 0 );
230 mHomepageWidget =
new KLineEdit;
231 mHomepageWidget->setTrapReturnKey(
true);
233 internetLayout->
addWidget( mHomepageWidget, 1, 1 );
235 label =
new QLabel( i18nc(
"@label The blog URL of a contact",
"Blog:" ) );
236 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
237 internetLayout->
addWidget( label, 2, 0 );
239 mBlogWidget =
new KLineEdit;
240 mBlogWidget->setTrapReturnKey(
true);
242 internetLayout->
addWidget( mBlogWidget, 2, 1 );
244 label =
new QLabel( i18nc(
"@label The instant messaging address of a contact",
"Messaging:" ) );
245 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
246 internetLayout->
addWidget( label, 3, 0 );
250 internetLayout->
addWidget( mIMWidget, 3, 1 );
256 phonesLayout->
addWidget( mPhonesWidget, 0, 0 );
262 label =
new QLabel( i18nc(
"@label The categories of a contact",
"Categories:" ) );
263 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
266 label->
setBuddy( mCategoriesWidget );
269 categoriesLayout->
addWidget( mCategoriesWidget );
271 layout->
addLayout( categoriesLayout, 1, 1 );
274 layout->
addWidget( receivedMessageGroupBox, 2, 1 );
279 label =
new QLabel( i18n(
"Show messages received from this contact as:" ) );
280 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
281 mMailPreferFormatting =
new KComboBox;
282 label->
setBuddy( mMailPreferFormatting );
284 listFormat << i18n(
"Default" ) << i18n(
"Plain Text" ) << i18n(
"HTML" );
285 mMailPreferFormatting->addItems( listFormat );
286 mailPreferFormattingLayout->
addWidget( label );
287 mailPreferFormattingLayout->
addWidget( mMailPreferFormatting );
290 vbox->
addLayout( mailPreferFormattingLayout );
292 mAllowRemoteContent =
new QCheckBox( i18n(
"Allow remote content in received HTML messages" ) );
298 void ContactEditorWidget::Private::initGuiLocationTab()
303 mTabWidget->addTab( widget, i18nc(
"@title:tab",
"Location" ) );
306 QGroupBox *coordinatesGroupBox =
new QGroupBox( i18nc(
"@title:group",
"Coordinates" ) );
309 layout->
addWidget( coordinatesGroupBox );
316 mAddressesWidget->setMinimumHeight( 200 );
317 addressesLayout->
addWidget( mAddressesWidget, 0, 0 );
321 mCoordinatesWidget =
new GeoEditWidget;
322 coordinatesLayout->
addWidget( mCoordinatesWidget, 0, 0 );
326 void ContactEditorWidget::Private::initGuiBusinessTab()
331 mTabWidget->addTab( widget, i18nc(
"@title:tab",
"Business" ) );
333 QGroupBox *generalGroupBox =
new QGroupBox( i18nc(
"@title:group General properties of a contact",
"General" ) );
345 mLogoWidget =
new ImageWidget( ImageWidget::Logo );
346 generalLayout->
addWidget( mLogoWidget, 0, 2, 6, 1, Qt::AlignTop );
348 label =
new QLabel( i18nc(
"@label The organization of a contact",
"Organization:" ) );
349 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
352 mOrganizationWidget =
new KLineEdit;
353 mOrganizationWidget->setTrapReturnKey(
true);
354 label->
setBuddy( mOrganizationWidget );
355 generalLayout->
addWidget( mOrganizationWidget, 0, 1 );
357 label =
new QLabel( i18nc(
"@label The profession of a contact",
"Profession:" ) );
358 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
361 mProfessionWidget =
new KLineEdit;
362 mProfessionWidget->setTrapReturnKey(
true);
363 label->
setBuddy( mProfessionWidget );
364 generalLayout->
addWidget( mProfessionWidget, 1, 1 );
366 label =
new QLabel( i18nc(
"@label The title of a contact",
"Title:" ) );
367 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
370 mTitleWidget =
new KLineEdit;
371 mTitleWidget->setTrapReturnKey(
true);
373 generalLayout->
addWidget( mTitleWidget , 2, 1 );
375 label =
new QLabel( i18nc(
"@label The department of a contact",
"Department:" ) );
376 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
379 mDepartmentWidget =
new KLineEdit;
380 mDepartmentWidget->setTrapReturnKey(
true);
381 label->
setBuddy( mDepartmentWidget );
382 generalLayout->
addWidget( mDepartmentWidget, 3, 1 );
384 label =
new QLabel( i18nc(
"@label The office of a contact",
"Office:" ) );
385 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
388 mOfficeWidget =
new KLineEdit;
389 mOfficeWidget->setTrapReturnKey(
true);
391 generalLayout->
addWidget( mOfficeWidget, 4, 1 );
393 label =
new QLabel( i18nc(
"@label The manager's name of a contact",
"Manager's name:" ) );
394 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
397 mManagerWidget =
new KLineEdit;
398 mManagerWidget->setTrapReturnKey(
true);
400 generalLayout->
addWidget( mManagerWidget, 5, 1 );
402 label =
new QLabel( i18nc(
"@label The assistant's name of a contact",
"Assistant's name:" ) );
403 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
406 mAssistantWidget =
new KLineEdit;
407 mAssistantWidget->setTrapReturnKey(
true);
408 label->
setBuddy( mAssistantWidget );
409 generalLayout->
addWidget( mAssistantWidget, 6, 1 );
412 label =
new QLabel( i18nc(
"@label The free/busy information of a contact",
"Free/Busy:" ) );
413 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
414 groupwareLayout->
addWidget( label, 0, 0 );
416 mFreeBusyWidget =
new FreeBusyEditWidget;
418 groupwareLayout->
addWidget( mFreeBusyWidget, 0, 1 );
422 void ContactEditorWidget::Private::initGuiPersonalTab()
427 mTabWidget->addTab( widget, i18nc(
"@title:tab Personal properties of a contact",
"Personal" ) );
429 QGroupBox *datesGroupBox =
new QGroupBox( i18nc(
"@title:group Date related properties of a contact",
"Dates" ) );
430 QGroupBox *familyGroupBox =
new QGroupBox( i18nc(
"@title:group Family related properties of a contact",
"Family" ) );
441 label =
new QLabel( i18nc(
"@label The birthdate of a contact",
"Birthdate:" ) );
442 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
445 mBirthdateWidget =
new DateEditWidget( DateEditWidget::Birthday );
446 label->
setBuddy( mBirthdateWidget );
447 datesLayout->
addWidget( mBirthdateWidget, 0, 1 );
449 label =
new QLabel( i18nc(
"@label The wedding anniversary of a contact",
"Anniversary:" ) );
450 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
453 mAnniversaryWidget =
new DateEditWidget( DateEditWidget::Anniversary );
454 label->
setBuddy( mAnniversaryWidget );
455 datesLayout->
addWidget( mAnniversaryWidget, 1, 1 );
461 label =
new QLabel( i18nc(
"@label The partner's name of a contact",
"Partner's name:" ) );
462 label->
setAlignment( Qt::AlignRight | Qt::AlignVCenter );
465 mPartnerWidget =
new KLineEdit;
466 mPartnerWidget->setTrapReturnKey(
true);
468 familyLayout->
addWidget( mPartnerWidget, 0, 1 );
473 void ContactEditorWidget::Private::initGuiNotesTab()
478 mTabWidget->addTab( widget, i18nc(
"@title:tab",
"Notes" ) );
480 mNotesWidget =
new KTextEdit;
481 mNotesWidget->setAcceptRichText(
false);
485 void ContactEditorWidget::Private::initGuiCustomFieldsTab()
490 mTabWidget->addTab( widget, i18nc(
"@title:tab",
"Custom Fields" ) );
492 mCustomFieldsWidget =
new CustomFieldsEditWidget;
493 layout->
addWidget( mCustomFieldsWidget );
496 void ContactEditorWidget::Private::loadCustomPages()
498 qDeleteAll( mCustomPages );
499 mCustomPages.clear();
501 const QString pluginDirectory = KStandardDirs::locate(
"lib",
QLatin1String(
"akonadi/contact/editorpageplugins/" ) );
503 while ( it.hasNext() ) {
505 if ( !loader.load() ) {
514 mCustomPages.append( plugin );
518 mTabWidget->addTab( plugin, plugin->
title() );
522 QString ContactEditorWidget::Private::loadCustom(
const KABC::Addressee &contact,
const QString &key )
const
524 return contact.custom(
QLatin1String(
"KADDRESSBOOK" ), key );
527 void ContactEditorWidget::Private::storeCustom( KABC::Addressee &contact,
const QString &key,
const QString &value )
const
530 contact.removeCustom(
QLatin1String(
"KADDRESSBOOK" ), key );
532 contact.insertCustom(
QLatin1String(
"KADDRESSBOOK" ), key, value );
537 : d( new Private( FullMode, this ) )
541 connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
542 d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
544 d->mDisplayNameWidget, SLOT(changeOrganization(
QString)) );
548 : d( new Private( displayMode, this ) )
552 connect( d->mNameWidget, SIGNAL(nameChanged(KABC::Addressee)),
553 d->mDisplayNameWidget, SLOT(changeName(KABC::Addressee)) );
555 d->mDisplayNameWidget, SLOT(changeOrganization(
QString)) );
566 d->mPhotoWidget->loadContact( contact );
567 d->mNameWidget->loadContact( contact );
568 d->mDisplayNameWidget->loadContact( contact );
569 d->mNickNameWidget->setText( contact.nickName() );
570 d->mPronunciationWidget->loadContact( contact );
573 d->mEmailWidget->loadContact( contact );
574 d->mHomepageWidget->setUrl( contact.url() );
575 d->mBlogWidget->setText( d->loadCustom( contact,
QLatin1String(
"BlogFeed" ) ) );
576 d->mIMWidget->loadContact( contact );
579 d->mPhonesWidget->loadContact( contact );
582 d->mCategoriesWidget->loadContact( contact );
584 const QString mailPreferedFormatting = d->loadCustom( contact,
QLatin1String(
"MailPreferedFormatting" ) );
585 if ( mailPreferedFormatting.
isEmpty() ) {
586 d->mMailPreferFormatting->setCurrentIndex( 0 );
587 }
else if ( mailPreferedFormatting ==
QLatin1String(
"TEXT" ) ) {
588 d->mMailPreferFormatting->setCurrentIndex( 1 );
589 }
else if ( mailPreferedFormatting ==
QLatin1String(
"HTML" ) ) {
590 d->mMailPreferFormatting->setCurrentIndex( 2 );
592 d->mMailPreferFormatting->setCurrentIndex( 0 );
595 const QString mailAllowToRemoteContent = d->loadCustom( contact,
QLatin1String(
"MailAllowToRemoteContent" ) );
596 d->mAllowRemoteContent->setChecked( mailAllowToRemoteContent ==
QLatin1String(
"TRUE" ) );
599 d->mAddressesWidget->loadContact( contact );
602 d->mCoordinatesWidget->loadContact( contact );
605 d->mLogoWidget->loadContact( contact );
606 d->mOrganizationWidget->setText( contact.organization() );
607 d->mProfessionWidget->setText( d->loadCustom( contact,
QLatin1String(
"X-Profession" ) ) );
608 d->mTitleWidget->setText( contact.title() );
609 d->mDepartmentWidget->setText( contact.department() );
610 d->mOfficeWidget->setText( d->loadCustom( contact,
QLatin1String(
"X-Office" ) ) );
611 d->mManagerWidget->setText( d->loadCustom( contact,
QLatin1String(
"X-ManagersName" ) ) );
612 d->mAssistantWidget->setText( d->loadCustom( contact,
QLatin1String(
"X-AssistantsName" ) ) );
615 d->mFreeBusyWidget->loadContact( contact );
618 d->mNotesWidget->setPlainText( contact.note() );
621 d->mBirthdateWidget->setDate( contact.birthday().date() );
626 d->mPartnerWidget->setText( d->loadCustom( contact,
QLatin1String(
"X-SpousesName" ) ) );
633 d->mCustomFieldsWidget->loadContact( contact );
645 d->mPhotoWidget->storeContact( contact );
646 d->mNameWidget->storeContact( contact );
647 d->mDisplayNameWidget->storeContact( contact );
648 contact.setNickName( d->mNickNameWidget->text().trimmed() );
649 d->mPronunciationWidget->storeContact( contact );
652 d->mEmailWidget->storeContact( contact );
653 contact.setUrl( KUrl( d->mHomepageWidget->text().trimmed() ) );
654 d->storeCustom( contact,
QLatin1String(
"BlogFeed" ), d->mBlogWidget->text().trimmed() );
655 d->mIMWidget->storeContact( contact );
658 d->mPhonesWidget->storeContact( contact );
661 d->mCategoriesWidget->storeContact( contact );
663 QString mailPreferedFormatting;
664 const int index = d->mMailPreferFormatting->currentIndex();
667 }
else if ( index == 1 ) {
669 }
else if ( index == 2 ) {
672 d->storeCustom( contact,
QLatin1String(
"MailPreferedFormatting" ), mailPreferedFormatting );
674 QString mailAllowToRemoteContent;
675 if ( d->mAllowRemoteContent->isChecked() ) {
678 d->storeCustom( contact,
QLatin1String(
"MailAllowToRemoteContent" ), mailAllowToRemoteContent );
681 d->mAddressesWidget->storeContact( contact );
684 d->mCoordinatesWidget->storeContact( contact );
687 d->mLogoWidget->storeContact( contact );
688 contact.setOrganization( d->mOrganizationWidget->text() );
689 d->storeCustom( contact,
QLatin1String(
"X-Profession" ), d->mProfessionWidget->text().trimmed() );
690 contact.setTitle( d->mTitleWidget->text().trimmed() );
691 contact.setDepartment( d->mDepartmentWidget->text().trimmed() );
692 d->storeCustom( contact,
QLatin1String(
"X-Office" ), d->mOfficeWidget->text().trimmed() );
693 d->storeCustom( contact,
QLatin1String(
"X-ManagersName" ), d->mManagerWidget->text().trimmed() );
694 d->storeCustom( contact,
QLatin1String(
"X-AssistantsName" ), d->mAssistantWidget->text().trimmed() );
697 d->mFreeBusyWidget->storeContact( contact );
700 contact.setNote( d->mNotesWidget->toPlainText() );
708 contact.setBirthday( birthday );
709 d->storeCustom( contact,
QLatin1String(
"X-Anniversary" ), d->mAnniversaryWidget->date().toString( Qt::ISODate ) );
712 d->storeCustom( contact,
QLatin1String(
"X-SpousesName" ), d->mPartnerWidget->text().trimmed() );
716 d->mCustomFieldsWidget->storeContact( contact );
731 d->mNameWidget->setReadOnly( readOnly );
732 d->mPhotoWidget->setReadOnly( readOnly );
733 d->mDisplayNameWidget->setReadOnly( readOnly );
734 d->mNickNameWidget->setReadOnly( readOnly );
735 d->mPronunciationWidget->setReadOnly( readOnly );
738 d->mEmailWidget->setReadOnly( readOnly );
739 d->mHomepageWidget->setReadOnly( readOnly );
740 d->mBlogWidget->setReadOnly( readOnly );
741 d->mIMWidget->setReadOnly( readOnly );
744 d->mPhonesWidget->setReadOnly( readOnly );
747 d->mCategoriesWidget->setReadOnly( readOnly );
750 d->mMailPreferFormatting->setEnabled( !readOnly );
751 d->mAllowRemoteContent->setEnabled( !readOnly );
754 d->mAddressesWidget->setReadOnly( readOnly );
757 d->mCoordinatesWidget->setReadOnly( readOnly );
760 d->mLogoWidget->setReadOnly( readOnly );
761 d->mOrganizationWidget->setReadOnly( readOnly );
762 d->mProfessionWidget->setReadOnly( readOnly );
763 d->mTitleWidget->setReadOnly( readOnly );
764 d->mDepartmentWidget->setReadOnly( readOnly );
765 d->mOfficeWidget->setReadOnly( readOnly );
766 d->mManagerWidget->setReadOnly( readOnly );
767 d->mAssistantWidget->setReadOnly( readOnly );
770 d->mFreeBusyWidget->setReadOnly( readOnly );
773 d->mNotesWidget->setReadOnly( readOnly );
776 d->mBirthdateWidget->setReadOnly( readOnly );
777 d->mAnniversaryWidget->setReadOnly( readOnly );
780 d->mPartnerWidget->setReadOnly( readOnly );
784 d->mCustomFieldsWidget->setReadOnly( readOnly );
virtual void loadContact(const KABC::Addressee &contact)=0
This method is called to fill the editor widget with the data from contact.
void setTime(const QTime &time)
void setAlignment(QFlags< Qt::AlignmentFlag >)
The base class for custom ContactEditor page plugins.
void setBuddy(QWidget *buddy)
QDate fromString(const QString &string, Qt::DateFormat format)
void setRowStretch(int row, int stretch)
virtual void storeContact(KABC::Addressee &contact) const =0
This method is called to store the data from the editor widget into contact.
void setMargin(int margin)
virtual QString title() const =0
Returns the i18n'd page title.
void addLayout(QLayout *layout, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
void setColumnStretch(int column, int stretch)
virtual void setReadOnly(bool readOnly)=0
This method is called to set the editor widget readOnly.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addLayout(QLayout *layout, int stretch)