Merge duplicated code from Database, CMAObject and SQListDB to utils.
Fix savedata metadata processing. Insert metadata from games/apps into the database.
This commit is contained in:
@@ -212,7 +212,7 @@ quint16 CmaEvent::processAllObjects(CMAObject *parent, quint32 handle)
|
|||||||
root_obj = root_obj->parent;
|
root_obj = root_obj->parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileType = Database::checkFileType(dir.absoluteFilePath(name), root_obj->metadata.ohfi);
|
fileType = checkFileType(dir.absoluteFilePath(name), root_obj->metadata.ohfi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,24 +29,6 @@
|
|||||||
|
|
||||||
int CMAObject::ohfi_count = OHFI_OFFSET;
|
int CMAObject::ohfi_count = OHFI_OFFSET;
|
||||||
|
|
||||||
const CMAObject::file_type CMAObject::audio_list[] = {
|
|
||||||
{"mp3", FILE_FORMAT_MP3, CODEC_TYPE_MP3},
|
|
||||||
{"mp4", FILE_FORMAT_MP4, CODEC_TYPE_AAC},
|
|
||||||
{"wav", FILE_FORMAT_WAV, CODEC_TYPE_PCM}
|
|
||||||
};
|
|
||||||
|
|
||||||
const CMAObject::file_type CMAObject::photo_list[] = {
|
|
||||||
{"jpg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
|
||||||
{"jpeg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
|
||||||
{"png", FILE_FORMAT_PNG, CODEC_TYPE_PNG},
|
|
||||||
{"tif", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
|
||||||
{"tiff", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
|
||||||
{"bmp", FILE_FORMAT_BMP, CODEC_TYPE_BMP},
|
|
||||||
{"gif", FILE_FORMAT_GIF, CODEC_TYPE_GIF},
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *CMAObject::video_list[] = {"mp4"};
|
|
||||||
|
|
||||||
CMAObject::CMAObject(CMAObject *obj_parent) :
|
CMAObject::CMAObject(CMAObject *obj_parent) :
|
||||||
parent(obj_parent), metadata()
|
parent(obj_parent), metadata()
|
||||||
{
|
{
|
||||||
|
@@ -27,26 +27,6 @@
|
|||||||
|
|
||||||
#define OHFI_OFFSET 256
|
#define OHFI_OFFSET 256
|
||||||
|
|
||||||
#define FILE_FORMAT_MP4 1
|
|
||||||
#define FILE_FORMAT_WAV 2
|
|
||||||
#define FILE_FORMAT_MP3 3
|
|
||||||
#define FILE_FORMAT_JPG 4
|
|
||||||
#define FILE_FORMAT_PNG 5
|
|
||||||
#define FILE_FORMAT_GIF 6
|
|
||||||
#define FILE_FORMAT_BMP 7
|
|
||||||
#define FILE_FORMAT_TIF 8
|
|
||||||
|
|
||||||
#define CODEC_TYPE_MPEG4 2
|
|
||||||
#define CODEC_TYPE_AVC 3
|
|
||||||
#define CODEC_TYPE_MP3 12
|
|
||||||
#define CODEC_TYPE_AAC 13
|
|
||||||
#define CODEC_TYPE_PCM 15
|
|
||||||
#define CODEC_TYPE_JPG 17
|
|
||||||
#define CODEC_TYPE_PNG 18
|
|
||||||
#define CODEC_TYPE_TIF 19
|
|
||||||
#define CODEC_TYPE_BMP 20
|
|
||||||
#define CODEC_TYPE_GIF 21
|
|
||||||
|
|
||||||
class CMAObject
|
class CMAObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -72,16 +52,6 @@ public:
|
|||||||
ohfi_count = OHFI_OFFSET;
|
ohfi_count = OHFI_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *file_ext;
|
|
||||||
int file_format;
|
|
||||||
int file_codec;
|
|
||||||
} file_type;
|
|
||||||
|
|
||||||
static const file_type audio_list[3];
|
|
||||||
static const file_type photo_list[7];
|
|
||||||
static const char *video_list[1];
|
|
||||||
|
|
||||||
QString path;
|
QString path;
|
||||||
CMAObject *parent;
|
CMAObject *parent;
|
||||||
metadata_t metadata;
|
metadata_t metadata;
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "cmaobject.h"
|
#include "cmaobject.h"
|
||||||
|
|
||||||
@@ -477,33 +478,3 @@ int Database::filterObjects(int ohfiParent, metadata_t **p_head, int index, int
|
|||||||
|
|
||||||
return numObjects;
|
return numObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Database::checkFileType(const QString path, int ohfi_root)
|
|
||||||
{
|
|
||||||
switch(ohfi_root) {
|
|
||||||
case VITA_OHFI_MUSIC:
|
|
||||||
for(int i = 0, max = sizeof(CMAObject::audio_list) / sizeof(CMAObject::file_type); i < max; i++) {
|
|
||||||
if(path.endsWith(CMAObject::audio_list[i].file_ext, Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VITA_OHFI_PHOTO:
|
|
||||||
for(int i = 0, max = sizeof(CMAObject::photo_list) / sizeof(CMAObject::file_type); i < max; i++) {
|
|
||||||
if(path.endsWith(CMAObject::photo_list[i].file_ext, Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VITA_OHFI_VIDEO:
|
|
||||||
for(int i = 0, max = sizeof(CMAObject::video_list) / sizeof(const char *); i < max; i++) {
|
|
||||||
if(path.endsWith(CMAObject::video_list[i], Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
@@ -53,8 +53,6 @@ public:
|
|||||||
CMAObject *pathToObject(const char *path, int ohfiRoot);
|
CMAObject *pathToObject(const char *path, int ohfiRoot);
|
||||||
int acceptFilteredObject(const CMAObject *parent, const CMAObject *current, int type);
|
int acceptFilteredObject(const CMAObject *parent, const CMAObject *current, int type);
|
||||||
|
|
||||||
static int checkFileType(const QString path, int ohfi_root);
|
|
||||||
|
|
||||||
QMutex mutex;
|
QMutex mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
207
src/sqlitedb.cpp
207
src/sqlitedb.cpp
@@ -1,3 +1,4 @@
|
|||||||
|
#include "utils.h"
|
||||||
#include "sqlitedb.h"
|
#include "sqlitedb.h"
|
||||||
#include "sforeader.h"
|
#include "sforeader.h"
|
||||||
#include "avdecoder.h"
|
#include "avdecoder.h"
|
||||||
@@ -50,6 +51,11 @@ static const char create_music[] = "CREATE TABLE IF NOT EXISTS music ("
|
|||||||
"album TEXT,"
|
"album TEXT,"
|
||||||
"track_number INTEGER)";
|
"track_number INTEGER)";
|
||||||
|
|
||||||
|
static const char create_apps[] = "CREATE TABLE IF NOT EXISTS application ("
|
||||||
|
"object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE,"
|
||||||
|
"title TEXT NOT NULL CHECK (LENGTH(title) > 0),"
|
||||||
|
"app_type INTEGER)";
|
||||||
|
|
||||||
static const char create_photos[] = "CREATE TABLE IF NOT EXISTS photos ("
|
static const char create_photos[] = "CREATE TABLE IF NOT EXISTS photos ("
|
||||||
"object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE,"
|
"object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE,"
|
||||||
"date_created TIMESTAMP,"
|
"date_created TIMESTAMP,"
|
||||||
@@ -99,56 +105,9 @@ static const char create_trigger_adjdel[] = "CREATE TRIGGER IF NOT EXISTS trg_ad
|
|||||||
"DELETE FROM object_node WHERE object_id = OLD.child_id AND reference_count <= 0;"
|
"DELETE FROM object_node WHERE object_id = OLD.child_id AND reference_count <= 0;"
|
||||||
"END";
|
"END";
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *file_ext;
|
|
||||||
int file_format;
|
|
||||||
int file_codec;
|
|
||||||
} file_type;
|
|
||||||
|
|
||||||
#define FILE_FORMAT_MP4 1
|
|
||||||
#define FILE_FORMAT_WAV 2
|
|
||||||
#define FILE_FORMAT_MP3 3
|
|
||||||
#define FILE_FORMAT_JPG 4
|
|
||||||
#define FILE_FORMAT_PNG 5
|
|
||||||
#define FILE_FORMAT_GIF 6
|
|
||||||
#define FILE_FORMAT_BMP 7
|
|
||||||
#define FILE_FORMAT_TIF 8
|
|
||||||
|
|
||||||
#define CODEC_TYPE_MPEG4 2
|
|
||||||
#define CODEC_TYPE_AVC 3
|
|
||||||
#define CODEC_TYPE_MP3 12
|
|
||||||
#define CODEC_TYPE_AAC 13
|
|
||||||
#define CODEC_TYPE_PCM 15
|
|
||||||
#define CODEC_TYPE_JPG 17
|
|
||||||
#define CODEC_TYPE_PNG 18
|
|
||||||
#define CODEC_TYPE_TIF 19
|
|
||||||
#define CODEC_TYPE_BMP 20
|
|
||||||
#define CODEC_TYPE_GIF 21
|
|
||||||
|
|
||||||
static const file_type audio_list[] = {
|
|
||||||
{"mp3", FILE_FORMAT_MP3, CODEC_TYPE_MP3},
|
|
||||||
{"mp4", FILE_FORMAT_MP4, CODEC_TYPE_AAC},
|
|
||||||
{"wav", FILE_FORMAT_WAV, CODEC_TYPE_PCM}
|
|
||||||
};
|
|
||||||
|
|
||||||
static const file_type photo_list[] = {
|
|
||||||
{"jpg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
|
||||||
{"jpeg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
|
||||||
{"png", FILE_FORMAT_PNG, CODEC_TYPE_PNG},
|
|
||||||
{"tif", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
|
||||||
{"tiff", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
|
||||||
{"bmp", FILE_FORMAT_BMP, CODEC_TYPE_BMP},
|
|
||||||
{"gif", FILE_FORMAT_GIF, CODEC_TYPE_GIF},
|
|
||||||
};
|
|
||||||
|
|
||||||
static const file_type video_list[] = {
|
|
||||||
{"mp4", FILE_FORMAT_MP4, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const char *table_list[] = {
|
static const char *table_list[] = {
|
||||||
create_adjacent, create_obj_node, create_sources,
|
create_adjacent, create_obj_node, create_sources,
|
||||||
create_music, create_photos, create_videos, create_savedata
|
create_music, create_photos, create_videos, create_savedata, create_apps
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *trigger_list[] = {
|
static const char *trigger_list[] = {
|
||||||
@@ -219,34 +178,6 @@ QSqlError SQLiteDB::getLastError()
|
|||||||
return db.lastError();
|
return db.lastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SQLiteDB::checkFileType(const QString path, int ohfi_root)
|
|
||||||
{
|
|
||||||
switch(ohfi_root) {
|
|
||||||
case VITA_OHFI_MUSIC:
|
|
||||||
for(int i = 0, max = sizeof(audio_list) / sizeof(file_type); i < max; i++) {
|
|
||||||
if(path.endsWith(audio_list[i].file_ext, Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VITA_OHFI_PHOTO:
|
|
||||||
for(int i = 0, max = sizeof(photo_list) / sizeof(file_type); i< max; i++) {
|
|
||||||
if(path.endsWith(photo_list[i].file_ext, Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VITA_OHFI_VIDEO:
|
|
||||||
for(int i = 0, max = sizeof(video_list) / sizeof(file_type); i< max; i++) {
|
|
||||||
if(path.endsWith(video_list[i].file_ext, Qt::CaseInsensitive)) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int SQLiteDB::create()
|
int SQLiteDB::create()
|
||||||
{
|
{
|
||||||
int total_objects = 0;
|
int total_objects = 0;
|
||||||
@@ -271,31 +202,26 @@ int SQLiteDB::create()
|
|||||||
base_path = settings.value("photoPath").toString();
|
base_path = settings.value("photoPath").toString();
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_BACKUP:
|
case VITA_OHFI_BACKUP:
|
||||||
continue;
|
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "SYSTEM" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "SYSTEM" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_VITAAPP:
|
case VITA_OHFI_VITAAPP:
|
||||||
continue;
|
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "APP" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "APP" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_PSPAPP:
|
case VITA_OHFI_PSPAPP:
|
||||||
continue;
|
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "PGAME" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "PGAME" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_PSPSAVE:
|
case VITA_OHFI_PSPSAVE:
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSAVEDATA" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSAVEDATA" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_PSXAPP:
|
case VITA_OHFI_PSXAPP:
|
||||||
continue;
|
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSGAME" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSGAME" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
case VITA_OHFI_PSMAPP:
|
case VITA_OHFI_PSMAPP:
|
||||||
continue;
|
|
||||||
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSM" + QDir::separator() + uuid;
|
base_path = settings.value("appsPath").toString() + QDir::separator() + "PSM" + QDir::separator() + uuid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dir_count = recursiveScanRootDirectory(base_path, ohfi_array[i], OBJECT_FOLDER);
|
int dir_count = recursiveScanRootDirectory(base_path, ohfi_array[i], ohfi_array[i]);
|
||||||
|
|
||||||
if(dir_count < 0) {
|
if(dir_count < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -314,7 +240,7 @@ int SQLiteDB::recursiveScanRootDirectory(const QString &base_path, int parent, i
|
|||||||
QFileInfoList qsl = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
|
QFileInfoList qsl = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
foreach(const QFileInfo &info, qsl) {
|
foreach(const QFileInfo &info, qsl) {
|
||||||
qDebug() << "Processing " << info.fileName();
|
//qDebug() << "Processing " << info.fileName();
|
||||||
if(info.isDir()) {
|
if(info.isDir()) {
|
||||||
int ohfi = insertDirectoryEntry(info.absoluteFilePath(), parent_type, parent);
|
int ohfi = insertDirectoryEntry(info.absoluteFilePath(), parent_type, parent);
|
||||||
total_objects += recursiveScanRootDirectory(info.absoluteFilePath(), ohfi, parent_type);
|
total_objects += recursiveScanRootDirectory(info.absoluteFilePath(), ohfi, parent_type);
|
||||||
@@ -332,6 +258,12 @@ int SQLiteDB::recursiveScanRootDirectory(const QString &base_path, int parent, i
|
|||||||
case VITA_OHFI_PSPSAVE:
|
case VITA_OHFI_PSPSAVE:
|
||||||
insertSavedataEntry(info.absoluteFilePath(), OBJECT_SAVEDATA | (parent_type & ~OBJECT_FOLDER), parent);
|
insertSavedataEntry(info.absoluteFilePath(), OBJECT_SAVEDATA | (parent_type & ~OBJECT_FOLDER), parent);
|
||||||
break;
|
break;
|
||||||
|
case VITA_OHFI_VITAAPP:
|
||||||
|
case VITA_OHFI_PSPAPP:
|
||||||
|
case VITA_OHFI_PSXAPP:
|
||||||
|
case VITA_OHFI_PSMAPP:
|
||||||
|
case VITA_OHFI_BACKUP:
|
||||||
|
insertApplicationEntry(info.absoluteFilePath(), OBJECT_APPLICATION | (parent_type & ~OBJECT_FOLDER), parent, parent_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
total_objects++;
|
total_objects++;
|
||||||
@@ -434,11 +366,11 @@ uint SQLiteDB::insertObjectEntry(const char *title, int type)
|
|||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|
||||||
query.prepare("SELECT object_id FROM object_node WHERE type == :type and title == :title");
|
//query.prepare("SELECT object_id FROM object_node WHERE type == :type and title == :title");
|
||||||
query.bindValue(0, type);
|
//query.bindValue(0, type);
|
||||||
query.bindValue(1, title);
|
//query.bindValue(1, title);
|
||||||
|
|
||||||
if(!query.exec() || !query.next()) {
|
//if(!query.exec() || !query.next()) {
|
||||||
query.prepare("INSERT INTO object_node (type, title) VALUES (:type, :title)");
|
query.prepare("INSERT INTO object_node (type, title) VALUES (:type, :title)");
|
||||||
query.bindValue(0, type);
|
query.bindValue(0, type);
|
||||||
query.bindValue(1, title);
|
query.bindValue(1, title);
|
||||||
@@ -446,7 +378,7 @@ uint SQLiteDB::insertObjectEntry(const char *title, int type)
|
|||||||
if(!query.exec() || !query.exec("SELECT last_insert_rowid()") || !query.next()) {
|
if(!query.exec() || !query.exec("SELECT last_insert_rowid()") || !query.next()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
|
|
||||||
return query.value(0).toInt();
|
return query.value(0).toInt();
|
||||||
}
|
}
|
||||||
@@ -481,7 +413,7 @@ uint SQLiteDB::insertMusicEntry(const QString &path, int type, int parent)
|
|||||||
const char *artist, *album, *albumartist, *genre, *track, *title;
|
const char *artist, *album, *albumartist, *genre, *track, *title;
|
||||||
int file_format, audio_codec, audio_bitrate, genre_id, artist_id, track_id, album_id, track_number;
|
int file_format, audio_codec, audio_bitrate, genre_id, artist_id, track_id, album_id, track_number;
|
||||||
|
|
||||||
int file_type = checkFileType(path, type);
|
int file_type = checkFileType(path, VITA_OHFI_MUSIC);
|
||||||
if(file_type < 0) {
|
if(file_type < 0) {
|
||||||
qDebug() << "Excluding from database:" << path;
|
qDebug() << "Excluding from database:" << path;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -497,12 +429,18 @@ uint SQLiteDB::insertMusicEntry(const QString &path, int type, int parent)
|
|||||||
albumartist = decoder.getMetadataEntry("album_artist");
|
albumartist = decoder.getMetadataEntry("album_artist");
|
||||||
track = decoder.getMetadataEntry("track");
|
track = decoder.getMetadataEntry("track");
|
||||||
|
|
||||||
track_number = QString(track).toInt(&ok);
|
track_number = QString(track).split("/")[0].toInt(&ok);
|
||||||
if(!ok) {
|
if(!ok) {
|
||||||
// set track number to 1 by default
|
// set track number to 1 by default
|
||||||
track_number = 1;
|
track_number = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(decoder.loadCodec(AVDecoder::CODEC_AUDIO)) {
|
||||||
audio_bitrate = decoder.getBitrate();
|
audio_bitrate = decoder.getBitrate();
|
||||||
|
} else {
|
||||||
|
audio_bitrate = 0;
|
||||||
|
}
|
||||||
|
|
||||||
duration = decoder.getDuration();
|
duration = decoder.getDuration();
|
||||||
|
|
||||||
file_format = audio_list[file_type].file_format;
|
file_format = audio_list[file_type].file_format;
|
||||||
@@ -616,7 +554,7 @@ uint SQLiteDB::insertVideoEntry(const QString &path, int type, int parent)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_type = checkFileType(path, type);
|
int file_type = checkFileType(path, VITA_OHFI_VIDEO);
|
||||||
if(file_type < 0) {
|
if(file_type < 0) {
|
||||||
qDebug() << "Excluding from database:" << path;
|
qDebug() << "Excluding from database:" << path;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -628,13 +566,13 @@ uint SQLiteDB::insertVideoEntry(const QString &path, int type, int parent)
|
|||||||
width = decoder.getWidth();
|
width = decoder.getWidth();
|
||||||
height = decoder.getHeight();
|
height = decoder.getHeight();
|
||||||
duration = decoder.getDuration();
|
duration = decoder.getDuration();
|
||||||
video_codec = 3;
|
video_codec = CODEC_TYPE_AVC;
|
||||||
video_bitrate = decoder.getCodecBitrate();
|
video_bitrate = decoder.getBitrate();
|
||||||
file_format = video_list[file_type].file_format;
|
file_format = video_list[file_type].file_format;
|
||||||
|
|
||||||
if(decoder.loadCodec(AVDecoder::CODEC_AUDIO)) {
|
if(decoder.loadCodec(AVDecoder::CODEC_AUDIO)) {
|
||||||
audio_codec = 13;
|
audio_codec = CODEC_TYPE_AAC;
|
||||||
audio_bitrate = decoder.getCodecBitrate();
|
audio_bitrate = decoder.getBitrate();
|
||||||
} else {
|
} else {
|
||||||
audio_codec = 0;
|
audio_codec = 0;
|
||||||
audio_bitrate = 0;
|
audio_bitrate = 0;
|
||||||
@@ -696,7 +634,7 @@ uint SQLiteDB::insertPhotoEntry(const QString &path, int type, int parent)
|
|||||||
uint date_created;
|
uint date_created;
|
||||||
int width, height, file_format, photo_codec;
|
int width, height, file_format, photo_codec;
|
||||||
|
|
||||||
int file_type = checkFileType(path, type);
|
int file_type = checkFileType(path, VITA_OHFI_PHOTO);
|
||||||
if(file_type < 0) {
|
if(file_type < 0) {
|
||||||
qDebug() << "Excluding from database:" << path;
|
qDebug() << "Excluding from database:" << path;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -755,25 +693,24 @@ uint SQLiteDB::insertPhotoEntry(const QString &path, int type, int parent)
|
|||||||
uint SQLiteDB::insertSavedataEntry(const QString &path, int type, int parent)
|
uint SQLiteDB::insertSavedataEntry(const QString &path, int type, int parent)
|
||||||
{
|
{
|
||||||
int ohfi;
|
int ohfi;
|
||||||
|
|
||||||
uint date_updated;
|
|
||||||
const char *title, *savedata_detail, *savedata_directory;
|
|
||||||
|
|
||||||
SfoReader reader;
|
SfoReader reader;
|
||||||
QString base_name = QFileInfo(path).baseName();
|
uint date_updated = 0;
|
||||||
QString sfo_file = QDir(path).absoluteFilePath("PARAM.SFO");
|
const char *title = NULL;
|
||||||
|
const char *savedata_detail = NULL;
|
||||||
|
const char *savedata_directory = NULL;
|
||||||
|
|
||||||
if(!reader.load(sfo_file)) {
|
QString file_name = QFileInfo(path).fileName();
|
||||||
return 0;
|
QByteArray utf8name = file_name.toUtf8();
|
||||||
}
|
|
||||||
|
|
||||||
title = reader.value("TITLE", base_name.toUtf8().constData());
|
|
||||||
savedata_detail = reader.value("SAVEDATA_DETAIL", "");
|
|
||||||
savedata_directory = reader.value("SAVEDATA_DIRECTORY", base_name.toUtf8().constData());
|
|
||||||
date_updated = QFileInfo(sfo_file).lastModified().toTime_t();
|
|
||||||
|
|
||||||
db.transaction();
|
db.transaction();
|
||||||
|
|
||||||
|
if(file_name.endsWith(".sfo", Qt::CaseInsensitive) && reader.load(path)) {
|
||||||
|
title = reader.value("TITLE", utf8name.constData());
|
||||||
|
savedata_detail = reader.value("SAVEDATA_DETAIL", "");
|
||||||
|
savedata_directory = reader.value("SAVEDATA_DIRECTORY", utf8name.constData());
|
||||||
|
date_updated = QFileInfo(path).lastModified().toTime_t();
|
||||||
|
}
|
||||||
|
|
||||||
if((ohfi = insertObjectEntry(title, type)) == 0) {
|
if((ohfi = insertObjectEntry(title, type)) == 0) {
|
||||||
db.rollback();
|
db.rollback();
|
||||||
return 0;
|
return 0;
|
||||||
@@ -789,6 +726,14 @@ uint SQLiteDB::insertSavedataEntry(const QString &path, int type, int parent)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!path.endsWith(".sfo", Qt::CaseInsensitive)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!title) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("REPLACE INTO savedata"
|
query.prepare("REPLACE INTO savedata"
|
||||||
"(object_id, detail, dir_name, title, date_updated)"
|
"(object_id, detail, dir_name, title, date_updated)"
|
||||||
@@ -808,3 +753,45 @@ uint SQLiteDB::insertSavedataEntry(const QString &path, int type, int parent)
|
|||||||
db.commit();
|
db.commit();
|
||||||
return ohfi;
|
return ohfi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint SQLiteDB::insertApplicationEntry(const QString &path, int type, int parent, int app_type)
|
||||||
|
{
|
||||||
|
int ohfi;
|
||||||
|
|
||||||
|
QString base_name = QFileInfo(path).baseName();
|
||||||
|
|
||||||
|
db.transaction();
|
||||||
|
|
||||||
|
if((ohfi = insertObjectEntry(base_name.toUtf8().constData(), type)) == 0) {
|
||||||
|
db.rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(parent && !updateAdjacencyList(ohfi, parent)) {
|
||||||
|
db.rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!insertSourceEntry(ohfi, path)) {
|
||||||
|
db.rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("REPLACE INTO application"
|
||||||
|
"(object_id, title, app_type)"
|
||||||
|
"VALUES (:object_id, :title, :app_type)");
|
||||||
|
|
||||||
|
query.bindValue(0, ohfi);
|
||||||
|
query.bindValue(1, base_name);
|
||||||
|
query.bindValue(2, app_type);
|
||||||
|
|
||||||
|
if(!query.exec()) {
|
||||||
|
db.rollback();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.commit();
|
||||||
|
return ohfi;
|
||||||
|
}
|
||||||
|
@@ -23,6 +23,8 @@
|
|||||||
#define OBJECT_SAVEDATA 0x00040000
|
#define OBJECT_SAVEDATA 0x00040000
|
||||||
#define OBJECT_SAVEDATA_FILE 0x00000002
|
#define OBJECT_SAVEDATA_FILE 0x00000002
|
||||||
|
|
||||||
|
#define OBJECT_APPLICATION 0x00080000
|
||||||
|
|
||||||
class SQLiteDB : public QObject
|
class SQLiteDB : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -47,11 +49,11 @@ public:
|
|||||||
uint insertVideoEntry(const QString &path, int type, int parent);
|
uint insertVideoEntry(const QString &path, int type, int parent);
|
||||||
uint insertPhotoEntry(const QString &path, int type, int parent);
|
uint insertPhotoEntry(const QString &path, int type, int parent);
|
||||||
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);
|
||||||
|
|
||||||
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);
|
||||||
int checkFileType(const QString path, int ohfi_root);
|
|
||||||
bool updateAdjacencyList(int ohfi, int parent);
|
bool updateAdjacencyList(int ohfi, int parent);
|
||||||
|
|
||||||
QString uuid;
|
QString uuid;
|
||||||
|
@@ -31,6 +31,26 @@
|
|||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const file_type audio_list[] = {
|
||||||
|
{"mp3", FILE_FORMAT_MP3, CODEC_TYPE_MP3},
|
||||||
|
{"mp4", FILE_FORMAT_MP4, CODEC_TYPE_AAC},
|
||||||
|
{"wav", FILE_FORMAT_WAV, CODEC_TYPE_PCM}
|
||||||
|
};
|
||||||
|
|
||||||
|
const file_type photo_list[] = {
|
||||||
|
{"jpg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
||||||
|
{"jpeg", FILE_FORMAT_JPG, CODEC_TYPE_JPG},
|
||||||
|
{"png", FILE_FORMAT_PNG, CODEC_TYPE_PNG},
|
||||||
|
{"tif", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
||||||
|
{"tiff", FILE_FORMAT_TIF, CODEC_TYPE_TIF},
|
||||||
|
{"bmp", FILE_FORMAT_BMP, CODEC_TYPE_BMP},
|
||||||
|
{"gif", FILE_FORMAT_GIF, CODEC_TYPE_GIF},
|
||||||
|
};
|
||||||
|
|
||||||
|
const file_type video_list[] = {
|
||||||
|
{"mp4", FILE_FORMAT_MP4, 0}
|
||||||
|
};
|
||||||
|
|
||||||
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total)
|
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@@ -175,3 +195,33 @@ QString readable_size(quint64 size, bool use_gib)
|
|||||||
}
|
}
|
||||||
return QString().setNum(size_f,'f',2) + " " + unit;
|
return QString().setNum(size_f,'f',2) + " " + unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int checkFileType(const QString path, int ohfi_root)
|
||||||
|
{
|
||||||
|
switch(ohfi_root) {
|
||||||
|
case VITA_OHFI_MUSIC:
|
||||||
|
for(int i = 0, max = sizeof(audio_list) / sizeof(file_type); i < max; i++) {
|
||||||
|
if(path.endsWith(audio_list[i].file_ext, Qt::CaseInsensitive)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VITA_OHFI_PHOTO:
|
||||||
|
for(int i = 0, max = sizeof(photo_list) / sizeof(file_type); i< max; i++) {
|
||||||
|
if(path.endsWith(photo_list[i].file_ext, Qt::CaseInsensitive)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VITA_OHFI_VIDEO:
|
||||||
|
for(int i = 0, max = sizeof(video_list) / sizeof(file_type); i< max; i++) {
|
||||||
|
if(path.endsWith(video_list[i].file_ext, Qt::CaseInsensitive)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
31
src/utils.h
31
src/utils.h
@@ -26,6 +26,36 @@
|
|||||||
|
|
||||||
#include <vitamtp.h>
|
#include <vitamtp.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *file_ext;
|
||||||
|
int file_format;
|
||||||
|
int file_codec;
|
||||||
|
} file_type;
|
||||||
|
|
||||||
|
#define FILE_FORMAT_MP4 1
|
||||||
|
#define FILE_FORMAT_WAV 2
|
||||||
|
#define FILE_FORMAT_MP3 3
|
||||||
|
#define FILE_FORMAT_JPG 4
|
||||||
|
#define FILE_FORMAT_PNG 5
|
||||||
|
#define FILE_FORMAT_GIF 6
|
||||||
|
#define FILE_FORMAT_BMP 7
|
||||||
|
#define FILE_FORMAT_TIF 8
|
||||||
|
|
||||||
|
#define CODEC_TYPE_MPEG4 2
|
||||||
|
#define CODEC_TYPE_AVC 3
|
||||||
|
#define CODEC_TYPE_MP3 12
|
||||||
|
#define CODEC_TYPE_AAC 13
|
||||||
|
#define CODEC_TYPE_PCM 15
|
||||||
|
#define CODEC_TYPE_JPG 17
|
||||||
|
#define CODEC_TYPE_PNG 18
|
||||||
|
#define CODEC_TYPE_TIF 19
|
||||||
|
#define CODEC_TYPE_BMP 20
|
||||||
|
#define CODEC_TYPE_GIF 21
|
||||||
|
|
||||||
|
extern const file_type audio_list[3];
|
||||||
|
extern const file_type photo_list[7];
|
||||||
|
extern const file_type video_list[1];
|
||||||
|
|
||||||
// Qt4 doesn't have public methods for Thread::*sleep
|
// Qt4 doesn't have public methods for Thread::*sleep
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||||
typedef QThread Sleeper;
|
typedef QThread Sleeper;
|
||||||
@@ -49,5 +79,6 @@ bool removeRecursively(const QString &dirName);
|
|||||||
QString readable_size(quint64 size, bool use_gib = false);
|
QString readable_size(quint64 size, bool use_gib = false);
|
||||||
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total);
|
bool getDiskSpace(const QString &dir, quint64 *free, quint64 *total);
|
||||||
QByteArray getThumbnail(const QString &path, DataType type, metadata_t *metadata);
|
QByteArray getThumbnail(const QString &path, DataType type, metadata_t *metadata);
|
||||||
|
int checkFileType(const QString path, int ohfi_root);
|
||||||
|
|
||||||
#endif // UTILS_H
|
#endif // UTILS_H
|
||||||
|
Reference in New Issue
Block a user