1 #include "about.h"
2 #include "ui_about.h"
3 #include <QMessageBox>
4 #include <QListView>
5 #include <QProcess>
6 #include <QByteArray>
7 #include "frmmessagebox.h"
8 #if defined(Q_OS_LINUX)
9
is_dir_exist(const char * dir_path)10 int is_dir_exist(const char *dir_path)
11 {
12 if(dir_path==NULL)
13 return -1;
14 if(opendir(dir_path)==NULL)
15 return -1;
16 return 0;
17 }
18 #endif
About(QWidget * parent)19 About::About(QWidget *parent) :
20 QDialog(parent),
21 ui(new Ui::About)
22 {
23
24 ui->setupUi(this);
25 this->setWindowFlags(Qt::FramelessWindowHint);
26 ui->ROM_usage->setRange(0,100);
27 connect(ui->formatButton,SIGNAL(clicked()),this,SLOT(on_formatButton_clicked()),Qt::UniqueConnection);
28
29 #if defined(Q_OS_LINUX)
30 #if 0
31 int sdklog_level=sdk_log_getlevel();
32 if(sdklog_level<=6)
33 ui->logLevelComboBox->setCurrentIndex(sdklog_level);
34 #endif
35 if(!is_dir_exist(PATH_SDCARD))
36 {
37
38 dev_type=0;
39 QProcess process;
40 QString cmd=QString("df /mnt/sdcard/mmcblk1p1 | grep %1").arg(QString("/dev/mmcblk1p1"));
41
42 process.start(cmd);
43 process.waitForFinished();
44 QByteArray output = process.readAllStandardOutput();
45 QString str_output = output;
46 str_output=str_output.simplified();
47 QStringList list=str_output.split(' ');
48 qDebug()<<str_output<<"\n"<<"usage of sdcard"<<list[11];
49 QString t=list[11];
50 t=t.left(t.length()-1);
51 test=t.toInt();
52 qDebug()<<test;
53
54 }else if(!is_dir_exist(PATH_USB)){
55 dev_type=1;
56
57 QProcess process;
58 QString cmd=QString("df /mnt/usb/sda4/ | grep %1").arg(QString("/dev/sda4/"));
59
60 process.start(cmd);
61 process.waitForFinished();
62 QByteArray output = process.readAllStandardOutput();
63 QString str_output = output;
64 str_output=str_output.simplified();
65 QStringList list=str_output.split(' ');
66 qDebug()<<str_output<<"\n"<<"usage of usb"<<list[11];
67 QString t=list[11];
68 t=t.left(t.length()-1);
69 test=t.toInt();
70 qDebug()<<test;
71
72 }else{
73 // ui->formatButton->setEnabled(false);
74 }
75
76 #else
77 #if 0
78
79 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
80 test =qrand()%100;
81 qDebug()<<"random number"<<test;
82 #endif
83 test=66;
84 #endif
85 ui->ROM_usage->setValue(test);
86 }
87
~About()88 About::~About()
89 {
90 delete ui;
91 }
on_formatButton_clicked()92 void About::on_formatButton_clicked()
93 {
94 // QMessageBox::StandardButton ret =QMessageBox::question(this,tr("format question"),tr("sure to format?"),QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Cancel);
95 frmMessageBox* mesg=new frmMessageBox();
96 mesg->SetMessage(QString(tr("Sure to Format?")), 1);
97 if(1==mesg->exec()){
98 #if defined(Q_OS_LINUX)
99 if(dev_type==0){
100 pfat=new Fat();
101 pfat->format(PATH_SD_DEV, PATH_SDCARD);
102 }else{
103 pfat=new Fat();
104 pfat->format(PATH_USB_DEV,PATH_USB);
105 }
106
107 #else
108 qDebug()<<"format";
109 #endif
110 timer=new QTimer(this);
111 connect(timer,SIGNAL(timeout()),this,SLOT(set_pro_value()));
112 timer->start(10);
113 }
114 }
set_pro_value()115 void About::set_pro_value()
116 {
117 if(test>=0){
118 ui->ROM_usage->setValue(test--);
119 }else{
120 timer->stop();
121 }
122 }
123
on_logLevelComboBox_currentIndexChanged(int index)124 void About::on_logLevelComboBox_currentIndexChanged(int index)
125 {
126 qDebug()<<"log level set:"<<index;
127 #if defined(Q_OS_LINUX)
128 sdk_log_setlevel(index);
129 #endif
130 }
131