Fix memory leaks.
Use "/" separator for internal cmaobject nodes. Use new vitamtp init function. Remove console config for Win32.
This commit is contained in:
@@ -80,8 +80,8 @@ bool DeviceCapability::exchangeInfo(vita_device_t *device)
|
||||
|
||||
void DeviceCapability::free_pc_capability_info(capability_info_t *info)
|
||||
{
|
||||
delete &info->functions.formats.next_item[-1];
|
||||
delete &info->functions.next_item[-1];
|
||||
delete[] &info->functions.formats.next_item[-1];
|
||||
delete[] &info->functions.next_item[-1];
|
||||
delete info;
|
||||
}
|
||||
|
||||
|
@@ -20,12 +20,18 @@
|
||||
#include "clientmanager.h"
|
||||
#include "progressform.h"
|
||||
#include "cmaclient.h"
|
||||
#include "utils.h"
|
||||
|
||||
ClientManager::ClientManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
ClientManager::~ClientManager()
|
||||
{
|
||||
VitaMTP_Cleanup();
|
||||
}
|
||||
|
||||
void ClientManager::databaseUpdated(int count)
|
||||
{
|
||||
progress.hide();
|
||||
@@ -44,6 +50,12 @@ void ClientManager::showPinDialog(QString name, int pin)
|
||||
|
||||
void ClientManager::start()
|
||||
{
|
||||
if(VitaMTP_Init() < 0)
|
||||
{
|
||||
emit messageSent(tr("Cannot initialize VitaMTP library"));
|
||||
return;
|
||||
}
|
||||
|
||||
// initializing database for the first use
|
||||
refreshDatabase();
|
||||
CmaEvent::db = &db;
|
||||
@@ -102,7 +114,9 @@ void ClientManager::refreshDatabase()
|
||||
|
||||
void ClientManager::stop()
|
||||
{
|
||||
CmaClient::stop();
|
||||
if(CmaClient::stop() < 0) {
|
||||
emit stopped();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientManager::threadStopped()
|
||||
|
@@ -32,6 +32,7 @@ class ClientManager : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientManager(QObject *parent = 0);
|
||||
~ClientManager();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
@@ -37,7 +37,7 @@ QMutex CmaClient::runner;
|
||||
QMutex CmaClient::cancel;
|
||||
QSemaphore CmaClient::sema;
|
||||
|
||||
bool CmaClient::is_active = true;
|
||||
bool CmaClient::is_active = false;
|
||||
bool CmaClient::in_progress = false;
|
||||
int CmaClient::is_cancelled = false;
|
||||
|
||||
@@ -53,12 +53,13 @@ void CmaClient::connectUsb()
|
||||
{
|
||||
vita_device_t *vita;
|
||||
|
||||
qDebug() << "Starting usb_thread:" << QThread::currentThreadId();
|
||||
qDebug("Starting usb_thread: %u", (unsigned int)QThread::currentThreadId());
|
||||
|
||||
setActive(true);
|
||||
|
||||
do {
|
||||
if((vita = VitaMTP_Get_First_USB_Vita()) !=NULL) {
|
||||
processNewConnection(vita);
|
||||
VitaMTP_Close_USB_Vita();
|
||||
} else {
|
||||
//TODO: replace this with an event-driven setup
|
||||
Sleeper::msleep(2000);
|
||||
@@ -83,7 +84,9 @@ void CmaClient::connectWireless()
|
||||
QTime now = QTime::currentTime();
|
||||
qsrand(now.msec());
|
||||
|
||||
qDebug() << "Starting wireless_thread:" << QThread::currentThreadId();
|
||||
qDebug("Starting wireless_thread: %u", (unsigned int)QThread::currentThreadId());
|
||||
|
||||
setActive(true);
|
||||
|
||||
do {
|
||||
if((vita = VitaMTP_Get_First_Wireless_Vita(&host, 0, CC::cancelCallback, CC::deviceRegistered, CC::generatePin, CC::registrationComplete)) != NULL) {
|
||||
@@ -109,17 +112,18 @@ void CmaClient::processNewConnection(vita_device_t *device)
|
||||
broadcast.setUnavailable();
|
||||
|
||||
qDebug("Vita connected: id %s", VitaMTP_Get_Identification(device));
|
||||
DeviceCapability *vita_info = new DeviceCapability();
|
||||
DeviceCapability vita_info;
|
||||
|
||||
if(!vita_info->exchangeInfo(device)) {
|
||||
if(!vita_info.exchangeInfo(device)) {
|
||||
qCritical("Error while exchanging info with the vita");
|
||||
} else {
|
||||
// Conection successful, inform the user
|
||||
emit deviceConnected(QString(tr("Connected to ")) + vita_info->getOnlineId());
|
||||
emit deviceConnected(QString(tr("Connected to ")) + vita_info.getOnlineId());
|
||||
enterEventLoop(device);
|
||||
}
|
||||
|
||||
VitaMTP_SendHostStatus(device, VITA_HOST_STATUS_EndConnection);
|
||||
qDebug("Releasing device...");
|
||||
VitaMTP_Release_Device(device);
|
||||
|
||||
emit deviceDisconnected();
|
||||
@@ -202,12 +206,16 @@ void CmaClient::enterEventLoop(vita_device_t *device)
|
||||
qDebug("Finishing event loop");
|
||||
}
|
||||
|
||||
void CmaClient::stop()
|
||||
int CmaClient::stop()
|
||||
{
|
||||
if(!isActive()) {
|
||||
return -1;
|
||||
}
|
||||
CmaClient::setActive(false);
|
||||
cancel.lock();
|
||||
is_cancelled = true;
|
||||
cancel.unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CmaClient::isActive()
|
||||
|
@@ -76,7 +76,7 @@ signals:
|
||||
void finished();
|
||||
|
||||
public slots:
|
||||
static void stop();
|
||||
static int stop();
|
||||
|
||||
private slots:
|
||||
void connectUsb();
|
||||
|
@@ -40,7 +40,7 @@ CmaEvent::CmaEvent(vita_device_t *s_device) :
|
||||
|
||||
void CmaEvent::process()
|
||||
{
|
||||
qDebug() << "Starting event_thread:" << QThread::currentThreadId();
|
||||
qDebug("Starting event_thread: %u", (unsigned int)QThread::currentThreadId());
|
||||
while(true) {
|
||||
sema.acquire();
|
||||
if(!isActive()) {
|
||||
|
@@ -185,7 +185,7 @@ void CMAObject::initObject(const QFileInfo &file, int file_type)
|
||||
if(parent->metadata.path == NULL) {
|
||||
metadata.path = strdup(metadata.name);
|
||||
} else {
|
||||
QString newpath = QString(parent->metadata.path) + QDir::separator() + metadata.name;
|
||||
QString newpath = QString(parent->metadata.path) + "/" + metadata.name;
|
||||
metadata.path = strdup(newpath.toUtf8().data());
|
||||
}
|
||||
|
||||
@@ -216,22 +216,22 @@ void CMAObject::rename(const QString &newname)
|
||||
metadata.name = strdup(newname.toUtf8().data());
|
||||
|
||||
if(metadata.path) {
|
||||
QStringList metadata_path(QString(metadata.path).split(QDir::separator()));
|
||||
QStringList metadata_path(QString(metadata.path).split("/"));
|
||||
metadata_path.replace(metadata_path.count() - 1, newname);
|
||||
free(metadata.path);
|
||||
metadata.path = strdup(metadata_path.join(QDir::separator()).toUtf8().data());
|
||||
metadata.path = strdup(metadata_path.join("/").toUtf8().data());
|
||||
}
|
||||
|
||||
path = QFileInfo(path).absoluteDir().path() + QDir::separator() + newname;
|
||||
path = QFileInfo(path).absoluteDir().path() + "/" + newname;
|
||||
}
|
||||
|
||||
void CMAObject::refreshPath()
|
||||
{
|
||||
if(parent) {
|
||||
free(metadata.path);
|
||||
QString newpath(QString(parent->metadata.path) + QDir::separator() + metadata.name);
|
||||
QString newpath(QString(parent->metadata.path) + "/" + metadata.name);
|
||||
metadata.path = strdup(newpath.toUtf8().data());
|
||||
path = parent->path + QDir::separator() + metadata.name;
|
||||
path = parent->path + "/" + metadata.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
4
main.cpp
4
main.cpp
@@ -71,12 +71,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
QTranslator translator;
|
||||
QString locale = QLocale().system().name();
|
||||
qDebug() << "Current locale:" << locale;
|
||||
qDebug("Current locale: %s", locale.toUtf8().data());
|
||||
if(translator.load("qcma." + locale, ":/main/resources/translations")) {
|
||||
app.installTranslator(&translator);
|
||||
}
|
||||
|
||||
qDebug() << "From main thread: "<< QThread::currentThreadId();
|
||||
qDebug("Starting main thread: %u", (unsigned int)QThread::currentThreadId());
|
||||
|
||||
// set the organization/application for QSettings to work properly
|
||||
app.setOrganizationName("qcma");
|
||||
|
Reference in New Issue
Block a user