File indexing completed on 2024-05-12 05:25:33
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "pimdatabackupthread.h" 0008 #include "pimdataexportcore_debug.h" 0009 0010 #include <KLocalizedString> 0011 #include <KZip> 0012 #include <QTemporaryFile> 0013 0014 PimDataBackupThread::PimDataBackupThread(KZip *zip, const QString &url, const QString &archivePath, const QString &archivename, QObject *parent) 0015 : QThread(parent) 0016 , mUrl(url) 0017 , mArchivePath(archivePath) 0018 , mArchiveName(archivename) 0019 , mZip(zip) 0020 { 0021 qCDebug(PIMDATAEXPORTERCORE_LOG) << " PimDataBackupThread::PimDataBackupThread" << this; 0022 } 0023 0024 PimDataBackupThread::~PimDataBackupThread() 0025 { 0026 qCDebug(PIMDATAEXPORTERCORE_LOG) << " PimDataBackupThread::~PimDataBackupThread()" << this; 0027 } 0028 0029 void PimDataBackupThread::run() 0030 { 0031 QTemporaryFile tmp; 0032 tmp.open(); 0033 auto archiveFile = new KZip(tmp.fileName()); 0034 archiveFile->setCompression(KZip::NoCompression); 0035 bool result = archiveFile->open(QIODevice::WriteOnly); 0036 if (!result) { 0037 Q_EMIT error(i18n("Impossible to open archive file.")); 0038 Q_EMIT terminated(false); 0039 delete archiveFile; 0040 return; 0041 } 0042 const bool vcarddirAdded = archiveFile->addLocalDirectory(mUrl, QString()); 0043 if (!vcarddirAdded) { 0044 Q_EMIT error(i18n("Impossible to backup \"%1\".", mUrl)); 0045 Q_EMIT terminated(false); 0046 delete archiveFile; 0047 return; 0048 } 0049 archiveFile->close(); 0050 tmp.close(); 0051 0052 const bool fileAdded = mZip->addLocalFile(tmp.fileName(), mArchivePath + mArchiveName); 0053 if (fileAdded) { 0054 Q_EMIT info(i18n("\"%1\" was backed up.", mUrl)); 0055 } else { 0056 Q_EMIT error(i18n("\"%1\" file cannot be added to backup file.", mUrl)); 0057 } 0058 delete archiveFile; 0059 Q_EMIT terminated(fileAdded); 0060 } 0061 0062 #include "moc_pimdatabackupthread.cpp"