diff --git a/core/exportresourcearchivejob.h b/core/exportresourcearchivejob.h index 8327308..7ce0336 100644 --- a/core/exportresourcearchivejob.h +++ b/core/exportresourcearchivejob.h @@ -1,63 +1,62 @@ /* Copyright (C) 2015-2017 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 EXPORTRESOURCEARCHIVEJOB_H #define EXPORTRESOURCEARCHIVEJOB_H #include class KZip; class PimSettingBackupThread; class ExportResourceArchiveJob : public QObject { Q_OBJECT public: explicit ExportResourceArchiveJob(QObject *parent = nullptr); ~ExportResourceArchiveJob(); void setArchivePath(const QString &archivePath); void setUrl(const QString &url); void setIdentifier(const QString &identifier); void setArchive(KZip *zip); void start(); void setArchiveName(const QString &archiveName); Q_SIGNALS: void error(const QString &str); void info(const QString &str); void terminated(); - public Q_SLOTS: void slotTaskCanceled(); private: void slotTerminated(bool success); void finished(); QString mArchiveName; QString mUrl; QString mArchivePath; QString mIdentifier; KZip *mZip = nullptr; PimSettingBackupThread *mThread = nullptr; }; #endif // EXPORTRESOURCEARCHIVEJOB_H diff --git a/gui/dialog/synchronizeresourcedialog.h b/gui/dialog/synchronizeresourcedialog.h index 1e98cc9..07ce7cb 100644 --- a/gui/dialog/synchronizeresourcedialog.h +++ b/gui/dialog/synchronizeresourcedialog.h @@ -1,51 +1,50 @@ /* Copyright (C) 2015-2017 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 SYNCHRONIZERESOURCEDIALOG_H #define SYNCHRONIZERESOURCEDIALOG_H #include class QListWidget; class SynchronizeResourceDialog : public QDialog { Q_OBJECT public: explicit SynchronizeResourceDialog(QWidget *parent = nullptr); ~SynchronizeResourceDialog(); void setResources(const QHash &resources); QStringList resources() const; private: void slotAccepted(); void slotSelectAll(); void slotUnselectAll(); - enum DataType { ResourceIdentifier = Qt::UserRole + 1 }; void readConfig(); void writeConfig(); void selectItem(bool state); QListWidget *mListResourceWidget = nullptr; }; #endif // SYNCHRONIZERESOURCEDIALOG_H diff --git a/gui/pimsettingexporterwindow.cpp b/gui/pimsettingexporterwindow.cpp index 2c9f6f8..ee5708b 100644 --- a/gui/pimsettingexporterwindow.cpp +++ b/gui/pimsettingexporterwindow.cpp @@ -1,430 +1,430 @@ /* Copyright (C) 2012-2017 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 "pimsettingexporterwindow.h" #include "dialog/showarchivestructuredialog.h" #include "importexportprogressindicatorgui.h" #include "widgets/logwidget.h" #include "pimsettingexportgui_debug.h" #include "job/fullsynchronizeresourcesjob.h" #include "trayicon/pimsettingstrayicon.h" #include "pimsettingimportdatainfofile.h" #include "pimsettingexporterkernel.h" #include "dialog/selectiontypedialog.h" #include "utils.h" #include "pimsettingsbackuprestoreui.h" #include "dialog/synchronizeresourcedialog.h" #include "dialog/backupfilestructureinfodialog.h" #include #include #include "PimCommon/PimUtil" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include PimSettingExporterWindow::PimSettingExporterWindow(QWidget *parent) : KXmlGuiWindow(parent) { //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 setupActions(true); setupGUI(Keys | StatusBar | Save | Create, QStringLiteral("pimsettingexporter.rc")); mLogWidget = new LogWidget(this); setCentralWidget(mLogWidget); resize(800, 600); Akonadi::ControlGui::widgetNeedsAkonadi(this); statusBar()->hide(); mTrayIcon = new PimSettingsTrayIcon(this); } PimSettingExporterWindow::~PimSettingExporterWindow() { MailCommon::FilterManager::instance()->cleanup(); KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup groupConfig = config->group(QStringLiteral("Recent File")); mRecentFilesAction->saveEntries(groupConfig); } void PimSettingExporterWindow::initializeBackupRestoreUi() { mPimSettingsBackupRestoreUI = new PimSettingsBackupRestoreUI(this, this); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::addInfo, this, &PimSettingExporterWindow::slotAddInfo); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::addEndLine, this, &PimSettingExporterWindow::slotAddEndLine); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::addError, this, &PimSettingExporterWindow::slotAddError); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::addTitle, this, &PimSettingExporterWindow::slotAddTitle); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::updateActions, this, &PimSettingExporterWindow::slotUpdateActions); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::jobFinished, this, &PimSettingExporterWindow::slotJobFinished); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::backupDone, this, &PimSettingExporterWindow::slotShowBackupFinishDialogInformation); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::jobFailed, this, &PimSettingExporterWindow::slotJobFailed); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestoreUI::needSyncResource, this, &PimSettingExporterWindow::slotAddResourceToSync); connect(mPimSettingsBackupRestoreUI, &PimSettingsBackupRestore::restoreDone, this, &PimSettingExporterWindow::slotRestoreDone); } void PimSettingExporterWindow::slotAddResourceToSync(const QString &name, const QString &identifier) { mNeedToSyncResources.insert(name, identifier); } void PimSettingExporterWindow::slotJobFinished() { mPimSettingsBackupRestoreUI->nextStep(); } void PimSettingExporterWindow::slotJobFailed() { mPimSettingsBackupRestoreUI->closeArchive(); } void PimSettingExporterWindow::slotRestoreDone() { if (!mNeedToSyncResources.isEmpty()) { QPointer dlg = new SynchronizeResourceDialog(this); dlg->setResources(mNeedToSyncResources); QStringList list; if (dlg->exec()) { list = dlg->resources(); } delete dlg; if (!list.isEmpty()) { slotAddInfo(i18n("Full sync starts...")); FullSynchronizeResourcesJob *job = new FullSynchronizeResourcesJob(this); job->setWindowParent(this); job->setResources(list); connect(job, &FullSynchronizeResourcesJob::synchronizeFinished, this, &PimSettingExporterWindow::slotFullSyncFinished); connect(job, &FullSynchronizeResourcesJob::synchronizeInstanceDone, this, &PimSettingExporterWindow::slotFullSyncInstanceDone); connect(job, &FullSynchronizeResourcesJob::synchronizeInstanceFailed, this, &PimSettingExporterWindow::slotFullSyncInstanceFailed); job->start(); } } else { slotUpdateActions(false); } } void PimSettingExporterWindow::slotShowBackupFinishDialogInformation() { showFinishInformation(); } void PimSettingExporterWindow::slotFullSyncFinished() { slotUpdateActions(false); const QString str = i18n("Full sync finished."); slotAddInfo(str); mTrayIcon->setStatus(KStatusNotifierItem::Passive); mTrayIcon->setToolTipSubTitle(str); } void PimSettingExporterWindow::slotFullSyncInstanceDone(const QString &identifier) { slotAddInfo(i18n("Full sync for \"%1\" done.", identifier)); } void PimSettingExporterWindow::slotFullSyncInstanceFailed(const QString &identifier) { slotAddError(i18n("Full sync for \"%1\" failed.", identifier)); } void PimSettingExporterWindow::showFinishInformation() { KMessageBox::information( this, i18n("For restoring data, you must use \"pimsettingexporter\". " "Be careful as it can overwrite your existing settings and data."), i18n("Backup"), QStringLiteral("setProgressDialogLabelBackupInfos")); mTrayIcon->setStatus(KStatusNotifierItem::Passive); } void PimSettingExporterWindow::handleCommandLine(const QCommandLineParser &parser) { QString templateFile; if (parser.isSet(QStringLiteral("template"))) { templateFile = parser.value(QStringLiteral("template")); } if (parser.isSet(QStringLiteral("import"))) { if (!parser.positionalArguments().isEmpty()) { loadData(parser.positionalArguments().at(0), templateFile); } } else if (parser.isSet(QStringLiteral("export"))) { if (!parser.positionalArguments().isEmpty()) { backupData(parser.positionalArguments().at(0), templateFile); } } } void PimSettingExporterWindow::setupActions(bool canZipFile) { KActionCollection *ac = actionCollection(); mBackupAction = ac->addAction(QStringLiteral("backup"), this, &PimSettingExporterWindow::slotBackupData); mBackupAction->setText(i18n("Export Data...")); mBackupAction->setEnabled(canZipFile); mRestoreAction = ac->addAction(QStringLiteral("restore"), this, &PimSettingExporterWindow::slotRestoreData); mRestoreAction->setText(i18n("Import Data...")); mRestoreAction->setEnabled(canZipFile); mSaveLogAction = ac->addAction(QStringLiteral("save_log"), this, &PimSettingExporterWindow::slotSaveLog); mSaveLogAction->setText(i18n("Save log...")); mArchiveStructureInfo = ac->addAction(QStringLiteral("show_structure_info"), this, &PimSettingExporterWindow::slotShowStructureInfos); mArchiveStructureInfo->setText(i18n("Show Archive Structure Information...")); mShowArchiveInformationsAction = ac->addAction(QStringLiteral("show_archive_info"), this, &PimSettingExporterWindow::slotShowArchiveInformations); mShowArchiveInformationsAction->setText(i18n("Show Archive Information...")); mShowArchiveInformationsAboutCurrentArchiveAction = ac->addAction(QStringLiteral("show_current_archive_info"), this, &PimSettingExporterWindow::slotShowCurrentArchiveInformations); mShowArchiveInformationsAboutCurrentArchiveAction->setText(i18n("Show Information on current Archive...")); mShowArchiveInformationsAboutCurrentArchiveAction->setEnabled(false); KStandardAction::quit(this, &PimSettingExporterWindow::close, ac); mRecentFilesAction = KStandardAction::openRecent(this, &PimSettingExporterWindow::slotRestoreFile, ac); KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup groupConfig = config->group(QStringLiteral("Recent File")); mRecentFilesAction->loadEntries(groupConfig); KStandardAction::preferences(this, &PimSettingExporterWindow::slotConfigure, ac); } void PimSettingExporterWindow::slotConfigure() { QPointer dlg = new PimSettingExporterConfigureDialog(this); dlg->exec(); delete dlg; } void PimSettingExporterWindow::slotUpdateActions(bool inAction) { mBackupAction->setEnabled(!inAction); mRestoreAction->setEnabled(!inAction); mSaveLogAction->setEnabled(!inAction); mArchiveStructureInfo->setEnabled(!inAction); mShowArchiveInformationsAction->setEnabled(!inAction); mShowArchiveInformationsAboutCurrentArchiveAction->setEnabled(!inAction && !mLastArchiveFileName.isEmpty()); } void PimSettingExporterWindow::slotRestoreFile(const QUrl &url) { if (!url.isEmpty()) { loadData(url.path()); } } void PimSettingExporterWindow::slotShowArchiveInformations() { const QString filename = QFileDialog::getOpenFileName(this, i18n("Select Archive"), QString(), QStringLiteral("%1 (*.zip)").arg(i18n("Zip file"))); if (filename.isEmpty()) { return; } QPointer dlg = new ShowArchiveStructureDialog(filename, this); dlg->exec(); delete dlg; } void PimSettingExporterWindow::slotSaveLog() { if (mLogWidget->isEmpty()) { KMessageBox::information(this, i18n("Log is empty."), i18n("Save log")); return; } const QString log = mLogWidget->toHtml(); const QString filter(i18n("HTML Files (*.html)")); PimCommon::Util::saveTextAs(log, filter, this); } void PimSettingExporterWindow::slotBackupData() { if (KMessageBox::warningContinueCancel( - this, - i18n("Please quit all kdepim applications before backing up your data."), - i18n("Backup")) == KMessageBox::Cancel) { + this, + i18n("Please quit all kdepim applications before backing up your data."), + i18n("Backup")) == KMessageBox::Cancel) { return; } backupData(); } void PimSettingExporterWindow::backupData(const QString &filename, const QString &templateFile) { QString currentFileName = filename; QPointer dialog = new SelectionTypeDialog(this); dialog->loadTemplate(templateFile); if (dialog->exec()) { mLogWidget->clear(); initializeBackupRestoreUi(); mPimSettingsBackupRestoreUI->setStoredParameters(dialog->storedType()); mPimSettingsBackupRestoreUI->setExportedInfoFileName(dialog->exportedFileInfo()); delete dialog; if (currentFileName.isEmpty()) { QString recentDirClass; currentFileName = QFileDialog::getSaveFileName(this, i18n("Create backup"), KFileWidget::getStartUrl(QUrl(QStringLiteral("kfiledialog:///pimsettingexporter")), recentDirClass).toLocalFile(), i18n("Zip file (*.zip)")); if (currentFileName.isEmpty()) { return; } if (!recentDirClass.isEmpty()) { KRecentDirs::add(recentDirClass, currentFileName); } mRecentFilesAction->addUrl(QUrl::fromLocalFile(currentFileName)); } mTrayIcon->setStatus(KStatusNotifierItem::Active); mTrayIcon->setToolTipSubTitle(i18n("Backup in progress...")); if (!mPimSettingsBackupRestoreUI->backupStart(currentFileName)) { qCDebug(PIMSETTINGEXPORTERGUI_LOG) << " backup Start failed"; } mLastArchiveFileName = currentFileName; } else { delete dialog; } } void PimSettingExporterWindow::slotAddInfo(const QString &info) { mLogWidget->addInfoLogEntry(info); qApp->processEvents(); } void PimSettingExporterWindow::slotAddError(const QString &info) { mLogWidget->addErrorLogEntry(info); qApp->processEvents(); } void PimSettingExporterWindow::slotAddTitle(const QString &info) { mLogWidget->addTitleLogEntry(info); qApp->processEvents(); } void PimSettingExporterWindow::slotAddEndLine() { mLogWidget->addEndLineLogEntry(); qApp->processEvents(); } void PimSettingExporterWindow::slotRestoreData() { loadData(); } void PimSettingExporterWindow::loadData(const QString &filename, const QString &templateFile) { if (KMessageBox::warningYesNo( - this, - i18n("Before restoring data you must close all kdepim applications. " - "Do you want to continue?"), - i18n("Backup")) == KMessageBox::No) { + this, + i18n("Before restoring data you must close all kdepim applications. " + "Do you want to continue?"), + i18n("Backup")) == KMessageBox::No) { return; } //First select filename. QString currentFileName = filename; if (currentFileName.isEmpty()) { QString recentDirClass; - currentFileName = - QFileDialog::getOpenFileName( - this, - i18n("Restore backup"), - KFileWidget::getStartUrl(QUrl(QStringLiteral("kfiledialog:///pimsettingexporter")), - recentDirClass).toLocalFile(), - QStringLiteral("%1 (*.zip)").arg(i18n("Zip File"))); + currentFileName + = QFileDialog::getOpenFileName( + this, + i18n("Restore backup"), + KFileWidget::getStartUrl(QUrl(QStringLiteral("kfiledialog:///pimsettingexporter")), + recentDirClass).toLocalFile(), + QStringLiteral("%1 (*.zip)").arg(i18n("Zip File"))); if (currentFileName.isEmpty()) { return; } if (!recentDirClass.isEmpty()) { KRecentDirs::add(recentDirClass, currentFileName); } } // Don't put it in 'if' otherwise temporary file will be removed after that. QString templateFileName; PimSettingImportDataInfoFile dataInfo; bool cleanupItems = false; if (templateFile.isEmpty()) { dataInfo.setCurrentFileName(currentFileName); templateFileName = dataInfo.importDataInfoPath(); cleanupItems = true; } else { templateFileName = templateFile; } QPointer dialog = new SelectionTypeDialog(this); dialog->loadTemplate(templateFileName); if (cleanupItems) { dialog->removeNotSelectedItems(); } if (dialog->exec()) { mLogWidget->clear(); mNeedToSyncResources.clear(); initializeBackupRestoreUi(); mPimSettingsBackupRestoreUI->setStoredParameters(dialog->storedType()); delete dialog; mTrayIcon->setStatus(KStatusNotifierItem::Active); mTrayIcon->setToolTipSubTitle(i18n("Restore in progress...")); if (!mPimSettingsBackupRestoreUI->restoreStart(currentFileName)) { qCDebug(PIMSETTINGEXPORTERGUI_LOG) << " PimSettingExporterWindow restore failed"; } } else { delete dialog; } } void PimSettingExporterWindow::slotShowStructureInfos() { QPointer dlg = new BackupFileStructureInfoDialog(this); dlg->exec(); delete dlg; } void PimSettingExporterWindow::slotShowCurrentArchiveInformations() { if (!mLastArchiveFileName.isEmpty()) { QPointer dlg = new ShowArchiveStructureDialog(mLastArchiveFileName, this); dlg->exec(); delete dlg; } } diff --git a/gui/pimsettingexporterwindow.h b/gui/pimsettingexporterwindow.h index 6b9badb..ffbbaac 100644 --- a/gui/pimsettingexporterwindow.h +++ b/gui/pimsettingexporterwindow.h @@ -1,81 +1,81 @@ /* Copyright (C) 2012-2017 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 PIMSETTINGEXPORTERWINDOW_H #define PIMSETTINGEXPORTERWINDOW_H #include #include "utils.h" class LogWidget; class KRecentFilesAction; class QAction; class QCommandLineParser; class PimSettingsBackupRestoreUI; class PimSettingsTrayIcon; class PimSettingExporterWindow : public KXmlGuiWindow { Q_OBJECT public: explicit PimSettingExporterWindow(QWidget *parent = nullptr); ~PimSettingExporterWindow(); void handleCommandLine(const QCommandLineParser &parser); private Q_SLOTS: void slotBackupData(); void slotRestoreData(); void slotAddInfo(const QString &info); void slotAddError(const QString &info); void slotAddTitle(const QString &info); void slotAddEndLine(); void slotSaveLog(); void slotShowStructureInfos(); void slotRestoreFile(const QUrl &url); void slotShowArchiveInformations(); void slotUpdateActions(bool inAction); void slotShowBackupFinishDialogInformation(); void slotJobFailed(); void slotJobFinished(); void slotShowCurrentArchiveInformations(); void slotAddResourceToSync(const QString &name, const QString &identifier); void slotFullSyncFinished(); void slotFullSyncInstanceDone(const QString &identifier); void slotFullSyncInstanceFailed(const QString &identifier); void slotRestoreDone(); void slotConfigure(); private: void initializeBackupRestoreUi(); void backupData(const QString &filename = QString(), const QString &templateFile = QString()); void loadData(const QString &filename = QString(), const QString &templateFile = QString()); void setupActions(bool canZipFile); void showFinishInformation(); QString mLastArchiveFileName; // Name, identifier QHash mNeedToSyncResources; - LogWidget *mLogWidget= nullptr; - KRecentFilesAction *mRecentFilesAction= nullptr; - QAction *mBackupAction= nullptr; - QAction *mRestoreAction= nullptr; - QAction *mSaveLogAction= nullptr; - QAction *mArchiveStructureInfo= nullptr; - QAction *mShowArchiveInformationsAction= nullptr; - QAction *mShowArchiveInformationsAboutCurrentArchiveAction= nullptr; - PimSettingsBackupRestoreUI *mPimSettingsBackupRestoreUI= nullptr; + LogWidget *mLogWidget = nullptr; + KRecentFilesAction *mRecentFilesAction = nullptr; + QAction *mBackupAction = nullptr; + QAction *mRestoreAction = nullptr; + QAction *mSaveLogAction = nullptr; + QAction *mArchiveStructureInfo = nullptr; + QAction *mShowArchiveInformationsAction = nullptr; + QAction *mShowArchiveInformationsAboutCurrentArchiveAction = nullptr; + PimSettingsBackupRestoreUI *mPimSettingsBackupRestoreUI = nullptr; PimSettingsTrayIcon *mTrayIcon = nullptr; }; #endif /* PIMSETTINGEXPORTERWINDOW_H */