From 362f447ede988023951f85f86dc3e7c609fd5014 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Tue, 26 Jun 2012 00:24:58 +0200 Subject: Create dedicated backup dialog. The "Installation" dialog allows backing up the current installation by creating a zip file from the .rockbox folder since quite a while. However, this has the drawback that you need to update your build to create a backup, but creating a backup might be desireable in other cases as well (before updating themes, or just for backup reasons). Since the functionality is somewhat hidden it's also not obvious to users such a functionality exists (most users are likely to use the "Quick Start" instead). Implement backup functionality as dedicated dialog placed on the Uninstall tab. Rename the Uninstall tab to accommodate this. Change-Id: I1d2c6c8f646672d1b66bb442408fbfc2eeec700d --- rbutil/rbutilqt/base/rbsettings.cpp | 1 + rbutil/rbutilqt/base/rbsettings.h | 1 + rbutil/rbutilqt/gui/backupdialog.cpp | 141 +++++++++++++++++++++++++++ rbutil/rbutilqt/gui/backupdialog.h | 49 ++++++++++ rbutil/rbutilqt/gui/backupdialogfrm.ui | 142 ++++++++++++++++++++++++++++ rbutil/rbutilqt/icons/package-x-generic.png | Bin 540 -> 1900 bytes rbutil/rbutilqt/rbutilqt.cpp | 9 ++ rbutil/rbutilqt/rbutilqt.h | 3 + rbutil/rbutilqt/rbutilqt.pri | 5 +- rbutil/rbutilqt/rbutilqtfrm.ui | 38 +++++--- 10 files changed, 376 insertions(+), 13 deletions(-) create mode 100644 rbutil/rbutilqt/gui/backupdialog.cpp create mode 100644 rbutil/rbutilqt/gui/backupdialog.h create mode 100644 rbutil/rbutilqt/gui/backupdialogfrm.ui diff --git a/rbutil/rbutilqt/base/rbsettings.cpp b/rbutil/rbutilqt/base/rbsettings.cpp index f584c6808c..f6a936ab9a 100644 --- a/rbutil/rbutilqt/base/rbsettings.cpp +++ b/rbutil/rbutilqt/base/rbsettings.cpp @@ -40,6 +40,7 @@ const static struct { { RbSettings::OfPath, "ofpath", "" }, { RbSettings::Platform, "platform", "" }, { RbSettings::Language, "lang", "" }, + { RbSettings::BackupPath, "backuppath", "" }, #if defined(Q_OS_WIN32) { RbSettings::Tts, "tts", "sapi" }, #elif defined(Q_OS_MACX) diff --git a/rbutil/rbutilqt/base/rbsettings.h b/rbutil/rbutilqt/base/rbsettings.h index 45ec7092e2..21234a4e9a 100644 --- a/rbutil/rbutilqt/base/rbsettings.h +++ b/rbutil/rbutilqt/base/rbsettings.h @@ -40,6 +40,7 @@ class RbSettings : public QObject OfPath, Platform, Language, + BackupPath, Tts, UseTtsCorrections, TalkFolders, diff --git a/rbutil/rbutilqt/gui/backupdialog.cpp b/rbutil/rbutilqt/gui/backupdialog.cpp new file mode 100644 index 0000000000..5d04b322ed --- /dev/null +++ b/rbutil/rbutilqt/gui/backupdialog.cpp @@ -0,0 +1,141 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2012 by Dominik Riebeling + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include "backupdialog.h" +#include "ui_backupdialogfrm.h" +#include "rbsettings.h" +#include "progressloggergui.h" +#include "ziputil.h" +#include "rockboxinfo.h" + +class BackupSizeThread : public QThread +{ + public: + void run(void); + void setPath(QString p) { m_path = p; } + qint64 currentSize(void) { return m_currentSize; } + + private: + QString m_path; + qint64 m_currentSize; +}; + + +void BackupSizeThread::run(void) +{ + qDebug() << "BackupSizeThread] Thread started, calculating" << m_path; + m_currentSize = 0; + + QDirIterator it(m_path, QDirIterator::Subdirectories); + while(it.hasNext()) { + m_currentSize += QFileInfo(it.next()).size(); + } + qDebug() << "[BackupSizeThread] Thread done, sum:" << m_currentSize; +} + + +BackupDialog::BackupDialog(QWidget* parent) : QDialog(parent) +{ + ui.setupUi(this); + + m_thread = new BackupSizeThread(); + connect(m_thread, SIGNAL(finished()), this, SLOT(updateSizeInfo())); + connect(m_thread, SIGNAL(terminated()), this, SLOT(updateSizeInfo())); + + connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close())); + connect(ui.buttonCancel, SIGNAL(clicked()), m_thread, SLOT(quit())); + connect(ui.buttonChange, SIGNAL(clicked()), this, SLOT(changeBackupPath())); + connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup())); + + ui.backupSize->setText(tr("Installation size: calculating ...")); + m_mountpoint = RbSettings::value(RbSettings::Mountpoint).toString(); + + m_backupName = RbSettings::value(RbSettings::BackupPath).toString(); + if(m_backupName.isEmpty()) { + m_backupName = m_mountpoint; + } + RockboxInfo info(m_mountpoint); + m_backupName += "/.backup/rockbox-backup-" + info.version() + ".zip"; + ui.backupLocation->setText(QDir::toNativeSeparators(m_backupName)); + + m_thread->setPath(m_mountpoint + "/.rockbox"); + m_thread->start(); +} + + +void BackupDialog::changeBackupPath(void) +{ + QString backupString = QFileDialog::getSaveFileName(this, + tr("Select Backup Filename"), m_backupName, "*.zip"); + // only update if a filename was entered, ignore if cancelled + if(!backupString.isEmpty()) { + m_backupName = backupString; + ui.backupLocation->setText(QDir::toNativeSeparators(m_backupName)); + RbSettings::setValue(RbSettings::BackupPath, QFileInfo(m_backupName).absolutePath()); + } +} + + +void BackupDialog::updateSizeInfo(void) +{ + double size = m_thread->currentSize() / (1024 * 1024); + QString unit = "MiB"; + + if(size > 1024) { + size /= 1024; + unit = "GiB"; + } + + ui.backupSize->setText(tr("Installation size: %L1 %2").arg(size, 0, 'g', 4).arg(unit)); +} + + +void BackupDialog::backup(void) +{ + m_logger = new ProgressLoggerGui(this); + connect(m_logger, SIGNAL(closed()), this, SLOT(close())); + m_logger->show(); + m_logger->addItem(tr("Starting backup ..."),LOGINFO); + QCoreApplication::processEvents(); + + // create dir, if it doesnt exist + QFileInfo backupFile(m_backupName); + if(!QDir(backupFile.path()).exists()) + { + QDir a; + a.mkpath(backupFile.path()); + } + + // create backup + ZipUtil zip(this); + connect(&zip, SIGNAL(logProgress(int, int)), m_logger, SLOT(setProgress(int, int))); + connect(&zip, SIGNAL(logItem(QString, int)), m_logger, SLOT(addItem(QString, int))); + zip.open(m_backupName, QuaZip::mdCreate); + + QString mp = m_mountpoint + "/.rockbox"; + if(zip.appendDirToArchive(mp, m_mountpoint)) { + m_logger->addItem(tr("Backup successful."), LOGINFO); + } + else { + m_logger->addItem(tr("Backup failed!"), LOGERROR); + } + zip.close(); + m_logger->setFinished(); +} + diff --git a/rbutil/rbutilqt/gui/backupdialog.h b/rbutil/rbutilqt/gui/backupdialog.h new file mode 100644 index 0000000000..cd5ea398d9 --- /dev/null +++ b/rbutil/rbutilqt/gui/backupdialog.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2012 by Dominik Riebeling + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef BACKUPDIALOG_H +#define BACKUPDIALOG_H + +#include +#include +#include "ui_backupdialogfrm.h" +#include "progressloggergui.h" + +class BackupSizeThread; + +class BackupDialog : public QDialog +{ + Q_OBJECT + public: + BackupDialog(QWidget* parent = 0); + + private slots: + void changeBackupPath(void); + void updateSizeInfo(void); + void backup(void); + + private: + Ui::BackupDialog ui; + QString m_backupName; + QString m_mountpoint; + BackupSizeThread *m_thread; + ProgressLoggerGui *m_logger; +}; + +#endif + diff --git a/rbutil/rbutilqt/gui/backupdialogfrm.ui b/rbutil/rbutilqt/gui/backupdialogfrm.ui new file mode 100644 index 0000000000..5de61d1e91 --- /dev/null +++ b/rbutil/rbutilqt/gui/backupdialogfrm.ui @@ -0,0 +1,142 @@ + + + BackupDialog + + + + 0 + 0 + 554 + 448 + + + + Backup + + + + + + + + + :/icons/wizard.jpg + + + + + + + <html><head/><body><p>This dialog will create a backup by archiving the contents of the Rockbox installation on the player into a zip file. This will include installed themes and settings stored below the .rockbox folder on the player.</p><p>The backup filename will be created based on the installed version. </p></body></html> + + + true + + + + + + + Backup + + + + + + Size: unknown + + + + + + + Backup to: unknown + + + + + + + Qt::Horizontal + + + + 78 + 20 + + + + + + + + &Change + + + + :/icons/edit-find.png:/icons/edit-find.png + + + + + + + + + + Qt::Vertical + + + + 20 + 1 + + + + + + + + Qt::Horizontal + + + + 143 + 20 + + + + + + + + &Backup + + + + :/icons/go-next.png:/icons/go-next.png + + + + + + + &Cancel + + + + :/icons/process-stop.png:/icons/process-stop.png + + + + + + + buttonBackup + buttonCancel + + + + + + diff --git a/rbutil/rbutilqt/icons/package-x-generic.png b/rbutil/rbutilqt/icons/package-x-generic.png index 9015426153..6728f590e0 100644 Binary files a/rbutil/rbutilqt/icons/package-x-generic.png and b/rbutil/rbutilqt/icons/package-x-generic.png differ diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index b62167a4e7..5bce622799 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -40,6 +40,7 @@ #include "ziputil.h" #include "manualwidget.h" #include "infowidget.h" +#include "backupdialog.h" #include "progressloggerinterface.h" @@ -152,6 +153,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) connect(ui.buttonRemoveBootloader, SIGNAL(clicked()), this, SLOT(uninstallBootloader())); connect(ui.buttonSmall, SIGNAL(clicked()), this, SLOT(smallInstall())); connect(ui.buttonComplete, SIGNAL(clicked()), this, SLOT(completeInstall())); + connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup())); // actions accessible from the menu connect(ui.actionComplete_Installation, SIGNAL(triggered()), this, SLOT(completeInstall())); @@ -386,6 +388,13 @@ void RbUtilQt::updateDevice() } +void RbUtilQt::backup(void) +{ + backupdialog = new BackupDialog(this); + backupdialog->show(); +} + + void RbUtilQt::completeInstall() { if(chkConfig(this)) return; diff --git a/rbutil/rbutilqt/rbutilqt.h b/rbutil/rbutilqt/rbutilqt.h index 67fbff78e1..3e57af589b 100644 --- a/rbutil/rbutilqt/rbutilqt.h +++ b/rbutil/rbutilqt/rbutilqt.h @@ -34,6 +34,7 @@ #include "bootloaderinstallbase.h" #include "manualwidget.h" #include "infowidget.h" +#include "backupdialog.h" class RbUtilQt : public QMainWindow { @@ -47,6 +48,7 @@ class RbUtilQt : public QMainWindow private: ManualWidget *manual; InfoWidget *info; + BackupDialog *backupdialog; Ui::RbUtilQtFrm ui; void changeEvent(QEvent *e); @@ -106,6 +108,7 @@ class RbUtilQt : public QMainWindow void createVoiceFile(void); void downloadDone(bool); void downloadInfo(void); + void backup(void); void installVoice(void); void installThemes(void); diff --git a/rbutil/rbutilqt/rbutilqt.pri b/rbutil/rbutilqt/rbutilqt.pri index 6a74a7c52f..330a3cd19a 100644 --- a/rbutil/rbutilqt/rbutilqt.pri +++ b/rbutil/rbutilqt/rbutilqt.pri @@ -78,6 +78,7 @@ SOURCES += \ quazip/ioapi.c \ base/ziputil.cpp \ comboboxviewdelegate.cpp \ + gui/backupdialog.cpp \ HEADERS += \ @@ -149,6 +150,7 @@ HEADERS += \ base/ziputil.h \ lame/lame.h \ comboboxviewdelegate.h \ + gui/backupdialog.h \ FORMS += \ @@ -165,7 +167,8 @@ FORMS += \ previewfrm.ui \ createvoicefrm.ui \ sysinfofrm.ui \ - systracefrm.ui + systracefrm.ui \ + gui/backupdialogfrm.ui \ TRANSLATIONS += \ diff --git a/rbutil/rbutilqt/rbutilqtfrm.ui b/rbutil/rbutilqt/rbutilqtfrm.ui index d851b19021..aae4bd4f9b 100644 --- a/rbutil/rbutilqt/rbutilqtfrm.ui +++ b/rbutil/rbutilqt/rbutilqtfrm.ui @@ -282,9 +282,6 @@ true - - buttonRockbox - @@ -549,12 +546,12 @@ - &Uninstallation + Backup && &Uninstallation Uninstall Rockbox - + @@ -616,19 +613,36 @@ - - - Qt::Vertical + + + Backup - + + + :/icons/package-x-generic.png:/icons/package-x-generic.png + + - 20 - 40 + 56 + 46 - + + + + <html><head/><body><p><span style=" font-weight:600;">Backup current installation.</span></p><p>Create a backup by archiving the contents of the Rockbox installation folder.</p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + true + + + + Qt::Vertical -- cgit v1.2.3