Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Data Exporter
Commits
d642383e
Commit
d642383e
authored
May 10, 2020
by
Laurent Montel
Browse files
Allow to reuse code
parent
df3ba5ad
Changes
7
Hide whitespace changes
Inline
Side-by-side
core/autotests/notes/exportnotesjobinterfacetest.cpp
View file @
d642383e
...
...
@@ -59,6 +59,7 @@ void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &arc
qDebug
()
<<
" void ExportNotesJobInterfaceTestImpl::exportResourceToArchive(const QString &archivePath, const QString &url, const QString &identifier)"
<<
archivePath
<<
" url "
<<
url
<<
" identifier "
<<
identifier
;
QVERIFY
(
identifier
.
startsWith
(
QLatin1String
(
"akonadi_akonotes_resource_"
)));
QVERIFY
(
mArchiveStorage
->
archive
()
->
addLocalFile
(
url
+
identifier
+
QLatin1String
(
".zip"
),
archivePath
+
Utils
::
resourceNoteArchiveName
()));
//TODO export config file too.
slotNoteJobTerminated
();
}
...
...
core/mail/exportmailjobinterfaceimpl.cpp
View file @
d642383e
...
...
@@ -116,7 +116,8 @@ void ExportMailJobInterfaceImpl::exportResourceToArchive(const QString &archiveP
QString
ExportMailJobInterfaceImpl
::
storeResources
(
KZip
*
archive
,
const
QString
&
identifier
,
const
QString
&
path
)
{
return
Utils
::
storeResources
(
archive
,
identifier
,
path
);
ResourceConverterImpl
converter
;
return
converter
.
storeResources
(
archive
,
identifier
,
path
);
}
QString
ExportMailJobInterfaceImpl
::
resourcePath
(
const
QString
&
identifier
)
const
...
...
core/resourceconverterbase.cpp
View file @
d642383e
...
...
@@ -19,9 +19,14 @@
#include
"resourceconverterbase.h"
#include
"utils.h"
#include
<PimCommon/PimUtil>
#include
<KConfigGroup>
#include
<KLocalizedString>
#include
<KZip>
#include
<QDir>
#include
<QFileInfo>
#include
<QFileInfo>
#include
<QTemporaryFile>
ResourceConverterBase
::
ResourceConverterBase
()
{
...
...
@@ -171,3 +176,47 @@ QString ResourceConverterBase::agentFileName(const QString &filename)
agentFileConfigName
=
Utils
::
resourcesPath
()
+
Utils
::
prefixAkonadiConfigFile
()
+
agentFileConfigName
;
return
agentFileConfigName
;
}
QString
ResourceConverterBase
::
storeResources
(
KZip
*
archive
,
const
QString
&
identifier
,
const
QString
&
path
)
{
const
QString
agentFileName
=
identifier
+
QStringLiteral
(
"rc"
);
const
QString
configFileName
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
ConfigLocation
)
+
QLatin1Char
(
'/'
)
+
agentFileName
;
qCDebug
(
PIMDATAEXPORTERCORE_LOG
)
<<
"configFileName "
<<
configFileName
<<
"agentFileName "
<<
configFileName
;
KSharedConfigPtr
resourceConfig
=
KSharedConfig
::
openConfig
(
configFileName
);
QTemporaryFile
tmp
;
tmp
.
open
();
KConfig
*
config
=
resourceConfig
->
copyTo
(
tmp
.
fileName
());
if
(
identifier
.
contains
(
POP3_RESOURCE_IDENTIFIER
))
{
const
QString
targetCollection
=
QStringLiteral
(
"targetCollection"
);
KConfigGroup
group
=
config
->
group
(
"General"
);
if
(
group
.
hasKey
(
targetCollection
))
{
group
.
writeEntry
(
targetCollection
,
convertToFullCollectionPath
(
group
.
readEntry
(
targetCollection
).
toLongLong
()));
}
}
else
if
(
PimCommon
::
Util
::
isImapResource
(
identifier
))
{
const
QString
trash
=
QStringLiteral
(
"TrashCollection"
);
KConfigGroup
group
=
config
->
group
(
"cache"
);
if
(
group
.
hasKey
(
trash
))
{
group
.
writeEntry
(
trash
,
convertToFullCollectionPath
(
group
.
readEntry
(
trash
).
toLongLong
()));
}
}
//Customize resource if necessary here.
config
->
sync
();
bool
fileAdded
=
archive
->
addLocalFile
(
tmp
.
fileName
(),
path
+
agentFileName
);
delete
config
;
if
(
!
fileAdded
)
{
return
i18n
(
"Resource file
\"
%1
\"
cannot be added to backup file."
,
agentFileName
);
}
const
QString
agentConfigFileName
=
Utils
::
prefixAkonadiConfigFile
()
+
identifier
;
const
QString
agentConfigFileNamePath
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
ConfigLocation
)
+
QLatin1String
(
"/akonadi/"
)
+
agentConfigFileName
;
if
(
QFileInfo
::
exists
(
agentConfigFileNamePath
))
{
fileAdded
=
archive
->
addLocalFile
(
agentConfigFileNamePath
,
path
+
agentConfigFileName
);
if
(
!
fileAdded
)
{
return
i18n
(
"Resource file
\"
%1
\"
cannot be added to backup file."
,
agentFileName
);
}
}
return
QString
();
}
core/resourceconverterbase.h
View file @
d642383e
...
...
@@ -24,6 +24,7 @@
#include
<QString>
#include
<KSharedConfig>
#include
<AkonadiCore/Collection>
class
KZip
;
class
PIMDATAEXPORTER_EXPORT
ResourceConverterBase
{
public:
...
...
@@ -40,6 +41,7 @@ public:
virtual
Q_REQUIRED_RESULT
QString
convertToFullCollectionPath
(
const
qlonglong
collectionValue
)
=
0
;
virtual
Q_REQUIRED_RESULT
Akonadi
::
Collection
::
Id
convertFolderPathToCollectionId
(
const
QString
&
path
)
=
0
;
Q_REQUIRED_RESULT
QString
storeResources
(
KZip
*
archive
,
const
QString
&
identifier
,
const
QString
&
path
);
};
#endif // RESOURCECONVERTER_H
core/storeresourcejob.cpp
View file @
d642383e
...
...
@@ -20,6 +20,7 @@
#include
"storeresourcejob.h"
#include
"utils.h"
#include
"pimdataexportcore_debug.h"
#include
"resourceconverterimpl.h"
#include
<KLocalizedString>
#include
<KZip>
#include
<AkonadiCore/ServerManager>
...
...
@@ -59,7 +60,9 @@ void StoreResourceJob::start()
deleteLater
();
return
;
}
const
QString
errorStr
=
Utils
::
storeResources
(
mZip
,
mIdentifier
,
mArchivePath
);
ResourceConverterImpl
converter
;
const
QString
errorStr
=
converter
.
storeResources
(
mZip
,
mIdentifier
,
mArchivePath
);
if
(
!
errorStr
.
isEmpty
())
{
Q_EMIT
error
(
errorStr
);
}
...
...
core/utils.cpp
View file @
d642383e
...
...
@@ -110,50 +110,6 @@ QString Utils::infoPath()
return
QStringLiteral
(
"information/"
);
}
QString
Utils
::
storeResources
(
KZip
*
archive
,
const
QString
&
identifier
,
const
QString
&
path
)
{
const
QString
agentFileName
=
identifier
+
QStringLiteral
(
"rc"
);
const
QString
configFileName
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
ConfigLocation
)
+
QLatin1Char
(
'/'
)
+
agentFileName
;
qCDebug
(
PIMDATAEXPORTERCORE_LOG
)
<<
"configFileName "
<<
configFileName
<<
"agentFileName "
<<
configFileName
;
KSharedConfigPtr
resourceConfig
=
KSharedConfig
::
openConfig
(
configFileName
);
QTemporaryFile
tmp
;
tmp
.
open
();
KConfig
*
config
=
resourceConfig
->
copyTo
(
tmp
.
fileName
());
if
(
identifier
.
contains
(
POP3_RESOURCE_IDENTIFIER
))
{
const
QString
targetCollection
=
QStringLiteral
(
"targetCollection"
);
KConfigGroup
group
=
config
->
group
(
"General"
);
if
(
group
.
hasKey
(
targetCollection
))
{
group
.
writeEntry
(
targetCollection
,
MailCommon
::
Util
::
fullCollectionPath
(
Akonadi
::
Collection
(
group
.
readEntry
(
targetCollection
).
toLongLong
())));
}
}
else
if
(
PimCommon
::
Util
::
isImapResource
(
identifier
))
{
const
QString
trash
=
QStringLiteral
(
"TrashCollection"
);
KConfigGroup
group
=
config
->
group
(
"cache"
);
if
(
group
.
hasKey
(
trash
))
{
group
.
writeEntry
(
trash
,
MailCommon
::
Util
::
fullCollectionPath
(
Akonadi
::
Collection
(
group
.
readEntry
(
trash
).
toLongLong
())));
}
}
//Customize resource if necessary here.
config
->
sync
();
bool
fileAdded
=
archive
->
addLocalFile
(
tmp
.
fileName
(),
path
+
agentFileName
);
delete
config
;
if
(
!
fileAdded
)
{
return
i18n
(
"Resource file
\"
%1
\"
cannot be added to backup file."
,
agentFileName
);
}
const
QString
agentConfigFileName
=
Utils
::
prefixAkonadiConfigFile
()
+
identifier
;
const
QString
agentConfigFileNamePath
=
QStandardPaths
::
writableLocation
(
QStandardPaths
::
ConfigLocation
)
+
QLatin1String
(
"/akonadi/"
)
+
agentConfigFileName
;
if
(
QFileInfo
::
exists
(
agentConfigFileNamePath
))
{
fileAdded
=
archive
->
addLocalFile
(
agentConfigFileNamePath
,
path
+
agentConfigFileName
);
if
(
!
fileAdded
)
{
return
i18n
(
"Resource file
\"
%1
\"
cannot be added to backup file."
,
agentFileName
);
}
}
return
QString
();
}
QString
Utils
::
akonadiAgentName
(
const
QString
&
configPath
)
{
QSettings
settings
(
configPath
,
QSettings
::
IniFormat
);
...
...
core/utils.h
View file @
d642383e
...
...
@@ -103,7 +103,6 @@ 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
);
PIMDATAEXPORTER_EXPORT
void
storeDataExportInfo
(
KZip
*
archive
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment