aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General/library/librarymodel.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-07 16:41:08 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2021-01-07 16:41:08 +0000
commit26c0acfe811b4494d4aeb0763362eedddcff4806 (patch)
tree6e28c7a890ac2e30165e4cbed4c5364ab5135960 /src/plugins/General/library/librarymodel.cpp
parent591632121a1e74e61a83c3a15e0909ef9e685ef8 (diff)
downloadqmmp-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/library/librarymodel.cpp')
-rw-r--r--src/plugins/General/library/librarymodel.cpp27
1 files changed, 22 insertions, 5 deletions
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;