几乎完成
parent
bc3b3f69a7
commit
b728e697fb
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
#include "MyButton.h"
|
||||
|
@ -10,6 +10,7 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButto
|
|||
this->height2=height;
|
||||
this->text=buttonStruct.text;
|
||||
this->op = buttonStruct.op;
|
||||
this->orig_name = buttonStruct.orig_name;
|
||||
this->func = buttonStruct.func;
|
||||
this->url = buttonStruct.url;
|
||||
this->path = buttonStruct.path;
|
||||
|
@ -43,7 +44,7 @@ void MyButton::paintEvent(QPaintEvent *e) {
|
|||
setContentsMargins(0,0,0,0);
|
||||
QFont ft;
|
||||
ft.setPixelSize(TEXT_SIZE);
|
||||
//别问我为啥乘3,我也不知道
|
||||
//别问我为啥乘3,我也不知道
|
||||
int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2;
|
||||
int text_y=(logo_width+logo_y+10);
|
||||
QRectF logo_rect(logo_x, logo_y, logo_width, logo_width);
|
||||
|
@ -91,6 +92,6 @@ void MyButton::mouseReleaseEvent(QMouseEvent *event) {
|
|||
checked=false;
|
||||
else
|
||||
checked=true;
|
||||
emit clicked1(op, func, url, path, initial_position);
|
||||
emit clicked1(orig_name,op, func, url, path, initial_position);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
|||
class MyButton: public QPushButton{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void clicked1(QString op, QString func, QString url, QString path, QString initial_position);
|
||||
void clicked1(QString orig_name,QString op, QString func, QString url, QString path, QString initial_position);
|
||||
public:
|
||||
MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr);
|
||||
~MyButton() override;
|
||||
|
@ -57,6 +57,7 @@ private:
|
|||
QImage *logo_cover;
|
||||
QVBoxLayout *layout;
|
||||
QString text;
|
||||
QString orig_name;
|
||||
QString url;
|
||||
QString op;
|
||||
QString path;
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
<QtRcc Include="OfficeAssistant_msvc.qrc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="userimprove.h" />
|
||||
<QtMoc Include="applicationmanager.h" />
|
||||
<QtMoc Include="addapp.h" />
|
||||
<QtMoc Include="addcategory.h" />
|
||||
|
@ -139,6 +140,7 @@
|
|||
<ClCompile Include="netio.cpp" />
|
||||
<ClCompile Include="qminiblink.cpp" />
|
||||
<ClCompile Include="sqlitehelper.cpp" />
|
||||
<ClCompile Include="userimprove.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="addapp.ui" />
|
||||
|
@ -152,6 +154,7 @@
|
|||
<QtUic Include="mysettingsdialog.ui" />
|
||||
<QtUic Include="navbar.ui" />
|
||||
<QtUic Include="qminiblink.ui" />
|
||||
<QtUic Include="userimprove.ui" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="logo.rc" />
|
||||
|
|
|
@ -85,6 +85,9 @@
|
|||
<QtMoc Include="applicationmanagerpage.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="userimprove.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mainscreen.cpp">
|
||||
|
@ -132,6 +135,9 @@
|
|||
<ClCompile Include="applicationmanagerpage.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="userimprove.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="navbar.ui">
|
||||
|
@ -167,6 +173,9 @@
|
|||
<QtUic Include="applicationmanagerpage.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="userimprove.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="logo.rc">
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<QtLastBackgroundBuild>2023-08-12T03:22:21.9071424Z</QtLastBackgroundBuild>
|
||||
<QtLastBackgroundBuild>2023-08-17T22:00:04.0470850Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<QtLastBackgroundBuild>2023-08-12T03:22:23.0360904Z</QtLastBackgroundBuild>
|
||||
<QtLastBackgroundBuild>2023-08-17T22:00:04.1224923Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,4 +1,4 @@
|
|||
#include "addapp.h"
|
||||
#include "addapp.h"
|
||||
#include <QFileDialog>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QMessageBox>
|
||||
|
@ -18,19 +18,19 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
|||
ui.setupUi(this);
|
||||
this->row=row;
|
||||
SQLiteHelper sqlite_helper;
|
||||
setFixedSize(450, 450);
|
||||
setFixedSize(450, 600);
|
||||
Record2 record;
|
||||
sqlite_helper.get_a_software(row->orig_name, &record);
|
||||
setWindowFlags(Qt::WindowCloseButtonHint);
|
||||
form = new QFormLayout;
|
||||
name = new QLineEdit;
|
||||
form->addRow(QString::fromLocal8Bit("名称"), name);
|
||||
form->addRow(QString::fromLocal8Bit("名称"), name);
|
||||
|
||||
if (isEdit)
|
||||
{
|
||||
sqlite_helper.get_a_software(row->orig_name, &record);
|
||||
name_label = new QLabel(orig_name_str);
|
||||
form->addRow(QString::fromLocal8Bit("全名"), name_label);
|
||||
|
||||
form->addRow(QString::fromLocal8Bit("全名"), name_label);
|
||||
record = *row;//最初为啥这么写我也忘了
|
||||
if (!record.orig_name.isEmpty())
|
||||
{
|
||||
name_label->setText(record.orig_name);
|
||||
|
@ -40,17 +40,17 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
|||
else
|
||||
{
|
||||
orig_name = new QLineEdit;
|
||||
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
|
||||
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
|
||||
}
|
||||
|
||||
if (record.orig_name.isEmpty())
|
||||
{
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||
sort = new QLineEdit;
|
||||
sort->setValidator(new QIntValidator(10, 100));
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
QList<Categrory> categrories;
|
||||
layout_inner = new QVBoxLayout;
|
||||
sqlite_helper.get_category(categrories, true);
|
||||
|
@ -62,8 +62,8 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
|||
layout_inner->addWidget(check_box);
|
||||
categories_list.insert(category.id, check_box);
|
||||
}
|
||||
form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
|
||||
submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
|
||||
submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
form->addWidget(submit_btn);
|
||||
this->setLayout(form);
|
||||
connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
|
||||
|
@ -75,15 +75,18 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
|||
name->setText(record.name);
|
||||
name_str = record.name;
|
||||
sort_str = QString::number(record.sort);
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
path_str = record.exe_file;
|
||||
path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str()));
|
||||
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||
if (record.op == "soft")
|
||||
{
|
||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||
}
|
||||
sort = new QLineEdit;
|
||||
sort->setText(QString::number(record.sort));
|
||||
sort->setValidator(new QIntValidator(10, 100));
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
QList<Categrory> categrories;
|
||||
layout_inner = new QVBoxLayout;
|
||||
sqlite_helper.get_category(categrories, true);
|
||||
|
@ -98,15 +101,14 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
|||
layout_inner->addWidget(check_box);
|
||||
categories_list.insert(category.id, check_box);
|
||||
}
|
||||
form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
|
||||
submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
form->addRow(QString::fromLocal8Bit("类别"), layout_inner);
|
||||
submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
form->addWidget(submit_btn);
|
||||
this->setLayout(form);
|
||||
connect(path, &QPushButton::click, this, &AddApp::broswer_exe);
|
||||
connect(submit_btn, &QPushButton::clicked, this, &AddApp::submit);
|
||||
this->isEdit = isEdit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AddApp::~AddApp()
|
||||
|
@ -130,13 +132,13 @@ void AddApp::broswer_exe(){
|
|||
QString path_str_old = path_str;
|
||||
if(path_str.isEmpty())
|
||||
{
|
||||
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
|
||||
QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)"));
|
||||
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
|
||||
QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)"));
|
||||
}
|
||||
else
|
||||
{
|
||||
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
|
||||
path_str, QString::fromLocal8Bit("应用程序 (*.exe)"));
|
||||
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
|
||||
path_str, QString::fromLocal8Bit("应用程序 (*.exe)"));
|
||||
}
|
||||
if (path_str.isEmpty()) {
|
||||
path_str = path_str_old;
|
||||
|
@ -147,9 +149,7 @@ void AddApp::broswer_exe(){
|
|||
}
|
||||
|
||||
void AddApp::submit() {
|
||||
if(isEdit)
|
||||
{
|
||||
if (!path->text().isEmpty())
|
||||
if (isEdit)
|
||||
{
|
||||
QString name_str_old = name_str;
|
||||
QString sort_str_old = sort_str;
|
||||
|
@ -163,12 +163,6 @@ void AddApp::submit() {
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写路径"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((!orig_name->text().isEmpty()) && (!path->text().isEmpty()))
|
||||
{
|
||||
|
@ -184,27 +178,21 @@ void AddApp::submit() {
|
|||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
categories = new bool[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++) {
|
||||
categories[i] = false;
|
||||
}
|
||||
categories[ALL-1] = true;
|
||||
if (row->op == "soft") {
|
||||
categories[SOFT-1] = true;
|
||||
}
|
||||
else if (row->op == "app") {
|
||||
categories[INNER-1] = true;
|
||||
}
|
||||
for(auto key:categories_list.keys())
|
||||
{
|
||||
categories[key - 1] = categories_list[key]->checkState();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++) {
|
||||
qDebug() << categories[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
@ -16,7 +16,7 @@ class AddApp : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AddApp(bool isEdit = false, Record2 *orig_name_str=nullptr,QWidget* parent = nullptr);
|
||||
AddApp(bool isEdit = false, Record2 *row=nullptr,QWidget* parent = nullptr);
|
||||
~AddApp();
|
||||
QString get_exe_path()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#include "addcategory.h"
|
||||
#include "addcategory.h"
|
||||
#include <QString>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
AddCategory::AddCategory(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
|
@ -9,21 +12,21 @@ AddCategory::AddCategory(QWidget* parent)
|
|||
//connect(ui.submit, &QPushButton::click, this, &AddCategory::submit);
|
||||
QStringList title;
|
||||
ui.tableWidget->setColumnCount(3);
|
||||
title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序");
|
||||
title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序");
|
||||
ui.tableWidget->setHorizontalHeaderLabels(title);
|
||||
sqlite_helper.get_category(categrories,false);
|
||||
sqlite_helper.get_category(categrories,true);
|
||||
ui.tableWidget->setRowCount(categrories.count());
|
||||
int i = 0;
|
||||
for(auto category : categrories)
|
||||
{
|
||||
ui.tableWidget->setItem(i, 0, new QTableWidgetItem(category.name));
|
||||
if(category.id==1&&category.id==8)
|
||||
if(category.id==ALL||category.id==OTHERS||category.id==ELITE)
|
||||
{
|
||||
ui.tableWidget->item(i, 0)->setFlags(ui.tableWidget->item(i, 0)->flags() & (~Qt::ItemIsEditable));
|
||||
}
|
||||
QComboBox* combo_box = new QComboBox;
|
||||
combo_box->addItem(QString::fromLocal8Bit("显示"), true);
|
||||
combo_box->addItem(QString::fromLocal8Bit("不显示"), false);
|
||||
combo_box->addItem(QString::fromLocal8Bit("显示"), true);
|
||||
combo_box->addItem(QString::fromLocal8Bit("不显示"), false);
|
||||
if(category.display==true)
|
||||
{
|
||||
combo_box->setCurrentIndex(0);
|
||||
|
@ -36,7 +39,7 @@ AddCategory::AddCategory(QWidget* parent)
|
|||
combo_boxes << combo_box;
|
||||
i++;
|
||||
}
|
||||
//submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
//submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit);
|
||||
}
|
||||
AddCategory::~AddCategory()
|
||||
|
@ -60,7 +63,7 @@ void AddCategory::submit()
|
|||
categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10);
|
||||
if(!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字"));
|
||||
return;
|
||||
}
|
||||
categrories_new << categrory;
|
||||
|
|
|
@ -1,30 +1,34 @@
|
|||
#include "applicationmanager.h"
|
||||
#include "applicationmanager.h"
|
||||
#include "applicationmanagerpage.h"
|
||||
#include "config.h"
|
||||
#include "addapp.h"
|
||||
#include "addcategory.h"
|
||||
#include "sqlitehelper.h"
|
||||
#include "userimprove.h"
|
||||
#include "globalvariables.h"
|
||||
#include "netio.h"
|
||||
#include <ctime>
|
||||
|
||||
#include "globalvariables.h"
|
||||
|
||||
#include "MyButton.h"
|
||||
ApplicationManager::ApplicationManager(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
application_manager = this;
|
||||
ui.setupUi(this);
|
||||
resize(parent->width(), parent->height());
|
||||
this->parent = parent;
|
||||
miniblink = new QMiniBlink(this);
|
||||
miniblink->init();
|
||||
miniblink->show();
|
||||
connect(this, &ApplicationManager::changeUrl, miniblink, &QMiniBlink::switchUrl);
|
||||
layout = new QVBoxLayout(this);
|
||||
layout_top = new QHBoxLayout(this);
|
||||
layout_top->setAlignment(Qt::AlignRight);
|
||||
layout_top->setMargin(5);
|
||||
layout_top_right = new QHBoxLayout(this);
|
||||
layout_top_right->setAlignment(Qt::AlignRight);
|
||||
layout_top_right->setMargin(5);
|
||||
layout_top= new QHBoxLayout(this);
|
||||
layout_top_left = new QHBoxLayout(this);
|
||||
layout_top_left->setMargin(0);
|
||||
layout_top_left->setAlignment(Qt::AlignLeft);
|
||||
layout_bottom = new QHBoxLayout(this);
|
||||
QList<Categrory> categrories;
|
||||
sqlite_helper.get_category(categrories,false,true);
|
||||
sqlite_helper.get_category(categrories,false);
|
||||
sqlite_helper.get_buttons(button_structs);
|
||||
for (auto button_struct : button_structs)
|
||||
{
|
||||
|
@ -36,8 +40,8 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
|||
button->setMaximumHeight(TEXT_SIZE * scale * 3 + 20);
|
||||
//button->resize(TEXT_SIZE * button->text().length() * scale * 3 + 20, TEXT_SIZE * scale * 3 + 10);
|
||||
buttons << button;
|
||||
layout_top->addWidget(button, 1);
|
||||
connect(button, &MiniButton::click0, button, &MiniButton::onclick1);
|
||||
layout_top_right->addWidget(button, 1);
|
||||
connect(button, &MiniButton::clicked, button, &MiniButton::onclick1);
|
||||
connect(button, &MiniButton::click1, this, &ApplicationManager::onclick1);
|
||||
}
|
||||
//ui.tabWidget->setStyleSheet("border:none;");
|
||||
|
@ -49,24 +53,29 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
|||
tab_bar = new QTabBar(this);
|
||||
layout_bottom_top = new QVBoxLayout;
|
||||
|
||||
for(int i=1;i<=8;i++)
|
||||
for(int i=0;i<categrories.length();i++)
|
||||
{
|
||||
tab_bar->addTab(categrories[i - 1].name + "(" + QString::number(categrories[i - 1].total) + ")");
|
||||
tab_bar->addTab(categrories[i].name + "(" + QString::number(categrories[i].total) + ")");
|
||||
map2.insert(i, categrories[i].id);
|
||||
}
|
||||
layout_bottom_top->addWidget(tab_bar, 1);
|
||||
layout_top_left->addWidget(tab_bar, 1);
|
||||
layout_top->addLayout(layout_top_left, 7);
|
||||
layout_top->addLayout(layout_top_right, 3);
|
||||
application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
|
||||
connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh);
|
||||
layout_bottom_top->addWidget(application_manager_page_all, 19);
|
||||
map.insert(1, application_manager_page_all);
|
||||
for(int i=2;i<=8;i++)
|
||||
map.insert(ALL, application_manager_page_all);
|
||||
for(int i=2;i<=CATEGORIES_NUM;i++)
|
||||
{
|
||||
ApplicationManagerPage* application_manager_page = new ApplicationManagerPage(i, this, this);
|
||||
connect(this, &ApplicationManager::refresh, application_manager_page, &ApplicationManagerPage::refresh);
|
||||
layout_bottom_top->addWidget(application_manager_page, 19);
|
||||
layout_bottom_top->addWidget(application_manager_page, 1);
|
||||
application_manager_page->setHidden(true);
|
||||
map.insert(i, application_manager_page);
|
||||
}
|
||||
connect(this,&ApplicationManager::refresh,this,&ApplicationManager::onNumChange);
|
||||
//先不刷新,创建完navbar再刷新
|
||||
//emit refresh();
|
||||
connect(this,&ApplicationManager::refresh_tab,this,&ApplicationManager::onNumChange);
|
||||
tab_bar->setCurrentIndex(0);
|
||||
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
|
||||
QString style = "QTabBar::tab{height:80;width:150; border:2px} QTabBar::tab:hover{ border:2px;height:80;width:150;color:";
|
||||
|
@ -76,63 +85,7 @@ ApplicationManager::ApplicationManager(QWidget *parent)
|
|||
style += ";}";
|
||||
tab_bar->setStyleSheet(style);
|
||||
tab_bar->setDrawBase(false);
|
||||
/*ApplicationManagerPage* application_manager_page_all = new ApplicationManagerPage(ALL,this);
|
||||
QHBoxLayout *application_manager_page_all_layout = new QHBoxLayout;
|
||||
application_manager_page_all_layout->addWidget(application_manager_page_all);
|
||||
pages.insert(application_manager_page_all_layout, application_manager_page_all);
|
||||
ui.tab_1->setLayout(application_manager_page_all_layout);
|
||||
ui.tabWidget->setTabText(0,QString::fromLocal8Bit("全部"));
|
||||
|
||||
ApplicationManagerPage* application_manager_page_elite = new ApplicationManagerPage(ELITE,this);
|
||||
QHBoxLayout* application_manager_page_elite_layout = new QHBoxLayout;
|
||||
application_manager_page_elite_layout->addWidget(application_manager_page_elite);
|
||||
ui.tab_2->setLayout(application_manager_page_elite_layout);
|
||||
pages.insert(application_manager_page_elite_layout, application_manager_page_elite);
|
||||
ui.tabWidget->setTabText(1, categrories[0].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_soft = new ApplicationManagerPage(SOFT,this);
|
||||
QHBoxLayout* application_manager_page_soft_layout = new QHBoxLayout;
|
||||
application_manager_page_soft_layout->addWidget(application_manager_page_soft);
|
||||
pages.insert(application_manager_page_soft_layout, application_manager_page_soft);
|
||||
ui.tab_3->setLayout(application_manager_page_soft_layout);
|
||||
ui.tabWidget->setTabText(2, categrories[1].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_system = new ApplicationManagerPage(SYSTEM,this);
|
||||
QHBoxLayout* application_manager_page_system_layout = new QHBoxLayout;
|
||||
application_manager_page_system_layout->addWidget(application_manager_page_system);
|
||||
pages.insert(application_manager_page_system_layout, application_manager_page_system);
|
||||
ui.tab_4->setLayout(application_manager_page_system_layout);
|
||||
ui.tabWidget->setTabText(3, categrories[2].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_inner = new ApplicationManagerPage(INNER,this);
|
||||
QHBoxLayout* application_manager_page_inner_layout = new QHBoxLayout;
|
||||
application_manager_page_inner_layout->addWidget(application_manager_page_inner);
|
||||
pages.insert(application_manager_page_inner_layout, application_manager_page_inner);
|
||||
ui.tab_5->setLayout(application_manager_page_inner_layout);
|
||||
ui.tabWidget->setTabText(4, categrories[3].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_custom_1 = new ApplicationManagerPage(CUSTOM_1, this);
|
||||
QHBoxLayout* application_manager_page_custom_1_layout = new QHBoxLayout;
|
||||
application_manager_page_custom_1_layout->addWidget(application_manager_page_custom_1);
|
||||
pages.insert(application_manager_page_custom_1_layout, application_manager_page_custom_1);
|
||||
ui.tab_6->setLayout(application_manager_page_custom_1_layout);
|
||||
ui.tabWidget->setTabText(5, categrories[4].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_custom_2 = new ApplicationManagerPage(CUSTOM_2, this);
|
||||
QHBoxLayout* application_manager_page_custom_2_layout = new QHBoxLayout;
|
||||
application_manager_page_custom_2_layout->addWidget(application_manager_page_custom_2);
|
||||
pages.insert(application_manager_page_custom_2_layout, application_manager_page_custom_2);
|
||||
ui.tab_7->setLayout(application_manager_page_custom_2_layout);
|
||||
ui.tabWidget->setTabText(6, categrories[5].name);
|
||||
|
||||
ApplicationManagerPage* application_manager_page_others = new ApplicationManagerPage(OTHERS,this);
|
||||
QHBoxLayout* application_manager_page_others_layout = new QHBoxLayout;
|
||||
application_manager_page_others_layout->addWidget(application_manager_page_others);
|
||||
pages.insert(application_manager_page_others_layout, application_manager_page_others);
|
||||
ui.tab_8->setLayout(application_manager_page_others_layout);
|
||||
ui.tabWidget->setTabText(7, categrories[6].name);*/
|
||||
layout_bottom->addLayout(layout_bottom_top,7);
|
||||
layout_bottom->addWidget(miniblink, 3);
|
||||
layout->addLayout(layout_top, 1);
|
||||
layout->addLayout(layout_bottom, 9);
|
||||
setLayout(layout);
|
||||
|
@ -149,7 +102,8 @@ ApplicationManager::~ApplicationManager()
|
|||
delete pages[layout];
|
||||
delete layout;
|
||||
}
|
||||
delete miniblink;
|
||||
delete layout_top_left;
|
||||
delete layout_top_right;
|
||||
delete layout_top;
|
||||
delete layout_bottom;
|
||||
delete layout;
|
||||
|
@ -169,65 +123,77 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
|
|||
add_app.get_sort(), add_app.get_categories());
|
||||
if (!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名"));
|
||||
}
|
||||
|
||||
emit refresh();
|
||||
/*table->insertRow(table->rowCount()-1);
|
||||
table->setItem(table->rowCount(), 0, new QTableWidgetItem(add_app.get_name()));
|
||||
table->setItem(table->rowCount(), 1, new QTableWidgetItem(add_app.get_orig_name()));
|
||||
Record2 record2;
|
||||
srand(time(nullptr));
|
||||
|
||||
int id = rand();
|
||||
if(id<RAND_MAX-100000)
|
||||
{
|
||||
id += 100000;
|
||||
}
|
||||
record2.settings = new MiniButton(id, "settings");
|
||||
record2.settings->setText(QString::fromLocal8Bit("设置"));
|
||||
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2);
|
||||
connect(record2.settings, &MiniButton::click2, this, &ApplicationManager::onclick2);
|
||||
record2.open = new MiniButton(id, "open");
|
||||
record2.open->setText(QString::fromLocal8Bit("打开"));
|
||||
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2);
|
||||
connect(record2.open, &MiniButton::click2, this, &ApplicationManager::onclick2);
|
||||
record2.exe_file = add_app.get_exe_path();
|
||||
record2.orig_name = add_app.get_orig_name();
|
||||
table->setCellWidget(table->rowCount(), 4, record2.settings);
|
||||
table->setCellWidget(table->rowCount(), 5, record2.open);
|
||||
rows.insert(id, record2);*/
|
||||
}
|
||||
}
|
||||
else if (func == "app_update")
|
||||
{
|
||||
bool software_ok = sqlite_helper.update_software();
|
||||
bool app_ok = sqlite_helper.update_app();
|
||||
if(software_ok&&app_ok)
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_FILE);
|
||||
if(file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功"));
|
||||
QByteArray ba = file.readAll();
|
||||
file.close();
|
||||
QJsonParseError json_error;
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(ba, &json_error));
|
||||
if (json_error.error == QJsonParseError::NoError)
|
||||
{
|
||||
QJsonObject rootObj = jsonDoc.object();
|
||||
agree=rootObj.value("agree").toBool();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
}
|
||||
}else
|
||||
{
|
||||
UserImprove user_improve;
|
||||
user_improve.exec();
|
||||
if(file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QJsonObject rootObj;
|
||||
rootObj.insert("agree", agree);
|
||||
QJsonDocument jsonDoc;
|
||||
jsonDoc.setObject(rootObj);
|
||||
file.write(jsonDoc.toJson());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(agree)
|
||||
{
|
||||
DeviceRequest *device_request = new DeviceRequest;//构造函数里面会自动发送请求
|
||||
delete device_request;
|
||||
}
|
||||
if(software_ok&&app_ok)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功"));
|
||||
emit refresh();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败,全名是否重名?"));
|
||||
}
|
||||
}else if(func=="app_category")
|
||||
{
|
||||
AddCategory add_category;
|
||||
add_category.exec();
|
||||
if(add_category.changed)
|
||||
{
|
||||
for(int i=0;i<7;i++)
|
||||
for(int i=0;i<add_category.categrories.length();i++)
|
||||
{
|
||||
tab_bar->setTabText(i + 1, add_category.categrories[i].name);
|
||||
}
|
||||
bool ok = sqlite_helper.set_category(add_category.categrories);
|
||||
if (!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("添加失败,分类是否重名?"));
|
||||
}
|
||||
emit refresh();
|
||||
emit refresh_tab();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -248,10 +214,11 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
|
|||
|
||||
void ApplicationManager::onclick2(QString orig_name, QString op)
|
||||
{
|
||||
sqlite_helper.use_software(orig_name);
|
||||
if (op == "app")
|
||||
{
|
||||
if (application_manager_page_all->rows[orig_name].func == "openwechat") {
|
||||
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].exe_file, application_manager_page_all->rows[orig_name].url);
|
||||
emit application_manager_page_all->onclick3(orig_name,application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].exe_file, application_manager_page_all->rows[orig_name].url);
|
||||
}
|
||||
else {
|
||||
emit changeUrl(application_manager_page_all->rows[orig_name].url);
|
||||
|
@ -267,14 +234,14 @@ void ApplicationManager::onclick2(QString orig_name, QString op)
|
|||
bool ok = sqlite_helper.edit_software(add_app.get_name(), add_app.get_orig_name(), add_app.get_exe_path(), add_app.get_sort(), add_app.get_categories());
|
||||
if (!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
|
||||
}
|
||||
emit refresh();
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op,
|
||||
emit application_manager_page_all->onclick3(orig_name,application_manager_page_all->rows[orig_name].op,
|
||||
application_manager_page_all->rows[orig_name].func,
|
||||
application_manager_page_all->rows[orig_name].url,
|
||||
application_manager_page_all->rows[orig_name].exe_file
|
||||
|
@ -289,13 +256,42 @@ void ApplicationManager::tabChange(int index)
|
|||
{
|
||||
map[i]->setHidden(true);
|
||||
}
|
||||
map[index + 1]->setHidden(false);
|
||||
map[map2[index]]->setHidden(false);
|
||||
}
|
||||
|
||||
void ApplicationManager::onNumChange() {
|
||||
QList<Categrory> categrories;
|
||||
sqlite_helper.get_category(categrories, false, true);
|
||||
for (int i = 0; i < categrories.size(); i++) {
|
||||
tab_bar->setTabText(i, categrories[i].name + "(" + QString::number(categrories[i].total) + ")");
|
||||
int count = tab_bar->count();
|
||||
disconnect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
tab_bar->removeTab(0);
|
||||
}
|
||||
for(auto i:map.values())
|
||||
{
|
||||
delete i;
|
||||
}
|
||||
application_manager_page_all = new ApplicationManagerPage(ALL, this, this);
|
||||
connect(this, &ApplicationManager::refresh, application_manager_page_all, &ApplicationManagerPage::refresh);
|
||||
layout_bottom_top->addWidget(application_manager_page_all, 19);
|
||||
map.insert(ALL, application_manager_page_all);
|
||||
for (int i = 2; i <= CATEGORIES_NUM; i++)
|
||||
{
|
||||
ApplicationManagerPage* application_manager_page = new ApplicationManagerPage(i, this, this);
|
||||
connect(this, &ApplicationManager::refresh, application_manager_page, &ApplicationManagerPage::refresh);
|
||||
layout_bottom_top->addWidget(application_manager_page, 1);
|
||||
application_manager_page->setHidden(true);
|
||||
map.insert(i, application_manager_page);
|
||||
}
|
||||
QList<Categrory> categories;
|
||||
map2.clear();
|
||||
sqlite_helper.get_category(categories,false);
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
tab_bar->addTab(categories[i].name + "(" + QString::number(categories[i].total) + ")");
|
||||
map2.insert(i, categories[i].id);
|
||||
}
|
||||
connect(tab_bar, &QTabBar::currentChanged, this, &ApplicationManager::tabChange);
|
||||
|
||||
tab_bar->setCurrentIndex(0);
|
||||
emit refresh();
|
||||
}
|
||||
ApplicationManager *application_manager;
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "sqlitehelper.h"
|
||||
|
@ -16,6 +16,8 @@
|
|||
#include "ui_applicationmanager.h"
|
||||
#include <QTabBar>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include "config.h"
|
||||
class ApplicationManagerPage;
|
||||
|
||||
struct Record2
|
||||
|
@ -24,7 +26,7 @@ struct Record2
|
|||
QLabel *orig_name;
|
||||
QLabel *dev;
|
||||
QLabel *use_time;*/
|
||||
QSvgWidget* icon;
|
||||
QLabel* icon;
|
||||
MiniButton* settings;
|
||||
MiniButton * open;
|
||||
QString op;
|
||||
|
@ -33,9 +35,10 @@ struct Record2
|
|||
QString orig_name;
|
||||
QString exe_file;
|
||||
QCheckBox *check_box;
|
||||
bool is_locked;
|
||||
int sort;
|
||||
QString url;
|
||||
bool categories[8];
|
||||
bool categories[CATEGORIES_NUM];
|
||||
};
|
||||
|
||||
struct Title
|
||||
|
@ -52,6 +55,7 @@ class ApplicationManager : public QWidget
|
|||
signals:
|
||||
void changeUrl(QString url);
|
||||
void refresh();
|
||||
void refresh_tab();
|
||||
public:
|
||||
ApplicationManager(QWidget *parent = nullptr);
|
||||
~ApplicationManager();
|
||||
|
@ -61,6 +65,7 @@ private:
|
|||
QVBoxLayout* layout;
|
||||
QTabBar *tab_bar;
|
||||
QMap<int, ApplicationManagerPage*> map;
|
||||
QMap<int,int> map2;
|
||||
QHBoxLayout* layout_top;
|
||||
QHBoxLayout* layout_bottom;
|
||||
QMiniBlink* miniblink;
|
||||
|
@ -69,6 +74,8 @@ private:
|
|||
QList<ButtonStruct> button_structs;
|
||||
ApplicationManagerPage* application_manager_page_all;
|
||||
Ui::ApplicationManagerClass ui;
|
||||
QHBoxLayout* layout_top_left;
|
||||
QHBoxLayout* layout_top_right;
|
||||
SQLiteHelper sqlite_helper;
|
||||
QVBoxLayout *layout_bottom_top;
|
||||
QTableWidget *table;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "applicationmanagerpage.h"
|
||||
#include "applicationmanagerpage.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
|
@ -12,20 +12,21 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager
|
|||
{
|
||||
ui.setupUi(this);
|
||||
this->category = category;
|
||||
this->parent = parent;
|
||||
this->application_manager = application_manager;
|
||||
sqlite_helper.get_buttons(button_structs);
|
||||
layout = new QVBoxLayout;
|
||||
sqlite_helper.get_all_software(softwares, category);
|
||||
table = new QTableWidget(this);
|
||||
table->setColumnCount(8);
|
||||
table->setColumnCount(9);
|
||||
QStringList titles;
|
||||
titles<< QString::fromLocal8Bit("图标") << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("全名") << QString::fromLocal8Bit("开发者") << QString::fromLocal8Bit("最后使用日期") << QString::fromLocal8Bit("添加到导航条") <<QString::fromLocal8Bit("设置") << QString::fromLocal8Bit("打开");
|
||||
titles<< QString::fromLocal8Bit("图标") << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("全名") << QString::fromLocal8Bit("开发者") << QString::fromLocal8Bit("最后使用日期")<<QString::fromLocal8Bit("排序") << QString::fromLocal8Bit("添加到导航条") <<QString::fromLocal8Bit("设置") << QString::fromLocal8Bit("打开");
|
||||
table->setHorizontalHeaderLabels(titles);
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->setStyleSheet("QTableWidget{border:1px;outline:1px;align: center;} QQTableWidget::widget QTableWidget::item {text-align: center;}");
|
||||
table->horizontalHeader()->setDefaultAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
int i = 0;
|
||||
for (i = 0; i < 8; i++)
|
||||
for (i = 0; i < 9; i++)
|
||||
{
|
||||
table->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
|
||||
|
||||
|
@ -34,92 +35,6 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager
|
|||
QTableWidgetItem* item = new QTableWidgetItem;
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setItemPrototype(item);
|
||||
for (auto software : softwares)
|
||||
{
|
||||
table->insertRow(i);
|
||||
|
||||
table->setItem(i, 1, new QTableWidgetItem(software.name));
|
||||
table->setItem(i, 2, new QTableWidgetItem(software.orig_name));
|
||||
table->setItem(i, 3, new QTableWidgetItem(software.dev));
|
||||
QString date;
|
||||
std::tm* time;
|
||||
time = std::localtime(&software.use_time);
|
||||
date = QString::number(1900 + time->tm_year, 10);
|
||||
date += "/";
|
||||
date += QString::number(1 + time->tm_mon, 10);
|
||||
date += "/";
|
||||
date += QString::number(time->tm_mday, 10);
|
||||
if (software.use_time == 0) {
|
||||
date.clear();
|
||||
}
|
||||
table->setItem(i, 4, new QTableWidgetItem(date));
|
||||
Record2 record2;
|
||||
record2.name = software.name;
|
||||
record2.icon = new QSvgWidget;
|
||||
QFile file(software.logo);
|
||||
if(file.exists())
|
||||
{
|
||||
record2.icon->load(software.logo);
|
||||
}
|
||||
else {
|
||||
record2.icon->load(QApplication::applicationDirPath() + DEFAULT_IMAGE);
|
||||
}
|
||||
record2.icon->setMaximumSize(80, 80);
|
||||
table->setCellWidget(i, 0, record2.icon);
|
||||
record2.settings = new MiniButton(software.orig_name, "settings");
|
||||
record2.settings->setText(QString::fromLocal8Bit("设置"));
|
||||
record2.settings->setMaximumSize(60, 40);
|
||||
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2);
|
||||
connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
record2.open = new MiniButton(software.orig_name,software.op);
|
||||
record2.open->setText(QString::fromLocal8Bit("打开"));
|
||||
record2.open->setMaximumSize(60, 40);
|
||||
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2);
|
||||
connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
record2.exe_file = software.path;
|
||||
record2.orig_name = software.orig_name;
|
||||
record2.url = software.url;
|
||||
record2.op = software.op;
|
||||
record2.func = software.func;
|
||||
connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
record2.categories[i] = false;
|
||||
}
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
if (software.category_id.contains(QString::number(i+1)))
|
||||
{
|
||||
record2.categories[i] = true;
|
||||
}
|
||||
}
|
||||
record2.sort = software.sort;
|
||||
record2.check_box = new QCheckBox;
|
||||
if(software.type=="navbar")
|
||||
{
|
||||
record2.check_box->setCheckState(Qt::Checked);
|
||||
checked.insert(software.orig_name, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
record2.check_box->setCheckState(Qt::Unchecked);
|
||||
checked.insert(software.orig_name, false);
|
||||
}
|
||||
connect(record2.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked);
|
||||
QTableWidgetItem* check_box_item = new QTableWidgetItem;
|
||||
table->setItem(i, 5, check_box_item);
|
||||
table->setCellWidget(i, 5, record2.check_box);
|
||||
check_box_item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 6, record2.settings);
|
||||
//table->item(i, 5)->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 7, record2.open);
|
||||
//table->item(i, 6)->setTextAlignment(Qt::AlignCenter);
|
||||
rows.insert(software.orig_name, record2);
|
||||
table->resizeColumnToContents(0);
|
||||
//table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
|
||||
//table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||
i++;
|
||||
}
|
||||
layout->addWidget(table);
|
||||
setLayout(layout);
|
||||
|
||||
|
@ -134,11 +49,11 @@ ApplicationManagerPage::~ApplicationManagerPage()
|
|||
delete layout;
|
||||
}
|
||||
|
||||
void ApplicationManagerPage::onclicked()
|
||||
void ApplicationManagerPage::onclicked(int state)
|
||||
{
|
||||
for(int i=0;i<table->rowCount();i++)
|
||||
{
|
||||
if(((QCheckBox *)table->cellWidget(i,5))->checkState()==Qt::Checked)
|
||||
if(((QCheckBox *)table->cellWidget(i,6))->checkState()==Qt::Checked)
|
||||
{
|
||||
if(!checked[table->item(i,2)->text()])
|
||||
{
|
||||
|
@ -146,9 +61,10 @@ void ApplicationManagerPage::onclicked()
|
|||
bool ok=sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories,"navbar");
|
||||
if(!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||
break;
|
||||
}
|
||||
checked[table->item(i, 2)->text()] = true;
|
||||
}
|
||||
}else
|
||||
{
|
||||
|
@ -158,18 +74,23 @@ void ApplicationManagerPage::onclicked()
|
|||
bool ok = sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories, "app");
|
||||
if (!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败"));
|
||||
break;
|
||||
}
|
||||
checked[table->item(i, 2)->text()] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
emit application_manager->refresh();
|
||||
//在后面refresh,避免因为refresh导致信号和槽断开
|
||||
}
|
||||
|
||||
//刷新页面
|
||||
void ApplicationManagerPage::refresh()
|
||||
{
|
||||
int rowcount = table->rowCount();
|
||||
for(auto i : connections)
|
||||
{
|
||||
disconnect(i);
|
||||
}
|
||||
for(int i=0;i<rowcount;i++)
|
||||
{
|
||||
table->removeRow(0);
|
||||
|
@ -197,37 +118,51 @@ void ApplicationManagerPage::refresh()
|
|||
date += QString::number(time->tm_mday, 10);
|
||||
table->setItem(i, 4, new QTableWidgetItem(date));
|
||||
}
|
||||
else
|
||||
{
|
||||
table->setItem(i, 4, new QTableWidgetItem(QString::fromLocal8Bit("从未使用")));
|
||||
}
|
||||
Record2 record2;
|
||||
record2.name = software.name;
|
||||
record2.icon = new QSvgWidget;
|
||||
QFile file(software.logo);
|
||||
record2.icon = new QLabel;
|
||||
QFile file(software.img);
|
||||
record2.icon->setMaximumSize(50, 50);
|
||||
record2.icon->setScaledContents(true);
|
||||
if (file.exists())
|
||||
{
|
||||
record2.icon->load(software.logo);
|
||||
QPixmap pixmap(software.img);
|
||||
//pixmap.scaled(40, 40);
|
||||
record2.icon->setPixmap(pixmap);
|
||||
}
|
||||
else {
|
||||
record2.icon->load(QApplication::applicationDirPath() + DEFAULT_IMAGE);
|
||||
QPixmap pixmap(QApplication::applicationDirPath() + DEFAULT_PNG);
|
||||
//pixmap.scaled(40, 40);
|
||||
record2.icon->setPixmap(pixmap);
|
||||
}
|
||||
record2.icon->setMaximumSize(80, 80);
|
||||
|
||||
table->setCellWidget(i, 0, record2.icon);
|
||||
record2.settings = new MiniButton(software.orig_name, "settings");
|
||||
record2.settings->setText(QString::fromLocal8Bit("设置"));
|
||||
record2.settings->setText(QString::fromLocal8Bit("设置"));
|
||||
record2.settings->setMaximumSize(60, 40);
|
||||
connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2);
|
||||
connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
QMetaObject::Connection connect1=connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2);
|
||||
connections << connect1;
|
||||
QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
connections << connect2;
|
||||
record2.open = new MiniButton(software.orig_name, "open");
|
||||
record2.open->setText(QString::fromLocal8Bit("打开"));
|
||||
record2.open->setText(QString::fromLocal8Bit("打开"));
|
||||
record2.open->setMaximumSize(60, 40);
|
||||
connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2);
|
||||
connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
QMetaObject::Connection connect3=connect(record2.open, &MiniButton::clicked, record2.open, &MiniButton::onclick2);
|
||||
connections << connect3;
|
||||
QMetaObject::Connection connect4=connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
connections << connect4;
|
||||
record2.exe_file = software.path;
|
||||
record2.orig_name = software.orig_name;
|
||||
record2.url = software.url;
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
record2.categories[i] = false;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
if (software.category_id.contains(QString::number(i+1)))
|
||||
{
|
||||
|
@ -236,10 +171,11 @@ void ApplicationManagerPage::refresh()
|
|||
}
|
||||
record2.op = software.op;
|
||||
record2.func = software.func;
|
||||
connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
|
||||
QMetaObject::Connection connect5 = connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton);
|
||||
connections<<connect5;
|
||||
record2.sort = software.sort;
|
||||
record2.check_box = new QCheckBox;
|
||||
if (software.type == "navbar")
|
||||
if (software.is_navbar)
|
||||
{
|
||||
record2.check_box->setCheckState(Qt::Checked);
|
||||
checked.insert(software.orig_name, true);
|
||||
|
@ -249,19 +185,28 @@ void ApplicationManagerPage::refresh()
|
|||
record2.check_box->setCheckState(Qt::Unchecked);
|
||||
checked.insert(software.orig_name, false);
|
||||
}
|
||||
connect(record2.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked);
|
||||
if(software.locked)
|
||||
{
|
||||
record2.check_box->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
record2.check_box->setEnabled(true);
|
||||
}
|
||||
|
||||
QMetaObject::Connection connect6 = connect(record2.check_box, &QCheckBox::stateChanged, this, &ApplicationManagerPage::onclicked);
|
||||
connections << connect6;
|
||||
QMetaObject::Connection connect7 = connect(record2.check_box, &QCheckBox::stateChanged, mainWindowLayout->navBar, &NavBar::refresh);
|
||||
connections << connect7;
|
||||
table->setItem(i, 5, new QTableWidgetItem(QString::number(software.sort)));
|
||||
QTableWidgetItem* check_box_item = new QTableWidgetItem;
|
||||
table->setItem(i, 5, check_box_item);
|
||||
table->setCellWidget(i, 5, record2.check_box);
|
||||
table->setItem(i, 6, check_box_item);
|
||||
table->setCellWidget(i, 6, record2.check_box);
|
||||
check_box_item->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 6, record2.settings);
|
||||
//table->item(i, 5)->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 7, record2.open);
|
||||
//table->item(i, 6)->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 7, record2.settings);
|
||||
table->setCellWidget(i, 8, record2.open);
|
||||
rows.insert(software.orig_name, record2);
|
||||
table->resizeColumnToContents(0);
|
||||
//table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
|
||||
//table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -17,7 +17,7 @@ class ApplicationManagerPage : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void onclick3(QString op, QString func, QString url, QString path,QString initial_position="");
|
||||
void onclick3(QString orig_name,QString op, QString func, QString url, QString path,QString initial_position="");
|
||||
public:
|
||||
ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr);
|
||||
~ApplicationManagerPage();
|
||||
|
@ -28,6 +28,7 @@ private:
|
|||
QVBoxLayout* layout;
|
||||
QHBoxLayout* layout_top;
|
||||
QHBoxLayout* layout_bottom;
|
||||
QList<QMetaObject::Connection> connections;
|
||||
QMiniBlink* miniblink;
|
||||
QList<MiniButton*> buttons;
|
||||
QList<Record> softwares;
|
||||
|
@ -39,7 +40,8 @@ private:
|
|||
ApplicationManager* application_manager;
|
||||
Title *title;
|
||||
int category;
|
||||
QWidget *parent;
|
||||
public slots:
|
||||
void refresh();
|
||||
void onclicked();
|
||||
void onclicked(int state);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
|||
typedef struct taButtonStruct{
|
||||
QImage *image;
|
||||
QImage *image_cover;
|
||||
QImage *png;
|
||||
QString text;
|
||||
QString orig_name;
|
||||
QString url;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config" //获取导航栏信息的地址
|
||||
#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op" //上传是否设置开机启动、是否建立桌面快捷方式的地址
|
||||
#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址
|
||||
#define WECHAT_URL " http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open"
|
||||
#define WECHAT_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open"
|
||||
#define BASE_URL "http://softapi.s103.y01.cn/" //域名
|
||||
#define DEFAULT_FILE "/config/config.kmd" //默认配置文件位置
|
||||
#define DEFAULT_NAVBAR_FILLE "/config/default_navbar.kmd"
|
||||
|
@ -28,8 +28,10 @@
|
|||
#define DEFAULT_IMAGE "/images/svg/default.svg" //默认图标
|
||||
#define DEFAULT_SVG_PATH "/images/svg/"
|
||||
#define DEFAULT_LOGO "/images/logo.png" //logo路径
|
||||
#define DEFAULT_PNG_PATH "/images/png/" //png路径
|
||||
#define TITLE " " //标题栏
|
||||
#define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制
|
||||
#define DEFAULT_PNG "/images/png/default.png" //默认PNG图标
|
||||
#define TEXT_SIZE_BIG 10
|
||||
//分类
|
||||
#define ALL 1
|
||||
|
@ -40,4 +42,5 @@
|
|||
#define CUSTOM_1 6
|
||||
#define CUSTOM_2 7
|
||||
#define OTHERS 8
|
||||
#define CATEGORIES_NUM 8
|
||||
#endif //OFFICEASSISTANT_CONFIG_H
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/27.
|
||||
//
|
||||
|
||||
#ifndef OFFICEASSISTANT_GLOBALVARIABLES_H
|
||||
#define OFFICEASSISTANT_GLOBALVARIABLES_H
|
||||
#include "exitmanager.h"
|
||||
class ApplicationManager;
|
||||
class MainWindowLayout;
|
||||
extern ExitManager exit_manager;
|
||||
extern double scale;
|
||||
|
@ -12,4 +13,5 @@ extern MainWindowLayout *mainWindowLayout;
|
|||
extern QString url_param;
|
||||
extern bool autostart;
|
||||
extern bool agree;
|
||||
extern ApplicationManager *application_manager;
|
||||
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/27.
|
||||
//
|
||||
|
||||
|
@ -27,6 +27,7 @@ public:
|
|||
explicit MainScreen(QWidget *parent = nullptr);
|
||||
~MainScreen() override;
|
||||
QWidget* parent;
|
||||
ApplicationManager* application_manager;
|
||||
public slots:
|
||||
void clickButton1(QString op, QString url);
|
||||
void firstUrl(QString url);
|
||||
|
@ -38,7 +39,6 @@ private:
|
|||
QVBoxLayout *layout_left;
|
||||
QPushButton *button;
|
||||
QIcon *icon;
|
||||
ApplicationManager* application_manager;
|
||||
QWidget *broswer;
|
||||
static bool isInited();
|
||||
QWidget *widget;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
|
@ -25,92 +25,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
icon = new QIcon(path);
|
||||
setWindowIcon(*icon);
|
||||
setStyleSheet("*{font-family:SimHei;}");
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_FILE);
|
||||
if(!file.open(QIODevice::Text|QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
exit_manager.exit(1);
|
||||
}
|
||||
QByteArray buffer;
|
||||
buffer = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson(buffer);
|
||||
if(document.isObject())
|
||||
{
|
||||
if(document.object().value("agree").isUndefined())
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setWindowTitle(QString::fromLocal8Bit("用户体验改善计划"));
|
||||
msg.setText(QString::fromLocal8Bit("为改善我们的服务质量,我们将向服务器发送以下信息:\n"
|
||||
"1.您的计算机配置;\n"
|
||||
"2.您计算机上的软件安装列表;\n"
|
||||
"3.您是否设置了开机启动,以及是不是通过开机启动的方式启动本软件。\n"
|
||||
"第二项信息是我们提供服务所必需的,如您选择不同意但继续使用本软件,则第二项数据将正常发送,但第一项和第三项数据不会发送。选择不同意不影响您使用本软件。"));
|
||||
msg.addButton(QString::fromLocal8Bit("同意"), QMessageBox::AcceptRole);
|
||||
msg.addButton(QString::fromLocal8Bit("不同意"), QMessageBox::RejectRole);
|
||||
int ret = msg.exec();
|
||||
if(ret==QMessageBox::AcceptRole)
|
||||
{
|
||||
QJsonObject obj_root = document.object();
|
||||
obj_root.insert("agree", true);
|
||||
document.setObject(obj_root);
|
||||
agree = true;
|
||||
DeviceRequest* device_request = new DeviceRequest;//构造函数直接发出去数据了
|
||||
delete device_request;
|
||||
}else
|
||||
{
|
||||
QJsonObject obj_root = document.object();
|
||||
obj_root.insert("agree", false);
|
||||
document.setObject(obj_root);
|
||||
agree = false;
|
||||
}
|
||||
if(file.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
{
|
||||
file.write(document.toJson());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
else if(document.object().value("agree").toBool())
|
||||
{
|
||||
agree = true;
|
||||
DeviceRequest* device_request = new DeviceRequest;
|
||||
delete device_request;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setWindowTitle(QString::fromLocal8Bit("用户体验改善计划"));
|
||||
msg.setText(QString::fromLocal8Bit("为改善我们的服务质量,我们将向服务器发送以下信息:\n"
|
||||
"1.您的计算机配置;\n"
|
||||
"2.您计算机上的软件安装列表;\n"
|
||||
"3.您是否设置了开机启动,以及是不是通过开机启动的方式启动本软件。\n"
|
||||
"第二项信息是我们提供服务所必需的,如您选择不同意但继续使用本软件,则第二项数据将正常发送,但第一项和第三项数据不会发送。选择不同意不影响您使用本软件。"));
|
||||
msg.addButton(QString::fromLocal8Bit("同意"), QMessageBox::AcceptRole);
|
||||
msg.addButton(QString::fromLocal8Bit("不同意"), QMessageBox::RejectRole);
|
||||
int ret = msg.exec();
|
||||
if (ret == QMessageBox::AcceptRole)
|
||||
{
|
||||
QJsonObject obj_root;
|
||||
obj_root.insert("agree", true);
|
||||
document.setObject(obj_root);
|
||||
agree = true;
|
||||
DeviceRequest* device_request = new DeviceRequest;//构造函数直接发出去数据了
|
||||
delete device_request;
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonObject obj_root;
|
||||
obj_root.insert("agree", false);
|
||||
document.setObject(obj_root);
|
||||
agree = false;
|
||||
}
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
file.write(document.toJson());
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
|
@ -17,14 +17,11 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
|
|||
mainWindowLayout = this;
|
||||
QList<ButtonStruct> list;
|
||||
mainScreen = new MainScreen(this);
|
||||
navBar=new NavBar(mainScreen,this);
|
||||
navBar = new NavBar(mainScreen, this);
|
||||
emit mainScreen->application_manager->refresh_tab();
|
||||
navBar->setMinimumHeight(0);
|
||||
navBar->setMaximumHeight(this->height() / 8);
|
||||
mainScreen->setMinimumHeight(0);
|
||||
//navBar->setAttribute(Qt::WA_DeleteOnClose);
|
||||
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
|
||||
//navBar->setSizePolicy(sizePolicy);
|
||||
//layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(navBar,1);
|
||||
layout->addWidget(mainScreen,7);
|
||||
layout->setMargin(0);
|
||||
|
@ -48,7 +45,10 @@ void MainWindowLayout::resizeEvent(QResizeEvent *event) {
|
|||
//layout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
}
|
||||
|
||||
void MainWindowLayout::clickButton(QString op, QString func, QString url,QString path,QString initial_position) {
|
||||
void MainWindowLayout::clickButton(QString orig_name,QString op, QString func, QString url,QString path,QString initial_position) {
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.use_software(orig_name);
|
||||
emit mainScreen->application_manager->refresh();
|
||||
QString root_path = QApplication::applicationDirPath();
|
||||
if(op=="app")
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ void MainWindowLayout::clickButton(QString op, QString func, QString url,QString
|
|||
{
|
||||
path = root_path + path;
|
||||
path.replace("/", "\\");
|
||||
WinExec(path.toStdString().c_str(), SW_SHOW);
|
||||
ShellExecute(GetDesktopWindow(), L"open", path.toStdWString().c_str(), L"", initial_position.toStdWString().c_str(), SW_SHOW);
|
||||
emit clickButton1(op, url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
|
||||
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
@ -22,10 +22,10 @@ signals:
|
|||
void clickButton1(QString op,QString url);
|
||||
public:
|
||||
explicit MainWindowLayout(QWidget *parent = nullptr);
|
||||
|
||||
NavBar* navBar;
|
||||
~MainWindowLayout() override;
|
||||
public slots:
|
||||
void clickButton(QString op, QString func, QString url, QString path, QString initial_position);
|
||||
void clickButton(QString orig_name,QString op, QString func, QString url, QString path, QString initial_position);
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
//void paintEvent(QPaintEvent *event) override;
|
||||
|
@ -34,7 +34,6 @@ private:
|
|||
Ui::MainWindowLayout *ui;
|
||||
QVBoxLayout *layout;
|
||||
//QList<ButtonStruct *> list;
|
||||
NavBar *navBar;
|
||||
ButtonStruct *buttons;
|
||||
MainScreen *mainScreen;
|
||||
ConfigResponse *configResponse;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "minibutton.h"
|
||||
#include "minibutton.h"
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "globalvariables.h"
|
||||
|
@ -45,10 +45,6 @@ void MiniButton::paintEvent(QPaintEvent* event)
|
|||
|
||||
}
|
||||
|
||||
void MiniButton::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
emit click0();
|
||||
}
|
||||
|
||||
void MiniButton::onclick1()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
@ -18,7 +18,6 @@ public:
|
|||
~MiniButton();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
private:
|
||||
QString orig_name;
|
||||
QString op;
|
||||
|
|
|
@ -42,6 +42,7 @@ void ConvertImageToTransparent(QImage &img)
|
|||
NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::NavBar) {
|
||||
ui->setupUi(this);
|
||||
this->parent = parent;
|
||||
//this->setAttribute(Qt::WA_DeleteOnClose);
|
||||
buffer = new QByteArray;
|
||||
/*QString style = "background-color:";
|
||||
|
@ -55,7 +56,9 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
|
|||
config_request.sendRequest(&config_response);
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.get_software(&buttonStructs, &config_response);
|
||||
|
||||
background_color = config_response.basic.backgroud_color;
|
||||
text_color = config_response.basic.title_color;
|
||||
text_cover_color = config_response.basic.title_cover_color;
|
||||
if(!config_response.succeed)
|
||||
{
|
||||
qColor.setNamedColor(buttonStructs[0].background_color);
|
||||
|
@ -177,31 +180,24 @@ void NavBar::cancelDownload() {
|
|||
downloadSuccess = false;
|
||||
}
|
||||
|
||||
/*void NavBar::getLogoFromLocal() {
|
||||
QString dir = QApplication::applicationDirPath();
|
||||
QFile file(dir + DEFAULT_FILE);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
exit(1);
|
||||
void NavBar::refresh(int state)
|
||||
{
|
||||
SQLiteHelper sqlite_helper;
|
||||
buttonStructs.clear();
|
||||
sqlite_helper.get_software(&buttonStructs, background_color,text_color,text_cover_color);
|
||||
for(auto button:buttons)
|
||||
{
|
||||
layout_right->removeWidget(button);
|
||||
delete button;
|
||||
buttons.removeOne(button);
|
||||
}
|
||||
buffer->clear();
|
||||
*buffer = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument *qJsonDocument = new QJsonDocument;
|
||||
*qJsonDocument = QJsonDocument::fromJson(*buffer);
|
||||
QJsonObject *obj_root = new QJsonObject;
|
||||
if (qJsonDocument->isObject()) {
|
||||
*obj_root = qJsonDocument->object();
|
||||
delete qJsonDocument;
|
||||
QString logo_path = obj_root->value("basic").toObject().value("logo").toString();
|
||||
logo = new QPixmap(logo_path);
|
||||
QJsonArray *array = new QJsonArray;
|
||||
for (auto buttonStruct : buttonStructs) {
|
||||
MyButton* myButton = new MyButton(buttonStruct, height(), height(), &buttons, this);
|
||||
myButton->setMaximumHeight(parent->height() / 8);
|
||||
layout_right->addWidget(myButton);
|
||||
//myButton->show();
|
||||
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
|
||||
buttons << myButton;
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
delete obj_root;
|
||||
exit(1);
|
||||
}
|
||||
delete obj_root;
|
||||
|
||||
}*/
|
||||
emit application_manager->refresh();//在这里refresh,避免因为refresh导致信号和槽断开
|
||||
}
|
|
@ -28,6 +28,8 @@ class NavBar : public QWidget {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void firstUrl(QString url);
|
||||
public slots:
|
||||
void refresh(int state);
|
||||
public:
|
||||
NavBar(MainScreen *mainScreen,QWidget *parent = nullptr);
|
||||
|
||||
|
@ -48,6 +50,10 @@ private:
|
|||
QByteArray *buffer;
|
||||
int width2;
|
||||
int height2;
|
||||
QWidget* parent;
|
||||
QString background_color;
|
||||
QString text_color;
|
||||
QString text_cover_color;
|
||||
QNetworkAccessManager *manager;
|
||||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
|
|
|
@ -165,7 +165,7 @@ RequestBodyBase::RequestBodyBase(){
|
|||
url_param = "?";
|
||||
url_param += "product=";
|
||||
url_param += product;
|
||||
url_param += "&parter_id=";
|
||||
url_param += "&partner_id=";
|
||||
url_param += parter_id;
|
||||
url_param += "&os=";
|
||||
url_param += this->os;
|
||||
|
@ -252,14 +252,24 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
for(auto value:array){
|
||||
QJsonObject object=value.toObject();
|
||||
Button button;
|
||||
button.img=object.value("img").toString();
|
||||
button.orig_name= object.value("orig_name").toString();
|
||||
// button.img_cover=object.value("img_cover").toString();
|
||||
button.title=object.value("name").toString();
|
||||
button.categroy_id = object.value("category_id").toString();
|
||||
button.img = object.value("img").toString();
|
||||
button.png = object.value("logo").toString();
|
||||
button.img_name = object.value("img_name").toString();
|
||||
button.name = object.value("name").toString();
|
||||
button.type = object.value("type").toString();
|
||||
button.sort = object.value("sort").toInt();
|
||||
button.status = object.value("status").toInt();
|
||||
button.is_navbar = object.value("is_navbar").toBool();
|
||||
button.is_elite = object.value("is_elite").toBool();
|
||||
button.orig_name = object.value("orig_name").toString();
|
||||
button.categroy_id = object.value("categroy_id").toString();
|
||||
button.op = object.value("op").toString();
|
||||
button.func=object.value("func").toString();
|
||||
button.url=object.value("url").toString();
|
||||
button.func = object.value("func").toString();
|
||||
button.url = object.value("url").toString();
|
||||
button.dev = object.value("dev").toString();
|
||||
button.locked = object.value("locked").toBool();
|
||||
button.is_delete = object.value("is_delete").toBool();
|
||||
button.version = object.value("version").toString();
|
||||
configResponse->buttons << button;
|
||||
i++;
|
||||
}
|
||||
|
@ -620,7 +630,7 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
|
|||
QJsonObject object;
|
||||
object.insert("reg", array);
|
||||
object.insert("start", menu_list);
|
||||
object.insert("exists", software_exists);
|
||||
object.insert("app", software_exists);
|
||||
obj_root.insert("data", object);
|
||||
obj_root.insert("type", "update");
|
||||
qJsonDocument.setObject(obj_root);
|
||||
|
@ -643,8 +653,9 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
|
|||
// auto error = reply->error();
|
||||
//如果没有错误
|
||||
qDebug() << reply->error();
|
||||
auto result2=reply->readAll();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
result = QJsonDocument::fromJson(reply->readAll());
|
||||
result = QJsonDocument::fromJson(result2);
|
||||
}
|
||||
else {
|
||||
//如果有错误
|
||||
|
@ -652,7 +663,7 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
|
|||
return false;
|
||||
}
|
||||
//qDebug() << result.toJson();
|
||||
|
||||
records->clear();
|
||||
//如果数据完整
|
||||
if (result.isObject()) {
|
||||
QJsonObject obj_root2 = result.object();
|
||||
|
@ -689,17 +700,26 @@ bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QStrin
|
|||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
(*records)[orig_name].logo = dir + orig_name + ".svg";
|
||||
(*records)[orig_name].name = object.value("name").toString();
|
||||
(*records)[orig_name].locked = object.value("locked").toBool();
|
||||
(*records)[orig_name].url = object.value("url").toString();
|
||||
(*records)[orig_name].path = object.value("path").toString();
|
||||
if ((*records)[orig_name].path.isEmpty())
|
||||
{
|
||||
delete httpMgr;
|
||||
return false;
|
||||
}
|
||||
Record record;
|
||||
record.orig_name = orig_name;
|
||||
record.path = object.value("path").toString();
|
||||
record.img = dir + orig_name + ".svg";
|
||||
record.name = object.value("name").toString();
|
||||
record.version = object.value("version").toString();
|
||||
record.app_id=object.value("app_id").toString();
|
||||
record.locked=object.value("locked").toBool();
|
||||
record.type=object.value("type").toString();
|
||||
record.category_id=object.value("category_id").toString();
|
||||
record.status=object.value("status").toBool();
|
||||
record.op=object.value("op").toString();
|
||||
record.func=object.value("func").toString();
|
||||
record.initial_position=object.value("initial_position").toString();
|
||||
record.url=object.value("url").toString();
|
||||
record.logo=object.value("logo").toString();
|
||||
record.img=object.value("img").toString();
|
||||
record.is_navbar=object.value("is_navbar").toBool();
|
||||
record.is_elite=object.value("is_elite").toBool();
|
||||
records->insert(orig_name, record);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -734,8 +754,10 @@ QString OpenWeChatRequest::sendRequest(bool notuse)
|
|||
//启动循环
|
||||
eventLoop.exec();
|
||||
timer->stop();
|
||||
qDebug() << reply->error();
|
||||
QByteArray buffer = reply->readAll();
|
||||
QJsonDocument reply_json = QJsonDocument::fromJson(buffer);
|
||||
|
||||
if(!reply_json.isObject())
|
||||
{
|
||||
delete timer;
|
||||
|
@ -745,7 +767,6 @@ QString OpenWeChatRequest::sendRequest(bool notuse)
|
|||
}
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
delete reply;
|
||||
return reply_json.object().value("msg").toString();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//
|
||||
//
|
||||
// Created by HW on 2023/07/27.
|
||||
//
|
||||
|
||||
|
@ -17,13 +17,24 @@
|
|||
|
||||
typedef struct {
|
||||
QString img;
|
||||
QString img_cover;
|
||||
QString title;
|
||||
QString png;
|
||||
QString img_name;
|
||||
QString name;
|
||||
QString type;
|
||||
int sort;
|
||||
int status;
|
||||
bool is_navbar;
|
||||
bool is_elite;
|
||||
QString orig_name;
|
||||
QString categroy_id;
|
||||
QString op;
|
||||
QString func;
|
||||
QString url;
|
||||
QString dev;
|
||||
bool locked;
|
||||
bool is_delete;
|
||||
QString version;
|
||||
|
||||
} Button;
|
||||
struct ConfigResponse {
|
||||
bool succeed;
|
||||
|
@ -126,6 +137,6 @@ class OpenWeChatRequest:public RequestBodyBase
|
|||
{
|
||||
public:
|
||||
OpenWeChatRequest():RequestBodyBase(){}
|
||||
QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/);
|
||||
QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/);
|
||||
};
|
||||
#endif //OFFICEASSISTANT_NETIO_H
|
||||
|
|
|
@ -6,13 +6,52 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1142</width>
|
||||
<height>806</height>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>QMiniBlink</string>
|
||||
</property>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>130</y>
|
||||
<width>401</width>
|
||||
<height>61</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>我同意加入用户体验改善计划</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="detail">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>280</y>
|
||||
<width>150</width>
|
||||
<height>46</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>查看详情</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="submit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>370</x>
|
||||
<y>280</y>
|
||||
<width>150</width>
|
||||
<height>46</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>确定</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||
#include <experimental/filesystem>
|
||||
namespace fs= std::experimental::filesystem;
|
||||
|
||||
|
||||
|
||||
bool getMenu(std::wstring &path_str,QHash<QString,QString> *paths)
|
||||
{
|
||||
fs::directory_iterator* it = new fs::directory_iterator(path_str);
|
||||
|
@ -139,39 +142,6 @@ bool SQLiteHelper::update_software()
|
|||
{
|
||||
HKEY hKeyUninstall = nullptr;
|
||||
QHash<QString, QString>* paths = new QHash<QString, QString>;
|
||||
/*QSqlQuery query;
|
||||
QString sql = "select * from kmd_menu;";
|
||||
query.exec(sql);
|
||||
while(query.next())
|
||||
{
|
||||
Record record;
|
||||
record.id = query.value("id").toInt();
|
||||
record.sort = query.value("sort").toInt();
|
||||
record.app_id = query.value("app_id").toString();
|
||||
record.locked = query.value("locked").toBool();
|
||||
record.type = query.value("type").toString();
|
||||
record.category_id = query.value("category_id").toString();
|
||||
record.name = query.value("name").toString();
|
||||
record.orig_name = query.value("orig_name").toString();
|
||||
record.version = query.value("version").toString();
|
||||
record.dev = query.value("dev").toString();
|
||||
record.create_time = query.value("create_time").toLongLong();
|
||||
record.use_time = query.value("use_time").toLongLong();
|
||||
record.op = query.value("op").toString();
|
||||
record.func = query.value("func").toString();
|
||||
record.path = query.value("path").toString();
|
||||
record.url = query.value("url").toString();
|
||||
QStringList path_list = record.path.split("\\");
|
||||
path_list.removeLast();
|
||||
QString path;
|
||||
for(auto str : path_list)
|
||||
{
|
||||
path.append(str);
|
||||
path.append("\\");
|
||||
}
|
||||
path.remove(path.length() - 1, 1);
|
||||
records.insert(path, record);
|
||||
}*/
|
||||
//开始菜单中已安装软件列表
|
||||
WCHAR path[MAX_PATH];
|
||||
HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//获取ProgramData中开始菜单的路径
|
||||
|
@ -622,31 +592,7 @@ bool SQLiteHelper::update_software()
|
|||
}
|
||||
}
|
||||
|
||||
//对比两个路径,找出公共部分(划掉)
|
||||
QHash<QString, Record> public_programs_list;
|
||||
/*for(auto path:*paths)
|
||||
{
|
||||
QStringList path_list = path.split("\\");
|
||||
path_list.removeLast();
|
||||
QString path2;
|
||||
for(auto str : path_list)
|
||||
{
|
||||
path2.append(str);
|
||||
path2.append("\\");
|
||||
}
|
||||
if(reg_records.contains(path2))
|
||||
{
|
||||
reg_records[path2].path = path;
|
||||
public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]);
|
||||
}
|
||||
path2.remove(path2.length() - 1, 1);
|
||||
if(reg_records.contains(path2))
|
||||
{
|
||||
reg_records[path2].path = path;
|
||||
public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]);
|
||||
}
|
||||
}
|
||||
delete paths;*/
|
||||
for (auto key : reg_records.keys())
|
||||
{
|
||||
public_programs_list.insert(reg_records[key].orig_name, reg_records[key]);
|
||||
|
@ -674,7 +620,8 @@ bool SQLiteHelper::update_software()
|
|||
obj.insert("initial_position", find2.value("initial_position").toString());
|
||||
obj.insert("logo", find2.value("logo").toString());
|
||||
obj.insert("status", find2.value("status").toBool());
|
||||
obj.insert("is_delete", find2.value("is_delete").toBool());
|
||||
obj.insert("is_navbar", find2.value("is_navbar").toBool());
|
||||
obj.insert("is_elite", find2.value("is_elite").toBool());
|
||||
array.append(obj);
|
||||
}
|
||||
}
|
||||
|
@ -695,7 +642,7 @@ bool SQLiteHelper::update_software()
|
|||
}
|
||||
for(auto key : public_programs_list.keys())
|
||||
{
|
||||
|
||||
QSqlQuery query(db);
|
||||
QString sql_find = "select sort from kmd_menu where orig_name='";
|
||||
sql_find += key;
|
||||
sql_find += "';";
|
||||
|
@ -726,76 +673,32 @@ bool SQLiteHelper::update_software()
|
|||
}
|
||||
else
|
||||
{
|
||||
sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status) values (";
|
||||
sql += "50";
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].app_id;
|
||||
sql += "',";
|
||||
sql += QString::number(public_programs_list[key].locked);
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].type;
|
||||
sql += "','";
|
||||
sql += QString::number(ALL, 10);
|
||||
sql += ",";
|
||||
sql += QString::number(SOFT, 10);
|
||||
sql += ",";
|
||||
sql += QString::number(OTHERS, 10);
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].name;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].orig_name;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].version;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].dev;
|
||||
sql += "',";
|
||||
sql += QString::number(public_programs_list[key].create_time);
|
||||
sql += ",";
|
||||
sql += QString::number(public_programs_list[key].use_time);
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].op;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].func;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].path;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].url;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].status;
|
||||
sql += "');";
|
||||
bool categories[8] = { false };
|
||||
sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status,is_navbar,is_elite) values "
|
||||
"(:sort,:app_id,:locked,:type,:category_id,:name,:orig_name,:version,:dev,:create_time,:use_time,:op,:func,:path,:url,:status,:is_navbar,:is_elite); ";
|
||||
query.prepare(sql);
|
||||
query.bindValue(":sort", 50);
|
||||
query.bindValue(":app_id", public_programs_list[key].app_id);
|
||||
query.bindValue(":locked", public_programs_list[key].locked);
|
||||
query.bindValue(":type", public_programs_list[key].type);
|
||||
query.bindValue(":category_id", public_programs_list[key].category_id);
|
||||
query.bindValue(":name", public_programs_list[key].name);
|
||||
query.bindValue(":orig_name", public_programs_list[key].orig_name);
|
||||
query.bindValue(":version", public_programs_list[key].version);
|
||||
query.bindValue(":dev", public_programs_list[key].dev);
|
||||
query.bindValue(":create_time", public_programs_list[key].create_time);
|
||||
query.bindValue(":use_time", public_programs_list[key].use_time);
|
||||
query.bindValue(":op", public_programs_list[key].op);
|
||||
query.bindValue(":func", public_programs_list[key].func);
|
||||
query.bindValue(":path", public_programs_list[key].path);
|
||||
query.bindValue(":url", public_programs_list[key].url);
|
||||
query.bindValue(":is_navbar", public_programs_list[key].is_navbar);
|
||||
query.bindValue(":is_elite", public_programs_list[key].is_elite);
|
||||
query.bindValue(":status", true);
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
categories[ALL - 1] = true;
|
||||
categories[SOFT - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
update_total();
|
||||
if(!query.exec(sql))
|
||||
{
|
||||
QSqlQuery rollback("rollback;");
|
||||
|
@ -817,37 +720,10 @@ bool SQLiteHelper::update_software()
|
|||
del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;");
|
||||
del.bindValue(":orig_value", find.value("orig_name"));
|
||||
del.exec();
|
||||
bool categories[8] = { false };
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
categories[ALL - 1] = true;
|
||||
categories[SOFT - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total - 1);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -883,10 +759,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
{
|
||||
QSqlQuery query(db);
|
||||
QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;";
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString background_color;
|
||||
QString title_color;
|
||||
QString title_cover_color;
|
||||
|
@ -896,6 +769,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
background_color = config_response->basic.backgroud_color;
|
||||
title_color = config_response->basic.title_color;
|
||||
title_cover_color = config_response->basic.title_cover_color;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -913,25 +787,11 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
|
||||
array = obj_root.value("data").toObject().value("menu").toArray();
|
||||
qDebug() << array;
|
||||
QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject();
|
||||
QJsonObject obj_data = obj_root.value("data").toObject();
|
||||
QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object();
|
||||
background_color = obj_basic.value("backgroud_color").toString();
|
||||
title_color = obj_basic.value("title_color").toString();
|
||||
title_cover_color = obj_basic.value("title_cover_color").toString();
|
||||
auto i = 0;
|
||||
for (auto value : array) {
|
||||
QJsonObject object = value.toObject();
|
||||
Button button;
|
||||
button.img = object.value("img").toString();
|
||||
// button.img_cover=object.value("img_cover").toString();
|
||||
button.title = object.value("title").toString();
|
||||
button.categroy_id = object.value("category_id").toString();
|
||||
button.orig_name = object.value("orig_name").toString();
|
||||
button.op = object.value("op").toString();
|
||||
button.func = object.value("func").toString();
|
||||
button.url = object.value("url").toString();
|
||||
buttons << button;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
background_color = DEFAULT_BACKGROUND_COLOR;
|
||||
|
@ -940,13 +800,14 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray* buffer = new QByteArray;
|
||||
QHash<QString, ButtonStruct> button_map;
|
||||
QNetworkAccessManager* manager;
|
||||
for (auto menu : buttons)
|
||||
{
|
||||
ButtonStruct button_struct;
|
||||
button_struct.text = menu.title;
|
||||
button_struct.text = menu.name;
|
||||
button_struct.orig_name = menu.orig_name;
|
||||
button_struct.op = menu.op;
|
||||
button_struct.func = menu.func;
|
||||
|
@ -968,8 +829,9 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
*buffer = reply->readAll();
|
||||
delete request_logo;
|
||||
reply->close();
|
||||
QString svg_path = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg";;
|
||||
if ((reply->error() == QNetworkReply::NoError)&&(downloadSuccess == true)) {
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg");
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg");
|
||||
if (file.open(QIODevice::Text | QIODevice::WriteOnly))
|
||||
{
|
||||
file.write(*buffer);
|
||||
|
@ -978,8 +840,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg";
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg";
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
|
@ -1000,37 +861,78 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
}
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
QUrl url_png(menu.png);
|
||||
QNetworkRequest* request_png = new QNetworkRequest(url_logo);
|
||||
manager = new QNetworkAccessManager;
|
||||
reply = manager->get(*request_png);
|
||||
QTimer timer_png;
|
||||
timer_png.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
connect(&timer_png, &QTimer::timeout, this, &SQLiteHelper::cancelDownload);
|
||||
eventLoop.exec();
|
||||
timer_png.stop();
|
||||
QByteArray buffer_png;
|
||||
buffer_png = reply->readAll();
|
||||
delete request_png;
|
||||
reply->close();
|
||||
QString png_path = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";;
|
||||
if ((reply->error() == QNetworkReply::NoError) && (downloadSuccess == true))
|
||||
{
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png");
|
||||
if (file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
file.write(buffer_png);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
buffer_png = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_PNG;
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
buffer_png = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
for(int i=0;i<CATEGORIES_NUM;i++)
|
||||
{
|
||||
if (menu.categroy_id.contains(QString::number(i+1)))
|
||||
{
|
||||
categories[i] = true;
|
||||
}
|
||||
}
|
||||
if(menu.is_delete)
|
||||
{
|
||||
delete_software(menu.orig_name);
|
||||
}else
|
||||
{
|
||||
insert_software(menu.name, menu.orig_name, "", QString::number(menu.sort),
|
||||
categories, QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg",
|
||||
QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png", menu.type,
|
||||
menu.locked, menu.op, menu.func, menu.url, menu.is_navbar, menu.is_elite, menu.dev);
|
||||
}
|
||||
|
||||
QSvgRenderer* render_image = new QSvgRenderer(*buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(*buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
}
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + "/images/svg/" + query.value("orig_name").toString() + ".svg";
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
|
@ -1095,6 +997,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
delete render_image_cover;
|
||||
}
|
||||
}
|
||||
button_struct.png = new QImage(query.value("png").toString());
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
|
@ -1102,8 +1005,101 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
|||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
}
|
||||
QSqlQuery begin_query(db);
|
||||
begin_query.exec("BEGIN;");
|
||||
update_total();
|
||||
QSqlQuery commit_query(db);
|
||||
commit_query.exec("COMMIT;");
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs,QString background_color,QString title_color,QString title_cover_color)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;";
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
button_struct.orig_name = query.value("orig_name").toString();
|
||||
button_struct.op = query.value("op").toString();
|
||||
button_struct.func = query.value("func").toString();
|
||||
button_struct.url = query.value("url").toString();
|
||||
button_struct.initial_position = query.value("initial_position").toString();
|
||||
QImage* image = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QImage* image_cover = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QByteArray svg_buffer = file.readAll();
|
||||
file.close();
|
||||
QSvgRenderer* render_image = new QSvgRenderer(svg_buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QByteArray svg_buffer = file.readAll();
|
||||
file.close();
|
||||
QSvgRenderer* render_image = new QSvgRenderer(svg_buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
}
|
||||
}
|
||||
button_struct.png = new QImage(query.value("png").toString());
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
}
|
||||
QSqlQuery begin_query(db);
|
||||
begin_query.exec("BEGIN;");
|
||||
update_total();
|
||||
QSqlQuery commit_query(db);
|
||||
commit_query.exec("COMMIT;");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1122,7 +1118,7 @@ bool SQLiteHelper::update_app()
|
|||
{
|
||||
if(fs::is_directory(dir))
|
||||
{
|
||||
QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config.json";
|
||||
QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config/config.json";
|
||||
config_path.replace("/", "\\");
|
||||
QFile config_file(config_path);
|
||||
if(!config_file.open(QIODevice::Text|QIODevice::ReadOnly))
|
||||
|
@ -1150,7 +1146,7 @@ bool SQLiteHelper::update_app()
|
|||
QString sql = "insert into kmd_menu "
|
||||
"(sort, app_id, locked, type, category_id, name, orig_name,"
|
||||
" version, dev, create_time, op, func, path, url, "
|
||||
"logo, initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
"logo, initial_position,status,img,is_navbar,is_elite) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(50);
|
||||
query.addBindValue(obj_root.value("app_id").toString());
|
||||
|
@ -1169,32 +1165,14 @@ bool SQLiteHelper::update_app()
|
|||
query.addBindValue(obj_root.value("logo").toString());
|
||||
query.addBindValue(obj_root.value("initial_position").toString());
|
||||
query.addBindValue(obj_root.value("status").toBool());
|
||||
query.addBindValue(obj_root.value("img").toString());
|
||||
query.addBindValue(false);
|
||||
query.addBindValue(false);
|
||||
query.exec();
|
||||
bool categories[8]={false};
|
||||
bool categories[CATEGORIES_NUM]={false};
|
||||
categories[ALL - 1] = true;
|
||||
categories[INNER - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1225,66 +1203,103 @@ bool SQLiteHelper::get_buttons(QList<ButtonStruct> &buttons)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories) {
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories, QString logo, QString img,QString type,bool locked,QString op,QString func,QString url,bool is_navbar,bool is_elite,QString dev) {
|
||||
QSqlQuery begin(db);
|
||||
begin.exec("BEGIN;");
|
||||
QSqlQuery query(db);
|
||||
QString categories_str="";
|
||||
for(int i=0;i<8;i++)
|
||||
categories[ALL - 1] = true;
|
||||
if(is_elite)
|
||||
{
|
||||
categories[ELITE - 1] = true;
|
||||
}
|
||||
for(int i=0;i< CATEGORIES_NUM;i++)
|
||||
{
|
||||
if(categories[i])
|
||||
{
|
||||
categories_str = categories_str + QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
if(logo.isEmpty())
|
||||
{
|
||||
logo = QApplication::applicationDirPath()+DEFAULT_IMAGE;
|
||||
}
|
||||
if(img.isEmpty())
|
||||
{
|
||||
img = QApplication::applicationDirPath()+DEFAULT_PNG;
|
||||
}
|
||||
QSqlQuery query_sel(db);
|
||||
query_sel.prepare("select id from kmd_menu where orig_name = :orig_name;");
|
||||
query_sel.bindValue(":orig_name",orig_name);
|
||||
if(query_sel.exec())
|
||||
{
|
||||
if(query_sel.next())
|
||||
{
|
||||
QString sql="update kmd_menu"
|
||||
" set sort=:sort,locked=:locked,type=:type,category_id=:category_id,"
|
||||
"name=:name,orig_name=:orig_name,op=:op,"
|
||||
"func=:func,path=:path,url=:url,logo=:logo,img=:img,is_navbar=:is_navbar,is_elite=:is_elite,dev=:dev where orig_name=:orig_name;";
|
||||
query.prepare(sql);
|
||||
query.bindValue(":sort",sort);
|
||||
query.bindValue(":locked",locked);
|
||||
query.bindValue(":type",type);
|
||||
query.bindValue(":category_id",categories_str);
|
||||
query.bindValue(":name",name);
|
||||
query.bindValue(":orig_name",orig_name);
|
||||
query.bindValue(":op",op);
|
||||
query.bindValue(":func",func);
|
||||
query.bindValue(":path",path);
|
||||
query.bindValue(":url",url);
|
||||
query.bindValue(":logo",logo);
|
||||
query.bindValue(":img",img);
|
||||
query.bindValue(":is_navbar",is_navbar);
|
||||
query.bindValue(":is_elite", is_elite);
|
||||
query.bindValue(":dev", dev);
|
||||
if(!query.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
QString sql = "insert into kmd_menu "
|
||||
"(sort, app_id, locked, type, category_id, name, orig_name,"
|
||||
" create_time, op, func, path, url, "
|
||||
"initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
"initial_position,status,logo,img,is_navbar,is_elite,dev) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(sort.toInt());
|
||||
query.addBindValue("");
|
||||
query.addBindValue(false);
|
||||
query.addBindValue("app");
|
||||
query.addBindValue(locked);
|
||||
query.addBindValue(type);
|
||||
query.addBindValue(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(orig_name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
query.addBindValue("soft");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(op);
|
||||
query.addBindValue(func);
|
||||
query.addBindValue(path);
|
||||
query.addBindValue("");
|
||||
query.addBindValue(url);
|
||||
query.addBindValue("");
|
||||
query.addBindValue(true);
|
||||
query.addBindValue(logo);
|
||||
query.addBindValue(img);
|
||||
query.addBindValue(is_navbar);
|
||||
query.addBindValue(is_elite);
|
||||
query.addBindValue(dev);
|
||||
if(!query.exec())
|
||||
{
|
||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("写入数据库失败"));
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
qDebug()<< query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("COMMIT;");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1293,6 +1308,20 @@ bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
|||
{
|
||||
QSqlQuery work(db);
|
||||
work.exec("begin;");
|
||||
QSqlQuery query2(db);
|
||||
bool ok=query2.exec("update kmd_category set status=0;");
|
||||
Categrory categrory_all;
|
||||
categrory_all.id = ALL;
|
||||
categrory_all.name = QString::fromLocal8Bit("全部");
|
||||
categrory_all.sort = 0;
|
||||
categrory_all.display = true;
|
||||
categrories << categrory_all;
|
||||
Categrory categrory_elite;
|
||||
categrory_elite.id = ELITE;
|
||||
categrory_elite.name = QString::fromLocal8Bit("推荐");
|
||||
categrory_elite.sort = 1;
|
||||
categrory_elite.display = true;
|
||||
categrories << categrory_elite;
|
||||
for(Categrory categrory:categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
|
@ -1355,16 +1384,12 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit,bool
|
|||
}
|
||||
else
|
||||
{
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category where status=1 order by sort;"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
if (query.value("name") == QString::fromLocal8Bit("全部"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Categrory categrory;
|
||||
categrory.name = query.value("name").toString();
|
||||
categrory.id = query.value("id").toInt();
|
||||
|
@ -1382,13 +1407,17 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
|
|||
QString sql;
|
||||
if(category==ALL)
|
||||
{
|
||||
sql = "select * from kmd_menu where status=1 and not type='app_manage' and not op='self' order by sort;";
|
||||
sql = "select * from kmd_menu where type='app' and status=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
else if(category==ELITE)
|
||||
{
|
||||
sql = "select * from kmd_menu where type='app' and status=1 and is_elite=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = "select * from kmd_menu where category_id like '%";
|
||||
sql += QString::number(category, 10);
|
||||
sql += "%' and not type='app_manage' and status=1 order by sort;";
|
||||
sql += "%' and type='app' and status=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec(sql))
|
||||
|
@ -1400,6 +1429,9 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
|
|||
|
||||
Record record;
|
||||
record.id = query.value("id").toInt();
|
||||
record.logo=query.value("logo").toString();
|
||||
record.is_navbar=query.value("is_navbar").toBool();
|
||||
record.img = query.value("img").toString();
|
||||
record.sort = query.value("sort").toInt();
|
||||
record.app_id = query.value("app_id").toString();
|
||||
record.locked = query.value("locked").toBool();
|
||||
|
@ -1433,7 +1465,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
|||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
|
@ -1450,47 +1482,35 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
|||
}
|
||||
qDebug() << query.lastError();
|
||||
QSqlQuery categories_sql(db);
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
qDebug() << query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,type=:type where orig_name=:orig_name;";
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,is_navbar=:is_navbar where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":type", type);
|
||||
if(type=="navbar")
|
||||
{
|
||||
query.bindValue(":is_navbar", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
query.bindValue(":is_navbar", false);
|
||||
}
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
|
@ -1499,44 +1519,27 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
|||
}
|
||||
qDebug() << query.lastError();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
QSqlQuery total(db);
|
||||
QSqlQuery query3(db);
|
||||
QString total_sql = "select id from kmd_menu where category_id like '%";
|
||||
total_sql += QString::number(i + 1);
|
||||
total_sql += "%';";
|
||||
total.exec(total_sql);
|
||||
query3.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query3.bindValue(":total", total.size()+1);
|
||||
query3.bindValue(":id", i + 1);
|
||||
if (!query3.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLiteHelper::delete_software(QString orig_name)
|
||||
{
|
||||
QSqlQuery query(db);;
|
||||
query.prepare("delete from kmd_menu where orig_name=:orig_name;");
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if(!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
||||
QString sql = "select * from kmd_menu where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
|
@ -1567,3 +1570,53 @@ bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//警告:这个函数必须用于事务中
|
||||
inline bool SQLiteHelper::update_total()
|
||||
{
|
||||
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if(i==ELITE-1)
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE is_elite=1 AND type='app';");
|
||||
}
|
||||
else if(i==ALL-1)
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE type='app';");
|
||||
}
|
||||
else
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId AND type='app';");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
}
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::use_software(QString orig_name)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
query.prepare("update kmd_menu set use_time=:use_time where orig_name=:orig_name;");
|
||||
query.bindValue(":use_time", QDateTime::currentDateTime().toTime_t());
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
#pragma once
|
||||
#include <QtSql/QSqlDatabase>
|
||||
#include <QtSql/QSqlError>
|
||||
#include <QtSql/QSqlQuery>
|
||||
|
@ -14,11 +14,15 @@ class SoftwareRequest;
|
|||
typedef struct tagRecord{
|
||||
int id;
|
||||
int sort;
|
||||
QString initial_position;
|
||||
QString app_id;
|
||||
bool locked;
|
||||
bool is_navbar;
|
||||
bool is_elite;
|
||||
QString type;
|
||||
QString category_id;
|
||||
QString logo;
|
||||
QString img;
|
||||
QString name;
|
||||
QString orig_name;
|
||||
QString version;
|
||||
|
@ -47,15 +51,19 @@ class SQLiteHelper : public QObject
|
|||
public:
|
||||
SQLiteHelper(QObject *parent = nullptr);
|
||||
bool update_software();
|
||||
bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories);
|
||||
bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString logo="", QString img="",QString type="app",bool locked=false,QString op="soft",QString func="",QString url="",bool is_navbar=false,bool is_elite=false,QString dev="");
|
||||
bool edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories,QString type="");
|
||||
bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response);
|
||||
bool get_software(QList<ButtonStruct>* button_structs,QString background_color , QString title_color, QString title_cover_color);
|
||||
bool update_app();
|
||||
bool get_buttons(QList<ButtonStruct> &buttons);
|
||||
bool get_category(QList<Categrory>& categrories, bool is_edit,bool all=false);
|
||||
bool set_category(QList<Categrory>& categrories);
|
||||
bool get_all_software(QList<Record> &softwares,int category);
|
||||
bool get_a_software(QString orig_name, Record2 *record);
|
||||
bool update_total();//警告:这个函数必须用于事务中
|
||||
bool use_software(QString orig_name);
|
||||
|
||||
QSqlDatabase db;
|
||||
|
||||
~SQLiteHelper();
|
||||
|
@ -64,6 +72,8 @@ private:
|
|||
QNetworkReply* reply;
|
||||
QEventLoop eventLoop;
|
||||
bool downloadSuccess;
|
||||
bool delete_software(QString orig_name);
|
||||
bool execute_query(QString sql, QList<Record>& softwares);
|
||||
|
||||
void cancelDownload();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#include "userimprove.h"
|
||||
#include "globalvariables.h"
|
||||
UserImprove::UserImprove(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.submit, &QPushButton::clicked, this, &UserImprove::submit);
|
||||
connect(ui.detail, &QPushButton::clicked, this, &UserImprove::showDetail);
|
||||
setFixedSize(600, 400);
|
||||
}
|
||||
|
||||
UserImprove::~UserImprove()
|
||||
{
|
||||
}
|
||||
|
||||
void UserImprove::submit()
|
||||
{
|
||||
if (ui.checkBox->checkState() == Qt::Checked)
|
||||
{
|
||||
agree = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
agree = false;
|
||||
}
|
||||
}
|
||||
void UserImprove::showDetail()
|
||||
{
|
||||
QString path = QApplication::applicationDirPath();
|
||||
QString license = path + "/detail.txt";
|
||||
license.replace("/", "\\");
|
||||
ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe", license.toStdWString().c_str(), nullptr, SW_SHOW);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_userimprove.h"
|
||||
|
||||
class UserImprove : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UserImprove(QWidget *parent = nullptr);
|
||||
~UserImprove();
|
||||
private slots:
|
||||
void submit();
|
||||
void showDetail();
|
||||
private:
|
||||
Ui::UserImproveClass ui;
|
||||
};
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>UserImproveClass</class>
|
||||
<widget class="QDialog" name="UserImproveClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>UserImprove</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="detail">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>80</x>
|
||||
<y>310</y>
|
||||
<width>150</width>
|
||||
<height>46</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>查看详情</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="submit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>310</y>
|
||||
<width>150</width>
|
||||
<height>46</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>确定</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>170</y>
|
||||
<width>371</width>
|
||||
<height>28</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>我同意加入用户体验改善计划</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue