Enable setting for skip metadata retrieval on database scanning.

Enabled settings for enabling/disabling USB/WiFi monitoring.
Make sure to init properly in the db multimedia files copied to the PC.
Translate system Qt widgets.
This commit is contained in:
codestation
2014-01-09 02:33:44 -04:30
parent 019d2a03a4
commit bc92743269
11 changed files with 161 additions and 111 deletions

View File

@@ -22,6 +22,8 @@
#include "utils.h"
#include "forms/progressform.h"
#include <QSettings>
#include <vitamtp.h>
ClientManager::ClientManager(QObject *parent) :
@@ -59,6 +61,7 @@ void ClientManager::start()
// initializing database for the first use
refreshDatabase();
CmaEvent::db = &db;
connect(&db, SIGNAL(fileAdded(QString)), &progress, SLOT(setFileName(QString)));
connect(&db, SIGNAL(directoryAdded(QString)), &progress, SLOT(setDirectoryName(QString)));
@@ -68,44 +71,53 @@ void ClientManager::start()
thread_count = 0;
qDebug("Starting cma threads");
CmaClient *client;
QSettings settings;
usb_thread = new QThread();
client = new CmaClient();
usb_thread->setObjectName("usb_thread");
connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb()));
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
connect(client, SIGNAL(finished()), usb_thread, SLOT(quit()), Qt::DirectConnection);
connect(usb_thread, SIGNAL(finished()), usb_thread, SLOT(deleteLater()));
connect(usb_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
connect(usb_thread, SIGNAL(finished()), client, SLOT(deleteLater()));
if(!settings.value("disableUSB", false).toBool()) {
usb_thread = new QThread();
client = new CmaClient();
usb_thread->setObjectName("usb_thread");
connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb()));
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
connect(client, SIGNAL(finished()), usb_thread, SLOT(quit()), Qt::DirectConnection);
connect(usb_thread, SIGNAL(finished()), usb_thread, SLOT(deleteLater()));
connect(usb_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
connect(usb_thread, SIGNAL(finished()), client, SLOT(deleteLater()));
connect(client, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString)));
connect(client, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected()));
connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));
connect(client, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString)));
connect(client, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected()));
connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));
client->moveToThread(usb_thread);
usb_thread->start();
thread_count++;
client->moveToThread(usb_thread);
usb_thread->start();
thread_count++;
}
wireless_thread = new QThread();
client = new CmaClient();
wireless_thread->setObjectName("wireless_thread");
connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless()));
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
connect(client, SIGNAL(receivedPin(QString,int)), this, SLOT(showPinDialog(QString,int)));
connect(client, SIGNAL(finished()), wireless_thread, SLOT(quit()), Qt::DirectConnection);
connect(wireless_thread, SIGNAL(finished()), wireless_thread, SLOT(deleteLater()));
connect(wireless_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
connect(wireless_thread, SIGNAL(finished()), client, SLOT(deleteLater()));
if(!settings.value("disableWireless", false).toBool()) {
wireless_thread = new QThread();
client = new CmaClient();
wireless_thread->setObjectName("wireless_thread");
connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless()));
connect(client, SIGNAL(messageSent(QString)), this, SIGNAL(messageSent(QString)));
connect(client, SIGNAL(receivedPin(QString,int)), this, SLOT(showPinDialog(QString,int)));
connect(client, SIGNAL(finished()), wireless_thread, SLOT(quit()), Qt::DirectConnection);
connect(wireless_thread, SIGNAL(finished()), wireless_thread, SLOT(deleteLater()));
connect(wireless_thread, SIGNAL(finished()), this, SLOT(threadStopped()));
connect(wireless_thread, SIGNAL(finished()), client, SLOT(deleteLater()));
connect(client, SIGNAL(pinComplete()), &pinForm, SLOT(hide()));
connect(client, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString)));
connect(client, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected()));
connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));
connect(client, SIGNAL(pinComplete()), &pinForm, SLOT(hide()));
connect(client, SIGNAL(deviceConnected(QString)), this, SIGNAL(deviceConnected(QString)));
connect(client, SIGNAL(deviceDisconnected()), this, SIGNAL(deviceDisconnected()));
connect(client, SIGNAL(refreshDatabase()), this, SLOT(refreshDatabase()));
client->moveToThread(wireless_thread);
wireless_thread->start();
thread_count++;
client->moveToThread(wireless_thread);
wireless_thread->start();
thread_count++;
}
if(thread_count == 0) {
emit messageSent(tr("You must enable at least USB or Wireless monitoring"));
}
}
void ClientManager::refreshDatabase()

View File

@@ -75,6 +75,7 @@ void CmaClient::connectUsb()
}
} while(isActive());
usbwait.unlock();
qDebug("Finishing usb_thread");
emit finished();
}

View File

@@ -154,7 +154,7 @@ quint16 CmaEvent::processAllObjects(CMAObject *parent, quint32 handle)
qDebug("Called %s, handle: %d, parent name: %s", Q_FUNC_INFO, handle, parent->metadata.name);
char *name;
uint64_t size;
int fileType = -1;
int dataType;
uint32_t *p_handles;
@@ -199,15 +199,26 @@ quint16 CmaEvent::processAllObjects(CMAObject *parent, quint32 handle)
delete m_file;
return PTP_RC_VITA_Invalid_Permission;
} else {
// the size gets ignored because we can also get it via info.size()
uint64_t size;
VitaMTP_GetObject_Callback(device, handle, &size, CmaEvent::writeCallback);
m_file->close();
delete m_file;
// get the root ohfi type
CMAObject *root_obj = parent;
while(root_obj->parent) {
root_obj = root_obj->parent;
}
fileType = Database::checkFileType(dir.absoluteFilePath(name), root_obj->metadata.ohfi);
}
}
QFileInfo info(dir, name);
object = new CMAObject(parent);
object->initObject(info);
object->initObject(info, fileType);
object->metadata.handle = handle;
db->append(parent->metadata.ohfi, object);
free(name);

View File

@@ -25,6 +25,7 @@
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include <QSettings>
int CMAObject::ohfi_count = OHFI_OFFSET;
@@ -83,9 +84,10 @@ CMAObject::~CMAObject()
void CMAObject::loadSfoMetadata(const QString &path)
{
QString sfo = QDir(path).absoluteFilePath("PARAM.SFO");
bool skipMetadata = QSettings().value("skipMetadata", false).toBool();
SfoReader reader;
if(reader.load(sfo)) {
if(!skipMetadata && reader.load(sfo)) {
metadata.data.saveData.title = strdup(reader.value("TITLE", ""));
//FIXME: disable savedata detail for now
//QString detail(reader.value("SAVEDATA_DETAIL", ""));
@@ -127,7 +129,9 @@ void CMAObject::loadSfoMetadata(const QString &path)
void CMAObject::loadMusicMetadata(const QString &path)
{
AVDecoder decoder;
if(decoder.open(path)) {
bool skipMetadata = QSettings().value("skipMetadata", false).toBool();
if(!skipMetadata && decoder.open(path)) {
decoder.getAudioMetadata(metadata);
} else {
metadata.data.music.album = strdup(parent->metadata.name ? parent->metadata.name : "");
@@ -139,7 +143,9 @@ void CMAObject::loadMusicMetadata(const QString &path)
void CMAObject::loadVideoMetadata(const QString &path)
{
AVDecoder decoder;
if(decoder.open(path)) {
bool skipMetadata = QSettings().value("skipMetadata", false).toBool();
if(!skipMetadata && decoder.open(path)) {
decoder.getVideoMetadata(metadata);
} else {
metadata.data.video.title = strdup(metadata.name);
@@ -151,7 +157,9 @@ void CMAObject::loadVideoMetadata(const QString &path)
void CMAObject::loadPhotoMetadata(const QString &path)
{
QImage img;
if(img.load(path)) {
bool skipMetadata = QSettings().value("skipMetadata", false).toBool();
if(!skipMetadata && img.load(path)) {
metadata.data.photo.tracks->data.track_photo.width = img.width();
metadata.data.photo.tracks->data.track_photo.height = img.height();
}
@@ -176,6 +184,12 @@ void CMAObject::initObject(const QFileInfo &file, int file_type)
metadata.data.saveData.statusType = 1;
loadSfoMetadata(file.absoluteFilePath());
} else if(MASK_SET(metadata.dataType, Music | File)) {
if(file_type < 0) {
qWarning("Invalid file type for music: %i, setting it to zero", file_type);
file_type = 0;
}
metadata.data.music.fileName = strdup(metadata.name);
metadata.data.music.fileFormatType = audio_list[file_type].file_format;
metadata.data.music.statusType = 1;
@@ -195,6 +209,12 @@ void CMAObject::initObject(const QFileInfo &file, int file_type)
metadata.data.video.tracks->type = VITA_TRACK_TYPE_VIDEO;
loadVideoMetadata(file.absoluteFilePath());
} else if(MASK_SET(metadata.dataType, Photo | File)) {
if(file_type < 0) {
qWarning("Invalid file type for photos: %i, setting it to zero", file_type);
file_type = 0;
}
metadata.data.photo.fileName = strdup(metadata.name);
metadata.data.photo.fileFormatType = photo_list[file_type].file_format;
metadata.data.photo.statusType = 1;

View File

@@ -53,6 +53,8 @@ public:
CMAObject *pathToObject(const char *path, int ohfiRoot);
int acceptFilteredObject(const CMAObject *parent, const CMAObject *current, int type);
static int checkFileType(const QString path, int ohfi_root);
QMutex mutex;
private:
@@ -74,7 +76,6 @@ private:
CMAObject *getParent(CMAObject *last_dir, const QString &current_path);
CMAObject *pathToObjectInternal(const root_list &list, const char *path);
static bool lessThanComparator(const CMAObject *a, const CMAObject *b);
int checkFileType(const QString path, int ohfi_root);
void dumpMetadataList(const metadata_t *p_head);
bool continueOperation();

View File

@@ -41,7 +41,7 @@ ConfigWidget::ConfigWidget(QWidget *parent) :
{
ui->setupUi(this);
connectSignals();
setDefaultDirs();
setDefaultData();
}
void ConfigWidget::connectSignals()
@@ -62,7 +62,7 @@ void ConfigWidget::connectSignals()
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void ConfigWidget::setDefaultDirs()
void ConfigWidget::setDefaultData()
{
QString defaultdir;
QSettings settings;
@@ -78,6 +78,11 @@ void ConfigWidget::setDefaultDirs()
defaultdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
defaultdir.append(QDir::separator()).append("PSV Updates");
ui->urlPath->setText(settings.value("urlPath", defaultdir).toString());
ui->offlineCheck->setChecked(settings.value("offlineMode", true).toBool());
ui->metadataCheck->setChecked(settings.value("skipMetadata", false).toBool());
ui->usbCheck->setChecked(settings.value("disableUSB", false).toBool());
ui->wifiCheck->setChecked(settings.value("disableWireless", false).toBool());
}
ConfigWidget::~ConfigWidget()
@@ -146,6 +151,10 @@ void ConfigWidget::accept()
savePath(settings, ui->appPath, "appsPath");
savePath(settings, ui->urlPath, "urlPath");
settings.setValue("offlineMode", ui->offlineCheck->isChecked());
settings.setValue("skipMetadata", ui->metadataCheck->isChecked());
settings.setValue("disableUSB", ui->usbCheck->isChecked());
settings.setValue("disableWireless", ui->wifiCheck->isChecked());
settings.sync();
done(Accepted);
}

View File

@@ -41,7 +41,7 @@ private:
enum browse_buttons {BTN_PHOTO, BTN_MUSIC, BTN_VIDEO, BTN_APPS, BTN_URL};
void connectSignals();
void setDefaultDirs();
void setDefaultData();
void savePath(QSettings &settings, const QLineEdit *edit, const QString &key);
Ui::ConfigWidget *ui;

View File

@@ -242,15 +242,26 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QCheckBox" name="metadataCheck">
<property name="text">
<string>Skip metadata extraction</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="usbCheck">
<property name="text">
<string>Disable USB monitoring</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wifiCheck">
<property name="text">
<string>Disable Wi-Fi monitoring</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="enabled">
@@ -261,26 +272,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Disable USB monitoring</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_5">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Disable Wi-Fi monitoring</string>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">

View File

@@ -22,6 +22,7 @@
#endif
#include <QDebug>
#include <QLibraryInfo>
#include <QLocale>
#include <QThread>
#include <QTranslator>
@@ -89,6 +90,10 @@ int main(int argc, char *argv[])
app.installTranslator(&translator);
}
QTranslator system_translator;
system_translator.load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&system_translator);
qDebug("Starting main thread: 0x%016" PRIxPTR, (uintptr_t)QThread::currentThreadId());
// set the organization/application for QSettings to work properly