• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

mailtransport

  • mailtransport
addtransportdialog.cpp
1 /*
2  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "addtransportdialog.h"
21 #include "transport.h"
22 #include "transportconfigwidget.h"
23 #include "transportmanager.h"
24 #include "transporttype.h"
25 #include "ui_addtransportdialog.h"
26 
27 #include <KDebug>
28 
29 #include <akonadi/agentinstance.h>
30 #include <akonadi/agentinstancecreatejob.h>
31 
32 using namespace MailTransport;
33 
37 class AddTransportDialog::Private
38 {
39  public:
40  Private( AddTransportDialog *qq )
41  : q( qq )
42  {
43  }
44 
49  TransportType selectedType() const;
50 
54  void updateOkButton(); // slot
55 
56  AddTransportDialog *const q;
57  ::Ui::AddTransportDialog ui;
58 };
59 
60 TransportType AddTransportDialog::Private::selectedType() const
61 {
62  QList<QTreeWidgetItem*> sel = ui.typeListView->selectedItems();
63  if ( !sel.empty() ) {
64  return sel.first()->data( 0, Qt::UserRole ).value<TransportType>();
65  }
66  return TransportType();
67 }
68 
69 void AddTransportDialog::Private::updateOkButton()
70 {
71  // Make sure a type is selected before allowing the user to continue.
72  q->enableButtonOk( selectedType().isValid() && !ui.name->text().trimmed().isEmpty() );
73 }
74 
75 AddTransportDialog::AddTransportDialog( QWidget *parent )
76  : KDialog( parent ), d( new Private( this ) )
77 {
78  // Setup UI.
79  {
80  QWidget *widget = new QWidget( this );
81  d->ui.setupUi( widget );
82  setMainWidget( widget );
83  setCaption( i18n( "Create Outgoing Account" ) );
84  setButtons( Ok|Cancel );
85  enableButtonOk( false );
86  setButtonText( Ok, i18nc( "create and configure a mail transport", "Create and Configure" ) );
87 
88 #ifdef KDEPIM_MOBILE_UI
89  d->ui.descLabel->hide();
90  d->ui.setDefault->hide();
91 #endif
92  }
93 
94  // Populate type list.
95  foreach ( const TransportType &type, TransportManager::self()->types() ) {
96  QTreeWidgetItem *treeItem = new QTreeWidgetItem( d->ui.typeListView );
97  treeItem->setText( 0, type.name() );
98  treeItem->setText( 1, type.description() );
99  treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( type ) ); // the transport type
100  }
101  d->ui.typeListView->resizeColumnToContents( 0 );
102  updateGeometry();
103  d->ui.typeListView->setFocus();
104 
105  // Connect user input.
106  connect( d->ui.typeListView, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
107  this, SLOT(updateOkButton()) );
108  connect( d->ui.typeListView, SIGNAL(itemSelectionChanged()),
109  this, SLOT(updateOkButton()) );
110  connect( d->ui.typeListView, SIGNAL(doubleClicked(QModelIndex)),
111  this, SLOT(accept()) );
112  connect( d->ui.name, SIGNAL(textChanged(QString)),
113  this, SLOT(updateOkButton()) );
114 }
115 
116 AddTransportDialog::~AddTransportDialog()
117 {
118  delete d;
119 }
120 
121 void AddTransportDialog::accept()
122 {
123  if ( !d->selectedType().isValid() ) {
124  return;
125  }
126 
127  // Create a new transport and configure it.
128  Transport *transport = TransportManager::self()->createTransport();
129  transport->setTransportType( d->selectedType() );
130  if ( d->selectedType().type() == Transport::EnumType::Akonadi ) {
131  // Create a resource instance if Akonadi-type transport.
132  using namespace Akonadi;
133  AgentInstanceCreateJob *cjob = new AgentInstanceCreateJob( d->selectedType().agentType() );
134  if ( !cjob->exec() ) {
135  kWarning() << "Failed to create agent instance of type"
136  << d->selectedType().agentType().identifier();
137  return;
138  }
139  transport->setHost( cjob->instance().identifier() );
140  }
141  transport->setName( d->ui.name->text().trimmed() );
142  transport->forceUniqueName();
143  if ( TransportManager::self()->configureTransport( transport, this ) ) {
144  // The user clicked OK and the transport settings were saved.
145  TransportManager::self()->addTransport( transport );
146 #ifndef KDEPIM_MOBILE_UI
147  if ( d->ui.setDefault->isChecked() ) {
148  TransportManager::self()->setDefaultTransport( transport->id() );
149  }
150 #endif
151  KDialog::accept();
152  }
153 }
154 
155 #include "moc_addtransportdialog.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:52 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailtransport

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

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal