Allow choosing on which device to install
This commit is contained in:
+61
-21
@@ -32,6 +32,7 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QUrl>
|
||||
#include <QWizard>
|
||||
#include <algorithm>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "adb.h"
|
||||
@@ -183,6 +184,8 @@ wizard::wizard() :
|
||||
// Detect connected android devices
|
||||
connect(&adb_service, &adb::android_devices_changed, this, &wizard::on_android_device_list_changed);
|
||||
on_android_device_list_changed(adb_service.devices());
|
||||
|
||||
connect(ui->list_devices, &QListWidget::itemSelectionChanged, this, &wizard::on_selected_android_device_changed);
|
||||
}
|
||||
|
||||
void wizard::on_latest_release_finished()
|
||||
@@ -204,7 +207,7 @@ void wizard::on_latest_release_finished()
|
||||
if (latest_release == git_version)
|
||||
{
|
||||
// This is already the latest release
|
||||
ui->label_release_info->setText("This is the latest WiVRn release.");
|
||||
ui->label_release_info->setText(tr("This is the latest WiVRn release."));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -382,6 +385,7 @@ void wizard::on_page_changed(int id)
|
||||
|
||||
case wizard_page::sideload_devmode:
|
||||
setButtonLayout({QWizard::Stretch, QWizard::BackButton, QWizard::NextButton, QWizard::CancelButton});
|
||||
button(NextButton)->setEnabled(false);
|
||||
return;
|
||||
|
||||
case wizard_page::sideload_install:
|
||||
@@ -569,46 +573,82 @@ void wizard::on_download_finished()
|
||||
}
|
||||
}
|
||||
|
||||
void wizard::on_android_device_list_changed(const std::vector<adb::device>& new_devs)
|
||||
void wizard::on_android_device_list_changed(const std::vector<adb::device> & new_devs)
|
||||
{
|
||||
auto old_devs = android_devices;
|
||||
auto old_devs = std::move(android_devices);
|
||||
android_devices = new_devs;
|
||||
|
||||
if (android_devices.empty())
|
||||
{
|
||||
ui->label_device_detected->setText(tr("No device detected."));
|
||||
|
||||
if (currentId() == (int)wizard_page::sideload_devmode)
|
||||
button(NextButton)->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->label_device_detected->setText(tr("%n device(s) detected.", nullptr, android_devices.size()));
|
||||
|
||||
if (currentId() == (int)wizard_page::sideload_devmode)
|
||||
button(NextButton)->setEnabled(true);
|
||||
// Removed devices
|
||||
for (int i = 0; i < ui->list_devices->count();)
|
||||
{
|
||||
QListWidgetItem * item = ui->list_devices->item(i);
|
||||
|
||||
std::string serial = item->data(QListWidgetItem::UserType).toString().toStdString();
|
||||
|
||||
if (std::ranges::none_of(android_devices, [&](const adb::device & x) { return x.serial() == serial; }))
|
||||
delete item;
|
||||
else
|
||||
i++;
|
||||
}
|
||||
|
||||
// TODO show device list
|
||||
// Added devices
|
||||
for (const auto & i: android_devices)
|
||||
{
|
||||
if (std::ranges::none_of(old_devs, [&](const adb::device & x) { return x == i; }))
|
||||
{
|
||||
auto it = i.properties().find("model");
|
||||
|
||||
const std::string model = (it == i.properties().end()) ? "Unknown model (" + i.serial() + ")" : it->second;
|
||||
|
||||
QListWidgetItem * item = new QListWidgetItem(QString::fromStdString(model));
|
||||
|
||||
item->setData(QListWidgetItem::UserType, QString::fromStdString(i.serial()));
|
||||
|
||||
ui->list_devices->addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wizard::on_selected_android_device_changed()
|
||||
{
|
||||
if (ui->list_devices->currentItem())
|
||||
button(NextButton)->setEnabled(true);
|
||||
else
|
||||
button(NextButton)->setEnabled(false);
|
||||
}
|
||||
|
||||
void wizard::start_install()
|
||||
{
|
||||
if (android_devices.empty())
|
||||
QListWidgetItem * item = ui->list_devices->currentItem();
|
||||
|
||||
if (not item)
|
||||
{
|
||||
back();
|
||||
return;
|
||||
}
|
||||
|
||||
auto dev = android_devices.back(); // TODO choose device from device list
|
||||
process_adb_install = dev.install(apk_file.fileName().toStdString());
|
||||
const std::string serial = item->data(QListWidgetItem::UserType).toString().toStdString();
|
||||
|
||||
connect(process_adb_install.get(), &QProcess::finished, this, &wizard::on_install_finished);
|
||||
connect(process_adb_install.get(), &QProcess::readyReadStandardOutput, this, &wizard::on_install_stdout);
|
||||
connect(process_adb_install.get(), &QProcess::readyReadStandardError, this, &wizard::on_install_stderr);
|
||||
process_adb_install->setParent(this);
|
||||
process_adb_install->start();
|
||||
ui->adb_install_logs->setPlainText("");
|
||||
for (adb::device & i: android_devices)
|
||||
{
|
||||
if (i.serial() == serial)
|
||||
{
|
||||
process_adb_install = i.install(apk_file.fileName().toStdString());
|
||||
|
||||
connect(process_adb_install.get(), &QProcess::finished, this, &wizard::on_install_finished);
|
||||
connect(process_adb_install.get(), &QProcess::readyReadStandardOutput, this, &wizard::on_install_stdout);
|
||||
connect(process_adb_install.get(), &QProcess::readyReadStandardError, this, &wizard::on_install_stderr);
|
||||
process_adb_install->setParent(this);
|
||||
process_adb_install->start();
|
||||
ui->adb_install_logs->setPlainText("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wizard::on_install_stdout()
|
||||
|
||||
+2
-1
@@ -86,7 +86,8 @@ public:
|
||||
void on_download_error(QNetworkReply::NetworkError code);
|
||||
void on_download_finished();
|
||||
|
||||
void on_android_device_list_changed(const std::vector<adb::device>&);
|
||||
void on_android_device_list_changed(const std::vector<adb::device> &);
|
||||
void on_selected_android_device_changed();
|
||||
|
||||
void start_install();
|
||||
void on_install_finished(int exit_code, QProcess::ExitStatus exit_status);
|
||||
|
||||
+25
-3
@@ -280,7 +280,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@@ -293,18 +293,24 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<spacer name="verticalSpacer_13">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="list_devices"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWizardPage" name="page_4_sideload_install">
|
||||
@@ -335,6 +341,22 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="adb_install_logs">
|
||||
<property name="font">
|
||||
|
||||
Reference in New Issue
Block a user