transportmanagementwidget.cpp
00001 /* 00002 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> 00003 00004 Based on KMail code by: 00005 Copyright (C) 2001-2003 Marc Mutz <mutz@kde.org> 00006 00007 This library is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU Library General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or (at your 00010 option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to the 00019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 00021 */ 00022 00023 #include "transportmanagementwidget.h" 00024 #include "ui_transportmanagementwidget.h" 00025 #include "transportmanager.h" 00026 #include "transport.h" 00027 00028 using namespace MailTransport; 00029 00030 class TransportManagementWidget::Private 00031 { 00032 public: 00033 00034 Private( TransportManagementWidget *parent ); 00035 00036 Ui::TransportManagementWidget ui; 00037 TransportManagementWidget *q; 00038 00039 // Slots 00040 void defaultClicked(); 00041 void removeClicked(); 00042 void renameClicked(); 00043 void editClicked(); 00044 void addClicked(); 00045 void updateButtonState(); 00046 }; 00047 00048 TransportManagementWidget::Private::Private( TransportManagementWidget *parent ) 00049 : q( parent ) 00050 { 00051 } 00052 00053 TransportManagementWidget::TransportManagementWidget( QWidget *parent ) 00054 : QWidget( parent ), d( new Private( this ) ) 00055 { 00056 KGlobal::locale()->insertCatalog( QString::fromLatin1( "libmailtransport" ) ); 00057 d->ui.setupUi( this ); 00058 d->updateButtonState(); 00059 00060 connect( d->ui.transportList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), 00061 SLOT(updateButtonState()) ); 00062 connect( d->ui.transportList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), 00063 SLOT(editClicked()) ); 00064 connect( d->ui.addButton, SIGNAL(clicked()), SLOT(addClicked()) ); 00065 connect( d->ui.editButton, SIGNAL(clicked()), SLOT(editClicked()) ); 00066 connect( d->ui.renameButton, SIGNAL(clicked()), SLOT(renameClicked()) ); 00067 connect( d->ui.removeButton, SIGNAL(clicked()), SLOT(removeClicked()) ); 00068 connect( d->ui.defaultButton, SIGNAL(clicked()), SLOT(defaultClicked()) ); 00069 } 00070 00071 TransportManagementWidget::~TransportManagementWidget() 00072 { 00073 delete d; 00074 } 00075 00076 void TransportManagementWidget::Private::updateButtonState() 00077 { 00078 // TODO figure out current item vs. selected item (in almost every function) 00079 if ( !ui.transportList->currentItem() ) { 00080 ui.editButton->setEnabled( false ); 00081 ui.renameButton->setEnabled( false ); 00082 ui.removeButton->setEnabled( false ); 00083 ui.defaultButton->setEnabled( false ); 00084 } else { 00085 ui.editButton->setEnabled( true ); 00086 ui.renameButton->setEnabled( true ); 00087 ui.removeButton->setEnabled( true ); 00088 if ( ui.transportList->currentItem()->data( 0, Qt::UserRole ) == 00089 TransportManager::self()->defaultTransportId() ) { 00090 ui.defaultButton->setEnabled( false ); 00091 } else { 00092 ui.defaultButton->setEnabled( true ); 00093 } 00094 } 00095 } 00096 00097 void TransportManagementWidget::Private::addClicked() 00098 { 00099 TransportManager::self()->showTransportCreationDialog( q ); 00100 } 00101 00102 void TransportManagementWidget::Private::editClicked() 00103 { 00104 if( !ui.transportList->currentItem() ) { 00105 return; 00106 } 00107 00108 int currentId = ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt(); 00109 Transport *transport = TransportManager::self()->transportById( currentId ); 00110 TransportManager::self()->configureTransport( transport, q ); 00111 } 00112 00113 void TransportManagementWidget::Private::renameClicked() 00114 { 00115 if( !ui.transportList->currentItem() ) { 00116 return; 00117 } 00118 00119 ui.transportList->editItem( ui.transportList->currentItem(), 0 ); 00120 } 00121 00122 void TransportManagementWidget::Private::removeClicked() 00123 { 00124 if( !ui.transportList->currentItem() ) { 00125 return; 00126 } 00127 00128 TransportManager::self()->removeTransport( 00129 ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() ); 00130 } 00131 00132 void TransportManagementWidget::Private::defaultClicked() 00133 { 00134 if( !ui.transportList->currentItem() ) { 00135 return; 00136 } 00137 00138 TransportManager::self()->setDefaultTransport( 00139 ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() ); 00140 } 00141 00142 #include "transportmanagementwidget.moc"