• Skip to content
  • Skip to link menu
KDE 4.3 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 
00029 using namespace MailTransport;
00030 
00031 class TransportManagementWidget::Private
00032 {
00033   public:
00034     Ui::TransportManagementWidget ui;
00035 };
00036 
00037 TransportManagementWidget::TransportManagementWidget( QWidget *parent )
00038   : QWidget( parent ), d( new Private )
00039 {
00040   KGlobal::locale()->insertCatalog( QString::fromLatin1( "libmailtransport" ) );
00041   d->ui.setupUi( this );
00042 
00043   d->ui.transportList->setHeaderLabels( QStringList()
00044                                         << i18nc( "@title:column email transport name", "Name" )
00045                                         << i18nc( "@title:column email transport type", "Type" ) );
00046   d->ui.transportList->sortItems( 0, Qt::AscendingOrder );
00047   connect( d->ui.transportList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
00048            SLOT(updateButtonState()) );
00049   connect( d->ui.transportList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
00050            SLOT(editClicked()) );
00051   connect( d->ui.addButton, SIGNAL(clicked()), SLOT(addClicked()) );
00052   connect( d->ui.editButton, SIGNAL(clicked()), SLOT(editClicked()) );
00053   connect( d->ui.removeButton, SIGNAL(clicked()), SLOT(removeClicked()) );
00054   connect( d->ui.defaultButton, SIGNAL(clicked()), SLOT(defaultClicked()) );
00055 
00056   fillTransportList();
00057   connect( TransportManager::self(), SIGNAL(transportsChanged()),
00058            SLOT(fillTransportList()) );
00059 }
00060 
00061 TransportManagementWidget::~TransportManagementWidget()
00062 {
00063   delete d;
00064 }
00065 
00066 void TransportManagementWidget::fillTransportList()
00067 {
00068   // try to preserve the selection
00069   int selected = -1;
00070   if ( d->ui.transportList->currentItem() ) {
00071     selected = d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
00072   }
00073 
00074   d->ui.transportList->clear();
00075   foreach ( Transport *t, TransportManager::self()->transports() ) {
00076     QTreeWidgetItem *item = new QTreeWidgetItem( d->ui.transportList );
00077     item->setData( 0, Qt::UserRole, t->id() );
00078     item->setText( 0, t->name() );
00079     QString type;
00080     switch ( t->type() ) {
00081     case Transport::EnumType::SMTP:
00082       type = i18nc( "@option SMTP transport", "SMTP" );
00083       break;
00084     case Transport::EnumType::Sendmail:
00085       type = i18nc( "@option sendmail transport", "Sendmail" );
00086       break;
00087     }
00088     if ( TransportManager::self()->defaultTransportId() == t->id() ) {
00089       type += i18nc( "@label the default mail transport", " (Default)" );
00090     }
00091     item->setText( 1, type );
00092     if ( t->id() == selected ) {
00093       d->ui.transportList->setCurrentItem( item );
00094     }
00095   }
00096 
00097   updateButtonState();
00098 }
00099 
00100 void TransportManagementWidget::updateButtonState()
00101 {
00102   if ( !d->ui.transportList->currentItem() ) {
00103     d->ui.editButton->setEnabled( false );
00104     d->ui.removeButton->setEnabled( false );
00105     d->ui.defaultButton->setEnabled( false );
00106   } else {
00107     d->ui.editButton->setEnabled( true );
00108     d->ui.removeButton->setEnabled( true );
00109     if ( d->ui.transportList->currentItem()->data( 0, Qt::UserRole ) ==
00110          TransportManager::self()->defaultTransportId() ) {
00111       d->ui.defaultButton->setEnabled( false );
00112     } else {
00113       d->ui.defaultButton->setEnabled( true );
00114     }
00115   }
00116 }
00117 
00118 void TransportManagementWidget::addClicked()
00119 {
00120   // initialize transport
00121   Transport *t = TransportManager::self()->createTransport();
00122   t->setType( Transport::EnumType::SMTP );
00123 
00124   // configure transporr
00125   TransportConfigDialog *tcd = new TransportConfigDialog( t, this );
00126   connect( tcd, SIGNAL(sendmailClicked()), SLOT(slotSendmail()) );
00127   tcd->setCaption( i18nc( "@title:window", "Add Transport" ) );
00128   if ( tcd->exec() == KDialog::Accepted ) {
00129     TransportManager::self()->addTransport( t );
00130   } else {
00131     delete t;
00132   }
00133 }
00134 
00135 void TransportManagementWidget::slotSendmail()
00136 {
00137   // initialize transport
00138   Transport *t = TransportManager::self()->createTransport();
00139   t->setType( Transport::EnumType::Sendmail );
00140   t->setHost( QLatin1String( "/usr/sbin/sendmail" ) );
00141 
00142   TransportConfigDialog tcd( t, this );
00143   tcd.setCaption( i18nc( "@title:window", "Add Transport" ) );
00144   if ( tcd.exec() == KDialog::Accepted ) {
00145     TransportManager::self()->addTransport( t );
00146   } else {
00147     delete t;
00148   }
00149 }
00150 
00151 void TransportManagementWidget::editClicked()
00152 {
00153   Q_ASSERT( d->ui.transportList->currentItem() );
00154 
00155   int currentId = d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
00156   Transport *transport = TransportManager::self()->transportById( currentId );
00157   if ( !transport ) {
00158     return;
00159   }
00160   transport = transport->clone();
00161   TransportConfigDialog t( transport, this );
00162   t.setCaption( i18nc( "@title:window", "Modify Transport" ) );
00163   t.exec();
00164   delete transport;
00165 }
00166 
00167 void TransportManagementWidget::removeClicked()
00168 {
00169   Q_ASSERT( d->ui.transportList->currentItem() );
00170 
00171   TransportManager::self()->removeTransport(
00172         d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
00173 }
00174 
00175 void TransportManagementWidget::defaultClicked()
00176 {
00177   Q_ASSERT( d->ui.transportList->currentItem() );
00178 
00179   TransportManager::self()->setDefaultTransport(
00180         d->ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
00181 }
00182 
00183 #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"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
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