/
rndssucli.cpp
75 lines (61 loc) · 1.85 KB
/
rndssucli.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
/**
* @file rndssucli.cpp
* @copyright 2012 Jolla Ltd.
* @author Bernd Wachter <bernd.wachter@jollamobile.com>
* @date 2012
*/
#include <QCoreApplication>
#include "rndssucli.h"
RndSsuCli::RndSsuCli(): QObject(){
connect(this,SIGNAL(done()),
QCoreApplication::instance(),SLOT(quit()), Qt::DirectConnection);
connect(&ssu, SIGNAL(done()),
this, SLOT(handleResponse()));
}
void RndSsuCli::handleResponse(){
QTextStream qout(stdout);
if (ssu.error()){
qout << "Last operation failed: \n" << ssu.lastError() << endl;
QCoreApplication::exit(1);
} else {
qout << "Operation successful" << endl;
QCoreApplication::exit(0);
}
}
void RndSsuCli::run(){
QTextStream qout(stdout);
QStringList arguments = QCoreApplication::arguments();
if (arguments.count() != 2){
usage();
return;
}
if (arguments.at(1) == "register"){
QString username, password;
QTextStream qin(stdin);
qout << "Username: " << flush;
username = qin.readLine();
qout << "Password: " << flush;
password = qin.readLine();
ssu.sendRegistration(username, password);
} else if (arguments.at(1) == "update"){
if (!ssu.isRegistered()){
qout << "Device is not registered, can't update credentials" << endl;
QCoreApplication::exit(1);
} else {
ssu.updateCredentials();
}
} else if (arguments.at(1) == "status"){
qout << "Device registration status: "
<< (ssu.isRegistered() ? "registered" : "not registered") << endl;
qout << "Device family: " << ssu.deviceFamily() << endl;
qout << "Device model: " << ssu.deviceModel() << endl;
qout << "Device UID: " << ssu.deviceUid() << endl;
QCoreApplication::exit(1);
} else
usage();
}
void RndSsuCli::usage(){
QTextStream qout(stdout);
qout << "Usage: rndssu register|update|status" << endl;
QCoreApplication::exit(1);
}