• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

mailtransport

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 #include "transportconfigdialog.h"
00028 #include "transporttypedialog.h"
00029 
00030 using namespace MailTransport;
00031 
00032 class TransportManagementWidget::Private
00033 {
00034   public:
00035     Ui::TransportManagementWidget ui;
00036 };
00037 
00038 TransportManagementWidget::TransportManagementWidget(QWidget * parent) :
00039     QWidget( parent ),
00040     d( new Private )
00041 {
00042   d->ui.setupUi( this );
00043 
00044   d->ui.transportList->setHeaderLabels(
00045                            QStringList() << i18n("Name") << i18n("Type") );
00046   connect( d->ui.transportList, SIGNAL(currentItemChanged(QTreeWidgetItem*,
00047            QTreeWidgetItem*)), SLOT(updateButtonState()) );
00048   connect( d->ui.transportList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
00049            SLOT(editClicked()) );
00050   connect( d->ui.addButton, SIGNAL(clicked()), SLOT(addClicked()) );
00051   connect( d->ui.editButton, SIGNAL(clicked()), SLOT(editClicked()) );
00052   connect( d->ui.removeButton, SIGNAL(clicked()), SLOT(removeClicked()) );
00053   connect( d->ui.defaultButton, SIGNAL(clicked()), SLOT(defaultClicked()) );
00054 
00055   fillTransportList();
00056   connect( TransportManager::self(), SIGNAL(transportsChanged()),
00057            SLOT(fillTransportList()) );
00058 }
00059 
00060 TransportManagementWidget::~TransportManagementWidget()
00061 {
00062   delete d;
00063 }
00064 
00065 void TransportManagementWidget::fillTransportList()
00066 {
00067   // try to preserve the selection
00068   int selected = -1;
00069   if ( d->ui.transportList->currentItem() )
00070     selected = d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
00071 
00072   d->ui.transportList->clear();
00073   foreach ( Transport* t, TransportManager::self()->transports() ) {
00074     QTreeWidgetItem *item = new QTreeWidgetItem( d->ui.transportList );
00075     item->setData( 0, Qt::UserRole, t->id() );
00076     item->setText( 0, t->name() );
00077     QString type;
00078     switch ( t->type() ) {
00079       case Transport::EnumType::SMTP:
00080         type = i18n("SMTP");
00081         break;
00082       case Transport::EnumType::Sendmail:
00083         type = i18n("Sendmail");
00084         break;
00085     }
00086     if ( TransportManager::self()->defaultTransportId() == t->id() )
00087       type += i18n(" (Default)" );
00088     item->setText( 1, type );
00089     if ( t->id() == selected )
00090       d->ui.transportList->setCurrentItem( item );
00091   }
00092 
00093   updateButtonState();
00094 }
00095 
00096 void TransportManagementWidget::updateButtonState()
00097 {
00098   if ( !d->ui.transportList->currentItem() ) {
00099     d->ui.editButton->setEnabled( false );
00100     d->ui.removeButton->setEnabled( false );
00101     d->ui.defaultButton->setEnabled( false );
00102   } else {
00103     d->ui.editButton->setEnabled( true );
00104     d->ui.removeButton->setEnabled( true );
00105     if ( d->ui.transportList->currentItem()->data( 0, Qt::UserRole ) ==
00106          TransportManager::self()->defaultTransportId() )
00107       d->ui.defaultButton->setEnabled( false );
00108     else
00109       d->ui.defaultButton->setEnabled( true );
00110   }
00111 }
00112 
00113 void TransportManagementWidget::addClicked()
00114 {
00115   // get transport type
00116   TransportTypeDialog tdd( this );
00117   if ( tdd.exec() != QDialog::Accepted )
00118     return;
00119 
00120   // initialize transport
00121   Transport *t = TransportManager::self()->createTransport();
00122   t->setType( tdd.transportType() );
00123   if ( t->type() == Transport::EnumType::Sendmail )
00124     t->setHost( QLatin1String("/usr/sbin/sendmail") );
00125 
00126   // configure transport
00127   TransportConfigDialog tcd( t, this );
00128   tcd.setCaption( i18n("Add Transport") );
00129   if ( tcd.exec() == QDialog::Accepted ) {
00130     TransportManager::self()->addTransport( t );
00131   } else {
00132     delete t;
00133   }
00134 }
00135 
00136 void TransportManagementWidget::editClicked()
00137 {
00138   Q_ASSERT( d->ui.transportList->currentItem() );
00139 
00140   int currentId = d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
00141   Transport* transport = TransportManager::self()->transportById( currentId );
00142   if ( !transport )
00143     return;
00144   transport = transport->clone();
00145   TransportConfigDialog t( transport, this );
00146   t.setCaption( i18n("Modify Transport") );
00147   t.exec();
00148   delete transport;
00149 }
00150 
00151 void TransportManagementWidget::removeClicked()
00152 {
00153   Q_ASSERT( d->ui.transportList->currentItem() );
00154 
00155   TransportManager::self()->removeTransport(
00156         d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
00157 }
00158 
00159 void TransportManagementWidget::defaultClicked()
00160 {
00161   Q_ASSERT( d->ui.transportList->currentItem() );
00162 
00163   TransportManager::self()->setDefaultTransport(
00164         d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
00165 }
00166 
00167 #include "transportmanagementwidget.moc"

mailtransport

Skip menu "mailtransport"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal