From 8f68886c3a3828a4796013019488b4a1e3cd7872 Mon Sep 17 00:00:00 2001 From: birkeh Date: Thu, 15 Aug 2019 00:17:33 +0200 Subject: [PATCH] initial commit --- cfile.cpp | 36 ++++++++- cfile.h | 4 + cmainwindow.cpp | 157 ++++++++++++++++++++++++++++++++++++-- cmainwindow.h | 8 ++ cmainwindow.ui | 35 +++++++++ csortfilterproxymodel.cpp | 2 - 6 files changed, 232 insertions(+), 10 deletions(-) diff --git a/cfile.cpp b/cfile.cpp index 61605f0..cfeb172 100644 --- a/cfile.cpp +++ b/cfile.cpp @@ -97,8 +97,31 @@ void cFileList::parseLine(const QString& curDir, const QString& line) QDateTime dateTime = QDateTime(QDate::fromString(date, "dd.MM.yyyy"), QTime::fromString(time, "hh:mm")); - if(file.endsWith(".nef", Qt::CaseInsensitive)) - add(dir.replace("\\", "/"), file, dateTime, size.toLongLong(), false); + add(dir.replace("\\", "/"), file, dateTime, size.toLongLong(), false); +} + +void cFileList::parseDir(const QString& dir, QStatusBar* lpStatusBar) +{ + QDir _dir(dir); + + if(lpStatusBar) + { + lpStatusBar->showMessage(_dir.path()); + qApp->processEvents(); + } + + QFileInfoList fileList = _dir.entryInfoList(QDir::Files, QDir::Name); + + for(QFileInfoList::iterator i = fileList.begin();i != fileList.end();i++) + add(_dir.path(), i->fileName(), i->birthTime(), i->size(), false); + + + QStringList dirList = _dir.entryList(QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDir::Name); + + for(QStringList::iterator i = dirList.begin();i != dirList.end();i++) + { + parseDir(dir + QDir::separator() + *i, lpStatusBar); + } } bool cFileList::load(const QString& file, QProgressBar* lpProgressBar) @@ -147,6 +170,15 @@ bool cFileList::load(const QString& file, QProgressBar* lpProgressBar) return(true); } +bool cFileList::load(const QString& dir, QStatusBar* lpStatusBar) +{ + clear(); + + parseDir(dir, lpStatusBar); + + return(true); +} + cFile* cFileList::add(const QString& dir, const QString& file, const QDateTime& dateTime, const qint64& size, bool search) { cFile* lpFile = nullptr; diff --git a/cfile.h b/cfile.h index 0bdddae..34475d5 100644 --- a/cfile.h +++ b/cfile.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include class cFile @@ -41,6 +43,7 @@ class cFileList : public QList { public: bool load(const QString& file, QProgressBar* lpProgressBar = nullptr); + bool load(const QString& dir, QStatusBar* lpStatusBar = nullptr); cFile* add(const QString& dir, const QString& file, const QDateTime& dateTime, const qint64& size, bool search = true); cFile* find(const QString& dir, const QString& file, const QDateTime& dateTime, const qint64& size); @@ -48,6 +51,7 @@ public: bool contains(cFile& file, bool bDir, bool bFile, bool bDate, bool bSize); private: void parseLine(const QString& curDir, const QString& line); + void parseDir(const QString& dir, QStatusBar* lpStatusBar); }; #endif // CFILE_H diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 78531f5..3e7223d 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + //#define TREEVIEW @@ -131,6 +134,9 @@ void cMainWindow::createActions() connect(ui->m_lpLoadListFromFileLeft, &QToolButton::clicked, this, &cMainWindow::onLoadListFromFileLeft); connect(ui->m_lpLoadListFromFileRight, &QToolButton::clicked, this, &cMainWindow::onLoadListFromFileRight); + connect(ui->m_lpLoadListFromDirLeft, &QToolButton::clicked, this, &cMainWindow::onLoadListFromDirLeft); + connect(ui->m_lpLoadListFromDirRight, &QToolButton::clicked, this, &cMainWindow::onLoadListFromDirRight); + connect(ui->m_lpLeftList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onLeftListSelected); connect(ui->m_lpRightList->selectionModel(), &QItemSelectionModel::selectionChanged, this, &cMainWindow::onRightListSelected); @@ -138,6 +144,11 @@ void cMainWindow::createActions() connect(ui->m_lpMatchFile, &QCheckBox::clicked, this, &cMainWindow::onMatchFileChecked); connect(ui->m_lpMatchDateTime, &QCheckBox::clicked, this, &cMainWindow::onMatchDateTimeChecked); connect(ui->m_lpMatchSize, &QCheckBox::clicked, this, &cMainWindow::onMatchSizeChecked); + + connect(ui->m_lpMarkDifference, &QToolButton::clicked, this, &cMainWindow::onMarkDifference); + + connect(ui->m_lpClearSelectionLeft, &QToolButton::clicked, this, &cMainWindow::onClearSelectionLeft); + connect(ui->m_lpClearSelectionRight, &QToolButton::clicked, this, &cMainWindow::onClearSelectionRight); } void cMainWindow::createFileActions() @@ -151,19 +162,23 @@ void cMainWindow::createContextActions() void cMainWindow::onLoadListFromFileLeft() { QSettings settings; - QString szPath = settings.value("main/leftDir", QDir::homePath()).toString(); + QString szPath = settings.value("main/leftFile", QDir::homePath()).toString(); QString szFile = QFileDialog::getOpenFileName(this, tr("Open Text File"), szPath, tr("Text Files (*.txt)")); if(szFile.isEmpty()) return; - settings.setValue("main/leftDir", QVariant::fromValue(szFile.left(szFile.lastIndexOf("/")))); + settings.setValue("main/leftFile", QVariant::fromValue(szFile.left(szFile.lastIndexOf("/")))); m_loading = true; m_lpProgressBar->setVisible(true); -// m_listLeft.load("C:\\Users\\VET0572\\Documents\\github\\build-dir2csv-Desktop_Qt_5_13_0_MinGW_64_bit-Release\\deploy\\photos.txt", m_lpProgressBar); + ui->m_lpStatusBar->showMessage("loading list..."); + qApp->processEvents(); m_listLeft.load(szFile, m_lpProgressBar); + ui->m_lpStatusBar->showMessage("populating list..."); + qApp->processEvents(); displayList(ui->m_lpLeftList, m_lpLeftListModel, m_listLeft); + ui->m_lpStatusBar->showMessage("done.", 5000); m_lpProgressBar->setVisible(false); m_loading = false; } @@ -171,23 +186,151 @@ void cMainWindow::onLoadListFromFileLeft() void cMainWindow::onLoadListFromFileRight() { QSettings settings; - QString szPath = settings.value("main/rightDir", QDir::homePath()).toString(); + QString szPath = settings.value("main/rightFile", QDir::homePath()).toString(); QString szFile = QFileDialog::getOpenFileName(this, tr("Open Text File"), szPath, tr("Text Files (*.txt)")); if(szFile.isEmpty()) return; - settings.setValue("main/rightDir", QVariant::fromValue(szFile.left(szFile.lastIndexOf("/")))); + settings.setValue("main/rightFile", QVariant::fromValue(szFile.left(szFile.lastIndexOf("/")))); m_loading = true; m_lpProgressBar->setVisible(true); -// m_listRight.load("C:\\Users\\VET0572\\Documents\\github\\build-dir2csv-Desktop_Qt_5_13_0_MinGW_64_bit-Release\\deploy\\photos1.txt", m_lpProgressBar); + ui->m_lpStatusBar->showMessage("loading list..."); + qApp->processEvents(); m_listRight.load(szFile, m_lpProgressBar); + ui->m_lpStatusBar->showMessage("populating list..."); + qApp->processEvents(); displayList(ui->m_lpRightList, m_lpRightListModel, m_listRight); + ui->m_lpStatusBar->showMessage("done.", 5000); m_lpProgressBar->setVisible(false); m_loading = false; } +void cMainWindow::onLoadListFromDirLeft() +{ + QSettings settings; + QString szPath = settings.value("main/leftDir", QDir::homePath()).toString(); + QString szDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), szPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + if(szDir.isEmpty()) + return; + + settings.setValue("main/leftDir", QVariant::fromValue(szDir)); + + m_loading = true; + ui->m_lpStatusBar->showMessage("loading list..."); + qApp->processEvents(); + m_listLeft.load(szDir, ui->m_lpStatusBar); + ui->m_lpStatusBar->showMessage("populating list..."); + qApp->processEvents(); + displayList(ui->m_lpLeftList, m_lpLeftListModel, m_listLeft); + ui->m_lpStatusBar->showMessage("done.", 5000); + m_loading = false; +} + +void cMainWindow::onLoadListFromDirRight() +{ + QSettings settings; + QString szPath = settings.value("main/rightDir", QDir::homePath()).toString(); + QString szDir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), szPath, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + if(szDir.isEmpty()) + return; + + settings.setValue("main/rightDir", QVariant::fromValue(szDir)); + + m_loading = true; + ui->m_lpStatusBar->showMessage("loading list..."); + qApp->processEvents(); + m_listRight.load(szDir, ui->m_lpStatusBar); + ui->m_lpStatusBar->showMessage("populating list..."); + qApp->processEvents(); + displayList(ui->m_lpRightList, m_lpRightListModel, m_listRight); + ui->m_lpStatusBar->showMessage("done.", 5000); + m_loading = false; +} + +void cMainWindow::onMarkDifference() +{ + qint64 div = m_lpLeftListModel->rowCount() / 1000; + + ui->m_lpStatusBar->showMessage("processing left list..."); + + m_lpProgressBar->setVisible(true); + m_lpProgressBar->setRange(0, m_lpLeftListModel->rowCount()); + + QVariant white = QVariant::fromValue(QBrush(QColor(Qt::white))); + QVariant green = QVariant::fromValue(QBrush(QColor(Qt::green))); + + for(int i = 0;i < m_lpLeftListModel->rowCount();i++) + { + QStandardItem* lpItem = m_lpLeftListModel->item(i, 0); + cFile* lpFile = lpItem->data(Qt::UserRole+1).value(); + QVariant var; + + if(m_listRight.contains(*lpFile)) + { + lpItem->setData(green, Qt::BackgroundRole); + m_lpLeftListModel->setData(m_lpLeftListModel->index(i, 1), green, Qt::BackgroundRole); + m_lpLeftListModel->setData(m_lpLeftListModel->index(i, 2), green, Qt::BackgroundRole); +#ifndef TREEVIEW + m_lpLeftListModel->setData(m_lpLeftListModel->index(i, 3), green, Qt::BackgroundRole); +#endif + } + + if(!(i % div)) + { + m_lpProgressBar->setValue(i); + qApp->processEvents(); + } + } + + div = m_lpRightListModel->rowCount() / 1000; + + ui->m_lpStatusBar->showMessage("processing right list..."); + + m_lpProgressBar->setRange(0, m_lpRightListModel->rowCount()); + + for(int i = 0;i < m_lpRightListModel->rowCount();i++) + { + QStandardItem* lpItem = m_lpRightListModel->item(i, 0); + cFile* lpFile = lpItem->data(Qt::UserRole+1).value(); + QBrush brush(Qt::white); + + if(m_listLeft.contains(*lpFile)) + { + lpItem->setData(green, Qt::BackgroundRole); + m_lpRightListModel->setData(m_lpRightListModel->index(i, 1), green, Qt::BackgroundRole); + m_lpRightListModel->setData(m_lpRightListModel->index(i, 2), green, Qt::BackgroundRole); +#ifndef TREEVIEW + m_lpRightListModel->setData(m_lpRightListModel->index(i, 3), green, Qt::BackgroundRole); +#endif + } + + if(!(i % div)) + { + m_lpProgressBar->setValue(i); + qApp->processEvents(); + } + } + + m_lpProgressBar->setVisible(false); + + ui->m_lpStatusBar->showMessage("done.", 5000); +} + +void cMainWindow::onClearSelectionLeft() +{ + ui->m_lpLeftList->clearSelection(); + m_lpRightListProxyModel->setFilterFile(nullptr); +} + +void cMainWindow::onClearSelectionRight() +{ + ui->m_lpRightList->clearSelection(); + m_lpLeftListProxyModel->setFilterFile(nullptr); +} + #ifdef TREEVIEW QStandardItem* insertPath(QTreeView* lpView, QStandardItem* lpRootItem, QString szPath) { @@ -257,6 +400,8 @@ void cMainWindow::displayList(QTreeView* lpView, QStandardItemModel* lpModel, cF lpModel->setHorizontalHeaderLabels(header); QStandardItem* lpRoot = lpModel->invisibleRootItem(); + m_lpProgressBar->setRange(0, fileList.count()); + for(cFileList::iterator i = fileList.begin();i != fileList.end();i++) { QList items; diff --git a/cmainwindow.h b/cmainwindow.h index a2ad1a0..bdbb906 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -27,6 +27,9 @@ private slots: void onLoadListFromFileLeft(); void onLoadListFromFileRight(); + void onLoadListFromDirLeft(); + void onLoadListFromDirRight(); + void onLeftListSelected(const QItemSelection& selection, const QItemSelection& previous); void onRightListSelected(const QItemSelection& selection, const QItemSelection& previous); @@ -35,6 +38,11 @@ private slots: void onMatchDateTimeChecked(bool checked); void onMatchSizeChecked(bool checked); + void onMarkDifference(); + + void onClearSelectionLeft(); + void onClearSelectionRight(); + private: Ui::cMainWindow* ui; QStandardItemModel* m_lpLeftListModel; diff --git a/cmainwindow.ui b/cmainwindow.ui index a178035..9261809 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -47,6 +47,13 @@ + + + + mark difference + + + @@ -71,6 +78,13 @@ + + + + from dir + + + @@ -78,6 +92,13 @@ + + + + clear selection + + + @@ -106,6 +127,13 @@ + + + + from dir + + + @@ -113,6 +141,13 @@ + + + + clear selection + + + diff --git a/csortfilterproxymodel.cpp b/csortfilterproxymodel.cpp index af004a9..05df933 100644 --- a/csortfilterproxymodel.cpp +++ b/csortfilterproxymodel.cpp @@ -24,8 +24,6 @@ bool cSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &s if(!m_lpFile) return(true); - bool bValid = false; - QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); cFile* lpFile = sourceModel()->data(index0, Qt::UserRole+1).value();