阶段性完成,还差独立浏览器和几个别的需求。

master
Mike Solar 2023-08-26 22:13:39 +08:00
parent 9ee232cead
commit fd525fb8d1
12 changed files with 227 additions and 119 deletions

View File

@ -126,9 +126,6 @@
<ClCompile Include="minibutton.cpp"> <ClCompile Include="minibutton.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="addapp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="addcategory.cpp"> <ClCompile Include="addcategory.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@ -138,6 +135,9 @@
<ClCompile Include="userimprove.cpp"> <ClCompile Include="userimprove.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="addapp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtUic Include="navbar.ui"> <QtUic Include="navbar.ui">

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>79c86fb12b36dfa33d1a537c9af100b4c7928a9c</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>autostart</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>$(QmlDebug)</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

View File

@ -123,7 +123,7 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
add_app.get_sort(), add_app.get_categories()); add_app.get_sort(), add_app.get_categories());
if (!ok) if (!ok)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名?"));
} }
emit refresh_tab(); emit refresh_tab();
@ -153,7 +153,7 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
{ {
UserImprove user_improve; UserImprove user_improve;
user_improve.exec(); user_improve.exec();
if(file.open(QIODevice::WriteOnly)) if(file.open(QIODevice::WriteOnly|QIODevice::Text))
{ {
QJsonObject rootObj; QJsonObject rootObj;
rootObj.insert("agree", agree); rootObj.insert("agree", agree);

View File

@ -15,5 +15,6 @@ extern bool autostart;
extern bool agree; extern bool agree;
extern QString background_color; extern QString background_color;
extern QString text_color; extern QString text_color;
extern QString text_cover_color;
extern ApplicationManager *application_manager; extern ApplicationManager *application_manager;
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H #endif //OFFICEASSISTANT_GLOBALVARIABLES_H

View File

@ -1,4 +1,4 @@
#include "mysettingsdialog.h" #include "mysettingsdialog.h"
#include <Windows.h> #include <Windows.h>
#include <QClipBoard> #include <QClipBoard>
#include "netio.h" #include "netio.h"
@ -12,9 +12,9 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
setWindowFlags(Qt::WindowCloseButtonHint); setWindowFlags(Qt::WindowCloseButtonHint);
this->setFixedSize(width(), height()); this->setFixedSize(width(), height());
HKEY hRoot = HKEY_CURRENT_USER; HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = (wchar_t *)"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey; HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建 DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
@ -22,9 +22,10 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
app.replace("/", "\\"); app.replace("/", "\\");
DWORD size=128+sizeof(wchar_t); app += " autostart";
char reg[128] = { 0 }; DWORD size=256*sizeof(wchar_t);
lRet = RegQueryValueEx(hKey, L"OfficeAssistant", NULL, NULL,(LPBYTE)reg, &size); wchar_t reg[256] = { 0 };
lRet = RegQueryValueEx(hKey, LENG_NAME, NULL, NULL,(LPBYTE)reg, &size);
if (lRet==0) { if (lRet==0) {
ui.autostart->setChecked(true); ui.autostart->setChecked(true);
} }
@ -47,11 +48,11 @@ void MySettingsDialog::autoStart(int state)
HKEY hRoot = HKEY_CURRENT_USER; HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey; HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建 DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败")); QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败"));
return; return;
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
@ -61,7 +62,7 @@ void MySettingsDialog::autoStart(int state)
lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t)); lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
if (lRet == ERROR_SUCCESS) if (lRet == ERROR_SUCCESS)
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
} }
RegCloseKey(hKey); RegCloseKey(hKey);
if(agree) if(agree)
@ -78,14 +79,14 @@ void MySettingsDialog::autoStart(int state)
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) { if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败。")); QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败。"));
return; return;
} }
QString app = QApplication::applicationFilePath(); QString app = QApplication::applicationFilePath();
lRet = RegDeleteValue(hKey, LENG_NAME); lRet = RegDeleteValue(hKey, LENG_NAME);
if (lRet == ERROR_SUCCESS) if (lRet == ERROR_SUCCESS)
{ {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。"));
} }
RegCloseKey(hKey); RegCloseKey(hKey);
if(agree) if(agree)
@ -116,9 +117,9 @@ void MySettingsDialog::createShortcut() {
QString srcFile = QApplication::applicationFilePath(); QString srcFile = QApplication::applicationFilePath();
bool succeed=QFile::link(srcFile, deskTopPath); bool succeed=QFile::link(srcFile, deskTopPath);
if (succeed) { if (succeed) {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式成功。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式成功。"));
} }
else { else {
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式失败。")); QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建快捷方式失败。"));
} }
} }

View File

@ -56,16 +56,13 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
config_request.sendRequest(&config_response); config_request.sendRequest(&config_response);
SQLiteHelper sqlite_helper; SQLiteHelper sqlite_helper;
sqlite_helper.get_software(&buttonStructs, &config_response); sqlite_helper.get_software(&buttonStructs, &config_response);
background_color = config_response.basic.backgroud_color;
text_color = config_response.basic.title_color;
text_cover_color = config_response.basic.title_cover_color;
if(!config_response.succeed) if(!config_response.succeed)
{ {
qColor.setNamedColor(buttonStructs[0].background_color); qColor.setNamedColor(background_color);
}else }else
{ {
qColor.setNamedColor(config_response.basic.backgroud_color); qColor.setNamedColor(background_color);
} }
layout2 = new QHBoxLayout; layout2 = new QHBoxLayout;
layout_right = new QHBoxLayout; layout_right = new QHBoxLayout;
@ -89,7 +86,7 @@ NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) :
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this); MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this);
myButton->setMaximumHeight(parent->height() / 8); myButton->setMaximumHeight(parent->height() / 8);
layout_right->addWidget(myButton); layout_right->addWidget(myButton);
//myButton->show(); myButton->show();
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton); connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
buttons << myButton; buttons << myButton;
} }

View File

@ -51,9 +51,6 @@ private:
int width2; int width2;
int height2; int height2;
QWidget* parent; QWidget* parent;
QString background_color;
QString text_color;
QString text_cover_color;
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
QNetworkReply *reply; QNetworkReply *reply;
QEventLoop eventLoop; QEventLoop eventLoop;

View File

@ -33,6 +33,7 @@
#pragma comment(lib,"comsuppw.lib") #pragma comment(lib,"comsuppw.lib")
QString background_color; QString background_color;
QString text_color; QString text_color;
QString text_cover_color;
//读取注册表获取MachineUUID //读取注册表获取MachineUUID
bool IsWin11AndLater() bool IsWin11AndLater()
{ {
@ -256,8 +257,8 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
for(auto value:array){ for(auto value:array){
QJsonObject object=value.toObject(); QJsonObject object=value.toObject();
Button button; Button button;
button.img = object.value("img").toString(); button.img = object.value("logo").toString();
button.png = object.value("logo").toString(); button.png = object.value("img").toString();
button.img_name = object.value("img_name").toString(); button.img_name = object.value("img_name").toString();
button.name = object.value("name").toString(); button.name = object.value("name").toString();
button.type = object.value("type").toString(); button.type = object.value("type").toString();
@ -324,8 +325,6 @@ void RequestBodyBase::sendRequest() {
DeviceRequest::DeviceRequest() : RequestBodyBase() { DeviceRequest::DeviceRequest() : RequestBodyBase() {
//CPU
QString cpu = QSysInfo::currentCpuArchitecture();
//内存大小 //内存大小
MEMORYSTATUSEX status; MEMORYSTATUSEX status;
status.dwLength = sizeof(status); status.dwLength = sizeof(status);
@ -334,59 +333,14 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
//硬盘大小 //硬盘大小
QStorageInfo storage = QStorageInfo::root(); QStorageInfo storage = QStorageInfo::root();
int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024); int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024);
//显卡型号
QStringList gpus;
BOOL success;
DWORD deviceIndex = 0;
DISPLAY_DEVICE displayDevice;
displayDevice.cb = sizeof(displayDevice);
while (EnumDisplayDevices(NULL, deviceIndex, &displayDevice, 0)) {
WCHAR valueName[128];
DWORD valueSize;
DWORD valueType;
BYTE valueData[MAX_PATH];
HKEY hKey;
WCHAR keyName[128];
wsprintf(keyName, L"SYSTEM\\CurrentControlSet\\Control\\Video\\%s\\HardwareInformation",
displayDevice.DeviceID);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
valueSize = sizeof(valueData);
wsprintf(valueName, L"HardwareInformation.AdapterString");
if (RegQueryValueEx(hKey, valueName, NULL, &valueType, valueData, &valueSize) == ERROR_SUCCESS) {
Q_ASSERT(valueType == REG_SZ);
QString adapterString = QString::fromWCharArray((wchar_t *) valueData, valueSize / sizeof(wchar_t) - 1);
gpus.append(adapterString);
}
RegCloseKey(hKey);
}
deviceIndex++;
displayDevice.cb = sizeof(displayDevice);
}
//主板型号
QString motherboard = QSysInfo::prettyProductName();
//WMI获取网卡型号 //WMI获取网卡型号
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(hr)) { if (FAILED(hr)) {
std::cerr << "Failed to initialize COM library." << std::endl; std::cerr << "Failed to initialize COM library." << std::endl;
return; return;
} }
QStringList netCards; QStringList netCards;
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hr)) {
std::cerr << "Failed to initialize security." << std::endl;
CoUninitialize();
return;
}
IWbemLocator* pLoc = NULL; IWbemLocator* pLoc = NULL;
hr = CoCreateInstance( hr = CoCreateInstance(
@ -441,7 +395,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
IEnumWbemClassObject* pEnumerator = NULL; IEnumWbemClassObject* pEnumerator = NULL;
hr = pSvc->ExecQuery( hr = pSvc->ExecQuery(
_bstr_t("WQL"), _bstr_t("WQL"),
_bstr_t("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE AND NetConnectionStatus = 3"), _bstr_t("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL, NULL,
&pEnumerator &pEnumerator
@ -471,6 +425,78 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
pClassObj->Release(); pClassObj->Release();
} }
pEnumerator->Release();
pEnumerator = nullptr;
// 获取 CPU 信息
hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_Processor"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
IWbemClassObject* pclsObj = NULL;
uReturn = 0;
QString cpu;
while (pEnumerator) {
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
cpu=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
// 获取主板信息
QString motherboard;
hr = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_BaseBoard"), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
while (pEnumerator) {
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Product", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
motherboard=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
pEnumerator->Release();
pEnumerator=nullptr;
//WMI获取显卡型号
hr = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_VideoController"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hr))
{
std::cerr << "Query failed." << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
QStringList graphicsCards;
pclsObj->Release();
pclsObj = NULL;
uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (0 == uReturn) break;
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr))
{
graphicsCards<< QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
}
pclsObj->Release();
}
//WMI获取声卡型号 //WMI获取声卡型号
hr = pSvc->ExecQuery( hr = pSvc->ExecQuery(
_bstr_t("WQL"), _bstr_t("WQL"),
@ -531,7 +557,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
hr = pClassObj->Get(L"Manufacturer", 0, &vtProp, 0, 0); hr = pClassObj->Get(L"Manufacturer", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
std::wcout << "Manufacturer: " << vtProp.bstrVal << std::endl; RAMModel<<QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp); VariantClear(&vtProp);
} }
@ -547,9 +573,30 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
pSvc->Release(); pSvc->Release();
pLoc->Release(); pLoc->Release();
CoUninitialize(); CoUninitialize();
DISPLAY_DEVICE d = { sizeof(DISPLAY_DEVICE) };
::EnumDisplayDevices(NULL, 0, &d, 0); DISPLAY_DEVICE dd;
QString monitor=QString::fromWCharArray(d.DeviceString, wcslen(d.DeviceString)); ZeroMemory(&dd, sizeof(dd));
dd.cb = sizeof(dd);
int deviceIndex = 0;
QStringList monitors;
// 枚举显卡设备
while (EnumDisplayDevices(0, deviceIndex, &dd, 0))
{
DISPLAY_DEVICE monitor;
ZeroMemory(&monitor, sizeof(monitor));
monitor.cb = sizeof(monitor);
int monitorIndex = 0;
// 对每个显卡枚举其连接的显示器
while (EnumDisplayDevices(dd.DeviceName, monitorIndex, &monitor, 0))
{
// 打印显示器型号
monitors<<QString::fromWCharArray(monitor.DeviceString);
monitorIndex++;
}
deviceIndex++;
}
//发送 //发送
//构造JSON //构造JSON
QJsonDocument *device=new QJsonDocument; QJsonDocument *device=new QJsonDocument;
@ -558,7 +605,9 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
object->insert("RAM",QJsonValue(ram)); object->insert("RAM",QJsonValue(ram));
object->insert("Hard_Disk",QJsonValue(disk)); object->insert("Hard_Disk",QJsonValue(disk));
QJsonArray *gpu_array=new QJsonArray; QJsonArray *gpu_array=new QJsonArray;
for(auto gpu:gpus) {
for(auto gpu:graphicsCards)
{
gpu_array->append(gpu); gpu_array->append(gpu);
} }
object->insert("GPU",*gpu_array); object->insert("GPU",*gpu_array);
@ -582,7 +631,13 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
} }
object->insert("Audio_Card",*audioCards_json); object->insert("Audio_Card",*audioCards_json);
delete audioCards_json; delete audioCards_json;
object->insert("Monitor",monitor); QJsonArray *monitors_json=new QJsonArray;
for(auto monitor:monitors)
{
monitors_json->append(monitor);
}
object->insert("Monitor",*monitors_json);
delete monitors_json;
device->setObject(*object); device->setObject(*object);
delete object; delete object;
QJsonObject obj_root=qJsonDocument.object(); QJsonObject obj_root=qJsonDocument.object();
@ -597,6 +652,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
requestInfo.setUrl(QUrl(DEVICE_URL)); requestInfo.setUrl(QUrl(DEVICE_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量 //保存响应的变量
qDebug()<<qJsonDocument.toJson();
reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止 //开启一个循环,直到超时或者获取到数据为止
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
@ -605,6 +661,8 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
timer->start(5000); timer->start(5000);
//启动循环 //启动循环
eventLoop.exec(); eventLoop.exec();
qDebug()<<reply->error();
qDebug()<<reply->readAll();
delete httpMgr; delete httpMgr;
} }
bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QString, Record> *records, QJsonArray &software_exists) bool SoftwareRequest::sendRequest(QHash<QString,QString>&startMenu, QHash<QString, Record> *records, QJsonArray &software_exists)

View File

@ -17,6 +17,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include <fstream>
#include <QFile> #include <QFile>
#include "applicationmanager.h" #include "applicationmanager.h"
#define MAX_KEY_LENGTH 255 #define MAX_KEY_LENGTH 255
@ -30,6 +31,7 @@
#pragma comment (lib,"Shell32.lib") #pragma comment (lib,"Shell32.lib")
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <iostream>
#include <experimental/filesystem> #include <experimental/filesystem>
namespace fs= std::experimental::filesystem; namespace fs= std::experimental::filesystem;
@ -768,6 +770,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
{ {
background_color = config_response->basic.backgroud_color; background_color = config_response->basic.backgroud_color;
text_color = config_response->basic.title_color; text_color = config_response->basic.title_color;
text_cover_color = config_response->basic.title_cover_color;
title_color = config_response->basic.title_color; title_color = config_response->basic.title_color;
title_cover_color = config_response->basic.title_cover_color; title_cover_color = config_response->basic.title_cover_color;
@ -789,7 +792,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
array = obj_root.value("data").toObject().value("menu").toArray(); array = obj_root.value("data").toObject().value("menu").toArray();
qDebug() << array; qDebug() << array;
QJsonObject obj_data = obj_root.value("data").toObject(); QJsonObject obj_data = obj_root.value("data").toObject();
QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object(); QJsonObject obj_basic = obj_data.value("basic").toObject();
background_color = obj_basic.value("backgroud_color").toString(); background_color = obj_basic.value("backgroud_color").toString();
title_color = obj_basic.value("title_color").toString(); title_color = obj_basic.value("title_color").toString();
text_color = obj_basic.value("title_color").toString(); text_color = obj_basic.value("title_color").toString();
@ -865,7 +868,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
delete manager; delete manager;
manager = nullptr; manager = nullptr;
QUrl url_png(menu.png); QUrl url_png(menu.png);
QNetworkRequest* request_png = new QNetworkRequest(url_logo); QNetworkRequest* request_png = new QNetworkRequest(url_png);
manager = new QNetworkAccessManager; manager = new QNetworkAccessManager;
reply = manager->get(*request_png); reply = manager->get(*request_png);
QTimer timer_png; QTimer timer_png;
@ -877,15 +880,15 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
QByteArray buffer_png; QByteArray buffer_png;
buffer_png = reply->readAll(); buffer_png = reply->readAll();
delete request_png; delete request_png;
reply->close();
QString png_path = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";; QString png_path = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";;
if ((reply->error() == QNetworkReply::NoError) && (downloadSuccess == true)) if ((reply->error() == QNetworkReply::NoError) && (downloadSuccess == true))
{ {
QFile file(QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png"); //没仔细研究QFile貌似读写二进制文件挺麻烦先用标准库吧
if (file.open(QIODevice::WriteOnly)) std::ofstream out(png_path.toStdString(), std::ios::binary);
if(out.is_open())
{ {
file.write(buffer_png); out.write(buffer_png.data(), buffer_png.size());
file.close(); out.close();
} }
} }
else else
@ -907,6 +910,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
} }
} }
} }
reply->close();
delete manager; delete manager;
manager = nullptr; manager = nullptr;
bool categories[CATEGORIES_NUM] = { false }; bool categories[CATEGORIES_NUM] = { false };
@ -1044,7 +1048,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs,QString back
} }
while (query.next()) while (query.next())
{ {
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg"; QString icon = QApplication::applicationDirPath() + query.value("logo").toString();
ButtonStruct button_struct; ButtonStruct button_struct;
button_struct.path = query.value("path").toString(); button_struct.path = query.value("path").toString();
button_struct.text = query.value("name").toString(); button_struct.text = query.value("name").toString();
@ -1260,34 +1264,35 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
{ {
img = QApplication::applicationDirPath()+DEFAULT_PNG; img = QApplication::applicationDirPath()+DEFAULT_PNG;
} }
QSqlQuery query_sel(db); QSqlQuery query_sel(db);
query_sel.prepare("select id from kmd_menu where orig_name = :orig_name;"); query_sel.prepare("select id from kmd_menu where orig_name = :orig_name;");
query_sel.bindValue(":orig_name",orig_name); query_sel.bindValue(":orig_name", orig_name);
if(query_sel.exec()) if (query_sel.exec())
{ {
if(query_sel.next()) if (query_sel.next())
{ {
QString sql="update kmd_menu" QString sql = "update kmd_menu"
" set sort=:sort,locked=:locked,type=:type,category_id=:category_id," " set sort=:sort,locked=:locked,type=:type,category_id=:category_id,"
"name=:name,orig_name=:orig_name,op=:op," "name=:name,orig_name=:orig_name,op=:op,"
"func=:func,path=:path,url=:url,logo=:logo,img=:img,is_navbar=:is_navbar,is_elite=:is_elite,dev=:dev where orig_name=:orig_name;"; "func=:func,path=:path,url=:url,logo=:logo,img=:img,is_navbar=:is_navbar,is_elite=:is_elite,dev=:dev where orig_name=:orig_name;";
query.prepare(sql); query.prepare(sql);
query.bindValue(":sort",sort); query.bindValue(":sort", sort);
query.bindValue(":locked",locked); query.bindValue(":locked", locked);
query.bindValue(":type",type); query.bindValue(":type", type);
query.bindValue(":category_id",categories_str); query.bindValue(":category_id", categories_str);
query.bindValue(":name",name); query.bindValue(":name", name);
query.bindValue(":orig_name",orig_name); query.bindValue(":orig_name", orig_name);
query.bindValue(":op",op); query.bindValue(":op", op);
query.bindValue(":func",func); query.bindValue(":func", func);
query.bindValue(":path",path); query.bindValue(":path", path);
query.bindValue(":url",url); query.bindValue(":url", url);
query.bindValue(":logo",logo); query.bindValue(":logo", logo);
query.bindValue(":img",img); query.bindValue(":img", img);
query.bindValue(":is_navbar",is_navbar); query.bindValue(":is_navbar", is_navbar);
query.bindValue(":is_elite", is_elite); query.bindValue(":is_elite", is_elite);
query.bindValue(":dev", dev); query.bindValue(":dev", dev);
if(!query.exec()) if (!query.exec())
{ {
QSqlQuery rollback(db); QSqlQuery rollback(db);
rollback.exec("ROLLBACK;"); rollback.exec("ROLLBACK;");
@ -1335,7 +1340,50 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
return true; return true;
} }
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories) {
QSqlQuery begin(db);
begin.exec("BEGIN;");
QSqlQuery query(db);
QString categories_str = "";
categories[ALL - 1] = true;
QString sql = "insert into kmd_menu "
"(sort, app_id, locked, type, category_id, name, orig_name,"
" create_time, op, func, path, url, "
"initial_position,status,logo,img,is_navbar,is_elite,dev) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
query.prepare(sql);
query.addBindValue(sort.toInt());
query.addBindValue("");
query.addBindValue(false);
query.addBindValue("app");
query.addBindValue(categories_str);
query.addBindValue(name);
query.addBindValue(orig_name);
time_t create_time;
time(&create_time);
query.addBindValue(create_time);
query.addBindValue("app");
query.addBindValue("open");
query.addBindValue(path);
query.addBindValue("");
query.addBindValue("");
query.addBindValue(true);
query.addBindValue(QApplication::applicationDirPath() + DEFAULT_IMAGE);
query.addBindValue(QApplication::applicationDirPath() + DEFAULT_PNG);
query.addBindValue(false);
query.addBindValue(false);
query.addBindValue("");
if (!query.exec())
{
QSqlQuery rollback(db);
rollback.exec("ROLLBACK;");
return false;
}
update_total();
QSqlQuery commit(db);
commit.exec("COMMIT;");
return true;
}
bool SQLiteHelper::set_category(QList<Categrory>& categrories) bool SQLiteHelper::set_category(QList<Categrory>& categrories)
{ {
QSqlQuery work(db); QSqlQuery work(db);

View File

@ -51,7 +51,8 @@ class SQLiteHelper : public QObject
public: public:
SQLiteHelper(QObject *parent = nullptr); SQLiteHelper(QObject *parent = nullptr);
bool update_software(); bool update_software();
bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString logo="", QString img="",QString type="app",bool locked=false,QString op="soft",QString func="",QString url="",bool is_navbar=false,bool is_elite=false,QString dev=""); bool insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories, QString logo, QString img,QString type,bool locked,QString op,QString func,QString url,bool is_navbar,bool is_elite,QString dev);
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 edit_software(QString name, QString orig_name, QString path, QString sort, bool* categories,QString type="");
bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response); bool get_software(QList<ButtonStruct>* buttons, ConfigResponse* config_response);
bool get_software(QList<ButtonStruct>* button_structs,QString background_color , QString title_color, QString title_cover_color); bool get_software(QList<ButtonStruct>* button_structs,QString background_color , QString title_color, QString title_cover_color);

View File

@ -23,6 +23,7 @@ void UserImprove::submit()
{ {
agree = false; agree = false;
} }
close();
} }
void UserImprove::showDetail() void UserImprove::showDetail()
{ {

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>UserImprove</string> <string>用户体验改善计划</string>
</property> </property>
<widget class="QPushButton" name="detail"> <widget class="QPushButton" name="detail">
<property name="geometry"> <property name="geometry">