kopete/libkopete
addressbooklinkwidget.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
00021
00022
00023
00024 #include <qapplication.h>
00025 #include <klineedit.h>
00026 #include <klocale.h>
00027 #include <kpushbutton.h>
00028
00029 #include <kiconloader.h>
00030
00031 #include <kopetemetacontact.h>
00032
00033 #include "addressbooklinkwidget.h"
00034 #include "addressbookselectordialog.h"
00035 #include "addressbookselectorwidget.h"
00036
00037 namespace Kopete {
00038 namespace UI {
00039
00040
00041 AddressBookLinkWidget::AddressBookLinkWidget( QWidget * parent, const char * name ) : QWidget(parent), Ui::AddressBookLinkWidgetBase(), mMetaContact( 0 )
00042 {
00043 setObjectName(name);
00044 setupUi(this);
00045
00046 btnClear->setIcon( KIcon( (QApplication::layoutDirection() == Qt::RightToLeft) ? QString::fromLatin1( "edit-clear-locationbar-ltr" ) : QString::fromLatin1( "edit-clear-locationbar-rtl") ) );
00047 connect( btnClear, SIGNAL( clicked() ), this, SLOT( slotClearAddressee() ) );
00048 connect( btnSelectAddressee, SIGNAL( clicked() ), SLOT( slotSelectAddressee() ) );
00049 }
00050
00051 void AddressBookLinkWidget::setAddressee( const KABC::Addressee& addr )
00052 {
00053 edtAddressee->setText( addr.realName() );
00054 btnClear->setEnabled( !addr.isEmpty() );
00055 }
00056
00057 void AddressBookLinkWidget::setMetaContact( const Kopete::MetaContact * mc )
00058 {
00059 mMetaContact = mc;
00060 }
00061
00062 QString AddressBookLinkWidget::uid() const
00063 {
00064 return mSelectedUid;
00065 }
00066
00067 void AddressBookLinkWidget::slotClearAddressee()
00068 {
00069 edtAddressee->clear();
00070 btnClear->setEnabled( false );
00071 KABC::Addressee mrEmpty;
00072 mSelectedUid.clear();
00073 emit addresseeChanged( mrEmpty );
00074 }
00075
00076 void AddressBookLinkWidget::slotSelectAddressee()
00077 {
00078 QString message;
00079 if ( mMetaContact )
00080 message = i18n("Choose the corresponding entry for '%1'", mMetaContact->displayName() );
00081 else
00082 message = i18n("Choose the corresponding entry in the address book" );
00083
00084 Kopete::UI::AddressBookSelectorDialog dialog( i18n("Addressbook Association"), message, ( mMetaContact ? mMetaContact->metaContactId() : QString::null ), this );
00085 int result = dialog.exec();
00086
00087 KABC::Addressee addr;
00088 if ( result == QDialog::Accepted )
00089 {
00090 addr = dialog.addressBookSelectorWidget()->addressee();
00091
00092 edtAddressee->setText( addr.realName() );
00093 btnClear->setEnabled( !addr.isEmpty() );
00094 mSelectedUid = ( addr.isEmpty() ? QString::null : addr.uid() );
00095 emit addresseeChanged( addr );
00096 }
00097 }
00098
00099 }
00100 }
00101
00102 #include "addressbooklinkwidget.moc"