kaddressbook
imaddresswidget.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 <qcombobox.h>
00026 #include <qlineedit.h>
00027 #include <qlabel.h>
00028
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031 #include <klocale.h>
00032 #include <kplugininfo.h>
00033
00034 #include "imaddresswidget.h"
00035
00036 IMAddressWidget::IMAddressWidget( QWidget *parent, QValueList<KPluginInfo *> protocols )
00037 : IMAddressBase( parent )
00038 {
00039 mProtocols = protocols;
00040 populateProtocols();
00041 init();
00042 }
00043
00044 IMAddressWidget::IMAddressWidget( QWidget *parent, QValueList<KPluginInfo *> protocols,
00045 KPluginInfo *protocol, const QString& address,
00046 const IMContext& context )
00047 : IMAddressBase( parent )
00048 {
00049 Q_UNUSED( context );
00050
00051 mProtocols = protocols;
00052 populateProtocols();
00053 cmbProtocol->setCurrentItem( mProtocols.findIndex( protocol ) );
00054
00055 edtAddress->setText( address.section( QChar( 0xE120 ), 0, 0 ) );
00056 edtNetwork->setText( address.section( QChar( 0xE120 ), 1 ) );
00057
00058 init();
00059 }
00060
00061 void IMAddressWidget::init()
00062 {
00063 connect( cmbProtocol, SIGNAL( activated( const QString& ) ),
00064 this, SLOT( slotProtocolChanged() ) );
00065 connect( edtAddress, SIGNAL( textChanged( const QString& ) ),
00066 this, SLOT( slotAddressChanged( const QString& ) ) );
00067
00068 slotProtocolChanged();
00069 }
00070
00071 void IMAddressWidget::slotAddressChanged( const QString &text )
00072 {
00073 emit inValidState( !text.stripWhiteSpace().isEmpty() );
00074 }
00075
00076 KPluginInfo * IMAddressWidget::protocol() const
00077 {
00078 int protocolIndex = cmbProtocol->currentItem();
00079
00080 return mProtocols[ protocolIndex ];
00081 }
00082
00083 IMContext IMAddressWidget::context() const
00084 {
00085 IMContext context = Any;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 return context;
00106 }
00107
00108 QString IMAddressWidget::address() const
00109 {
00110
00111
00112 if ( protocol()->name() == "IRC" && !edtNetwork->text().stripWhiteSpace().isEmpty() )
00113 return edtAddress->text().stripWhiteSpace() + QChar( 0xE120 ) + edtNetwork->text().stripWhiteSpace();
00114 else
00115 return edtAddress->text().stripWhiteSpace();
00116 }
00117
00118 void IMAddressWidget::populateProtocols()
00119 {
00120
00121 QValueList<KPluginInfo *>::ConstIterator it;
00122 for ( it = mProtocols.begin(); it != mProtocols.end(); ++it )
00123 cmbProtocol->insertItem( SmallIcon( (*it)->icon() ), (*it)->name() );
00124 }
00125
00126 void IMAddressWidget::slotProtocolChanged()
00127 {
00128 if ( protocol()->name() == "IRC" ) {
00129 edtNetwork->show();
00130 labelNetwork->show();
00131 } else {
00132 edtNetwork->hide();
00133 labelNetwork->hide();
00134 }
00135 }
00136
00137 #include "imaddresswidget.moc"
|