Commit fa401b8f authored by Daniel Teske's avatar Daniel Teske
Browse files

AndroidDeviceDialog: Move default device selection into Dialog



Change-Id: Ib4a272eba1f1521c082ec519ef016ad5969eb527
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 828360d8
......@@ -1159,25 +1159,14 @@ AndroidDeviceInfo AndroidConfigurations::showDeviceDialog(Project *project,
Options options)
{
QString serialNumber = defaultDevice(project, abi);
if (!serialNumber.isEmpty()) {
// search for that device
foreach (const AndroidDeviceInfo &info, AndroidConfigurations::currentConfig().connectedDevices())
if (info.serialNumber == serialNumber
&& info.sdk >= apiLevel)
return info;
foreach (const AndroidDeviceInfo &info, AndroidConfigurations::currentConfig().androidVirtualDevices())
if (info.serialNumber == serialNumber
&& info.sdk >= apiLevel)
return info;
}
AndroidDeviceDialog dialog(apiLevel, abi, options, Core::ICore::mainWindow());
AndroidDeviceDialog dialog(apiLevel, abi, options, serialNumber, Core::ICore::mainWindow());
if (dialog.exec() == QDialog::Accepted) {
AndroidDeviceInfo info = dialog.device();
if (dialog.saveDeviceSelection()) {
if (!info.serialNumber.isEmpty())
AndroidConfigurations::setDefaultDevice(project, abi, info.serialNumber);
const QString serialNumber = info.type == AndroidDeviceInfo::Hardware ?
info.serialNumber : info.avdname;
if (!serialNumber.isEmpty())
AndroidConfigurations::setDefaultDevice(project, abi, serialNumber);
}
return info;
}
......
......@@ -420,12 +420,14 @@ static inline QString msgAdbListDevices()
return AndroidDeviceDialog::tr("<p>The adb tool in the Android SDK lists all connected devices if run via &quot;adb devices&quot;.</p>");
}
AndroidDeviceDialog::AndroidDeviceDialog(int apiLevel, const QString &abi, AndroidConfigurations::Options options, QWidget *parent) :
AndroidDeviceDialog::AndroidDeviceDialog(int apiLevel, const QString &abi, AndroidConfigurations::Options options,
const QString &serialNumber, QWidget *parent) :
QDialog(parent),
m_model(new AndroidDeviceModel(apiLevel, abi, options)),
m_ui(new Ui::AndroidDeviceDialog),
m_apiLevel(apiLevel),
m_abi(abi)
m_abi(abi),
m_defaultDevice(serialNumber)
{
m_ui->setupUi(this);
m_ui->deviceView->setModel(m_model);
......@@ -466,6 +468,19 @@ AndroidDeviceDialog::AndroidDeviceDialog(int apiLevel, const QString &abi, Andro
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Large, this);
m_progressIndicator->attachToWidget(m_ui->deviceView);
if (serialNumber.isEmpty()) {
m_ui->lookingForDevice->setVisible(false);
m_ui->lookingForDeviceCancel->setVisible(false);
} else {
m_ui->lookingForDevice->setVisible(true);
m_ui->lookingForDevice->setText(tr("Looking for default device <b>%1</b>.").arg(serialNumber));
m_ui->lookingForDeviceCancel->setVisible(true);
}
connect(m_ui->lookingForDeviceCancel, &QPushButton::clicked,
this, &AndroidDeviceDialog::defaultDeviceClear);
m_defaultDeviceTimer.start();
}
AndroidDeviceDialog::~AndroidDeviceDialog()
......@@ -523,17 +538,11 @@ void AndroidDeviceDialog::devicesRefreshed()
m_progressIndicator->hide();
QString serialNumber;
AndroidDeviceInfo::AndroidDeviceType deviceType;
if (!m_avdNameFromAdd.isEmpty()) {
serialNumber = m_avdNameFromAdd;
m_avdNameFromAdd.clear();
deviceType = AndroidDeviceInfo::Emulator;
} else {
QModelIndex currentIndex = m_ui->deviceView->currentIndex();
if (currentIndex.isValid()) {
AndroidDeviceInfo info = m_model->device(currentIndex);
deviceType = info.type;
serialNumber = deviceType == AndroidDeviceInfo::Hardware ? info.serialNumber : info.avdname;
}
QModelIndex currentIndex = m_ui->deviceView->currentIndex();
if (currentIndex.isValid()) { // save currently selected index
AndroidDeviceInfo info = m_model->device(currentIndex);
deviceType = info.type;
serialNumber = deviceType == AndroidDeviceInfo::Hardware ? info.serialNumber : info.avdname;
}
QVector<AndroidDeviceInfo> devices = m_futureWatcherRefreshDevices.result();
......@@ -545,7 +554,20 @@ void AndroidDeviceDialog::devicesRefreshed()
// Smartly select a index
QModelIndex newIndex;
if (!serialNumber.isEmpty())
if (!m_defaultDevice.isEmpty()) {
newIndex = m_model->indexFor(AndroidDeviceInfo::Hardware, m_defaultDevice);
if (!newIndex.isValid())
newIndex = m_model->indexFor(AndroidDeviceInfo::Emulator, m_defaultDevice);
if (!newIndex.isValid()) // not found the default device
defaultDeviceClear();
}
if (!newIndex.isValid() && !m_avdNameFromAdd.isEmpty()) {
newIndex = m_model->indexFor(AndroidDeviceInfo::Emulator, m_avdNameFromAdd);
m_avdNameFromAdd.clear();
}
if (!newIndex.isValid() && !serialNumber.isEmpty())
newIndex = m_model->indexFor(deviceType, serialNumber);
if (!newIndex.isValid() && !devices.isEmpty()) {
......@@ -559,6 +581,26 @@ void AndroidDeviceDialog::devicesRefreshed()
m_ui->stackedWidget->setCurrentIndex(devices.isEmpty() ? 1 : 0);
m_ui->refreshDevicesButton->setEnabled(true);
if (!m_defaultDevice.isEmpty()) {
int elapsed = m_defaultDeviceTimer.elapsed();
if (elapsed > 4000)
accept();
else
QTimer::singleShot(4000 - elapsed, this, &AndroidDeviceDialog::useDefaultDevice);
}
}
void AndroidDeviceDialog::useDefaultDevice()
{
if (m_defaultDevice.isEmpty())
return;
AndroidDeviceInfo info = m_model->device(m_ui->deviceView->currentIndex());
if (info.serialNumber == m_defaultDevice
|| info.avdname == m_defaultDevice)
accept();
else // something different is selected
defaultDeviceClear();
}
void AndroidDeviceDialog::createAvd()
......@@ -614,3 +656,10 @@ void AndroidDeviceDialog::showHelp()
pos = m_ui->missingLabel->parentWidget()->mapToGlobal(pos);
QToolTip::showText(pos, msgConnect() + msgAdbListDevices(), this);
}
void AndroidDeviceDialog::defaultDeviceClear()
{
m_ui->lookingForDevice->setVisible(false);
m_ui->lookingForDeviceCancel->setVisible(false);
m_defaultDevice.clear();
}
......@@ -36,6 +36,7 @@
#include <QVector>
#include <QDialog>
#include <QFutureWatcher>
#include <QTime>
QT_BEGIN_NAMESPACE
class QModelIndex;
......@@ -54,7 +55,8 @@ class AndroidDeviceDialog : public QDialog
Q_OBJECT
public:
explicit AndroidDeviceDialog(int apiLevel, const QString &abi, AndroidConfigurations::Options opts, QWidget *parent = 0);
explicit AndroidDeviceDialog(int apiLevel, const QString &abi, AndroidConfigurations::Options opts,
const QString &serialNumber, QWidget *parent = 0);
~AndroidDeviceDialog();
AndroidDeviceInfo device();
......@@ -74,6 +76,8 @@ private:
const Utils::Environment &environment);
void devicesRefreshed();
void enableOkayButton();
void useDefaultDevice();
void defaultDeviceClear();
AndroidDeviceModel *m_model;
Ui::AndroidDeviceDialog *m_ui;
......@@ -81,6 +85,8 @@ private:
int m_apiLevel;
QString m_abi;
QString m_avdNameFromAdd;
QString m_defaultDevice;
QTime m_defaultDeviceTimer;
QFutureWatcher<AndroidConfig::CreateAvdInfo> m_futureWatcherAddDevice;
QFutureWatcher<QVector<AndroidDeviceInfo>> m_futureWatcherRefreshDevices;
};
......
......@@ -6,53 +6,54 @@
<rect>
<x>0</x>
<y>0</y>
<width>636</width>
<height>438</height>
<width>788</width>
<height>466</height>
</rect>
</property>
<property name="windowTitle">
<string>Select Android Device</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="defaultDeviceCheckBox">
<property name="text">
<string>Always use this device for architecture %1</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="createAVDButton">
<property name="text">
<string>Create Android Virtual Device</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<item row="6" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="refreshDevicesButton">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="defaultDeviceCheckBox">
<property name="text">
<string>Refresh Device List</string>
<string>Always use this device for architecture %1</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<item row="0" column="0" colspan="4">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="devicesPage">
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QTreeView" name="deviceView">
<property name="minimumSize">
<size>
......@@ -62,7 +63,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="missingLabel">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;aaa&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0057ae;&quot;&gt;My device is missing&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
......@@ -72,10 +73,42 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lookingForDevice">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="lookingForDeviceCancel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="noDevicesPage">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="noDeviceFoundLabel">
<property name="text">
......@@ -96,6 +129,42 @@
</widget>
</widget>
</item>
<item row="8" column="0" colspan="4">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="createAVDButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Create Android Virtual Device</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="refreshDevicesButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Refresh Device List</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment