From 4936d58092d923cfb2e0ce73579778de712620be Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 25 Nov 2010 01:23:48 +0100 Subject: [PATCH] Implement a custom FileSystemModel class derived from QFileSystemModel in order to avoid "+" button in front of folders without sub-dirs. --- LameXP.vcproj | 20 ++++++++++++----- gui/MainWindow.ui | 4 +++- gui/ProcessingDialog.ui | 4 +++- src/Config.h | 2 +- src/Dialog_MainWindow.cpp | 12 +++++----- src/Dialog_MainWindow.h | 6 ++--- src/Model_FileSystem.cpp | 47 +++++++++++++++++++++++++++++++++++++++ src/Model_FileSystem.h | 31 ++++++++++++++++++++++++++ 8 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 src/Model_FileSystem.cpp create mode 100644 src/Model_FileSystem.h diff --git a/LameXP.vcproj b/LameXP.vcproj index 64c5277d..5cc32d0e 100644 --- a/LameXP.vcproj +++ b/LameXP.vcproj @@ -350,6 +350,10 @@ RelativePath=".\src\Model_FileList.cpp" > + + @@ -435,7 +439,7 @@ @@ -445,7 +449,7 @@ @@ -455,7 +459,7 @@ @@ -748,6 +752,10 @@ /> + + @@ -1215,7 +1223,7 @@ @@ -1225,7 +1233,7 @@ @@ -1235,7 +1243,7 @@ diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index 112f830e..90d1c157 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -361,7 +361,7 @@ - Save output files to the same location where the input file is loacated + Save output files to the same location where the input file is located @@ -1348,6 +1348,8 @@ + + diff --git a/gui/ProcessingDialog.ui b/gui/ProcessingDialog.ui index af5e531e..236b5a56 100644 --- a/gui/ProcessingDialog.ui +++ b/gui/ProcessingDialog.ui @@ -182,7 +182,7 @@ - <b>Encoding Files</b><br>Your files are being encoded, please be pateint... + <b>Encoding Files</b><br>Your files are being encoded, please be patient... @@ -434,6 +434,8 @@ + + diff --git a/src/Config.h b/src/Config.h index 813275ad..d87a493f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 74 +#define VER_LAMEXP_BUILD 76 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 8547aa8e..eb286737 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -32,6 +32,7 @@ #include "Model_MetaInfo.h" #include "Model_Settings.h" #include "Model_FileList.h" +#include "Model_FileSystem.h" #include "Encoder_MP3.h" //Qt includes @@ -129,8 +130,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel *metaInfo, S connect(m_fileListModel, SIGNAL(modelReset()), this, SLOT(sourceModelChanged())); //Setup "Output" tab - m_fileSystemModel = new QFileSystemModel(); - m_fileSystemModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + m_fileSystemModel = new QFileSystemModelEx(); m_fileSystemModel->setRootPath(m_fileSystemModel->rootPath()); m_fileSystemModel->installEventFilter(this); outputFolderView->setModel(m_fileSystemModel); @@ -396,10 +396,10 @@ void MainWindow::resizeEvent(QResizeEvent *event) bool MainWindow::eventFilter(QObject *obj, QEvent *event) { - if(obj == m_fileSystemModel) + if(obj == m_fileSystemModel && QApplication::overrideCursor() == NULL) { QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - QTimer::singleShot(0, this, SLOT(restoreCursor())); + QTimer::singleShot(250, this, SLOT(restoreCursor())); } return false; @@ -763,7 +763,7 @@ void MainWindow::makeFolderButtonClicked(void) { ABORT_IF_BUSY; - QDir basePath(m_fileSystemModel->filePath(outputFolderView->currentIndex())); + QDir basePath(m_fileSystemModel->fileInfo(outputFolderView->currentIndex()).absoluteFilePath()); bool bApplied = true; QString folderName = QInputDialog::getText(this, "New Folder", "Enter the name of the new folder:", QLineEdit::Normal, "New folder", &bApplied, Qt::WindowStaysOnTopHint).simplified(); @@ -798,7 +798,7 @@ void MainWindow::makeFolderButtonClicked(void) } else { - QMessageBox::warning(this, "Failed to create folder", QString("The folder '%1' could not be created!").arg(newFolder)); + QMessageBox::warning(this, "Failed to create folder", QString("The new folder could not be created:
%1

Drive is read-only or insufficient access rights!").arg(basePath.absoluteFilePath(newFolder))); } } } diff --git a/src/Dialog_MainWindow.h b/src/Dialog_MainWindow.h index 87153907..cba8c17c 100644 --- a/src/Dialog_MainWindow.h +++ b/src/Dialog_MainWindow.h @@ -23,10 +23,8 @@ #include "../tmp/UIC_MainWindow.h" -//#include "Model_FileList.h" - //Class declarations -class QFileSystemModel; +class QFileSystemModelEx; class WorkingBanner; class MessageHandlerThread; class AudioFileModel; @@ -96,7 +94,7 @@ private: bool m_accepted; bool m_firstTimeShown; FileListModel *m_fileListModel; - QFileSystemModel *m_fileSystemModel; + QFileSystemModelEx *m_fileSystemModel; QActionGroup *m_tabActionGroup; QActionGroup *m_styleActionGroup; QButtonGroup *m_encoderButtonGroup; diff --git a/src/Model_FileSystem.cpp b/src/Model_FileSystem.cpp new file mode 100644 index 00000000..9e694d0d --- /dev/null +++ b/src/Model_FileSystem.cpp @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#include "Model_FileSystem.h" + +#include + +QFileSystemModelEx::QFileSystemModelEx() +: + QFileSystemModel() +{ + this->setFilter(QDir::Dirs | QDir::NoDotAndDotDot); +} + +bool QFileSystemModelEx::hasChildren(const QModelIndex &parent) const +{ + bool result = QFileSystemModel::hasChildren(parent); + + if(parent.isValid() && result) + { + QFileInfo fileInfo = QFileSystemModel::fileInfo(parent); + if(fileInfo.isDir()) + { + result = (QDir(fileInfo.absoluteFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot).count() > 0); + } + } + + return result; +} diff --git a/src/Model_FileSystem.h b/src/Model_FileSystem.h new file mode 100644 index 00000000..4e548cc6 --- /dev/null +++ b/src/Model_FileSystem.h @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2010 LoRd_MuldeR +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +class QFileSystemModelEx : public QFileSystemModel +{ +public: + QFileSystemModelEx(); + virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; +};