From 41e9051f2d809c42c3dfecc2eb11ad544cbd27b7 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 19 Sep 2022 02:39:03 -0400 Subject: You break it, you fix it! The GUI is now working again, with scanning built-in. --- qdeduper/pathchooser.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 qdeduper/pathchooser.cpp (limited to 'qdeduper/pathchooser.cpp') diff --git a/qdeduper/pathchooser.cpp b/qdeduper/pathchooser.cpp new file mode 100644 index 0000000..c08199f --- /dev/null +++ b/qdeduper/pathchooser.cpp @@ -0,0 +1,79 @@ +#include "pathchooser.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +PathChooser::PathChooser(QWidget *parent) : QDialog(parent) +{ + QVBoxLayout *l = new QVBoxLayout(); + this->setLayout(l); + bb = new QDialogButtonBox(QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Cancel, this); + bb->button(QDialogButtonBox::StandardButton::Ok)->setText("Scan"); + + QPushButton *pbbrowse = new QPushButton(); + pbbrowse->setText("Browse..."); + pbbrowse->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DirOpenIcon)); + bb->addButton(pbbrowse, QDialogButtonBox::ButtonRole::ActionRole); + QObject::connect(pbbrowse, &QPushButton::pressed, this, &PathChooser::add_new); + + QPushButton *pbdelete = new QPushButton(); + pbdelete->setText("Delete"); + pbdelete->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DialogDiscardButton)); + bb->addButton(pbdelete, QDialogButtonBox::ButtonRole::ActionRole); + QObject::connect(pbdelete, &QPushButton::pressed, this, &PathChooser::delete_selected); + QObject::connect(bb, &QDialogButtonBox::accepted, this, &PathChooser::accept); + QObject::connect(bb, &QDialogButtonBox::rejected, this, &PathChooser::reject); + im = new QStandardItemModel(this); + tv = new QTableView(); + tv->setModel(im); + tv->setSortingEnabled(false); + tv->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection); + im->setHorizontalHeaderLabels({"Path", "Recursive?"}); + + QLabel *lb = new QLabel("Choose directories to scan"); + l->addWidget(lb); + l->addWidget(tv); + l->addWidget(bb); +} + +std::vector> PathChooser::get_dirs() +{ + std::vector> ret; + for (int i = 0; i < im->rowCount(); ++i) + { +#if PATH_VALSIZE == 2 + fs::path p(im->item(i, 0)->text().toStdWString()); +#else + fs::path p(im->item(i, 0)->text().toStdString()); +#endif + ret.emplace_back(p, (im->item(i, 1)->checkState() == Qt::CheckState::Checked)); + } + return ret; +} + +void PathChooser::add_new() +{ + QString s = QFileDialog::getExistingDirectory(this, "Open"); + if (s.isNull() || s.isEmpty()) return; + QStandardItem *it = new QStandardItem(s); + QStandardItem *ck = new QStandardItem(); + it->setEditable(false); + ck->setCheckable(true); + im->appendRow({it, ck}); + tv->resizeColumnsToContents(); +} + +void PathChooser::delete_selected() +{ + im->removeRow(tv->currentIndex().row()); +} -- cgit v1.2.3