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 d->general.photo->setText( QString("<qt><a href=\"selectPhoto\">"
00056 "<p align=\"center\">No Photo</p>"
00057 "</a>").arg( i18n("No Photo") ));
00058
00059 connect(d->general.selectPhoto, SIGNAL(clicked(bool)),
00060 this, SLOT(slotSelectPhoto()));
00061 connect(d->general.photo, SIGNAL(linkActivated(const QString&)),
00062 this, SLOT(slotSelectPhoto()));
00063 connect(d->general.clearPhoto, SIGNAL(clicked(bool)),
00064 this, SLOT(slotClearPhoto()));
00065 addWidget(w, i18n("General Information"));
00066
00067
00068 w = new QWidget(this);
00069 d->detailed.setupUi(w);
00070 addWidget(w, i18n("Detailed Information"));
00071
00072 setIcon(KIcon(d->identity->customIcon()));
00073
00074 load();
00075 }
00076
00077 IdentityDialog::~IdentityDialog()
00078 {
00079 delete d;
00080 }
00081
00082 void IdentityDialog::load()
00083 {
00084
00085
00086 if (d->identity->hasProperty( d->props->photo().key() ))
00087 setPhoto( d->identity->property(d->props->photo()).value().toString() );
00088
00089
00090
00091 d->general.label->setText( d->identity->label() );
00092
00093
00094 if (d->identity->hasProperty( d->props->nickName().key() ))
00095 d->general.nickName->setText( d->identity->property(d->props->nickName()).value().toString() );
00096
00097
00098 if (d->identity->hasProperty( d->props->firstName().key() ))
00099 d->general.firstName->setText( d->identity->property(d->props->firstName()).value().toString() );
00100
00101
00102 if (d->identity->hasProperty( d->props->lastName().key() ))
00103 d->general.lastName->setText( d->identity->property(d->props->lastName()).value().toString() );
00104
00105
00106
00107 if (d->identity->hasProperty( d->props->emailAddress().key() ))
00108 d->detailed.email->setText( d->identity->property(d->props->emailAddress()).value().toString() );
00109
00110
00111 if (d->identity->hasProperty( d->props->privatePhone().key() ))
00112 d->detailed.privatePhone->setText(
00113 d->identity->property(d->props->privatePhone()).value().toString() );
00114
00115
00116 if (d->identity->hasProperty( d->props->privateMobilePhone().key() ))
00117 d->detailed.mobilePhone->setText(
00118 d->identity->property(d->props->privateMobilePhone()).value().toString() );
00119
00120 }
00121
00122 void IdentityDialog::slotSave()
00123 {
00124
00125 d->identity->setLabel( d->general.label->text() );
00126 if ( d->photoPath.isEmpty() )
00127 d->identity->removeProperty( d->props->photo() );
00128 else
00129 d->identity->setProperty( d->props->photo(), d->photoPath );
00130 d->identity->setProperty( d->props->nickName(), d->general.nickName->text() );
00131 d->identity->setProperty( d->props->firstName(), d->general.firstName->text() );
00132 d->identity->setProperty( d->props->lastName(), d->general.lastName->text() );
00133
00134
00135 d->identity->setProperty( d->props->emailAddress(), d->detailed.email->text() );
00136 d->identity->setProperty( d->props->privatePhone(), d->detailed.privatePhone->text() );
00137 d->identity->setProperty( d->props->privateMobilePhone(), d->detailed.mobilePhone->text() );
00138 }
00139
00140 void IdentityDialog::setPhoto(QString path)
00141 {
00142 d->photoPath = path;
00143 if (!path.isEmpty())
00144 {
00145 d->general.photo->setText( QString("<qt><a href=\"selectPhoto\">"
00146 "<p align=\"center\"><img src=\"%1\"></p>"
00147 "</a>").arg( d->photoPath ) );
00148 }
00149 else
00150 {
00151 d->general.photo->setText( QString("<qt><a href=\"selectPhoto\">"
00152 "<p align=\"center\">No Photo</p>"
00153 "</a>").arg( i18n("No Photo") ));
00154 }
00155 }
00156
00157 void IdentityDialog::slotSelectPhoto()
00158 {
00159 bool ok;
00160 QString photo = Kopete::UI::AvatarDialog::getAvatar(this, d->photoPath, &ok);
00161 if ( ok )
00162 setPhoto( photo );
00163 }
00164
00165 void IdentityDialog::slotClearPhoto()
00166 {
00167 setPhoto( QString::null );
00168 }
00169
00170 #include "identitydialog.moc"
00171