kaddressbook
imeditwidget.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qcheckbox.h>
00025 #include <qlabel.h>
00026 #include <qlayout.h>
00027 #include <qpainter.h>
00028 #include <qpushbutton.h>
00029 #include <qstring.h>
00030 #include <qtoolbutton.h>
00031 #include <qtooltip.h>
00032
00033 #include <kaccelmanager.h>
00034 #include <kconfig.h>
00035 #include <kcombobox.h>
00036 #include <kdebug.h>
00037 #include <kdialog.h>
00038 #include <kiconloader.h>
00039 #include <klineedit.h>
00040 #include <klocale.h>
00041 #include <kmessagebox.h>
00042
00043 #include "imeditwidget.h"
00044 #include "imeditorwidget.h"
00045
00046 IMEditWidget::IMEditWidget( QWidget *parent, KABC::Addressee &addr, const char *name )
00047 : QWidget( parent, name ), mAddressee(addr)
00048 {
00049 QGridLayout *topLayout = new QGridLayout( this, 2, 2, KDialog::marginHint(),
00050 KDialog::spacingHint() );
00051
00052 QLabel *label = new QLabel( i18n( "IM address:" ), this );
00053 topLayout->addWidget( label, 0, 0 );
00054
00055 mIMEdit = new KLineEdit( this );
00056 connect( mIMEdit, SIGNAL( textChanged( const QString& ) ),
00057 SLOT( textChanged( const QString& ) ) );
00058 connect( mIMEdit, SIGNAL( textChanged( const QString& ) ),
00059 SIGNAL( modified() ) );
00060 label->setBuddy( mIMEdit );
00061 topLayout->addWidget( mIMEdit, 0, 1 );
00062
00063 mEditButton = new QPushButton( i18n( "Edit IM Addresses..." ), this);
00064 connect( mEditButton, SIGNAL( clicked() ), SLOT( edit() ) );
00065 topLayout->addMultiCellWidget( mEditButton, 1, 1, 0, 1 );
00066
00067 topLayout->activate();
00068 }
00069
00070 IMEditWidget::~IMEditWidget()
00071 {
00072 }
00073
00074 void IMEditWidget::setReadOnly( bool readOnly )
00075 {
00076 mIMEdit->setReadOnly( readOnly );
00077 mReadOnly = readOnly;
00078
00079 }
00080 void IMEditWidget::setPreferredIM( const QString &addr )
00081 {
00082 bool blocked = mIMEdit->signalsBlocked();
00083 mIMEdit->blockSignals( true );
00084 mIMEdit->setText( addr );
00085 mIMEdit->blockSignals( blocked );
00086 }
00087 void IMEditWidget::setIMs( const QStringList &list )
00088 {
00089 mIMList = list;
00090
00091 bool blocked = mIMEdit->signalsBlocked();
00092 mIMEdit->blockSignals( true );
00093 if ( list.count() > 0 )
00094 mIMEdit->setText( list[ 0 ] );
00095 else
00096 mIMEdit->setText( "" );
00097 mIMEdit->blockSignals( blocked );
00098 }
00099
00100 QStringList IMEditWidget::ims()
00101 {
00102 if ( mIMEdit->text().isEmpty() ) {
00103 if ( mIMList.count() > 0 )
00104 mIMList.remove( mIMList.begin() );
00105 } else {
00106 if ( mIMList.count() > 0 )
00107 mIMList.remove( mIMList.begin() );
00108
00109 mIMList.prepend( mIMEdit->text() );
00110 }
00111
00112 return mIMList;
00113 }
00114 QString IMEditWidget::preferredIM()
00115 {
00116 return mIMEdit->text();
00117 }
00118 void IMEditWidget::edit()
00119 {
00120 IMEditorWidget dlg(this, mIMEdit->text());
00121 dlg.loadContact(&mAddressee);
00122 dlg.setReadOnly(mReadOnly);
00123
00124 if ( dlg.exec() ) {
00125 if ( dlg.isModified() ) {
00126
00127
00128 dlg.storeContact(&mAddressee);
00129 mIMEdit->setText( dlg.preferred() );
00130 emit modified();
00131 }
00132 }
00133 }
00134
00135 void IMEditWidget::textChanged( const QString &text )
00136 {
00137 if ( mIMList.count() > 0 )
00138 mIMList.remove( mIMList.begin() );
00139
00140 mIMList.prepend( text );
00141 }
00142
00143
00144 #include "imeditwidget.moc"
00145
|