From 80f19e5d2343f5310877a5f3a617aa7ca62ef2d0 Mon Sep 17 00:00:00 2001 From: codestation Date: Fri, 28 Mar 2014 10:07:13 -0430 Subject: [PATCH] New qcma headless app. Updated changelog. Bumped version to 0.3.0. --- ChangeLog | 11 ++ qcma.pro | 181 ++-------------------------- qcma_cli.pro | 28 +++++ qcma_common.pri | 121 +++++++++++++++++++ qcma_gui.pro | 69 +++++++++++ src/cli/headlessmanager.cpp | 135 +++++++++++++++++++++ src/cli/headlessmanager.h | 62 ++++++++++ src/cli/main_cli.cpp | 115 ++++++++++++++++++ src/cli/singlecoreapplication.cpp | 69 +++++++++++ src/cli/singlecoreapplication.h | 50 ++++++++ src/cmaclient.cpp | 1 - src/cmaevent.cpp | 1 + src/forms/backupmanagerform.cpp | 4 +- src/forms/backupmanagerform.ui | 2 +- src/{ => gui}/clientmanager.cpp | 0 src/{ => gui}/clientmanager.h | 2 +- src/{ => gui}/filterlineedit.cpp | 0 src/{ => gui}/filterlineedit.h | 0 src/{ => gui}/kdenotifier.cpp | 0 src/{ => gui}/kdenotifier.h | 0 src/{ => gui}/main.cpp | 0 src/{ => gui}/mainwidget.cpp | 0 src/{ => gui}/mainwidget.h | 0 src/{ => gui}/singleapplication.cpp | 0 src/{ => gui}/singleapplication.h | 0 src/httpdownloader.cpp | 7 +- src/sqlitedb.cpp | 54 +++++---- 27 files changed, 712 insertions(+), 200 deletions(-) create mode 100644 qcma_cli.pro create mode 100644 qcma_common.pri create mode 100644 qcma_gui.pro create mode 100644 src/cli/headlessmanager.cpp create mode 100644 src/cli/headlessmanager.h create mode 100644 src/cli/main_cli.cpp create mode 100644 src/cli/singlecoreapplication.cpp create mode 100644 src/cli/singlecoreapplication.h rename src/{ => gui}/clientmanager.cpp (100%) rename src/{ => gui}/clientmanager.h (98%) rename src/{ => gui}/filterlineedit.cpp (100%) rename src/{ => gui}/filterlineedit.h (100%) rename src/{ => gui}/kdenotifier.cpp (100%) rename src/{ => gui}/kdenotifier.h (100%) rename src/{ => gui}/main.cpp (100%) rename src/{ => gui}/mainwidget.cpp (100%) rename src/{ => gui}/mainwidget.h (100%) rename src/{ => gui}/singleapplication.cpp (100%) rename src/{ => gui}/singleapplication.h (100%) diff --git a/ChangeLog b/ChangeLog index 5169916..988e997 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +qcma (0.3.0) unstable; urgency=low + + * Set the default video codec to h264 is metadata skip is enabled. + * Delay the progress dialog by one second so it doesn't show on quick scans. + * Do not show the disconnect message if no connection is established. + * Show correct directory separators on Windows. + * Show if savedata, updates or dlc are present on backup manager. + * New database backend. Disabled for now. + + -- codestation Thu, 28 Mar 2014 00:00:00 -0000 + qcma (0.2.8) unstable; urgency=low * Fixed bug where USB transfers couldn't be cancelled. diff --git a/qcma.pro b/qcma.pro index 4adebd9..724186a 100644 --- a/qcma.pro +++ b/qcma.pro @@ -1,176 +1,13 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2013-07-23T15:34:17 -# -#------------------------------------------------- +-#------------------------------------------------- +-# +-# Project created by QtCreator 2013-07-23T15:34:17 +-# +-#------------------------------------------------- -QT += core \ - gui \ - widgets \ - network \ - sql +TEMPLATE = subdirs +SUBDIRS = qcma_gui.pro -TARGET = qcma - -VERSION = 0.2.9 - -TEMPLATE = app - -SOURCES += src/main.cpp \ - src/capability.cpp \ - src/cmaobject.cpp \ - src/cmarootobject.cpp \ - src/cmautils.cpp \ - src/mainwidget.cpp \ - src/singleapplication.cpp \ - src/sforeader.cpp \ - src/cmaclient.cpp \ - src/cmabroadcast.cpp \ - src/avdecoder.cpp \ - src/cmaevent.cpp \ - src/clientmanager.cpp \ - src/filterlineedit.cpp \ - src/dds.cpp \ - src/sqlitedb.cpp \ - src/httpdownloader.cpp \ - src/qlistdb.cpp \ - src/database.cpp \ -# forms - src/forms/backupitem.cpp \ - src/forms/backupmanagerform.cpp \ - src/forms/configwidget.cpp \ - src/forms/confirmdialog.cpp \ - src/forms/pinform.cpp \ - src/forms/progressform.cpp - -HEADERS += \ - src/capability.h \ - src/cmaobject.h \ - src/cmarootobject.h \ - src/cmautils.h \ - src/mainwidget.h \ - src/singleapplication.h \ - src/sforeader.h \ - src/cmaclient.h \ - src/cmabroadcast.h \ - src/avdecoder.h \ - src/cmaevent.h \ - src/clientmanager.h \ - src/filterlineedit.h \ - src/dds.h \ - src/sqlitedb.h \ - src/httpdownloader.h \ - src/qlistdb.h \ - src/database.h \ -# forms - src/forms/backupitem.h \ - src/forms/backupmanagerform.h \ - src/forms/configwidget.h \ - src/forms/confirmdialog.h \ - src/forms/pinform.h \ - src/forms/progressform.h - -FORMS += \ - src/forms/configwidget.ui \ - src/forms/backupmanagerform.ui \ - src/forms/backupitem.ui \ - src/forms/confirmdialog.ui \ - src/forms/progressform.ui \ - src/forms/pinform.ui - -TRANSLATIONS += \ - resources/translations/qcma_es.ts \ - resources/translations/qcma_ja.ts - -OTHER_FILES += \ - resources/xml/psp2-updatelist.xml \ - resources/images/psv_icon.png \ - resources/images/psv_icon_16.png \ - resources/images/qcma.png \ - resources/qcma.desktop \ - qcma.rc - -INCLUDEPATH += src/ - -RESOURCES += qcmares.qrc translations.qrc - -# find packages using pkg-config -CONFIG += link_pkgconfig -PKGCONFIG += libvitamtp libavformat libavcodec libavutil libswscale - -# custom CXXFLAGS -QMAKE_CXXFLAGS += -Wno-write-strings -Wall -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS - -#Linux-only config +# Compile the headless binary only on Linux because it depends on dbus unix:!macx { - # largefile support - DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE - - # installation prefix - isEmpty(PREFIX) { - PREFIX = /usr/local - } - - BINDIR = $$PREFIX/bin - DATADIR = $$PREFIX/share - - # config for desktop file and icon - desktop.path = $$DATADIR/applications/$${TARGET} - desktop.files += resources/$${TARGET}.desktop - - icon64.path = $$DATADIR/icons/hicolor/64x64/apps - icon64.files += resources/images/$${TARGET}.png - - target.path = $$BINDIR - INSTALLS += target desktop icon64 - - # KDE support - ENABLE_KDE { - greaterThan(QT_MAJOR_VERSION, 4) { - error("ENABLE_KDE can only be used with Qt4") - } - LIBS += -lkdeui - DEFINES += ENABLE_KDE_NOTIFIER=1 - SOURCES += src/kdenotifier.cpp - HEADERS += src/kdenotifier.h - } -} - -# Windows config -win32 { - # Windows icon - RC_FILE = qcma.rc - # avoid alignment issues with newer mingw compiler - QMAKE_CXXFLAGS += -mno-ms-bitfields -} - -# OS X config -macx { - # OS X icon - ICON = resources/images/$${TARGET}.icns - # re-enable pkg-config on OS X (brew installs pkg-config files) - QT_CONFIG -= no-pkg-config -} - - -# try to get the current git version + hash -QCMA_GIT_VERSION=$$system(git describe --tags) - -#use the generic version if the above command fails (no git executable or metadata) -isEmpty(QCMA_GIT_VERSION) { - DEFINES += QCMA_VER=\\\"$$VERSION\\\" -} else { - DEFINES += QCMA_VER=\\\"$$QCMA_GIT_VERSION\\\" -} - -GET_HASHES { - # try to get the current git commit and branch - QCMA_GIT_HASH=$$system(git rev-parse --short HEAD) - QCMA_GIT_BRANCH=$$system(git rev-parse --abbrev-ref HEAD) - - # pass the current git commit hash - !isEmpty(QCMA_GIT_HASH):!isEmpty(QCMA_GIT_BRANCH) { - DEFINES += QCMA_BUILD_HASH=\\\"$$QCMA_GIT_HASH\\\" - DEFINES += QCMA_BUILD_BRANCH=\\\"$$QCMA_GIT_BRANCH\\\" - } + SUBDIRS += qcma_cli.pro } diff --git a/qcma_cli.pro b/qcma_cli.pro new file mode 100644 index 0000000..bd138b1 --- /dev/null +++ b/qcma_cli.pro @@ -0,0 +1,28 @@ +include(qcma_common.pri) + +QT += dbus + +TARGET = qcma_cli + +SOURCES += \ + src/cli/main_cli.cpp \ + src/cli/singlecoreapplication.cpp \ + src/cli/headlessmanager.cpp + +HEADERS += \ + src/cli/singlecoreapplication.h \ + src/cli/headlessmanager.h + +# Linux-only config +unix:!macx { + target.path = $$BINDIR + + INSTALLS += target +} + +# Create the introspection XML +system(qdbuscpp2xml -M -s src/cli/headlessmanager.h -o org.qcma.HeadlessManager.xml) + +# Create the helper class +DBUS_ADAPTORS = org.qcma.HeadlessManager.xml + diff --git a/qcma_common.pri b/qcma_common.pri new file mode 100644 index 0000000..567e478 --- /dev/null +++ b/qcma_common.pri @@ -0,0 +1,121 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-07-23T15:34:17 +# +#------------------------------------------------- + +QT += core \ + network \ + sql + +VERSION = 0.3.0 + +TEMPLATE = app + +SOURCES += \ + src/capability.cpp \ + src/cmaobject.cpp \ + src/cmarootobject.cpp \ + src/cmautils.cpp \ + src/sforeader.cpp \ + src/cmaclient.cpp \ + src/cmabroadcast.cpp \ + src/avdecoder.cpp \ + src/cmaevent.cpp \ + src/dds.cpp \ + src/sqlitedb.cpp \ + src/httpdownloader.cpp \ + src/qlistdb.cpp \ + src/database.cpp \ + +HEADERS += \ + src/capability.h \ + src/cmaobject.h \ + src/cmarootobject.h \ + src/cmautils.h \ + src/sforeader.h \ + src/cmaclient.h \ + src/cmabroadcast.h \ + src/avdecoder.h \ + src/cmaevent.h \ + src/dds.h \ + src/sqlitedb.h \ + src/httpdownloader.h \ + src/qlistdb.h \ + src/database.h \ + +TRANSLATIONS += \ + resources/translations/qcma_es.ts \ + resources/translations/qcma_ja.ts + +OTHER_FILES += \ + resources/xml/psp2-updatelist.xml \ + resources/images/psv_icon.png \ + resources/images/psv_icon_16.png \ + resources/images/qcma.png \ + resources/qcma.desktop \ + qcma.rc + +INCLUDEPATH += src/ + +RESOURCES += qcmares.qrc translations.qrc + +# find packages using pkg-config +CONFIG += link_pkgconfig +PKGCONFIG += libvitamtp libavformat libavcodec libavutil libswscale + +# custom CXXFLAGS +QMAKE_CXXFLAGS += -Wno-write-strings -Wall -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS + +#Linux-only config +unix:!macx { + # largefile support + DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE + + # installation prefix + isEmpty(PREFIX) { + PREFIX = /usr/local + } + + BINDIR = $$PREFIX/bin + DATADIR = $$PREFIX/share +} + +# Windows config +win32 { + # Windows icon + RC_FILE = qcma.rc + # avoid alignment issues with newer mingw compiler + QMAKE_CXXFLAGS += -mno-ms-bitfields +} + +# OS X config +macx { + # OS X icon + ICON = resources/images/$${TARGET}.icns + # re-enable pkg-config on OS X (brew installs pkg-config files) + QT_CONFIG -= no-pkg-config +} + + +# try to get the current git version + hash +QCMA_GIT_VERSION=$$system(git describe --tags) + +#use the generic version if the above command fails (no git executable or metadata) +isEmpty(QCMA_GIT_VERSION) { + DEFINES += QCMA_VER=\\\"$$VERSION\\\" +} else { + DEFINES += QCMA_VER=\\\"$$QCMA_GIT_VERSION\\\" +} + +GET_HASHES { + # try to get the current git commit and branch + QCMA_GIT_HASH=$$system(git rev-parse --short HEAD) + QCMA_GIT_BRANCH=$$system(git rev-parse --abbrev-ref HEAD) + + # pass the current git commit hash + !isEmpty(QCMA_GIT_HASH):!isEmpty(QCMA_GIT_BRANCH) { + DEFINES += QCMA_BUILD_HASH=\\\"$$QCMA_GIT_HASH\\\" + DEFINES += QCMA_BUILD_BRANCH=\\\"$$QCMA_GIT_BRANCH\\\" + } +} diff --git a/qcma_gui.pro b/qcma_gui.pro new file mode 100644 index 0000000..c86ff89 --- /dev/null +++ b/qcma_gui.pro @@ -0,0 +1,69 @@ +include(qcma_common.pri) + +TARGET = qcma + +QT += \ + gui \ + widgets + +SOURCES += \ + src/gui/main.cpp \ + src/gui/mainwidget.cpp \ + src/gui/singleapplication.cpp \ + src/gui/clientmanager.cpp \ + src/gui/filterlineedit.cpp \ +# forms + src/forms/backupitem.cpp \ + src/forms/backupmanagerform.cpp \ + src/forms/configwidget.cpp \ + src/forms/confirmdialog.cpp \ + src/forms/pinform.cpp \ + src/forms/progressform.cpp + +HEADERS += \ + src/gui/mainwidget.h \ + src/gui/singleapplication.h \ + src/gui/clientmanager.h \ + src/gui/filterlineedit.h \ +# forms + src/forms/backupitem.h \ + src/forms/backupmanagerform.h \ + src/forms/configwidget.h \ + src/forms/confirmdialog.h \ + src/forms/pinform.h \ + src/forms/progressform.h + +FORMS += \ + src/forms/configwidget.ui \ + src/forms/backupmanagerform.ui \ + src/forms/backupitem.ui \ + src/forms/confirmdialog.ui \ + src/forms/progressform.ui \ + src/forms/pinform.ui + +#Linux-only config +unix:!macx { + DATADIR = $$PREFIX/share + + # config for desktop file and icon + desktop.path = $$DATADIR/applications/$${TARGET} + desktop.files += resources/$${TARGET}.desktop + + icon64.path = $$DATADIR/icons/hicolor/64x64/apps + icon64.files += resources/images/$${TARGET}.png + + target.path = $$BINDIR + + INSTALLS += target desktop icon64 + + # KDE support + ENABLE_KDE { + greaterThan(QT_MAJOR_VERSION, 4) { + error("ENABLE_KDE can only be used with Qt4") + } + LIBS += -lkdeui + DEFINES += ENABLE_KDE_NOTIFIER=1 + SOURCES += src/kdenotifier.cpp + HEADERS += src/kdenotifier.h + } +} diff --git a/src/cli/headlessmanager.cpp b/src/cli/headlessmanager.cpp new file mode 100644 index 0000000..38334db --- /dev/null +++ b/src/cli/headlessmanager.cpp @@ -0,0 +1,135 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2013 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "cmaclient.h" +#include "cmautils.h" +#include "sqlitedb.h" +#include "qlistdb.h" +#include "headlessmanager.h" +#include "headlessmanager_adaptor.h" + +#include +#include +#include + +HeadlessManager::HeadlessManager(QObject *parent) : + QObject(parent), dbus_conn(QDBusConnection::sessionBus()) +{ + new HeadlessManagerAdaptor(this); + QDBusConnection dbus = QDBusConnection::sessionBus(); + // expose qcma over dbus so the database update can be triggered + dbus.registerObject("/HeadlessManager", this); + dbus.registerService("org.qcma.HeadlessManager"); +} + +HeadlessManager::~HeadlessManager() +{ + VitaMTP_Cleanup(); + delete m_db; +} + +void HeadlessManager::refreshDatabase() +{ + if(m_db->load()) { + return; + } + + if(!m_db->rescan()) { + qDebug("No PS Vita system has been registered"); + } +} + +void HeadlessManager::start() +{ + if(VitaMTP_Init() < 0) { + qDebug("Cannot initialize VitaMTP library"); + return; + } + + if(QSettings().value("useMemoryStorage", true).toBool()) { + m_db = new QListDB(); + } else { + m_db = new SQLiteDB(); + } + + // initializing database for the first use + refreshDatabase(); + + // send a signal over dbus of the connected peers knows when the update is finished + connect(m_db, SIGNAL(updated(int)), this, SIGNAL(databaseUpdated(int))); + + thread_count = 0; + qDebug("Starting cma threads"); + CmaClient *client; + QSettings settings; + + if(!settings.value("disableUSB", false).toBool()) { + usb_thread = new QThread(); + client = new CmaClient(m_db); + usb_thread->setObjectName("usb_thread"); + connect(usb_thread, SIGNAL(started()), client, SLOT(connectUsb())); + 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(refreshDatabase()), this, SLOT(refreshDatabase())); + + client->moveToThread(usb_thread); + usb_thread->start(); + thread_count++; + } + + if(!settings.value("disableWireless", false).toBool()) { + wireless_thread = new QThread(); + client = new CmaClient(m_db); + wireless_thread->setObjectName("wireless_thread"); + connect(wireless_thread, SIGNAL(started()), client, SLOT(connectWireless())); + 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(refreshDatabase()), this, SLOT(refreshDatabase())); + + client->moveToThread(wireless_thread); + wireless_thread->start(); + thread_count++; + } + + if(thread_count == 0) { + qDebug("You must enable at least USB or Wireless monitoring"); + } +} + +void HeadlessManager::stop() +{ + if(CmaClient::stop() < 0) { + QCoreApplication::quit(); + } +} + +void HeadlessManager::threadStopped() +{ + mutex.lock(); + if(--thread_count == 0) { + QCoreApplication::quit(); + } + mutex.unlock(); +} diff --git a/src/cli/headlessmanager.h b/src/cli/headlessmanager.h new file mode 100644 index 0000000..44c3733 --- /dev/null +++ b/src/cli/headlessmanager.h @@ -0,0 +1,62 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2013 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef HEADLESSMANAGER_H +#define HEADLESSMANAGER_H + +#include "database.h" + +#include +#include +#include + +class HeadlessManager : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.qcma.HeadlessManager") + +public: + explicit HeadlessManager(QObject *parent = 0); + ~HeadlessManager(); + + void start(); + +private: + int thread_count; + QMutex mutex; + + Database *m_db; + + QThread *usb_thread; + QThread *wireless_thread; + QDBusConnection dbus_conn; + +signals: + void stopped(); + Q_SCRIPTABLE void databaseUpdated(int count); + +public slots: + void refreshDatabase(); + void stop(); + +private slots: + void threadStopped(); +}; + +#endif // HEADLESSMANAGER_H diff --git a/src/cli/main_cli.cpp b/src/cli/main_cli.cpp new file mode 100644 index 0000000..beee358 --- /dev/null +++ b/src/cli/main_cli.cpp @@ -0,0 +1,115 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2013 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef Q_OS_WIN32 +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "singlecoreapplication.h" +#include "headlessmanager.h" + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +void noMessageOutput(QtMsgType type, const QMessageLogContext &, const QString & str) +{ + const char * msg = str.toStdString().c_str(); +#else +void noMessageOutput(QtMsgType type, const char *msg) +{ +#endif + Q_UNUSED(type); + Q_UNUSED(msg); +} + +int main(int argc, char *argv[]) +{ + if(SingleCoreApplication::sendMessage(QObject::tr("A instance of QCMA is already running"))) { + return 0; + } + + SingleCoreApplication app(argc, argv); + +#ifndef Q_OS_WIN32 + // FIXME: libmtp sends SIGPIPE if a socket write fails crashing the whole app + // the proper fix is to libmtp to handle the cancel properly or ignoring + // SIGPIPE on the socket + signal(SIGPIPE, SIG_IGN); +#endif + + if(app.arguments().contains("--with-debug")) { + VitaMTP_Set_Logging(VitaMTP_DEBUG); + } else if(app.arguments().contains("--verbose")) { + VitaMTP_Set_Logging(VitaMTP_VERBOSE); + } else { + VitaMTP_Set_Logging(VitaMTP_NONE); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + qInstallMessageHandler(noMessageOutput); +#else + qInstallMsgHandler(noMessageOutput); +#endif + } + +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); +#endif + + qDebug("Starting QCMA %s", QCMA_VER); + + QTranslator translator; + QString locale = QLocale().system().name(); + qDebug() << "Current locale:" << locale; + + if(app.arguments().contains("--set-locale")) { + int index = app.arguments().indexOf("--set-locale"); + if(index + 1 < app.arguments().length()) { + qDebug("Enforcing locale: %s", app.arguments().at(index + 1).toUtf8().data()); + locale = app.arguments().at(index + 1); + } + } + + if(translator.load("qcma_" + locale, ":/resources/translations")) { + app.installTranslator(&translator); + } else { + qDebug() << "Cannot load translation for locale:" << locale; + } + + 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 + app.setOrganizationName("qcma"); + app.setApplicationName("qcma"); + + HeadlessManager manager; + manager.start(); + + return app.exec(); +} diff --git a/src/cli/singlecoreapplication.cpp b/src/cli/singlecoreapplication.cpp new file mode 100644 index 0000000..8b37a58 --- /dev/null +++ b/src/cli/singlecoreapplication.cpp @@ -0,0 +1,69 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2013 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "singlecoreapplication.h" + +#include + +const int SingleCoreApplication::timeout = 500; +const QString SingleCoreApplication::SHARED_KEY = "QCMA_KEY"; + +SingleCoreApplication::SingleCoreApplication(int &argc, char **argv) : + QCoreApplication(argc, argv) +{ + server = new QLocalServer(this); + connect(server, SIGNAL(newConnection()), this, SLOT(receiveMessage())); + QLocalServer::removeServer(SHARED_KEY); + server->listen(SHARED_KEY); +} + +void SingleCoreApplication::receiveMessage() +{ + QLocalSocket *socket = server->nextPendingConnection(); + + if(!socket->waitForReadyRead(timeout)) { + qDebug() << socket->errorString(); + return; + } + + QByteArray byteArray = socket->readAll(); + QString message = QString::fromUtf8(byteArray.constData()); + emit messageAvailable(message); + socket->disconnectFromServer(); +} + +bool SingleCoreApplication::sendMessage(const QString &message) +{ + QLocalSocket socket; + socket.connectToServer(SHARED_KEY, QIODevice::WriteOnly); + + if(!socket.waitForConnected(timeout)) { + return false; + } + + socket.write(message.toUtf8()); + + if(!socket.waitForBytesWritten(timeout)) { + qDebug() << socket.errorString(); + return false; + } + + socket.disconnectFromServer(); + return true; +} diff --git a/src/cli/singlecoreapplication.h b/src/cli/singlecoreapplication.h new file mode 100644 index 0000000..4b6a154 --- /dev/null +++ b/src/cli/singlecoreapplication.h @@ -0,0 +1,50 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2013 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef SINGLECOREAPPLICATION_H +#define SINGLECOREAPPLICATION_H + +#include +#include +#include +#include + +class SingleCoreApplication : public QCoreApplication +{ + Q_OBJECT +public: + explicit SingleCoreApplication(int &argc, char **argv); + + static bool sendMessage(const QString &message); + +private: + QLocalServer *server; + + static const int timeout; + static const QString SHARED_KEY; + +signals: + void messageAvailable(QString message); + + +public slots: + void receiveMessage(); +}; + +#endif // SINGLECOREAPPLICATION_H diff --git a/src/cmaclient.cpp b/src/cmaclient.cpp index b843230..ce1d6c6 100644 --- a/src/cmaclient.cpp +++ b/src/cmaclient.cpp @@ -23,7 +23,6 @@ #include "cmaevent.h" #include "cmautils.h" -#include #include #include #include diff --git a/src/cmaevent.cpp b/src/cmaevent.cpp index d504b67..ac88139 100644 --- a/src/cmaevent.cpp +++ b/src/cmaevent.cpp @@ -504,6 +504,7 @@ void CmaEvent::vitaEventSendHttpObjectFromURL(vita_event_t *event, int eventId) data = res.readAll(); } else if(!offlineMode) { + qDebug("URL: %s", url); HTTPDownloader downloader(url); QThread *http_thread = new QThread(); http_thread->setObjectName("http_thread"); diff --git a/src/forms/backupmanagerform.cpp b/src/forms/backupmanagerform.cpp index 3f83244..230fd4d 100644 --- a/src/forms/backupmanagerform.cpp +++ b/src/forms/backupmanagerform.cpp @@ -23,7 +23,7 @@ #include "sforeader.h" #include "confirmdialog.h" #include "cmautils.h" -#include "filterlineedit.h" +#include "gui/filterlineedit.h" #include #include @@ -143,7 +143,7 @@ void BackupManagerForm::loadBackupListing(int index) m_db->mutex.lock(); - // get the item list + // get the item list metadata_t *meta = NULL; int row_count = m_db->getObjectMetadatas(ohfi, &meta); ui->tableWidget->setRowCount(row_count); diff --git a/src/forms/backupmanagerform.ui b/src/forms/backupmanagerform.ui index c8b4505..e66d749 100644 --- a/src/forms/backupmanagerform.ui +++ b/src/forms/backupmanagerform.ui @@ -131,7 +131,7 @@ FilterLineEdit QLineEdit -
filterlineedit.h
+
gui/filterlineedit.h
diff --git a/src/clientmanager.cpp b/src/gui/clientmanager.cpp similarity index 100% rename from src/clientmanager.cpp rename to src/gui/clientmanager.cpp diff --git a/src/clientmanager.h b/src/gui/clientmanager.h similarity index 98% rename from src/clientmanager.h rename to src/gui/clientmanager.h index 40fa562..57b41df 100644 --- a/src/clientmanager.h +++ b/src/gui/clientmanager.h @@ -20,7 +20,7 @@ #ifndef CLIENTMANAGER_H #define CLIENTMANAGER_H -#include "qlistdb.h" +#include "database.h" #include "forms/pinform.h" #include "forms/progressform.h" diff --git a/src/filterlineedit.cpp b/src/gui/filterlineedit.cpp similarity index 100% rename from src/filterlineedit.cpp rename to src/gui/filterlineedit.cpp diff --git a/src/filterlineedit.h b/src/gui/filterlineedit.h similarity index 100% rename from src/filterlineedit.h rename to src/gui/filterlineedit.h diff --git a/src/kdenotifier.cpp b/src/gui/kdenotifier.cpp similarity index 100% rename from src/kdenotifier.cpp rename to src/gui/kdenotifier.cpp diff --git a/src/kdenotifier.h b/src/gui/kdenotifier.h similarity index 100% rename from src/kdenotifier.h rename to src/gui/kdenotifier.h diff --git a/src/main.cpp b/src/gui/main.cpp similarity index 100% rename from src/main.cpp rename to src/gui/main.cpp diff --git a/src/mainwidget.cpp b/src/gui/mainwidget.cpp similarity index 100% rename from src/mainwidget.cpp rename to src/gui/mainwidget.cpp diff --git a/src/mainwidget.h b/src/gui/mainwidget.h similarity index 100% rename from src/mainwidget.h rename to src/gui/mainwidget.h diff --git a/src/singleapplication.cpp b/src/gui/singleapplication.cpp similarity index 100% rename from src/singleapplication.cpp rename to src/gui/singleapplication.cpp diff --git a/src/singleapplication.h b/src/gui/singleapplication.h similarity index 100% rename from src/singleapplication.h rename to src/gui/singleapplication.h diff --git a/src/httpdownloader.cpp b/src/httpdownloader.cpp index 41c2510..0fe0a4c 100644 --- a/src/httpdownloader.cpp +++ b/src/httpdownloader.cpp @@ -42,6 +42,7 @@ HTTPDownloader::HTTPDownloader(const QString &url, QObject *parent) : HTTPDownloader::~HTTPDownloader() { lengthMutex.unlock(); + dataAvailable.unlock(); free(buffer); } @@ -105,6 +106,8 @@ void HTTPDownloader::readyRead() downloadLeft -= bufferSize; + //qDebug("bufferSize: %li, downloadLeft: %li", bufferSize, downloadLeft); + if(bufferSize > 16384 || downloadLeft == 0) { dataAvailable.unlock(); } @@ -149,8 +152,10 @@ int HTTPDownloader::readCallback(unsigned char *data, unsigned long wantlen, uns void HTTPDownloader::error(QNetworkReply::NetworkError errorCode) { Q_UNUSED(errorCode); + QString error = reply->errorString(); - emit messageSent(tr("Network error: %1").arg(reply->errorString())); + qWarning() << "Network error:" << error; + emit messageSent(tr("Network error: %1").arg(error)); // set buffer to zero so a read callback can be aborted dataRead.lock(); diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 039c248..064f42b 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -77,8 +77,8 @@ static const char create_apps[] = "CREATE TABLE IF NOT EXISTS application (" "app_type INTEGER)"; static const char create_virtual[] = "CREATE TABLE IF NOT EXISTS virtual_nodes (" - "object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE," - "app_type INTEGER)"; + "object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE," + "app_type INTEGER)"; static const char create_photos[] = "CREATE TABLE IF NOT EXISTS photos (" "object_id INTEGER PRIMARY KEY REFERENCES object_node(object_id) ON DELETE CASCADE," @@ -1246,55 +1246,65 @@ bool SQLiteDB::insertVirtualEntries() { int ohfi; - if((ohfi = insertNodeEntry("Folders", VITA_DIR_TYPE_MASK_REGULAR, Video)) > 0) + if((ohfi = insertNodeEntry("Folders", VITA_DIR_TYPE_MASK_REGULAR, Video)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("All", VITA_DIR_TYPE_MASK_ALL, Video)) > 0) + if((ohfi = insertNodeEntry("All", VITA_DIR_TYPE_MASK_ALL, Video)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Folders", VITA_DIR_TYPE_MASK_REGULAR, Photo)) > 0) + if((ohfi = insertNodeEntry("Folders", VITA_DIR_TYPE_MASK_REGULAR, Photo)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Month", VITA_DIR_TYPE_MASK_MONTH, Photo)) > 0) + if((ohfi = insertNodeEntry("Month", VITA_DIR_TYPE_MASK_MONTH, Photo)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("All", VITA_DIR_TYPE_MASK_ALL, Photo)) > 0) + if((ohfi = insertNodeEntry("All", VITA_DIR_TYPE_MASK_ALL, Photo)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Artists", VITA_DIR_TYPE_MASK_ARTISTS, Music)) > 0) + if((ohfi = insertNodeEntry("Artists", VITA_DIR_TYPE_MASK_ARTISTS, Music)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Albums", VITA_DIR_TYPE_MASK_ALBUMS, Music)) > 0) + if((ohfi = insertNodeEntry("Albums", VITA_DIR_TYPE_MASK_ALBUMS, Music)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Songs", VITA_DIR_TYPE_MASK_SONGS, Music)) > 0) + if((ohfi = insertNodeEntry("Songs", VITA_DIR_TYPE_MASK_SONGS, Music)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Genres", VITA_DIR_TYPE_MASK_GENRES, Music)) > 0) + if((ohfi = insertNodeEntry("Genres", VITA_DIR_TYPE_MASK_GENRES, Music)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } - if((ohfi = insertNodeEntry("Playlists", VITA_DIR_TYPE_MASK_PLAYLISTS, Music)) > 0) + if((ohfi = insertNodeEntry("Playlists", VITA_DIR_TYPE_MASK_PLAYLISTS, Music)) > 0) { insertVirtualEntry(ohfi); - else + } else { return false; + } return true; }