diff --git a/OfficeAssistant_msvc.VC.db b/OfficeAssistant_msvc.VC.db index ce2643c..ceaba1d 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 ed2a854..a860a69 100644 --- a/OfficeAssistant_msvc/MyButton.cpp +++ b/OfficeAssistant_msvc/MyButton.cpp @@ -15,8 +15,6 @@ MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QListheight()-6, this->width(), 5); - painter.fillRect(rect, QColor("#FFFFFF")); - } + painter.setPen(QColor("#FFFFFF")); + painter.drawImage(logo_rect, *logo_cover); + painter.drawText(text_rect, Qt::AlignCenter, text); + } + else { + painter.setPen(QColor("#FFFFFF")); + painter.drawImage(logo_rect, *logo); + painter.drawText(text_rect, Qt::AlignCenter, text); + } } QSize MyButton::sizeHint() const { diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj index c3651fd..9cd4ad5 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj @@ -76,7 +76,7 @@ MultiThreadedDebugDLL - Windows + Console true diff --git a/OfficeAssistant_msvc/config.h b/OfficeAssistant_msvc/config.h index 57a8f7e..73c9636 100644 --- a/OfficeAssistant_msvc/config.h +++ b/OfficeAssistant_msvc/config.h @@ -4,9 +4,9 @@ #ifndef OFFICEASSISTANT_CONFIG_H #define OFFICEASSISTANT_CONFIG_H -#define CONFIG_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/config" -#define OP_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/op" -#define DEVICE_URL "http://apisoft.s103.y01.cn/addons/Kmdsoft/Index/device" -#define BASE_URL "http://apisoft.s103.y01.cn/" -#define DEFAULT_FILE "/config/default.kmd" +#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config" +#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op" +#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" +#define BASE_URL "http://softapi.s103.y01.cn/" +#define DEFAULT_FILE "/config/default_navbar.kmd" #endif //OFFICEASSISTANT_CONFIG_H diff --git a/OfficeAssistant_msvc/mainwindowlayout.cpp b/OfficeAssistant_msvc/mainwindowlayout.cpp index 455f711..1e15099 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.cpp +++ b/OfficeAssistant_msvc/mainwindowlayout.cpp @@ -11,6 +11,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindowLayout) { ui->setupUi(this); layout=new QVBoxLayout(this); + mainWindowLayout = this; ConfigRequest *configRequest = new ConfigRequest; ConfigResponse *configResponse = new ConfigResponse; configRequest->sendRequest(configResponse); @@ -26,7 +27,7 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) : MainWindowLayout::~MainWindowLayout() { - delete[] list[0]; + //delete[] list[0]; delete navBar; //delete layout; delete ui; diff --git a/OfficeAssistant_msvc/mainwindowlayout.h b/OfficeAssistant_msvc/mainwindowlayout.h index ff506e9..e442a36 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.h +++ b/OfficeAssistant_msvc/mainwindowlayout.h @@ -33,7 +33,7 @@ protected: private: Ui::MainWindowLayout *ui; QVBoxLayout *layout; - QList list; + //QList list; NavBar *navBar; ButtonStruct *buttons; MainScreen *mainScreen; diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index d01f4e6..a67628a 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -19,12 +19,13 @@ NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) : QWidget(parent), ui(new Ui::NavBar) { ui->setupUi(this); - if (configResponse->succeed) { + buffer = new QByteArray; + if (configResponse->succeed&&configResponse->menus.empty()!=true) { getLogoFromInternet(configResponse); } else { getLogoFromLocal(); - }; + } int n = buttonStructs.length(); int x = (width() - height()*n) / 2; for (auto buttonStruct : buttonStructs) { @@ -83,6 +84,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit); connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload); timer.stop(); + buffer = new QByteArray; delete request_logo; if (downloadSuccess == true) { *buffer = reply->readAll(); @@ -91,7 +93,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { QPainter painter_logo(logo); render_logo->render(&painter_logo); buffer->clear(); - for (auto button : *configResponse->menus) { + 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); diff --git a/OfficeAssistant_msvc/netio.cpp b/OfficeAssistant_msvc/netio.cpp index 87c5643..581a310 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #pragma comment(lib, "wbemuuid.lib") #ifdef _DEBUG #pragma comment(lib, "Qt5Networkd.lib") @@ -47,7 +48,7 @@ RequestBodyBase::RequestBodyBase(){ QString request_id=QString::fromWCharArray(unix_time); //打开配置文件 QString dir=QApplication::applicationDirPath(); - QFile *infFile=new QFile(dir+"config/information.kmd"); + QFile *infFile=new QFile(dir+"/config/information.kmd"); if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){ QMessageBox::critical(nullptr,QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); delete infFile; @@ -83,18 +84,14 @@ RequestBodyBase::RequestBodyBase(){ exit(1); } version=obj_root.value("version").toString(); - if(obj_root.value("device_id")==QJsonValue::Undefined){ - QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); - exit(1); - } device_id=obj_root.value("device_id").toString(); }else{ //处理错误 - QMessageBox::warning(nullptr,"错误","配置文件损坏"); + QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); exit(1); } //获取操作系统版本 - os="Windows"; + this->os="Windows"; OSVERSIONINFOEX os; os.dwOSVersionInfoSize=sizeof(os); GetVersionEx((OSVERSIONINFO *)&os); @@ -130,7 +127,7 @@ RequestBodyBase::RequestBodyBase(){ //读取MachineGUID并取MD5作为device_id QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5); device_id=hash.toHex(); - infFile=new QFile(".\\config\\information.kmd"); + infFile=new QFile(dir + "/config/information.kmd"); if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){ //处理错误 QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法覆写配置文件")); @@ -140,7 +137,7 @@ RequestBodyBase::RequestBodyBase(){ } //加入json序列 QJsonValue value=device_id; - QJsonObject obj_root; + QJsonObject obj_root = qJsonDocument.object(); obj_root.insert("device_id",value); qJsonDocument.setObject(obj_root); //写入配置文件 @@ -149,25 +146,24 @@ RequestBodyBase::RequestBodyBase(){ infFile->close(); delete infFile; } + QJsonValue os_json(this->os); + QJsonValue os_version_json(this->os_version); + QJsonValue sign_json(QString("123456789890")); QJsonValue requestId_json=QJsonValue(request_id); - QJsonObject obj_root; + QJsonObject obj_root=qJsonDocument.object(); //插入request_id obj_root.insert("request_id",requestId_json); + obj_root.insert("os", os_json); + obj_root.insert("os_version", os_version_json); + obj_root.insert("sign", sign_json); qJsonDocument.setObject(obj_root); } void ConfigRequest::sendRequest(ConfigResponse *configResponse) { - 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,"错误","无法打开配置文件"); - file->close(); - delete file; - exit(1); - }*/ QNetworkRequest requestInfo; //HTTP请求 //请求头 @@ -175,33 +171,40 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json")); //保存响应的变量 reply = httpMgr->post(requestInfo,qJsonDocument.toJson()); + qDebug() << qJsonDocument.toJson(); //开启一个循环,直到超时或者获取到数据为止 connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit); //设置定时器防止超时 connect(timer,&QTimer::timeout,this,&ConfigRequest::cancelDownload); timer->start(5000); //启动循环 - eventLoop.exec(); - delete httpMgr; + eventLoop.exec(); + timer->stop(); + //delete httpMgr; QJsonDocument result; configResponse=new ConfigResponse; - memset(configResponse,0,sizeof(*configResponse)); + configResponse->succeed = false; + //memset(configResponse,0,sizeof(*configResponse)); + auto error = reply->error(); //如果没有错误 if(reply->error() == QNetworkReply::NoError) { result = QJsonDocument::fromJson(reply->readAll()); }else{ //如果有错误 configResponse->succeed=false; - delete reply; + //delete reply; delete timer; + delete httpMgr; return; } + qDebug() << result.toJson(); + //如果数据完整 if(result.isObject()){ QJsonObject obj_root=result.object(); QJsonArray array; array = obj_root.value("menu").toArray(); - configResponse->menus=new QList; + auto i=0; for(auto value:array){ QJsonObject object=value.toObject(); @@ -211,16 +214,18 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { menu.title=object.value("title").toString(); menu.func=object.value("func").toString(); menu.url=object.value("url").toString(); - *configResponse->menus << menu; + configResponse->menus << menu; i++; } }else{ //数据不完整 configResponse->succeed=false; - delete reply; + //delete reply; delete timer; + delete httpMgr; return; } + delete httpMgr; } void RequestBodyBase::cancelDownload() { disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); diff --git a/OfficeAssistant_msvc/netio.h b/OfficeAssistant_msvc/netio.h index 699da3a..e4d6657 100644 --- a/OfficeAssistant_msvc/netio.h +++ b/OfficeAssistant_msvc/netio.h @@ -32,7 +32,7 @@ typedef struct { QString title_color; QString title_cover_color; }basic; - QList *menus; + QList menus; }ConfigResponse; class RequestBodyBase:public QObject{