代码拉取完成,页面将自动刷新
#include "completeinspection.h"
#include "ui_completeinspection.h"
QStandardItemModel* CompleteInspection::model;
bool* CompleteInspection::selected_inspection_args_p;
QList<int> CompleteInspection::select_rst_list;
QList<QString> CompleteInspection::inspection_rst_list;
int CompleteInspection::used_inspection_num;
int CompleteInspection::cancel_state;
CompleteInspection::CompleteInspection(QWidget *parent)
: QWidget(parent)
, ui(new Ui::CompleteInspection)
{
ui->setupUi(this);
set_styles();
}
void CompleteInspection::start_inspection(){
// QMessageBox::information(this,"args",QString("%1 %2 %3 %4")
// .arg(this->selected_inspection_args_p[0])
// .arg(this->selected_inspection_args_p[1])
// .arg(this->selected_inspection_args_p[2])
// .arg(this->selected_inspection_args_p[3])
// );
/* determine if working */
/* working. exit */
/* not working, start */
BeforeInspect::main_option(this);
}
CompleteInspection::~CompleteInspection()
{
delete ui;
}
void CompleteInspection::on_pushButton_clicked()
{
// exit progress
// TODO exit thread things
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,this,nullptr);
// switch to main
this->stack_widget->setCurrentWidget(this->parent_widget);
}
void CompleteInspection::set_args(QStackedWidget* stack_widget,QWidget* parent_widget){
this->stack_widget=stack_widget;
this->parent_widget=parent_widget;
}
void CompleteInspection::set_styles(){
// background
ui->widget_2->setStyleSheet(backgroud_widget_stype);
// card
ui->widget->setStyleSheet(card_widget_style);
// title
ui->label->setStyleSheet(title_text_style);
// main button
ui->pushButton_5->setStyleSheet(main_button_widget_style);
// sub button
ui->pushButton->setStyleSheet(sub_button_widget_style);
// content box
ui->treeView->setStyleSheet(contents_box);
// plain text
ui->label_3->setStyleSheet(plain_text_style);
// general text
ui->label_2->setStyleSheet(general_text_style);
// text
ui->widget_3->setStyleSheet(general_text_style);
}
QWidget* CompleteInspection::parent_page_static;
/*BeforeInspect*/
void CompleteInspection::BeforeInspect::main_option(CompleteInspection* parent_page){
cancel_state=0;
/*set ui*/
parent_page->ui->label_2->setText("未开始检查");
parent_page->ui->label_3->setText("请选择检查项");
parent_page->ui->pushButton_5->setText("开始检查");
CompleteInspection::parent_page_static=(QWidget*)parent_page;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,parent_page,[&](){
/*push action*/
QList<int> select_rst_list;
// 获取选中状态
QModelIndex index = CompleteInspection::model->index(0, 0, QModelIndex()); // 获取第一个子项的索引
if (index.isValid()) {
for(int i=0;i<4;i++){
QModelIndex firstChildIndex = model->index(i, 0, index);
if(firstChildIndex.isValid()){
Qt::CheckState state = model->data(firstChildIndex, Qt::CheckStateRole).value<Qt::CheckState>();
QVariant states = model->data(firstChildIndex, Qt::DisplayRole);
// qDebug() << "第"<<i+1<<"个子项的文本:" << states.toString();
if (state == Qt::Checked) {
select_rst_list.append(1);
} else {
select_rst_list.append(0);
}
}
}
}
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked, parent_page_static, nullptr);
Inspecting::main_option((CompleteInspection*)parent_page_static,select_rst_list);
});
CompleteInspection::model=new QStandardItemModel();
// 设置树形视图的数据模型
parent_page->ui->treeView->setModel(model);
// 创建一个根节点
QStandardItem *rootItem = new QStandardItem("检查条目");
rootItem->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItem);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_list[]={"加速优化","垃圾清理","病毒防护","防火墙状态"};
for (int i = 0; i < 4; ++i) {
QStandardItem *item = new QStandardItem(name_list[i]);
item->setCheckable(true); // 允许复选框
if(CompleteInspection::selected_inspection_args_p[i]){
item->setCheckState(Qt::Checked); // 默认选中状态
}else{
item->setCheckState(Qt::Unchecked);
}
rootItem->appendRow(item);
}
// // 显示树形视图
parent_page->ui->treeView->expandAll();
}
/*Inspecting*/
void CompleteInspection::Inspecting::main_option(CompleteInspection* parent_page,QList<int> select_rst_list){
/*set ui*/
parent_page->ui->label_2->setText("检查中");
parent_page->ui->label_3->setText("");
parent_page->ui->pushButton_5->setText("停止检查");
CompleteInspection::parent_page_static=parent_page;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,((CompleteInspection*)parent_page_static)->ui->pushButton,[&](){
/*push action*/
/*stop inspect*/
/*switch to cancel page*/
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,((CompleteInspection*)parent_page_static)->ui->pushButton,nullptr);
cancel_state=1;
CancelInspection::main_option((CompleteInspection*)parent_page_static,select_rst_list);
});
CompleteInspection::model=new QStandardItemModel();
// 设置树形视图的数据模型
((CompleteInspection*)parent_page_static)->ui->treeView->setModel(model);
// 创建一个根节点
QStandardItem *rootItem = new QStandardItem("检查条目");
rootItem->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItem);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_list[]={"加速优化-处理中","垃圾清理-处理中","病毒防护-处理中","防火墙状态-处理中"};
for (int i = 0; i < 4; ++i) {
if(select_rst_list[i]==1){
QStandardItem *item = new QStandardItem(name_list[i]);
item->setCheckable(false); // 允许复选框
rootItem->appendRow(item);
}
}
// // 显示树形视图
((CompleteInspection*)parent_page_static)->ui->treeView->expandAll();
/*option: inspect all*/
CompleteInspection::select_rst_list=select_rst_list;
inspection_rst_list.clear();
inspection_rst_list.append("optimize");
inspection_rst_list.append("clear");
inspection_rst_list.append("virus");
inspection_rst_list.append("firewall");
used_inspection_num=0;
for(int i=0;i<4;i++){
if(select_rst_list[i]){
used_inspection_num++;
}
}
// optimize
if(select_rst_list[0]){
inspection_rst_list[0]="o";
}
// clear
if(select_rst_list[1]){
inspection_rst_list[1]="c";
}
// defend virus
if(select_rst_list[2]){
// 创建 VSThread 实例,传递参数给构造函数
VSThread* vsThread = new VSThread("clamscan",QStringList()<<"-r"<<"--remove"<<"/home/");
// 连接信号和槽,并检查连接是否成功
bool connected = connect(vsThread, &VSThread::outputUpdated, parent_page, [](const QString& output){
/*get useful info*/
if(output.contains("Infected files")){
/*if usefull*/
reduce_used_inspection_num(output,2);
}
});
qDebug() << "Connection established: " << connected;
// 启动线程
vsThread->start();
}
// firewall
if(select_rst_list[3]){
QTimer::singleShot(1000, parent_page, [=]() {
QProcess process;
process.start("iptables -v");
process.waitForFinished(-1); // 等待进程完成
QByteArray output = process.readAllStandardOutput();
QString outputString(output);
if (outputString.contains("ecified")) {
// "运行结果中包含 'ecified'"
reduce_used_inspection_num("防火墙已开启",3);
} else {
// "运行结果中不包含 'ecified'"
reduce_used_inspection_num("防火墙已关闭",3);
}
});
}
}
void CompleteInspection::reduce_used_inspection_num(QString output,int i){
if(cancel_state){
return;
}
inspection_rst_list[i]=output;
used_inspection_num--;
if(used_inspection_num<=0){
/*wait success and switch to next*/
/*(not forget that you should disconnect socket)*/
InspectCompleted::main_option(((CompleteInspection*)parent_page_static),select_rst_list,inspection_rst_list);
}
}
/*InspectCompleted*/
void CompleteInspection::InspectCompleted::main_option(CompleteInspection* parent_page,QList<int> select_rst_list,QList<QString> inspection_rst_list){
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked, ((CompleteInspection*)parent_page_static)->ui->pushButton, nullptr);
CompleteInspection::model=new QStandardItemModel();
// 设置树形视图的数据模型
((CompleteInspection*)parent_page_static)->ui->treeView->setModel(model);
// 创建一个根节点
QStandardItem *rootItemx = new QStandardItem("检查条目");
rootItemx->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItemx);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_listx[]={"加速优化-已发现问题","垃圾清理-已发现问题","病毒防护-已发现问题","防火墙状态-已发现问题"};
for (int i = 0; i < 4; ++i) {
if(select_rst_list[i]==1){
QStandardItem *item = new QStandardItem(name_listx[i]);
item->setCheckable(false); // 允许复选框
if(inspection_rst_list.size()>i){
QStandardItem *childc_Itemx = new QStandardItem(inspection_rst_list[i]);
item->appendRow(childc_Itemx);
}
rootItemx->appendRow(item);
}
}
// // 显示树形视图
((CompleteInspection*)parent_page_static)->ui->treeView->expandAll();
/*set ui*/
parent_page->ui->label_2->setText("检查完成");
parent_page->ui->label_3->setText("");
parent_page->ui->pushButton_5->setText("开始优化");
// CompleteInspection::parent_page_static=(QWidget*)parent_page;
CompleteInspection::select_rst_list=select_rst_list;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,parent_page,[](){
/*push action*/
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,parent_page_static,nullptr);
Optimizing::main_option((CompleteInspection*)parent_page_static,CompleteInspection::select_rst_list);
});
}
/*Optimizing*/
void CompleteInspection::Optimizing::main_option(CompleteInspection* parent_page,QList<int> select_rst_list){
/*set ui*/
parent_page->ui->label_2->setText("优化中");
parent_page->ui->label_3->setText("");
parent_page->ui->pushButton_5->setText("停止优化");
CompleteInspection::parent_page_static=(QWidget*)parent_page;
CompleteInspection::select_rst_list=select_rst_list;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,parent_page,[&](){
/*push action*/
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,parent_page_static,nullptr);
cancel_state=1;
CancelInspection::main_option((CompleteInspection*)parent_page_static,CompleteInspection::select_rst_list);
});
auto model=new QStandardItemModel();
// 创建一个根节点
QStandardItem *rootItem = new QStandardItem("检查条目");
rootItem->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItem);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_list[]={"加速优化-优化中","垃圾清理-优化中","病毒防护-优化中","防火墙状态-优化中"};
for (int i = 0; i < 4; ++i) {
if(select_rst_list[i]==1){
QStandardItem *item = new QStandardItem(name_list[i]);
item->setCheckable(false); // 允许复选框
rootItem->appendRow(item);
}
}
// 设置树形视图的数据模型
parent_page->ui->treeView->setModel(model);
// // 显示树形视图
parent_page->ui->treeView->expandAll();
/*option*/
QTimer::singleShot(1000, parent_page, [=]() {
/*switch to next*/
if(!cancel_state){
OptimizeComplete::main_option(parent_page,select_rst_list);
}
});
}
/*OptimizeCompleted*/
void CompleteInspection::OptimizeComplete::main_option(CompleteInspection* parent_page,QList<int> select_rst_list){
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked, parent_page_static, nullptr);
/*set ui*/
parent_page->ui->label_2->setText("优化完成");
parent_page->ui->label_3->setText("");
parent_page->ui->pushButton_5->setText("重新检测");
CompleteInspection::parent_page_static=(QWidget*)parent_page;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,parent_page,[&](){
/*push action*/
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,parent_page_static,nullptr);
BeforeInspect::main_option((CompleteInspection*)parent_page_static);
});
auto model=new QStandardItemModel();
// 创建一个根节点
QStandardItem *rootItem = new QStandardItem("检查条目");
rootItem->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItem);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_list[]={"加速优化-已优化","垃圾清理-已优化","病毒防护-已优化","防火墙状态-已优化"};
for (int i = 0; i < 4; ++i) {
if(select_rst_list[i]==1){
QStandardItem *item = new QStandardItem(name_list[i]);
item->setCheckable(false); // 允许复选框
rootItem->appendRow(item);
}
}
// 设置树形视图的数据模型
parent_page->ui->treeView->setModel(model);
parent_page->ui->treeView->update();
// // 显示树形视图
parent_page->ui->treeView->expandAll();
}
/*CancelInspection*/
void CompleteInspection::CancelInspection::main_option(CompleteInspection* parent_page,QList<int> select_rst_list){
/*set ui*/
parent_page->ui->label_2->setText("已取消");
parent_page->ui->label_3->setText("");
parent_page->ui->pushButton_5->setText("重新检查");
CompleteInspection::parent_page_static=(QWidget*)parent_page;
connect(parent_page->ui->pushButton_5, &QPushButton::clicked,parent_page,[&](){
/*push action*/
disconnect(((CompleteInspection*)parent_page_static)->ui->pushButton_5, &QPushButton::clicked,parent_page_static,nullptr);
BeforeInspect::main_option((CompleteInspection*)parent_page_static);
});
auto model=new QStandardItemModel();
// 创建一个根节点
QStandardItem *rootItem = new QStandardItem("检查条目");
rootItem->setEditable(false); // 设置根节点为不可编辑
model->appendRow(rootItem);
// 根据func输入的内容,选择是否选中
// 添加带有复选框和文字的项到树中
QString name_list[]={"加速优化-已取消","垃圾清理-已取消","病毒防护-已取消","防火墙状态-已取消"};
for (int i = 0; i < 4; ++i) {
if(select_rst_list[i]==1){
QStandardItem *item = new QStandardItem(name_list[i]);
item->setCheckable(false); // 允许复选框
rootItem->appendRow(item);
}
}
// 设置树形视图的数据模型
parent_page->ui->treeView->setModel(model);
// // 显示树形视图
parent_page->ui->treeView->expandAll();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。