1
2 #include <QApplication>
3 #include <QDesktopWidget>
4 #include <QFileInfo>
5 #include <QMessageBox>
6 #include <QProcess>
7 #include "qtfactory.h"
8
9 #define UPDATE_EXE "/usr/bin/update"
10
qtFactoryReset(QWidget * parent)11 qtFactoryReset::qtFactoryReset(QWidget *parent)
12 {
13 const QRect availableGeometry = QApplication::desktop()->availableGeometry(parent);
14 QFont font;
15 font.setBold(true);
16 font.setPixelSize(availableGeometry.height()/40);
17 label.setFont(font);
18 label.setText("Factory Reset will wipe all the user data.\n Make sure your device are ready.\n then click OK button.");
19 label.setAlignment(Qt::AlignCenter);
20 btn.setText("O K");
21 connect(&btn, SIGNAL(clicked(bool)), this, SLOT(on_btnClicked()));
22 vLayout.addWidget(&label);
23 vLayout.addWidget(&btn);
24 setLayout(&vLayout);
25 setStyleSheet("background-color:rgb(204,228,247)");
26 setObjectName("Factory Reset");
27 }
28
~qtFactoryReset()29 qtFactoryReset::~qtFactoryReset()
30 {
31
32 }
33
on_btnClicked()34 void qtFactoryReset::on_btnClicked()
35 {
36 QFileInfo update = QFileInfo(UPDATE_EXE);
37 QString path;
38
39 QMessageBox::StandardButton rb = QMessageBox::question(
40 this, "Factory Reset",
41 "Do you want to reboot and do factory reset? It will wipe all your user data",
42 QMessageBox::Yes | QMessageBox::No);
43
44 if(rb == QMessageBox::Yes){
45 if(update.exists()){
46 QProcess p;
47
48 p.start(UPDATE_EXE);
49 p.waitForStarted();
50 p.waitForFinished();
51 QString err = QString::fromLocal8Bit(p.readAllStandardOutput());
52 QMessageBox::critical(this, "Error", err);
53 }else {
54 QMessageBox::warning(this, "Error", "Don't find " UPDATE_EXE "!");
55 }
56 }
57 }
58