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
df3ba5ad
Commit
df3ba5ad
authored
May 10, 2020
by
Laurent Montel
Browse files
Reduce duplicate code
parent
dfd6221b
Changes
5
Hide whitespace changes
Inline
Side-by-side
core/CMakeLists.txt
View file @
df3ba5ad
...
...
@@ -74,6 +74,7 @@ set(pimdataexporter_LIB_SRCS
pimdataimportdatainfofile.cpp
resourceconverterbase.cpp
resourceconverterimpl.cpp
storeresourcejob.cpp
)
ecm_qt_declare_logging_category
(
pimdataexporter_LIB_SRCS HEADER pimdataexportcore_debug.h IDENTIFIER PIMDATAEXPORTERCORE_LOG CATEGORY_NAME org.kde.pim.pimdataexportercore
...
...
core/abstractimportexportjob.cpp
View file @
df3ba5ad
...
...
@@ -21,6 +21,7 @@
#include
"archivestorage.h"
#include
"importexportprogressindicatorbase.h"
#include
"resourceconverterimpl.h"
#include
"storeresourcejob.h"
#include
"synchronizeresourcejob.h"
#include
<PimCommonAkonadi/CreateResource>
...
...
@@ -322,23 +323,15 @@ void AbstractImportExportJob::backupResourceFile(const QString &identifier, cons
QString
filename
=
fi
.
fileName
();
const
bool
fileAdded
=
archive
()
->
addLocalFile
(
url
,
archivePath
+
filename
);
if
(
fileAdded
)
{
const
QString
errorStr
=
Utils
::
storeResources
(
archive
(),
identifier
,
archivePath
);
if
(
!
errorStr
.
isEmpty
())
{
Q_EMIT
error
(
errorStr
);
}
Q_EMIT
info
(
i18n
(
"
\"
%1
\"
was backed up."
,
filename
));
url
=
Akonadi
::
ServerManager
::
agentConfigFilePath
(
identifier
);
if
(
!
url
.
isEmpty
())
{
fi
=
QFileInfo
(
url
);
filename
=
fi
.
fileName
();
const
bool
fileAdded
=
archive
()
->
addLocalFile
(
url
,
archivePath
+
filename
);
if
(
fileAdded
)
{
Q_EMIT
info
(
i18n
(
"
\"
%1
\"
was backed up."
,
filename
));
}
else
{
Q_EMIT
error
(
i18n
(
"
\"
%1
\"
file cannot be added to backup file."
,
filename
));
}
}
StoreResourceJob
*
job
=
new
StoreResourceJob
(
this
);
connect
(
job
,
&
StoreResourceJob
::
error
,
this
,
&
AbstractImportExportJob
::
error
);
connect
(
job
,
&
StoreResourceJob
::
info
,
this
,
&
AbstractImportExportJob
::
info
);
job
->
setArchivePath
(
archivePath
);
job
->
setZip
(
archive
());
job
->
setIdentifier
(
identifier
);
job
->
start
();
}
else
{
Q_EMIT
error
(
i18n
(
"
\"
%1
\"
file cannot be added to backup file."
,
filename
));
}
...
...
core/exportresourcearchivejob.cpp
View file @
df3ba5ad
...
...
@@ -19,6 +19,7 @@
#include
"exportresourcearchivejob.h"
#include
"utils.h"
#include
"storeresourcejob.h"
#include
"pimdataexportcore_debug.h"
#include
<pimdatabackupthread.h>
#include
<KLocalizedString>
...
...
@@ -79,21 +80,13 @@ void ExportResourceArchiveJob::start()
void
ExportResourceArchiveJob
::
slotTerminated
(
bool
success
)
{
if
(
success
)
{
const
QString
errorStr
=
Utils
::
storeResources
(
mZip
,
mIdentifier
,
mArchivePath
);
if
(
!
errorStr
.
isEmpty
())
{
Q_EMIT
error
(
errorStr
);
}
const
QString
url
=
Akonadi
::
ServerManager
::
agentConfigFilePath
(
mIdentifier
);
if
(
!
url
.
isEmpty
())
{
const
QFileInfo
fi
(
url
);
const
QString
filename
=
fi
.
fileName
();
const
bool
fileAdded
=
mZip
->
addLocalFile
(
url
,
mArchivePath
+
filename
);
if
(
fileAdded
)
{
Q_EMIT
info
(
i18n
(
"
\"
%1
\"
was backed up."
,
filename
));
}
else
{
Q_EMIT
error
(
i18n
(
"
\"
%1
\"
file cannot be added to backup file."
,
filename
));
}
}
StoreResourceJob
*
job
=
new
StoreResourceJob
(
this
);
connect
(
job
,
&
StoreResourceJob
::
error
,
this
,
&
ExportResourceArchiveJob
::
error
);
connect
(
job
,
&
StoreResourceJob
::
info
,
this
,
&
ExportResourceArchiveJob
::
info
);
job
->
setArchivePath
(
mArchivePath
);
job
->
setZip
(
mZip
);
job
->
setIdentifier
(
mIdentifier
);
job
->
start
();
}
finished
();
}
...
...
core/storeresourcejob.cpp
0 → 100644
View file @
df3ba5ad
/*
Copyright (C) 2020 Laurent Montel <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
"storeresourcejob.h"
#include
"utils.h"
#include
"pimdataexportcore_debug.h"
#include
<KLocalizedString>
#include
<KZip>
#include
<AkonadiCore/ServerManager>
#include
<QFileInfo>
StoreResourceJob
::
StoreResourceJob
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
StoreResourceJob
::~
StoreResourceJob
()
{
}
void
StoreResourceJob
::
setArchivePath
(
const
QString
&
archivePath
)
{
mArchivePath
=
archivePath
;
}
void
StoreResourceJob
::
setIdentifier
(
const
QString
&
identifier
)
{
mIdentifier
=
identifier
;
}
void
StoreResourceJob
::
setZip
(
KZip
*
zip
)
{
mZip
=
zip
;
}
void
StoreResourceJob
::
start
()
{
if
(
!
mZip
)
{
qCWarning
(
PIMDATAEXPORTERCORE_LOG
)
<<
" mZip null it's a bug"
;
deleteLater
();
return
;
}
const
QString
errorStr
=
Utils
::
storeResources
(
mZip
,
mIdentifier
,
mArchivePath
);
if
(
!
errorStr
.
isEmpty
())
{
Q_EMIT
error
(
errorStr
);
}
const
QString
url
=
Akonadi
::
ServerManager
::
agentConfigFilePath
(
mIdentifier
);
if
(
!
url
.
isEmpty
())
{
const
QFileInfo
fi
(
url
);
const
QString
filename
=
fi
.
fileName
();
const
bool
fileAdded
=
mZip
->
addLocalFile
(
url
,
mArchivePath
+
filename
);
if
(
fileAdded
)
{
Q_EMIT
info
(
i18n
(
"
\"
%1
\"
was backed up."
,
filename
));
}
else
{
Q_EMIT
error
(
i18n
(
"
\"
%1
\"
file cannot be added to backup file."
,
filename
));
}
}
deleteLater
();
}
core/storeresourcejob.h
0 → 100644
View file @
df3ba5ad
/*
Copyright (C) 2020 Laurent Montel <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 STORERESOURCEJOB_H
#define STORERESOURCEJOB_H
#include
<QObject>
class
KZip
;
class
StoreResourceJob
:
public
QObject
{
Q_OBJECT
public:
explicit
StoreResourceJob
(
QObject
*
parent
=
nullptr
);
~
StoreResourceJob
();
void
start
();
void
setArchivePath
(
const
QString
&
archivePath
);
void
setIdentifier
(
const
QString
&
identifier
);
void
setZip
(
KZip
*
zip
);
Q_SIGNALS:
void
error
(
const
QString
&
);
void
info
(
const
QString
&
);
private:
QString
mArchivePath
;
QString
mIdentifier
;
KZip
*
mZip
=
nullptr
;
};
#endif // STORERESOURCEJOB_H
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