-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdbSelectDeviceDialog.cpp
77 lines (65 loc) · 2.01 KB
/
AdbSelectDeviceDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "AdbSelectDeviceDialog.h"
#include "ui_AdbSelectDeviceDialog.h"
#include <QProcess>
#include <QTableWidgetItem>
#include <QDebug>
#include "AdbWrapper.h"
AdbSelectDeviceDialog::AdbSelectDeviceDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AdbSelectDeviceDialog)
{
ui->setupUi(this);
scan();
}
AdbSelectDeviceDialog::~AdbSelectDeviceDialog()
{
delete ui;
}
QString AdbSelectDeviceDialog::selectedDeviceId()
{
if( !ui->tableWidget->rowCount() ) return "";
else return ui->tableWidget->selectedItems().at( 0 )->text();
}
void AdbSelectDeviceDialog::on_pushButtonRefresh_clicked()
{
setCursor( Qt::WaitCursor );
reset();
scan();
unsetCursor();
}
void AdbSelectDeviceDialog::scan()
{
while( ui->tableWidget->rowCount() ) ui->tableWidget->removeRow( 0 );
AdbWrapper *adbWrap = new AdbWrapper( this );
QStringList deviceList = adbWrap->deviceList();
delete adbWrap;
foreach( QString device, deviceList )
{
QString serial = device;
serial = serial.left( serial.indexOf( " " ) );
QString model = device;
if( model.contains( "model:" ) )
{
model = model.right( model.size() - model.indexOf( "model:" ) - 6 );
model = model.left( model.indexOf( " " ) );
}
else
{
model = "unauthorized";
}
//qDebug() << serial << model;
QTableWidgetItem *item1 = new QTableWidgetItem( serial );
QTableWidgetItem *item2 = new QTableWidgetItem( model );
ui->tableWidget->setRowCount( ui->tableWidget->rowCount() + 1 );
ui->tableWidget->setItem( ui->tableWidget->rowCount() - 1, 0, item1 );
ui->tableWidget->setItem( ui->tableWidget->rowCount() - 1, 1, item2 );
}
if( ui->tableWidget->rowCount() ) ui->tableWidget->selectRow( 0 );
ui->pushButtonOk->setEnabled( ui->tableWidget->rowCount() );
}
void AdbSelectDeviceDialog::reset()
{
AdbWrapper *adbWrap = new AdbWrapper( this );
adbWrap->resetAdb();
delete adbWrap;
}