diff --git a/console/pimsettingexporterconsole.cpp b/console/pimsettingexporterconsole.cpp index 6791fac..fa334b7 100644 --- a/console/pimsettingexporterconsole.cpp +++ b/console/pimsettingexporterconsole.cpp @@ -1,202 +1,202 @@ /* Copyright (C) 2015-2019 Montel Laurent 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 "pimsettingexporterconsole.h" #include "pimsettingsbackuprestore.h" #include "pimsettingexportconsole_debug.h" #include "loginfile.h" #include "loginfo.h" #include "xml/templateselection.h" #include #include #include #include PimSettingExporterConsole::PimSettingExporterConsole(QObject *parent) : QObject(parent) , mPimSettingsBackupRestore(new PimSettingsBackupRestore(this)) , mLogInFile(nullptr) , mLogInfo(new LogInfo(this)) , mMode(Import) , mInProgress(false) { //Initialize filtermanager (void)MailCommon::FilterManager::instance(); PimSettingExporterKernel *kernel = new PimSettingExporterKernel(this); CommonKernel->registerKernelIf(kernel); //register KernelIf early, it is used by the Filter classes CommonKernel->registerSettingsIf(kernel); //SettingsIf is used in FolderTreeWidget initializeLogInFile(); //TODO initialize akonadi server } PimSettingExporterConsole::~PimSettingExporterConsole() { } void PimSettingExporterConsole::initializeLogInFile() { connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::addEndLine, this, &PimSettingExporterConsole::slotAddEndLine); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::addError, this, &PimSettingExporterConsole::slotAddError); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::addInfo, this, &PimSettingExporterConsole::slotAddInfo); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::addTitle, this, &PimSettingExporterConsole::slotAddTitle); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::jobFinished, this, &PimSettingExporterConsole::slotJobFinished); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::backupDone, this, &PimSettingExporterConsole::slotBackupDone); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::jobFailed, this, &PimSettingExporterConsole::slotJobFailed); connect(mPimSettingsBackupRestore, &PimSettingsBackupRestore::restoreDone, this, &PimSettingExporterConsole::slotRestoreDone); } void PimSettingExporterConsole::closeLogFile() { delete mLogInFile; mLogInFile = nullptr; } void PimSettingExporterConsole::slotRestoreDone() { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Restore Done"; closeLogFile(); QTimer::singleShot(0, this, &PimSettingExporterConsole::finished); } void PimSettingExporterConsole::slotJobFailed() { qCWarning(PIMSETTINGEXPORTERCONSOLE_LOG) << "job failed"; closeLogFile(); mPimSettingsBackupRestore->closeArchive(); } void PimSettingExporterConsole::slotBackupDone() { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Backup Done"; closeLogFile(); QTimer::singleShot(0, this, &PimSettingExporterConsole::finished); } void PimSettingExporterConsole::slotJobFinished() { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "job finished"; mPimSettingsBackupRestore->nextStep(); } void PimSettingExporterConsole::slotAddEndLine() { if (mLogInFile) { mLogInFile->addEndLine(); } mLogInfo->addEndLineLogEntry(); } void PimSettingExporterConsole::slotAddError(const QString &message) { if (mLogInFile) { mLogInFile->addError(message); } mLogInfo->addErrorLogEntry(message); } void PimSettingExporterConsole::slotAddInfo(const QString &message) { if (mLogInFile) { mLogInFile->addInfo(message); } mLogInfo->addInfoLogEntry(message); } void PimSettingExporterConsole::slotAddTitle(const QString &message) { if (mLogInFile) { mLogInFile->addTitle(message); } mLogInfo->addTitleLogEntry(message); } QString PimSettingExporterConsole::importExportFileName() const { return mImportExportFileName; } void PimSettingExporterConsole::setImportExportFileName(const QString &filename) { if (mInProgress) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Already in progress. We can't change it."; return; } mImportExportFileName = filename; } void PimSettingExporterConsole::start() { //Load template if necessary if (!mTemplateFileName.isEmpty()) { TemplateSelection selection; const QHash templateElements = selection.loadTemplate(mTemplateFileName); mPimSettingsBackupRestore->setStoredParameters(templateElements); } switch (mMode) { case Import: if (!mPimSettingsBackupRestore->restoreStart(mImportExportFileName)) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Unable to start restore."; QTimer::singleShot(0, this, &PimSettingExporterConsole::finished); } break; case Export: if (!mPimSettingsBackupRestore->backupStart(mImportExportFileName)) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Unable to start backup."; QTimer::singleShot(0, this, &PimSettingExporterConsole::finished); } break; } } PimSettingExporterConsole::Mode PimSettingExporterConsole::mode() const { return mMode; } -void PimSettingExporterConsole::setMode(const Mode &mode) +void PimSettingExporterConsole::setMode(Mode mode) { if (mInProgress) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Already in progress. We can't change it."; return; } mMode = mode; } void PimSettingExporterConsole::setLogFileName(const QString &logFileName) { if (mInProgress) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Already in progress. We can't change it."; return; } if (!mLogInFile) { mLogInFile = new LogInFile(this); } mLogInFile->setFileName(logFileName); } void PimSettingExporterConsole::setTemplateFileName(const QString &templateFileName) { if (mInProgress) { qCDebug(PIMSETTINGEXPORTERCONSOLE_LOG) << "Already in progress. We can't change it."; return; } mTemplateFileName = templateFileName; } diff --git a/console/pimsettingexporterconsole.h b/console/pimsettingexporterconsole.h index e746227..68dc8f1 100644 --- a/console/pimsettingexporterconsole.h +++ b/console/pimsettingexporterconsole.h @@ -1,75 +1,75 @@ /* Copyright (C) 2015-2019 Montel Laurent 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 PIMSETTINGEXPORTERCONSOLE_H #define PIMSETTINGEXPORTERCONSOLE_H #include class PimSettingsBackupRestore; class LogInFile; class LogInfo; class PimSettingExporterConsole : public QObject { Q_OBJECT public: enum Mode { Import = 0, Export = 1 }; explicit PimSettingExporterConsole(QObject *parent = nullptr); ~PimSettingExporterConsole(); Mode mode() const; - void setMode(const Mode &mode); + void setMode(Mode mode); void setLogFileName(const QString &logFileName); void setTemplateFileName(const QString &templateFileName); void start(); QString importExportFileName() const; void setImportExportFileName(const QString &importFileName); Q_SIGNALS: void finished(); private: void slotAddEndLine(); void slotAddError(const QString &message); void slotAddInfo(const QString &message); void slotAddTitle(const QString &message); void slotJobFailed(); void slotBackupDone(); void slotJobFinished(); void slotRestoreDone(); void initializeLogInFile(); void closeLogFile(); QString mTemplateFileName; QString mImportExportFileName; PimSettingsBackupRestore *mPimSettingsBackupRestore = nullptr; LogInFile *mLogInFile = nullptr; LogInfo *mLogInfo = nullptr; Mode mMode; bool mInProgress = false; }; #endif // PIMSETTINGEXPORTERCONSOLE_H