1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
/*
Copyright (C) 2015-2018 Montel Laurent <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 "pimsettingexporterconsole.h"
#include "pimsettingsbackuprestore.h"
#include "pimsettingexportconsole_debug.h"
#include "loginfile.h"
#include "loginfo.h"
#include "xml/templateselection.h"
#include <QTimer>
#include <pimsettingexporterkernel.h>
#include <MailCommon/MailKernel>
#include <MailCommon/FilterManager>
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<Utils::AppsType, Utils::importExportParameters> 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)
{
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;
}
|