Commit 93bc60d3 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Return list of agent

parent aca4ab7c
......@@ -122,6 +122,7 @@ protected:
PimCommon::CreateResource *mCreateResource = nullptr;
QStringList mAgentPaths;
QVector<Utils::StoredType> mListStep;
QVector<Utils::AkonadiInstanceInfo> mAkonadiInstanceInfo;
int mIndex = -1;
static int sArchiveVersion;
......
......@@ -39,6 +39,7 @@ protected:
virtual void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) = 0;
void slotCheckBackupConfig();
virtual void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) = 0;
virtual Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() = 0;
private:
void slotCheckBackupResource();
......
......@@ -41,8 +41,14 @@ ExportAddressbookJobInterfaceImpl::~ExportAddressbookJobInterfaceImpl()
{
}
QVector<Utils::AkonadiInstanceInfo> ExportAddressbookJobInterfaceImpl::listOfResource()
{
return Utils::listOfResource();
}
void ExportAddressbookJobInterfaceImpl::exportArchiveResource()
{
mAkonadiInstanceInfo = listOfResource();
QTimer::singleShot(0, this, &ExportAddressbookJobInterfaceImpl::slotWriteNextArchiveResource);
}
......@@ -58,11 +64,9 @@ void ExportAddressbookJobInterfaceImpl::slotAddressbookJobTerminated()
void ExportAddressbookJobInterfaceImpl::slotWriteNextArchiveResource()
{
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
if (mIndexIdentifier < list.count()) {
const Akonadi::AgentInstance agent = list.at(mIndexIdentifier);
const QString identifier = agent.identifier();
if (mIndexIdentifier < mAkonadiInstanceInfo.count()) {
const Utils::AkonadiInstanceInfo agent = mAkonadiInstanceInfo.at(mIndexIdentifier);
const QString identifier = agent.identifier;
if (identifier.contains(QLatin1String("akonadi_vcarddir_resource_")) || identifier.contains(QLatin1String("akonadi_contacts_resource_"))) {
const QString archivePath = Utils::addressbookPath() + identifier + QLatin1Char('/');
......
......@@ -37,6 +37,7 @@ protected:
void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) override;
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override;
Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource();
private:
void slotWriteNextArchiveResource();
void slotAddressbookJobTerminated();
......
......@@ -51,6 +51,12 @@ void ExportAddressbookJobInterfaceTestImpl::exportResourceToArchive(const QStrin
//TODO implement it
}
QVector<Utils::AkonadiInstanceInfo> ExportAddressbookJobInterfaceTestImpl::listOfResource()
{
//TODO
return {};
}
void ExportAddressbookJobInterfaceTestImpl::convertCollectionToRealPath(KConfigGroup &group, const QString &currentKey)
{
ResourceConverterTest resourceConverter;
......@@ -86,3 +92,5 @@ void ExportAddressbookJobInterfaceTest::exportAddressBookConfig()
file->start();
delete exportNote;
}
......@@ -39,6 +39,7 @@ protected:
void convertCollectionListToRealPath(KConfigGroup &group, const QString &currentKey) override;
Q_REQUIRED_RESULT Akonadi::Collection::Id convertFolderPathToCollectionId(const QString &path) override;
void exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier) override;
Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource() override;
};
class ExportAddressbookJobInterfaceTest : public QObject
......
......@@ -30,6 +30,7 @@
#include <KLocalizedString>
#include <KZip>
#include <AkonadiCore/AgentManager>
#include <QDir>
#include <QStandardPaths>
......@@ -251,3 +252,18 @@ QString Utils::storedTypeToI18n(StoredType type)
qCDebug(PIMDATAEXPORTERCORE_LOG) << " type unknown " << type;
return QString();
}
QVector<Utils::AkonadiInstanceInfo> Utils::listOfResource()
{
QVector<Utils::AkonadiInstanceInfo> instanceInfoList;
Akonadi::AgentManager *manager = Akonadi::AgentManager::self();
const Akonadi::AgentInstance::List list = manager->instances();
for (const Akonadi::AgentInstance &agent : list) {
Utils::AkonadiInstanceInfo info;
info.identifier = agent.identifier();
info.mimeTypes = agent.type().mimeTypes();
instanceInfoList.append(info);
}
return instanceInfoList;
}
......@@ -24,9 +24,7 @@
#include <KSharedConfig>
#include "pimdataexportcore_debug.h"
class KZip;
namespace Akonadi {
class AgentInstance;
}
struct ResourceFiles {
QString akonadiConfigFile;
......@@ -39,6 +37,10 @@ struct ResourceFiles {
};
namespace Utils {
struct AkonadiInstanceInfo {
QString identifier;
QStringList mimeTypes;
};
enum StoredType {
None = 0,
Identity = 1,
......@@ -92,6 +94,7 @@ PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString notePath();
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString prefixAkonadiConfigFile();
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString exportDataTypeFileName();
Q_REQUIRED_RESULT QString akonadiAgentName(const QString &configPath);
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QVector<Utils::AkonadiInstanceInfo> listOfResource();
Q_REQUIRED_RESULT QString storeResources(KZip *archive, const QString &identifier, const QString &path);
KZip *openZip(const QString &filename, QString &errorMsg);
......@@ -104,4 +107,5 @@ Q_REQUIRED_RESULT int currentArchiveVersion();
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString appTypeToI18n(AppsType type);
PIMDATAEXPORTER_EXPORT Q_REQUIRED_RESULT QString storedTypeToI18n(StoredType type);
}
Q_DECLARE_TYPEINFO(Utils::AkonadiInstanceInfo, Q_MOVABLE_TYPE);
#endif // UTILS_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