提交测试,基本完成
parent
b8da134809
commit
098e06a39b
|
@ -1,8 +1,9 @@
|
|||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
#define TEXT_SIZE 7
|
||||
#include "MyButton.h"
|
||||
#include "config.h"
|
||||
|
||||
MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) {
|
||||
this->buttons=buttons;
|
||||
this->width2=width;
|
||||
|
@ -30,7 +31,11 @@ MyButton::~MyButton() {
|
|||
|
||||
void MyButton::paintEvent(QPaintEvent *e) {
|
||||
QPushButton::paintEvent(e);
|
||||
QPainter painter(this);
|
||||
QRectF rect(0, 0, this->width(), this->height());
|
||||
QColor qColor;
|
||||
qColor.setNamedColor(background_color);
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect, qColor);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
int logo_width=width()/3;
|
||||
int logo_x=width()/3;
|
||||
|
|
|
@ -102,15 +102,20 @@
|
|||
<QtRcc Include="OfficeAssistant_msvc.qrc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtMoc Include="applicationmanager.h" />
|
||||
<QtMoc Include="addapp.h" />
|
||||
<QtMoc Include="addcategory.h" />
|
||||
<QtMoc Include="applicationmanagerpage.h" />
|
||||
<ClInclude Include="buttonstruct.h" />
|
||||
<ClInclude Include="config.h" />
|
||||
<QtMoc Include="exitmanager.h" />
|
||||
<ClInclude Include="globalvariables.h" />
|
||||
<QtMoc Include="qminiblink.h" />
|
||||
<QtMoc Include="mysettingsdialog.h" />
|
||||
<QtMoc Include="minibutton.h" />
|
||||
<ClInclude Include="mb.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<QtMoc Include="sqlitehelper.h" />
|
||||
<ClInclude Include="wke.h" />
|
||||
<QtMoc Include="mainwindowlayout.h" />
|
||||
<QtMoc Include="mainwindow.h" />
|
||||
<QtMoc Include="mainscreen.h" />
|
||||
|
@ -119,10 +124,15 @@
|
|||
<QtMoc Include="navbar.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="addapp.cpp" />
|
||||
<ClCompile Include="addcategory.cpp" />
|
||||
<ClCompile Include="applicationmanager.cpp" />
|
||||
<ClCompile Include="applicationmanagerpage.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="mainscreen.cpp" />
|
||||
<ClCompile Include="mainwindow.cpp" />
|
||||
<ClCompile Include="mainwindowlayout.cpp" />
|
||||
<ClCompile Include="minibutton.cpp" />
|
||||
<ClCompile Include="MyButton.cpp" />
|
||||
<ClCompile Include="mysettingsdialog.cpp" />
|
||||
<ClCompile Include="navbar.cpp" />
|
||||
|
@ -131,9 +141,14 @@
|
|||
<ClCompile Include="sqlitehelper.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="addapp.ui" />
|
||||
<QtUic Include="addcategory.ui" />
|
||||
<QtUic Include="applicationmanager.ui" />
|
||||
<QtUic Include="applicationmanagerpage.ui" />
|
||||
<QtUic Include="mainscreen.ui" />
|
||||
<QtUic Include="mainwindow.ui" />
|
||||
<QtUic Include="mainwindowlayout.ui" />
|
||||
<QtUic Include="minibutton.ui" />
|
||||
<QtUic Include="mysettingsdialog.ui" />
|
||||
<QtUic Include="navbar.ui" />
|
||||
<QtUic Include="qminiblink.ui" />
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
<ClInclude Include="globalvariables.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="wke.h">
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<ClInclude Include="mb.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
@ -70,6 +70,21 @@
|
|||
<QtMoc Include="exitmanager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="applicationmanager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="minibutton.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="addapp.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="addcategory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="applicationmanagerpage.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="mainscreen.cpp">
|
||||
|
@ -102,6 +117,21 @@
|
|||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="applicationmanager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="minibutton.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="addapp.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="addcategory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="applicationmanagerpage.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<QtUic Include="navbar.ui">
|
||||
|
@ -116,10 +146,25 @@
|
|||
<QtUic Include="mainwindowlayout.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="mysettingsdialog.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="applicationmanager.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="minibutton.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="qminiblink.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="mysettingsdialog.ui">
|
||||
<QtUic Include="addapp.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="addcategory.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
<QtUic Include="applicationmanagerpage.ui">
|
||||
<Filter>Form Files</Filter>
|
||||
</QtUic>
|
||||
</ItemGroup>
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<QtLastBackgroundBuild>2023-08-08T01:58:42.4896992Z</QtLastBackgroundBuild>
|
||||
<QtLastBackgroundBuild>2023-08-12T03:22:21.9071424Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<QtLastBackgroundBuild>2023-08-08T01:58:34.1935757Z</QtLastBackgroundBuild>
|
||||
<QtLastBackgroundBuild>2023-08-12T03:22:23.0360904Z</QtLastBackgroundBuild>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -0,0 +1,164 @@
|
|||
#include "addapp.h"
|
||||
#include <QFileDialog>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QMessageBox>
|
||||
#include <sqlitehelper.h>
|
||||
|
||||
#include "applicationmanager.h"
|
||||
|
||||
#if _MSC_VER >=1936
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#else
|
||||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#endif
|
||||
|
||||
AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
SQLiteHelper sqlite_helper;
|
||||
setFixedSize(450, 450);
|
||||
setWindowFlags(Qt::WindowCloseButtonHint);
|
||||
form = new QFormLayout;
|
||||
name = new QLineEdit;
|
||||
form->addRow(QString::fromLocal8Bit("名称"), name);
|
||||
if(isEdit)
|
||||
{
|
||||
name_label = new QLabel(orig_name_str);
|
||||
form->addRow(QString::fromLocal8Bit("全名"), name_label);
|
||||
}
|
||||
else
|
||||
{
|
||||
orig_name = new QLineEdit;
|
||||
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
|
||||
}
|
||||
if(row==nullptr)
|
||||
{
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
|
||||
form->addRow(QString::fromLocal8Bit("路径"), path);
|
||||
sort = new QLineEdit;
|
||||
sort->setValidator(new QIntValidator(10, 100));
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
QList<Categrory> categrories;
|
||||
layout_inner = new QVBoxLayout;
|
||||
sqlite_helper.get_category(categrories);
|
||||
|
||||
for (auto category : categrories)
|
||||
{
|
||||
if ((category.id == 1) || (category.id == 8) || (category.id == 4) || (category.id == 5 || category.id == 3))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QCheckBox* check_box = new QCheckBox(category.name);
|
||||
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->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;
|
||||
}else
|
||||
{
|
||||
path = new QPushButton(QString::fromLocal8Bit("浏览"));
|
||||
path_str = row->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);
|
||||
sort = new QLineEdit;
|
||||
sort->setText(QString::number(row->sort));
|
||||
sort->setValidator(new QIntValidator(10, 100));
|
||||
form->addRow(QString::fromLocal8Bit("排序"), sort);
|
||||
QList<Categrory> categrories;
|
||||
layout_inner = new QVBoxLayout;
|
||||
sqlite_helper.get_category(categrories);
|
||||
|
||||
for (auto category : categrories)
|
||||
{
|
||||
if ((category.id == 1) || (category.id == 8) || (category.id == 4) || (category.id == 5 || category.id == 3))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QCheckBox* check_box = new QCheckBox(category.name);
|
||||
if(row->categories[category.id])
|
||||
{
|
||||
check_box->setCheckState(Qt::Checked);
|
||||
}
|
||||
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->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()
|
||||
{
|
||||
//delete categories;
|
||||
delete name;
|
||||
if(isEdit)
|
||||
{
|
||||
delete name_label;
|
||||
}else
|
||||
{
|
||||
delete orig_name;
|
||||
}
|
||||
delete path;
|
||||
delete sort;
|
||||
delete submit_btn;
|
||||
delete form;
|
||||
}
|
||||
|
||||
void AddApp::broswer_exe(){
|
||||
path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"),
|
||||
QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)"));
|
||||
fs::path file(path_str.toStdWString());
|
||||
path->setText(QString::fromStdWString(file.filename().c_str()));
|
||||
}
|
||||
|
||||
void AddApp::submit() {
|
||||
if((!orig_name->text().isEmpty())&&(!path->text().isEmpty()))
|
||||
{
|
||||
orig_name_str = orig_name->text();
|
||||
name_str = orig_name_str;
|
||||
sort_str = sort->text();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写名称或路径"));
|
||||
return;
|
||||
}
|
||||
categories = new bool[8];
|
||||
categories[0] = true;
|
||||
categories[2] = true;
|
||||
categories[7] = true;
|
||||
categories[3] = false;
|
||||
categories[4] = false;
|
||||
for(auto key:categories_list.keys())
|
||||
{
|
||||
if(key==0||key==2||key==7||key==3||key==4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
categories[key - 1] = categories_list[key]->checkState();
|
||||
}
|
||||
}
|
||||
categories[0] = true;
|
||||
categories[7] = true;
|
||||
changed = true;
|
||||
close();
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QString>
|
||||
#include <QPushButton>
|
||||
#include <QFormLayout>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
||||
struct Record2;
|
||||
#include "ui_addapp.h"
|
||||
|
||||
class AddApp : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AddApp(bool isEdit = false, Record2 *orig_name_str=nullptr,QWidget* parent = nullptr);
|
||||
~AddApp();
|
||||
QString get_exe_path()
|
||||
{
|
||||
return path_str;
|
||||
}
|
||||
QString get_orig_name()
|
||||
{
|
||||
return orig_name_str;
|
||||
}
|
||||
QString get_name()
|
||||
{
|
||||
return name_str;
|
||||
}
|
||||
QString get_sort()
|
||||
{
|
||||
return sort_str;
|
||||
}
|
||||
bool *get_categories()
|
||||
{
|
||||
return categories;
|
||||
}
|
||||
bool changed = false;
|
||||
private:
|
||||
Ui::AddAppClass ui;
|
||||
QFormLayout *form;
|
||||
bool *categories;
|
||||
QPushButton *path;
|
||||
QPushButton* submit_btn;
|
||||
QLineEdit *name;
|
||||
QLabel *name_label;
|
||||
QLineEdit *orig_name;
|
||||
QLineEdit *sort;
|
||||
QMap<int,QCheckBox*> categories_list;
|
||||
QString sort_str;
|
||||
QString name_str;
|
||||
QString orig_name_str;
|
||||
QString path_str;
|
||||
QVBoxLayout* layout_inner;
|
||||
bool isEdit;
|
||||
private slots:
|
||||
void broswer_exe();
|
||||
void submit();
|
||||
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AddAppClass</class>
|
||||
<widget class="QDialog" name="AddAppClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>450</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>添加应用</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>icon/wechat.ico</normaloff>icon/wechat.ico</iconset>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">backgroound-color:#ffffff</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,73 @@
|
|||
#include "addcategory.h"
|
||||
#include <QString>
|
||||
AddCategory::AddCategory(QWidget* parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
setWindowFlags(Qt::WindowCloseButtonHint);
|
||||
setFixedSize(900, 600);
|
||||
//connect(ui.submit, &QPushButton::click, this, &AddCategory::submit);
|
||||
QStringList title;
|
||||
ui.tableWidget->setColumnCount(3);
|
||||
title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序");
|
||||
ui.tableWidget->setHorizontalHeaderLabels(title);
|
||||
sqlite_helper.get_category(categrories);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
if(category.display==true)
|
||||
{
|
||||
combo_box->setCurrentIndex(0);
|
||||
}else
|
||||
{
|
||||
combo_box->setCurrentIndex(1);
|
||||
}
|
||||
ui.tableWidget->setCellWidget(i, 1, combo_box);
|
||||
ui.tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(category.sort)));
|
||||
combo_boxes << combo_box;
|
||||
i++;
|
||||
}
|
||||
//submit_btn = new QPushButton(QString::fromLocal8Bit("提交"));
|
||||
connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit);
|
||||
}
|
||||
AddCategory::~AddCategory()
|
||||
{
|
||||
for(auto combo_box : combo_boxes)
|
||||
{
|
||||
delete combo_box;
|
||||
}
|
||||
}
|
||||
void AddCategory::submit()
|
||||
{
|
||||
int num = categrories.count();
|
||||
QList<Categrory> categrories_new;
|
||||
int i=0;
|
||||
for(Categrory categrory:categrories)
|
||||
{
|
||||
categrory.name = ui.tableWidget->item(i, 0)->text();
|
||||
QComboBox * combox =(QComboBox *)ui.tableWidget->cellWidget(i, 1);
|
||||
categrory.display = combox->currentData().toBool();
|
||||
bool ok;
|
||||
categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10);
|
||||
if(!ok)
|
||||
{
|
||||
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("排序列中有一行不是数字"));
|
||||
return;
|
||||
}
|
||||
categrories_new << categrory;
|
||||
i++;
|
||||
}
|
||||
categrories.clear();
|
||||
categrories = categrories_new;
|
||||
changed = true;
|
||||
close();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
#include "sqlitehelper.h"
|
||||
#include "ui_addcategory.h"
|
||||
|
||||
class AddCategory : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AddCategory(QWidget *parent = nullptr);
|
||||
~AddCategory();
|
||||
QList<Categrory> categrories;
|
||||
bool changed = false;
|
||||
private:
|
||||
Ui::AddCategoryClass ui;
|
||||
SQLiteHelper sqlite_helper;
|
||||
QPushButton* submit_btn;
|
||||
QList<QComboBox *> combo_boxes;
|
||||
private slots:
|
||||
void submit();
|
||||
};
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AddCategoryClass</class>
|
||||
<widget class="QDialog" name="AddCategoryClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>900</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>类别名称</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>icon/wechat.ico</normaloff>icon/wechat.ico</iconset>
|
||||
</property>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>90</x>
|
||||
<y>70</y>
|
||||
<width>711</width>
|
||||
<height>411</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="submit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>380</x>
|
||||
<y>520</y>
|
||||
<width>150</width>
|
||||
<height>46</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>确定</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,274 @@
|
|||
#include "applicationmanager.h"
|
||||
#include "applicationmanagerpage.h"
|
||||
#include "config.h"
|
||||
#include "addapp.h"
|
||||
#include "addcategory.h"
|
||||
#include "sqlitehelper.h"
|
||||
#include <ctime>
|
||||
|
||||
#include "globalvariables.h"
|
||||
|
||||
ApplicationManager::ApplicationManager(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
resize(parent->width(), parent->height());
|
||||
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_bottom = new QHBoxLayout(this);
|
||||
QList<Categrory> categrories;
|
||||
sqlite_helper.get_category(categrories);
|
||||
sqlite_helper.get_buttons(button_structs);
|
||||
for (auto button_struct : button_structs)
|
||||
{
|
||||
MiniButton* button = new MiniButton(button_struct, this);
|
||||
button->setText(button_struct.text);
|
||||
//button->show();
|
||||
button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
||||
button->setMaximumWidth(TEXT_SIZE * button->text().length() * scale * 3 + 40);
|
||||
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);
|
||||
connect(button, &MiniButton::click1, this, &ApplicationManager::onclick1);
|
||||
}
|
||||
//ui.tabWidget->setStyleSheet("border:none;");
|
||||
//ui.tabWidget->setMinimumHeight(40);
|
||||
//ui.tabWidget->setMovable(false);
|
||||
//ui.tabWidget->setDocumentMode(false);
|
||||
//ui.tabWidget->setCurrentIndex(0);
|
||||
tab_bar = new QTabBar(this);
|
||||
tab_bar->addTab(QString::fromLocal8Bit("全部"));
|
||||
layout_bottom_top = new QVBoxLayout;
|
||||
|
||||
for(int i=2;i<=8;i++)
|
||||
{
|
||||
tab_bar->addTab(categrories[i - 2].name);
|
||||
}
|
||||
layout_bottom_top->addWidget(tab_bar, 1);
|
||||
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++)
|
||||
{
|
||||
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);
|
||||
application_manager_page->setHidden(true);
|
||||
map.insert(i, application_manager_page);
|
||||
}
|
||||
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:";
|
||||
style += DEFAULT_COVER_COLOR;
|
||||
style += ";}QTabBar::tab:selected { border:2px;height:80;width:150;color:";
|
||||
style += DEFAULT_COVER_COLOR;
|
||||
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);
|
||||
}
|
||||
|
||||
ApplicationManager::~ApplicationManager()
|
||||
{
|
||||
for(auto button:buttons)
|
||||
{
|
||||
delete button;
|
||||
}
|
||||
for(auto layout:pages.keys())
|
||||
{
|
||||
delete pages[layout];
|
||||
delete layout;
|
||||
}
|
||||
delete miniblink;
|
||||
delete layout_top;
|
||||
delete layout_bottom;
|
||||
delete layout;
|
||||
}
|
||||
|
||||
void ApplicationManager::onclick1(QString op, QString func, QString path, QString url)
|
||||
{
|
||||
if(op=="self")
|
||||
{
|
||||
if(func=="app_add")
|
||||
{
|
||||
AddApp add_app;
|
||||
add_app.exec();
|
||||
if(add_app.changed)
|
||||
{
|
||||
bool ok = sqlite_helper.insert_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("插入失败"));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新成功"));
|
||||
}
|
||||
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++)
|
||||
{
|
||||
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("添加失败"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(op=="soft")
|
||||
{
|
||||
emit changeUrl(url);
|
||||
ShellExecute(GetDesktopWindow(), L"open", path.toStdWString().c_str(), L"", L"", SW_SHOW);
|
||||
}else if(op=="app")
|
||||
{
|
||||
emit changeUrl(url);
|
||||
QString str = QApplication::applicationDirPath() + path;
|
||||
ShellExecute(GetDesktopWindow(), L"open",str.toStdWString().c_str(), L"", L"", SW_SHOW);
|
||||
}else if(op=="url")
|
||||
{
|
||||
emit changeUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationManager::onclick2(QString orig_name, QString op)
|
||||
{
|
||||
if (op == "open")
|
||||
{
|
||||
emit changeUrl(application_manager_page_all->rows[orig_name].url);
|
||||
WinExec(application_manager_page_all->rows[orig_name].exe_file.toStdString().c_str(), SW_SHOW);
|
||||
}
|
||||
else if (op == "settings")
|
||||
{
|
||||
AddApp add_app(true, &application_manager_page_all->rows[orig_name]);
|
||||
add_app.exec();
|
||||
if (add_app.changed)
|
||||
{
|
||||
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("编辑失败"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationManager::tabChange(int index)
|
||||
{
|
||||
tab_bar->setHidden(false);
|
||||
for(auto i:map.keys())
|
||||
{
|
||||
map[i]->setHidden(true);
|
||||
}
|
||||
map[index + 1]->setHidden(false);
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "sqlitehelper.h"
|
||||
#include "buttonstruct.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QHBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QSvgWidget>
|
||||
#include <QPushButton>
|
||||
#include "minibutton.h"
|
||||
#include <QLabel>
|
||||
#include "qminiblink.h"
|
||||
#include "ui_applicationmanager.h"
|
||||
#include <QTabBar>
|
||||
#include <QCheckBox>
|
||||
class ApplicationManagerPage;
|
||||
|
||||
struct Record2
|
||||
{
|
||||
/*QLabel *name;
|
||||
QLabel *orig_name;
|
||||
QLabel *dev;
|
||||
QLabel *use_time;*/
|
||||
QSvgWidget* icon;
|
||||
MiniButton* settings;
|
||||
MiniButton * open;
|
||||
QString orig_name;
|
||||
QString exe_file;
|
||||
QCheckBox *check_box;
|
||||
int sort;
|
||||
QString url;
|
||||
bool categories[8];
|
||||
};
|
||||
|
||||
struct Title
|
||||
{
|
||||
QLabel* name;
|
||||
QLabel* orig_name;
|
||||
QLabel* dev;
|
||||
QLabel* use_time;
|
||||
QLabel* op;
|
||||
};
|
||||
class ApplicationManager : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void changeUrl(QString url);
|
||||
void refresh();
|
||||
public:
|
||||
ApplicationManager(QWidget *parent = nullptr);
|
||||
~ApplicationManager();
|
||||
private:
|
||||
QHash<QHBoxLayout*,ApplicationManagerPage*> pages;
|
||||
QVBoxLayout* layout;
|
||||
QTabBar *tab_bar;
|
||||
QMap<int, ApplicationManagerPage*> map;
|
||||
QHBoxLayout* layout_top;
|
||||
QHBoxLayout* layout_bottom;
|
||||
QMiniBlink* miniblink;
|
||||
QList<MiniButton*> buttons;
|
||||
QList<Record> softwares;
|
||||
QList<ButtonStruct> button_structs;
|
||||
ApplicationManagerPage* application_manager_page_all;
|
||||
Ui::ApplicationManagerClass ui;
|
||||
SQLiteHelper sqlite_helper;
|
||||
QVBoxLayout *layout_bottom_top;
|
||||
QTableWidget *table;
|
||||
Title title;
|
||||
public slots:
|
||||
void onclick1(QString op, QString func, QString path, QString url);
|
||||
void onclick2(QString orig_name, QString op);
|
||||
void tabChange(int index);
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ApplicationManagerClass</class>
|
||||
<widget class="QWidget" name="ApplicationManagerClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ApplicationManager</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,238 @@
|
|||
#include "applicationmanagerpage.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include "applicationmanager.h"
|
||||
#include "config.h"
|
||||
|
||||
ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
this->category = category;
|
||||
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);
|
||||
QStringList titles;
|
||||
titles<< 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++)
|
||||
{
|
||||
table->horizontalHeader()->setSectionResizeMode(i, QHeaderView::Stretch);
|
||||
|
||||
}
|
||||
i = 0;
|
||||
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);
|
||||
table->setItem(i, 4, new QTableWidgetItem(date));
|
||||
Record2 record2;
|
||||
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, "open");
|
||||
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;
|
||||
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)))
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
ApplicationManagerPage::~ApplicationManagerPage()
|
||||
{
|
||||
for (auto button : buttons)
|
||||
{
|
||||
delete button;
|
||||
}
|
||||
delete table;
|
||||
delete layout;
|
||||
}
|
||||
|
||||
void ApplicationManagerPage::onclicked()
|
||||
{
|
||||
for(int i=0;i<table->rowCount();i++)
|
||||
{
|
||||
if(((QCheckBox *)table->cellWidget(i,4))->checkState()==Qt::Checked)
|
||||
{
|
||||
if(!checked[table->item(i,1)->text()])
|
||||
{
|
||||
QString orig_name = table->item(i, 1)->text();
|
||||
bool ok=sqlite_helper.edit_software(table->item(i, 0)->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("更新部分或全部失败"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
if (checked[table->item(i, 1)->text()])
|
||||
{
|
||||
QString orig_name = table->item(i, 1)->text();
|
||||
bool ok = sqlite_helper.edit_software(table->item(i, 0)->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("更新部分或全部失败"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emit application_manager->refresh();
|
||||
}
|
||||
|
||||
void ApplicationManagerPage::refresh()
|
||||
{
|
||||
int rowcount = table->rowCount();
|
||||
for(int i=0;i<rowcount;i++)
|
||||
{
|
||||
table->removeRow(0);
|
||||
}
|
||||
for(auto row:rows)
|
||||
{
|
||||
disconnect(row.settings, &MiniButton::click0, row.settings, &MiniButton::onclick2);
|
||||
disconnect(row.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
disconnect(row.open, &MiniButton::click0, row.open, &MiniButton::onclick2);
|
||||
disconnect(row.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
|
||||
disconnect(row.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked);
|
||||
}
|
||||
softwares.clear();
|
||||
sqlite_helper.get_all_software(softwares, category);
|
||||
int i = 0;
|
||||
for (auto software : softwares)
|
||||
{
|
||||
table->insertRow(i);
|
||||
table->setItem(i, 0, new QTableWidgetItem(software.name));
|
||||
table->setItem(i, 1, new QTableWidgetItem(software.orig_name));
|
||||
table->setItem(i, 2, 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);
|
||||
table->setItem(i, 3, new QTableWidgetItem(date));
|
||||
Record2 record2;
|
||||
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, "open");
|
||||
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;
|
||||
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)))
|
||||
{
|
||||
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);
|
||||
table->setCellWidget(i, 4, record2.check_box);
|
||||
table->setCellWidget(i, 5, record2.settings);
|
||||
//table->item(i, 5)->setTextAlignment(Qt::AlignCenter);
|
||||
table->setCellWidget(i, 6, record2.open);
|
||||
//table->item(i, 6)->setTextAlignment(Qt::AlignCenter);
|
||||
rows.insert(software.orig_name, record2);
|
||||
i++;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "minibutton.h"
|
||||
#include "qminiblink.h"
|
||||
#include "sqlitehelper.h"
|
||||
#include "ui_applicationmanagerpage.h"
|
||||
|
||||
class ApplicationManager;
|
||||
struct Title;
|
||||
struct Record2;
|
||||
|
||||
class ApplicationManagerPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr);
|
||||
~ApplicationManagerPage();
|
||||
QMap<QString, Record2> rows;
|
||||
|
||||
private:
|
||||
Ui::ApplicationManagerPageClass ui;
|
||||
QVBoxLayout* layout;
|
||||
QHBoxLayout* layout_top;
|
||||
QHBoxLayout* layout_bottom;
|
||||
QMiniBlink* miniblink;
|
||||
QList<MiniButton*> buttons;
|
||||
QList<Record> softwares;
|
||||
QList<ButtonStruct> button_structs;
|
||||
QHash<QString, bool> checked;
|
||||
SQLiteHelper sqlite_helper;
|
||||
QGridLayout* layout_left;
|
||||
QTableWidget* table;
|
||||
ApplicationManager* application_manager;
|
||||
Title *title;
|
||||
int category;
|
||||
public slots:
|
||||
void refresh();
|
||||
void onclicked();
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
<UI version="4.0" >
|
||||
<class>ApplicationManagerPageClass</class>
|
||||
<widget class="QWidget" name="ApplicationManagerPageClass" >
|
||||
<property name="objectName" >
|
||||
<string notr="true">ApplicationManagerPageClass</string>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>ApplicationManagerPage</string>
|
||||
</property>$centralwidget$
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<connections/>
|
||||
</UI>
|
|
@ -6,7 +6,8 @@
|
|||
#define OFFICEASSISTANT_CONFIG_H
|
||||
#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 DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址
|
||||
#define WECHAT_URL " http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open"
|
||||
#define BASE_URL "http://softapi.s103.y01.cn/" //域名
|
||||
#define DEFAULT_FILE "/config/default_navbar.kmd" //默认导航栏文件位置
|
||||
#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key
|
||||
|
@ -18,7 +19,23 @@
|
|||
#define ADD_SHORTCUT 2
|
||||
#define VERSION "1.0.0" //软件版本
|
||||
#define RELEASE "20230801" //Release
|
||||
#define SOFTWARE_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/soft"
|
||||
#define SOFTWARE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/App/update/type/add"
|
||||
#define DEFAULT_BACKGROUND_COLOR "#333332"
|
||||
#define DEFAULT_COLOR "#3399FF"
|
||||
#define DEFAULT_TEXT_COLOR "#FFFFFF"
|
||||
#define DEFAULT_COVER_COLOR "#0033FF"
|
||||
#define DEFAULT_IMAGE "/images/icon/default.svg"
|
||||
#define DEFAULT_LOGO "/images/logo.png"
|
||||
#define TITLE " "
|
||||
#define TEXT_SIZE 7
|
||||
#define TEXT_SIZE_BIG 10
|
||||
//分类
|
||||
#define ALL 1
|
||||
#define ELITE 2
|
||||
#define SOFT 3
|
||||
#define SYSTEM 4
|
||||
#define INNER 5
|
||||
#define CUSTOM_1 6
|
||||
#define CUSTOM_2 7
|
||||
#define OTHERS 8
|
||||
#endif //OFFICEASSISTANT_CONFIG_H
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include "sqlitehelper.h"
|
||||
template <typename T>
|
||||
class AutoDeleteList
|
||||
{
|
||||
|
@ -37,7 +38,9 @@ public:
|
|||
// 退出应用程序
|
||||
void exit(int exitCode = 0)
|
||||
{
|
||||
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.db.close();
|
||||
QSqlDatabase::removeDatabase("mydb");
|
||||
// 发射退出应用程序信号
|
||||
emit exitApplication(exitCode);
|
||||
}
|
||||
|
|
|
@ -10,4 +10,6 @@ extern ExitManager exit_manager;
|
|||
extern double scale;
|
||||
extern MainWindowLayout *mainWindowLayout;
|
||||
extern QString url_param;
|
||||
extern bool autostart;
|
||||
extern bool agree;
|
||||
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H
|
||||
|
|
|
@ -2,9 +2,16 @@
|
|||
#include <QApplication>
|
||||
#include <Windows.h>
|
||||
double scale;
|
||||
bool autostart = false;
|
||||
bool agree = false;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QStringList args = a.arguments();
|
||||
if(args.contains("autostart"))
|
||||
{
|
||||
autostart = true;
|
||||
}
|
||||
HDC hdc = GetDC(NULL);
|
||||
scale = GetDeviceCaps(hdc, LOGPIXELSX)/96;
|
||||
ReleaseDC(NULL,hdc);
|
||||
|
|
|
@ -37,6 +37,9 @@ MainScreen::MainScreen(QWidget *parent) :
|
|||
//button->setStyleSheet("text-color:white");
|
||||
layout = new QHBoxLayout;
|
||||
miniblink = new QMiniBlink(this);
|
||||
application_manager = new ApplicationManager(this);
|
||||
application_manager->setHidden(true);
|
||||
layout->addWidget(application_manager);
|
||||
layout->addWidget(widget, 1);
|
||||
layout->addWidget(miniblink, 4);
|
||||
this->setLayout(layout);
|
||||
|
@ -64,8 +67,10 @@ MainScreen::~MainScreen() {
|
|||
delete layout_left;
|
||||
delete button;
|
||||
emit ondestroy();
|
||||
layout->removeWidget(application_manager);
|
||||
layout->removeWidget(miniblink);
|
||||
layout->removeWidget(widget);
|
||||
delete application_manager;
|
||||
delete miniblink;
|
||||
delete widget;
|
||||
delete layout;
|
||||
|
@ -79,13 +84,28 @@ void MainScreen::firstUrl(QString url)
|
|||
void MainScreen::clickButton1(QString op,QString url) {
|
||||
QString url_full = BASE_URL + url + url_param;
|
||||
if (op == "openwechat") {
|
||||
OpenWeChatRequest open_wechat_request;
|
||||
QString msg = open_wechat_request.sendRequest();
|
||||
if(msg!="ok")
|
||||
{
|
||||
QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), msg);
|
||||
return;
|
||||
}
|
||||
widget->setHidden(false);
|
||||
miniblink->setHidden(false);
|
||||
application_manager->setHidden(true);
|
||||
emit changeUrl(url_full);
|
||||
}
|
||||
else if(op=="app_mgr")
|
||||
{
|
||||
miniblink->setHidden(true);
|
||||
widget->setHidden(true);
|
||||
application_manager->setHidden(false);
|
||||
}
|
||||
else {
|
||||
widget->setHidden(true);
|
||||
miniblink->setHidden(false);
|
||||
application_manager->setHidden(true);
|
||||
emit changeUrl(url_full);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include "wke.h"
|
||||
#include "qminiblink.h"
|
||||
#include "applicationmanager.h"
|
||||
class MyThread;
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainScreen; }
|
||||
|
@ -37,6 +37,7 @@ private:
|
|||
QVBoxLayout *layout_left;
|
||||
QPushButton *button;
|
||||
QIcon *icon;
|
||||
ApplicationManager* application_manager;
|
||||
QWidget *broswer;
|
||||
static bool isInited();
|
||||
QWidget *widget;
|
||||
|
|
|
@ -6,27 +6,117 @@
|
|||
|
||||
#include "mainwindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "netio.h"
|
||||
#include "config.h"
|
||||
ExitManager exit_manager;
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
agree = false;
|
||||
QDesktopWidget* desktopWidget = QApplication::desktop();
|
||||
QRect deskRect = desktopWidget->availableGeometry();
|
||||
resize(deskRect.width()*0.8, deskRect.height()*0.8);
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
mainWindowLayout=new MainWindowLayout(this);
|
||||
setCentralWidget(mainWindowLayout);
|
||||
setWindowTitle(QString::fromLocal8Bit(NAME));
|
||||
setWindowTitle(QString::fromLocal8Bit(TITLE));
|
||||
QString path = QApplication::applicationDirPath();
|
||||
path += LOGO_TITLEBAR;
|
||||
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() {
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.db.close();
|
||||
QSqlDatabase::removeDatabase("mydb");
|
||||
delete icon;
|
||||
this->setCentralWidget(nullptr);
|
||||
delete mainWindowLayout;
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
#include <QMainWindow>
|
||||
#include <QVBoxLayout>
|
||||
#include "mainwindowlayout.h"
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,6 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
|
|||
QWidget(parent), ui(new Ui::MainWindowLayout) {
|
||||
ui->setupUi(this);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.update_app();
|
||||
sqlite_helper.update_software();
|
||||
layout=new QVBoxLayout(this);
|
||||
mainWindowLayout = this;
|
||||
QList<ButtonStruct> list;
|
||||
|
@ -78,6 +75,10 @@ void MainWindowLayout::clickButton(QString op, QString func, QString url,QString
|
|||
settings->exec();
|
||||
delete settings;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit clickButton1(func, url);
|
||||
}
|
||||
}
|
||||
else if(op=="soft"){
|
||||
ShellExecute(GetDesktopWindow(), L"open",path.toStdWString().c_str(),L"",initial_position.toStdWString().c_str(),SW_SHOW);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,62 @@
|
|||
#include "minibutton.h"
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "globalvariables.h"
|
||||
|
||||
MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent)
|
||||
{
|
||||
this->orig_name = orig_name;
|
||||
q_color.setNamedColor(DEFAULT_BACKGROUND_COLOR);
|
||||
|
||||
this->op = op;
|
||||
connect(this, &MiniButton::click, this, &MiniButton::onclick2);
|
||||
}
|
||||
MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
q_color.setNamedColor(DEFAULT_COVER_COLOR);
|
||||
QString style_sheet = "MiniButton:{background-color:";
|
||||
style_sheet += DEFAULT_TEXT_COLOR;
|
||||
style_sheet += ";}";
|
||||
setStyleSheet(style_sheet);
|
||||
connect(this, &MiniButton::click, this, &MiniButton::onclick1);
|
||||
this->button_struct = button_struct;
|
||||
}
|
||||
|
||||
MiniButton::~MiniButton()
|
||||
{}
|
||||
|
||||
void MiniButton::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QPushButton::paintEvent(event);
|
||||
setContentsMargins(0, 0, 0, 0);
|
||||
QRect rect(0, 0, this->width(), this->height());
|
||||
QPainter painter(this);
|
||||
|
||||
painter.fillRect(rect, q_color);
|
||||
int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2;
|
||||
int text_y = (height()- TEXT_SIZE * scale * 3)/2;
|
||||
QFont ft;
|
||||
ft.setPixelSize(TEXT_SIZE);
|
||||
QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3);
|
||||
painter.setPen(DEFAULT_TEXT_COLOR);
|
||||
painter.drawText(text_rect, Qt::AlignCenter, text());
|
||||
|
||||
}
|
||||
|
||||
void MiniButton::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
emit click0();
|
||||
}
|
||||
|
||||
void MiniButton::onclick1()
|
||||
{
|
||||
emit click1(button_struct.op, button_struct.func, button_struct.path, button_struct.url);
|
||||
}
|
||||
|
||||
void MiniButton::onclick2()
|
||||
{
|
||||
emit click2(this->orig_name,this->op);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include "buttonstruct.h"
|
||||
#include "ui_minibutton.h"
|
||||
|
||||
class MiniButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void click1(QString op, QString func, QString path, QString url);
|
||||
void click2(QString orig_name,QString op);
|
||||
void click0();
|
||||
public:
|
||||
MiniButton(QString orig_name, QString op, QWidget* parent = nullptr);
|
||||
MiniButton(ButtonStruct button_struct, QWidget *parent = nullptr);
|
||||
~MiniButton();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
private:
|
||||
QString orig_name;
|
||||
QString op;
|
||||
QColor q_color;
|
||||
Ui::MiniButtonClass ui;
|
||||
bool checked = false;
|
||||
ButtonStruct button_struct;
|
||||
public slots:
|
||||
void onclick1();
|
||||
void onclick2();
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
<UI version="4.0" >
|
||||
<class>MiniButtonClass</class>
|
||||
<widget class="QPushButton" name="MiniButtonClass" >
|
||||
<property name="objectName" >
|
||||
<string notr="true">MiniButtonClass</string>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>MiniButton</string>
|
||||
</property>$centralwidget$
|
||||
</widget>
|
||||
<layoutDefault spacing="6" margin="11" />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<connections/>
|
||||
</UI>
|
|
@ -56,6 +56,7 @@ void MySettingsDialog::autoStart(int state)
|
|||
}
|
||||
QString app = QApplication::applicationFilePath();
|
||||
app.replace("/", "\\");
|
||||
app += " autostart";
|
||||
qDebug() << app.toStdWString().c_str();
|
||||
lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
|
||||
if (lRet == ERROR_SUCCESS)
|
||||
|
@ -63,6 +64,11 @@ void MySettingsDialog::autoStart(int state)
|
|||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
if(agree)
|
||||
{
|
||||
OpRequest op_request("auto_start", "true");
|
||||
op_request.sendRequest();
|
||||
}
|
||||
}
|
||||
else if (state == Qt::Unchecked) {
|
||||
HKEY hRoot = HKEY_CURRENT_USER;
|
||||
|
@ -82,6 +88,11 @@ void MySettingsDialog::autoStart(int state)
|
|||
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。"));
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
if(agree)
|
||||
{
|
||||
OpRequest op_request("auto_start", "false");
|
||||
op_request.sendRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QPixmap>
|
||||
#include "mainwindowlayout.h"
|
||||
#include "globalvariables.h"
|
||||
#include "MyButton.h"
|
||||
#include "sqlitehelper.h"
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "Qt5Svgd.lib")
|
||||
|
@ -54,20 +55,28 @@ NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *p
|
|||
config_request.sendRequest(&config_response);
|
||||
SQLiteHelper sqlite_helper;
|
||||
sqlite_helper.get_software(&buttonStructs, &config_response);
|
||||
if(config_response.succeed==true)
|
||||
if(!config_response.succeed)
|
||||
{
|
||||
getLogoFromInternet(&config_response);
|
||||
qColor.setNamedColor(DEFAULT_BACKGROUND_COLOR);
|
||||
|
||||
}else
|
||||
{
|
||||
getLogoFromLocal();
|
||||
qColor.setNamedColor(config_response.basic.backgroud_color);
|
||||
}
|
||||
layout2 = new QHBoxLayout;
|
||||
layout_right = new QHBoxLayout;
|
||||
layout_left = new QHBoxLayout;
|
||||
logo_label = new QLabel(this);
|
||||
logo_label->setAttribute(Qt::WA_TranslucentBackground);
|
||||
//*logo = logo->scaled(this->width() / (5 / scale), this->height());
|
||||
logo_label->setScaledContents(true);
|
||||
logo_label->setPixmap(QPixmap::fromImage(*logo));
|
||||
QPixmap pixmap(QApplication::applicationDirPath() + DEFAULT_LOGO);
|
||||
pixmap.setMask(pixmap.createMaskFromColor(QColor(Qt::transparent)));
|
||||
logo_label->setAutoFillBackground(true);
|
||||
QPalette palette = logo_label->palette();
|
||||
palette.setColor(QPalette::Window, Qt::transparent);
|
||||
logo_label->setPalette(palette);
|
||||
logo_label->setPixmap(pixmap);
|
||||
logo_label->setMaximumHeight(parent->height() / 8);
|
||||
layout_left->addWidget(logo_label);
|
||||
layout_left->setAlignment(Qt::AlignCenter);
|
||||
|
@ -104,7 +113,6 @@ NavBar::~NavBar() {
|
|||
}
|
||||
layout2->removeWidget(logo_label);
|
||||
delete logo_label;
|
||||
delete logo;
|
||||
//delete layout_left;
|
||||
delete layout_right;
|
||||
delete layout2;
|
||||
|
@ -129,7 +137,7 @@ void NavBar::resizeEvent(QResizeEvent *event) {
|
|||
}
|
||||
logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
|
||||
}
|
||||
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
||||
/*void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
||||
qColor.setNamedColor(configResponse->basic.backgroud_color);
|
||||
|
||||
QUrl url_logo(configResponse->basic.logo_url);
|
||||
|
@ -147,7 +155,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
|||
reply->close();
|
||||
if (downloadSuccess == true) {
|
||||
*buffer = reply->readAll();
|
||||
logo = new QImage();
|
||||
logo = new ;
|
||||
logo->loadFromData(*buffer);
|
||||
buffer->clear();
|
||||
}else
|
||||
|
@ -157,7 +165,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
|||
delete manager;
|
||||
manager = nullptr;
|
||||
|
||||
}
|
||||
}*/
|
||||
void NavBar::storeToBuffer() {
|
||||
buffer = new QByteArray;
|
||||
|
||||
|
@ -169,7 +177,7 @@ void NavBar::cancelDownload() {
|
|||
downloadSuccess = false;
|
||||
}
|
||||
|
||||
void NavBar::getLogoFromLocal() {
|
||||
/*void NavBar::getLogoFromLocal() {
|
||||
QString dir = QApplication::applicationDirPath();
|
||||
QFile file(dir + DEFAULT_FILE);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
|
@ -186,9 +194,7 @@ void NavBar::getLogoFromLocal() {
|
|||
*obj_root = qJsonDocument->object();
|
||||
delete qJsonDocument;
|
||||
QString logo_path = obj_root->value("basic").toObject().value("logo").toString();
|
||||
logo = new QImage(logo_path);
|
||||
QString color= obj_root->value("basic").toObject().value("backgroud_color").toString();
|
||||
qColor.setNamedColor(color);
|
||||
logo = new QPixmap(logo_path);
|
||||
QJsonArray *array = new QJsonArray;
|
||||
}
|
||||
else {
|
||||
|
@ -198,4 +204,4 @@ void NavBar::getLogoFromLocal() {
|
|||
}
|
||||
delete obj_root;
|
||||
|
||||
}
|
||||
}*/
|
|
@ -1,67 +1,67 @@
|
|||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
#ifndef OFFICEASSISTANT_NAVBAR_H
|
||||
#define OFFICEASSISTANT_NAVBAR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QList>
|
||||
#include <map>
|
||||
#include "netio.h"
|
||||
#include "MyButton.h"
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include "buttonstruct.h"
|
||||
#include <QtNetwork/QtNetwork>
|
||||
#include "mainscreen.h"
|
||||
#include <QImage>
|
||||
#include "mainwindowlayout.h"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class NavBar; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class NavBar : public QWidget {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void firstUrl(QString url);
|
||||
public:
|
||||
NavBar(ConfigResponse *configResponse,MainScreen *mainScreen,QWidget *parent = nullptr);
|
||||
|
||||
~NavBar() override;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
|
||||
private:
|
||||
Ui::NavBar *ui;
|
||||
QColor qColor;
|
||||
QList<MyButton *> buttons;
|
||||
QList<ButtonStruct> buttonStructs;
|
||||
QByteArray *buffer;
|
||||
int width2;
|
||||
int height2;
|
||||
QNetworkAccessManager *manager;
|
||||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
QImage *logo;
|
||||
QLabel *logo_label;
|
||||
bool downloadSuccess=true;
|
||||
void getLogoFromInternet(ConfigResponse *configResponse);
|
||||
void getLogoFromLocal();
|
||||
MainScreen *mainScreen;
|
||||
QHBoxLayout *layout_left;
|
||||
QHBoxLayout *layout_right;
|
||||
QHBoxLayout *layout2;
|
||||
private slots:
|
||||
void storeToBuffer();
|
||||
void cancelDownload();
|
||||
};
|
||||
|
||||
|
||||
#endif //OFFICEASSISTANT_NAVBAR_H
|
||||
//
|
||||
// Created by HW on 2023/07/26.
|
||||
//
|
||||
|
||||
#ifndef OFFICEASSISTANT_NAVBAR_H
|
||||
#define OFFICEASSISTANT_NAVBAR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QList>
|
||||
#include <map>
|
||||
#include "netio.h"
|
||||
#include "MyButton.h"
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include "buttonstruct.h"
|
||||
#include <QtNetwork/QtNetwork>
|
||||
#include "mainscreen.h"
|
||||
#include <QImage>
|
||||
#include "mainwindowlayout.h"
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class NavBar; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class NavBar : public QWidget {
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void firstUrl(QString url);
|
||||
public:
|
||||
NavBar(ConfigResponse *configResponse,MainScreen *mainScreen,QWidget *parent = nullptr);
|
||||
|
||||
~NavBar() override;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
|
||||
private:
|
||||
Ui::NavBar *ui;
|
||||
QColor qColor;
|
||||
QList<MyButton *> buttons;
|
||||
QList<ButtonStruct> buttonStructs;
|
||||
QByteArray *buffer;
|
||||
int width2;
|
||||
int height2;
|
||||
QNetworkAccessManager *manager;
|
||||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
QPixmap *logo;
|
||||
QLabel *logo_label;
|
||||
bool downloadSuccess=true;
|
||||
//void getLogoFromInternet(ConfigResponse *configResponse);
|
||||
//void getLogoFromLocal();
|
||||
MainScreen *mainScreen;
|
||||
QHBoxLayout *layout_left;
|
||||
QHBoxLayout *layout_right;
|
||||
QHBoxLayout *layout2;
|
||||
private slots:
|
||||
void storeToBuffer();
|
||||
void cancelDownload();
|
||||
};
|
||||
|
||||
|
||||
#endif //OFFICEASSISTANT_NAVBAR_H
|
||||
|
|
|
@ -60,7 +60,7 @@ RequestBodyBase::RequestBodyBase(){
|
|||
if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){
|
||||
QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
delete infFile;
|
||||
exit(1);
|
||||
exit_manager.exit(1);
|
||||
}
|
||||
//读取配置文件
|
||||
QByteArray bytes;
|
||||
|
@ -73,19 +73,19 @@ RequestBodyBase::RequestBodyBase(){
|
|||
//读取数据,写入对应字段
|
||||
QJsonObject obj_root=qJsonDocument.object();
|
||||
if(obj_root.value("product")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit_manager.exit(1);
|
||||
}
|
||||
product=obj_root.value("product").toString();
|
||||
if(obj_root.value("parter_id")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
if(obj_root.value("partner_id")==QJsonValue::Undefined){
|
||||
QMessageBox::critical(nullptr , QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit_manager.exit(1);
|
||||
}
|
||||
parter_id=obj_root.value("parter_id").toString();
|
||||
parter_id=obj_root.value("partner_id").toString();
|
||||
}else{
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit_manager.exit(1);
|
||||
}
|
||||
//获取操作系统版本
|
||||
this->os="Windows";
|
||||
|
@ -188,6 +188,13 @@ RequestBodyBase::RequestBodyBase(){
|
|||
|
||||
void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
||||
timer = new QTimer(this);
|
||||
if(agree)
|
||||
{
|
||||
QJsonObject obj_root = qJsonDocument.object();
|
||||
obj_root.insert("autostart", autostart);
|
||||
qJsonDocument.setObject(obj_root);
|
||||
}
|
||||
|
||||
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
|
@ -208,12 +215,13 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
timer->stop();
|
||||
//delete httpMgr;
|
||||
QJsonDocument result;
|
||||
QByteArray buffer;
|
||||
configResponse->succeed = false;
|
||||
//memset(configResponse,0,sizeof(*configResponse));
|
||||
auto error = reply->error();
|
||||
//如果没有错误
|
||||
if(reply->error() == QNetworkReply::NoError) {
|
||||
result = QJsonDocument::fromJson(reply->readAll());
|
||||
buffer = reply->readAll();
|
||||
}else{
|
||||
//如果有错误
|
||||
configResponse->succeed=false;
|
||||
|
@ -223,7 +231,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
return;
|
||||
}
|
||||
//qDebug() << result.toJson();
|
||||
|
||||
result = QJsonDocument::fromJson(buffer);
|
||||
//如果数据完整
|
||||
if(result.isObject()){
|
||||
QJsonObject obj_root=result.object();
|
||||
|
@ -264,6 +272,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
|||
delete httpMgr;
|
||||
}
|
||||
void RequestBodyBase::cancelDownload() {
|
||||
downloadSuccess = false;
|
||||
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.quit();
|
||||
reply->abort();
|
||||
|
@ -575,7 +584,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
|||
eventLoop.exec();
|
||||
delete httpMgr;
|
||||
}
|
||||
bool SoftwareRequest::sendRequest(QHash<QString, Record> *records)
|
||||
bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QString, Record> *records)
|
||||
{
|
||||
timer = new QTimer(this);
|
||||
QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
|
||||
|
@ -590,8 +599,20 @@ bool SoftwareRequest::sendRequest(QHash<QString, Record> *records)
|
|||
object.insert("path", record.path);
|
||||
array.append(object);
|
||||
}
|
||||
QJsonArray menu_list;
|
||||
for(auto name:startMenu.keys())
|
||||
{
|
||||
QJsonObject object;
|
||||
object.insert("name", name);
|
||||
object.insert("path", startMenu[name]);
|
||||
menu_list.append(object);
|
||||
}
|
||||
QJsonObject obj_root = qJsonDocument.object();
|
||||
obj_root.insert("software", array);
|
||||
QJsonObject object;
|
||||
object.insert("reg", array);
|
||||
object.insert("start", menu_list);
|
||||
obj_root.insert("data", object);
|
||||
obj_root.insert("type", "update");
|
||||
qJsonDocument.setObject(obj_root);
|
||||
QString url = SOFTWARE_URL;
|
||||
requestInfo.setUrl(url);
|
||||
|
@ -607,15 +628,16 @@ bool SoftwareRequest::sendRequest(QHash<QString, Record> *records)
|
|||
//启动循环
|
||||
eventLoop.exec();
|
||||
timer->stop();
|
||||
delete timer;
|
||||
QJsonDocument result;
|
||||
// auto error = reply->error();
|
||||
//如果没有错误
|
||||
qDebug() << reply->error();
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
result = QJsonDocument::fromJson(reply->readAll());
|
||||
}
|
||||
else {
|
||||
//如果有错误
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
return false;
|
||||
}
|
||||
|
@ -628,15 +650,51 @@ bool SoftwareRequest::sendRequest(QHash<QString, Record> *records)
|
|||
for (auto value : array) {
|
||||
QJsonObject object = value.toObject();
|
||||
QString orig_name = object.value("orig_name").toString();
|
||||
(*records)[orig_name].logo = object.value("img").toString();
|
||||
if (orig_name.isEmpty())
|
||||
{
|
||||
delete httpMgr;
|
||||
return false;
|
||||
}
|
||||
QNetworkAccessManager manager;
|
||||
downloadSuccess = true;
|
||||
QUrl url_logo(object.value("img").toString());
|
||||
QNetworkRequest* request_logo = new QNetworkRequest(url_logo);
|
||||
reply = manager.get(*request_logo);
|
||||
QTimer timer;
|
||||
timer.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
connect(&timer, &QTimer::timeout, this, &SoftwareRequest::cancelDownload);
|
||||
eventLoop.exec();
|
||||
timer.stop();
|
||||
QByteArray buffer;
|
||||
delete request_logo;
|
||||
reply->close();
|
||||
QString dir = QApplication::applicationDirPath() + "/images/software/";
|
||||
if (downloadSuccess == true) {
|
||||
buffer = reply->readAll();
|
||||
QFile file(dir + orig_name + ".svg");
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
file.write(buffer);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//数据不完整
|
||||
//delete reply;
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
return false;
|
||||
}
|
||||
|
@ -644,3 +702,64 @@ bool SoftwareRequest::sendRequest(QHash<QString, Record> *records)
|
|||
return true;
|
||||
}
|
||||
|
||||
QString OpenWeChatRequest::sendRequest(bool notuse)
|
||||
{
|
||||
timer = new QTimer(this);
|
||||
QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
requestInfo.setUrl(QUrl(WECHAT_URL));
|
||||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo, qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply, &QNetworkReply::finished, this, &OpenWeChatRequest::cancelDownload);
|
||||
//设置定时器防止超时
|
||||
connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
timer->stop();
|
||||
QByteArray buffer = reply->readAll();
|
||||
QJsonDocument reply_json = QJsonDocument::fromJson(buffer);
|
||||
if(!reply_json.isObject())
|
||||
{
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
delete reply;
|
||||
return "ok";
|
||||
}
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
delete reply;
|
||||
return reply_json.object().value("msg").toString();
|
||||
}
|
||||
|
||||
void OpRequest::sendRequest()
|
||||
{
|
||||
timer = new QTimer(this);
|
||||
QJsonObject object = qJsonDocument.object();
|
||||
object.insert(op, op_value);
|
||||
qJsonDocument.setObject(object);
|
||||
QNetworkAccessManager* httpMgr = new QNetworkAccessManager();
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
requestInfo.setUrl(QUrl(OP_URL));
|
||||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo, qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply, &QNetworkReply::finished, this, &OpRequest::cancelDownload);
|
||||
//设置定时器防止超时
|
||||
connect(timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
timer->stop();
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
delete reply;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ protected:
|
|||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
QTimer *timer;
|
||||
bool downloadSuccess = true;
|
||||
protected slots:
|
||||
void cancelDownload();
|
||||
};
|
||||
|
@ -95,6 +96,7 @@ protected:
|
|||
};
|
||||
|
||||
class DeviceRequest:RequestBodyBase{
|
||||
public:
|
||||
DeviceRequest();
|
||||
};
|
||||
|
||||
|
@ -117,6 +119,13 @@ inline QString getMachineGUID() {
|
|||
class SoftwareRequest :public RequestBodyBase {
|
||||
public:
|
||||
SoftwareRequest():RequestBodyBase(){}
|
||||
bool sendRequest(QHash<QString, Record>*records);
|
||||
bool sendRequest(QHash<QString, QString>&startMenu, QHash<QString, Record>*records);
|
||||
};
|
||||
|
||||
class OpenWeChatRequest:public RequestBodyBase
|
||||
{
|
||||
public:
|
||||
OpenWeChatRequest():RequestBodyBase(){}
|
||||
QString sendRequest(bool notuse=false/*为了构成函数重载,凑数的*/);
|
||||
};
|
||||
#endif //OFFICEASSISTANT_NETIO_H
|
||||
|
|
|
@ -1,64 +1,63 @@
|
|||
#include "qminiblink.h"
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#pragma comment (lib,"Comctl32.lib")
|
||||
|
||||
QMiniBlink::QMiniBlink(QWidget *parent)
|
||||
: QWidget(parent){
|
||||
|
||||
this->parent = parent;
|
||||
wkeView = nullptr;
|
||||
//QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
|
||||
//setSizePolicy(sizePolicy);
|
||||
}
|
||||
void QMiniBlink::init() {
|
||||
ui.setupUi(this);
|
||||
wkeInit();
|
||||
RECT rect;
|
||||
GetWindowRect((HWND)parent->winId(), &rect);
|
||||
resize(rect.right - rect.left, rect.bottom - rect.top);
|
||||
this->wkeView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
|
||||
wkeSetNavigationToNewWindowEnable(this->wkeView, false);
|
||||
wkeShowWindow(this->wkeView, TRUE);
|
||||
SetParent(wkeGetWindowHandle(this->wkeView), (HWND)this->winId());
|
||||
wkeMoveWindow(this->wkeView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
//while(this->firstUrl.isEmpty()){}
|
||||
//wkeLoadURL(this->wkeView, this->firstUrl.toStdString().c_str());
|
||||
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
|
||||
//wkeRunMessageLoop();
|
||||
}
|
||||
QMiniBlink::~QMiniBlink(){
|
||||
qDebug() << "Destroyed";
|
||||
}
|
||||
void QMiniBlink::ondestroy() {
|
||||
if (this->wkeView != nullptr) {
|
||||
wkeDestroyWebView(wkeView);
|
||||
qDebug() << "Destroyed";
|
||||
}
|
||||
wkeShutdown();
|
||||
}
|
||||
void QMiniBlink::switchUrl(QString url) {
|
||||
wkeLoadURL(wkeView, url.toStdString().c_str());
|
||||
}
|
||||
LRESULT CALLBACK QMiniBlink::subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||
{
|
||||
QMiniBlink *obj = (QMiniBlink *)dwRefData;
|
||||
if (obj == nullptr)
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
switch (uMsg) {
|
||||
case WM_SIZE:
|
||||
obj->autojustWebViewSize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
void QMiniBlink::autojustWebViewSize()
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect((HWND)this->winId(), &rect);
|
||||
wkeMoveWindow(wkeView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
|
||||
}
|
||||
#include "qminiblink.h"
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#pragma comment (lib,"Comctl32.lib")
|
||||
|
||||
QMiniBlink::QMiniBlink(QWidget *parent)
|
||||
: QWidget(parent){
|
||||
|
||||
this->parent = parent;
|
||||
//QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
|
||||
//setSizePolicy(sizePolicy);
|
||||
}
|
||||
void QMiniBlink::init() {
|
||||
ui.setupUi(this);
|
||||
mbSettings settings;
|
||||
memset(&settings, 0, sizeof(mbSettings));
|
||||
mbInit(&settings);
|
||||
RECT rect;
|
||||
GetWindowRect((HWND)parent->winId(), &rect);
|
||||
resize(rect.right - rect.left, rect.bottom - rect.top);
|
||||
this->mbView = mbCreateWebWindow(MB_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
|
||||
mbSetNavigationToNewWindowEnable(this->mbView, false);
|
||||
mbShowWindow(this->mbView, TRUE);
|
||||
SetParent(mbGetHostHWND(this->mbView), (HWND)this->winId());
|
||||
mbMoveWindow(this->mbView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
//while(this->firstUrl.isEmpty()){}
|
||||
//mbLoadURL(this->mbView, this->firstUrl.toStdString().c_str());
|
||||
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
|
||||
//mbRunMessageLoop();
|
||||
}
|
||||
QMiniBlink::~QMiniBlink(){
|
||||
qDebug() << "Destroyed";
|
||||
}
|
||||
void QMiniBlink::ondestroy() {
|
||||
mbDestroyWebView(mbView);
|
||||
qDebug() << "Destroyed";
|
||||
mbUninit();
|
||||
}
|
||||
void QMiniBlink::switchUrl(QString url) {
|
||||
mbLoadURL(mbView, url.toStdString().c_str());
|
||||
}
|
||||
LRESULT CALLBACK QMiniBlink::subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||
{
|
||||
QMiniBlink *obj = (QMiniBlink *)dwRefData;
|
||||
if (obj == nullptr)
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
switch (uMsg) {
|
||||
case WM_SIZE:
|
||||
obj->autojustWebViewSize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||
}
|
||||
void QMiniBlink::autojustWebViewSize()
|
||||
{
|
||||
RECT rect;
|
||||
GetWindowRect((HWND)this->winId(), &rect);
|
||||
mbMoveWindow(mbView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "ui_qminiblink.h"
|
||||
#include "wke.h"
|
||||
#include <Windows.h>
|
||||
#include <CommCtrl.h>
|
||||
|
||||
class QMiniBlink : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMiniBlink(QWidget *parent = nullptr);
|
||||
~QMiniBlink();
|
||||
void init();
|
||||
|
||||
void autojustWebViewSize();
|
||||
QString firstUrl;
|
||||
public slots:
|
||||
void ondestroy();
|
||||
void switchUrl(QString url);
|
||||
private:
|
||||
Ui::QMiniBlink ui;
|
||||
wkeWebView wkeView;
|
||||
QWidget *parent;
|
||||
int w;
|
||||
int h;
|
||||
static LRESULT CALLBACK subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
|
||||
};
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "ui_qminiblink.h"
|
||||
#include "mb.h"
|
||||
#include <Windows.h>
|
||||
#include <CommCtrl.h>
|
||||
|
||||
class QMiniBlink : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QMiniBlink(QWidget *parent = nullptr);
|
||||
~QMiniBlink();
|
||||
void init();
|
||||
|
||||
void autojustWebViewSize();
|
||||
QString firstUrl;
|
||||
public slots:
|
||||
void ondestroy();
|
||||
void switchUrl(QString url);
|
||||
private:
|
||||
Ui::QMiniBlink ui;
|
||||
mbWebView mbView;
|
||||
QWidget *parent;
|
||||
int w;
|
||||
int h;
|
||||
static LRESULT CALLBACK subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
|
||||
};
|
||||
|
|
|
@ -34,7 +34,8 @@ namespace fs = std::filesystem;
|
|||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#endif
|
||||
bool getMenu(std::wstring &path_str,QList<QString> *paths)
|
||||
|
||||
bool getMenu(std::wstring &path_str,QHash<QString,QString> *paths)
|
||||
{
|
||||
fs::directory_iterator* it = new fs::directory_iterator(path_str);
|
||||
for (auto file : *it)
|
||||
|
@ -65,7 +66,8 @@ bool getMenu(std::wstring &path_str,QList<QString> *paths)
|
|||
hr = pShellItem->GetPath(szTargetPath, sizeof(szTargetPath), &fd, 0); ;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
*paths << QString::fromWCharArray(szTargetPath);
|
||||
QString filename = file.path().filename().string().c_str();
|
||||
*paths->insert(filename,QString::fromWCharArray(szTargetPath));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -134,14 +136,12 @@ SQLiteHelper::SQLiteHelper(QObject *parent)
|
|||
|
||||
SQLiteHelper::~SQLiteHelper()
|
||||
{
|
||||
db.close();
|
||||
QSqlDatabase::removeDatabase("mydb");
|
||||
}
|
||||
|
||||
bool SQLiteHelper::update_software()
|
||||
{
|
||||
HKEY hKeyUninstall = nullptr;
|
||||
QList<QString>* paths = new QList<QString>;
|
||||
QHash<QString,QString>* paths = new QHash<QString, QString>;
|
||||
/*QSqlQuery query;
|
||||
QString sql = "select * from kmd_menu;";
|
||||
query.exec(sql);
|
||||
|
@ -176,7 +176,7 @@ bool SQLiteHelper::update_software()
|
|||
records.insert(path, record);
|
||||
}*/
|
||||
//开始菜单中已安装软件列表
|
||||
/*WCHAR path[MAX_PATH];
|
||||
WCHAR path[MAX_PATH];
|
||||
HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//获取ProgramData中开始菜单的路径
|
||||
std::wstring path_str(path);
|
||||
getMenu(path_str, paths);
|
||||
|
@ -188,7 +188,7 @@ bool SQLiteHelper::update_software()
|
|||
hr = SHGetFolderPathW(nullptr, CSIDL_PROGRAMS, nullptr, 0, path);//获取用户文件夹中开始菜单的路径
|
||||
path_str.clear();
|
||||
path_str = std::wstring(path);
|
||||
getMenu(path_str, paths); */
|
||||
getMenu(path_str, paths);
|
||||
// 打开注册表中的已安装软件列表
|
||||
QHash<QString, Record> reg_records;
|
||||
HKEY hKey;
|
||||
|
@ -656,7 +656,13 @@ bool SQLiteHelper::update_software()
|
|||
}
|
||||
//进行网络请求,补全字段
|
||||
SoftwareRequest software_request;
|
||||
software_request.sendRequest(&public_programs_list);
|
||||
bool ok=software_request.sendRequest(*paths,&public_programs_list);
|
||||
if(!ok)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
QSqlQuery begin(db);
|
||||
if (!begin.exec("begin;"))
|
||||
{
|
||||
|
@ -703,7 +709,7 @@ bool SQLiteHelper::update_software()
|
|||
sql += ",'";
|
||||
sql += public_programs_list[key].type;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].category_id;
|
||||
sql += QString::number(OTHERS, 10);
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].name;
|
||||
sql += "','";
|
||||
|
@ -736,6 +742,29 @@ bool SQLiteHelper::update_software()
|
|||
return false;
|
||||
}
|
||||
}
|
||||
QSqlQuery find(db);
|
||||
|
||||
find.exec("select orig_name,op from kmd_menu;");
|
||||
while(find.next())
|
||||
{
|
||||
if(!public_programs_list.contains(find.value("orig_name").toString()))
|
||||
{
|
||||
if (find.value("op").toString() == "soft")
|
||||
{
|
||||
QSqlQuery del(db);
|
||||
del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;");
|
||||
del.bindValue(":orig_value", find.value("orig_name"));
|
||||
del.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
find.clear();
|
||||
find.exec("select id from kmd_menu where status=0;");
|
||||
if(find.size()>=100)
|
||||
{
|
||||
QSqlQuery del(db);
|
||||
del.exec("delete from kmd_menu where status=0;");
|
||||
}
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
|
@ -765,11 +794,30 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
{
|
||||
return false;
|
||||
}
|
||||
QString background_color;
|
||||
QString title_color;
|
||||
QString title_cover_color;
|
||||
if(config_response->succeed)
|
||||
{
|
||||
background_color = config_response->basic.backgroud_color;
|
||||
title_color = config_response->basic.title_color;
|
||||
title_cover_color = config_response->basic.title_cover_color;
|
||||
}
|
||||
else
|
||||
{
|
||||
background_color = DEFAULT_BACKGROUND_COLOR;
|
||||
title_color = DEFAULT_TEXT_COLOR;
|
||||
title_cover_color = DEFAULT_COVER_COLOR;
|
||||
}
|
||||
QByteArray* buffer = new QByteArray;
|
||||
QHash<QString, ButtonStruct> button_map;
|
||||
for(auto menu : config_response->buttons)
|
||||
{
|
||||
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QNetworkAccessManager manager;
|
||||
downloadSuccess = true;
|
||||
QString icon = QApplication::applicationDirPath() + "/images/software/" + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
|
@ -780,11 +828,6 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
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);
|
||||
QString icon = QApplication::applicationDirPath() + query.value("logo").toString();
|
||||
if(icon.isEmpty())
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
}
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
|
@ -799,7 +842,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", config_response->basic.title_cover_color);
|
||||
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); // 清除画布
|
||||
|
@ -811,7 +854,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
delete render_image_cover;
|
||||
}else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + "/images/icon/default.svg";
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
|
@ -826,7 +869,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", config_response->basic.title_cover_color);
|
||||
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); // 清除画布
|
||||
|
@ -840,11 +883,12 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* buttons, ConfigResponse* co
|
|||
}
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = config_response->basic.backgroud_color;
|
||||
button_struct.text_color = QColor(config_response->basic.title_color);
|
||||
button_struct.text_cover_color = QColor(config_response->basic.title_cover_color);
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*buttons << button_struct;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -915,4 +959,207 @@ bool SQLiteHelper::update_app()
|
|||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLiteHelper::get_buttons(QList<ButtonStruct> &buttons)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec("select * from kmd_menu where type='app_manage'and status=1 order by sort asc"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while(query.next())
|
||||
{
|
||||
ButtonStruct button_struct;
|
||||
button_struct.text = query.value("name").toString();
|
||||
button_struct.op= query.value("op").toString();
|
||||
button_struct.func = query.value("func").toString();
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.url = query.value("url").toString();
|
||||
button_struct.text_color = DEFAULT_TEXT_COLOR;
|
||||
button_struct.background_color = DEFAULT_COVER_COLOR;
|
||||
buttons << button_struct;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories) {
|
||||
QSqlQuery query(db);
|
||||
QString categories_str="";
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
if(categories[i])
|
||||
{
|
||||
categories_str = categories_str + QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(sort.toInt());
|
||||
query.addBindValue("");
|
||||
query.addBindValue(false);
|
||||
query.addBindValue("app");
|
||||
query.addBindValue(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
query.addBindValue("soft");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(path);
|
||||
query.addBindValue("");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(true);
|
||||
if(!query.exec())
|
||||
{
|
||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("写入数据库失败"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery work(db);
|
||||
work.exec("begin;");
|
||||
for(Categrory categrory:categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
query.prepare("update kmd_category set name=:name,sort=:sort,status=:status where id=:id;");
|
||||
query.bindValue(":name", categrory.name);
|
||||
query.bindValue(":status", categrory.display);
|
||||
query.bindValue(":sort", categrory.sort);
|
||||
query.bindValue(":id", categrory.id);
|
||||
if (!query.exec())
|
||||
{
|
||||
qDebug() << query.lastError();
|
||||
work.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
QSqlQuery work2(db);
|
||||
work2.exec("commit;");
|
||||
qDebug() << work.lastError();
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::get_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec("select id,name,status,sort from kmd_category"))
|
||||
{
|
||||
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();
|
||||
categrory.sort = query.value("sort").toInt();
|
||||
categrory.display = query.value("status").toBool();
|
||||
categrories << categrory;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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;";
|
||||
}
|
||||
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;";
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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();
|
||||
softwares << record;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString type)
|
||||
{
|
||||
if (type.isEmpty())
|
||||
{
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort.toInt());
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":type", type);
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,13 @@ typedef struct tagRecord{
|
|||
bool status;
|
||||
}Record;
|
||||
#include "netio.h"
|
||||
|
||||
struct Categrory
|
||||
{
|
||||
int id;
|
||||
QString name;
|
||||
bool display;
|
||||
int sort;
|
||||
};
|
||||
class SQLiteHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -39,8 +45,16 @@ 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 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 update_app();
|
||||
bool get_buttons(QList<ButtonStruct> &buttons);
|
||||
bool get_category(QList<Categrory> &categrories);
|
||||
bool set_category(QList<Categrory>& categrories);
|
||||
bool get_all_software(QList<Record> &softwares,int category);
|
||||
QSqlDatabase db;
|
||||
|
||||
~SQLiteHelper();
|
||||
|
||||
private:
|
||||
|
@ -48,6 +62,5 @@ private:
|
|||
QEventLoop eventLoop;
|
||||
bool downloadSuccess;
|
||||
|
||||
QSqlDatabase db;
|
||||
void cancelDownload();
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue