Commit 45173232 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve import settings.

Add abstract class for addressbook (empty for the moment)
parent 6b8cb42b
......@@ -14,6 +14,7 @@ abstractimporter.cpp
selectcomponentpage.cpp
importfilterinfogui.cpp
abstractsettings.cpp
abstractaddressbook.cpp
thunderbird/thunderbirdimportdata.cpp
thunderbird/thunderbirdsettings.cpp
sylpheed/sylpheedimportdata.cpp
......
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "abstractaddressbook.h"
#include "importwizard.h"
AbstractAddressBook::AbstractAddressBook(ImportWizard *parent)
:mImportWizard(parent)
{
}
AbstractAddressBook::~AbstractAddressBook()
{
}
/*
Copyright (c) 2012 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ABSTRACTADDRESSBOOK_H
#define ABSTRACTADDRESSBOOK_H
class ImportWizard;
class AbstractAddressBook
{
public:
explicit AbstractAddressBook(ImportWizard *parent);
~AbstractAddressBook();
private:
ImportWizard *mImportWizard;
};
#endif // ABSTRACTADDRESSBOOK_H
......@@ -63,7 +63,7 @@ MailTransport::Transport *AbstractSettings::createTransport()
return mt;
}
void AbstractSettings::createResource( const QString& resources )
void AbstractSettings::createResource( const QString& resources, const QMap<QString, QVariant>& settings )
{
const AgentType type = AgentManager::self()->type( resources );
if ( !type.isValid() ) {
......@@ -85,54 +85,49 @@ void AbstractSettings::createResource( const QString& resources )
addFilterImportInfo( i18n( "Creating resource instance for '%1'...", type.name() ) );
AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type, this );
connect( job, SIGNAL(result(KJob*)), SLOT(instanceCreateResult(KJob*)) );
job->start();
}
void AbstractSettings::instanceCreateResult(KJob* job)
{
#if 0
if ( job->error() ) {
addFilterImportError( i18n( "Failed to create resource instance: %1", job->errorText() ) );
return;
}
m_instance = qobject_cast<AgentInstanceCreateJob*>( job )->instance();
if ( !m_settings.isEmpty() ) {
addFilterImportInfo( i18n( "Configuring resource instance..." ) );
QDBusInterface iface( "org.freedesktop.Akonadi.Resource." + m_instance.identifier(), "/Settings" );
if ( !iface.isValid() ) {
addFilterImportError( i18n( "Unable to configure resource instance." ) );
return;
}
// configure resource
if ( !m_name.isEmpty() )
m_instance.setName( m_name );
QMap<QString, QVariant>::const_iterator end( m_settings.constEnd());
for ( QMap<QString, QVariant>::const_iterator it = m_settings.constBegin(); it != end; ++it ) {
kDebug() << "Setting up " << it.key() << " for agent " << m_instance.identifier();
const QString methodName = QString::fromLatin1("set%1").arg( it.key() );
QVariant arg = it.value();
const QVariant::Type targetType = argumentType( iface.metaObject(), methodName );
if ( !arg.canConvert( targetType ) ) {
addFilterImportError( i18n( "Could not convert value of setting '%1' to required type %2.", it.key(), QVariant::typeToName( targetType ) ) );
if(job->exec()) {
#if 0
Akonadi::AgentInstance instance = job->instance();
if ( !settings.isEmpty() ) {
addFilterImportInfo( i18n( "Configuring resource instance..." ) );
QDBusInterface iface( "org.freedesktop.Akonadi.Resource." + instance.identifier(), "/Settings" );
if ( !iface.isValid() ) {
addFilterImportError( i18n( "Unable to configure resource instance." ) );
return;
}
arg.convert( targetType );
QDBusReply<void> reply = iface.call( methodName, arg );
if ( !reply.isValid() ) {
addFilterImportError( i18n( "Could not set setting '%1': %2", it.key(), reply.error().message() ) );
return;
// configure resource
if ( !m_name.isEmpty() )
instance.setName( m_name );
QMap<QString, QVariant>::const_iterator end( settings.constEnd());
for ( QMap<QString, QVariant>::const_iterator it = settings.constBegin(); it != end; ++it ) {
kDebug() << "Setting up " << it.key() << " for agent " << instance.identifier();
const QString methodName = QString::fromLatin1("set%1").arg( it.key() );
QVariant arg = it.value();
const QVariant::Type targetType = argumentType( iface.metaObject(), methodName );
if ( !arg.canConvert( targetType ) ) {
addFilterImportError( i18n( "Could not convert value of setting '%1' to required type %2.", it.key(), QVariant::typeToName( targetType ) ) );
return;
}
arg.convert( targetType );
QDBusReply<void> reply = iface.call( methodName, arg );
if ( !reply.isValid() ) {
addFilterImportError( i18n( "Could not set setting '%1': %2", it.key(), reply.error().message() ) );
return;
}
}
instance.reconfigure();
}
m_instance.reconfigure();
}
addFilterImportError( i18n( "Resource setup completed." ) );
addFilterImportError( i18n( "Resource setup completed." ) );
#endif
} else {
if ( job->error() ) {
addFilterImportError( i18n( "Failed to create resource instance: %1", job->errorText() ) );
}
}
}
void AbstractSettings::addFilterImportInfo( const QString& log )
......
......@@ -19,7 +19,7 @@
#define ABSTRACTSETTINGS_H
#include <QObject>
#include <QMap>
class ImportWizard;
class KJob;
......@@ -38,14 +38,12 @@ class AbstractSettings : public QObject
public:
explicit AbstractSettings(ImportWizard *parent);
~AbstractSettings();
private slots:
void instanceCreateResult( KJob* job );
protected:
void addFilterImportInfo( const QString& log );
void addFilterImportError( const QString& log );
void createResource( const QString& resources );
void createResource(const QString& resources , const QMap<QString, QVariant> &settings);
KPIMIdentities::Identity* createIdentity();
MailTransport::Transport *createTransport();
void storeIdentity(KPIMIdentities::Identity* identity);
......
......@@ -18,16 +18,59 @@
#include "evolutionsettings.h"
#include <KConfig>
#include <KConfigGroup>
#include <KDebug>
#include <QRegExp>
#include <QStringList>
#include <QFile>
#include <QDomDocument>
#include <QDomElement>
#include <QDebug>
EvolutionSettings::EvolutionSettings( const QString& filename, ImportWizard *parent )
:AbstractSettings( parent )
{
//Read gconf file
QFile file(filename);
if ( !file.open( QIODevice::ReadOnly ) ) {
qDebug()<<" We can't open file"<<filename;
return;
}
QDomDocument doc;
QString errorMsg;
int errorRow;
int errorCol;
if ( !doc.setContent( &file, &errorMsg, &errorRow, &errorCol ) ) {
kDebug() << "Unable to load document.Parse error in line " << errorRow
<< ", col " << errorCol << ": " << errorMsg;
return;
}
return;
QDomElement config = doc.documentElement();
if ( config.isNull() ) {
kDebug() << "No config found";
return;
}
for ( QDomElement e = config.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() ) {
const QString tag = e.tagName();
if ( tag == QLatin1String( "entry" ) ) {
if(e.hasAttribute( "name" ) && e.attribute("name") == QLatin1String("accounts") )
{
readAccount(e);
}
}
}
}
EvolutionSettings::~EvolutionSettings()
{
}
void EvolutionSettings::readAccount(const QDomElement &account)
{
for ( QDomElement accountConfig = account.firstChildElement(); !accountConfig.isNull(); accountConfig = accountConfig.nextSiblingElement() ) {
if(accountConfig.tagName() == QLatin1String("li")) {
//TODO
}
}
}
......@@ -23,6 +23,7 @@
class ImportWizard;
class KConfigGroup;
class QDomElement;
class EvolutionSettings : public AbstractSettings
{
......@@ -30,6 +31,8 @@ public:
explicit EvolutionSettings(const QString& filename, ImportWizard *parent );
~EvolutionSettings();
private:
void readAccount(const QDomElement &account);
};
#endif /* EVOLUTIONSETTINGS_H */
......
......@@ -56,7 +56,7 @@ QString Evolutionv3ImportData::name() const
bool Evolutionv3ImportData::importSettings()
{
const QString accountFile = mPath + QLatin1String("/accountrc");
const QString accountFile = QDir::homePath() + QLatin1String("/.gconf/apps/evolution/mail/%gconf");
if ( QFile( accountFile ).exists() ) {
EvolutionSettings account( accountFile, mImportWizard );
return true;
......
......@@ -16,6 +16,7 @@
*/
#include "sylpheedsettings.h"
#include <mailtransport/transportmanager.h>
#include <kpimidentities/identity.h>
......@@ -43,30 +44,49 @@ SylpheedSettings::~SylpheedSettings()
{
}
void SylpheedSettings::readPop3Account( const KConfigGroup& accountConfig )
{
//TODO
QMap<QString, QVariant> settings;
createResource( "akonadi_pop3_resource", settings );
}
void SylpheedSettings::readImapAccount( const KConfigGroup& accountConfig )
{
//TODO
QMap<QString, QVariant> settings;
createResource( "akonadi_imap_resource", settings );
}
void SylpheedSettings::readAccount( const KConfigGroup& accountConfig )
{
if ( accountConfig.hasKey( QLatin1String( "protocol" ) ) )
{
const int protocol = accountConfig.readEntry( QLatin1String( "protocol" ), 0 );
//TODO
QMap<QString, QVariant> settings;
switch( protocol )
{
case 0:
//pop3
break;
case 3:
//imap
break;
case 4:
//news
break;
case 5:
//local
break;
case 0:
readPop3Account( accountConfig );
break;
case 3:
//imap
readImapAccount(accountConfig);
break;
case 4:
qDebug()<<" we can't create news item";
//news
break;
case 5:
//local
break;
}
}
const QString name = accountConfig.readEntry( QLatin1String( "name" ) );
const QString smtp = accountConfig.readEntry( QLatin1String( "smtp_server" ) );
}
......@@ -74,9 +94,43 @@ void SylpheedSettings::readIdentity( const KConfigGroup& accountConfig )
{
const QString organization = accountConfig.readEntry( QLatin1String( "organization" ), QString() );
const QString email = accountConfig.readEntry( QLatin1String( "address" ) );
const QString bcc = accountConfig.readEntry(QLatin1String("auto_bcc"));
const QString cc = accountConfig.readEntry(QLatin1String("auto_cc"));
const QString draft = accountConfig.readEntry(QLatin1String("draft_folder"));
const QString sent = accountConfig.readEntry(QLatin1String("sent_folder"));
KPIMIdentities::Identity* identity = createIdentity();
identity->setOrganization(organization);
identity->setPrimaryEmailAddress(email);
identity->setBcc(bcc);
identity->setDrafts(draft); //FIXME
identity->setFcc(sent);//FIXME
//identity->setcc(cc); //FIXME
const QString transportId = readTransport(accountConfig);
if(!transportId.isEmpty())
{
identity->setTransport(transportId);
}
storeIdentity(identity);
}
QString SylpheedSettings::readTransport( const KConfigGroup& accountConfig )
{
const QString smtpservername = accountConfig.readEntry("receive_server");
const QString smtpserver = accountConfig.readEntry("smtp_server");
if(!smtpserver.isEmpty()) {
MailTransport::Transport *mt = createTransport();
mt->setName( smtpservername );
mt->writeConfig();
MailTransport::TransportManager::self()->addTransport( mt );
MailTransport::TransportManager::self()->setDefaultTransport( mt->id() );
return QString::number(mt->id()); //TODO verify
/*
smtp_auth_method=0
smtp_user_id=
smtp_password=
ssl_smtp=0
*/
}
return QString();//TODO
}
......@@ -32,6 +32,10 @@ public:
private:
void readAccount( const KConfigGroup& accountConfig );
void readIdentity( const KConfigGroup& accountConfig );
QString readTransport( const KConfigGroup& accountConfig );
void readPop3Account( const KConfigGroup& accountConfig );
void readImapAccount( const KConfigGroup& accountConfig );
};
#endif /* SYLPHEEDSETTINGS_H */
......
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