kopete/kopete
identitydialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "identitydialog.h"
00021 #include "ui_identitygeneral.h"
00022 #include "ui_identitydetailed.h"
00023
00024 #include <KIcon>
00025 #include <kopeteidentity.h>
00026 #include <avatardialog.h>
00027
00028 class IdentityDialog::Private
00029 {
00030 public:
00031 Kopete::Identity *identity;
00032 Kopete::Global::Properties *props;
00033 Ui::IdentityGeneral general;
00034 Ui::IdentityDetailed detailed;
00035 QString photoPath;
00036 };
00037
00038 IdentityDialog::IdentityDialog(Kopete::Identity *identity, QWidget *parent)
00039 : Kopete::UI::InfoDialog(parent, i18n("Identity Information"), "identity")
00040 {
00041 Q_ASSERT(identity);
00042
00043 setTitle(identity->label());
00044 setWindowTitle(i18n("Identity Information"));
00045
00046 d = new Private();
00047 d->identity = identity;
00048 d->props = Kopete::Global::Properties::self();
00049
00050
00051 QWidget *w = new QWidget(this);
00052 d->general.setupUi(w);
00053 d->general.selectPhoto->setIcon(KIcon("view-preview"));
00054 d->general.clearPhoto->setIcon(KIcon("edit-clear-locationbar-rtl"));
00055
00056 connect(d->general.selectPhoto, SIGNAL(clicked(bool)),
00057 this, SLOT(slotSelectPhoto()));
00058 connect(d->general.photo, SIGNAL(linkActivated(const QString&)),
00059 this, SLOT(slotSelectPhoto()));
00060 connect(d->general.clearPhoto, SIGNAL(clicked(bool)),
00061 this, SLOT(slotClearPhoto()));
00062 addWidget(w, i18n("General Information"));
00063
00064
00065 w = new QWidget(this);
00066 d->detailed.setupUi(w);
00067 addWidget(w, i18n("Detailed Information"));
00068
00069 setIcon(KIcon(d->identity->customIcon()));
00070
00071 load();
00072 }
00073
00074 IdentityDialog::~IdentityDialog()
00075 {
00076 delete d;
00077 }
00078
00079 void IdentityDialog::load()
00080 {
00081
00082
00083 if (d->identity->hasProperty( d->props->photo().key() ))
00084 setPhoto( d->identity->property(d->props->photo()).value().toString() );
00085
00086
00087
00088 d->general.label->setText( d->identity->label() );
00089
00090
00091 if (d->identity->hasProperty( d->props->nickName().key() ))
00092 d->general.nickName->setText( d->identity->property(d->props->nickName()).value().toString() );
00093
00094
00095 if (d->identity->hasProperty( d->props->firstName().key() ))
00096 d->general.firstName->setText( d->identity->property(d->props->firstName()).value().toString() );
00097
00098
00099 if (d->identity->hasProperty( d->props->lastName().key() ))
00100 d->general.lastName->setText( d->identity->property(d->props->lastName()).value().toString() );
00101
00102
00103
00104 if (d->identity->hasProperty( d->props->emailAddress().key() ))
00105 d->detailed.email->setText( d->identity->property(d->props->emailAddress()).value().toString() );
00106
00107
00108 if (d->identity->hasProperty( d->props->privatePhone().key() ))
00109 d->detailed.privatePhone->setText(
00110 d->identity->property(d->props->privatePhone()).value().toString() );
00111
00112
00113 if (d->identity->hasProperty( d->props->privateMobilePhone().key() ))
00114 d->detailed.mobilePhone->setText(
00115 d->identity->property(d->props->privateMobilePhone()).value().toString() );
00116
00117 }
00118
00119 void IdentityDialog::slotSave()
00120 {
00121
00122 d->identity->setLabel( d->general.label->text() );
00123 if ( d->photoPath.isEmpty() )
00124 d->identity->removeProperty( d->props->photo() );
00125 else
00126 d->identity->setProperty( d->props->photo(), d->photoPath );
00127 d->identity->setProperty( d->props->nickName(), d->general.nickName->text() );
00128 d->identity->setProperty( d->props->firstName(), d->general.firstName->text() );
00129 d->identity->setProperty( d->props->lastName(), d->general.lastName->text() );
00130
00131
00132 d->identity->setProperty( d->props->emailAddress(), d->detailed.email->text() );
00133 d->identity->setProperty( d->props->privatePhone(), d->detailed.privatePhone->text() );
00134 d->identity->setProperty( d->props->privateMobilePhone(), d->detailed.mobilePhone->text() );
00135 }
00136
00137 void IdentityDialog::setPhoto(QString path)
00138 {
00139 d->photoPath = path;
00140 if (!path.isEmpty())
00141 {
00142 d->general.photo->setText( QString("<qt><a href=\"selectPhoto\">"
00143 "<p align=\"center\"><img src=\"%1\"></p>"
00144 "</a>").arg( d->photoPath ) );
00145 }
00146 else
00147 {
00148 d->general.photo->setText( QString("<qt><a href=\"selectPhoto\">"
00149 "<p align=\"center\">No Photo</p>"
00150 "</a>").arg( i18n("No Photo") ));
00151 }
00152 }
00153
00154 void IdentityDialog::slotSelectPhoto()
00155 {
00156 bool ok;
00157 QString photo = Kopete::UI::AvatarDialog::getAvatar(this, d->photoPath, &ok);
00158 if ( ok )
00159 setPhoto( photo );
00160 }
00161
00162 void IdentityDialog::slotClearPhoto()
00163 {
00164 setPhoto( QString::null );
00165 }
00166
00167 #include "identitydialog.moc"
00168