• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.11.3 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  void writeConfig();
56  void readConfig();
57 
58  AddTransportDialog *const q;
59  ::Ui::AddTransportDialog ui;
60 };
61 
62 
63 void AddTransportDialog::Private::writeConfig()
64 {
65  KConfigGroup group( KGlobal::config(), "AddTransportDialog" );
66  group.writeEntry( "Size", q->size() );
67 }
68 
69 void AddTransportDialog::Private::readConfig()
70 {
71  KConfigGroup group( KGlobal::config(), "AddTransportDialog" );
72  const QSize sizeDialog = group.readEntry( "Size", QSize(300,200) );
73  if ( sizeDialog.isValid() ) {
74  q->resize( sizeDialog );
75  }
76 }
77 
78 TransportType AddTransportDialog::Private::selectedType() const
79 {
80  QList<QTreeWidgetItem*> sel = ui.typeListView->selectedItems();
81  if ( !sel.empty() ) {
82  return sel.first()->data( 0, Qt::UserRole ).value<TransportType>();
83  }
84  return TransportType();
85 }
86 
87 void AddTransportDialog::Private::updateOkButton()
88 {
89  // Make sure a type is selected before allowing the user to continue.
90  q->enableButtonOk( selectedType().isValid() && !ui.name->text().trimmed().isEmpty() );
91 }
92 
93 AddTransportDialog::AddTransportDialog( QWidget *parent )
94  : KDialog( parent ), d( new Private( this ) )
95 {
96  // Setup UI.
97  {
98  QWidget *widget = new QWidget( this );
99  d->ui.setupUi( widget );
100  setMainWidget( widget );
101  setCaption( i18n( "Create Outgoing Account" ) );
102  setButtons( Ok|Cancel );
103  enableButtonOk( false );
104  setButtonText( Ok, i18nc( "create and configure a mail transport", "Create and Configure" ) );
105 
106 #ifdef KDEPIM_MOBILE_UI
107  d->ui.descLabel->hide();
108  d->ui.setDefault->hide();
109 #endif
110  }
111 
112  // Populate type list.
113  foreach ( const TransportType &type, TransportManager::self()->types() ) {
114  QTreeWidgetItem *treeItem = new QTreeWidgetItem( d->ui.typeListView );
115  treeItem->setText( 0, type.name() );
116  treeItem->setText( 1, type.description() );
117  treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( type ) ); // the transport type
118  }
119  d->ui.typeListView->resizeColumnToContents( 0 );
120  updateGeometry();
121  d->ui.typeListView->setFocus();
122 
123  // Connect user input.
124  connect( d->ui.typeListView, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
125  this, SLOT(updateOkButton()) );
126  connect( d->ui.typeListView, SIGNAL(itemSelectionChanged()),
127  this, SLOT(updateOkButton()) );
128  connect( d->ui.typeListView, SIGNAL(doubleClicked(QModelIndex)),
129  this, SLOT(accept()) );
130  connect( d->ui.name, SIGNAL(textChanged(QString)),
131  this, SLOT(updateOkButton()) );
132  d->readConfig();
133 }
134 
135 AddTransportDialog::~AddTransportDialog()
136 {
137  d->writeConfig();
138  delete d;
139 }
140 
141 void AddTransportDialog::accept()
142 {
143  if ( !d->selectedType().isValid() ) {
144  return;
145  }
146 
147  // Create a new transport and configure it.
148  Transport *transport = TransportManager::self()->createTransport();
149  transport->setTransportType( d->selectedType() );
150  if ( d->selectedType().type() == Transport::EnumType::Akonadi ) {
151  // Create a resource instance if Akonadi-type transport.
152  using namespace Akonadi;
153  AgentInstanceCreateJob *cjob = new AgentInstanceCreateJob( d->selectedType().agentType() );
154  if ( !cjob->exec() ) {
155  kWarning() << "Failed to create agent instance of type"
156  << d->selectedType().agentType().identifier();
157  return;
158  }
159  transport->setHost( cjob->instance().identifier() );
160  }
161  transport->setName( d->ui.name->text().trimmed() );
162  transport->forceUniqueName();
163  if ( TransportManager::self()->configureTransport( transport, this ) ) {
164  // The user clicked OK and the transport settings were saved.
165  TransportManager::self()->addTransport( transport );
166 #ifndef KDEPIM_MOBILE_UI
167  if ( d->ui.setDefault->isChecked() ) {
168  TransportManager::self()->setDefaultTransport( transport->id() );
169  }
170 #endif
171  KDialog::accept();
172  }
173 }
174 
175 #include "moc_addtransportdialog.cpp"
MailTransport::TransportType
A representation of a transport type.
Definition: transporttype.h:51
MailTransport::TransportType::name
QString name() const
Returns the i18n&#39;ed name of the transport type.
Definition: transporttype.cpp:76
MailTransport::TransportManager::addTransport
void addTransport(Transport *transport)
Adds the given transport.
Definition: transportmanager.cpp:217
MailTransport::TransportManager::setDefaultTransport
Q_SCRIPTABLE void setDefaultTransport(int id)
Sets the default transport.
Definition: transportmanager.cpp:382
MailTransport::TransportManager::self
static TransportManager * self()
Returns the TransportManager instance.
Definition: transportmanager.cpp:163
MailTransport::Transport::setTransportType
void setTransportType(const TransportType &type)
Sets the type of this transport.
Definition: transport.cpp:349
MailTransport::TransportType::description
QString description() const
Returns a description of the transport type.
Definition: transporttype.cpp:81
MailTransport::TransportManager::createTransport
Transport * createTransport() const
Creates a new, empty Transport object.
Definition: transportmanager.cpp:209
MailTransport::AddTransportDialog
Definition: addtransportdialog.h:39
MailTransport::Transport::forceUniqueName
void forceUniqueName()
Makes sure the transport has a unique name.
Definition: transport.cpp:83
MailTransport::AddTransportDialog::AddTransportDialog
AddTransportDialog(QWidget *parent=0)
Creates a new AddTransportDialog.
Definition: addtransportdialog.cpp:93
MailTransport::Transport
Represents the settings of a specific mail transport.
Definition: transport.h:50
MailTransport::AddTransportDialog::~AddTransportDialog
virtual ~AddTransportDialog()
Destroys the AddTransportDialog.
Definition: addtransportdialog.cpp:135
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:01 by doxygen 1.8.5 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.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 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