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

Separate code from importwizard

parent 9b2ea142
......@@ -8,6 +8,7 @@ set(libimportwizard_SRCS
importwizard.cpp
importwizardkernel.cpp
importmailpluginmanager.cpp
importwizarddisplayinfo.cpp
)
set(libimportwizard_manual_SRCS
......
......@@ -31,10 +31,8 @@
#include <QPointer>
using namespace LibImportWizard;
AbstractAddressBook::AbstractAddressBook(ImportWizard *parent)
: mImportWizard(parent),
mAbstractDisplayInfo(nullptr),
mCollection(-1)
AbstractAddressBook::AbstractAddressBook()
: mCollection(-1)
{
}
......@@ -48,7 +46,7 @@ bool AbstractAddressBook::selectAddressBook()
addAddressBookImportInfo(i18n("Creating new contact..."));
if (!mCollection.isValid()) {
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->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
dlg->setWindowTitle(i18n("Select Address Book"));
......@@ -88,11 +86,6 @@ void AbstractAddressBook::addImportContactNote(KContacts::Addressee &address, co
address.setNote(currentNote);
}
void AbstractAddressBook::setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo)
{
mAbstractDisplayInfo = abstractDisplayInfo;
}
void AbstractAddressBook::createContact(const KContacts::Addressee &address)
{
if (selectAddressBook()) {
......
......@@ -24,7 +24,6 @@
#include "abstractbase.h"
#include "libimportwizard_export.h"
class ImportWizard;
namespace KContacts
{
......@@ -40,11 +39,9 @@ class LIBIMPORTWIZARD_EXPORT AbstractAddressBook: public LibImportWizard::Abstra
{
Q_OBJECT
public:
explicit AbstractAddressBook(ImportWizard *parent);
AbstractAddressBook();
~AbstractAddressBook();
void setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo);
protected:
void createGroup(const KContacts::ContactGroup &group);
void createContact(const KContacts::Addressee &address);
......@@ -57,10 +54,6 @@ protected:
void cleanUp();
void addImportContactNote(KContacts::Addressee &address, const QString &applicationName);
protected:
ImportWizard *mImportWizard;
AbstractDisplayInfo *mAbstractDisplayInfo;
private:
void slotStoreDone(KJob *job);
bool selectAddressBook();
......
......@@ -31,6 +31,7 @@
using namespace Akonadi;
using namespace LibImportWizard;
AbstractBase::AbstractBase()
: mAbstractDisplayInfo(nullptr)
{
mCreateResource = new PimCommon::CreateResource();
connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractBase::slotCreateResourceInfo);
......@@ -47,6 +48,11 @@ QString LibImportWizard::AbstractBase::createResource(const QString &resources,
return mCreateResource->createResource(resources, name, settings);
}
void AbstractBase::setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo)
{
mAbstractDisplayInfo = abstractDisplayInfo;
}
void AbstractBase::slotCreateResourceError(const QString &msg)
{
addImportError(msg);
......
......@@ -32,6 +32,7 @@ class CreateResource;
}
namespace LibImportWizard
{
class AbstractDisplayInfo;
class LIBIMPORTWIZARD_EXPORT AbstractBase : public QObject
{
Q_OBJECT
......@@ -41,10 +42,14 @@ public:
QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings);
void setAbstractDisplayInfo(AbstractDisplayInfo *abstractDisplayInfo);
protected:
virtual void addImportInfo(const QString &log) = 0;
virtual void addImportError(const QString &log) = 0;
AbstractDisplayInfo *mAbstractDisplayInfo;
private:
void slotCreateResourceError(const QString &);
void slotCreateResourceInfo(const QString &);
......
......@@ -18,14 +18,13 @@
*/
#include "abstractcalendar.h"
#include "importwizard.h"
#include "importcalendarpage.h"
#include "abstract/abstractdisplayinfo.h"
#include <KSharedConfig>
#include <KConfigGroup>
using namespace LibImportWizard;
AbstractCalendar::AbstractCalendar(ImportWizard *parent)
: mImportWizard(parent)
AbstractCalendar::AbstractCalendar()
{
}
......@@ -35,15 +34,15 @@ AbstractCalendar::~AbstractCalendar()
void AbstractCalendar::addImportInfo(const QString &log)
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportInfo(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->calendarImportInfo(log);
}
}
void AbstractCalendar::addImportError(const QString &log)
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportError(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->calendarImportError(log);
}
}
......
......@@ -20,7 +20,6 @@
#ifndef ABSTRACTCALENDAR_H
#define ABSTRACTCALENDAR_H
class ImportWizard;
#include "abstractbase.h"
#include "libimportwizard_export.h"
#include <QString>
......@@ -30,16 +29,13 @@ class LIBIMPORTWIZARD_EXPORT AbstractCalendar : public LibImportWizard::Abstract
{
Q_OBJECT
public:
explicit AbstractCalendar(ImportWizard *parent);
AbstractCalendar();
virtual ~AbstractCalendar();
protected:
void addEvenViewConfig(const QString &groupName, const QString &key, const QString &value);
void addImportInfo(const QString &log) Q_DECL_OVERRIDE;
void addImportError(const QString &log) Q_DECL_OVERRIDE;
private:
ImportWizard *mImportWizard;
};
}
#endif // ABSTRACTCALENDAR_H
......@@ -29,30 +29,50 @@ AbstractDisplayInfo::AbstractDisplayInfo()
void AbstractDisplayInfo::calendarImportError(const QString &log)
{
Q_UNUSED(log);
}
void AbstractDisplayInfo::settingsImportError(const QString &log)
{
Q_UNUSED(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)
{
Q_UNUSED(log);
}
void AbstractDisplayInfo::settingsImportInfo(const QString &log)
{
Q_UNUSED(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 @@
#include "libimportwizard_export.h"
#include <QString>
class QWidget;
namespace MailImporter
{
class Filter;
}
namespace LibImportWizard
{
......@@ -34,10 +40,15 @@ public:
virtual void calendarImportError(const QString &log);
virtual void settingsImportError(const QString &log);
virtual void addressbookImportError(const QString &log);
virtual void filterImportError(const QString &log);
virtual void calendarImportInfo(const QString &log);
virtual void settingsImportInfo(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 @@
*/
#include "abstractimporter.h"
#include "importwizard.h"
#include "importmailpage.h"
#include "importfilterinfogui.h"
#include "importfilterpage.h"
#include "importsettingpage.h"
#include "importcalendarpage.h"
#include "abstract/abstractdisplayinfo.h"
#include "mailimporter/filterinfo.h"
#include "MailCommon/FilterManager"
......@@ -35,7 +35,6 @@ using namespace LibImportWizard;
AbstractImporter::AbstractImporter(QObject *parent)
: QObject(parent),
mImportWizard(nullptr),
mAbstractDisplayInfo(nullptr),
mParentWidget(nullptr)
{
......@@ -72,23 +71,14 @@ bool AbstractImporter::importCalendar()
void AbstractImporter::initializeFilter(MailImporter::Filter &filter)
{
if (mImportWizard) {
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);
}
mAbstractDisplayInfo->initializeFilter(filter);
}
bool AbstractImporter::addFilters(const QString &filterPath, MailCommon::FilterImporterExporter::FilterType type)
{
if (QFileInfo::exists(filterPath)) {
bool canceled = false;
MailCommon::FilterImporterExporter importer(mImportWizard);
MailCommon::FilterImporterExporter importer(mAbstractDisplayInfo->parentWidget());
QList<MailCommon::MailFilter *> listFilter = importer.importFilters(canceled, type, filterPath);
appendFilters(listFilter);
if (canceled) {
......@@ -112,37 +102,32 @@ void AbstractImporter::appendFilters(const QList<MailCommon::MailFilter *> &filt
void AbstractImporter::addImportFilterInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importFilterPage()->addImportInfo(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->filterImportInfo(log);
}
}
void AbstractImporter::addImportFilterError(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importFilterPage()->addImportError(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->filterImportError(log);
}
}
void AbstractImporter::addImportSettingsInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importSettingPage()->addImportError(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->settingsImportInfo(log);
}
}
void AbstractImporter::addImportCalendarInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportError(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->calendarImportInfo(log);
}
}
void AbstractImporter::setImportWizard(ImportWizard *importWizard)
{
mImportWizard = importWizard;
}
void AbstractImporter::setParentWidget(QWidget *parent)
{
mParentWidget = parent;
......
......@@ -22,7 +22,6 @@
#include "MailCommon/FilterImporterExporter"
#include "libimportwizard_export.h"
class ImportWizard;
namespace MailImporter
{
class FilterInfo;
......@@ -75,8 +74,6 @@ public:
virtual bool importAddressBook();
virtual bool importCalendar();
void setImportWizard(ImportWizard *importWizard);
void setParentWidget(QWidget *parent);
QWidget *parentWidget() const;
......@@ -84,8 +81,7 @@ public:
protected:
//TODO we need to redefine it.
virtual void initializeFilter(MailImporter::Filter &filter);
void initializeFilter(MailImporter::Filter &filter);
void appendFilters(const QList<MailCommon::MailFilter *> &filters);
void addImportFilterInfo(const QString &log) const;
......@@ -95,7 +91,6 @@ protected:
void addImportCalendarInfo(const QString &log) const;
QString mPath;
ImportWizard *mImportWizard;
AbstractDisplayInfo *mAbstractDisplayInfo;
QWidget *mParentWidget;
};
......
......@@ -17,9 +17,10 @@
Boston, MA 02110-1301, USA.
*/
#include "abstract/abstractsettings.h"
#include "importwizard.h"
#include "abstract/abstractdisplayinfo.h"
#include "importsettingpage.h"
#include <KIdentityManagement/kidentitymanagement/identitymanager.h>
#include <KIdentityManagement/kidentitymanagement/identity.h>
#include <mailtransport/transportmanager.h>
......@@ -35,8 +36,7 @@
using namespace Akonadi;
AbstractSettings::AbstractSettings(ImportWizard *parent)
: mImportWizard(parent)
AbstractSettings::AbstractSettings()
{
mManager = KIdentityManagement::IdentityManager::self();
mKmailConfig = KSharedConfig::openConfig(QStringLiteral("kmail2rc"));
......@@ -93,15 +93,15 @@ void AbstractSettings::storeTransport(MailTransport::Transport *mt, bool isDefau
void AbstractSettings::addImportInfo(const QString &log)
{
if (mImportWizard) {
mImportWizard->importSettingPage()->addImportInfo(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->settingsImportInfo(log);
}
}
void AbstractSettings::addImportError(const QString &log)
{
if (mImportWizard) {
mImportWizard->importSettingPage()->addImportError(log);
if (mAbstractDisplayInfo) {
mAbstractDisplayInfo->settingsImportError(log);
}
}
......
......@@ -25,7 +25,6 @@
#include <KSharedConfig>
#include <QMap>
class ImportWizard;
namespace KIdentityManagement
{
......@@ -42,7 +41,7 @@ class LIBIMPORTWIZARD_EXPORT AbstractSettings : public LibImportWizard::Abstract
{
Q_OBJECT
public:
explicit AbstractSettings(ImportWizard *parent);
AbstractSettings();
~AbstractSettings();
protected:
......@@ -73,7 +72,6 @@ protected:
void addToManualCheck(const QString &agentIdentifyName, bool manualCheck);
int readKmailSettings(const QString &groupName, const QString &key);
ImportWizard *mImportWizard;
KIdentityManagement::IdentityManager *mManager;
KSharedConfigPtr mKmailConfig;
};
......
......@@ -27,6 +27,8 @@
#include "importcalendarpage.h"
#include "importfinishpage.h"
#include "importmailpluginmanager.h"
#include "importwizarddisplayinfo.h"
#include "helper_p.h"
#include "manual/manualimportmailpage.h"
......@@ -54,6 +56,7 @@ ImportWizard::ImportWizard(WizardMode mode, QWidget *parent)
setModal(true);
setWindowTitle(i18n("PIM Import Tool"));
setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Help);
mAbstractDisplayInfo = new ImportWizardDisplayInfo(this);
ImportWizardKernel *kernel = new ImportWizardKernel(this);
CommonKernel->registerKernelIf(kernel); //register KernelIf early, it is used by the Filter classes
......@@ -207,8 +210,8 @@ void ImportWizard::initializeImportModule()
const QVector<LibImportWizard::AbstractImporter *> lstPlugins = ImportMailPluginManager::self()->pluginsList();
for (LibImportWizard::AbstractImporter *abstractPlugin : qAsConst(lstPlugins)) {
if (abstractPlugin->foundMailer()) {
abstractPlugin->setImportWizard(this);
abstractPlugin->setParentWidget(this);
abstractPlugin->setAbstractDisplayInfo(mAbstractDisplayInfo);
mlistImport.insert(abstractPlugin->name(), abstractPlugin);
}
}
......
......@@ -25,6 +25,7 @@
#include <KAssistantDialog>
namespace LibImportWizard {
class AbstractImporter;
class AbstractDisplayInfo;
}
class KPageWidgetItem;
class SelectProgramPage;
......@@ -120,6 +121,8 @@ private:
ManualImportMailPage *mImportpage;
KPageWidgetItem *mSelfilterpageItem;
KPageWidgetItem *mImportpageItem;
LibImportWizard::AbstractDisplayInfo *mAbstractDisplayInfo;
};
#endif /* IMPORTWIZARD_H */
......
/*
Copyright (C) 2017 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "importwizarddisplayinfo.h"
#include "importwizard.h"
#include "importcalendarpage.h"
#include "importsettingpage.h"
#include "importaddressbookpage.h"
#include "importfilterpage.h"
#include "importmailpage.h"
#include <MailImporter/FilterInfo>
#include <MailImporterAkonadi/FilterImporterAkonadi>
#include <importfilterinfogui.h>
ImportWizardDisplayInfo::ImportWizardDisplayInfo(ImportWizard *wizard)
: mImportWizard(wizard)
{
}
ImportWizardDisplayInfo::~ImportWizardDisplayInfo()
{
}
void ImportWizardDisplayInfo::calendarImportError(const QString &log)
{
mImportWizard->importCalendarPage()->addImportError(log);
}
void ImportWizardDisplayInfo::settingsImportError(const QString &log)
{
mImportWizard->importSettingPage()->addImportError(log);
}
void ImportWizardDisplayInfo::addressbookImportError(const QString &log)
{
mImportWizard->importAddressBookPage()->addImportError(log);
}
void ImportWizardDisplayInfo::calendarImportInfo(const QString &log)
{
mImportWizard->importCalendarPage()->addImportInfo(log);
}
void ImportWizardDisplayInfo::settingsImportInfo(const QString &log)
{
mImportWizard->importSettingPage()->addImportInfo(log);
}
void ImportWizardDisplayInfo::addressbookImportInfo(const QString &log)
{
mImportWizard->importAddressBookPage()->addImportInfo(log);
}
QWidget *ImportWizardDisplayInfo::parentWidget() const
{
return mImportWizard;
}
void ImportWizardDisplayInfo::filterImportError(const QString &log)
{
mImportWizard->importFilterPage()->addImportError(log);
}
void ImportWizardDisplayInfo::filterImportInfo(const QString &log)
{
mImportWizard->importFilterPage()->addImportInfo(log);
}
void ImportWizardDisplayInfo::initializeFilter(MailImporter::Filter &filter)
{
if (mImportWizard) {
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);
}
}
/*
Copyright (C) 2017 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef IMPORTWIZARDDISPLAYINFO_H
#define IMPORTWIZARDDISPLAYINFO_H
#include "abstract/abstractdisplayinfo.h"
#include <QObject>