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

mailtransport

addtransportdialog.cpp

00001 /*
00002     Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
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 "addtransportdialog.h"
00021 #include "transport.h"
00022 #include "transportconfigwidget.h"
00023 #include "transportmanager.h"
00024 #include "transporttype.h"
00025 #include "ui_addtransportdialog.h"
00026 
00027 #include <KDebug>
00028 
00029 #include <akonadi/agentinstance.h>
00030 #include <akonadi/agentinstancecreatejob.h>
00031 
00032 using namespace MailTransport;
00033 
00037 class AddTransportDialog::Private
00038 {
00039   public:
00040     Private( AddTransportDialog *qq )
00041       : q( qq )
00042     {
00043     }
00044 
00049     TransportType selectedType() const;
00050 
00054     void typeListClicked(); // slot
00055 
00056     AddTransportDialog *const q;
00057     ::Ui::AddTransportDialog ui;
00058 };
00059 
00060 TransportType AddTransportDialog::Private::selectedType() const
00061 {
00062   QList<QTreeWidgetItem*> sel = ui.typeListView->selectedItems();
00063   if ( !sel.empty() ) {
00064     return sel.first()->data( 0, Qt::UserRole ).value<TransportType>();
00065   }
00066   return TransportType();
00067 }
00068 
00069 void AddTransportDialog::Private::typeListClicked()
00070 {
00071   // Make sure a type is selected before allowing the user to continue.
00072   q->enableButtonOk( selectedType().isValid() );
00073 }
00074 
00075 AddTransportDialog::AddTransportDialog( QWidget *parent )
00076   : KDialog( parent ), d( new Private( this ) )
00077 {
00078   // Setup UI.
00079   {
00080     QWidget *widget = new QWidget( this );
00081     d->ui.setupUi( widget );
00082     setMainWidget( widget );
00083     setCaption( i18n( "Create Outgoing Account" ) );
00084     setButtons( Ok|Cancel );
00085     enableButtonOk( false );
00086     setButtonText( Ok, i18nc( "create and configure a mail transport", "Create and Configure" ) );
00087   }
00088 
00089   // Populate type list.
00090   foreach ( const TransportType &type, TransportManager::self()->types() ) {
00091     QTreeWidgetItem *treeItem = new QTreeWidgetItem( d->ui.typeListView );
00092     treeItem->setText( 0, type.name() );
00093     treeItem->setText( 1, type.description() );
00094     treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( type ) ); // the transport type
00095   }
00096   d->ui.typeListView->resizeColumnToContents( 0 );
00097   updateGeometry();
00098   d->ui.typeListView->setFocus();
00099 
00100   // Connect user input.
00101   connect( d->ui.typeListView, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
00102       this, SLOT(typeListClicked()) );
00103   connect( d->ui.typeListView, SIGNAL(itemSelectionChanged()),
00104       this, SLOT(typeListClicked()) );
00105   connect( d->ui.typeListView, SIGNAL(doubleClicked(const QModelIndex &) ),
00106            this, SLOT(accept() ) );
00107 }
00108 
00109 AddTransportDialog::~AddTransportDialog()
00110 {
00111   delete d;
00112 }
00113 
00114 void AddTransportDialog::accept()
00115 {
00116   if( !d->selectedType().isValid() ) {
00117     return;
00118   }
00119 
00120   // Create a new transport and configure it.
00121   Transport *transport = TransportManager::self()->createTransport();
00122   transport->setTransportType( d->selectedType() );
00123   if( d->selectedType().type() == Transport::EnumType::Akonadi ) {
00124     // Create a resource instance if Akonadi-type transport.
00125     using namespace Akonadi;
00126     AgentInstanceCreateJob *cjob = new AgentInstanceCreateJob( d->selectedType().agentType() );
00127     if( !cjob->exec() ) {
00128       kWarning() << "Failed to create agent instance of type"
00129         << d->selectedType().agentType().identifier();
00130       return;
00131     }
00132     transport->setHost( cjob->instance().identifier() );
00133   }
00134   transport->setName( d->ui.name->text() );
00135   transport->forceUniqueName();
00136   if( TransportManager::self()->configureTransport( transport, this ) ) {
00137     // The user clicked OK and the transport settings were saved.
00138     TransportManager::self()->addTransport( transport );
00139     if( d->ui.setDefault->isChecked() ) {
00140       TransportManager::self()->setDefaultTransport( transport->id() );
00141     }
00142     KDialog::accept();
00143   }
00144 }
00145 
00146 #include "addtransportdialog.moc"

mailtransport

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
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