Skip to content

Commit

Permalink
Display list of files to be restored in restore dialog.
Browse files Browse the repository at this point in the history
Issue #129.
  • Loading branch information
shinnok committed Jun 5, 2017
1 parent 9b0f84a commit 87394c6
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 32 deletions.
75 changes: 58 additions & 17 deletions forms/restoredialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,41 @@
<x>0</x>
<y>0</y>
<width>500</width>
<height>300</height>
<height>335</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>300</height>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Archive restore</string>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="restoreDialogLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>12</number>
<number>6</number>
</property>
<property name="topMargin">
<number>12</number>
<number>6</number>
</property>
<property name="rightMargin">
<number>12</number>
<number>6</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="infoLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
Expand All @@ -51,6 +57,41 @@
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="filesListWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">#filesListWidget
{
font-family: Monospace, Monaco;
font-size: 12px;
}

#filesListWidget::item
{
height: 25px;
}
</string>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="layoutMode">
<enum>QListView::Batched</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="optionsGroupBox">
<layout class="QGridLayout" name="optionsGridLayout">
Expand Down Expand Up @@ -158,16 +199,6 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="preservePermCheckBox">
<property name="toolTip">
<string>Attempt to restore the full permissions, including owner, file modes, file flags and ACLs, if available, for each item extracted from the archive.</string>
</property>
<property name="text">
<string>Preserve file permissions</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="optionBaseDirRadio">
<property name="toolTip">
Expand All @@ -185,6 +216,16 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="preservePermCheckBox">
<property name="toolTip">
<string>Attempt to restore the full permissions, including owner, file modes, file flags and ACLs, if available, for each item extracted from the archive.</string>
</property>
<property name="text">
<string>Preserve file permissions</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/archivelistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void ArchiveListWidget::restoreSelectedItem()
static_cast<ArchiveListWidgetItem *>(selectedItems().first());
if(archiveItem && !archiveItem->archive()->deleteScheduled())
{
RestoreDialog restoreDialog(archiveItem->archive(), this);
RestoreDialog restoreDialog(this, archiveItem->archive());
if(QDialog::Accepted == restoreDialog.exec())
emit restoreArchive(archiveItem->archive(),
restoreDialog.getOptions());
Expand Down Expand Up @@ -257,7 +257,7 @@ void ArchiveListWidget::restoreItem()
qobject_cast<ArchiveListWidgetItem *>(sender());
if(archiveItem)
{
RestoreDialog restoreDialog(archiveItem->archive(), this);
RestoreDialog restoreDialog(this, archiveItem->archive());
if(QDialog::Accepted == restoreDialog.exec())
emit restoreArchive(archiveItem->archive(),
restoreDialog.getOptions());
Expand Down
3 changes: 1 addition & 2 deletions src/widgets/archivewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,11 @@ void ArchiveWidget::restoreFiles()
foreach(QModelIndex index, indexes)
files << index.data().toString();

RestoreDialog restoreDialog(_archive, this);
RestoreDialog restoreDialog(this, _archive, files);
restoreDialog.displayTarOption(false);
if(QDialog::Accepted == restoreDialog.exec())
{
ArchiveRestoreOptions options = restoreDialog.getOptions();
options.files = files;
emit restoreArchive(_archive, options);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/joblistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void JobListWidget::restoreItem()
if(!job->archives().isEmpty())
{
ArchivePtr archive = job->archives().first();
RestoreDialog restoreDialog(archive, this);
RestoreDialog restoreDialog(this, archive);
if(QDialog::Accepted == restoreDialog.exec())
emit restoreArchive(archive, restoreDialog.getOptions());
}
Expand Down Expand Up @@ -218,7 +218,7 @@ void JobListWidget::restoreSelectedItem()
if(!job->archives().isEmpty())
{
ArchivePtr archive = job->archives().first();
RestoreDialog restoreDialog(archive, this);
RestoreDialog restoreDialog(this, archive);
if(QDialog::Accepted == restoreDialog.exec())
emit restoreArchive(archive, restoreDialog.getOptions());
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/jobwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void JobWidget::restoreButtonClicked()
if(_job && !_job->archives().isEmpty())
{
ArchivePtr archive = _job->archives().first();
RestoreDialog restoreDialog(archive, this);
RestoreDialog restoreDialog(this, archive);
if(QDialog::Accepted == restoreDialog.exec())
emit restoreJobArchive(archive, restoreDialog.getOptions());
}
Expand Down
17 changes: 10 additions & 7 deletions src/widgets/restoredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
#include <QMessageBox>
#include <QSettings>

RestoreDialog::RestoreDialog(ArchivePtr archive, QWidget *parent)
: QDialog(parent), _archive(archive)
RestoreDialog::RestoreDialog(QWidget *parent, ArchivePtr archive, QStringList files)
: QDialog(parent), _archive(archive), _files(files)
{
_ui.setupUi(this);
setWindowFlags((windowFlags() | Qt::CustomizeWindowHint)
& ~Qt::WindowMaximizeButtonHint);

QSettings settings;
_downDir = settings.value("app/downloads_dir", DEFAULT_DOWNLOADS).toString();
Expand Down Expand Up @@ -58,6 +56,10 @@ RestoreDialog::RestoreDialog(ArchivePtr archive, QWidget *parent)
displayRestoreOption(canRestore);
_ui.optionRestoreRadio->setChecked(canRestore);
_ui.optionBaseDirRadio->setChecked(!canRestore);
if(!_files.isEmpty())
_ui.filesListWidget->addItems(_files);
else
_ui.filesListWidget->addItems(_archive->contents().split(QChar('\n')));
}

RestoreDialog::~RestoreDialog()
Expand All @@ -73,6 +75,7 @@ ArchiveRestoreOptions RestoreDialog::getOptions()
options.overwriteFiles = _ui.overwriteCheckBox->isChecked();
options.keepNewerFiles = _ui.keepNewerCheckBox->isChecked();
options.preservePerms = _ui.preservePermCheckBox->isChecked();
options.files = _files;
if(options.optionRestoreDir)
options.path = _ui.baseDirLineEdit->text();
else if(options.optionTarArchive)
Expand All @@ -94,7 +97,7 @@ void RestoreDialog::displayTarOption(bool display)

void RestoreDialog::optionBaseDirToggled(bool checked)
{
_ui.infoLabel->setText(tr("Restore archive <b>%1</b> contents to specified"
_ui.infoLabel->setText(tr("Restore from archive <b>%1</b> to specified"
" directory? Any existing files will not be"
" replaced by default. Use the options below to"
" modify this behavior:")
Expand All @@ -110,7 +113,7 @@ void RestoreDialog::optionBaseDirToggled(bool checked)
void RestoreDialog::optionTarArchiveToggled(bool checked)
{
_ui.infoLabel->setText(tr("Download archive <b>%1</b> contents as an"
" uncompressed TAR archive.")
" uncompressed TAR archive?")
.arg(_archive->name()));
_ui.archiveLineEdit->setVisible(checked);
_ui.changeArchiveButton->setVisible(checked);
Expand All @@ -119,7 +122,7 @@ void RestoreDialog::optionTarArchiveToggled(bool checked)

void RestoreDialog::optionRestoreToggled(bool checked)
{
_ui.infoLabel->setText(tr("Restore archive <b>%1</b> contents to original"
_ui.infoLabel->setText(tr("Restore from archive <b>%1</b> to original"
" locations? Any existing files will not be"
" replaced by default. Use the options below to"
" modify this behavior:")
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/restoredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class RestoreDialog : public QDialog
//! Constructor.
//! \param archive: the ArchivePtr to restore.
//! \param parent: standard Qt parameter.
explicit RestoreDialog(ArchivePtr archive, QWidget *parent = nullptr);
explicit RestoreDialog(QWidget *parent, ArchivePtr archive,
QStringList files = QStringList());
~RestoreDialog();

//! Returns options from the dialog window.
Expand All @@ -38,6 +39,7 @@ private slots:
private:
Ui::RestoreDialog _ui;
ArchivePtr _archive;
QStringList _files;
QString _downDir;

void displayRestoreOption(bool display);
Expand Down

0 comments on commit 87394c6

Please sign in to comment.