From e9d46005dc57fb7227c7c4c234ac6aea6eedf3a5 Mon Sep 17 00:00:00 2001 From: codestation Date: Wed, 25 Dec 2013 21:46:42 -0430 Subject: [PATCH] Receive the onlineId earlier so it can be shown in the connection popup. USB: save the device name after exchanging capability info. WiFi: save the device name used in the device pairing phrase. --- src/capability.cpp | 5 +++++ src/capability.h | 12 ++++++------ src/cmaclient.cpp | 17 ++++++++++++++++- src/cmaclient.h | 1 + src/cmaevent.cpp | 6 ------ src/forms/backupmanagerform.cpp | 6 ++++-- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/capability.cpp b/src/capability.cpp index 7dc074e..de54333 100644 --- a/src/capability.cpp +++ b/src/capability.cpp @@ -113,3 +113,8 @@ capability_info_t *DeviceCapability::generate_pc_capability_info() pc_capabilities->functions = functions[0]; return pc_capabilities; } + +DeviceCapability::~DeviceCapability() +{ + VitaMTP_Data_Free_VitaInfo(&vita_info); +} diff --git a/src/capability.h b/src/capability.h index 066ec47..ff11816 100644 --- a/src/capability.h +++ b/src/capability.h @@ -26,20 +26,20 @@ class DeviceCapability { public: explicit DeviceCapability() {} + ~DeviceCapability(); bool exchangeInfo(vita_device_t *device); - //TODO: vita_info_t doesn't retrieve this info, update vitamtp to get it const char *getVersion() { - return ""; + return vita_info.responderVersion; } - const char *getProtocol() { - return ""; + int getProtocolVersion() { + return vita_info.protocolVersion; } const char *getOnlineId() { - return "PS Vita"; + return vita_info.onlineId; } const char *getModelInfo() { - return ""; + return vita_info.modelInfo; } private: diff --git a/src/cmaclient.cpp b/src/cmaclient.cpp index 4d73b51..b2d41a1 100644 --- a/src/cmaclient.cpp +++ b/src/cmaclient.cpp @@ -37,6 +37,8 @@ QMutex CmaClient::runner; QMutex CmaClient::cancel; QSemaphore CmaClient::sema; +QString CmaClient::tempOnlineId = QString(); + bool CmaClient::is_active = false; bool CmaClient::in_progress = false; int CmaClient::is_cancelled = false; @@ -117,8 +119,17 @@ void CmaClient::processNewConnection(vita_device_t *device) if(!vita_info.exchangeInfo(device)) { qCritical("Error while exchanging info with the vita"); } else { + QSettings settings; + // Conection successful, inform the user - emit deviceConnected(QString(tr("Connected to ")) + vita_info.getOnlineId()); + if(vita_info.getOnlineId() != NULL) { + settings.setValue("lastOnlineId", vita_info.getOnlineId()); + emit deviceConnected(QString(tr("Connected to %1 (PS Vita)")).arg(vita_info.getOnlineId())); + } else { + QString onlineId = settings.value("lastOnlineId", "default").toString(); + emit deviceConnected(QString(tr("Connected to %1 (PS Vita)")).arg(onlineId)); + } + enterEventLoop(device); } @@ -135,7 +146,9 @@ void CmaClient::processNewConnection(vita_device_t *device) void CmaClient::registrationComplete() { + QSettings settings; qDebug("Registration completed"); + settings.setValue("lastOnlineId", tempOnlineId); emit this_object->pinComplete(); } @@ -148,6 +161,8 @@ int CmaClient::deviceRegistered(const char *deviceid) int CmaClient::generatePin(wireless_vita_info_t *info, int *p_err) { + // save the device name in a temporal variable, just in case the pin is rejected + tempOnlineId = QString(info->name); qDebug("Registration request from %s (MAC: %s)", info->name, info->mac_addr); int pin = rand() % 10000 * 10000 | rand() % 10000; qDebug("Your registration PIN for %s is: %08d", info->name, pin); diff --git a/src/cmaclient.h b/src/cmaclient.h index 3b61efe..b8550ad 100644 --- a/src/cmaclient.h +++ b/src/cmaclient.h @@ -54,6 +54,7 @@ private: static void registrationComplete(); CmaBroadcast broadcast; + static QString tempOnlineId; //TODO: move all the control variables to the client manager class static bool is_active; diff --git a/src/cmaevent.cpp b/src/cmaevent.cpp index 8ab2731..482e026 100644 --- a/src/cmaevent.cpp +++ b/src/cmaevent.cpp @@ -609,12 +609,6 @@ void CmaEvent::vitaEventGetSettingInfo(vita_event_t *event, int eventId) QSettings settings; - // Always refresh the account name - if(qstrcmp(settingsinfo->current_account.userName, "mtpr3InvalidUserName") != 0) { - // wewt, the Vita didn't go full retard again - settings.setValue("lastOnlineId", settingsinfo->current_account.userName); - } - if(settings.value("lastAccountId").toString() != settingsinfo->current_account.accountId) { db->setUUID(settingsinfo->current_account.accountId); // set the database to be updated ASAP diff --git a/src/forms/backupmanagerform.cpp b/src/forms/backupmanagerform.cpp index 262a99d..10cc9fc 100644 --- a/src/forms/backupmanagerform.cpp +++ b/src/forms/backupmanagerform.cpp @@ -51,8 +51,6 @@ void BackupManagerForm::setupForm() connect(ui->backupComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(loadBackupListing(int))); ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); ui->tableWidget->horizontalHeader()->hide(); - // the the account name when vitamtp returns this value - ui->accountBox->addItem(QSettings().value("lastOnlineId", tr("Default account")).toString()); } void BackupManagerForm::removeEntry(BackupItem *item) @@ -99,6 +97,10 @@ void BackupManagerForm::loadBackupListing(int index) bool sys_dir; int img_width; + //TODO: load all the accounts in the combobox + ui->accountBox->clear(); + ui->accountBox->addItem(QSettings().value("lastOnlineId", tr("Default account")).toString()); + if(index < 0) { index = ui->backupComboBox->currentIndex(); }