Commit 035594a7 authored by Laurent Montel's avatar Laurent Montel 😁

Move in own directory

parent 8c1262e1
......@@ -16,6 +16,15 @@ set(libimportwizard_manual_SRCS
manual/manualselectfilterpage.cpp
)
set(libimportwizard_abstract_SRCS
abstract/abstractimporter.cpp
abstract/abstractsettings.cpp
abstract/abstractaddressbook.cpp
abstract/abstractcalendar.cpp
abstract/abstractbase.cpp
)
set(libimportwizard_autodetect_SRCS
autodetect/widgets/selectprogramlistwidget.cpp
autodetect/importwizardutil.cpp
......@@ -28,11 +37,6 @@ set(libimportwizard_autodetect_SRCS
autodetect/selectcomponentpage.cpp
autodetect/importfilterinfogui.cpp
autodetect/importcalendarpage.cpp
autodetect/abstractimporter.cpp
autodetect/abstractsettings.cpp
autodetect/abstractaddressbook.cpp
autodetect/abstractcalendar.cpp
autodetect/abstractbase.cpp
)
......@@ -55,7 +59,7 @@ file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/*-apps-kontact-import-wi
ecm_add_app_icon(importwizard_SRCS ICONS ${ICONS_SRCS})
add_library(libimportwizard ${libimportwizard_autodetect_SRCS} ${libimportwizard_manual_SRCS} ${libimportwizard_SRCS})
add_library(libimportwizard ${libimportwizard_autodetect_SRCS} ${libimportwizard_manual_SRCS} ${libimportwizard_SRCS} ${libimportwizard_abstract_SRCS})
generate_export_header(libimportwizard BASE_NAME libimportwizard)
......
/*
Copyright (C) 2012-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 "abstract/abstractaddressbook.h"
#include "importwizard.h"
#include "importaddressbookpage.h"
#include <KContacts/Addressee>
#include <kcontacts/contactgroup.h>
#include <KLocalizedString>
#include "importwizard_debug.h"
#include <AkonadiCore/ItemCreateJob>
#include <AkonadiCore/Item>
#include <AkonadiWidgets/CollectionDialog>
#include <QPointer>
using namespace LibImportWizard;
AbstractAddressBook::AbstractAddressBook(ImportWizard *parent)
: mImportWizard(parent), mCollection(-1)
{
}
AbstractAddressBook::~AbstractAddressBook()
{
}
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);
dlg->setMimeTypeFilter(mimeTypes);
dlg->setAccessRightsFilter(Akonadi::Collection::CanCreateItem);
dlg->setWindowTitle(i18n("Select Address Book"));
dlg->setDescription(i18n("Select the address book the new contact shall be saved in:"));
if (dlg->exec() == QDialog::Accepted && dlg) {
mCollection = dlg->selectedCollection();
} else {
addAddressBookImportError(i18n("Address Book was not selected."));
delete dlg;
return false;
}
delete dlg;
}
return true;
}
void AbstractAddressBook::createGroup(const KContacts::ContactGroup &group)
{
if (selectAddressBook()) {
Akonadi::Item item;
item.setPayload<KContacts::ContactGroup>(group);
item.setMimeType(KContacts::ContactGroup::mimeType());
Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob(item, mCollection);
connect(job, &Akonadi::ItemCreateJob::result, this, &AbstractAddressBook::slotStoreDone);
}
}
void AbstractAddressBook::addImportContactNote(KContacts::Addressee &address, const QString &applicationName)
{
QString currentNote = address.note();
if (!currentNote.isEmpty()) {
currentNote += QLatin1Char('\n');
}
currentNote += i18n("Imported from \"%1\"", applicationName);
address.setNote(currentNote);
}
void AbstractAddressBook::createContact(const KContacts::Addressee &address)
{
if (selectAddressBook()) {
Akonadi::Item item;
item.setPayload<KContacts::Addressee>(address);
item.setMimeType(KContacts::Addressee::mimeType());
Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob(item, mCollection);
connect(job, &Akonadi::ItemCreateJob::result, this, &AbstractAddressBook::slotStoreDone);
}
}
void AbstractAddressBook::slotStoreDone(KJob *job)
{
if (job->error()) {
qCDebug(IMPORTWIZARD_LOG) << " job->errorString() : " << job->errorString();
addAddressBookImportError(i18n("Error during contact creation: %1", job->errorString()));
return;
}
addAddressBookImportInfo(i18n("Contact creation complete"));
}
void AbstractAddressBook::addImportInfo(const QString &log)
{
addAddressBookImportInfo(log);
}
void AbstractAddressBook::addImportError(const QString &log)
{
addAddressBookImportError(log);
}
void AbstractAddressBook::addAddressBookImportInfo(const QString &log)
{
if (mImportWizard) {
mImportWizard->importAddressBookPage()->addImportInfo(log);
}
}
void AbstractAddressBook::addAddressBookImportError(const QString &log)
{
if (mImportWizard) {
mImportWizard->importAddressBookPage()->addImportError(log);
}
}
void AbstractAddressBook::cleanUp()
{
mCollection = Akonadi::Collection();
}
/*
Copyright (C) 2012-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 ABSTRACTADDRESSBOOK_H
#define ABSTRACTADDRESSBOOK_H
#include <AkonadiCore/Collection>
#include "abstractbase.h"
#include "libimportwizard_export.h"
class ImportWizard;
namespace KContacts
{
class Addressee;
class ContactGroup;
}
class KJob;
namespace LibImportWizard
{
class LIBIMPORTWIZARD_EXPORT AbstractAddressBook: public LibImportWizard::AbstractBase
{
Q_OBJECT
public:
explicit AbstractAddressBook(ImportWizard *parent);
~AbstractAddressBook();
protected:
void createGroup(const KContacts::ContactGroup &group);
void createContact(const KContacts::Addressee &address);
void addImportInfo(const QString &log) Q_DECL_OVERRIDE;
void addImportError(const QString &log) Q_DECL_OVERRIDE;
void addAddressBookImportInfo(const QString &log);
void addAddressBookImportError(const QString &log);
void cleanUp();
void addImportContactNote(KContacts::Addressee &address, const QString &applicationName);
protected:
ImportWizard *mImportWizard;
private:
void slotStoreDone(KJob *job);
bool selectAddressBook();
Akonadi::Collection mCollection;
};
}
#endif // ABSTRACTADDRESSBOOK_H
/*
Copyright (C) 2012-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 "abstractbase.h"
#include "PimCommonAkonadi/CreateResource"
#include <KSharedConfig>
#include <AkonadiCore/agenttype.h>
#include <AkonadiCore/agentmanager.h>
#include <AkonadiCore/agentinstancecreatejob.h>
#include <QMetaMethod>
using namespace Akonadi;
using namespace LibImportWizard;
AbstractBase::AbstractBase()
{
mCreateResource = new PimCommon::CreateResource();
connect(mCreateResource, &PimCommon::CreateResource::createResourceInfo, this, &AbstractBase::slotCreateResourceInfo);
connect(mCreateResource, &PimCommon::CreateResource::createResourceError, this, &AbstractBase::slotCreateResourceError);
}
AbstractBase::~AbstractBase()
{
delete mCreateResource;
}
QString LibImportWizard::AbstractBase::createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings)
{
return mCreateResource->createResource(resources, name, settings);
}
void AbstractBase::slotCreateResourceError(const QString &msg)
{
addImportError(msg);
}
void AbstractBase::slotCreateResourceInfo(const QString &msg)
{
addImportInfo(msg);
}
/*
Copyright (C) 2012-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 ABSTRACTBASE_H
#define ABSTRACTBASE_H
#include <QObject>
#include "libimportwizard_export.h"
#include <QString>
#include <QMap>
#include <QVariant>
namespace PimCommon
{
class CreateResource;
}
namespace LibImportWizard
{
class LIBIMPORTWIZARD_EXPORT AbstractBase : public QObject
{
Q_OBJECT
public:
explicit AbstractBase();
virtual ~AbstractBase();
QString createResource(const QString &resources, const QString &name, const QMap<QString, QVariant> &settings);
protected:
virtual void addImportInfo(const QString &log) = 0;
virtual void addImportError(const QString &log) = 0;
private:
void slotCreateResourceError(const QString &);
void slotCreateResourceInfo(const QString &);
PimCommon::CreateResource *mCreateResource;
};
}
#endif // ABSTRACTBASE_H
/*
Copyright (C) 2012-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 "abstractcalendar.h"
#include "importwizard.h"
#include "importcalendarpage.h"
#include <KConfigGroup>
using namespace LibImportWizard;
AbstractCalendar::AbstractCalendar(ImportWizard *parent)
: mImportWizard(parent)
{
}
AbstractCalendar::~AbstractCalendar()
{
}
void AbstractCalendar::addImportInfo(const QString &log)
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportInfo(log);
}
}
void AbstractCalendar::addImportError(const QString &log)
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportError(log);
}
}
//eventviewsrc for calendar color for example
void AbstractCalendar::addEvenViewConfig(const QString &groupName, const QString &key, const QString &value)
{
KSharedConfigPtr eventViewConfig = KSharedConfig::openConfig(QStringLiteral("eventviewsrc"));
KConfigGroup group = eventViewConfig->group(groupName);
group.writeEntry(key, value);
group.sync();
}
/*
Copyright (C) 2012-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 ABSTRACTCALENDAR_H
#define ABSTRACTCALENDAR_H
class ImportWizard;
#include "abstractbase.h"
#include "libimportwizard_export.h"
#include <QString>
namespace LibImportWizard
{
class LIBIMPORTWIZARD_EXPORT AbstractCalendar : public LibImportWizard::AbstractBase
{
Q_OBJECT
public:
explicit AbstractCalendar(ImportWizard *parent);
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
/*
Copyright (C) 2012-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 "abstractimporter.h"
#include "importwizard.h"
#include "importmailpage.h"
#include "importfilterinfogui.h"
#include "importfilterpage.h"
#include "importsettingpage.h"
#include "importcalendarpage.h"
#include "mailimporter/filterinfo.h"
#include "MailCommon/FilterManager"
#include <MailImporterAkonadi/FilterImporterAkonadi>
#include <QFile>
using namespace LibImportWizard;
AbstractImporter::AbstractImporter(QObject *parent)
: QObject(parent),
mImportWizard(nullptr)
{
}
AbstractImporter::~AbstractImporter()
{
}
bool AbstractImporter::importSettings()
{
return false;
}
bool AbstractImporter::importMails()
{
return false;
}
bool AbstractImporter::importFilters()
{
return false;
}
bool AbstractImporter::importAddressBook()
{
return false;
}
bool AbstractImporter::importCalendar()
{
return false;
}
void AbstractImporter::initializeFilter(MailImporter::Filter &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)
{
if (QFileInfo::exists(filterPath)) {
bool canceled = false;
MailCommon::FilterImporterExporter importer(mImportWizard);
QList<MailCommon::MailFilter *> listFilter = importer.importFilters(canceled, type, filterPath);
appendFilters(listFilter);
if (canceled) {
addImportFilterInfo(i18n("Importing of filters was canceled."));
} else {
addImportFilterInfo(i18np("1 filter was imported from \"%2\"", "%1 filters were imported from \"%2\"", listFilter.count(), filterPath));
}
return true;
} else {
addImportFilterError(i18n("Filters file was not found"));
return true;
}
}
void AbstractImporter::appendFilters(const QList<MailCommon::MailFilter *> &filters)
{
if (!filters.isEmpty()) {
MailCommon::FilterManager::instance()->appendFilters(filters, false);
}
}
void AbstractImporter::addImportFilterInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importFilterPage()->addImportInfo(log);
}
}
void AbstractImporter::addImportFilterError(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importFilterPage()->addImportError(log);
}
}
void AbstractImporter::addImportSettingsInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importSettingPage()->addImportError(log);
}
}
void AbstractImporter::addImportCalendarInfo(const QString &log) const
{
if (mImportWizard) {
mImportWizard->importCalendarPage()->addImportError(log);
}
}
void AbstractImporter::setImportWizard(ImportWizard *importWizard)
{
mImportWizard = importWizard;
}
/*
Copyright (C) 2012-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 AbstractImporter_H
#define AbstractImporter_H
#include "MailCommon/FilterImporterExporter"
#include "libimportwizard_export.h"
class ImportWizard;
namespace MailImporter
{
class FilterInfo;
class Filter;
}
namespace MailCommon