QT 制作的fastboot烧写器

来源:互联网 发布:良辰好景知几何 编辑:程序博客网 时间:2024/05/23 18:42

效果图:



代码:

FastbootDialog.h:

#ifndef __FASTBOOTDIALOG_H__#define __FASTBOOTDIALOG_H__#include <QDialog>#include "ui_fastboot.h" class FastbootDialog : public QDialog, public Ui::FastbootDialog{        Q_OBJECTpublic:FastbootDialog(QWidget *parent=0);        QString localPw, localLog;        QString fileName;        QString systemPath;signals:private slots:   void selectFastbootPath();   void selectSystemPath();   void checkDevice();   void preEraseSystem();   void eraseSystem();   void preFlashSystem();   void flashSystem();   void restartDevice();   void on_lineEditDeviceAddr_textChanged();   void on_lineEditSystem_textChanged();public:    void readLog();};#endif 

FastbootDialog.cpp:

#include <QtGui>#include <QDebug>#include "FastbootDialog.h" FastbootDialog::FastbootDialog(QWidget *parent)    : QDialog(parent){        setupUi(this);   localPw = "123456";   localLog = "/home/luke/fastboot/lslog.txt";    fileName = "/home/luke/AndroidServer/samba/mmp3/out/host/linux-x86/bin/fastboot";    lineEditDeviceAddr->setText(fileName);    systemPath ="/home/luke/AndroidServer/samba/mmp3/out/target/product/thunderstone/system.img";    lineEditSystem->setText(systemPath);    connect(pushButtonSelect,SIGNAL(clicked()),this,SLOT(selectFastbootPath()));    connect(pushButtonCheck,SIGNAL(clicked()),this,SLOT(checkDevice()));    connect(pushButtonEraseSystem,SIGNAL(pressed()),this,SLOT(preEraseSystem()));    connect(pushButtonEraseSystem,SIGNAL(released()),this,SLOT(eraseSystem()));    connect(pushButtonFlashSystem,SIGNAL(pressed()),this,SLOT(preFlashSystem()));    connect(pushButtonFlashSystem,SIGNAL(released()),this,SLOT(flashSystem()));    connect(pushButtonSystemSelect,SIGNAL(clicked()),this,SLOT(selectSystemPath()));    connect(pushButtonRestart,SIGNAL(clicked()),this,SLOT(restartDevice()));}//api -------------------------void FastbootDialog::checkDevice(){ //system("echo 854632 | sudo -S ls /home/luke/tmp/ > /home/luke/fastboot/lslog.txt");    QString tmp;    tmp += "echo "+ localPw +" | sudo -S " + fileName + " devices 1>" + localLog +" 2>"+ localLog;  system(tmp.toStdString().data());  readLog();}void FastbootDialog::preEraseSystem(){    QString tmp;    QString tmpComand = "erase system.....";    tmp += "---------------------------------log---------------------------------------\n"           +tmpComand+"\n---------------------------------------------------------------------------\n";    labelLog->setText(tmp);}void FastbootDialog::eraseSystem(){    QString tmp;    tmp += "echo "+ localPw +" | sudo -S " + fileName + " erase system 1>" + localLog +" 2>"+ localLog;    system(tmp.toStdString().data());     readLog();}void FastbootDialog::preFlashSystem(){    QString tmp;    QString tmpComand = "flash system.....";    tmp += "---------------------------------log---------------------------------------\n"           +tmpComand+"\n---------------------------------------------------------------------------\n";    labelLog->setText(tmp);}void FastbootDialog::flashSystem(){    QString tmp;    tmp += "echo "+ localPw +" | sudo -S " + fileName + " flash system " +systemPath +" 1>" + localLog +" 2>"+ localLog;    system(tmp.toStdString().data());     readLog();}void FastbootDialog::restartDevice(){    QString tmp;    tmp += "echo "+ localPw +" | sudo -S " + fileName + " reboot " +" 1>" + localLog +" 2>"+ localLog;    system(tmp.toStdString().data());     readLog();}void FastbootDialog::readLog(){    QFile file(localLog);     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))            return;     QTextStream in(&file);     QString line = in.readAll();     qDebug()<<"log:"<<line;     labelLog->setText("---------------------------------log---------------------------------------\n"                        +line+                        "\n---------------------------------------------------------------------------\n");    file.close();}//select ----------------------void FastbootDialog::selectSystemPath(){}void FastbootDialog::selectFastbootPath(){      fileName = QFileDialog::getOpenFileName(this,         tr("Select Fastboot Path"), "/home/luke", tr("fastboot (fastboot)"));     lineEditDeviceAddr->setText(fileName);     qDebug()<<"fiename:"<<fileName;}//line edit -------------------------------void FastbootDialog::on_lineEditDeviceAddr_textChanged(){    fileName = lineEditDeviceAddr->text();    qDebug()<<"on_lineEditDeviceAddr_textChanged:"<<fileName;}void FastbootDialog::on_lineEditSystem_textChanged(){    systemPath = lineEditSystem->text();    qDebug()<<"on_lineEditSystem_textChanged:"<<systemPath;}

main.cpp:

#include <QApplication>#include "FastbootDialog.h"int main(int argc, char *argv[]){    QApplication app(argc, argv);    FastbootDialog *dialog = new FastbootDialog;    dialog->show();    return app.exec(); }


fastboot.ui:

/********************************************************************************** Form generated from reading UI file 'fastbootf13815.ui'**** Created: Wed Dec 26 16:50:04 2012**      by: Qt User Interface Compiler version 4.6.2**** WARNING! All changes made in this file will be lost when recompiling UI file!********************************************************************************/#ifndef FASTBOOTF13815_H#define FASTBOOTF13815_H#include <QtCore/QVariant>#include <QtGui/QAction>#include <QtGui/QApplication>#include <QtGui/QButtonGroup>#include <QtGui/QDialog>#include <QtGui/QHBoxLayout>#include <QtGui/QHeaderView>#include <QtGui/QLabel>#include <QtGui/QLineEdit>#include <QtGui/QPushButton>#include <QtGui/QVBoxLayout>QT_BEGIN_NAMESPACEclass Ui_FastbootDialog{public:    QVBoxLayout *verticalLayout;    QHBoxLayout *horizontalLayout_2;    QLabel *labelFastbootAddr;    QLineEdit *lineEditDeviceAddr;    QPushButton *pushButtonSelect;    QPushButton *pushButtonCheck;    QPushButton *pushButtonEraseSystem;    QHBoxLayout *horizontalLayout_3;    QPushButton *pushButtonFlashSystem;    QLineEdit *lineEditSystem;    QPushButton *pushButtonSystemSelect;    QPushButton *pushButtonRestart;    QLabel *labelLog;    void setupUi(QDialog *FastbootDialog)    {        if (FastbootDialog->objectName().isEmpty())            FastbootDialog->setObjectName(QString::fromUtf8("FastbootDialog"));        FastbootDialog->resize(395, 204);        verticalLayout = new QVBoxLayout(FastbootDialog);        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));        horizontalLayout_2 = new QHBoxLayout();        horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));        labelFastbootAddr = new QLabel(FastbootDialog);        labelFastbootAddr->setObjectName(QString::fromUtf8("labelFastbootAddr"));        horizontalLayout_2->addWidget(labelFastbootAddr);        lineEditDeviceAddr = new QLineEdit(FastbootDialog);        lineEditDeviceAddr->setObjectName(QString::fromUtf8("lineEditDeviceAddr"));        horizontalLayout_2->addWidget(lineEditDeviceAddr);        pushButtonSelect = new QPushButton(FastbootDialog);        pushButtonSelect->setObjectName(QString::fromUtf8("pushButtonSelect"));        horizontalLayout_2->addWidget(pushButtonSelect);        verticalLayout->addLayout(horizontalLayout_2);        pushButtonCheck = new QPushButton(FastbootDialog);        pushButtonCheck->setObjectName(QString::fromUtf8("pushButtonCheck"));        verticalLayout->addWidget(pushButtonCheck);        pushButtonEraseSystem = new QPushButton(FastbootDialog);        pushButtonEraseSystem->setObjectName(QString::fromUtf8("pushButtonEraseSystem"));        verticalLayout->addWidget(pushButtonEraseSystem);        horizontalLayout_3 = new QHBoxLayout();        horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));        pushButtonFlashSystem = new QPushButton(FastbootDialog);        pushButtonFlashSystem->setObjectName(QString::fromUtf8("pushButtonFlashSystem"));        horizontalLayout_3->addWidget(pushButtonFlashSystem);        lineEditSystem = new QLineEdit(FastbootDialog);        lineEditSystem->setObjectName(QString::fromUtf8("lineEditSystem"));        horizontalLayout_3->addWidget(lineEditSystem);        pushButtonSystemSelect = new QPushButton(FastbootDialog);        pushButtonSystemSelect->setObjectName(QString::fromUtf8("pushButtonSystemSelect"));        horizontalLayout_3->addWidget(pushButtonSystemSelect);        verticalLayout->addLayout(horizontalLayout_3);        pushButtonRestart = new QPushButton(FastbootDialog);        pushButtonRestart->setObjectName(QString::fromUtf8("pushButtonRestart"));        verticalLayout->addWidget(pushButtonRestart);        labelLog = new QLabel(FastbootDialog);        labelLog->setObjectName(QString::fromUtf8("labelLog"));        verticalLayout->addWidget(labelLog);        retranslateUi(FastbootDialog);        QMetaObject::connectSlotsByName(FastbootDialog);    } // setupUi    void retranslateUi(QDialog *FastbootDialog)    {        FastbootDialog->setWindowTitle(QApplication::translate("FastbootDialog", "fastboot\347\203\247\345\206\231\345\231\250", 0, QApplication::UnicodeUTF8));        labelFastbootAddr->setText(QApplication::translate("FastbootDialog", "\350\257\267\351\200\211\346\213\251fastboot\350\267\257\345\276\204\357\274\232", 0, QApplication::UnicodeUTF8));        pushButtonSelect->setText(QApplication::translate("FastbootDialog", "\350\267\257\345\276\204\351\200\211\346\213\251...", 0, QApplication::UnicodeUTF8));        pushButtonCheck->setText(QApplication::translate("FastbootDialog", "\346\237\245\347\234\213\350\277\236\346\216\245", 0, QApplication::UnicodeUTF8));        pushButtonEraseSystem->setText(QApplication::translate("FastbootDialog", "\346\223\246\351\231\244system", 0, QApplication::UnicodeUTF8));        pushButtonFlashSystem->setText(QApplication::translate("FastbootDialog", "\345\206\231\345\205\245system", 0, QApplication::UnicodeUTF8));        pushButtonSystemSelect->setText(QApplication::translate("FastbootDialog", "\347\263\273\347\273\237\351\200\211\346\213\251...", 0, QApplication::UnicodeUTF8));        pushButtonRestart->setText(QApplication::translate("FastbootDialog", "\351\207\215\345\220\257", 0, QApplication::UnicodeUTF8));        labelLog->setText(QApplication::translate("FastbootDialog", "log:", 0, QApplication::UnicodeUTF8));    } // retranslateUi};namespace Ui {    class FastbootDialog: public Ui_FastbootDialog {};} // namespace UiQT_END_NAMESPACE#endif // FASTBOOTF13815_H