Renamed database class to qlistdb in preparation to create generic database class.
This commit is contained in:
		
							
								
								
									
										12
									
								
								qcma.pro
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								qcma.pro
									
									
									
									
									
								
							@@ -18,7 +18,6 @@ TEMPLATE = app
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
SOURCES += src/main.cpp \
 | 
					SOURCES += src/main.cpp \
 | 
				
			||||||
    src/capability.cpp \
 | 
					    src/capability.cpp \
 | 
				
			||||||
    src/database.cpp \
 | 
					 | 
				
			||||||
    src/cmaobject.cpp \
 | 
					    src/cmaobject.cpp \
 | 
				
			||||||
    src/cmarootobject.cpp \
 | 
					    src/cmarootobject.cpp \
 | 
				
			||||||
    src/utils.cpp \
 | 
					    src/utils.cpp \
 | 
				
			||||||
@@ -33,18 +32,18 @@ SOURCES += src/main.cpp \
 | 
				
			|||||||
    src/filterlineedit.cpp \
 | 
					    src/filterlineedit.cpp \
 | 
				
			||||||
    src/dds.cpp \
 | 
					    src/dds.cpp \
 | 
				
			||||||
    src/sqlitedb.cpp \
 | 
					    src/sqlitedb.cpp \
 | 
				
			||||||
 | 
					    src/httpdownloader.cpp \
 | 
				
			||||||
 | 
					    src/qlistdb.cpp \
 | 
				
			||||||
# forms
 | 
					# forms
 | 
				
			||||||
    src/forms/backupitem.cpp \
 | 
					    src/forms/backupitem.cpp \
 | 
				
			||||||
    src/forms/backupmanagerform.cpp \
 | 
					    src/forms/backupmanagerform.cpp \
 | 
				
			||||||
    src/forms/configwidget.cpp \
 | 
					    src/forms/configwidget.cpp \
 | 
				
			||||||
    src/forms/confirmdialog.cpp \
 | 
					    src/forms/confirmdialog.cpp \
 | 
				
			||||||
    src/forms/pinform.cpp \
 | 
					    src/forms/pinform.cpp \
 | 
				
			||||||
    src/forms/progressform.cpp \
 | 
					    src/forms/progressform.cpp
 | 
				
			||||||
    src/httpdownloader.cpp
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
HEADERS += \
 | 
					HEADERS += \
 | 
				
			||||||
    src/capability.h \
 | 
					    src/capability.h \
 | 
				
			||||||
    src/database.h \
 | 
					 | 
				
			||||||
    src/cmaobject.h \
 | 
					    src/cmaobject.h \
 | 
				
			||||||
    src/cmarootobject.h \
 | 
					    src/cmarootobject.h \
 | 
				
			||||||
    src/utils.h \
 | 
					    src/utils.h \
 | 
				
			||||||
@@ -59,14 +58,15 @@ HEADERS += \
 | 
				
			|||||||
    src/filterlineedit.h \
 | 
					    src/filterlineedit.h \
 | 
				
			||||||
    src/dds.h \
 | 
					    src/dds.h \
 | 
				
			||||||
    src/sqlitedb.h \
 | 
					    src/sqlitedb.h \
 | 
				
			||||||
 | 
					    src/httpdownloader.h \
 | 
				
			||||||
 | 
					    src/qlistdb.h \
 | 
				
			||||||
# forms
 | 
					# forms
 | 
				
			||||||
    src/forms/backupitem.h \
 | 
					    src/forms/backupitem.h \
 | 
				
			||||||
    src/forms/backupmanagerform.h \
 | 
					    src/forms/backupmanagerform.h \
 | 
				
			||||||
    src/forms/configwidget.h \
 | 
					    src/forms/configwidget.h \
 | 
				
			||||||
    src/forms/confirmdialog.h \
 | 
					    src/forms/confirmdialog.h \
 | 
				
			||||||
    src/forms/pinform.h \
 | 
					    src/forms/pinform.h \
 | 
				
			||||||
    src/forms/progressform.h \
 | 
					    src/forms/progressform.h
 | 
				
			||||||
    src/httpdownloader.h
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
FORMS += \
 | 
					FORMS += \
 | 
				
			||||||
    src/forms/configwidget.ui \
 | 
					    src/forms/configwidget.ui \
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
#ifndef CLIENTMANAGER_H
 | 
					#ifndef CLIENTMANAGER_H
 | 
				
			||||||
#define CLIENTMANAGER_H
 | 
					#define CLIENTMANAGER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "database.h"
 | 
					#include "qlistdb.h"
 | 
				
			||||||
#include "forms/pinform.h"
 | 
					#include "forms/pinform.h"
 | 
				
			||||||
#include "forms/progressform.h"
 | 
					#include "forms/progressform.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -37,7 +37,7 @@ public:
 | 
				
			|||||||
    void start();
 | 
					    void start();
 | 
				
			||||||
    void stop();
 | 
					    void stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Database db;
 | 
					    QListDB db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    int thread_count;
 | 
					    int thread_count;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
#ifndef CMACLIENT_H
 | 
					#ifndef CMACLIENT_H
 | 
				
			||||||
#define CMACLIENT_H
 | 
					#define CMACLIENT_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "database.h"
 | 
					#include "qlistdb.h"
 | 
				
			||||||
#include "cmaevent.h"
 | 
					#include "cmaevent.h"
 | 
				
			||||||
#include "cmaobject.h"
 | 
					#include "cmaobject.h"
 | 
				
			||||||
#include "cmabroadcast.h"
 | 
					#include "cmabroadcast.h"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <inttypes.h>
 | 
					#include <inttypes.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Database *CmaEvent::db = NULL;
 | 
					QListDB *CmaEvent::db = NULL;
 | 
				
			||||||
QFile *CmaEvent::m_file = NULL;
 | 
					QFile *CmaEvent::m_file = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
metadata_t CmaEvent::g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{17, 240, 136, 0, 1, 1.0f, 2}}, NULL};
 | 
					metadata_t CmaEvent::g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{17, 240, 136, 0, 1, 1.0f, 2}}, NULL};
 | 
				
			||||||
@@ -412,7 +412,7 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    qDebug("Searching object with OHFI %d", ohfi);
 | 
					    qDebug("Searching object with OHFI %d", ohfi);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Database::find_data iters;
 | 
					    QListDB::find_data iters;
 | 
				
			||||||
    if(!db->find(ohfi, iters)) {
 | 
					    if(!db->find(ohfi, iters)) {
 | 
				
			||||||
        qWarning("Failed to find OHFI %d", ohfi);
 | 
					        qWarning("Failed to find OHFI %d", ohfi);
 | 
				
			||||||
        VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
 | 
					        VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
 | 
				
			||||||
@@ -816,7 +816,7 @@ void CmaEvent::vitaEventOperateObject(vita_event_t *event, int eventId)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        //rename the current object
 | 
					        //rename the current object
 | 
				
			||||||
        root->rename(operateobject.title);
 | 
					        root->rename(operateobject.title);
 | 
				
			||||||
        Database::find_data iters;
 | 
					        QListDB::find_data iters;
 | 
				
			||||||
        db->find(root->metadata.ohfi, iters);
 | 
					        db->find(root->metadata.ohfi, iters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // rename the rest of the list only if has the renamed parent in some part of the chain
 | 
					        // rename the rest of the list only if has the renamed parent in some part of the chain
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,7 @@
 | 
				
			|||||||
#define CMAEVENT_H
 | 
					#define CMAEVENT_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "cmaobject.h"
 | 
					#include "cmaobject.h"
 | 
				
			||||||
#include "database.h"
 | 
					#include "qlistdb.h"
 | 
				
			||||||
#include "httpdownloader.h"
 | 
					#include "httpdownloader.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QNetworkReply>
 | 
					#include <QNetworkReply>
 | 
				
			||||||
@@ -39,7 +39,7 @@ public:
 | 
				
			|||||||
    void vitaEventCancelTask(vita_event_t *event, int eventId);
 | 
					    void vitaEventCancelTask(vita_event_t *event, int eventId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // don't make the db reference static
 | 
					    // don't make the db reference static
 | 
				
			||||||
    static Database *db;
 | 
					    static QListDB *db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    uint16_t processAllObjects(CMAObject *parent, uint32_t handle);
 | 
					    uint16_t processAllObjects(CMAObject *parent, uint32_t handle);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@
 | 
				
			|||||||
#ifndef BACKUPMANAGERFORM_H
 | 
					#ifndef BACKUPMANAGERFORM_H
 | 
				
			||||||
#define BACKUPMANAGERFORM_H
 | 
					#define BACKUPMANAGERFORM_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "database.h"
 | 
					#include "qlistdb.h"
 | 
				
			||||||
#include "backupitem.h"
 | 
					#include "backupitem.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QWidget>
 | 
					#include <QWidget>
 | 
				
			||||||
@@ -37,7 +37,7 @@ public:
 | 
				
			|||||||
    explicit BackupManagerForm(QWidget *parent = 0);
 | 
					    explicit BackupManagerForm(QWidget *parent = 0);
 | 
				
			||||||
    ~BackupManagerForm();
 | 
					    ~BackupManagerForm();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Database *db;
 | 
					    QListDB *db;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void setupForm();
 | 
					    void setupForm();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "utils.h"
 | 
					#include "utils.h"
 | 
				
			||||||
#include "database.h"
 | 
					#include "qlistdb.h"
 | 
				
			||||||
#include "cmaobject.h"
 | 
					#include "cmaobject.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDir>
 | 
					#include <QDir>
 | 
				
			||||||
@@ -28,7 +28,7 @@
 | 
				
			|||||||
#include <QThread>
 | 
					#include <QThread>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Database::Database() :
 | 
					QListDB::QListDB() :
 | 
				
			||||||
    mutex(QMutex::Recursive)
 | 
					    mutex(QMutex::Recursive)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QString uuid = QSettings().value("lastAccountId", "ffffffffffffffff").toString();
 | 
					    QString uuid = QSettings().value("lastAccountId", "ffffffffffffffff").toString();
 | 
				
			||||||
@@ -43,7 +43,7 @@ Database::Database() :
 | 
				
			|||||||
    connect(timer, SIGNAL(timeout()), this, SLOT(process()));
 | 
					    connect(timer, SIGNAL(timeout()), this, SLOT(process()));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Database::~Database()
 | 
					QListDB::~QListDB()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    destroy();
 | 
					    destroy();
 | 
				
			||||||
    timer->stop();
 | 
					    timer->stop();
 | 
				
			||||||
@@ -53,13 +53,13 @@ Database::~Database()
 | 
				
			|||||||
    delete thread;
 | 
					    delete thread;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::setUUID(const QString uuid)
 | 
					void QListDB::setUUID(const QString uuid)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CMARootObject::uuid = uuid;
 | 
					    CMARootObject::uuid = uuid;
 | 
				
			||||||
    QSettings().setValue("lastAccountId", uuid);
 | 
					    QSettings().setValue("lastAccountId", uuid);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::reload(bool &prepared)
 | 
					bool QListDB::reload(bool &prepared)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(mutex.tryLock()) {
 | 
					    if(mutex.tryLock()) {
 | 
				
			||||||
        if(CMARootObject::uuid != "ffffffffffffffff") {
 | 
					        if(CMARootObject::uuid != "ffffffffffffffff") {
 | 
				
			||||||
@@ -76,7 +76,7 @@ bool Database::reload(bool &prepared)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::process()
 | 
					void QListDB::process()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    destroy();
 | 
					    destroy();
 | 
				
			||||||
    cancel_operation = false;
 | 
					    cancel_operation = false;
 | 
				
			||||||
@@ -90,19 +90,19 @@ void Database::process()
 | 
				
			|||||||
    mutex.unlock();
 | 
					    mutex.unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::cancelOperation()
 | 
					void QListDB::cancelOperation()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&cancel);
 | 
					    QMutexLocker locker(&cancel);
 | 
				
			||||||
    cancel_operation = true;
 | 
					    cancel_operation = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::continueOperation()
 | 
					bool QListDB::continueOperation()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&cancel);
 | 
					    QMutexLocker locker(&cancel);
 | 
				
			||||||
    return !cancel_operation;
 | 
					    return !cancel_operation;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::create()
 | 
					int QListDB::create()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int total_objects = 0;
 | 
					    int total_objects = 0;
 | 
				
			||||||
    //QMutexLocker locker(&mutex);
 | 
					    //QMutexLocker locker(&mutex);
 | 
				
			||||||
@@ -153,7 +153,7 @@ int Database::create()
 | 
				
			|||||||
    return total_objects;
 | 
					    return total_objects;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CMAObject *Database::getParent(CMAObject *last_dir, const QString ¤t_path)
 | 
					CMAObject *QListDB::getParent(CMAObject *last_dir, const QString ¤t_path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    while(last_dir && current_path != last_dir->path) {
 | 
					    while(last_dir && current_path != last_dir->path) {
 | 
				
			||||||
        last_dir = last_dir->parent;
 | 
					        last_dir = last_dir->parent;
 | 
				
			||||||
@@ -162,7 +162,7 @@ CMAObject *Database::getParent(CMAObject *last_dir, const QString ¤t_path)
 | 
				
			|||||||
    return last_dir;
 | 
					    return last_dir;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::scanRootDirectory(root_list &list, int ohfi_type)
 | 
					int QListDB::scanRootDirectory(root_list &list, int ohfi_type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int file_type = -1;
 | 
					    int file_type = -1;
 | 
				
			||||||
    int total_objects = 0;
 | 
					    int total_objects = 0;
 | 
				
			||||||
@@ -201,7 +201,7 @@ int Database::scanRootDirectory(root_list &list, int ohfi_type)
 | 
				
			|||||||
    return total_objects;
 | 
					    return total_objects;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::recursiveScanRootDirectory(root_list &list, CMAObject *parent, int ohfi_type)
 | 
					int QListDB::recursiveScanRootDirectory(root_list &list, CMAObject *parent, int ohfi_type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int file_type = -1;
 | 
					    int file_type = -1;
 | 
				
			||||||
    int total_objects = 0;
 | 
					    int total_objects = 0;
 | 
				
			||||||
@@ -236,7 +236,7 @@ int Database::recursiveScanRootDirectory(root_list &list, CMAObject *parent, int
 | 
				
			|||||||
    return total_objects;
 | 
					    return total_objects;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::destroy()
 | 
					void QListDB::destroy()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    //QMutexLocker locker(&mutex);
 | 
					    //QMutexLocker locker(&mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -249,7 +249,7 @@ void Database::destroy()
 | 
				
			|||||||
    object_list.clear();
 | 
					    object_list.clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::removeInternal(root_list &list, const CMAObject *obj)
 | 
					bool QListDB::removeInternal(root_list &list, const CMAObject *obj)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    bool found = false;
 | 
					    bool found = false;
 | 
				
			||||||
    QList<CMAObject *>::iterator it = list.begin();
 | 
					    QList<CMAObject *>::iterator it = list.begin();
 | 
				
			||||||
@@ -270,7 +270,7 @@ bool Database::removeInternal(root_list &list, const CMAObject *obj)
 | 
				
			|||||||
    return found;
 | 
					    return found;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::remove(const CMAObject *obj, int ohfi_root)
 | 
					bool QListDB::remove(const CMAObject *obj, int ohfi_root)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -286,12 +286,12 @@ bool Database::remove(const CMAObject *obj, int ohfi_root)
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::lessThanComparator(const CMAObject *a, const CMAObject *b)
 | 
					bool QListDB::lessThanComparator(const CMAObject *a, const CMAObject *b)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return a->metadata.ohfi < b->metadata.ohfi;
 | 
					    return a->metadata.ohfi < b->metadata.ohfi;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::hasFilter(const CMARootObject *object,int ohfi)
 | 
					bool QListDB::hasFilter(const CMARootObject *object,int ohfi)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    for(int i = 0; i < object->num_filters; i++) {
 | 
					    for(int i = 0; i < object->num_filters; i++) {
 | 
				
			||||||
        if(object->filters[i].ohfi == ohfi) {
 | 
					        if(object->filters[i].ohfi == ohfi) {
 | 
				
			||||||
@@ -301,20 +301,20 @@ bool Database::hasFilter(const CMARootObject *object,int ohfi)
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::findInternal(const root_list &list, int ohfi, find_data &data)
 | 
					bool QListDB::findInternal(const root_list &list, int ohfi, find_data &data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(hasFilter(static_cast<CMARootObject *>(list.first()), ohfi)) {
 | 
					    if(hasFilter(static_cast<CMARootObject *>(list.first()), ohfi)) {
 | 
				
			||||||
        data.it = list.begin();
 | 
					        data.it = list.begin();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        CMAObject obj;
 | 
					        CMAObject obj;
 | 
				
			||||||
        obj.setOhfi(ohfi);
 | 
					        obj.setOhfi(ohfi);
 | 
				
			||||||
        data.it = qBinaryFind(list.begin(), list.end(), &obj, Database::lessThanComparator);
 | 
					        data.it = qBinaryFind(list.begin(), list.end(), &obj, QListDB::lessThanComparator);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    data.end = list.end();
 | 
					    data.end = list.end();
 | 
				
			||||||
    return data.it != data.end;
 | 
					    return data.it != data.end;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Database::find(int ohfi, Database::find_data &data)
 | 
					bool QListDB::find(int ohfi, QListDB::find_data &data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -326,7 +326,7 @@ bool Database::find(int ohfi, Database::find_data &data)
 | 
				
			|||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::append(int parent_ohfi, CMAObject *object)
 | 
					void QListDB::append(int parent_ohfi, CMAObject *object)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
    CMAObject parent;
 | 
					    CMAObject parent;
 | 
				
			||||||
@@ -334,7 +334,7 @@ void Database::append(int parent_ohfi, CMAObject *object)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    for(map_list::iterator root = object_list.begin(); root != object_list.end(); ++root) {
 | 
					    for(map_list::iterator root = object_list.begin(); root != object_list.end(); ++root) {
 | 
				
			||||||
        root_list *cat_list = &(*root);
 | 
					        root_list *cat_list = &(*root);
 | 
				
			||||||
        root_list::const_iterator it = qBinaryFind(cat_list->begin(), cat_list->end(), &parent, Database::lessThanComparator);
 | 
					        root_list::const_iterator it = qBinaryFind(cat_list->begin(), cat_list->end(), &parent, QListDB::lessThanComparator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(it != cat_list->end()) {
 | 
					        if(it != cat_list->end()) {
 | 
				
			||||||
            cat_list->append(object);
 | 
					            cat_list->append(object);
 | 
				
			||||||
@@ -343,14 +343,14 @@ void Database::append(int parent_ohfi, CMAObject *object)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CMAObject *Database::ohfiToObject(int ohfi)
 | 
					CMAObject *QListDB::ohfiToObject(int ohfi)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
    find_data data;
 | 
					    find_data data;
 | 
				
			||||||
    return find(ohfi, data) ? *data.it : NULL;
 | 
					    return find(ohfi, data) ? *data.it : NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CMAObject *Database::pathToObjectInternal(const root_list &list, const char *path)
 | 
					CMAObject *QListDB::pathToObjectInternal(const root_list &list, const char *path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // skip the first element since is the root element
 | 
					    // skip the first element since is the root element
 | 
				
			||||||
    root_list::const_iterator skipped_first = ++list.begin();
 | 
					    root_list::const_iterator skipped_first = ++list.begin();
 | 
				
			||||||
@@ -363,7 +363,7 @@ CMAObject *Database::pathToObjectInternal(const root_list &list, const char *pat
 | 
				
			|||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CMAObject *Database::pathToObject(const char *path, int ohfiRoot)
 | 
					CMAObject *QListDB::pathToObject(const char *path, int ohfiRoot)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -381,7 +381,7 @@ CMAObject *Database::pathToObject(const char *path, int ohfiRoot)
 | 
				
			|||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::acceptFilteredObject(const CMAObject *parent, const CMAObject *current, int type)
 | 
					int QListDB::acceptFilteredObject(const CMAObject *parent, const CMAObject *current, int type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
    int result = 0;
 | 
					    int result = 0;
 | 
				
			||||||
@@ -413,7 +413,7 @@ int Database::acceptFilteredObject(const CMAObject *parent, const CMAObject *cur
 | 
				
			|||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Database::dumpMetadataList(const metadata_t *p_head)
 | 
					void QListDB::dumpMetadataList(const metadata_t *p_head)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    while(p_head) {
 | 
					    while(p_head) {
 | 
				
			||||||
        qDebug("Metadata: %s with OHFI %d", p_head->name, p_head->ohfi);
 | 
					        qDebug("Metadata: %s with OHFI %d", p_head->name, p_head->ohfi);
 | 
				
			||||||
@@ -421,7 +421,7 @@ void Database::dumpMetadataList(const metadata_t *p_head)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Database::filterObjects(int ohfiParent, metadata_t **p_head, int index, int max_number)
 | 
					int QListDB::filterObjects(int ohfiParent, metadata_t **p_head, int index, int max_number)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QMutexLocker locker(&mutex);
 | 
					    QMutexLocker locker(&mutex);
 | 
				
			||||||
    CMARootObject *parent = static_cast<CMARootObject *>(ohfiToObject(ohfiParent));
 | 
					    CMARootObject *parent = static_cast<CMARootObject *>(ohfiToObject(ohfiParent));
 | 
				
			||||||
@@ -17,8 +17,8 @@
 | 
				
			|||||||
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef DATABASE_H
 | 
					#ifndef QLISTDB_H
 | 
				
			||||||
#define DATABASE_H
 | 
					#define QLISTDB_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "cmarootobject.h"
 | 
					#include "cmarootobject.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,7 +30,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <vitamtp.h>
 | 
					#include <vitamtp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Database : public QObject
 | 
					class QListDB : public QObject
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Q_OBJECT
 | 
					    Q_OBJECT
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
@@ -39,8 +39,8 @@ public:
 | 
				
			|||||||
        QList<CMAObject *>::const_iterator end;
 | 
					        QList<CMAObject *>::const_iterator end;
 | 
				
			||||||
    } find_data;
 | 
					    } find_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    explicit Database();
 | 
					    explicit QListDB();
 | 
				
			||||||
    ~Database();
 | 
					    ~QListDB();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool reload(bool &prepared);
 | 
					    bool reload(bool &prepared);
 | 
				
			||||||
    void setUUID(const QString uuid);
 | 
					    void setUUID(const QString uuid);
 | 
				
			||||||
@@ -97,4 +97,4 @@ public slots:
 | 
				
			|||||||
    void cancelOperation();
 | 
					    void cancelOperation();
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // DATABASE_H
 | 
					#endif // QLISTDB_H
 | 
				
			||||||
@@ -156,12 +156,14 @@ bool SQLiteDB::initialize()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    for(unsigned int i = 0; i < sizeof(table_list) / sizeof(const char *); i++) {
 | 
					    for(unsigned int i = 0; i < sizeof(table_list) / sizeof(const char *); i++) {
 | 
				
			||||||
        if(!query.exec(table_list[i])) {
 | 
					        if(!query.exec(table_list[i])) {
 | 
				
			||||||
 | 
					            qDebug() << query.lastError();
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for(unsigned int i = 0; i < sizeof(trigger_list) / sizeof(const char *); i++) {
 | 
					    for(unsigned int i = 0; i < sizeof(trigger_list) / sizeof(const char *); i++) {
 | 
				
			||||||
        if(!query.exec(trigger_list[i])) {
 | 
					        if(!query.exec(trigger_list[i])) {
 | 
				
			||||||
 | 
					            qDebug() << query.lastError();
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -275,35 +277,28 @@ int SQLiteDB::recursiveScanRootDirectory(const QString &base_path, int parent, i
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int SQLiteDB::getPathId(const QString &path)
 | 
					int SQLiteDB::getPathId(const QString &path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (!db.isOpen()) {
 | 
					 | 
				
			||||||
        return -1;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    QSqlQuery query(QString("SELECT object_id from sources WHERE path = %1").arg(path));
 | 
					    QSqlQuery query(QString("SELECT object_id from sources WHERE path = %1").arg(path));
 | 
				
			||||||
    if(query.next()) {
 | 
					    if(query.next()) {
 | 
				
			||||||
        return query.value(0).toInt();
 | 
					        return query.value(0).toInt();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString SQLiteDB::getPathFromId(int ohfi)
 | 
					QString SQLiteDB::getPathFromId(int ohfi)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (!db.isOpen()) {
 | 
					 | 
				
			||||||
        return QString();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    QSqlQuery query(QString("SELECT path FROM sources WHERE object_id = %1").arg(ohfi));
 | 
					    QSqlQuery query(QString("SELECT path FROM sources WHERE object_id = %1").arg(ohfi));
 | 
				
			||||||
    if(query.next()) {
 | 
					    if(query.next()) {
 | 
				
			||||||
        return query.value(0).toString();
 | 
					        return query.value(0).toString();
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
        return QString();
 | 
					        return QString();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool SQLiteDB::updateSize(int ohfi, quint64 size)
 | 
					bool SQLiteDB::updateSize(int ohfi, quint64 size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (!db.isOpen()) {
 | 
					 | 
				
			||||||
        return false;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    QSqlQuery query(QString("UPDATE sources SET size = %1 WHERE object_id == %2").arg(size).arg(ohfi));
 | 
					    QSqlQuery query(QString("UPDATE sources SET size = %1 WHERE object_id == %2").arg(size).arg(ohfi));
 | 
				
			||||||
    return query.exec();
 | 
					    return query.exec();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -311,7 +306,11 @@ bool SQLiteDB::updateSize(int ohfi, quint64 size)
 | 
				
			|||||||
bool SQLiteDB::deleteEntry(int ohfi)
 | 
					bool SQLiteDB::deleteEntry(int ohfi)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    QSqlQuery query(QString("DELETE FROM object_node WHERE object_id == %1").arg(ohfi));
 | 
					    QSqlQuery query(QString("DELETE FROM object_node WHERE object_id == %1").arg(ohfi));
 | 
				
			||||||
    return query.exec();
 | 
					    bool ret = query.exec();
 | 
				
			||||||
 | 
					    if(!ret) {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool SQLiteDB::deleteEntry(const QString &path)
 | 
					bool SQLiteDB::deleteEntry(const QString &path)
 | 
				
			||||||
@@ -329,13 +328,19 @@ bool SQLiteDB::updateAdjacencyList(int ohfi, int parent)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if(query.exec() && query.next()) {
 | 
					    if(query.exec() && query.next()) {
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    query.prepare("INSERT INTO adjacent_objects (parent_id, child_id)"
 | 
					    query.prepare("INSERT INTO adjacent_objects (parent_id, child_id)"
 | 
				
			||||||
                  "VALUES (:parentid, :child_id)");
 | 
					                  "VALUES (:parentid, :child_id)");
 | 
				
			||||||
    query.bindValue(0, parent);
 | 
					    query.bindValue(0, parent);
 | 
				
			||||||
    query.bindValue(1, ohfi);
 | 
					    query.bindValue(1, ohfi);
 | 
				
			||||||
    return query.exec();
 | 
					    bool ret = query.exec();
 | 
				
			||||||
 | 
					    if(!ret) {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint SQLiteDB::insertDirectoryEntry(const QString &path, int type, int parent)
 | 
					uint SQLiteDB::insertDirectoryEntry(const QString &path, int type, int parent)
 | 
				
			||||||
@@ -376,6 +381,7 @@ uint SQLiteDB::insertObjectEntry(const char *title, int type)
 | 
				
			|||||||
    query.bindValue(1, title);
 | 
					    query.bindValue(1, title);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(!query.exec() || !query.exec("SELECT last_insert_rowid()") || !query.next()) {
 | 
					    if(!query.exec() || !query.exec("SELECT last_insert_rowid()") || !query.next()) {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    //}
 | 
					    //}
 | 
				
			||||||
@@ -401,7 +407,11 @@ bool SQLiteDB::insertSourceEntry(uint object_id, const QString &path)
 | 
				
			|||||||
    query.bindValue(2, size);
 | 
					    query.bindValue(2, size);
 | 
				
			||||||
    query.bindValue(3, date_created);
 | 
					    query.bindValue(3, date_created);
 | 
				
			||||||
    query.bindValue(4, date_modified);
 | 
					    query.bindValue(4, date_modified);
 | 
				
			||||||
    return query.exec();
 | 
					    bool ret = query.exec();
 | 
				
			||||||
 | 
					    if(!ret) {
 | 
				
			||||||
 | 
					        qDebug() << query.lastError();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint SQLiteDB::insertMusicEntry(const QString &path, int type, int parent)
 | 
					uint SQLiteDB::insertMusicEntry(const QString &path, int type, int parent)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user