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