diff --git a/.gitignore b/.gitignore index 231f5c5..b0326d9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,12 @@ cmake-build-debug/ cmake-build-release/ OfficeAssistant_msvc/Debug/ -OfficeAssistant_msvc/Release/ \ No newline at end of file +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/ \ No newline at end of file diff --git a/OfficeAssistant_msvc.VC.db b/OfficeAssistant_msvc.VC.db index c6be9f2..c35a662 100644 Binary files a/OfficeAssistant_msvc.VC.db and b/OfficeAssistant_msvc.VC.db differ diff --git a/OfficeAssistant_msvc/MyButton.cpp b/OfficeAssistant_msvc/MyButton.cpp index 83aacff..7fe1c88 100644 --- a/OfficeAssistant_msvc/MyButton.cpp +++ b/OfficeAssistant_msvc/MyButton.cpp @@ -3,18 +3,19 @@ // #define TEXT_SIZE 7 #include "MyButton.h" -MyButton::MyButton(QString logo,QString text,int width,int height,QList *buttons,QWidget *parent) : QPushButton(parent) { +MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList *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) { diff --git a/OfficeAssistant_msvc/MyButton.h b/OfficeAssistant_msvc/MyButton.h index 3b31add..a3ff14d 100644 --- a/OfficeAssistant_msvc/MyButton.h +++ b/OfficeAssistant_msvc/MyButton.h @@ -11,10 +11,11 @@ #include #include #include "globalvariables.h" +#include "buttonstruct.h" class MyButton: public QPushButton{ public: - MyButton(QString logo,QString text,int width,int height,QList *buttons,QWidget *parent=nullptr); + MyButton(ButtonStruct &buttonStruct,int width,int height,QList *buttons,QWidget *parent=nullptr); ~MyButton() override; QString getText(){ return text; @@ -47,10 +48,8 @@ protected: private: QList *buttons; QImage *logo; - QLabel *logo_label; - QLabel *text_label; + QImage *logo_cover; QVBoxLayout *layout; - QPixmap* logo_pixmap; QString text; int width2; int height2; diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj index 7dcbc87..922bfad 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj @@ -57,6 +57,16 @@ + + + $(ProjectDir)\$(Configuration);%(AdditionalIncludeDirectories) + + + + + $(ProjectDir)\$(Configuration);%(AdditionalIncludeDirectories) + + true @@ -94,7 +104,7 @@ - + diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters index 4b14a04..7812fde 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters @@ -31,9 +31,6 @@ Header Files - - Header Files - Header Files @@ -57,6 +54,9 @@ Header Files + + Header Files + diff --git a/OfficeAssistant_msvc/buttons.ui b/OfficeAssistant_msvc/buttons.ui new file mode 100644 index 0000000..8efb53e --- /dev/null +++ b/OfficeAssistant_msvc/buttons.ui @@ -0,0 +1,23 @@ + + Buttons + + + Buttons + + + + 0 + 0 + 400 + 300 + + + + Buttons + + + + + + + diff --git a/OfficeAssistant_msvc/buttonstruct.h b/OfficeAssistant_msvc/buttonstruct.h index 9f22c0f..5299ca5 100644 --- a/OfficeAssistant_msvc/buttonstruct.h +++ b/OfficeAssistant_msvc/buttonstruct.h @@ -5,9 +5,11 @@ #ifndef OFFICEASSISTANT_BUTTONSTRUCT_H #define OFFICEASSISTANT_BUTTONSTRUCT_H #include +#include typedef struct taButtonStruct{ - int index; - QString logo; - QString text; + QImage *image; + QImage *image_cover; + QString text; + QString url; }ButtonStruct; #endif //OFFICEASSISTANT_BUTTONSTRUCT_H diff --git a/OfficeAssistant_msvc/config.h b/OfficeAssistant_msvc/config.h index 8ae1882..72fedb3 100644 --- a/OfficeAssistant_msvc/config.h +++ b/OfficeAssistant_msvc/config.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 diff --git a/OfficeAssistant_msvc/images/address.png b/OfficeAssistant_msvc/images/address.png new file mode 100644 index 0000000..875b34a Binary files /dev/null and b/OfficeAssistant_msvc/images/address.png differ diff --git a/OfficeAssistant_msvc/images/close-small.png b/OfficeAssistant_msvc/images/close-small.png new file mode 100644 index 0000000..c8c864d Binary files /dev/null and b/OfficeAssistant_msvc/images/close-small.png differ diff --git a/OfficeAssistant_msvc/images/close.png b/OfficeAssistant_msvc/images/close.png new file mode 100644 index 0000000..dcc9b40 Binary files /dev/null and b/OfficeAssistant_msvc/images/close.png differ diff --git a/OfficeAssistant_msvc/images/home.png b/OfficeAssistant_msvc/images/home.png new file mode 100644 index 0000000..4b774e2 Binary files /dev/null and b/OfficeAssistant_msvc/images/home.png differ diff --git a/OfficeAssistant_msvc/images/maxsize.png b/OfficeAssistant_msvc/images/maxsize.png new file mode 100644 index 0000000..d2539ed Binary files /dev/null and b/OfficeAssistant_msvc/images/maxsize.png differ diff --git a/OfficeAssistant_msvc/images/minsize.png b/OfficeAssistant_msvc/images/minsize.png new file mode 100644 index 0000000..f08070f Binary files /dev/null and b/OfficeAssistant_msvc/images/minsize.png differ diff --git a/OfficeAssistant_msvc/images/money.png b/OfficeAssistant_msvc/images/money.png new file mode 100644 index 0000000..93c1567 Binary files /dev/null and b/OfficeAssistant_msvc/images/money.png differ diff --git a/OfficeAssistant_msvc/images/personalcenter.png b/OfficeAssistant_msvc/images/personalcenter.png new file mode 100644 index 0000000..e37d1c7 Binary files /dev/null and b/OfficeAssistant_msvc/images/personalcenter.png differ diff --git a/OfficeAssistant_msvc/mainwindowlayout.cpp b/OfficeAssistant_msvc/mainwindowlayout.cpp index 42d6e65..d0ecdfb 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.cpp +++ b/OfficeAssistant_msvc/mainwindowlayout.cpp @@ -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); diff --git a/OfficeAssistant_msvc/mainwindowlayout.h b/OfficeAssistant_msvc/mainwindowlayout.h index f1421e9..1aec9d6 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.h +++ b/OfficeAssistant_msvc/mainwindowlayout.h @@ -10,7 +10,7 @@ #include #include "navbar.h" #include "mainscreen.h" - +#include "netio.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindowLayout; } diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index 8f6fa13..318f0be 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -6,34 +6,42 @@ #include "navbar.h" #include "ui_NavBar.h" - - -NavBar::NavBar(QList &buttonNames,QWidget *parent) : +#include "config.h" +#include +#include +#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<setAlignment(Qt::AlignHCenter); - layout->setSpacing(0); - this->setLayout(layout); - + if (configResponse->succeed) { + getLogoFromInternet(configResponse); + } + 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 button : buttons){ + 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; + +} \ No newline at end of file diff --git a/OfficeAssistant_msvc/navbar.h b/OfficeAssistant_msvc/navbar.h index 941e78b..0119b08 100644 --- a/OfficeAssistant_msvc/navbar.h +++ b/OfficeAssistant_msvc/navbar.h @@ -8,8 +8,14 @@ #include #include #include +#include "netio.h" #include "MyButton.h" +#include +#include +#include #include "buttonstruct.h" +#include + QT_BEGIN_NAMESPACE namespace Ui { class NavBar; } @@ -19,7 +25,7 @@ class NavBar : public QWidget { Q_OBJECT public: - NavBar(QList &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 buttons; + QList 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(); }; diff --git a/OfficeAssistant_msvc/netio.cpp b/OfficeAssistant_msvc/netio.cpp index 2179364..4ff5cd8 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -5,29 +5,29 @@ #include #include #include +#include #include "netio.h" #include "config.h" #include #include -#include -#include #include -#include #include #include #include #include #include #include -#include #include #include -#include #include #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 20005.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; 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(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; } diff --git a/OfficeAssistant_msvc/netio.h b/OfficeAssistant_msvc/netio.h index 2d500ad..699da3a 100644 --- a/OfficeAssistant_msvc/netio.h +++ b/OfficeAssistant_msvc/netio.h @@ -11,6 +11,7 @@ #include #include #include +#include typedef struct { @@ -31,10 +32,11 @@ typedef struct { QString title_color; QString title_cover_color; }basic; - Menu *menu; + QList *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: diff --git a/images/address.png b/images/address.png new file mode 100644 index 0000000..875b34a Binary files /dev/null and b/images/address.png differ diff --git a/images/close-small.png b/images/close-small.png new file mode 100644 index 0000000..c8c864d Binary files /dev/null and b/images/close-small.png differ diff --git a/images/close.png b/images/close.png new file mode 100644 index 0000000..dcc9b40 Binary files /dev/null and b/images/close.png differ diff --git a/images/home.png b/images/home.png new file mode 100644 index 0000000..4b774e2 Binary files /dev/null and b/images/home.png differ diff --git a/images/maxsize.png b/images/maxsize.png new file mode 100644 index 0000000..d2539ed Binary files /dev/null and b/images/maxsize.png differ diff --git a/images/minsize.png b/images/minsize.png new file mode 100644 index 0000000..f08070f Binary files /dev/null and b/images/minsize.png differ diff --git a/images/money.png b/images/money.png new file mode 100644 index 0000000..93c1567 Binary files /dev/null and b/images/money.png differ diff --git a/images/personalcenter.png b/images/personalcenter.png new file mode 100644 index 0000000..e37d1c7 Binary files /dev/null and b/images/personalcenter.png differ