Commit 677e7b31 authored by Constantin Berzan's avatar Constantin Berzan
Browse files

TransportTypeInfo class to avoid having to switch( type ) in a bunch of places.

svn path=/branches/kdepim/soc/kdepimlibs/; revision=977793
parent e21c8726
......@@ -8,6 +8,7 @@ add_definitions( -DKDE_DEFAULT_DEBUG_AREA=5324 )
set(mailtransport_lib_srcs
transport.cpp
transportmanager.cpp
transporttypeinfo.cpp
transportcombobox.cpp
transportlistview.cpp
......
......@@ -2,13 +2,11 @@
* 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
* figure out what needs to be exported and what not (add .hs to CMakeLists afterwards)
* 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
......@@ -21,16 +21,16 @@
#include "addtransportassistant.h"
#include "transport.h"
#include "transportconfigwidget.h"
#include "transportmanager.h"
#include "transporttypeinfo.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"
......@@ -74,6 +74,9 @@ AddTransportAssistant::AddTransportAssistant( QWidget *parent )
: KAssistantDialog( parent )
, d( new Private )
{
d->transport = TransportManager::self()->createTransport();
Q_ASSERT( d->transport );
// type page
d->typePage = new QWidget( this );
d->uiTypePage.setupUi( d->typePage );
......@@ -86,19 +89,11 @@ AddTransportAssistant::AddTransportAssistant( QWidget *parent )
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() ) {
for( int i = 0; i < TransportTypeInfo::typeCount(); i++ ) {
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 );
treeItem->setData( 0, Qt::UserRole, i ); // the transport type
treeItem->setText( 0, TransportTypeInfo::nameForType( i ) );
treeItem->setText( 1, TransportTypeInfo::descriptionForType( i ) );
}
d->uiTypePage.typeListView->resizeColumnToContents( 0 );
d->uiTypePage.typeListView->setFocus();
......@@ -168,7 +163,7 @@ void AddTransportAssistant::next()
d->transport->setType( type );
d->lastType = type;
delete d->configPageContents;
d->configPageContents = TransportManager::self()->configWidgetForTransport( d->transport, d->configPage );
d->configPageContents = TransportTypeInfo::configWidgetForTransport( d->transport, d->configPage );
// let the configWidget's KConfigDialogManager handle kcfg_name:
KConfigDialogManager *mgr = d->configPageContents->configManager();
......
......@@ -21,15 +21,12 @@
<choices>
<choice name="SMTP">
<label>SMTP Server</label>
<whatsthis>TODO smtp description</whatsthis>
</choice>
<choice name="Sendmail">
<label>Local sendmail</label>
<whatsthis>TODO sendmail description</whatsthis>
</choice>
<choice name="Akonadi">
<label>Akonadi Resource</label>
<whatsthis>TODO Akonadi description</whatsthis>
</choice>
</choices>
<label>Transport type</label>
......
......@@ -27,6 +27,7 @@
#include "transport.h"
#include "transportconfigwidget.h"
#include "transportmanager.h"
#include "transporttypeinfo.h"
#include <QString>
......@@ -47,7 +48,7 @@ TransportConfigDialog::TransportConfigDialog( Transport *transport, QWidget *par
{
Q_ASSERT( transport );
d->configWidget = TransportManager::self()->configWidgetForTransport( transport );
d->configWidget = TransportTypeInfo::configWidgetForTransport( transport );
kDebug() << "transport" << transport->id() << "config widget" << d->configWidget;
Q_ASSERT( d->configWidget );
setMainWidget( d->configWidget );
......
......@@ -24,6 +24,7 @@
#include "transportlistview.h"
#include "transport.h"
#include "transportmanager.h"
#include "transporttypeinfo.h"
#include <QHeaderView>
#include <QLineEdit>
......@@ -100,19 +101,7 @@ void TransportListView::fillTransportList()
QTreeWidgetItem *item = new QTreeWidgetItem( this );
item->setData( 0, Qt::UserRole, t->id() );
item->setText( 0, t->name() );
QString type;
// TODO: perhaps Transport or TransportManager should have nameForType()?
switch ( t->type() ) {
case Transport::EnumType::SMTP:
type = i18nc( "@option SMTP transport", "SMTP" );
break;
case Transport::EnumType::Sendmail:
type = i18nc( "@option sendmail transport", "Sendmail" );
break;
case Transport::EnumType::Akonadi:
type = i18nc( "@option Akonadi Resource transport", "Akonadi Resource" );
break;
}
QString type = TransportTypeInfo::nameForType( t->type() );
if ( TransportManager::self()->defaultTransportId() == t->id() ) {
type += i18nc( "@label the default mail transport", " (Default)" );
}
......@@ -121,8 +110,6 @@ void TransportListView::fillTransportList()
setCurrentItem( item );
}
}
// updateButtonState(); //TODO see comment in TransportManagementWidget
}
......
......@@ -20,13 +20,9 @@
#include "transportmanager.h"
#include "mailtransport_defs.h"
#include "transport.h"
#include "akonadijob.h"
#include "sendmailjob.h"
#include "smtpjob.h"
#include "transportconfigwidget.h"
#include "sendmailconfigwidget.h"
#include "akonadiconfigwidget.h"
#include "smtpconfigwidget.h"
#include "transportjob.h"
#include "transporttypeinfo.h"
#include <kconfig.h>
#include <kdebug.h>
......@@ -213,16 +209,7 @@ TransportJob *TransportManager::createTransportJob( int transportId )
if ( !t ) {
return 0;
}
switch ( t->type() ) {
case Transport::EnumType::SMTP:
return new SmtpJob( t->clone(), this );
case Transport::EnumType::Sendmail:
return new SendmailJob( t->clone(), this );
case Transport::EnumType::Akonadi:
return new AkonadiJob( t->clone(), this );
}
Q_ASSERT( false );
return 0;
return TransportTypeInfo::jobForTransport( t->clone(), this );
}
TransportJob *TransportManager::createTransportJob( const QString &transport )
......@@ -246,23 +233,6 @@ TransportJob *TransportManager::createTransportJob( const QString &transport )
return 0;
}
TransportConfigWidget *TransportManager::configWidgetForTransport( Transport *transport, QWidget *parent )
{
Q_ASSERT( transport );
switch( transport->type() ) {
case Transport::EnumType::SMTP:
return new SMTPConfigWidget( transport, parent );
case Transport::EnumType::Sendmail:
return new SendmailConfigWidget( transport, parent );
case Transport::EnumType::Akonadi:
return new AkonadiConfigWidget( transport, parent );
}
Q_ASSERT( false );
return 0;
}
bool TransportManager::isEmpty() const
{
return d->transports.isEmpty();
......
......@@ -140,17 +140,6 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
*/
void createDefaultTransport();
/**
Creates an appropriate configuration widget for the transport, depending
on its type.
@param transport The transport
@param parent The parent passed to the widget's constructor
TODO should this be public?
*/
TransportConfigWidget *configWidgetForTransport( Transport *transport, QWidget *parent = 0 );
public Q_SLOTS:
/**
Returns true if there are no mail transports at all.
......
/*
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 "transporttypeinfo.h"
#include "akonadiconfigwidget.h"
#include "sendmailconfigwidget.h"
#include "smtpconfigwidget.h"
#include "akonadijob.h"
#include "sendmailjob.h"
#include "smtpjob.h"
#include "transport.h"
#include <QObject>
#include <QWidget>
#include <KLocalizedString>
using namespace MailTransport;
int TransportTypeInfo::typeCount()
{
return 3;
}
QString TransportTypeInfo::nameForType( int type )
{
switch( type ) {
case Transport::EnumType::SMTP:
return i18nc( "@option SMTP transport", "SMTP" );
case Transport::Transport::EnumType::Sendmail:
return i18nc( "@option sendmail transport", "Sendmail" );
case Transport::EnumType::Akonadi:
return i18nc( "@option Akonadi Resource transport", "Akonadi Resource" );
}
Q_ASSERT( false );
return QString();
}
QString TransportTypeInfo::descriptionForType( int type )
{
// TODO polish these
switch( type ) {
case Transport::EnumType::SMTP:
return i18n( "An SMTP server on the internet" );
case Transport::EnumType::Sendmail:
return i18n( "A local sendmail installation" );
case Transport::EnumType::Akonadi:
return i18n( "A local Akonadi resource with the ability to send mail" );
}
Q_ASSERT( false );
return QString();
}
TransportJob *TransportTypeInfo::jobForTransport( Transport *transport, QObject *parent )
{
switch( transport->type() ) {
case Transport::EnumType::SMTP:
return new SmtpJob( transport, parent );
case Transport::EnumType::Sendmail:
return new SendmailJob( transport, parent );
case Transport::EnumType::Akonadi:
return new AkonadiJob( transport, parent );
}
Q_ASSERT( false );
return 0;
}
TransportConfigWidget *TransportTypeInfo::configWidgetForTransport( Transport *transport, QWidget *parent )
{
switch( transport->type() ) {
case Transport::EnumType::SMTP:
return new SMTPConfigWidget( transport, parent );
case Transport::EnumType::Sendmail:
return new SendmailConfigWidget( transport, parent );
case Transport::EnumType::Akonadi:
return new AkonadiConfigWidget( transport, parent );
}
Q_ASSERT( false );
return 0;
}
/*
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_TRANSPORTTYPEINFO_H
#define MAILTRANSPORT_TRANSPORTTYPEINFO_H
#include <QString>
class QObject;
class QWidget;
namespace MailTransport {
class Transport;
class TransportConfigWidget;
class TransportJob;
/**
A class providing central information about the types supported by
Mailtransport. It avoids having to switch(type) all over the place.
TODO export?
TODO docu
*/
class TransportTypeInfo
{
public:
static int typeCount();
static QString nameForType( int type );
static QString descriptionForType( int type );
static TransportJob *jobForTransport( Transport *transport, QObject *parent = 0 );
static TransportConfigWidget *configWidgetForTransport( Transport *transport, QWidget *parent = 0 );
private:
TransportTypeInfo();
~TransportTypeInfo();
};
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment