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

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