mailtransport
transportcombobox.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "transportcombobox.h"
00021 #include "transport.h"
00022 #include "transportmanager.h"
00023
00024 #include <kdebug.h>
00025 #include <klocale.h>
00026
00027 #include <qlineedit.h>
00028
00029 using namespace MailTransport;
00030
00035 class TransportComboBoxPrivate
00036 {
00037 public:
00038 QList<int> transports;
00039 };
00040
00041 TransportComboBox::TransportComboBox(QWidget * parent) :
00042 KComboBox( parent ), d( new TransportComboBoxPrivate )
00043 {
00044 fillComboBox();
00045 connect( TransportManager::self(), SIGNAL(transportsChanged()),
00046 SLOT(fillComboBox()) );
00047 }
00048
00049 TransportComboBox::~TransportComboBox()
00050 {
00051 delete d;
00052 }
00053
00054 int TransportComboBox::currentTransportId() const
00055 {
00056 if( currentIndex() >= 0 && currentIndex() < d->transports.count() )
00057 return d->transports.at( currentIndex() );
00058 return -1;
00059 }
00060
00061 void TransportComboBox::setCurrentTransport(int transportId)
00062 {
00063 int i = d->transports.indexOf( transportId );
00064 if ( i >= 0 && i < count() )
00065 setCurrentIndex( i );
00066 }
00067
00068 TransportBase::EnumType::type TransportComboBox::transportType() const
00069 {
00070 int transtype = TransportManager::self()->transportById( currentTransportId() )->type();
00071 return (TransportBase::EnumType::type)transtype;
00072 }
00073
00074 void TransportComboBox::fillComboBox()
00075 {
00076 int oldTransport = currentTransportId();
00077 clear();
00078 d->transports.clear();
00079
00080 int defaultId = 0;
00081 if ( !TransportManager::self()->isEmpty() ) {
00082 QStringList listNames = TransportManager::self()->transportNames();
00083 QList<int> listIds = TransportManager::self()->transportIds();
00084 addItems( listNames );
00085 d->transports << listIds;
00086 defaultId = TransportManager::self()->defaultTransportId();
00087 }
00088
00089 if ( oldTransport != -1 )
00090 setCurrentTransport( oldTransport );
00091 else
00092 setCurrentTransport( defaultId );
00093 }
00094
00095 #include "transportcombobox.moc"