mailtransport
transportcombobox.cpp
00001 /* 00002 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #include "transportcombobox.h" 00021 #include "transport.h" 00022 #include "transportmanager.h" 00023 00024 #include <KDebug> 00025 #include <KLocale> 00026 00027 using namespace MailTransport; 00028 00033 class TransportComboBoxPrivate 00034 { 00035 public: 00036 QList<int> transports; 00037 }; 00038 00039 TransportComboBox::TransportComboBox( QWidget *parent ) 00040 : KComboBox( parent ), d( new TransportComboBoxPrivate ) 00041 { 00042 fillComboBox(); 00043 connect( TransportManager::self(), SIGNAL(transportsChanged()), 00044 SLOT(fillComboBox()) ); 00045 } 00046 00047 TransportComboBox::~TransportComboBox() 00048 { 00049 delete d; 00050 } 00051 00052 int TransportComboBox::currentTransportId() const 00053 { 00054 if ( currentIndex() >= 0 && currentIndex() < d->transports.count() ) { 00055 return d->transports.at( currentIndex() ); 00056 } 00057 return -1; 00058 } 00059 00060 void TransportComboBox::setCurrentTransport( int transportId ) 00061 { 00062 int i = d->transports.indexOf( transportId ); 00063 if ( i >= 0 && i < count() ) { 00064 setCurrentIndex( i ); 00065 } 00066 } 00067 00068 TransportBase::EnumType::type TransportComboBox::transportType() const 00069 { 00070 int transtype = TransportManager::self()->transportById( currentTransportId() )->type(); 00071 return static_cast<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 00096 #include "transportcombobox.moc"