Commit 8c12d98d authored by Laurent Montel's avatar Laurent Montel 😁

Separate code from importwizard

parent 9b2ea142
...@@ -8,6 +8,7 @@ set(libimportwizard_SRCS ...@@ -8,6 +8,7 @@ set(libimportwizard_SRCS
importwizard.cpp importwizard.cpp
importwizardkernel.cpp importwizardkernel.cpp
importmailpluginmanager.cpp importmailpluginmanager.cpp
importwizarddisplayinfo.cpp
) )
set(libimportwizard_manual_SRCS set(libimportwizard_manual_SRCS
......
...@@ -31,10 +31,8 @@ ...@@ -31,10 +31,8 @@
#include <QPointer> #include <QPointer>
using namespace LibImportWizard; using namespace LibImportWizard;
AbstractAddressBook::AbstractAddressBook(ImportWizard *parent) AbstractAddressBook::AbstractAddressBook()
: mImportWizard(parent), : mCollection(-1)
mAbstractDisplayInfo(nullptr),
mCollection(-1)
{ {
} }
...@@ -48,7 +46,7 @@ bool AbstractAddressBook::selectAddressBook() ...@@ -48,7 +46,7 @@ bool AbstractAddressBook::selectAddressBook()
addAddressBookImportInfo(i18n("Creating new contact...")); addAddressBookImportInfo(i18n("Creating new contact..."));
if (!mCollection.isValid()) { if (!mCollection.isValid()) {
const QStringList mimeTypes(KContacts::Addressee::mimeType()); const QStringList mimeTypes(KContacts::Addressee::mimeType());
QPointer<Akonadi::CollectionDialog> dlg = new Akonadi::CollectionDialog(mImportWizard); QPointer<Akonadi::CollectionDialog> dlg = new Akonadi::CollectionDialog(mAbstractDisplayInfo->parentWidget());
dlg->setMimeTypeFilter(mimeTypes); dlg->setMimeTypeFilter(mimeTypes);
dlg->setAccessRightsFilter(Akonadi::Collection::CanCreateItem); dlg->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
dlg->setWindowTitle(i18n("Select Address Book")); dlg->setWindowTitle(i18n("Select Address Book"));
...@@ -88,11 +86,6 @@ void AbstractAddressBook::addImportContactNote(KContacts::Addressee &address, co ...@@ -88,11 +86,6 @@ void AbstractAddressBook::addImportContactNote(KContacts::Addressee &address, co
address.setNote(currentNote); address.setNote(currentNote);
} }
void AbstractAddressBook::setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo)
{
mAbstractDisplayInfo = abstractDisplayInfo;
}
void AbstractAddressBook::createContact(const KContacts::Addressee &address) void AbstractAddressBook::createContact(const KContacts::Addressee &address)
{ {
if (selectAddressBook()) { if (selectAddressBook()) {
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "abstractbase.h" #include "abstractbase.h"
#include "libimportwizard_export.h" #include "libimportwizard_export.h"
class ImportWizard;
namespace KContacts namespace KContacts
{ {
...@@ -40,11 +39,9 @@ class LIBIMPORTWIZARD_EXPORT AbstractAddressBook: public LibImportWizard::Abstra ...@@ -40,11 +39,9 @@ class LIBIMPORTWIZARD_EXPORT AbstractAddressBook: public LibImportWizard::Abstra
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AbstractAddressBook(ImportWizard *parent); AbstractAddressBook();
~AbstractAddressBook(); ~AbstractAddressBook();
void setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo);
protected: protected:
void createGroup(const KContacts::ContactGroup &group); void createGroup(const KContacts::ContactGroup &group);
void createContact(const KContacts::Addressee &address); void createContact(const KContacts::Addressee &address);
...@@ -57,10 +54,6 @@ protected: ...@@ -57,10 +54,6 @@ protected:
void cleanUp(); void cleanUp();
void addImportContactNote(KContacts::Addressee &address, const QString &applicationName); void addImportContactNote(KContacts::Addressee &address, const QString &applicationName);
protected:
ImportWizard *mImportWizard;
AbstractDisplayInfo *mAbstractDisplayInfo;
private: private:
void slotStoreDone(KJob *job); void slotStoreDone(KJob *job);
bool selectAddressBook(); bool selectAddressBook();
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
using namespace Akonadi; using namespace Akonadi;
using namespace LibImportWizard; using namespace LibImportWizard;
AbstractBase::AbstractBase() AbstractBase::AbstractBase()
: mAbstractDisplayInfo(nullptr)
{ {
mCreateResource = new PimCommon::CreateResource(); mCreateResource = new PimCommon::CreateResource();
connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractBase::slotCreateResourceInfo); connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractBase::slotCreateResourceInfo);
...@@ -47,6 +48,11 @@ QString LibImportWizard::AbstractBase::createResource(const QString &resources, ...@@ -47,6 +48,11 @@ QString LibImportWizard::AbstractBase::createResource(const QString &resources,
return mCreateResource->createResource(resources, name, settings); return mCreateResource->createResource(resources, name, settings);
} }
void AbstractBase::setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo)
{
mAbstractDisplayInfo = abstractDisplayInfo;
}
void AbstractBase::slotCreateResourceError(const QString &msg) void AbstractBase::slotCreateResourceError(const QString &msg)
{ {
addImportError(msg); addImportError(msg);
......
...@@ -32,6 +32,7 @@ class CreateResource; ...@@ -32,6 +32,7 @@ class CreateResource;
} }
namespace LibImportWizard namespace LibImportWizard
{ {
class AbstractDisplayInfo;
class LIBIMPORTWIZARD_EXPORT AbstractBase : public QObject class LIBIMPORTWIZARD_EXPORT AbstractBase : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -41,10 +42,14 @@ public: ...@@ -41,10 +42,14 @@ public:
QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings); QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings);
void setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo);
protected: protected:
virtual void addImportInfo(const QString &log) = 0; virtual void addImportInfo(const QString &log) = 0;
virtual void addImportError(const QString &log) = 0; virtual void addImportError(const QString &log) = 0;
AbstractDisplayInfo *mAbstractDisplayInfo;
private: private:
void slotCreateResourceError(const QString &); void slotCreateResourceError(const QString &);
void slotCreateResourceInfo(const QString &); void slotCreateResourceInfo(const QString &);
......
...@@ -18,14 +18,13 @@ ...@@ -18,14 +18,13 @@
*/ */
#include "abstractcalendar.h" #include "abstractcalendar.h"
#include "importwizard.h"
#include "importcalendarpage.h" #include "importcalendarpage.h"
#include "abstract/abstractdisplayinfo.h"
#include <KSharedConfig>
#include <KConfigGroup> #include <KConfigGroup>
using namespace LibImportWizard; using namespace LibImportWizard;
AbstractCalendar::AbstractCalendar(ImportWizard *parent) AbstractCalendar::AbstractCalendar()
: mImportWizard(parent)
{ {
} }
...@@ -35,15 +34,15 @@ AbstractCalendar::~AbstractCalendar() ...@@ -35,15 +34,15 @@ AbstractCalendar::~AbstractCalendar()
void AbstractCalendar::addImportInfo(const QString &log) void AbstractCalendar::addImportInfo(const QString &log)
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importCalendarPage()->addImportInfo(log); mAbstractDisplayInfo->calendarImportInfo(log);
} }
} }
void AbstractCalendar::addImportError(const QString &log) void AbstractCalendar::addImportError(const QString &log)
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importCalendarPage()->addImportError(log); mAbstractDisplayInfo->calendarImportError(log);
} }
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#ifndef ABSTRACTCALENDAR_H #ifndef ABSTRACTCALENDAR_H
#define ABSTRACTCALENDAR_H #define ABSTRACTCALENDAR_H
class ImportWizard;
#include "abstractbase.h" #include "abstractbase.h"
#include "libimportwizard_export.h" #include "libimportwizard_export.h"
#include <QString> #include <QString>
...@@ -30,16 +29,13 @@ class LIBIMPORTWIZARD_EXPORT AbstractCalendar : public LibImportWizard::Abstract ...@@ -30,16 +29,13 @@ class LIBIMPORTWIZARD_EXPORT AbstractCalendar : public LibImportWizard::Abstract
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AbstractCalendar(ImportWizard *parent); AbstractCalendar();
virtual ~AbstractCalendar(); virtual ~AbstractCalendar();
protected: protected:
void addEvenViewConfig(const QString &groupName, const QString &key, const QString &value); void addEvenViewConfig(const QString &groupName, const QString &key, const QString &value);
void addImportInfo(const QString &log) Q_DECL_OVERRIDE; void addImportInfo(const QString &log) Q_DECL_OVERRIDE;
void addImportError(const QString &log) Q_DECL_OVERRIDE; void addImportError(const QString &log) Q_DECL_OVERRIDE;
private:
ImportWizard *mImportWizard;
}; };
} }
#endif // ABSTRACTCALENDAR_H #endif // ABSTRACTCALENDAR_H
...@@ -29,30 +29,50 @@ AbstractDisplayInfo::AbstractDisplayInfo() ...@@ -29,30 +29,50 @@ AbstractDisplayInfo::AbstractDisplayInfo()
void AbstractDisplayInfo::calendarImportError(const QString &log) void AbstractDisplayInfo::calendarImportError(const QString &log)
{ {
Q_UNUSED(log);
} }
void AbstractDisplayInfo::settingsImportError(const QString &log) void AbstractDisplayInfo::settingsImportError(const QString &log)
{ {
Q_UNUSED(log);
} }
void AbstractDisplayInfo::addressbookImportError(const QString &log) void AbstractDisplayInfo::addressbookImportError(const QString &log)
{ {
Q_UNUSED(log);
}
void AbstractDisplayInfo::filterImportError(const QString &log)
{
Q_UNUSED(log);
} }
void AbstractDisplayInfo::calendarImportInfo(const QString &log) void AbstractDisplayInfo::calendarImportInfo(const QString &log)
{ {
Q_UNUSED(log);
} }
void AbstractDisplayInfo::settingsImportInfo(const QString &log) void AbstractDisplayInfo::settingsImportInfo(const QString &log)
{ {
Q_UNUSED(log);
} }
void AbstractDisplayInfo::addressbookImportInfo(const QString &log) void AbstractDisplayInfo::addressbookImportInfo(const QString &log)
{ {
Q_UNUSED(log);
}
void AbstractDisplayInfo::filterImportInfo(const QString &log)
{
Q_UNUSED(log);
}
QWidget *AbstractDisplayInfo::parentWidget() const
{
return nullptr;
}
void AbstractDisplayInfo::initializeFilter(MailImporter::Filter &filter)
{
Q_UNUSED(filter);
} }
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
#include "libimportwizard_export.h" #include "libimportwizard_export.h"
#include <QString> #include <QString>
class QWidget;
namespace MailImporter
{
class Filter;
}
namespace LibImportWizard namespace LibImportWizard
{ {
...@@ -34,10 +40,15 @@ public: ...@@ -34,10 +40,15 @@ public:
virtual void calendarImportError(const QString &log); virtual void calendarImportError(const QString &log);
virtual void settingsImportError(const QString &log); virtual void settingsImportError(const QString &log);
virtual void addressbookImportError(const QString &log); virtual void addressbookImportError(const QString &log);
virtual void filterImportError(const QString &log);
virtual void calendarImportInfo(const QString &log); virtual void calendarImportInfo(const QString &log);
virtual void settingsImportInfo(const QString &log); virtual void settingsImportInfo(const QString &log);
virtual void addressbookImportInfo(const QString &log); virtual void addressbookImportInfo(const QString &log);
virtual void filterImportInfo(const QString &log);
virtual QWidget *parentWidget() const;
virtual void initializeFilter(MailImporter::Filter &filter);
}; };
} }
......
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
*/ */
#include "abstractimporter.h" #include "abstractimporter.h"
#include "importwizard.h"
#include "importmailpage.h" #include "importmailpage.h"
#include "importfilterinfogui.h" #include "importfilterinfogui.h"
#include "importfilterpage.h" #include "importfilterpage.h"
#include "importsettingpage.h" #include "importsettingpage.h"
#include "importcalendarpage.h" #include "importcalendarpage.h"
#include "abstract/abstractdisplayinfo.h"
#include "mailimporter/filterinfo.h" #include "mailimporter/filterinfo.h"
#include "MailCommon/FilterManager" #include "MailCommon/FilterManager"
...@@ -35,7 +35,6 @@ using namespace LibImportWizard; ...@@ -35,7 +35,6 @@ using namespace LibImportWizard;
AbstractImporter::AbstractImporter(QObject *parent) AbstractImporter::AbstractImporter(QObject *parent)
: QObject(parent), : QObject(parent),
mImportWizard(nullptr),
mAbstractDisplayInfo(nullptr), mAbstractDisplayInfo(nullptr),
mParentWidget(nullptr) mParentWidget(nullptr)
{ {
...@@ -72,23 +71,14 @@ bool AbstractImporter::importCalendar() ...@@ -72,23 +71,14 @@ bool AbstractImporter::importCalendar()
void AbstractImporter::initializeFilter(MailImporter::Filter &filter) void AbstractImporter::initializeFilter(MailImporter::Filter &filter)
{ {
if (mImportWizard) { mAbstractDisplayInfo->initializeFilter(filter);
MailImporter::FilterInfo *info = new MailImporter::FilterInfo();
ImportFilterInfoGui *infoGui = new ImportFilterInfoGui(mImportWizard->importMailPage());
info->setFilterInfoGui(infoGui);
info->clear(); // Clear info from last time
MailImporter::FilterImporterAkonadi *filterImporter = new MailImporter::FilterImporterAkonadi(info);
filterImporter->setRootCollection(mImportWizard->importMailPage()->selectedCollection());
filter.setFilterImporter(filterImporter);
filter.setFilterInfo(info);
}
} }
bool AbstractImporter::addFilters(const QString &filterPath, MailCommon::FilterImporterExporter::FilterType type) bool AbstractImporter::addFilters(const QString &filterPath, MailCommon::FilterImporterExporter::FilterType type)
{ {
if (QFileInfo::exists(filterPath)) { if (QFileInfo::exists(filterPath)) {
bool canceled = false; bool canceled = false;
MailCommon::FilterImporterExporter importer(mImportWizard); MailCommon::FilterImporterExporter importer(mAbstractDisplayInfo->parentWidget());
QList<MailCommon::MailFilter *> listFilter = importer.importFilters(canceled, type, filterPath); QList<MailCommon::MailFilter *> listFilter = importer.importFilters(canceled, type, filterPath);
appendFilters(listFilter); appendFilters(listFilter);
if (canceled) { if (canceled) {
...@@ -112,37 +102,32 @@ void AbstractImporter::appendFilters(const QList<MailCommon::MailFilter *> &filt ...@@ -112,37 +102,32 @@ void AbstractImporter::appendFilters(const QList<MailCommon::MailFilter *> &filt
void AbstractImporter::addImportFilterInfo(const QString &log) const void AbstractImporter::addImportFilterInfo(const QString &log) const
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importFilterPage()->addImportInfo(log); mAbstractDisplayInfo->filterImportInfo(log);
} }
} }
void AbstractImporter::addImportFilterError(const QString &log) const void AbstractImporter::addImportFilterError(const QString &log) const
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importFilterPage()->addImportError(log); mAbstractDisplayInfo->filterImportError(log);
} }
} }
void AbstractImporter::addImportSettingsInfo(const QString &log) const void AbstractImporter::addImportSettingsInfo(const QString &log) const
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importSettingPage()->addImportError(log); mAbstractDisplayInfo->settingsImportInfo(log);
} }
} }
void AbstractImporter::addImportCalendarInfo(const QString &log) const void AbstractImporter::addImportCalendarInfo(const QString &log) const
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importCalendarPage()->addImportError(log); mAbstractDisplayInfo->calendarImportInfo(log);
} }
} }
void AbstractImporter::setImportWizard(ImportWizard *importWizard)
{
mImportWizard = importWizard;
}
void AbstractImporter::setParentWidget(QWidget *parent) void AbstractImporter::setParentWidget(QWidget *parent)
{ {
mParentWidget = parent; mParentWidget = parent;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "MailCommon/FilterImporterExporter" #include "MailCommon/FilterImporterExporter"
#include "libimportwizard_export.h" #include "libimportwizard_export.h"
class ImportWizard;
namespace MailImporter namespace MailImporter
{ {
class FilterInfo; class FilterInfo;
...@@ -75,8 +74,6 @@ public: ...@@ -75,8 +74,6 @@ public:
virtual bool importAddressBook(); virtual bool importAddressBook();
virtual bool importCalendar(); virtual bool importCalendar();
void setImportWizard(ImportWizard *importWizard);
void setParentWidget(QWidget *parent); void setParentWidget(QWidget *parent);
QWidget *parentWidget() const; QWidget *parentWidget() const;
...@@ -84,8 +81,7 @@ public: ...@@ -84,8 +81,7 @@ public:
protected: protected:
//TODO we need to redefine it. void initializeFilter(MailImporter::Filter &filter);
virtual void initializeFilter(MailImporter::Filter &filter);
void appendFilters(const QList<MailCommon::MailFilter *> &filters); void appendFilters(const QList<MailCommon::MailFilter *> &filters);
void addImportFilterInfo(const QString &log) const; void addImportFilterInfo(const QString &log) const;
...@@ -95,7 +91,6 @@ protected: ...@@ -95,7 +91,6 @@ protected:
void addImportCalendarInfo(const QString &log) const; void addImportCalendarInfo(const QString &log) const;
QString mPath; QString mPath;
ImportWizard *mImportWizard;
AbstractDisplayInfo *mAbstractDisplayInfo; AbstractDisplayInfo *mAbstractDisplayInfo;
QWidget *mParentWidget; QWidget *mParentWidget;
}; };
......
...@@ -17,9 +17,10 @@ ...@@ -17,9 +17,10 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#include "abstract/abstractsettings.h" #include "abstract/abstractsettings.h"
#include "importwizard.h" #include "abstract/abstractdisplayinfo.h"
#include "importsettingpage.h" #include "importsettingpage.h"
#include <KIdentityManagement/kidentitymanagement/identitymanager.h> #include <KIdentityManagement/kidentitymanagement/identitymanager.h>
#include <KIdentityManagement/kidentitymanagement/identity.h> #include <KIdentityManagement/kidentitymanagement/identity.h>
#include <mailtransport/transportmanager.h> #include <mailtransport/transportmanager.h>
...@@ -35,8 +36,7 @@ ...@@ -35,8 +36,7 @@
using namespace Akonadi; using namespace Akonadi;
AbstractSettings::AbstractSettings(ImportWizard *parent) AbstractSettings::AbstractSettings()
: mImportWizard(parent)
{ {
mManager = KIdentityManagement::IdentityManager::self(); mManager = KIdentityManagement::IdentityManager::self();
mKmailConfig = KSharedConfig::openConfig(QStringLiteral("kmail2rc")); mKmailConfig = KSharedConfig::openConfig(QStringLiteral("kmail2rc"));
...@@ -93,15 +93,15 @@ void AbstractSettings::storeTransport(MailTransport::Transport *mt, bool isDefau ...@@ -93,15 +93,15 @@ void AbstractSettings::storeTransport(MailTransport::Transport *mt, bool isDefau
void AbstractSettings::addImportInfo(const QString &log) void AbstractSettings::addImportInfo(const QString &log)
{ {
if (mImportWizard) { if (mAbstractDisplayInfo) {
mImportWizard->importSettingPage()->addImportInfo(log); mAbstractDisplayInfo->settingsImportInfo(log);
} }
} }
void AbstractSettings::addImportError(const QString &log)