Pass database object to others using their constructors.
Prepare SQLiteDB class functions so it can be instantiated.
This commit is contained in:
@@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
ClientManager::ClientManager(QObject *parent) :
|
ClientManager::ClientManager(Database *db, QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent), m_db(db)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +63,10 @@ void ClientManager::start()
|
|||||||
// initializing database for the first use
|
// initializing database for the first use
|
||||||
refreshDatabase();
|
refreshDatabase();
|
||||||
|
|
||||||
CmaEvent::db = &db;
|
connect(m_db, SIGNAL(fileAdded(QString)), &progress, SLOT(setFileName(QString)));
|
||||||
connect(&db, SIGNAL(fileAdded(QString)), &progress, SLOT(setFileName(QString)));
|
connect(m_db, SIGNAL(directoryAdded(QString)), &progress, SLOT(setDirectoryName(QString)));
|
||||||
connect(&db, SIGNAL(directoryAdded(QString)), &progress, SLOT(setDirectoryName(QString)));
|
connect(m_db, SIGNAL(updated(int)), this, SLOT(databaseUpdated(int)));
|
||||||
connect(&db, SIGNAL(updated(int)), this, SLOT(databaseUpdated(int)));
|
connect(&progress, SIGNAL(canceled()), m_db, SLOT(cancelOperation()), Qt::DirectConnection);
|
||||||
connect(&progress, SIGNAL(canceled()), &db, SLOT(cancelOperation()), Qt::DirectConnection);
|
|
||||||
|
|
||||||
thread_count = 0;
|
thread_count = 0;
|
||||||
qDebug("Starting cma threads");
|
qDebug("Starting cma threads");
|
||||||
@@ -76,7 +75,7 @@ void ClientManager::start()
|
|||||||
|
|
||||||
if(!settings.value("disableUSB", false).toBool()) {
|
if(!settings.value("disableUSB", false).toBool()) {
|
||||||
usb_thread = new QThread();
|
usb_thread = new QThread();
|
||||||
client = new CmaClient();
|
client = new CmaClient(m_db);
|
||||||
usb_thread->setObjectName("usb_thread");
|
usb_thread->setObjectName("usb_thread");
|
||||||
connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb()));
|
connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb()));
|
||||||
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
|
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
|
||||||
@@ -96,7 +95,7 @@ void ClientManager::start()
|
|||||||
|
|
||||||
if(!settings.value("disableWireless", false).toBool()) {
|
if(!settings.value("disableWireless", false).toBool()) {
|
||||||
wireless_thread = new QThread();
|
wireless_thread = new QThread();
|
||||||
client = new CmaClient();
|
client = new CmaClient(m_db);
|
||||||
wireless_thread->setObjectName("wireless_thread");
|
wireless_thread->setObjectName("wireless_thread");
|
||||||
connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless()));
|
connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless()));
|
||||||
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
|
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
|
||||||
@@ -124,7 +123,7 @@ void ClientManager::start()
|
|||||||
void ClientManager::refreshDatabase()
|
void ClientManager::refreshDatabase()
|
||||||
{
|
{
|
||||||
bool prepared;
|
bool prepared;
|
||||||
if(!db.reload(prepared)) {
|
if(!m_db->reload(prepared)) {
|
||||||
if(prepared) {
|
if(prepared) {
|
||||||
emit messageSent(tr("Cannot refresh the database while is in use"));
|
emit messageSent(tr("Cannot refresh the database while is in use"));
|
||||||
} else {
|
} else {
|
||||||
|
@@ -31,18 +31,18 @@ class ClientManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ClientManager(QObject *parent = 0);
|
explicit ClientManager(Database *db, QObject *parent = 0);
|
||||||
~ClientManager();
|
~ClientManager();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
QListDB db;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int thread_count;
|
int thread_count;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
|
Database *m_db;
|
||||||
|
|
||||||
PinForm pinForm;
|
PinForm pinForm;
|
||||||
ProgressForm progress;
|
ProgressForm progress;
|
||||||
|
|
||||||
|
@@ -45,8 +45,8 @@ bool CmaClient::in_progress = false;
|
|||||||
|
|
||||||
CmaClient *CmaClient::this_object = NULL;
|
CmaClient *CmaClient::this_object = NULL;
|
||||||
|
|
||||||
CmaClient::CmaClient(QObject *parent) :
|
CmaClient::CmaClient(Database *db, QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent), m_db(db)
|
||||||
{
|
{
|
||||||
this_object = this;
|
this_object = this;
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ void CmaClient::enterEventLoop(vita_device_t *device)
|
|||||||
|
|
||||||
qDebug("Starting event loop");
|
qDebug("Starting event loop");
|
||||||
|
|
||||||
CmaEvent eventLoop (device);
|
CmaEvent eventLoop(m_db, device);
|
||||||
QThread thread;
|
QThread thread;
|
||||||
thread.setObjectName("event_thread");
|
thread.setObjectName("event_thread");
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ class CmaClient : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CmaClient(QObject *parent = 0);
|
explicit CmaClient(Database *db, QObject *parent = 0);
|
||||||
|
|
||||||
static bool isRunning();
|
static bool isRunning();
|
||||||
void launch();
|
void launch();
|
||||||
@@ -55,6 +55,7 @@ private:
|
|||||||
static void registrationComplete();
|
static void registrationComplete();
|
||||||
|
|
||||||
CmaBroadcast broadcast;
|
CmaBroadcast broadcast;
|
||||||
|
Database *m_db;
|
||||||
static QString tempOnlineId;
|
static QString tempOnlineId;
|
||||||
|
|
||||||
//TODO: move all the control variables to the client manager class
|
//TODO: move all the control variables to the client manager class
|
||||||
|
101
src/cmaevent.cpp
101
src/cmaevent.cpp
@@ -28,13 +28,12 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
QListDB *CmaEvent::db = NULL;
|
|
||||||
QFile *CmaEvent::m_file = NULL;
|
QFile *CmaEvent::m_file = NULL;
|
||||||
|
|
||||||
static metadata_t g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{17, 240, 136, 0, 1, 1.0f, 2}}, NULL};
|
static metadata_t g_thumbmeta = {0, 0, 0, NULL, NULL, 0, 0, 0, Thumbnail, {{17, 240, 136, 0, 1, 1.0f, 2}}, NULL};
|
||||||
|
|
||||||
CmaEvent::CmaEvent(vita_device_t *s_device) :
|
CmaEvent::CmaEvent(Database *db, vita_device_t *s_device) :
|
||||||
device(s_device), is_active(true)
|
device(s_device), m_db(db), is_active(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,16 +170,16 @@ quint16 CmaEvent::processAllObjects(metadata_t &parent_metadata, quint32 handle)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ohfi = db->getPathId(name, parent_metadata.ohfi);
|
int ohfi = m_db->getPathId(name, parent_metadata.ohfi);
|
||||||
|
|
||||||
if(ohfi > 0) {
|
if(ohfi > 0) {
|
||||||
const QString fullpath = db->getAbsolutePath(ohfi);
|
const QString fullpath = m_db->getAbsolutePath(ohfi);
|
||||||
qDebug() << "Deleting" << fullpath;
|
qDebug() << "Deleting" << fullpath;
|
||||||
removeRecursively(fullpath);
|
removeRecursively(fullpath);
|
||||||
db->deleteEntry(ohfi);
|
m_db->deleteEntry(ohfi);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir dir(db->getAbsolutePath(parent_metadata.ohfi));
|
QDir dir(m_db->getAbsolutePath(parent_metadata.ohfi));
|
||||||
|
|
||||||
if(dataType & Folder) {
|
if(dataType & Folder) {
|
||||||
if(!dir.mkpath(name)) {
|
if(!dir.mkpath(name)) {
|
||||||
@@ -207,14 +206,14 @@ quint16 CmaEvent::processAllObjects(metadata_t &parent_metadata, quint32 handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo info(dir, name);
|
QFileInfo info(dir, name);
|
||||||
int new_ohfi = db->insertObjectEntry(info.absoluteFilePath(), parent_metadata.ohfi);
|
int new_ohfi = m_db->insertObjectEntry(info.absoluteFilePath(), parent_metadata.ohfi);
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
qDebug() << QString("Added object %1 with OHFI %2 to database").arg(info.absoluteFilePath(), QString::number(new_ohfi));
|
qDebug() << QString("Added object %1 with OHFI %2 to database").arg(info.absoluteFilePath(), QString::number(new_ohfi));
|
||||||
|
|
||||||
if(dataType & Folder) {
|
if(dataType & Folder) {
|
||||||
metadata_t folder_metadata;
|
metadata_t folder_metadata;
|
||||||
db->getObjectMetadata(new_ohfi, folder_metadata);
|
m_db->getObjectMetadata(new_ohfi, folder_metadata);
|
||||||
folder_metadata.handle = handle;
|
folder_metadata.handle = handle;
|
||||||
|
|
||||||
for(unsigned int i = 0; i < p_len; i++) {
|
for(unsigned int i = 0; i < p_len; i++) {
|
||||||
@@ -222,7 +221,7 @@ quint16 CmaEvent::processAllObjects(metadata_t &parent_metadata, quint32 handle)
|
|||||||
|
|
||||||
if(ret != PTP_RC_OK) {
|
if(ret != PTP_RC_OK) {
|
||||||
qDebug("Deleteting object with OHFI %d", new_ohfi);
|
qDebug("Deleteting object with OHFI %d", new_ohfi);
|
||||||
db->deleteEntry(new_ohfi);
|
m_db->deleteEntry(new_ohfi);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -242,11 +241,11 @@ void CmaEvent::vitaEventGetTreatObject(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
|
|
||||||
if(!db->getObjectMetadata(treatObject.ohfiParent, metadata)) {
|
if(!m_db->getObjectMetadata(treatObject.ohfiParent, metadata)) {
|
||||||
qWarning("Cannot find parent OHFI %d", treatObject.ohfiParent);
|
qWarning("Cannot find parent OHFI %d", treatObject.ohfiParent);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
||||||
return;
|
return;
|
||||||
@@ -265,13 +264,13 @@ void CmaEvent::vitaEventSendCopyConfirmationInfo(vita_event_t *event, int eventI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
qint64 size;
|
qint64 size;
|
||||||
qint64 total_size = 0;
|
qint64 total_size = 0;
|
||||||
|
|
||||||
for(quint32 i = 0; i < info->count; i++) {
|
for(quint32 i = 0; i < info->count; i++) {
|
||||||
if((size = db->getObjectSize(info->ohfi[i])) < 0) {
|
if((size = m_db->getObjectSize(info->ohfi[i])) < 0) {
|
||||||
qWarning("Cannot find OHFI %d", info->ohfi[i]);
|
qWarning("Cannot find OHFI %d", info->ohfi[i]);
|
||||||
free(info);
|
free(info);
|
||||||
return;
|
return;
|
||||||
@@ -299,11 +298,11 @@ void CmaEvent::vitaEventSendObjectMetadataItems(vita_event_t *event, int eventId
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
|
|
||||||
if(!db->getObjectMetadata(ohfi, metadata)) {
|
if(!m_db->getObjectMetadata(ohfi, metadata)) {
|
||||||
qWarning("Cannot find OHFI %d in database", ohfi);
|
qWarning("Cannot find OHFI %d in database", ohfi);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
||||||
return;
|
return;
|
||||||
@@ -355,10 +354,10 @@ void CmaEvent::vitaEventSendNumOfObject(vita_event_t *event, int eventId)
|
|||||||
{
|
{
|
||||||
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = event->Param2;
|
int ohfi = event->Param2;
|
||||||
int items = db->childObjectCount(ohfi);
|
int items = m_db->childObjectCount(ohfi);
|
||||||
|
|
||||||
if(VitaMTP_SendNumOfObject(device, eventId, items) != PTP_RC_OK) {
|
if(VitaMTP_SendNumOfObject(device, eventId, items) != PTP_RC_OK) {
|
||||||
qWarning("Error occured receiving object count for OHFI parent %d", ohfi);
|
qWarning("Error occured receiving object count for OHFI parent %d", ohfi);
|
||||||
@@ -378,11 +377,11 @@ void CmaEvent::vitaEventSendObjectMetadata(vita_event_t *event, int eventId)
|
|||||||
qWarning("GetBrowseInfo failed");
|
qWarning("GetBrowseInfo failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
metadata_t *meta = NULL;
|
metadata_t *meta = NULL;
|
||||||
|
|
||||||
int count = db->getObjectMetadatas(browse.ohfiParent, &meta, browse.index, browse.numObjects); // if meta is null, will return empty XML
|
int count = m_db->getObjectMetadatas(browse.ohfiParent, &meta, browse.index, browse.numObjects); // if meta is null, will return empty XML
|
||||||
qDebug("Sending %i metadata filtered objects for OHFI %d", count, browse.ohfiParent);
|
qDebug("Sending %i metadata filtered objects for OHFI %d", count, browse.ohfiParent);
|
||||||
|
|
||||||
if(VitaMTP_SendObjectMetadata(device, eventId, meta) != PTP_RC_OK) { // send all objects with OHFI parent
|
if(VitaMTP_SendObjectMetadata(device, eventId, meta) != PTP_RC_OK) { // send all objects with OHFI parent
|
||||||
@@ -398,12 +397,12 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
|
|||||||
|
|
||||||
int ohfi = event->Param2;
|
int ohfi = event->Param2;
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
qDebug("Searching object with OHFI %d", ohfi);
|
qDebug("Searching object with OHFI %d", ohfi);
|
||||||
|
|
||||||
metadata_t *metadata = NULL;
|
metadata_t *metadata = NULL;
|
||||||
if(!db->getObjectMetadatas(ohfi, &metadata)) {
|
if(!m_db->getObjectMetadatas(ohfi, &metadata)) {
|
||||||
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);
|
||||||
return;
|
return;
|
||||||
@@ -416,7 +415,7 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned long len = metadata->size;
|
unsigned long len = metadata->size;
|
||||||
m_file = new QFile(db->getAbsolutePath(metadata->ohfi));
|
m_file = new QFile(m_db->getAbsolutePath(metadata->ohfi));
|
||||||
|
|
||||||
// read the file to send if it's not a directory
|
// read the file to send if it's not a directory
|
||||||
// if it is a directory, data and len are not used by VitaMTP
|
// if it is a directory, data and len are not used by VitaMTP
|
||||||
@@ -435,7 +434,7 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
|
|||||||
|
|
||||||
if(start != metadata) {
|
if(start != metadata) {
|
||||||
metadata_t parent_metadata;
|
metadata_t parent_metadata;
|
||||||
db->getObjectMetadata(metadata->ohfiParent, parent_metadata);
|
m_db->getObjectMetadata(metadata->ohfiParent, parent_metadata);
|
||||||
parentHandle = parent_metadata.handle;
|
parentHandle = parent_metadata.handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -469,7 +468,7 @@ void CmaEvent::vitaEventSendObject(vita_event_t *event, int eventId)
|
|||||||
|
|
||||||
metadata = metadata->next_metadata;
|
metadata = metadata->next_metadata;
|
||||||
|
|
||||||
} while(metadata && metadata->ohfiParent >= OHFI_OFFSET); // get everything under this "folder"
|
} while(metadata && metadata->ohfiParent >= OHFI_BASE_VALUE); // get everything under this "folder"
|
||||||
|
|
||||||
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, handle);
|
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, handle);
|
||||||
|
|
||||||
@@ -561,16 +560,16 @@ void CmaEvent::vitaEventSendObjectStatus(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = db->getPathId(objectstatus.title, objectstatus.ohfiRoot);
|
int ohfi = m_db->getPathId(objectstatus.title, objectstatus.ohfiRoot);
|
||||||
|
|
||||||
if(ohfi == 0) { // not in database, don't return metadata
|
if(ohfi == 0) { // not in database, don't return metadata
|
||||||
qDebug("Object %s not in database (OHFI: %i). Sending OK response for non-existence", objectstatus.title, objectstatus.ohfiRoot);
|
qDebug("Object %s not in database (OHFI: %i). Sending OK response for non-existence", objectstatus.title, objectstatus.ohfiRoot);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
|
||||||
} else {
|
} else {
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
db->getObjectMetadata(ohfi, metadata);
|
m_db->getObjectMetadata(ohfi, metadata);
|
||||||
metadata.next_metadata = NULL;
|
metadata.next_metadata = NULL;
|
||||||
qDebug("Sending metadata for OHFI %d", ohfi);
|
qDebug("Sending metadata for OHFI %d", ohfi);
|
||||||
|
|
||||||
@@ -588,18 +587,18 @@ void CmaEvent::vitaEventSendObjectThumb(vita_event_t *event, int eventId)
|
|||||||
{
|
{
|
||||||
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = event->Param2;
|
int ohfi = event->Param2;
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
|
|
||||||
if(!db->getObjectMetadata(ohfi, metadata)) {
|
if(!m_db->getObjectMetadata(ohfi, metadata)) {
|
||||||
qWarning("Cannot find OHFI %d in database.", ohfi);
|
qWarning("Cannot find OHFI %d in database.", ohfi);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString fullpath = db->getAbsolutePath(ohfi);
|
QString fullpath = m_db->getAbsolutePath(ohfi);
|
||||||
QByteArray data = getThumbnail(fullpath, metadata.dataType, &g_thumbmeta);
|
QByteArray data = getThumbnail(fullpath, metadata.dataType, &g_thumbmeta);
|
||||||
|
|
||||||
if(data.size() == 0) {
|
if(data.size() == 0) {
|
||||||
@@ -629,21 +628,21 @@ void CmaEvent::vitaEventDeleteObject(vita_event_t *event, int eventId)
|
|||||||
{
|
{
|
||||||
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = event->Param2;
|
int ohfi = event->Param2;
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
|
|
||||||
if(!db->getObjectMetadata(ohfi, metadata)) {
|
if(!m_db->getObjectMetadata(ohfi, metadata)) {
|
||||||
qWarning("OHFI %d not found", ohfi);
|
qWarning("OHFI %d not found", ohfi);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Invalid_OHFI);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString fullpath = db->getAbsolutePath(ohfi);
|
QString fullpath = m_db->getAbsolutePath(ohfi);
|
||||||
qDebug() << QString("Deleting %1, OHFI: %2").arg(fullpath, QString::number(ohfi));
|
qDebug() << QString("Deleting %1, OHFI: %2").arg(fullpath, QString::number(ohfi));
|
||||||
removeRecursively(fullpath);
|
removeRecursively(fullpath);
|
||||||
db->deleteEntry(ohfi);
|
m_db->deleteEntry(ohfi);
|
||||||
|
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_OK);
|
||||||
}
|
}
|
||||||
@@ -663,7 +662,7 @@ void CmaEvent::vitaEventGetSettingInfo(vita_event_t *event, int eventId)
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
if(settings.value("lastAccountId").toString() != settingsinfo->current_account.accountId) {
|
if(settings.value("lastAccountId").toString() != settingsinfo->current_account.accountId) {
|
||||||
db->setUUID(settingsinfo->current_account.accountId);
|
m_db->setUUID(settingsinfo->current_account.accountId);
|
||||||
// set the database to be updated ASAP
|
// set the database to be updated ASAP
|
||||||
emit refreshDatabase();
|
emit refreshDatabase();
|
||||||
}
|
}
|
||||||
@@ -720,9 +719,9 @@ void CmaEvent::vitaEventSendPartOfObject(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
QString fullpath = db->getAbsolutePath(part_init.ohfi);
|
QString fullpath = m_db->getAbsolutePath(part_init.ohfi);
|
||||||
|
|
||||||
if(fullpath.isNull()) {
|
if(fullpath.isNull()) {
|
||||||
qWarning("Cannot find object for OHFI %d", part_init.ohfi);
|
qWarning("Cannot find object for OHFI %d", part_init.ohfi);
|
||||||
@@ -762,9 +761,9 @@ void CmaEvent::vitaEventOperateObject(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
QString fullpath = db->getAbsolutePath(operateobject.ohfi);
|
QString fullpath = m_db->getAbsolutePath(operateobject.ohfi);
|
||||||
|
|
||||||
// end for renaming only
|
// end for renaming only
|
||||||
if(fullpath.isNull()) {
|
if(fullpath.isNull()) {
|
||||||
@@ -781,7 +780,7 @@ void CmaEvent::vitaEventOperateObject(vita_event_t *event, int eventId)
|
|||||||
qWarning("Unable to create temporary folder: %s", operateobject.title);
|
qWarning("Unable to create temporary folder: %s", operateobject.title);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Failed_Operate_Object);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Failed_Operate_Object);
|
||||||
} else {
|
} else {
|
||||||
int new_ohfi = db->insertObjectEntry(QDir(dir).absoluteFilePath(operateobject.title), operateobject.ohfi);
|
int new_ohfi = m_db->insertObjectEntry(QDir(dir).absoluteFilePath(operateobject.title), operateobject.ohfi);
|
||||||
qDebug("Created folder %s with OHFI %d", operateobject.title, new_ohfi);
|
qDebug("Created folder %s with OHFI %d", operateobject.title, new_ohfi);
|
||||||
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, new_ohfi);
|
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, new_ohfi);
|
||||||
}
|
}
|
||||||
@@ -795,7 +794,7 @@ void CmaEvent::vitaEventOperateObject(vita_event_t *event, int eventId)
|
|||||||
qWarning("Unable to create temporary file: %s", operateobject.title);
|
qWarning("Unable to create temporary file: %s", operateobject.title);
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Failed_Operate_Object);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Failed_Operate_Object);
|
||||||
} else {
|
} else {
|
||||||
int new_ohfi = db->insertObjectEntry(file.fileName(), operateobject.ohfi);
|
int new_ohfi = m_db->insertObjectEntry(file.fileName(), operateobject.ohfi);
|
||||||
//qDebug("Created file %s with OHFI %d under parent %s", newobj->metadata.path, new_ohfi, root->metadata.path);
|
//qDebug("Created file %s with OHFI %d under parent %s", newobj->metadata.path, new_ohfi, root->metadata.path);
|
||||||
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, new_ohfi);
|
VitaMTP_ReportResultWithParam(device, eventId, PTP_RC_OK, new_ohfi);
|
||||||
}
|
}
|
||||||
@@ -804,8 +803,8 @@ void CmaEvent::vitaEventOperateObject(vita_event_t *event, int eventId)
|
|||||||
case VITA_OPERATE_RENAME: {
|
case VITA_OPERATE_RENAME: {
|
||||||
//qDebug("Operate command %d: Rename %s to %s", operateobject.cmd, root->metadata.name, operateobject.title);
|
//qDebug("Operate command %d: Rename %s to %s", operateobject.cmd, root->metadata.name, operateobject.title);
|
||||||
|
|
||||||
db->renameObject(operateobject.ohfi, operateobject.title);
|
m_db->renameObject(operateobject.ohfi, operateobject.title);
|
||||||
QString newpath = db->getAbsolutePath(operateobject.ohfi);
|
QString newpath = m_db->getAbsolutePath(operateobject.ohfi);
|
||||||
|
|
||||||
// rename in filesystem
|
// rename in filesystem
|
||||||
if(!QFile(fullpath).rename(newpath)) {
|
if(!QFile(fullpath).rename(newpath)) {
|
||||||
@@ -840,8 +839,8 @@ void CmaEvent::vitaEventGetPartOfObject(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
QString fullpath = db->getAbsolutePath(part_init.ohfi);
|
QString fullpath = m_db->getAbsolutePath(part_init.ohfi);
|
||||||
|
|
||||||
if(fullpath.isNull()) {
|
if(fullpath.isNull()) {
|
||||||
qWarning("Cannot find OHFI %d", part_init.ohfi);
|
qWarning("Cannot find OHFI %d", part_init.ohfi);
|
||||||
@@ -861,7 +860,7 @@ void CmaEvent::vitaEventGetPartOfObject(vita_event_t *event, int eventId)
|
|||||||
} else {
|
} else {
|
||||||
file.seek(part_init.offset);
|
file.seek(part_init.offset);
|
||||||
file.write((const char *)data, part_init.size);
|
file.write((const char *)data, part_init.size);
|
||||||
db->setObjectSize(part_init.ohfi, part_init.size);
|
m_db->setObjectSize(part_init.ohfi, part_init.size);
|
||||||
|
|
||||||
qDebug() << QString("Written %1 bytes to %2 at offset %3").arg(
|
qDebug() << QString("Written %1 bytes to %2 at offset %3").arg(
|
||||||
QString::number(part_init.size), fullpath, QString::number(part_init.offset)
|
QString::number(part_init.size), fullpath, QString::number(part_init.offset)
|
||||||
@@ -877,10 +876,10 @@ void CmaEvent::vitaEventSendStorageSize(vita_event_t *event, int eventId)
|
|||||||
{
|
{
|
||||||
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
qDebug("Event recieved in %s, code: 0x%x, id: %d", Q_FUNC_INFO, event->Code, eventId);
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = event->Param2;
|
int ohfi = event->Param2;
|
||||||
QString fullpath = db->getAbsolutePath(ohfi);
|
QString fullpath = m_db->getAbsolutePath(ohfi);
|
||||||
|
|
||||||
if(fullpath.isNull()) {
|
if(fullpath.isNull()) {
|
||||||
qWarning("Error: Cannot find OHFI %d", ohfi);
|
qWarning("Error: Cannot find OHFI %d", ohfi);
|
||||||
@@ -931,9 +930,9 @@ void CmaEvent::vitaEventCheckExistance(vita_event_t *event, int eventId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int ohfi = db->getPathId(existance.name, 0);
|
int ohfi = m_db->getPathId(existance.name, 0);
|
||||||
|
|
||||||
if(ohfi == 0) {
|
if(ohfi == 0) {
|
||||||
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Different_Object);
|
VitaMTP_ReportResult(device, eventId, PTP_RC_VITA_Different_Object);
|
||||||
|
@@ -20,9 +20,10 @@
|
|||||||
#ifndef CMAEVENT_H
|
#ifndef CMAEVENT_H
|
||||||
#define CMAEVENT_H
|
#define CMAEVENT_H
|
||||||
|
|
||||||
#include "qlistdb.h"
|
#include "database.h"
|
||||||
#include "httpdownloader.h"
|
#include "httpdownloader.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSemaphore>
|
#include <QSemaphore>
|
||||||
@@ -33,13 +34,9 @@ class CmaEvent : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit CmaEvent(vita_device_t *s_device);
|
explicit CmaEvent(Database *db, vita_device_t *s_device);
|
||||||
|
|
||||||
void vitaEventCancelTask(vita_event_t *event, int eventId);
|
void vitaEventCancelTask(vita_event_t *event, int eventId);
|
||||||
|
|
||||||
// don't make the db reference static
|
|
||||||
static QListDB *db;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t processAllObjects(metadata_t &metadata, uint32_t handle);
|
uint16_t processAllObjects(metadata_t &metadata, uint32_t handle);
|
||||||
void vitaEventSendObject(vita_event_t *event, int eventId);
|
void vitaEventSendObject(vita_event_t *event, int eventId);
|
||||||
@@ -72,6 +69,8 @@ private:
|
|||||||
vita_device_t *device;
|
vita_device_t *device;
|
||||||
vita_event_t t_event;
|
vita_event_t t_event;
|
||||||
|
|
||||||
|
Database *m_db;
|
||||||
|
|
||||||
// control variables
|
// control variables
|
||||||
bool is_active;
|
bool is_active;
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
@@ -24,7 +24,8 @@ const file_type video_list[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Database::Database(QObject *parent) :
|
Database::Database(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent),
|
||||||
|
mutex(QMutex::Recursive)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
#ifndef DATABASE_H
|
#ifndef DATABASE_H
|
||||||
#define DATABASE_H
|
#define DATABASE_H
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -10,6 +12,8 @@ typedef struct {
|
|||||||
int file_codec;
|
int file_codec;
|
||||||
} file_type;
|
} file_type;
|
||||||
|
|
||||||
|
#define OHFI_BASE_VALUE 256
|
||||||
|
|
||||||
#define FILE_FORMAT_MP4 1
|
#define FILE_FORMAT_MP4 1
|
||||||
#define FILE_FORMAT_WAV 2
|
#define FILE_FORMAT_WAV 2
|
||||||
#define FILE_FORMAT_MP3 3
|
#define FILE_FORMAT_MP3 3
|
||||||
@@ -39,7 +43,6 @@ class Database : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Database(QObject *parent = 0);
|
explicit Database(QObject *parent = 0);
|
||||||
|
|
||||||
virtual int childObjectCount(int parent_ohfi) = 0;
|
virtual int childObjectCount(int parent_ohfi) = 0;
|
||||||
virtual bool deleteEntry(int ohfi, int root_ohfi = 0) = 0;
|
virtual bool deleteEntry(int ohfi, int root_ohfi = 0) = 0;
|
||||||
virtual QString getAbsolutePath(int ohfi) = 0;
|
virtual QString getAbsolutePath(int ohfi) = 0;
|
||||||
@@ -54,11 +57,15 @@ public:
|
|||||||
virtual int getParentId(int ohfi) = 0;
|
virtual int getParentId(int ohfi) = 0;
|
||||||
virtual int getRootId(int ohfi) = 0;
|
virtual int getRootId(int ohfi) = 0;
|
||||||
|
|
||||||
|
virtual bool reload(bool &prepared) = 0;
|
||||||
|
virtual void setUUID(const QString uuid) = 0;
|
||||||
|
|
||||||
static int checkFileType(const QString path, int ohfi_root);
|
static int checkFileType(const QString path, int ohfi_root);
|
||||||
static void loadMusicMetadata(const QString &path, metadata_t &metadata);
|
static void loadMusicMetadata(const QString &path, metadata_t &metadata);
|
||||||
static void loadPhotoMetadata(const QString &path, metadata_t &metadata);
|
static void loadPhotoMetadata(const QString &path, metadata_t &metadata);
|
||||||
static void loadVideoMetadata(const QString &path, metadata_t &metadata);
|
static void loadVideoMetadata(const QString &path, metadata_t &metadata);
|
||||||
|
|
||||||
|
QMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DATABASE_H
|
#endif // DATABASE_H
|
||||||
|
@@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
BackupManagerForm::BackupManagerForm(QWidget *parent) :
|
BackupManagerForm::BackupManagerForm(Database *db, QWidget *parent) :
|
||||||
QWidget(parent),
|
QDialog(parent), m_db(db),
|
||||||
ui(new Ui::BackupManagerForm)
|
ui(new Ui::BackupManagerForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@@ -64,11 +64,11 @@ void BackupManagerForm::removeEntry(BackupItem *item)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&db->mutex);
|
QMutexLocker locker(&m_db->mutex);
|
||||||
|
|
||||||
int parent_ohfi = db->getParentId(item->ohfi);
|
int parent_ohfi = m_db->getParentId(item->ohfi);
|
||||||
removeRecursively(db->getAbsolutePath(item->ohfi));
|
removeRecursively(m_db->getAbsolutePath(item->ohfi));
|
||||||
db->deleteEntry(item->ohfi);
|
m_db->deleteEntry(item->ohfi);
|
||||||
|
|
||||||
for(int i = 0; i < ui->tableWidget->rowCount(); ++i) {
|
for(int i = 0; i < ui->tableWidget->rowCount(); ++i) {
|
||||||
BackupItem *iter_item = static_cast<BackupItem *>(ui->tableWidget->cellWidget(i, 0));
|
BackupItem *iter_item = static_cast<BackupItem *>(ui->tableWidget->cellWidget(i, 0));
|
||||||
@@ -79,7 +79,7 @@ void BackupManagerForm::removeEntry(BackupItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(parent_ohfi > 0) {
|
if(parent_ohfi > 0) {
|
||||||
setBackupUsage(db->getObjectSize(parent_ohfi));
|
setBackupUsage(m_db->getObjectSize(parent_ohfi));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,17 +141,17 @@ void BackupManagerForm::loadBackupListing(int index)
|
|||||||
sys_dir = true;
|
sys_dir = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
db->mutex.lock();
|
m_db->mutex.lock();
|
||||||
|
|
||||||
// get the item list
|
// get the item list
|
||||||
metadata_t *meta = NULL;
|
metadata_t *meta = NULL;
|
||||||
int row_count = db->getObjectMetadatas(ohfi, &meta);
|
int row_count = m_db->getObjectMetadatas(ohfi, &meta);
|
||||||
ui->tableWidget->setRowCount(row_count);
|
ui->tableWidget->setRowCount(row_count);
|
||||||
|
|
||||||
// exit if there aren't any items
|
// exit if there aren't any items
|
||||||
if(row_count == 0) {
|
if(row_count == 0) {
|
||||||
setBackupUsage(0);
|
setBackupUsage(0);
|
||||||
db->mutex.unlock();
|
m_db->mutex.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +163,8 @@ void BackupManagerForm::loadBackupListing(int index)
|
|||||||
#else
|
#else
|
||||||
horiz_header->setResizeMode(QHeaderView::Stretch);
|
horiz_header->setResizeMode(QHeaderView::Stretch);
|
||||||
#endif
|
#endif
|
||||||
setBackupUsage(db->getObjectSize(ohfi));
|
setBackupUsage(m_db->getObjectSize(ohfi));
|
||||||
QString path = db->getAbsolutePath(ohfi);
|
QString path = m_db->getAbsolutePath(ohfi);
|
||||||
QList<BackupItem *> item_list;
|
QList<BackupItem *> item_list;
|
||||||
|
|
||||||
while(meta) {
|
while(meta) {
|
||||||
@@ -228,7 +228,7 @@ void BackupManagerForm::loadBackupListing(int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vert_header->setUpdatesEnabled(true);
|
vert_header->setUpdatesEnabled(true);
|
||||||
db->mutex.unlock();
|
m_db->mutex.unlock();
|
||||||
|
|
||||||
// apply filter
|
// apply filter
|
||||||
this->on_filterLineEdit_textChanged(ui->filterLineEdit->text());
|
this->on_filterLineEdit_textChanged(ui->filterLineEdit->text());
|
||||||
|
@@ -20,24 +20,24 @@
|
|||||||
#ifndef BACKUPMANAGERFORM_H
|
#ifndef BACKUPMANAGERFORM_H
|
||||||
#define BACKUPMANAGERFORM_H
|
#define BACKUPMANAGERFORM_H
|
||||||
|
|
||||||
#include "qlistdb.h"
|
#include "database.h"
|
||||||
#include "backupitem.h"
|
#include "backupitem.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QDialog>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class BackupManagerForm;
|
class BackupManagerForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BackupManagerForm : public QWidget
|
class BackupManagerForm : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BackupManagerForm(QWidget *parent = 0);
|
explicit BackupManagerForm(Database *db, QWidget *parent = 0);
|
||||||
~BackupManagerForm();
|
~BackupManagerForm();
|
||||||
|
|
||||||
QListDB *db;
|
Database *m_db;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupForm();
|
void setupForm();
|
||||||
|
@@ -83,6 +83,7 @@ void ConfigWidget::setDefaultData()
|
|||||||
ui->metadataCheck->setChecked(settings.value("skipMetadata", false).toBool());
|
ui->metadataCheck->setChecked(settings.value("skipMetadata", false).toBool());
|
||||||
ui->usbCheck->setChecked(settings.value("disableUSB", false).toBool());
|
ui->usbCheck->setChecked(settings.value("disableUSB", false).toBool());
|
||||||
ui->wifiCheck->setChecked(settings.value("disableWireless", false).toBool());
|
ui->wifiCheck->setChecked(settings.value("disableWireless", false).toBool());
|
||||||
|
ui->databaseSelect->setCurrentIndex(settings.value("useMemoryStorage", true).toBool() ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigWidget::~ConfigWidget()
|
ConfigWidget::~ConfigWidget()
|
||||||
@@ -154,6 +155,7 @@ void ConfigWidget::accept()
|
|||||||
settings.setValue("skipMetadata", ui->metadataCheck->isChecked());
|
settings.setValue("skipMetadata", ui->metadataCheck->isChecked());
|
||||||
settings.setValue("disableUSB", ui->usbCheck->isChecked());
|
settings.setValue("disableUSB", ui->usbCheck->isChecked());
|
||||||
settings.setValue("disableWireless", ui->wifiCheck->isChecked());
|
settings.setValue("disableWireless", ui->wifiCheck->isChecked());
|
||||||
|
settings.setValue("useMemoryStorage", ui->databaseSelect->currentIndex() == 0);
|
||||||
settings.sync();
|
settings.sync();
|
||||||
|
|
||||||
done(Accepted);
|
done(Accepted);
|
||||||
|
@@ -282,15 +282,17 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="comboBox">
|
<widget class="QComboBox" name="databaseSelect">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>In Memory</string>
|
<string>In Memory</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>SQLite</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
@@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "cmaclient.h"
|
#include "cmaclient.h"
|
||||||
#include "cmaevent.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include "qlistdb.h"
|
||||||
|
#include "sqlitedb.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@@ -43,7 +45,7 @@ const QStringList MainWidget::path_list = QStringList() << "photoPath" << "music
|
|||||||
bool sleptOnce = false;
|
bool sleptOnce = false;
|
||||||
|
|
||||||
MainWidget::MainWidget(QWidget *parent) :
|
MainWidget::MainWidget(QWidget *parent) :
|
||||||
QWidget(parent)
|
QWidget(parent), db(NULL), configForm(NULL), managerForm(NULL), backupForm(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,12 +56,12 @@ void MainWidget::checkSettings()
|
|||||||
foreach(const QString &path, path_list) {
|
foreach(const QString &path, path_list) {
|
||||||
if(!settings.contains(path)) {
|
if(!settings.contains(path)) {
|
||||||
first_run = true;
|
first_run = true;
|
||||||
dialog.show();
|
configForm->show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first_run = false;
|
first_run = false;
|
||||||
manager.start();
|
managerForm->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::dialogResult(int result)
|
void MainWidget::dialogResult(int result)
|
||||||
@@ -67,7 +69,7 @@ void MainWidget::dialogResult(int result)
|
|||||||
if(result == QDialog::Accepted) {
|
if(result == QDialog::Accepted) {
|
||||||
if(first_run) {
|
if(first_run) {
|
||||||
first_run = false;
|
first_run = false;
|
||||||
manager.start();
|
managerForm->start();
|
||||||
}
|
}
|
||||||
} else if(first_run) {
|
} else if(first_run) {
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
@@ -80,7 +82,7 @@ void MainWidget::stopServer()
|
|||||||
if(CmaClient::isRunning()) {
|
if(CmaClient::isRunning()) {
|
||||||
receiveMessage(tr("Stopping QCMA (disconnect your PS Vita)"));
|
receiveMessage(tr("Stopping QCMA (disconnect your PS Vita)"));
|
||||||
}
|
}
|
||||||
manager.stop();
|
managerForm->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::deviceDisconnect()
|
void MainWidget::deviceDisconnect()
|
||||||
@@ -117,6 +119,16 @@ void MainWidget::deviceConnected(QString message)
|
|||||||
|
|
||||||
void MainWidget::prepareApplication()
|
void MainWidget::prepareApplication()
|
||||||
{
|
{
|
||||||
|
//TODO: delete database before exit
|
||||||
|
if(QSettings().value("useMemoryStorage", true).toBool()) {
|
||||||
|
db = new QListDB();
|
||||||
|
} else {
|
||||||
|
db = NULL; // new SQLiteDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
configForm = new ConfigWidget(this);
|
||||||
|
backupForm = new BackupManagerForm(db, this);
|
||||||
|
managerForm = new ClientManager(db, this);
|
||||||
connectSignals();
|
connectSignals();
|
||||||
createTrayIcon();
|
createTrayIcon();
|
||||||
checkSettings();
|
checkSettings();
|
||||||
@@ -124,13 +136,13 @@ void MainWidget::prepareApplication()
|
|||||||
|
|
||||||
void MainWidget::connectSignals()
|
void MainWidget::connectSignals()
|
||||||
{
|
{
|
||||||
connect(&dialog, SIGNAL(finished(int)), this, SLOT(dialogResult(int)));
|
connect(configForm, SIGNAL(finished(int)), this, SLOT(dialogResult(int)));
|
||||||
connect(&manager, SIGNAL(stopped()), qApp, SLOT(quit()));
|
connect(managerForm, SIGNAL(stopped()), qApp, SLOT(quit()));
|
||||||
connect(&manager, SIGNAL(deviceConnected(QString)), this, SLOT(deviceConnected(QString)));
|
connect(managerForm, SIGNAL(deviceConnected(QString)), this, SLOT(deviceConnected(QString)));
|
||||||
connect(&manager, SIGNAL(deviceDisconnected()), this, SLOT(deviceDisconnect()));
|
connect(managerForm, SIGNAL(deviceDisconnected()), this, SLOT(deviceDisconnect()));
|
||||||
connect(&manager, SIGNAL(messageSent(QString)), this, SLOT(receiveMessage(QString)));
|
connect(managerForm, SIGNAL(messageSent(QString)), this, SLOT(receiveMessage(QString)));
|
||||||
|
|
||||||
form.db = &manager.db;
|
//backupForm.db = managerForm.db;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::setTrayTooltip(QString message)
|
void MainWidget::setTrayTooltip(QString message)
|
||||||
@@ -144,8 +156,8 @@ void MainWidget::setTrayTooltip(QString message)
|
|||||||
|
|
||||||
void MainWidget::openManager()
|
void MainWidget::openManager()
|
||||||
{
|
{
|
||||||
form.loadBackupListing(-1);
|
backupForm->loadBackupListing(-1);
|
||||||
form.show();
|
backupForm->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::showAboutDialog()
|
void MainWidget::showAboutDialog()
|
||||||
@@ -186,9 +198,9 @@ void MainWidget::createTrayIcon()
|
|||||||
about_qt = new QAction(tr("Abou&t Qt"), this);
|
about_qt = new QAction(tr("Abou&t Qt"), this);
|
||||||
quit = new QAction(tr("&Quit"), this);
|
quit = new QAction(tr("&Quit"), this);
|
||||||
|
|
||||||
connect(options, SIGNAL(triggered()), &dialog, SLOT(open()));
|
connect(options, SIGNAL(triggered()), configForm, SLOT(open()));
|
||||||
connect(backup, SIGNAL(triggered()), this, SLOT(openManager()));
|
connect(backup, SIGNAL(triggered()), this, SLOT(openManager()));
|
||||||
connect(reload, SIGNAL(triggered()), &manager, SLOT(refreshDatabase()));
|
connect(reload, SIGNAL(triggered()), managerForm, SLOT(refreshDatabase()));
|
||||||
connect(about, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
|
connect(about, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
|
||||||
connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt()));
|
connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt()));
|
||||||
connect(quit, SIGNAL(triggered()), this, SLOT(stopServer()));
|
connect(quit, SIGNAL(triggered()), this, SLOT(stopServer()));
|
||||||
|
@@ -52,10 +52,13 @@ private:
|
|||||||
|
|
||||||
bool first_run;
|
bool first_run;
|
||||||
|
|
||||||
|
// database
|
||||||
|
Database *db;
|
||||||
|
|
||||||
// forms
|
// forms
|
||||||
ConfigWidget dialog;
|
ConfigWidget *configForm;
|
||||||
ClientManager manager;
|
ClientManager *managerForm;
|
||||||
BackupManagerForm form;
|
BackupManagerForm *backupForm;
|
||||||
|
|
||||||
//system tray
|
//system tray
|
||||||
QAction *quit;
|
QAction *quit;
|
||||||
|
@@ -29,8 +29,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
QListDB::QListDB(QObject *parent) :
|
QListDB::QListDB(QObject *parent) :
|
||||||
Database(parent),
|
Database(parent)
|
||||||
mutex(QMutex::Recursive)
|
|
||||||
{
|
{
|
||||||
QString uuid = QSettings().value("lastAccountId", "ffffffffffffffff").toString();
|
QString uuid = QSettings().value("lastAccountId", "ffffffffffffffff").toString();
|
||||||
CMARootObject::uuid = uuid;
|
CMARootObject::uuid = uuid;
|
||||||
|
@@ -55,8 +55,6 @@ public:
|
|||||||
bool renameObject(int ohfi, const QString &name);
|
bool renameObject(int ohfi, const QString &name);
|
||||||
void setObjectSize(int ohfi, qint64 size);
|
void setObjectSize(int ohfi, qint64 size);
|
||||||
|
|
||||||
QMutex mutex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef struct {
|
typedef struct {
|
||||||
QList<CMAObject *>::const_iterator it;
|
QList<CMAObject *>::const_iterator it;
|
||||||
|
@@ -275,13 +275,6 @@ int SQLiteDB::recursiveScanRootDirectory(const QString &base_path, int parent, i
|
|||||||
return total_objects;
|
return total_objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SQLiteDB::getObjectMetadata(int ohfi, metadata_t &metadata)
|
|
||||||
{
|
|
||||||
Q_UNUSED(ohfi);
|
|
||||||
Q_UNUSED(metadata);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SQLiteDB::getPathId(const QString &path)
|
int SQLiteDB::getPathId(const QString &path)
|
||||||
{
|
{
|
||||||
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));
|
||||||
@@ -812,3 +805,70 @@ uint SQLiteDB::insertApplicationEntry(const QString &path, int type, int parent,
|
|||||||
db.commit();
|
db.commit();
|
||||||
return ohfi;
|
return ohfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool SQLiteDB::getObjectMetadata(int ohfi, metadata_t &metadata)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::childObjectCount(int parent_ohfi)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SQLiteDB::deleteEntry(int ohfi, int root_ohfi)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::getObjectMetadatas(int parent_ohfi, metadata_t **metadata, int index, int max_number)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
qint64 SQLiteDB::getObjectSize(int ohfi)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::getPathId(const char *name, int ohfi)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::insertObjectEntry(const QString &path, int parent_ohfi)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SQLiteDB::getAbsolutePath(int ohfi)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SQLiteDB::getRelativePath(int ohfi)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SQLiteDB::renameObject(int ohfi, const QString &name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SQLiteDB::setObjectSize(int ohfi, qint64 size)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::getRootId(int ohfi)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SQLiteDB::getParentId(int ohfi)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@@ -40,6 +40,20 @@ public:
|
|||||||
bool initialize();
|
bool initialize();
|
||||||
QSqlError getLastError();
|
QSqlError getLastError();
|
||||||
|
|
||||||
|
int childObjectCount(int parent_ohfi);
|
||||||
|
bool deleteEntry(int ohfi, int root_ohfi = 0);
|
||||||
|
QString getAbsolutePath(int ohfi);
|
||||||
|
bool getObjectMetadata(int ohfi, metadata_t &metadata);
|
||||||
|
int getObjectMetadatas(int parent_ohfi, metadata_t **metadata, int index = 0, int max_number = 0);
|
||||||
|
qint64 getObjectSize(int ohfi);
|
||||||
|
int getParentId(int ohfi);
|
||||||
|
int getPathId(const char *name, int ohfi);
|
||||||
|
QString getRelativePath(int ohfi);
|
||||||
|
int getRootId(int ohfi);
|
||||||
|
int insertObjectEntry(const QString &path, int parent_ohfi);
|
||||||
|
bool renameObject(int ohfi, const QString &name);
|
||||||
|
void setObjectSize(int ohfi, qint64 size);
|
||||||
|
|
||||||
int getPathId(const QString &path);
|
int getPathId(const QString &path);
|
||||||
QString getPathFromId(int ohfi);
|
QString getPathFromId(int ohfi);
|
||||||
bool updateSize(int ohfi, quint64 size);
|
bool updateSize(int ohfi, quint64 size);
|
||||||
@@ -53,8 +67,6 @@ public:
|
|||||||
uint insertSavedataEntry(const QString &path, int type, int parent);
|
uint insertSavedataEntry(const QString &path, int type, int parent);
|
||||||
uint insertApplicationEntry(const QString &path, int type, int parent, int app_type);
|
uint insertApplicationEntry(const QString &path, int type, int parent, int app_type);
|
||||||
|
|
||||||
bool getObjectMetadata(int ohfi, metadata_t &metadata);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int recursiveScanRootDirectory(const QString &base_path, int parent, int type);
|
int recursiveScanRootDirectory(const QString &base_path, int parent, int type);
|
||||||
uint insertDirectoryEntry(const QString &path, int type, int parent);
|
uint insertDirectoryEntry(const QString &path, int type, int parent);
|
||||||
|
Reference in New Issue
Block a user