summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-10-23 21:02:10 +0200
committerMontel Laurent <[email protected]>2015-10-23 22:12:48 +0200
commit880b412e5415ee4796c8f75599ce2e7fd140d7af (patch)
tree18756b2c292f4dcb1ca9bdde3bbfc65551fded2c
parent51e72573c44f6855b051e06e93e54c2d466dfe1b (diff)
implement thread
-rw-r--r--pimsettingexporter/core/pimsettingbackupthread.cpp43
-rw-r--r--pimsettingexporter/core/pimsettingbackupthread.h15
2 files changed, 52 insertions, 6 deletions
diff --git a/pimsettingexporter/core/pimsettingbackupthread.cpp b/pimsettingexporter/core/pimsettingbackupthread.cpp
index f65c127..87a67aa 100644
--- a/pimsettingexporter/core/pimsettingbackupthread.cpp
+++ b/pimsettingexporter/core/pimsettingbackupthread.cpp
@@ -18,8 +18,17 @@
#include "pimsettingbackupthread.h"
-PimSettingBackupThread::PimSettingBackupThread(QObject *parent)
- : QThread(parent)
+#include <KZip>
+#include <QTemporaryFile>
+#include <KLocalizedString>
+#include <QDebug>
+
+PimSettingBackupThread::PimSettingBackupThread(KZip *zip, const QString &url, const QString &archivePath, const QString &archivename, QObject *parent)
+ : QThread(parent),
+ mUrl(url),
+ mArchivePath(archivePath),
+ mArchiveName(archivename),
+ mZip(zip)
{
}
@@ -31,5 +40,33 @@ PimSettingBackupThread::~PimSettingBackupThread()
void PimSettingBackupThread::run()
{
- //TODO
+ QTemporaryFile tmp;
+ tmp.open();
+ KZip *archiveFile = new KZip(tmp.fileName());
+ archiveFile->setCompression(KZip::NoCompression);
+ bool result = archiveFile->open(QIODevice::WriteOnly);
+ if (!result) {
+ Q_EMIT error(i18n("Impossible to open archive file."));
+ Q_EMIT terminated(false);
+ delete archiveFile;
+ return;
+ }
+ const bool vcarddirAdded = archiveFile->addLocalDirectory(mUrl, QString());
+ if (!vcarddirAdded) {
+ Q_EMIT error(i18n("Impossible to backup \"%1\".", mUrl));
+ Q_EMIT terminated(false);
+ delete archiveFile;
+ return;
+ }
+ archiveFile->close();
+ tmp.close();
+
+ const bool fileAdded = mZip->addLocalFile(tmp.fileName(), mArchivePath + mArchiveName);
+ if (fileAdded) {
+ Q_EMIT info(i18n("\"%1\" was backed up.", mUrl));
+ } else {
+ Q_EMIT error(i18n("\"%1\" file cannot be added to backup file.", mUrl));
+ }
+ delete archiveFile;
+ Q_EMIT terminated(fileAdded);
}
diff --git a/pimsettingexporter/core/pimsettingbackupthread.h b/pimsettingexporter/core/pimsettingbackupthread.h
index 2137853..b4d5f4c 100644
--- a/pimsettingexporter/core/pimsettingbackupthread.h
+++ b/pimsettingexporter/core/pimsettingbackupthread.h
@@ -19,17 +19,26 @@
#define PIMSETTINGBACKUPTHREAD_H
#include <QThread>
-
+class KZip;
class PimSettingBackupThread : public QThread
{
Q_OBJECT
public:
- explicit PimSettingBackupThread(QObject *parent = Q_NULLPTR);
+ explicit PimSettingBackupThread(KZip *zip, const QString &url, const QString &archivePath, const QString &archivename, QObject *parent = Q_NULLPTR);
~PimSettingBackupThread();
- // QThread interface
+Q_SIGNALS:
+ void error(const QString &str);
+ void info(const QString &str);
+ void terminated(bool success);
+
protected:
void run() Q_DECL_OVERRIDE;
+private:
+ QString mUrl;
+ QString mArchivePath;
+ QString mArchiveName;
+ KZip *mZip;
};
#endif // PIMSETTINGBACKUPTHREAD_H