From 2e5445390504a02b8993671f08697b0403dd4945 Mon Sep 17 00:00:00 2001 From: birkeh Date: Fri, 8 Nov 2019 13:54:04 +0100 Subject: [PATCH] initial commit --- cmainwindow.cpp | 46 ++++++++++++++++++++++++++++++++++------------ cmainwindow.h | 3 ++- cmainwindow.ui | 4 ++-- ctreeview.cpp | 4 +++- ctreeview.h | 2 +- 5 files changed, 42 insertions(+), 17 deletions(-) diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 236b375..5842002 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -20,11 +20,14 @@ #include #include +#include + cMainWindow::cMainWindow(cSplashScreen* lpSplashScreen, QWidget *parent) : QMainWindow(parent), ui(new Ui::cMainWindow), - m_lpSplashScreen(lpSplashScreen) + m_lpSplashScreen(lpSplashScreen), + m_working(false) { initUI(); createActions(); @@ -40,6 +43,13 @@ cMainWindow::~cMainWindow() void cMainWindow::closeEvent(QCloseEvent *event) { + if(m_working) + { + QMessageBox::information(this, tr("Close"), tr("Can't close, pictureConvert is working.")); + event->ignore(); + return; + } + QSettings settings; settings.setValue("main/width", QVariant::fromValue(size().width())); settings.setValue("main/height", QVariant::fromValue(size().height())); @@ -97,7 +107,7 @@ void cMainWindow::createActions() connect(ui->m_lpConvert, &QPushButton::clicked, this, &cMainWindow::onConvert); - connect(ui->m_lpFileList, &cTreeView::addEntry, this, &cMainWindow::onAddEntry); + connect(ui->m_lpFileList, &cTreeView::addEntrys, this, &cMainWindow::onAddEntrys); connect(ui->m_lpThumbnailSize, &QSlider::valueChanged, this, &cMainWindow::onThumbnailSize); } @@ -257,8 +267,7 @@ void cMainWindow::onAddFile() path = info.path(); settings.setValue("import/oldPath", QVariant::fromValue(path)); - for(int i = 0;i < fileList.count();i++) - onAddEntry(fileList[i]); + onAddEntrys(fileList); } void cMainWindow::onAddFolder() @@ -290,10 +299,14 @@ void cMainWindow::onAddFolder() settings.setValue("import/oldPath", QVariant::fromValue(path)); settings.setValue("import/recursive", QVariant::fromValue(checked)); + m_working = true; + addPath(path, checked); for(int i = 0;i < m_lpFileListModel->columnCount();i++) ui->m_lpFileList->resizeColumnToContents(i); + + m_working = false; } void cMainWindow::onRemoveSelected() @@ -308,22 +321,31 @@ void cMainWindow::onClearList() m_lpFileListModel->setHorizontalHeaderLabels(headerLabels); } -void cMainWindow::onAddEntry(const QString& file) +void cMainWindow::onAddEntrys(const QStringList& fileList) { - QFileInfo fileInfo(file); + m_working = true; - if(fileInfo.isDir()) - addPath(file); - else + for(int i = 0;i < fileList.count();i++) { - QMimeType mimeType = m_mimeDB.mimeTypeForFile(file); + QString file = fileList[i]; - if(mimeType.name().startsWith("image")) - addFile(file); + QFileInfo fileInfo(file); + + if(fileInfo.isDir()) + addPath(file); + else + { + QMimeType mimeType = m_mimeDB.mimeTypeForFile(file); + + if(mimeType.name().startsWith("image")) + addFile(file); + } } for(int i = 0;i < m_lpFileListModel->columnCount();i++) ui->m_lpFileList->resizeColumnToContents(i); + + m_working = false; } void cMainWindow::addPath(const QString& path, bool recursive) diff --git a/cmainwindow.h b/cmainwindow.h index 9c67ddf..47a8a9b 100644 --- a/cmainwindow.h +++ b/cmainwindow.h @@ -42,6 +42,7 @@ private: QMimeDatabase m_mimeDB; QList m_imageFormats; + bool m_working; void initUI(); void createActions(); @@ -61,7 +62,7 @@ private slots: void onConvert(); void onThumbnailSize(int size); - void onAddEntry(const QString& file); + void onAddEntrys(const QStringList& fileList); protected: void closeEvent(QCloseEvent* event); diff --git a/cmainwindow.ui b/cmainwindow.ui index f428d0c..8a5a071 100644 --- a/cmainwindow.ui +++ b/cmainwindow.ui @@ -157,7 +157,7 @@ - + 0 @@ -167,7 +167,7 @@ - + diff --git a/ctreeview.cpp b/ctreeview.cpp index 3e5fbdd..3301b42 100644 --- a/ctreeview.cpp +++ b/ctreeview.cpp @@ -31,7 +31,9 @@ void cTreeView::dropEvent(QDropEvent* event) QList urlList = mimeData->urls(); for(int i = 0; i < urlList.size(); i++) - emit addEntry(urlList[i].toLocalFile()); + pathList.append(urlList[i].toLocalFile()); + + emit addEntrys(pathList); } event->acceptProposedAction(); diff --git a/ctreeview.h b/ctreeview.h index fe9224e..af01e02 100644 --- a/ctreeview.h +++ b/ctreeview.h @@ -26,7 +26,7 @@ protected: private: signals: - void addEntry(const QString& path); + void addEntrys(const QStringList& fileList); }; Q_DECLARE_METATYPE(cTreeView*)