20#include "addtransportdialog.h"
22#include "transportconfigwidget.h"
23#include "transportmanager.h"
24#include "transporttype.h"
25#include "ui_addtransportdialog.h"
30#include <akonadi/agentinstance.h>
31#include <akonadi/agentinstancecreatejob.h>
33using namespace MailTransport;
38class AddTransportDialog::Private
55 void updateOkButton();
61 ::Ui::AddTransportDialog ui;
65void AddTransportDialog::Private::writeConfig()
67 KConfigGroup group( KGlobal::config(),
"AddTransportDialog" );
68 group.writeEntry(
"Size", q->size() );
71void AddTransportDialog::Private::readConfig()
73 KConfigGroup group( KGlobal::config(),
"AddTransportDialog" );
74 const QSize sizeDialog = group.readEntry(
"Size", QSize(400,300) );
75 if ( sizeDialog.isValid() ) {
76 q->resize( sizeDialog );
80TransportType AddTransportDialog::Private::selectedType()
const
82 QList<QTreeWidgetItem*> sel = ui.typeListView->selectedItems();
84 return sel.first()->data( 0, Qt::UserRole ).value<
TransportType>();
89void AddTransportDialog::Private::doubleClicked()
91 if (selectedType().isValid() && !ui.name->text().trimmed().isEmpty()) {
96void AddTransportDialog::Private::updateOkButton()
99 q->enableButtonOk( selectedType().isValid() && !ui.name->text().trimmed().isEmpty() );
103 : KDialog( parent ), d( new Private( this ) )
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" ) );
115#ifdef KDEPIM_MOBILE_UI
116 d->ui.descLabel->hide();
117 d->ui.setDefault->hide();
123 QTreeWidgetItem *treeItem =
new QTreeWidgetItem( d->ui.typeListView );
124 treeItem->setText( 0, type.
name() );
126 treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( type ) );
128 d->ui.typeListView->resizeColumnToContents( 0 );
130 d->ui.typeListView->setFocus();
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()) );
150void AddTransportDialog::accept()
152 if ( !d->selectedType().isValid() ) {
159 if ( d->selectedType().type() == Transport::EnumType::Akonadi ) {
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();
168 transport->setHost( cjob->instance().identifier() );
170 transport->setName( d->ui.name->text().trimmed() );
175#ifndef KDEPIM_MOBILE_UI
176 if ( d->ui.setDefault->isChecked() ) {
184#include "moc_addtransportdialog.cpp"
AddTransportDialog(QWidget *parent=0)
Creates a new AddTransportDialog.
virtual ~AddTransportDialog()
Destroys the AddTransportDialog.
Q_SCRIPTABLE void setDefaultTransport(int id)
Sets the default transport.
void addTransport(Transport *transport)
Adds the given transport.
static TransportManager * self()
Returns the TransportManager instance.
Transport * createTransport() const
Creates a new, empty Transport object.
A representation of a transport type.
QString description() const
Returns a description of the transport type.
QString name() const
Returns the i18n'ed name of the transport type.
Represents the settings of a specific mail transport.
void forceUniqueName()
Makes sure the transport has a unique name.
void setTransportType(const TransportType &type)
Sets the type of this transport.