Commit 123491f9 authored by Volker Krause's avatar Volker Krause
Browse files

Add support for adhoc transports (as eg. available in KMail's composer).

svn path=/trunk/KDE/kdepim/mailtransport/; revision=620491
parent 650147fb
......@@ -19,10 +19,6 @@ TransportManager
(create a copy for edit?)
- load passwords if another instance opens the wallet
TransportComboBox
-----------------
- handle ad-hoc transports (see identity dialog)
Transport
---------
- password is not reloaded from wallet on remote change
......
......@@ -102,7 +102,7 @@ void SmtpJob::doStart()
{
QString user = transport()->userName();
QString passwd = transport()->password();
bool keep = transport()->storePassword();
bool keep = !transport()->isAdHoc(); // do not provide keep checkbox for adhoc transports
int result;
#warning yet another KMail specific thing
......
......@@ -38,6 +38,7 @@ TransportMgr::TransportMgr() :
{
new TransportManagementWidget( this );
mComboBox = new TransportComboBox( this );
mComboBox->setEditable( true );
QPushButton *b = new QPushButton( "&Edit", this );
connect( b, SIGNAL(clicked(bool)), SLOT(editBtnClicked()) );
mSenderEdit = new KLineEdit( this );
......@@ -59,6 +60,10 @@ TransportMgr::TransportMgr() :
void TransportMgr::editBtnClicked()
{
if ( mComboBox->isAdHocTransport() ) {
kDebug() << k_funcinfo << "Cannot edit adhoc transport!" << endl;
return;
}
TransportConfigDialog *t = new TransportConfigDialog( TransportManager::self()->transportById( mComboBox->currentTransportId() ), this );
t->exec();
delete t;
......@@ -66,8 +71,15 @@ void TransportMgr::editBtnClicked()
void TransportMgr::sendBtnClicked()
{
TransportJob *job = TransportManager::self()->createTransportJob( mComboBox->currentTransportId() );
Q_ASSERT( job );
TransportJob *job;
if ( mComboBox->isAdHocTransport() )
job = TransportManager::self()->createTransportJob( mComboBox->currentText() );
else
job = TransportManager::self()->createTransportJob( mComboBox->currentTransportId() );
if ( !job ) {
kDebug() << k_funcinfo << "Invalid transport!" << endl;
return;
}
job->setSender( mSenderEdit->text() );
job->setTo( mToEdit->text().isEmpty() ? QStringList() : mToEdit->text().split(',') );
job->setCc( mCcEdit->text().isEmpty() ? QStringList() : mCcEdit->text().split(',') );
......
......@@ -35,7 +35,8 @@ Transport::Transport( const QString &cfgGroup ) :
mPasswordLoaded( false ),
mPasswordDirty( false ),
mStorePasswordInFile( false ),
mNeedsWalletMigration( false )
mNeedsWalletMigration( false ),
mIsAdHoc( false )
{
kDebug() << k_funcinfo << cfgGroup << endl;
readConfig();
......@@ -43,7 +44,7 @@ Transport::Transport( const QString &cfgGroup ) :
bool Transport::isValid() const
{
return id() > 0 && !host().isEmpty() && port() <= 65536;
return (id() > 0 || isAdHoc()) && !host().isEmpty() && port() <= 65536;
}
QString Transport::password()
......@@ -110,6 +111,9 @@ void Transport::usrReadConfig()
void Transport::usrWriteConfig()
{
if ( isAdHoc() )
return;
if ( requiresAuthentication() && storePassword() && mPasswordDirty ) {
Wallet *wallet = TransportManager::self()->wallet();
if ( !wallet || wallet->writePassword(QString::number(id()), mPassword) != 0 ) {
......@@ -189,3 +193,13 @@ void Transport::migrateToWallet()
mStorePasswordInFile = false;
writeConfig();
}
bool Transport::isAdHoc() const
{
return mIsAdHoc;
}
void Transport::setAdHoc(bool b)
{
mIsAdHoc = b;
}
......@@ -67,6 +67,12 @@ class MAILTRANSPORT_EXPORT Transport : public TransportBase
*/
QString authenticationTypeString() const;
/**
Returns true if this is a adhoc transport, ie. a non-perisistent transport
configuration based on a url entered by the user.
*/
bool isAdHoc() const;
protected:
/**
Creates a Transport object. Should only be used by TransportManager.
......@@ -87,6 +93,11 @@ class MAILTRANSPORT_EXPORT Transport : public TransportBase
*/
void migrateToWallet();
/**
Sets the adhoc flag.
*/
void setAdHoc( bool b );
private:
void readPassword();
......@@ -96,6 +107,7 @@ class MAILTRANSPORT_EXPORT Transport : public TransportBase
bool mPasswordDirty;
bool mStorePasswordInFile;
bool mNeedsWalletMigration;
bool mIsAdHoc;
};
}
......
/*
Copyright (c) 2006 Volker Krause <vkrause@kde.org>
Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
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
......@@ -23,6 +23,8 @@
#include <kdebug.h>
#include <klocale.h>
#include <qlineedit.h>
using namespace KPIM;
TransportComboBox::TransportComboBox(QWidget * parent) :
......@@ -34,21 +36,31 @@ TransportComboBox::TransportComboBox(QWidget * parent) :
int TransportComboBox::currentTransportId() const
{
if( currentIndex() > 0 && currentIndex() <= mTransports.count() )
if ( currentIndex() == 0 )
return 0;
if( currentIndex() > 0 && currentIndex() < mTransports.count() )
return mTransports.at( currentIndex() );
return 0;
return -1;
}
void TransportComboBox::setCurrentTransport(int transportId)
{
int i = mTransports.indexOf( transportId );
if ( i >= 0 && i <= count() )
if ( i >= 0 && i < count() )
setCurrentIndex( i );
}
bool TransportComboBox::isAdHocTransport() const
{
return currentTransportId() == -1;
}
void TransportComboBox::fillComboBox()
{
int oldTransport = currentTransportId();
QString oldText;
if ( lineEdit() )
oldText = lineEdit()->text();
clear();
mTransports.clear();
......@@ -64,6 +76,8 @@ void TransportComboBox::fillComboBox()
}
setCurrentTransport( oldTransport );
if ( lineEdit() )
lineEdit()->setText( oldText );
}
#include "transportcombobox.moc"
/*
Copyright (c) 2006 Volker Krause <vkrause@kde.org>
Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
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
......@@ -41,6 +41,9 @@ class MAILTRANSPORT_EXPORT TransportComboBox : public KComboBox
/**
Returns identifier of the currently selected mail transport.
Note: This returns an invalid id if an adhoc transport is
selected.
@see isAdHocTransport()
*/
int currentTransportId() const;
......@@ -50,6 +53,13 @@ class MAILTRANSPORT_EXPORT TransportComboBox : public KComboBox
*/
void setCurrentTransport( int transportId );
/**
Returns true if the selected transport is an adhoc transport,
ie. an url entered directly (only possible if the setEditable(true)
has been called.
*/
bool isAdHocTransport() const;
private slots:
void fillComboBox();
......
......@@ -48,6 +48,8 @@ TransportJob::TransportJob( Transport* transport, QObject * parent ) :
TransportJob::~ TransportJob()
{
if ( d->transport->isAdHoc() )
delete d->transport;
delete d;
}
......
......@@ -24,12 +24,12 @@
#include "sendmailjob.h"
#include <kconfig.h>
#include <kconfigbase.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <krandom.h>
#include <kstaticdeleter.h>
#include <kurl.h>
#include <kwallet.h>
#include <QApplication>
......@@ -137,7 +137,7 @@ void TransportManager::schedule(TransportJob * job)
job->start();
}
TransportJob* TransportManager::createTransportJob(int transportId)
TransportJob* TransportManager::createTransportJob( int transportId )
{
Transport *t = transportById( transportId, false );
if ( !t )
......@@ -152,7 +152,68 @@ TransportJob* TransportManager::createTransportJob(int transportId)
return 0;
}
bool KPIM::TransportManager::isEmpty() const
TransportJob* TransportManager::createTransportJob(const QString & transport)
{
bool ok = false;
Transport *t = 0;
int transportId = transport.toInt( &ok );
if ( ok )
t = transportById( transportId );
if ( !t )
t = transportByName( transport, false );
if ( t )
return createTransportJob( t->id() );
KUrl url( transport );
if ( !url.isValid() )
return 0;
t = new Transport( "adhoc" );
t->setDefaults();
t->setName( transport );
t->setAdHoc( true );
if ( url.protocol() == SMTP_PROTOCOL || url.protocol() == SMTPS_PROTOCOL ) {
t->setType( Transport::EnumType::SMTP );
t->setHost( url.host() );
if ( url.protocol() == SMTPS_PROTOCOL ) {
t->setEncryption( Transport::EnumEncryption::SSL );
t->setPort( SMTPS_PORT );
}
if ( url.hasPort() )
t->setPort( url.port() );
if ( url.hasUser() ) {
t->setRequiresAuthentication( true );
t->setUserName( url.user() );
}
}
else if ( url.protocol() == "file" ) {
t->setType( Transport::EnumType::Sendmail );
t->setHost( url.path( KUrl::RemoveTrailingSlash ) );
}
else {
delete t;
return 0;
}
switch ( t->type() ) {
case Transport::EnumType::SMTP:
return new SmtpJob( t, this );
case Transport::EnumType::Sendmail:
return new SendmailJob( t, this );
}
delete t;
Q_ASSERT( false );
return 0;
}
bool TransportManager::isEmpty() const
{
return mTransports.isEmpty();
}
......
......@@ -115,6 +115,14 @@ class MAILTRANSPORT_EXPORT TransportManager : public QObject
*/
TransportJob* createTransportJob( int transportId );
/**
Creates a mail transport job for the given transport identifer,
transport name or adhoc transport description.
Returns 0 if the specified transport is invalid.
@param transport A string defining a mail transport.
*/
TransportJob* createTransportJob( const QString &transport );
/**
Executes the given transport job. This is the preferred way to start
transport jobs. It takes care of asynchronously loading passwords from
......
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