diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-01-07 16:41:08 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2021-01-07 16:41:08 +0000 |
| commit | 26c0acfe811b4494d4aeb0763362eedddcff4806 (patch) | |
| tree | 6e28c7a890ac2e30165e4cbed4c5364ab5135960 /src/plugins/General | |
| parent | 591632121a1e74e61a83c3a15e0909ef9e685ef8 (diff) | |
| download | qmmp-26c0acfe811b4494d4aeb0763362eedddcff4806.tar.gz qmmp-26c0acfe811b4494d4aeb0763362eedddcff4806.tar.bz2 qmmp-26c0acfe811b4494d4aeb0763362eedddcff4806.zip | |
library: fixed some issues
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9618 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General')
| -rw-r--r-- | src/plugins/General/library/library.cpp | 35 | ||||
| -rw-r--r-- | src/plugins/General/library/library.h | 12 | ||||
| -rw-r--r-- | src/plugins/General/library/libraryfactory.cpp | 5 | ||||
| -rw-r--r-- | src/plugins/General/library/libraryfactory.h | 2 | ||||
| -rw-r--r-- | src/plugins/General/library/librarymodel.cpp | 27 | ||||
| -rw-r--r-- | src/plugins/General/library/librarywidget.cpp | 5 | ||||
| -rw-r--r-- | src/plugins/General/library/librarywidget.h | 1 |
7 files changed, 68 insertions, 19 deletions
diff --git a/src/plugins/General/library/library.cpp b/src/plugins/General/library/library.cpp index 7f4db5f82..e38309398 100644 --- a/src/plugins/General/library/library.cpp +++ b/src/plugins/General/library/library.cpp @@ -32,17 +32,20 @@ #include <QHash> #include <QtConcurrent> #include <QtDebug> +#include <algorithm> #include <qmmp/qmmp.h> #include <qmmp/metadatamanager.h> #include <qmmpui/uihelper.h> #include "librarymodel.h" +#include "librarywidget.h" #include "library.h" #define CONNECTION_NAME "qmmp_library" -Library::Library(QObject *parent) : QObject(parent) +Library::Library(QPointer<LibraryWidget> *libraryWidget, QObject *parent) : + QObject(parent), + m_libraryWidget(libraryWidget) { - qDebug() << Q_FUNC_INFO; { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); if(db.isValid() && !db.isOpen()) @@ -63,6 +66,14 @@ Library::Library(QObject *parent) : QObject(parent) QAction *action = new QAction(QIcon::fromTheme("view-refresh"), tr("Update library"), this); UiHelper::instance()->addAction(action, UiHelper::TOOLS_MENU); connect(action, SIGNAL(triggered()), SLOT(startDirectoryScanning())); + + connect(&m_watcher, &QFutureWatcher<bool>::finished, [=] { + if(!m_libraryWidget->isNull()) + { + m_libraryWidget->data()->setEnabled(true); + m_libraryWidget->data()->refresh(); + } + }); } Library::~Library() @@ -80,6 +91,11 @@ Library::~Library() } } +bool Library::isRunning() const +{ + return m_future.isRunning(); +} + void Library::showLibraryWindow() { /*if(!m_historyWindow) @@ -90,13 +106,14 @@ void Library::showLibraryWindow() void Library::startDirectoryScanning() { - qDebug() << Q_FUNC_INFO << m_dirs; - if(m_future.isRunning()) return; m_filters = MetaDataManager::instance()->nameFilters(); m_future = QtConcurrent::run(this, &Library::scanDirectories, m_dirs); + m_watcher.setFuture(m_future); + if(!m_libraryWidget->isNull()) + m_libraryWidget->data()->setEnabled(false); } bool Library::createTables() @@ -195,7 +212,6 @@ QByteArray Library::serializeAudioInfo(const QMap<Qmmp::TrackProperty, QString> bool Library::scanDirectories(const QStringList &paths) { - qDebug() << Q_FUNC_INFO << paths; m_stopped = false; { @@ -218,12 +234,12 @@ bool Library::scanDirectories(const QStringList &paths) } } - removeInvalid(); + removeMissingFiles(paths); + db.close(); } QSqlDatabase::removeDatabase(CONNECTION_NAME); qDebug("Library: directory scan finished"); - return true; } @@ -285,7 +301,7 @@ void Library::addDirectory(const QString &s) } } -void Library::removeInvalid() +void Library::removeMissingFiles(const QStringList &paths) { QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME); if(!db.isOpen()) @@ -308,7 +324,8 @@ void Library::removeInvalid() previousPath = path; - if(!QFile::exists(path)) + if(!QFile::exists(path) || //remove missing or disabled file paths + !std::any_of(paths.cbegin(), paths.cend(), [path](const QString &p){ return path.startsWith(p); } )) { qDebug("Library: removing '%s' from library", qPrintable(path)); QSqlQuery rmQuery(db); diff --git a/src/plugins/General/library/library.h b/src/plugins/General/library/library.h index 516698fd2..fec9508a5 100644 --- a/src/plugins/General/library/library.h +++ b/src/plugins/General/library/library.h @@ -25,6 +25,7 @@ #include <QElapsedTimer> #include <QPointer> #include <QFuture> +#include <QFutureWatcher> #include <QStringList> #include <qmmp/trackinfo.h> #include <qmmp/qmmp.h> @@ -32,15 +33,17 @@ class QFileInfo; class SoundCore; class PlayListTrack; -//class HistoryWindow; +class LibraryWidget; class Library : public QObject { Q_OBJECT public: - explicit Library(QObject *parent = nullptr); + explicit Library(QPointer<LibraryWidget> *libraryWidget, QObject *parent = nullptr); ~Library(); + bool isRunning() const; + private slots: void showLibraryWindow(); @@ -53,14 +56,15 @@ private: QByteArray serializeAudioInfo(const QMap<Qmmp::TrackProperty, QString> &properties); bool scanDirectories(const QStringList &paths); void addDirectory(const QString &s); - void removeInvalid(); + void removeMissingFiles(const QStringList &paths); bool checkFile(const QFileInfo &info); void removeIgnoredTracks(QList<TrackInfo *> *tracks, const QStringList &ignoredPaths); - QFuture<bool> m_future; QStringList m_filters, m_dirs; bool m_stopped = false; + QPointer<LibraryWidget> *m_libraryWidget; + QFutureWatcher<bool> m_watcher; }; diff --git a/src/plugins/General/library/libraryfactory.cpp b/src/plugins/General/library/libraryfactory.cpp index 0948c2419..b19b5a709 100644 --- a/src/plugins/General/library/libraryfactory.cpp +++ b/src/plugins/General/library/libraryfactory.cpp @@ -41,7 +41,8 @@ GeneralProperties LibraryFactory::properties() const QObject *LibraryFactory::create(QObject *parent) { - return new Library(parent); + m_library = new Library(&m_libraryWidget, parent); + return m_library; } QWidget *LibraryFactory::createWidget(int id, QWidget *parent) @@ -49,6 +50,8 @@ QWidget *LibraryFactory::createWidget(int id, QWidget *parent) if(id == LIBRARY_WIDGET) { m_libraryWidget = new LibraryWidget(false, parent); + if(!m_library.isNull() && m_library->isRunning()) + m_libraryWidget->setEnabled(false); return m_libraryWidget; } return nullptr; diff --git a/src/plugins/General/library/libraryfactory.h b/src/plugins/General/library/libraryfactory.h index ab2e4ef6b..cb10bd09a 100644 --- a/src/plugins/General/library/libraryfactory.h +++ b/src/plugins/General/library/libraryfactory.h @@ -28,6 +28,7 @@ #include <qmmpui/generalfactory.h> class LibraryWidget; +class Library; /** @author Ilya Kotov <forkotov02@ya.ru> @@ -52,6 +53,7 @@ private: }; QPointer<LibraryWidget> m_libraryWidget; + QPointer<Library> m_library; }; #endif // LIBRARYFACTORY_H diff --git a/src/plugins/General/library/librarymodel.cpp b/src/plugins/General/library/librarymodel.cpp index 511927391..ca42b3ef0 100644 --- a/src/plugins/General/library/librarymodel.cpp +++ b/src/plugins/General/library/librarymodel.cpp @@ -26,6 +26,8 @@ #include <qmmp/qmmp.h> #include "librarymodel.h" +#define CONNECTION_NAME "qmmp_library_view" + class LibraryTreeItem { public: @@ -59,6 +61,12 @@ LibraryModel::LibraryModel(QObject *parent) : QAbstractItemModel(parent) LibraryModel::~LibraryModel() { delete m_rootItem; + + if(QSqlDatabase::contains(CONNECTION_NAME)) + { + QSqlDatabase::database(CONNECTION_NAME).close(); + QSqlDatabase::removeDatabase(CONNECTION_NAME); + } } Qt::ItemFlags LibraryModel::flags(const QModelIndex &index) const @@ -113,7 +121,7 @@ void LibraryModel::fetchMore(const QModelIndex &parent) LibraryTreeItem *parentItem = static_cast<LibraryTreeItem *>(parent.internalPointer()); - QSqlDatabase db = QSqlDatabase::database("qmmp_library_1"); + QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME); if(!db.isOpen()) return; @@ -225,9 +233,18 @@ void LibraryModel::refresh() beginResetModel(); m_rootItem->clear(); - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "qmmp_library_1"); - db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); - db.open(); + QSqlDatabase db; + + if(QSqlDatabase::contains(CONNECTION_NAME)) + { + db = QSqlDatabase::database(CONNECTION_NAME); + } + else + { + db = QSqlDatabase::addDatabase("QSQLITE", CONNECTION_NAME); + db.setDatabaseName(Qmmp::configDir() + "/" + "library.sqlite"); + db.open(); + } if(!db.isOpen()) { @@ -254,7 +271,7 @@ void LibraryModel::refresh() QList<QUrl> LibraryModel::getUrls(const QModelIndex &index) const { - QSqlDatabase db = QSqlDatabase::database("qmmp_library_1"); + QSqlDatabase db = QSqlDatabase::database(CONNECTION_NAME); QList<QUrl> urls; if(!db.isOpen()) return urls; diff --git a/src/plugins/General/library/librarywidget.cpp b/src/plugins/General/library/librarywidget.cpp index fae3ea218..ab7664d00 100644 --- a/src/plugins/General/library/librarywidget.cpp +++ b/src/plugins/General/library/librarywidget.cpp @@ -47,3 +47,8 @@ LibraryWidget::~LibraryWidget() { delete m_ui; } + +void LibraryWidget::refresh() +{ + m_model->refresh(); +} diff --git a/src/plugins/General/library/librarywidget.h b/src/plugins/General/library/librarywidget.h index e67150015..8a9db9288 100644 --- a/src/plugins/General/library/librarywidget.h +++ b/src/plugins/General/library/librarywidget.h @@ -35,6 +35,7 @@ class LibraryWidget : public QWidget public: explicit LibraryWidget(bool dialog, QWidget *parent = nullptr); ~LibraryWidget(); + void refresh(); private: Ui::LibraryWidget *m_ui; |
