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"
29 #include <akonadi/agentinstance.h>
30 #include <akonadi/agentinstancecreatejob.h>
32 using namespace MailTransport;
37 class AddTransportDialog::Private
54 void updateOkButton();
59 ::Ui::AddTransportDialog ui;
63 void AddTransportDialog::Private::writeConfig()
65 KConfigGroup group( KGlobal::config(),
"AddTransportDialog" );
66 group.writeEntry(
"Size", q->size() );
69 void AddTransportDialog::Private::readConfig()
71 KConfigGroup group( KGlobal::config(),
"AddTransportDialog" );
72 const QSize sizeDialog = group.readEntry(
"Size", QSize(300,200) );
73 if ( sizeDialog.isValid() ) {
74 q->resize( sizeDialog );
78 TransportType AddTransportDialog::Private::selectedType()
const
80 QList<QTreeWidgetItem*> sel = ui.typeListView->selectedItems();
82 return sel.first()->data( 0, Qt::UserRole ).value<
TransportType>();
87 void AddTransportDialog::Private::updateOkButton()
90 q->enableButtonOk( selectedType().isValid() && !ui.name->text().trimmed().isEmpty() );
94 : KDialog( parent ), d( new Private( this ) )
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" ) );
106 #ifdef KDEPIM_MOBILE_UI
107 d->ui.descLabel->hide();
108 d->ui.setDefault->hide();
114 QTreeWidgetItem *treeItem =
new QTreeWidgetItem( d->ui.typeListView );
115 treeItem->setText( 0, type.
name() );
117 treeItem->setData( 0, Qt::UserRole, QVariant::fromValue( type ) );
119 d->ui.typeListView->resizeColumnToContents( 0 );
121 d->ui.typeListView->setFocus();
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()) );
141 void AddTransportDialog::accept()
143 if ( !d->selectedType().isValid() ) {
150 if ( d->selectedType().type() == Transport::EnumType::Akonadi ) {
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();
159 transport->setHost( cjob->instance().identifier() );
161 transport->setName( d->ui.name->text().trimmed() );
166 #ifndef KDEPIM_MOBILE_UI
167 if ( d->ui.setDefault->isChecked() ) {
175 #include "moc_addtransportdialog.cpp"
A representation of a transport type.
QString name() const
Returns the i18n'ed name of the transport type.
void addTransport(Transport *transport)
Adds the given transport.
Q_SCRIPTABLE void setDefaultTransport(int id)
Sets the default transport.
static TransportManager * self()
Returns the TransportManager instance.
void setTransportType(const TransportType &type)
Sets the type of this transport.
QString description() const
Returns a description of the transport type.
Transport * createTransport() const
Creates a new, empty Transport object.
void forceUniqueName()
Makes sure the transport has a unique name.
AddTransportDialog(QWidget *parent=0)
Creates a new AddTransportDialog.
Represents the settings of a specific mail transport.
virtual ~AddTransportDialog()
Destroys the AddTransportDialog.