完成导航条,尚未Debug
|
@ -3,3 +3,11 @@ cmake-build-debug/
|
|||
cmake-build-release/
|
||||
OfficeAssistant_msvc/Debug/
|
||||
OfficeAssistant_msvc/Release/
|
||||
Debug/
|
||||
Release/
|
||||
OfficeAssistant_msvc/GeneratedFiles
|
||||
OfficeAssistant_msvc.VC.VC.opendb
|
||||
OfficeAssistant_msvc.VC.db
|
||||
OfficeAssistant_msvc.v12.suo
|
||||
OfficeAssistant_msvc.sdf
|
||||
.vs/
|
|
@ -3,18 +3,19 @@
|
|||
//
|
||||
#define TEXT_SIZE 7
|
||||
#include "MyButton.h"
|
||||
MyButton::MyButton(QString logo,QString text,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) {
|
||||
MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) {
|
||||
this->buttons=buttons;
|
||||
this->width2=width;
|
||||
this->height2=height;
|
||||
this->text=text;
|
||||
this->logo=new QImage;
|
||||
this->logo->load(logo);
|
||||
this->text=buttonStruct.text;
|
||||
this->logo=buttonStruct.image;
|
||||
this->logo_cover = buttonStruct.image_cover;
|
||||
this->setStyleSheet("background-color:#333332;/*border:none;*/");
|
||||
}
|
||||
|
||||
MyButton::~MyButton() {
|
||||
delete logo;
|
||||
delete logo_cover;
|
||||
}
|
||||
|
||||
void MyButton::paintEvent(QPaintEvent *e) {
|
||||
|
|
|
@ -11,10 +11,11 @@
|
|||
#include <QtSvg/QSvgWidget>
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#include "globalvariables.h"
|
||||
#include "buttonstruct.h"
|
||||
|
||||
class MyButton: public QPushButton{
|
||||
public:
|
||||
MyButton(QString logo,QString text,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr);
|
||||
MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr);
|
||||
~MyButton() override;
|
||||
QString getText(){
|
||||
return text;
|
||||
|
@ -47,10 +48,8 @@ protected:
|
|||
private:
|
||||
QList<MyButton *> *buttons;
|
||||
QImage *logo;
|
||||
QLabel *logo_label;
|
||||
QLabel *text_label;
|
||||
QImage *logo_cover;
|
||||
QVBoxLayout *layout;
|
||||
QPixmap* logo_pixmap;
|
||||
QString text;
|
||||
int width2;
|
||||
int height2;
|
||||
|
|
|
@ -57,6 +57,16 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)\$(Configuration);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)\$(Configuration);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="Configuration">
|
||||
<ClCompile>
|
||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||
|
@ -94,7 +104,7 @@
|
|||
<QtMoc Include="mainwindow.h" />
|
||||
<QtMoc Include="mainscreen.h" />
|
||||
<ClInclude Include="MyButton.h" />
|
||||
<ClInclude Include="netio.h" />
|
||||
<QtMoc Include="netio.h" />
|
||||
<QtMoc Include="navbar.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
<ClInclude Include="MyButton.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="netio.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="buttonstruct.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -57,6 +54,9 @@
|
|||
<QtMoc Include="mainwindowlayout.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
<QtMoc Include="netio.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</QtMoc>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<UI version=QString::fromLocal8bit(".*") >
|
||||
<class>Buttons</class>
|
||||
<widget class=QString::fromLocal8bit(".*") >
|
||||
<property name=QString::fromLocal8bit(".*") >
|
||||
<string notr=QString::fromLocal8bit(".*")>Buttons</string>
|
||||
</property>
|
||||
<property name=QString::fromLocal8bit(".*") >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name=QString::fromLocal8bit(".*") >
|
||||
<string>Buttons</string>
|
||||
</property>
|
||||
</widget>
|
||||
<layoutDefault spacing=QString::fromLocal8bit(".*") />
|
||||
<pixmapfunction></pixmapfunction>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</UI>
|
|
@ -5,9 +5,11 @@
|
|||
#ifndef OFFICEASSISTANT_BUTTONSTRUCT_H
|
||||
#define OFFICEASSISTANT_BUTTONSTRUCT_H
|
||||
#include <QString>
|
||||
#include <QImage>
|
||||
typedef struct taButtonStruct{
|
||||
int index;
|
||||
QString logo;
|
||||
QImage *image;
|
||||
QImage *image_cover;
|
||||
QString text;
|
||||
QString url;
|
||||
}ButtonStruct;
|
||||
#endif //OFFICEASSISTANT_BUTTONSTRUCT_H
|
||||
|
|
|
@ -7,4 +7,6 @@
|
|||
#define CONFIG_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/config"
|
||||
#define OP_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/op"
|
||||
#define DEVICE_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/device"
|
||||
#define BASE_URL "http://softapi.1.y01.cn/"
|
||||
#define DEFAULT_FILE "/config/default.kmd"
|
||||
#endif //OFFICEASSISTANT_CONFIG_H
|
||||
|
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.8 KiB |
|
@ -12,24 +12,10 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
|
|||
QWidget(parent), ui(new Ui::MainWindowLayout) {
|
||||
ui->setupUi(this);
|
||||
layout=new QVBoxLayout(this);
|
||||
buttons=new ButtonStruct[4];
|
||||
buttons[0].text="主页";
|
||||
buttons[0].logo=".\\images\\home.png";
|
||||
buttons[0].index=0;
|
||||
buttons[1].text="我的网址";
|
||||
buttons[1].logo=".\\images\\address.png";
|
||||
buttons[1].index=1;
|
||||
buttons[2].text="我的资产";
|
||||
buttons[2].logo=".\\images\\money.png";
|
||||
buttons[2].index=2;
|
||||
buttons[3].text="个人中心";
|
||||
buttons[3].logo=".\\images\\personalcenter.png";
|
||||
buttons[3].index=3;
|
||||
for(auto i=0;i<4;i++) {
|
||||
list << &buttons[i];
|
||||
}
|
||||
this->setLayout(nullptr);
|
||||
navBar=new NavBar(list,this);
|
||||
ConfigRequest *configRequest = new ConfigRequest;
|
||||
ConfigResponse *configResponse = new ConfigResponse;
|
||||
configRequest->sendRequest(configResponse);
|
||||
navBar=new NavBar(configResponse,this);
|
||||
mainScreen=new MainScreen();
|
||||
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
|
||||
//navBar->setSizePolicy(sizePolicy);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include "navbar.h"
|
||||
#include "mainscreen.h"
|
||||
|
||||
#include "netio.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindowLayout; }
|
||||
|
|
|
@ -6,34 +6,42 @@
|
|||
|
||||
#include "navbar.h"
|
||||
#include "ui_NavBar.h"
|
||||
|
||||
|
||||
NavBar::NavBar(QList<ButtonStruct *> &buttonNames,QWidget *parent) :
|
||||
#include "config.h"
|
||||
#include <QTimer>
|
||||
#include <QtSvg/QtSvg>
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "Qt5Svgd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "QtSvg.lib")
|
||||
#endif
|
||||
NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::NavBar) {
|
||||
ui->setupUi(this);
|
||||
layout=new QHBoxLayout();
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
this->setMinimumHeight(48);
|
||||
this->setMaximumHeight(200);
|
||||
for(auto buttonName : buttonNames){
|
||||
MyButton *button=new MyButton(buttonName->logo,buttonName->text,height(),height(),&buttons);
|
||||
QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
|
||||
button->setSizePolicy(sizePolicy);
|
||||
layout->addWidget(button);
|
||||
buttons<<button;
|
||||
if (configResponse->succeed) {
|
||||
getLogoFromInternet(configResponse);
|
||||
}
|
||||
|
||||
layout->setAlignment(Qt::AlignHCenter);
|
||||
layout->setSpacing(0);
|
||||
this->setLayout(layout);
|
||||
|
||||
else {
|
||||
getLogoFromLocal();
|
||||
};
|
||||
int n = buttonStructs.length();
|
||||
int x = (width() - height()*n) / 2;
|
||||
for (auto buttonStruct : buttonStructs) {
|
||||
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons);
|
||||
myButton->setGeometry(x, 0, height(), height());
|
||||
x += height();
|
||||
buttons << myButton;
|
||||
}
|
||||
this->setLayout(nullptr);
|
||||
}
|
||||
|
||||
NavBar::~NavBar() {
|
||||
for (auto buttonStruct : buttonStructs) {
|
||||
delete buttonStruct.image;
|
||||
delete buttonStruct.image_cover;
|
||||
}
|
||||
for(auto button : buttons){
|
||||
delete button;
|
||||
}
|
||||
delete layout;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -44,14 +52,137 @@ void NavBar::paintEvent(QPaintEvent *event) {
|
|||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
QRectF rect(0, 0, this->width(), this->height());
|
||||
painter.fillRect(rect, QColor("#333332"));
|
||||
painter.fillRect(rect, qColor);
|
||||
|
||||
QRectF rect2(0, 0, this->width()/5, this->height());
|
||||
painter.drawImage(rect2, *logo);
|
||||
|
||||
}
|
||||
void NavBar::resizeEvent(QResizeEvent *event) {
|
||||
QWidget::resizeEvent(event);
|
||||
int n = buttonStructs.length();
|
||||
int x = (width() - height()*n) / 2;
|
||||
for(auto button:buttons){
|
||||
button->setSize(event->size().height(),event->size().height(),event->size().height(),event->size().height());
|
||||
button->resize(event->size().height(),event->size().height());
|
||||
button->setGeometry(x, 0, event->size().height(), event->size().height());
|
||||
x += event->size().height();
|
||||
button->update();
|
||||
}
|
||||
}
|
||||
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
|
||||
qColor.setNamedColor(configResponse->basic.backgroud_color);
|
||||
QUrl url_logo(QString(BASE_URL) + configResponse->basic.logo_url);
|
||||
QNetworkRequest *request_logo = new QNetworkRequest(url_logo);
|
||||
manager = new QNetworkAccessManager;
|
||||
reply = manager->get(*request_logo);
|
||||
QTimer timer;
|
||||
timer.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit);
|
||||
connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload);
|
||||
timer.stop();
|
||||
delete request_logo;
|
||||
if (downloadSuccess == true) {
|
||||
*buffer = reply->readAll();
|
||||
QSvgRenderer *render_logo = new QSvgRenderer(*buffer);
|
||||
logo = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QPainter painter_logo(logo);
|
||||
render_logo->render(&painter_logo);
|
||||
buffer->clear();
|
||||
for (auto button : *configResponse->menus) {
|
||||
QUrl url_image(QString(BASE_URL) + button.img);
|
||||
QNetworkRequest *request_image = new QNetworkRequest(url_image);
|
||||
reply = manager->get(*request_image);
|
||||
QTimer timer;
|
||||
timer.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload);
|
||||
if (!downloadSuccess) {
|
||||
break;
|
||||
}
|
||||
*buffer = reply->readAll();
|
||||
QSvgRenderer *render_image = new QSvgRenderer(*buffer);
|
||||
QImage *image = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QPainter painter_image(image);
|
||||
render_image->render(&painter_image);
|
||||
|
||||
QUrl url_image_cover(QString(BASE_URL) + button.img_cover);
|
||||
QNetworkRequest *request_image_cover = new QNetworkRequest(url_image_cover);
|
||||
reply = manager->get(*request_image_cover);
|
||||
timer.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload);
|
||||
if (!downloadSuccess) {
|
||||
break;
|
||||
}
|
||||
*buffer = reply->readAll();
|
||||
QSvgRenderer *render_image_cover = new QSvgRenderer(*buffer);
|
||||
QImage *image_cover = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QPainter painter_image_cover(image_cover);
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
ButtonStruct buttonStruct;
|
||||
buttonStruct.image = image;
|
||||
buttonStruct.image_cover = image_cover;
|
||||
buttonStruct.text = button.title;
|
||||
buttonStruct.url = button.url;
|
||||
buttonStructs << buttonStruct;
|
||||
delete request_image;
|
||||
delete render_image;
|
||||
delete request_image_cover;
|
||||
delete render_image_cover;
|
||||
}
|
||||
}
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
|
||||
}
|
||||
void NavBar::storeToBuffer() {
|
||||
buffer = new QByteArray;
|
||||
|
||||
}
|
||||
void NavBar::cancelDownload() {
|
||||
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.quit();
|
||||
reply->abort();
|
||||
downloadSuccess = false;
|
||||
}
|
||||
|
||||
void NavBar::getLogoFromLocal() {
|
||||
QString dir = QApplication::applicationDirPath();
|
||||
QFile file(dir + DEFAULT_FILE);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
exit(1);
|
||||
}
|
||||
buffer->clear();
|
||||
*buffer = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument *qJsonDocument = new QJsonDocument;
|
||||
*qJsonDocument = QJsonDocument::fromJson(*buffer);
|
||||
QJsonObject *obj_root = new QJsonObject;
|
||||
if (qJsonDocument->isObject()) {
|
||||
*obj_root = qJsonDocument->object();
|
||||
delete qJsonDocument;
|
||||
QString logo_path = obj_root->value("basic").toObject().value("logo").toString();
|
||||
logo = new QImage(logo_path);
|
||||
QString color= obj_root->value("basic").toObject().value("backgroud_color").toString();
|
||||
qColor.setNamedColor(color);
|
||||
QJsonArray *array = new QJsonArray;
|
||||
*array = obj_root->value("menu").toArray();
|
||||
for (auto obj : *array) {
|
||||
ButtonStruct buttonStruct;
|
||||
buttonStruct.text = obj.toObject().value("title").toString();
|
||||
buttonStruct.url = QString(BASE_URL)+obj.toObject().value("url").toString();
|
||||
buttonStruct.image = new QImage(obj.toObject().value("img").toString());
|
||||
buttonStruct.image_cover = new QImage(obj.toObject().value("img_cover").toString());
|
||||
buttonStructs << buttonStruct;
|
||||
}
|
||||
delete array;
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
delete obj_root;
|
||||
exit(1);
|
||||
}
|
||||
delete obj_root;
|
||||
|
||||
}
|
|
@ -8,8 +8,14 @@
|
|||
#include <QWidget>
|
||||
#include <QList>
|
||||
#include <map>
|
||||
#include "netio.h"
|
||||
#include "MyButton.h"
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
#include "buttonstruct.h"
|
||||
#include <QtNetwork/QtNetwork>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class NavBar; }
|
||||
|
@ -19,7 +25,7 @@ class NavBar : public QWidget {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NavBar(QList<ButtonStruct *> &buttonNames,QWidget *parent = nullptr);
|
||||
NavBar(ConfigResponse *configResponse,QWidget *parent = nullptr);
|
||||
|
||||
~NavBar() override;
|
||||
protected:
|
||||
|
@ -30,10 +36,22 @@ protected:
|
|||
|
||||
private:
|
||||
Ui::NavBar *ui;
|
||||
QHBoxLayout *layout;
|
||||
QColor qColor;
|
||||
QList<MyButton *> buttons;
|
||||
QList<ButtonStruct> buttonStructs;
|
||||
QByteArray *buffer;
|
||||
int width2;
|
||||
int height2;
|
||||
QNetworkAccessManager *manager;
|
||||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
QImage *logo;
|
||||
bool downloadSuccess=true;
|
||||
void getLogoFromInternet(ConfigResponse *configResponse);
|
||||
void getLogoFromLocal();
|
||||
private slots:
|
||||
void storeToBuffer();
|
||||
void cancelDownload();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -5,29 +5,29 @@
|
|||
#include <QProcess>
|
||||
#include <QScreen>
|
||||
#include <QCryptographicHash>
|
||||
#include <wbemidl.h>
|
||||
#include "netio.h"
|
||||
#include "config.h"
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
#include <QtNetwork/QNetworkRequest>
|
||||
#include <QEventLoop>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QTimer>
|
||||
#include <cstring>
|
||||
#include <QJsonArray>
|
||||
#include <QSysInfo>
|
||||
#include <QStorageInfo>
|
||||
#include <comutil.h>
|
||||
#include <wbemidl.h>
|
||||
#include <iostream>
|
||||
#include <QGuiApplication>
|
||||
#include <wbemidl.h>
|
||||
#include <ctime>
|
||||
#pragma comment(lib, "wbemuuid.lib")
|
||||
#ifdef _DEBUG
|
||||
#pragma comment(lib, "Qt5Networkd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "Qt5Network.lib")
|
||||
#endif
|
||||
#pragma comment(lib,"comsuppw.lib")
|
||||
//读取注册表获取MachineUUID
|
||||
//读取注册表获取MachineUUID
|
||||
inline QString getMachineGUID(){
|
||||
HKEY hKey;
|
||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
|
||||
|
@ -44,64 +44,64 @@ RequestBodyBase::RequestBodyBase(){
|
|||
wchar_t unix_time[65]={0};
|
||||
wsprintf(unix_time,L"%ld",std::time(0));
|
||||
QString request_id=QString::fromWCharArray(unix_time);
|
||||
//打开配置文件
|
||||
//打开配置文件
|
||||
QFile *infFile=new QFile(".\\config\\information.cfg");
|
||||
if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){
|
||||
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
|
||||
QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
|
||||
delete infFile;
|
||||
exit(1);
|
||||
}
|
||||
//读取配置文件
|
||||
//读取配置文件
|
||||
QByteArray bytes;
|
||||
bytes=infFile->readAll();
|
||||
infFile->close();
|
||||
delete infFile;
|
||||
//转化位json
|
||||
//转化为json
|
||||
qJsonDocument=QJsonDocument::fromJson(bytes);
|
||||
if(qJsonDocument.isObject()){
|
||||
//读取数据,写入对应字段
|
||||
//读取数据,写入对应字段
|
||||
QJsonObject obj_root=qJsonDocument.object();
|
||||
if(obj_root.value("product")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
}
|
||||
product=obj_root.value("product").toString();
|
||||
if(obj_root.value("partner_id")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
}
|
||||
partner_id=obj_root.value("partner_id").toString();
|
||||
if(obj_root.value("release")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
}
|
||||
release=obj_root.value("release").toString();
|
||||
if(obj_root.value("version")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
}
|
||||
version=obj_root.value("version").toString();
|
||||
if(obj_root.value("device_id")==QJsonValue::Undefined){
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
|
||||
exit(1);
|
||||
}
|
||||
device_id=obj_root.value("device_id").toString();
|
||||
}else{
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr,"错误","配置文件损坏");
|
||||
exit(1);
|
||||
}
|
||||
//获取操作系统版本
|
||||
//获取操作系统版本
|
||||
os="Windows";
|
||||
OSVERSIONINFOEX os;
|
||||
os.dwOSVersionInfoSize=sizeof(os);
|
||||
GetVersionEx((OSVERSIONINFO *)&os);
|
||||
switch(os.dwMajorVersion){//主版本号
|
||||
case 5: //不兼容Windows 2000,因此5.x一定是Windows XP
|
||||
switch(os.dwMajorVersion){//主版本号
|
||||
case 5: //不兼容Windows 2000,因此5.x一定是Windows XP
|
||||
os_version="Windows XP";
|
||||
break;
|
||||
case 6:
|
||||
switch(os.dwMinorVersion){ //次版本号
|
||||
switch(os.dwMinorVersion){ //次版本号
|
||||
case 0:
|
||||
os_version="Windows Vista or Windows Server 2008";
|
||||
break;
|
||||
|
@ -117,39 +117,39 @@ RequestBodyBase::RequestBodyBase(){
|
|||
default:
|
||||
os_version="Unknown";
|
||||
}
|
||||
case 10: //这几个系统都是10.0
|
||||
case 10: //这几个系统都是10.0
|
||||
os_version="Windows 10, Windows 11, Windows Server 2016 or Windows Server 2019";
|
||||
break;
|
||||
default:
|
||||
os_version="Unknown";
|
||||
}
|
||||
//如果device_id是空值
|
||||
//如果device_id是空值
|
||||
if(device_id.isEmpty()){
|
||||
//读取MachineGUID并取MD5作为device_id
|
||||
//读取MachineGUID并取MD5作为device_id
|
||||
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
|
||||
device_id=hash.toHex();
|
||||
infFile=new QFile(".\\config\\information.cfg");
|
||||
if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr,"错误","无法覆写配置文件");
|
||||
//处理错误
|
||||
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法覆写配置文件"));
|
||||
infFile->close();
|
||||
delete infFile;
|
||||
exit(1);
|
||||
}
|
||||
//加入json序列
|
||||
//加入json序列
|
||||
QJsonValue value=device_id;
|
||||
QJsonObject obj_root;
|
||||
obj_root.insert("device_id",value);
|
||||
qJsonDocument.setObject(obj_root);
|
||||
//写入配置文件
|
||||
//写入配置文件
|
||||
infFile->write(qJsonDocument.toJson());
|
||||
//关闭文件;
|
||||
//关闭文件;
|
||||
infFile->close();
|
||||
delete infFile;
|
||||
}
|
||||
QJsonValue requestId_json=QJsonValue(request_id);
|
||||
QJsonObject obj_root;
|
||||
//插入request_id
|
||||
//插入request_id
|
||||
obj_root.insert("request_id",requestId_json);
|
||||
qJsonDocument.setObject(obj_root);
|
||||
}
|
||||
|
@ -157,86 +157,90 @@ RequestBodyBase::RequestBodyBase(){
|
|||
|
||||
|
||||
void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer = new QTimer(this);
|
||||
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
|
||||
/* QFile *file=new QFile(".\\config\\config.cfg");
|
||||
if(!file->open(QIODevice::ReadOnly|QIODevice::Text)){
|
||||
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
|
||||
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
|
||||
file->close();
|
||||
delete file;
|
||||
exit(1);
|
||||
}*/
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
//HTTP请求
|
||||
//请求头
|
||||
requestInfo.setUrl(QUrl(CONFIG_URL));
|
||||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
QEventLoop eventLoop;
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
delete httpMgr;
|
||||
QJsonDocument result;
|
||||
configResponse=new ConfigResponse;
|
||||
memset(configResponse,0,sizeof(*configResponse));
|
||||
//如果没有错误
|
||||
//如果没有错误
|
||||
if(reply->error() == QNetworkReply::NoError) {
|
||||
result = QJsonDocument::fromJson(reply->readAll());
|
||||
}else{
|
||||
//如果有错误
|
||||
//如果有错误
|
||||
configResponse->succeed=false;
|
||||
delete reply;
|
||||
delete timer;
|
||||
return;
|
||||
}
|
||||
//如果数据完整
|
||||
//如果数据完整
|
||||
if(result.isObject()){
|
||||
QJsonObject obj_root=result.object();
|
||||
QJsonArray array;
|
||||
array = obj_root.value("menu").toArray();
|
||||
configResponse->menu=new Menu[array.count()];
|
||||
configResponse->menus=new QList<Menu>;
|
||||
auto i=0;
|
||||
for(auto value:array){
|
||||
QJsonObject object=value.toObject();
|
||||
configResponse->menu[i].img=object.value("img").toString();
|
||||
configResponse->menu[i].img_cover=object.value("img_cover").toString();
|
||||
configResponse->menu[i].title=object.value("title").toString();
|
||||
configResponse->menu[i].func=object.value("func").toString();
|
||||
configResponse->menu[i].url=object.value("url").toString();
|
||||
Menu menu;
|
||||
menu.img=object.value("img").toString();
|
||||
menu.img_cover=object.value("img_cover").toString();
|
||||
menu.title=object.value("title").toString();
|
||||
menu.func=object.value("func").toString();
|
||||
menu.url=object.value("url").toString();
|
||||
*configResponse->menus << menu;
|
||||
i++;
|
||||
}
|
||||
}else{
|
||||
//数据不完整
|
||||
//数据不完整
|
||||
configResponse->succeed=false;
|
||||
delete reply;
|
||||
delete timer;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RequestBodyBase::cancelDownload() {
|
||||
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
eventLoop.quit();
|
||||
reply->abort();
|
||||
}
|
||||
void RequestBodyBase::sendRequest() {
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer = new QTimer(this);
|
||||
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
//HTTP请求
|
||||
//请求头
|
||||
requestInfo.setUrl(QUrl(OP_URL));
|
||||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
QEventLoop eventLoop;
|
||||
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply,&QNetworkReply::finished, this, &RequestBodyBase::cancelDownload);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
delete timer;
|
||||
delete httpMgr;
|
||||
|
@ -247,15 +251,15 @@ void RequestBodyBase::sendRequest() {
|
|||
DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
||||
//CPU
|
||||
QString cpu = QSysInfo::currentCpuArchitecture();
|
||||
//内存大小
|
||||
//内存大小
|
||||
MEMORYSTATUSEX status;
|
||||
status.dwLength = sizeof(status);
|
||||
GlobalMemoryStatusEx(&status);
|
||||
int ram = status.ullTotalPhys / 1024 / 1024;
|
||||
//硬盘大小
|
||||
//硬盘大小
|
||||
QStorageInfo storage = QStorageInfo::root();
|
||||
int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024);
|
||||
//显卡型号
|
||||
//显卡型号
|
||||
QStringList gpus;
|
||||
BOOL success;
|
||||
DWORD deviceIndex = 0;
|
||||
|
@ -283,9 +287,9 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
|||
deviceIndex++;
|
||||
displayDevice.cb = sizeof(displayDevice);
|
||||
}
|
||||
//主板型号
|
||||
//主板型号
|
||||
QString motherboard = QSysInfo::prettyProductName();
|
||||
//WMI获取网卡型号
|
||||
//WMI获取网卡型号
|
||||
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
|
||||
if (FAILED(hr)) {
|
||||
std::cerr << "Failed to initialize COM library." << std::endl;
|
||||
|
@ -392,7 +396,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
|||
|
||||
pClassObj->Release();
|
||||
}
|
||||
//WMI获取声卡型号
|
||||
//WMI获取声卡型号
|
||||
hr = pSvc->ExecQuery(
|
||||
_bstr_t("WQL"),
|
||||
_bstr_t("SELECT * FROM Win32_SoundDevice"),
|
||||
|
@ -471,8 +475,8 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
|||
DISPLAY_DEVICE d = { sizeof(DISPLAY_DEVICE) };
|
||||
::EnumDisplayDevices(NULL, 0, &d, 0);
|
||||
QString monitor=QString::fromWCharArray(d.DeviceString, wcslen(d.DeviceString));
|
||||
//发送
|
||||
//构造JSON
|
||||
//发送
|
||||
//构造JSON
|
||||
QJsonDocument *device=new QJsonDocument;
|
||||
QJsonObject *object=new QJsonObject;
|
||||
object->insert("CPU",QJsonValue(cpu));
|
||||
|
@ -510,22 +514,21 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() {
|
|||
obj_root.insert("data",QString(device->toJson()));
|
||||
delete device;
|
||||
qJsonDocument.setObject(obj_root);
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer = new QTimer(this);
|
||||
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
|
||||
QNetworkRequest requestInfo;
|
||||
//HTTP请求
|
||||
//请求头
|
||||
//HTTP请求
|
||||
//请求头
|
||||
requestInfo.setUrl(QUrl(DEVICE_URL));
|
||||
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
|
||||
//保存响应的变量
|
||||
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
QEventLoop eventLoop;
|
||||
//保存响应的变量
|
||||
reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
|
||||
//开启一个循环,直到超时或者获取到数据为止
|
||||
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
|
||||
//设置定时器防止超时
|
||||
connect(timer,&QTimer::timeout,this,&DeviceRequest::cancelDownload);
|
||||
timer->start(5000);
|
||||
//启动循环
|
||||
//启动循环
|
||||
eventLoop.exec();
|
||||
delete httpMgr;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <Windows.h>
|
||||
#include <QtNetwork/QtNetwork>
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
@ -31,10 +32,11 @@ typedef struct {
|
|||
QString title_color;
|
||||
QString title_cover_color;
|
||||
}basic;
|
||||
Menu *menu;
|
||||
QList<Menu> *menus;
|
||||
}ConfigResponse;
|
||||
|
||||
class RequestBodyBase:public QObject{
|
||||
Q_OBJECT;
|
||||
public:
|
||||
RequestBodyBase();
|
||||
virtual void sendRequest();
|
||||
|
@ -49,6 +51,11 @@ protected:
|
|||
QString release;
|
||||
QString sign;
|
||||
QJsonDocument qJsonDocument;
|
||||
QNetworkReply *reply;
|
||||
QEventLoop eventLoop;
|
||||
QTimer *timer;
|
||||
protected slots:
|
||||
void cancelDownload();
|
||||
};
|
||||
class ConfigRequest:public RequestBodyBase{
|
||||
public:
|
||||
|
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.8 KiB |