| 1 | #include "export_dialog.h" |
| 2 | #include "utils.h" |
| 3 | |
| 4 | ExportDialog::ExportDialog(const QString &remote, const QDir &path, |
| 5 | QWidget *parent) |
| 6 | : QDialog(parent) { |
| 7 | ui.setupUi(this); |
| 8 | resize(0, 0); |
| 9 | |
| 10 | setWindowTitle("Export files list"); |
| 11 | |
| 12 | mTarget = remote + ":" + path.path(); |
| 13 | |
| 14 | QObject::connect(ui.buttonBox->button(QDialogButtonBox::RestoreDefaults), |
| 15 | &QPushButton::clicked, this, [=]() { |
| 16 | ui.rbText->setChecked(true); |
| 17 | ui.checkSameFilesystem->setChecked(false); |
| 18 | ui.textMinSize->clear(); |
| 19 | ui.textMinAge->clear(); |
| 20 | ui.textMaxAge->clear(); |
| 21 | ui.spinMaxDepth->setValue(0); |
| 22 | ui.textExclude->clear(); |
| 23 | ui.textExtra->clear(); |
| 24 | }); |
| 25 | ui.buttonBox->button(QDialogButtonBox::RestoreDefaults)->click(); |
| 26 | |
| 27 | QObject::connect(ui.buttonBox, &QDialogButtonBox::accepted, this, |
| 28 | &QDialog::accept); |
| 29 | QObject::connect(ui.buttonBox, &QDialogButtonBox::rejected, this, |
| 30 | &QDialog::reject); |
| 31 | |
| 32 | QObject::connect(ui.fileBrowse, &QToolButton::clicked, this, [=]() { |
| 33 | QString file = |
| 34 | QFileDialog::getSaveFileName(this, "Choose destination file"); |
| 35 | if (!file.isEmpty()) { |
| 36 | ui.textFile->setText(QDir::toNativeSeparators(file)); |
| 37 | } |
| 38 | }); |
| 39 | |
| 40 | auto settings = GetSettings(); |
| 41 | settings->beginGroup("Export"); |
| 42 | ReadSettings(settings.get(), this); |
| 43 | settings->endGroup(); |
| 44 | } |
| 45 | |
| 46 | ExportDialog::~ExportDialog() { |
| 47 | if (result() == QDialog::Accepted) { |
| 48 | auto settings = GetSettings(); |
| 49 | settings->beginGroup("Export"); |
| 50 | WriteSettings(settings.get(), this); |
| 51 | settings->remove("textFile"); |
| 52 | settings->endGroup(); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | QString ExportDialog::getDestination() const { return ui.textFile->text(); } |
| 57 | |
| 58 | bool ExportDialog::onlyFilenames() const { return ui.rbText->isChecked(); } |
| 59 | |
| 60 | QStringList ExportDialog::getOptions() const { |
| 61 | QStringList list; |
| 62 | list << "lsl"; |
| 63 | if (ui.checkSameFilesystem->isChecked()) { |
| 64 | list << "--one-file-system"; |
| 65 | } |
| 66 | if (!ui.textMinSize->text().isEmpty()) { |
| 67 | list << "--min-size" << ui.textMinSize->text(); |
| 68 | } |
| 69 | if (!ui.textMinAge->text().isEmpty()) { |
| 70 | list << "--min-age" << ui.textMinAge->text(); |
| 71 | } |
| 72 | if (!ui.textMaxAge->text().isEmpty()) { |
| 73 | list << "--max-age" << ui.textMaxAge->text(); |
| 74 | } |
| 75 | if (ui.spinMaxDepth->value() != 0) { |
| 76 | list << "--max-depth" << ui.spinMaxDepth->text(); |
| 77 | } |
| 78 | |
| 79 | QString excluded = ui.textExclude->toPlainText().trimmed(); |
| 80 | if (!excluded.isEmpty()) { |
| 81 | for (auto line : excluded.split('\n')) { |
| 82 | list << "--exclude" << line; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | QString extra = ui.textExtra->text().trimmed(); |
| 87 | if (!extra.isEmpty()) { |
| 88 | for (auto arg : extra.split(' ')) { |
| 89 | list << arg; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | list << mTarget; |
| 94 | |
| 95 | return list; |
| 96 | } |
| 97 | |
| 98 | void ExportDialog::done(int r) { |
| 99 | if (r == QDialog::Accepted) { |
| 100 | if (ui.textFile->text().isEmpty()) { |
| 101 | QMessageBox::warning(this, "Warning", |
| 102 | "Please enter destination filename!"); |
| 103 | return; |
| 104 | } |
| 105 | } |
| 106 | QDialog::done(r); |
| 107 | } |