Commit e21c8726 authored by Constantin Berzan's avatar Constantin Berzan

Initial commit of a more flexible mailtransport, including support for Akonadi...

Initial commit of a more flexible mailtransport, including support for Akonadi resource-based transports.

Changes include:
* separate config widgets for each transport type (smtp, sendmail, akonadi)
* a nice KAssistantDialog for adding transports
* support for renaming transports in the management widget

A lot is still TODO, and this will eventually need an API review.


svn path=/branches/kdepim/soc/kdepimlibs/; revision=977460
parent e435c7ca
......@@ -7,14 +7,25 @@ add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 )
set(mailtransport_lib_srcs
transport.cpp
transportmanager.cpp
transportcombobox.cpp
transportlistview.cpp
transportmanagementwidget.cpp
addtransportassistant.cpp
transportconfigdialog.cpp
transportconfigwidget.cpp
akonadiconfigwidget.cpp
sendmailconfigwidget.cpp
smtpconfigwidget.cpp
transportjob.cpp
transportmanager.cpp
transportmanagementwidget.cpp
akonadijob.cpp
sendmailjob.cpp
smtpjob.cpp
precommandjob.cpp
legacydecrypt.cpp
socket.cpp
servertest.cpp
......@@ -22,14 +33,19 @@ set(mailtransport_lib_srcs
kde4_add_ui_files(mailtransport_lib_srcs
smtpsettings.ui
addtransportassistanttypepage.ui
addtransportassistantnamepage.ui
akonadisettings.ui
sendmailsettings.ui
smtpsettings.ui
transportmanagementwidget.ui
)
kde4_add_kcfg_files(mailtransport_lib_srcs transportbase.kcfgc)
kde4_add_library(mailtransport SHARED ${mailtransport_lib_srcs})
target_link_libraries(mailtransport ${KDE4_KIO_LIBS})
target_link_libraries(mailtransport ${KDE4_KIO_LIBS} akonadi-kde)
set_target_properties(mailtransport PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
install(TARGETS mailtransport EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -43,15 +59,20 @@ install(TARGETS kcm_mailtransport DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kcm_mailtransport.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install( FILES
mailtransport_export.h
transportjob.h
akonadijob.h
sendmailjob.h
smtpjob.h
transport.h
${CMAKE_CURRENT_BINARY_DIR}/transportbase.h
transport.h
transportmanager.h
servertest.h
transportcombobox.h
transportconfigdialog.h
transportjob.h
transportmanagementwidget.h
transportmanager.h
servertest.h
DESTINATION ${INCLUDE_INSTALL_DIR}/mailtransport COMPONENT Devel)
......@@ -29,8 +29,4 @@ Precommand
----------
- test conversion from kprocess to qprocess (TA)
TransportManagementWidget
-------------------------
- support inline editing of transport names
* TransportConfigDialog needs validate()
* all CamelCase...
* smtpsettings.ui has hidden widgets... test those... and why can't I set/see the 'visible' property in designer?
* why is identitylistview in kmail instead of kpimidentities?
* figure out what needs to be exported and what not
* include KLocale or KLocalizedString??
Design:
* is there a way to make KConfig XT give me separate settings for SMTP, Sendmail, Akonadi? Currently all of the settings are for SMTP, and Sendmail and Akonadi just use the 'host' setting for storing the sendmail path or Akonadi resource id, respectively.
* transport type manager to handle all the switches
-> also configWidgetForType
Bugs:
* modify -> change password -> ok. password is saved in wallet and seen ok on restart, but clicking modify again shows old password
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
Based on code from Kopete (addaccountwizard)
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "addtransportassistant.h"
#include <KConfigDialogManager>
#include <KConfigSkeleton>
#include <KDebug>
#include <KVBox>
#include "transportconfigwidget.h"
#include "transport.h"
#include "transportbase.h"
#include "transportmanager.h"
#include "ui_addtransportassistanttypepage.h"
#include "ui_addtransportassistantnamepage.h"
using namespace MailTransport;
/**
@internal
*/
class AddTransportAssistant::Private
{
public:
Private()
: typePage( 0 )
, configPage( 0 )
, namePage( 0 )
, configPageContents( 0 )
, transport( 0 )
, lastType( -1 )
{
}
QTreeWidgetItem* selectedType();
KPageWidgetItem *typeItem;
KPageWidgetItem *configItem;
KPageWidgetItem *nameItem;
QWidget *typePage;
KVBox *configPage;
QWidget *namePage;
TransportConfigWidget *configPageContents;
Transport *transport;
int lastType;
Ui::AddTransportAssistantTypePage uiTypePage;
Ui::AddTransportAssistantNamePage uiNamePage;
};
AddTransportAssistant::AddTransportAssistant( QWidget *parent )
: KAssistantDialog( parent )
, d( new Private )
{
// type page
d->typePage = new QWidget( this );
d->uiTypePage.setupUi( d->typePage );
d->uiTypePage.typeListView->setColumnCount( 2 );
QStringList header;
header << i18n( "Type" ) << i18n( "Description" );
d->uiTypePage.typeListView->setHeaderLabels( header );
d->typeItem = addPage( d->typePage, d->typePage->windowTitle() );
setValid( d->typeItem, false );
// populate type list
// TODO: HACKish way to get transport descriptions...
// TODO TransportManagementWidget has i18ns for transport types -> share?
Q_ASSERT( d->transport == 0 );
d->transport = TransportManager::self()->createTransport();
Q_ASSERT( d->transport );
int enumid = 0;
const KConfigSkeleton::ItemEnum *const item = d->transport->typeItem();
foreach( const KConfigSkeleton::ItemEnum::Choice2 &choice, item->choices2() ) {
QTreeWidgetItem *treeItem = new QTreeWidgetItem( d->uiTypePage.typeListView );
treeItem->setData( 0, Qt::UserRole, enumid ); // the transport type
enumid++;
treeItem->setText( 0, choice.label );
treeItem->setText( 1, choice.whatsThis );
}
d->uiTypePage.typeListView->resizeColumnToContents( 0 );
d->uiTypePage.typeListView->setFocus();
// connect user input
connect( d->uiTypePage.typeListView, SIGNAL( itemClicked( QTreeWidgetItem *, int ) ),
this, SLOT( typeListClicked() ) );
connect( d->uiTypePage.typeListView, SIGNAL( itemSelectionChanged() ),
this, SLOT( typeListClicked() ) );
connect( d->uiTypePage.typeListView, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ),
this, SLOT( typeListDoubleClicked() ) );
// settings page
d->configPage = new KVBox( this );
d->configItem = addPage( d->configPage, i18n( "Step Two: Transport Settings" ) );
// name page
d->namePage = new QWidget( this );
d->uiNamePage.setupUi( d->namePage );
// TODO set up sensible default name
d->nameItem = addPage( d->namePage, d->namePage->windowTitle() );
}
QTreeWidgetItem* AddTransportAssistant::Private::selectedType()
{
QList<QTreeWidgetItem*> sel = uiTypePage.typeListView->selectedItems();
if( !sel.empty() )
return sel.first();
return 0;
}
void AddTransportAssistant::typeListClicked()
{
// Make sure a type is selected before allowing the user to continue.
setValid( d->typeItem, d->selectedType() != 0 );
}
void AddTransportAssistant::typeListDoubleClicked()
{
// Proceed to the next page if a type is double clicked.
next();
}
void AddTransportAssistant::accept()
{
// register transport
d->configPageContents->apply();
TransportManager::self()->addTransport( d->transport );
d->transport = 0; // don't delete it
if( d->uiNamePage.setDefault->isChecked() ) {
TransportManager::self()->setDefaultTransport( d->transport->id() );
}
KAssistantDialog::accept();
}
void AddTransportAssistant::next()
{
if( currentPage() == d->typeItem ) {
QTreeWidgetItem *item = d->selectedType();
int type = item->data( 0, Qt::UserRole ).toInt(); // the transport type
Q_ASSERT( type >= 0 && type < TransportBase::EnumType::COUNT );
// create appropriate config widget
if( d->configPageContents && d->lastType == type ) {
// same type as before; keep settings
} else {
d->transport->setType( type );
d->lastType = type;
delete d->configPageContents;
d->configPageContents = TransportManager::self()->configWidgetForTransport( d->transport, d->configPage );
// let the configWidget's KConfigDialogManager handle kcfg_name:
KConfigDialogManager *mgr = d->configPageContents->configManager();
Q_ASSERT( mgr );
Q_ASSERT( d->namePage );
mgr->addWidget( d->namePage );
}
}
KAssistantDialog::next();
}
void AddTransportAssistant::reject()
{
delete d->transport;
d->transport = 0;
KAssistantDialog::reject();
}
AddTransportAssistant::~AddTransportAssistant()
{
delete d->transport;
delete d;
}
#include "addtransportassistant.moc"
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
Based on code from Kopete (addaccountwizard)
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef MAILTRANSPORT_ADDTRANSPORTASSISTANT_H
#define MAILTRANSPORT_ADDTRANSPORTASSISTANT_H
#include <mailtransport/mailtransport_export.h>
#include <KDE/KAssistantDialog>
namespace MailTransport
{
/**
Assistant to help the user set up a new transport.
*/
class MAILTRANSPORT_EXPORT AddTransportAssistant : public KAssistantDialog
{
Q_OBJECT
public:
// TODO docu
explicit AddTransportAssistant( QWidget *parent = 0 );
~AddTransportAssistant();
private slots:
void typeListClicked();
void typeListDoubleClicked();
protected slots:
virtual void accept();
virtual void next();
virtual void reject();
private:
class Private;
Private * const d;
};
}
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddTransportAssistantNamePage</class>
<widget class="QWidget" name="AddTransportAssistantNamePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>353</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Final Step: Choose Transport Name</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="m_header">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;h2&gt;Congratulations&lt;/h2&gt;
&lt;p&gt;You have finished configuring your mail transport. Please specify a name for it below, and click the Finish button.&lt;/p&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KLineEdit" name="kcfg_name"/>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="setDefault">
<property name="text">
<string>Make this the default mail transport.</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddTransportAssistantTypePage</class>
<widget class="QWidget" name="AddTransportAssistantTypePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>353</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Step One: Select Transport Type</string>
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="m_header">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;h2&gt;Welcome to the Add Transport Assistant&lt;/h2&gt;
&lt;p&gt;Select the transport type from the list below.&lt;/p&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="typeListView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<column>
<property name="text">
<string>1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "akonadiconfigwidget.h"
#include "transportconfigwidget_p.h"
#include "ui_akonadisettings.h"
#include <KStandardDirs>
#include <Akonadi/AgentFilterProxyModel>
#include <Akonadi/AgentInstance>
using namespace Akonadi;
using namespace MailTransport;
class MailTransport::AkonadiConfigWidgetPrivate : public TransportConfigWidgetPrivate
{
public:
Ui::AkonadiSettings ui;
};
AkonadiConfigWidget::AkonadiConfigWidget( Transport *transport, QWidget *parent )
: TransportConfigWidget( *new AkonadiConfigWidgetPrivate, transport, parent )
{
init();
}
AkonadiConfigWidget::AkonadiConfigWidget( AkonadiConfigWidgetPrivate &dd, Transport *transport, QWidget *parent )
: TransportConfigWidget( dd, transport, parent )
{
init();
}
void AkonadiConfigWidget::init()
{
Q_D( AkonadiConfigWidget );
d->ui.setupUi( this );
// The KConfigDialogManager is useless here, it doesn't handle the Akonadi::AgentInstanceWidget
//d->manager->addWidget( this ); // otherwise it doesn't find out about these widgets
//d->manager->updateWidgets();
d->ui.agentInstances->agentFilterProxyModel()->addCapabilityFilter( QLatin1String( "MailTransport" ) );
}
void AkonadiConfigWidget::apply()
{
Q_D( AkonadiConfigWidget );
const AgentInstance instance = d->ui.agentInstances->currentAgentInstance();
if( instance.isValid() ) {
d->transport->setHost( instance.identifier() );
}
TransportConfigWidget::apply();
}
#include "akonadiconfigwidget.moc"
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef MAILTRANSPORT_AKONADICONFIGWIDGET_H
#define MAILTRANSPORT_AKONADICONFIGWIDGET_H
#include "transportconfigwidget.h"
namespace MailTransport {
class Transport;
/**
@internal
*/
class AkonadiConfigWidgetPrivate;
/**
@internal
Configuration widget for an Akonadi transport.
*/
class AkonadiConfigWidget : public TransportConfigWidget
{
Q_OBJECT
public:
explicit AkonadiConfigWidget( Transport *transport, QWidget *parent = 0 );
//virtual ~AkonadiConfigWidget();
public Q_SLOTS:
/** reimpl */
virtual void apply();
protected:
AkonadiConfigWidget( AkonadiConfigWidgetPrivate &dd, Transport *transport, QWidget *parent );
private:
Q_DECLARE_PRIVATE( AkonadiConfigWidget )
void init();
};
}
#endif
/*
Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>