hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
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
 
#include <QApplication>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QMessageBox>
#include <QProcess>
#include "qtfactory.h"
 
#define UPDATE_EXE "/usr/bin/update"
 
qtFactoryReset::qtFactoryReset(QWidget *parent)
{
    const QRect availableGeometry = QApplication::desktop()->availableGeometry(parent);
    QFont font;
    font.setBold(true);
    font.setPixelSize(availableGeometry.height()/40);
    label.setFont(font);
    label.setText("Factory Reset will wipe all the user data.\n Make sure your device are ready.\n then click OK button.");
    label.setAlignment(Qt::AlignCenter);
    btn.setText("O K");
    connect(&btn, SIGNAL(clicked(bool)), this, SLOT(on_btnClicked()));
    vLayout.addWidget(&label);
    vLayout.addWidget(&btn);
    setLayout(&vLayout);
    setStyleSheet("background-color:rgb(204,228,247)");
    setObjectName("Factory Reset");
}
 
qtFactoryReset::~qtFactoryReset()
{
 
}
 
void qtFactoryReset::on_btnClicked()
{
    QFileInfo update = QFileInfo(UPDATE_EXE);
    QString path;
 
    QMessageBox::StandardButton rb = QMessageBox::question(
                this, "Factory Reset",
                "Do you want to reboot and do factory reset? It will wipe all your user data",
                QMessageBox::Yes | QMessageBox::No);
 
    if(rb == QMessageBox::Yes){
        if(update.exists()){
            QProcess p;
 
            p.start(UPDATE_EXE);
            p.waitForStarted();
            p.waitForFinished();
            QString err = QString::fromLocal8Bit(p.readAllStandardOutput());
            QMessageBox::critical(this, "Error", err);
        }else {
            QMessageBox::warning(this, "Error", "Don't find " UPDATE_EXE "!");
        }
    }
}