230 lines
6.9 KiB
C++
230 lines
6.9 KiB
C++
#include "widget.h"
|
|
#include "ui_widget.h"
|
|
|
|
Widget::Widget(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::Widget)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
{
|
|
p_labelUrl = new QLabel(tr("URL: "));
|
|
p_labelTime = new QLabel(tr("Update Time Period(sec): "));
|
|
p_labelProxyFile = new QLabel(tr("Save Location: "));
|
|
p_labelRecentTime = new QLabel("");
|
|
p_labelNextTime = new QLabel("");
|
|
|
|
p_labelRecent = new QLabel(tr("Recent Updated Time: "));
|
|
p_labelNext = new QLabel("Next Update Time: ");
|
|
|
|
p_lineUrl = new QLineEdit("http://proxylist.hidemyass.com/search-1305249#listable");
|
|
p_lineTime = new QLineEdit("1800");
|
|
p_lineProxyFile = new QLineEdit(qApp->applicationDirPath());
|
|
p_btnChoose = new QPushButton("Choose");
|
|
|
|
p_FileDialog = new QFileDialog();
|
|
glayout = new QGridLayout();
|
|
|
|
p_lineUrl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
p_lineTime->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
p_lineProxyFile->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
|
|
|
p_chkLocal = new QCheckBox("Local") ;
|
|
p_chkDb = new QCheckBox("DB");
|
|
p_chkLocal->setChecked(true);
|
|
QLabel *blank = new QLabel("Update Location: ");
|
|
|
|
|
|
glayout->addWidget(p_labelUrl, 0, 0);
|
|
glayout->addWidget(p_lineUrl, 0, 1, 1, 3);
|
|
glayout->addWidget(p_labelTime, 1, 0);
|
|
glayout->addWidget(p_lineTime, 1, 1, 1, 3);
|
|
glayout->addWidget(p_labelProxyFile, 2, 0);
|
|
glayout->addWidget(p_lineProxyFile, 2, 1, 1, 2);
|
|
glayout->addWidget(p_btnChoose, 2, 3);
|
|
glayout->addWidget(p_chkLocal, 3, 1);
|
|
glayout->addWidget(p_chkDb, 3, 2);
|
|
|
|
|
|
glayout->addWidget(p_labelRecent , 4, 0);
|
|
glayout->addWidget(p_labelRecentTime, 4, 1);
|
|
glayout->addWidget(p_labelNext, 4, 2);
|
|
glayout->addWidget(p_labelNextTime, 4, 3);
|
|
glayout->addWidget(blank, 3, 0);
|
|
|
|
connect(p_chkDb,SIGNAL(clicked()),this, SLOT(chkDb()));
|
|
connect(p_chkLocal,SIGNAL(clicked()),this, SLOT(chkLocal()));
|
|
|
|
|
|
/*
|
|
for(int i = 0; i < 4; i++)
|
|
{
|
|
hlayoutParam[i] = new QHBoxLayout();
|
|
}
|
|
|
|
hlayoutParam[0]->addWidget(p_labelUrl);
|
|
hlayoutParam[0]->addWidget(p_lineUrl);
|
|
hlayoutParam[1]->addWidget(p_labelTime);
|
|
hlayoutParam[1]->addWidget(p_lineTime);
|
|
hlayoutParam[2]->addWidget(p_labelProxyFile);
|
|
hlayoutParam[2]->addWidget(p_lineProxyFile);
|
|
hlayoutParam[2]->addWidget(p_btnChoose);
|
|
hlayoutParam[3]->addWidget(p_labelRecent);
|
|
hlayoutParam[3]->addWidget(p_labelRecentTime);
|
|
hlayoutParam[3]->addWidget(p_labelNext);
|
|
hlayoutParam[3]->addWidget(p_labelNextTime);
|
|
|
|
vlayoutParam = new QVBoxLayout();
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
{
|
|
vlayoutParam->addLayout(hlayoutParam[i]);
|
|
}
|
|
*/
|
|
}
|
|
|
|
{
|
|
p_btnStart = new QPushButton(tr("Timer Start"));
|
|
p_btnStop = new QPushButton(tr("Timer Stop"));
|
|
p_labelTimerOnOff = new QLabel(tr("Timer OFF"));
|
|
p_labelStatus = new QLabel(tr("Waiting"));
|
|
// vlayoutButton = new QVBoxLayout();
|
|
glayout->addWidget(p_btnStart,0, 4);
|
|
glayout->addWidget(p_btnStop, 1, 4);
|
|
glayout->addWidget(p_labelTimerOnOff, 2, 4);
|
|
glayout->addWidget(p_labelStatus,3 , 4);
|
|
|
|
|
|
QLabel *blank2 = new QLabel;
|
|
glayout->addWidget(blank2, 5, 0, 1, 4);
|
|
}
|
|
|
|
p_timer = new QTimer(this);
|
|
|
|
connect(p_timer,SIGNAL(timeout()),this,SLOT(update()));
|
|
connect(p_btnStart, SIGNAL(clicked()), this, SLOT(btnStart()));
|
|
connect(p_btnStop, SIGNAL(clicked()), this, SLOT(btnStop()));
|
|
connect(p_btnChoose, SIGNAL(clicked()), this, SLOT(btnChoose()));
|
|
connect(&v_pro,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int, QProcess::ExitStatus)));
|
|
//SIGNAL(finished(int,QProcess::ExitStatus)),SLOT(processFinished(int,QProcess::ExitStatus))
|
|
/*
|
|
hlayoutDefault = new QHBoxLayout(this);
|
|
hlayoutDefault->addLayout(vlayoutParam);
|
|
hlayoutDefault->addLayout(glayout);
|
|
hlayoutDefault->addLayout(vlayoutButton);
|
|
*/
|
|
setLayout(glayout);
|
|
resize(700, 200);
|
|
}
|
|
|
|
Widget::~Widget()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void Widget::btnChoose()
|
|
{
|
|
qDebug("btnChoose()");
|
|
QString directory = QFileDialog::getExistingDirectory(this,
|
|
tr("Find Files"), QDir::currentPath());
|
|
|
|
if (!directory.isEmpty()) {
|
|
this->p_lineProxyFile->setText(directory);
|
|
}
|
|
}
|
|
|
|
void Widget::btnStart()
|
|
{
|
|
qDebug("btnStart()");
|
|
if(p_timer->isActive())
|
|
return;
|
|
|
|
update();
|
|
|
|
p_timer->start(p_lineTime->text().toInt()*1000);
|
|
p_labelTimerOnOff->setText("Timer ON");
|
|
|
|
}
|
|
|
|
void Widget::btnStop()
|
|
{
|
|
qDebug("btnStop()");
|
|
|
|
if(p_timer->isActive())
|
|
p_timer->stop();
|
|
|
|
p_labelTimerOnOff->setText("Timer OFF");
|
|
p_labelNextTime->setText("");
|
|
p_labelStatus->setText("Waiting");
|
|
}
|
|
|
|
void Widget::update()
|
|
{
|
|
qDebug("update()");
|
|
//QDateTime time = QDateTime::currentDateTime();
|
|
QString strCheck;
|
|
|
|
if(p_chkDb->isChecked())
|
|
strCheck = "db";
|
|
if(p_chkLocal->isChecked())
|
|
strCheck = "local";
|
|
if(p_chkDb->isChecked() && p_chkLocal->isChecked())
|
|
strCheck = "both";
|
|
|
|
v_pro.start("ProxyProcess",QStringList() << p_lineUrl->text() << p_lineProxyFile->text() << strCheck);
|
|
//p_labelRecentTime->setText(time.toLocalTime().toString("yyyy-MM-dd hh:mm:ss"));
|
|
p_labelNextTime->setText(QDateTime::currentDateTime().toLocalTime().addSecs(p_lineTime->text().toInt()).toString("yyyy-MM-dd hh:mm:ss"));
|
|
p_labelStatus->setText("Updating");
|
|
}
|
|
|
|
void Widget::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
{
|
|
qDebug("process finished");
|
|
QProcess *pPro = (QProcess*)sender();
|
|
QString str = pPro->readAllStandardOutput();
|
|
|
|
QString message;
|
|
if(str.right(2).compare("ok") == 0)
|
|
{
|
|
message = "Update Done";
|
|
}
|
|
else if(str.right(7).compare("dbcfail") == 0)
|
|
{
|
|
message = "DB connection\nFail";
|
|
}
|
|
else if(str.right(7).compare("dbufail") == 0)
|
|
{
|
|
message = "DB update Fail";
|
|
}
|
|
else if(str.right(8).compare("savefail") == 0)
|
|
{
|
|
message = "Saving file\nFail";
|
|
}
|
|
else if(str.right(7).compare("timeout") == 0)
|
|
{
|
|
message = "TimeOut";
|
|
}
|
|
else if(str.right(8).compare("sitedown") == 0)
|
|
{
|
|
message = "Proxy Crawler\nFail";
|
|
}
|
|
else
|
|
message = "Unknown Error";
|
|
|
|
pPro->kill();
|
|
|
|
p_labelRecentTime->setText(QDateTime::currentDateTime().toLocalTime().toString("yyyy-MM-dd hh:mm:ss"));
|
|
p_labelStatus->setText(message);
|
|
}
|
|
|
|
void Widget::chkDb()
|
|
{
|
|
p_chkLocal->setChecked(true);
|
|
}
|
|
|
|
|
|
void Widget::chkLocal()
|
|
{
|
|
p_chkDb->setChecked(true);
|
|
}
|