diff --git a/OfficeAssistant_msvc.VC.db b/OfficeAssistant_msvc.VC.db index 9cbee02..9a4d23f 100644 Binary files a/OfficeAssistant_msvc.VC.db and b/OfficeAssistant_msvc.VC.db differ diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj index a676907..407053c 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj @@ -14,16 +14,18 @@ {A49230DF-A869-4AA1-8ACA-3C7322530E46} QtVS_v304 $(MSBuildProjectDirectory)\QtMsBuild - 8.1 + 7.0 Application - v140_xp + v141_xp + Unicode Application - v140_xp + v141_xp + Unicode @@ -31,12 +33,12 @@ 5.6.3_msvc2015 - core;gui;widgets;network + core;gui;widgets;network;svg;sql;xml debug 5.6.3_msvc2015 - core;gui;widgets + core;gui;widgets;sql;svg;network;xml release @@ -60,11 +62,14 @@ $(ProjectDir)\$(Configuration);.\;%(AdditionalIncludeDirectories) + /Zc:strictStrings- %(AdditionalOptions) $(ProjectDir)\$(Configuration);.\;%(AdditionalIncludeDirectories) + stdcpp17 + /Zc:strictStrings- %(AdditionalOptions) @@ -99,10 +104,12 @@ + + @@ -121,6 +128,7 @@ + diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters index cf3df22..e432da6 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.filters @@ -22,11 +22,6 @@ ts - - - Resource Files - - Header Files @@ -69,6 +64,12 @@ Header Files + + Header Files + + + Header Files + @@ -83,9 +84,6 @@ Source Files - - Source Files - Source Files @@ -98,6 +96,12 @@ Source Files + + Source Files + + + Source Files + @@ -129,4 +133,9 @@ Resource Files + + + Resource Files + + \ No newline at end of file diff --git a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user index 493b678..a7aae0c 100644 --- a/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user +++ b/OfficeAssistant_msvc/OfficeAssistant_msvc.vcxproj.user @@ -5,9 +5,9 @@ WindowsLocalDebugger - 2023-08-03T08:03:42.8435391Z + 2023-08-06T14:26:06.9540300Z - 2023-08-03T08:03:43.2818738Z + 2023-08-08T01:58:34.1935757Z \ No newline at end of file diff --git a/OfficeAssistant_msvc/buttonstruct.h b/OfficeAssistant_msvc/buttonstruct.h index 0b45f0d..de185e2 100644 --- a/OfficeAssistant_msvc/buttonstruct.h +++ b/OfficeAssistant_msvc/buttonstruct.h @@ -1,18 +1,20 @@ -// -// Created by HW on 2023/07/26. -// - -#ifndef OFFICEASSISTANT_BUTTONSTRUCT_H -#define OFFICEASSISTANT_BUTTONSTRUCT_H -#include -#include -typedef struct taButtonStruct{ - QImage *image; - QImage *image_cover; - QString text; - QString url; - QString background_color; - QColor text_color; - QColor text_cover_color; -}ButtonStruct; -#endif //OFFICEASSISTANT_BUTTONSTRUCT_H +// +// Created by HW on 2023/07/26. +// + +#ifndef OFFICEASSISTANT_BUTTONSTRUCT_H +#define OFFICEASSISTANT_BUTTONSTRUCT_H +#include +#include +typedef struct taButtonStruct{ + QImage *image; + QImage *image_cover; + QString text; + QString orig_name; + QString url; + QString background_color; + QColor text_color; + QColor text_cover_color; + QString path; +}ButtonStruct; +#endif //OFFICEASSISTANT_BUTTONSTRUCT_H diff --git a/OfficeAssistant_msvc/config.h b/OfficeAssistant_msvc/config.h index 5fdd6e9..dd27b17 100644 --- a/OfficeAssistant_msvc/config.h +++ b/OfficeAssistant_msvc/config.h @@ -1,21 +1,22 @@ -// -// Created by HW on 2023/07/27. -// - -#ifndef OFFICEASSISTANT_CONFIG_H -#define OFFICEASSISTANT_CONFIG_H -#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" //ĬÈϵ¼º½À¸ÎļþλÖà -#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key -#define NAME "°ì¹«ÖúÊÖ" //ÖÐÎÄÃû -#define LOGO_TITLEBAR "/icon/logo_navbar.png" //±êÌâÀ¸Í¼±ê -#define ENG_NAME "OfficeAssistant" //Ó¢ÎÄÃû -#define LENG_NAME L"OfficeAssistant" //Ó¢ÎÄÃû£¨¿í×Ö·û£© -#define ADD_AUTOSTART 1 -#define ADD_SHORTCUT 2 -#define VERSION "1.0.0" //Èí¼þ°æ±¾ -#define RELEASE "20230801" //Release -#endif //OFFICEASSISTANT_CONFIG_H +// +// Created by HW on 2023/07/27. +// + +#ifndef OFFICEASSISTANT_CONFIG_H +#define OFFICEASSISTANT_CONFIG_H +#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" //ĬÈϵ¼º½À¸ÎļþλÖà +#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key +#define NAME "°ì¹«ÖúÊÖ" //ÖÐÎÄÃû +#define LOGO_TITLEBAR "/icon/logo_navbar.png" //±êÌâÀ¸Í¼±ê +#define ENG_NAME "OfficeAssistant" //Ó¢ÎÄÃû +#define LENG_NAME L"OfficeAssistant" //Ó¢ÎÄÃû£¨¿í×Ö·û£© +#define ADD_AUTOSTART 1 +#define ADD_SHORTCUT 2 +#define VERSION "1.0.0" //Èí¼þ°æ±¾ +#define RELEASE "20230801" //Release +#define SOFTWARE_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/soft" +#endif //OFFICEASSISTANT_CONFIG_H diff --git a/OfficeAssistant_msvc/exitmanager.h b/OfficeAssistant_msvc/exitmanager.h new file mode 100644 index 0000000..77261c9 --- /dev/null +++ b/OfficeAssistant_msvc/exitmanager.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +template +class AutoDeleteList +{ +public: + // Ìí¼Ó¶ÔÏó + void add(T *obj) + { + objs.append(obj); + } + + // Îö¹¹¶ÔÏóÁбí + ~AutoDeleteList() + { + qDeleteAll(objs); + } + +private: + QList objs; +}; + + +class ExitManager : public QObject +{ + Q_OBJECT +public: + // Ìí¼ÓÐèÒªÔÚÍ˳öʱ×Ô¶¯Îö¹¹µÄ¶ÔÏó + template + void add(T *obj) + { + autoDeleteList.add(obj); + } + + // Í˳öÓ¦ÓóÌÐò + void exit(int exitCode = 0) + { + + // ·¢ÉäÍ˳öÓ¦ÓóÌÐòÐźŠ+ emit exitApplication(exitCode); + } + +signals: + // Í˳öÓ¦ÓóÌÐòÐźŠ+ void exitApplication(int exitCode); + +private: + // ×Ô¶¯Îö¹¹¶ÔÏóÁбí + AutoDeleteList autoDeleteList; +}; \ No newline at end of file diff --git a/OfficeAssistant_msvc/globalvariables.h b/OfficeAssistant_msvc/globalvariables.h index 619b194..6d9f4a2 100644 --- a/OfficeAssistant_msvc/globalvariables.h +++ b/OfficeAssistant_msvc/globalvariables.h @@ -1,11 +1,13 @@ -// -// Created by HW on 2023/07/27. -// - -#ifndef OFFICEASSISTANT_GLOBALVARIABLES_H -#define OFFICEASSISTANT_GLOBALVARIABLES_H -class MainWindowLayout; -extern double scale; -extern MainWindowLayout *mainWindowLayout; -extern QString url_param; -#endif //OFFICEASSISTANT_GLOBALVARIABLES_H +// +// Created by HW on 2023/07/27. +// + +#ifndef OFFICEASSISTANT_GLOBALVARIABLES_H +#define OFFICEASSISTANT_GLOBALVARIABLES_H +#include "exitmanager.h" +class MainWindowLayout; +extern ExitManager exit_manager; +extern double scale; +extern MainWindowLayout *mainWindowLayout; +extern QString url_param; +#endif //OFFICEASSISTANT_GLOBALVARIABLES_H diff --git a/OfficeAssistant_msvc/mainwindow.cpp b/OfficeAssistant_msvc/mainwindow.cpp index 1689572..ce2ae8a 100644 --- a/OfficeAssistant_msvc/mainwindow.cpp +++ b/OfficeAssistant_msvc/mainwindow.cpp @@ -1,33 +1,34 @@ -// -// Created by HW on 2023/07/26. -// - -// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved - -#include "mainwindow.h" -#include "ui_MainWindow.h" -#include "config.h" -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); - QDesktopWidget* desktopWidget = QApplication::desktop(); - QRect deskRect = desktopWidget->availableGeometry(); - resize(deskRect.width()*0.8, deskRect.height()*0.8); - setWindowState(Qt::WindowMaximized); - mainWindowLayout=new MainWindowLayout(this); - setCentralWidget(mainWindowLayout); - setWindowTitle(QString::fromLocal8Bit(NAME)); - QString path = QApplication::applicationDirPath(); - path += LOGO_TITLEBAR; - icon = new QIcon(path); - setWindowIcon(*icon); - - -} - -MainWindow::~MainWindow() { - delete icon; - this->setCentralWidget(nullptr); - delete mainWindowLayout; - delete ui; -} +// +// Created by HW on 2023/07/26. +// + +// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved + +#include "mainwindow.h" +#include "ui_MainWindow.h" +#include "config.h" +ExitManager exit_manager; +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), ui(new Ui::MainWindow) { + ui->setupUi(this); + QDesktopWidget* desktopWidget = QApplication::desktop(); + QRect deskRect = desktopWidget->availableGeometry(); + resize(deskRect.width()*0.8, deskRect.height()*0.8); + setWindowState(Qt::WindowMaximized); + mainWindowLayout=new MainWindowLayout(this); + setCentralWidget(mainWindowLayout); + setWindowTitle(QString::fromLocal8Bit(NAME)); + QString path = QApplication::applicationDirPath(); + path += LOGO_TITLEBAR; + icon = new QIcon(path); + setWindowIcon(*icon); + + +} + +MainWindow::~MainWindow() { + delete icon; + this->setCentralWidget(nullptr); + delete mainWindowLayout; + delete ui; +} diff --git a/OfficeAssistant_msvc/mainwindow.h b/OfficeAssistant_msvc/mainwindow.h index fae4151..0c4b22a 100644 --- a/OfficeAssistant_msvc/mainwindow.h +++ b/OfficeAssistant_msvc/mainwindow.h @@ -1,33 +1,34 @@ -// -// Created by HW on 2023/07/26. -// - -#ifndef UNTITLED_MAINWINDOW_H -#define UNTITLED_MAINWINDOW_H - -#include -#include -#include "mainwindowlayout.h" -#include - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; } -QT_END_NAMESPACE - -class MainWindow : public QMainWindow { -Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = nullptr); - - ~MainWindow() override; - -private: - Ui::MainWindow *ui; - QIcon *icon; - QVBoxLayout *layout; - MainWindowLayout *mainWindowLayout; -}; - - -#endif //UNTITLED_MAINWINDOW_H +// +// Created by HW on 2023/07/26. +// + +#ifndef UNTITLED_MAINWINDOW_H +#define UNTITLED_MAINWINDOW_H + +#include +#include +#include "mainwindowlayout.h" +#include + + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow { +Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = nullptr); + + ~MainWindow() override; + +private: + Ui::MainWindow *ui; + QIcon *icon; + QVBoxLayout *layout; + MainWindowLayout *mainWindowLayout; +}; + + +#endif //UNTITLED_MAINWINDOW_H diff --git a/OfficeAssistant_msvc/mainwindowlayout.cpp b/OfficeAssistant_msvc/mainwindowlayout.cpp index 16ce6a7..01241bd 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.cpp +++ b/OfficeAssistant_msvc/mainwindowlayout.cpp @@ -1,71 +1,74 @@ -// -// Created by HW on 2023/07/26. -// - -// You may need to build the project (run Qt uic code generator) to get "ui_MainWindowLagout.h" resolved - -#include "mainwindowlayout.h" -#include "ui_MainWindowLayout.h" -#include "mysettingsdialog.h" - -MainWindowLayout::MainWindowLayout(QWidget *parent) : - QWidget(parent), ui(new Ui::MainWindowLayout) { - ui->setupUi(this); - setContentsMargins(0, 0, 0, 0); - layout=new QVBoxLayout(this); - mainWindowLayout = this; - ConfigRequest *configRequest = new ConfigRequest; - configResponse = new ConfigResponse; - configRequest->sendRequest(configResponse); - mainScreen = new MainScreen(this); - navBar=new NavBar(configResponse,mainScreen,this); - navBar->setMinimumHeight(0); - navBar->setMaximumHeight(this->height() / 8); - mainScreen->setMinimumHeight(0); - //navBar->setAttribute(Qt::WA_DeleteOnClose); - delete configRequest; - //QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed); - //navBar->setSizePolicy(sizePolicy); - //layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(navBar,1); - layout->addWidget(mainScreen,7); - layout->setMargin(0); - setLayout(layout); - connect(this,&MainWindowLayout::clickButton1,mainScreen,&MainScreen::clickButton1); -} - -MainWindowLayout::~MainWindowLayout() { - delete configResponse; - layout->removeWidget(mainScreen); - layout->removeWidget(navBar); - delete mainScreen; - //delete[] list[0]; - delete navBar; - delete layout; - delete ui; -} - -void MainWindowLayout::resizeEvent(QResizeEvent *event) { - QWidget::resizeEvent(event); - navBar->setMaximumHeight(event->size().height()/8); - //layout->setAlignment(Qt::AlignmentFlag::AlignHCenter); -} - -void MainWindowLayout::clickButton(QString text, QString url) { - QString path = QApplication::applicationDirPath(); - path += "/app/startcalc.exe"; - path.replace("/", "\\"); - if (text== QString::fromLocal8Bit("¼ÆËãÆ÷")) { - WinExec(path.toStdString().c_str(), SW_SHOW); - } - else if (text == QString::fromLocal8Bit("Èí¼þÉèÖÃ")) { - MySettingsDialog *settings = new MySettingsDialog; - settings->exec(); - delete settings; - } - else{ - emit clickButton1(text, url); - } -} - -MainWindowLayout *mainWindowLayout; +// +// Created by HW on 2023/07/26. +// + +// You may need to build the project (run Qt uic code generator) to get "ui_MainWindowLagout.h" resolved + +#include "mainwindowlayout.h" +#include "ui_MainWindowLayout.h" +#include "mysettingsdialog.h" +#include "sqlitehelper.h" +MainWindowLayout::MainWindowLayout(QWidget *parent) : + QWidget(parent), ui(new Ui::MainWindowLayout) { + ui->setupUi(this); + setContentsMargins(0, 0, 0, 0); + layout=new QVBoxLayout(this); + mainWindowLayout = this; + SQLiteHelper sqlite_helper; + QList list; + sqlite_helper.get_software(&list); + ConfigRequest *configRequest = new ConfigRequest; + configResponse = new ConfigResponse; + configRequest->sendRequest(configResponse); + mainScreen = new MainScreen(this); + navBar=new NavBar(configResponse,mainScreen,this); + navBar->setMinimumHeight(0); + navBar->setMaximumHeight(this->height() / 8); + mainScreen->setMinimumHeight(0); + //navBar->setAttribute(Qt::WA_DeleteOnClose); + delete configRequest; + //QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed); + //navBar->setSizePolicy(sizePolicy); + //layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(navBar,1); + layout->addWidget(mainScreen,7); + layout->setMargin(0); + setLayout(layout); + connect(this,&MainWindowLayout::clickButton1,mainScreen,&MainScreen::clickButton1); +} + +MainWindowLayout::~MainWindowLayout() { + delete configResponse; + layout->removeWidget(mainScreen); + layout->removeWidget(navBar); + delete mainScreen; + //delete[] list[0]; + delete navBar; + delete layout; + delete ui; +} + +void MainWindowLayout::resizeEvent(QResizeEvent *event) { + QWidget::resizeEvent(event); + navBar->setMaximumHeight(event->size().height()/8); + //layout->setAlignment(Qt::AlignmentFlag::AlignHCenter); +} + +void MainWindowLayout::clickButton(QString text, QString url) { + QString path = QApplication::applicationDirPath(); + path += "/app/startcalc.exe"; + path.replace("/", "\\"); + if (text== QString::fromLocal8Bit("¼ÆËãÆ÷")) { + WinExec(path.toStdString().c_str(), SW_SHOW); + } + else if (text == QString::fromLocal8Bit("Èí¼þÉèÖÃ")) { + MySettingsDialog *settings = new MySettingsDialog; + settings->exec(); + delete settings; + } + else{ + emit clickButton1(text, url); + } +} + +MainWindowLayout *mainWindowLayout; diff --git a/OfficeAssistant_msvc/mysettingsdialog.cpp b/OfficeAssistant_msvc/mysettingsdialog.cpp index 1888e71..f7c8081 100644 --- a/OfficeAssistant_msvc/mysettingsdialog.cpp +++ b/OfficeAssistant_msvc/mysettingsdialog.cpp @@ -1,112 +1,112 @@ -#include "mysettingsdialog.h" -#include -#include -#include "netio.h" -#include "config.h" -#include "globalvariables.h" -MySettingsDialog::MySettingsDialog(QWidget *parent) - : QDialog(parent) -{ - ui.setupUi(this); - setWindowFlags(Qt::WindowCloseButtonHint); - this->setFixedSize(width(), height()); - HKEY hRoot = HKEY_CURRENT_USER; - wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; - HKEY hKey; - DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // Èç¹û²»´æÔÚ²»´´½¨ - LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); - if (lRet != ERROR_SUCCESS) { - ui.autostart->setDisabled(true); - } - QString app = QApplication::applicationFilePath(); - app.replace("/", "\\"); - DWORD size=128+sizeof(wchar_t); - char reg[128] = { 0 }; - lRet = RegQueryValueEx(hKey, L"OfficeAssistant", NULL, NULL,(LPBYTE)reg, &size); - if (lRet==0) { - ui.autostart->setChecked(true); - } - copyButton = ui.copy; - connect(copyButton, &QPushButton::clicked, this, &MySettingsDialog::copyToCLipboard); - connect(ui.autostart, &QCheckBox::stateChanged, this, &MySettingsDialog::autoStart); - connect(ui.addshortcut, &QPushButton::clicked, this, &MySettingsDialog::createShortcut); - connect(ui.law_button, &QPushButton::clicked, this, &MySettingsDialog::law); - ui.code->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex())); - ui.version->setText(QString(VERSION) + "-" + QString(RELEASE)); -} - -MySettingsDialog::~MySettingsDialog() -{ -} - -void MySettingsDialog::autoStart(int state) -{ - if (state == Qt::Checked) { - HKEY hRoot = HKEY_CURRENT_USER; - wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; - HKEY hKey; - DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // Èç¹û²»´æÔÚ²»´´½¨ - LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); - if (lRet != ERROR_SUCCESS) { - QMessageBox::critical(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ª»úÆô¶¯Ïîʧ°Ü")); - return; - } - QString app = QApplication::applicationFilePath(); - app.replace("/", "\\"); - qDebug() << app.toStdWString().c_str(); - lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t)); - if (lRet == ERROR_SUCCESS) - { - QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ª»úÆô¶¯Ïî³É¹¦")); - } - RegCloseKey(hKey); - } - else if (state == Qt::Unchecked) { - HKEY hRoot = HKEY_CURRENT_USER; - wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; - HKEY hKey; - DWORD dwDisposition = REG_OPENED_EXISTING_KEY; - LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); - if (lRet != ERROR_SUCCESS) { - QMessageBox::critical(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("ÒƳý¿ª»úÆô¶¯Ïîʧ°Ü¡£")); - return; - } - QString app = QApplication::applicationFilePath(); - lRet = RegDeleteValue(hKey, LENG_NAME); - if (lRet == ERROR_SUCCESS) - { - QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("ÒƳý¿ª»úÆô¶¯Ïî³É¹¦¡£")); - } - RegCloseKey(hKey); - } -} - -void MySettingsDialog::law() -{ - QString path = QApplication::applicationDirPath(); - QString license = path + "/license.txt"; - license.replace("/", "\\"); - ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe" , license.toStdWString().c_str(), nullptr, SW_SHOW); -} - -void MySettingsDialog::copyToCLipboard() { - QClipboard *clip = QApplication::clipboard(); - clip->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex())); -} -void MySettingsDialog::createShortcut() { - QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); - deskTopPath = deskTopPath + QString::fromLocal8Bit("/"); - deskTopPath = deskTopPath + QString::fromLocal8Bit(NAME); - deskTopPath = deskTopPath + QString::fromLocal8Bit(".lnk"); - QString srcFile = QApplication::applicationFilePath(); - bool succeed=QFile::link(srcFile, deskTopPath); - if (succeed) { - QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ì½Ý·½Ê½³É¹¦¡£")); - } - else { - QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ì½Ý·½Ê½Ê§°Ü¡£")); - } +#include "mysettingsdialog.h" +#include +#include +#include "netio.h" +#include "config.h" +#include "globalvariables.h" +MySettingsDialog::MySettingsDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + setWindowFlags(Qt::WindowCloseButtonHint); + this->setFixedSize(width(), height()); + HKEY hRoot = HKEY_CURRENT_USER; + wchar_t *szSubKey = (wchar_t *)"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + HKEY hKey; + DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // Èç¹û²»´æÔÚ²»´´½¨ + LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, + REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); + if (lRet != ERROR_SUCCESS) { + ui.autostart->setDisabled(true); + } + QString app = QApplication::applicationFilePath(); + app.replace("/", "\\"); + DWORD size=128+sizeof(wchar_t); + char reg[128] = { 0 }; + lRet = RegQueryValueEx(hKey, L"OfficeAssistant", NULL, NULL,(LPBYTE)reg, &size); + if (lRet==0) { + ui.autostart->setChecked(true); + } + copyButton = ui.copy; + connect(copyButton, &QPushButton::clicked, this, &MySettingsDialog::copyToCLipboard); + connect(ui.autostart, &QCheckBox::stateChanged, this, &MySettingsDialog::autoStart); + connect(ui.addshortcut, &QPushButton::clicked, this, &MySettingsDialog::createShortcut); + connect(ui.law_button, &QPushButton::clicked, this, &MySettingsDialog::law); + ui.code->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex())); + ui.version->setText(QString(VERSION) + "-" + QString(RELEASE)); +} + +MySettingsDialog::~MySettingsDialog() +{ +} + +void MySettingsDialog::autoStart(int state) +{ + if (state == Qt::Checked) { + HKEY hRoot = HKEY_CURRENT_USER; + wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + HKEY hKey; + DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // Èç¹û²»´æÔÚ²»´´½¨ + LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, + REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); + if (lRet != ERROR_SUCCESS) { + QMessageBox::critical(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ª»úÆô¶¯Ïîʧ°Ü")); + return; + } + QString app = QApplication::applicationFilePath(); + app.replace("/", "\\"); + qDebug() << app.toStdWString().c_str(); + lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t)); + if (lRet == ERROR_SUCCESS) + { + QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ª»úÆô¶¯Ïî³É¹¦")); + } + RegCloseKey(hKey); + } + else if (state == Qt::Unchecked) { + HKEY hRoot = HKEY_CURRENT_USER; + wchar_t *szSubKey = (wchar_t*)L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; + HKEY hKey; + DWORD dwDisposition = REG_OPENED_EXISTING_KEY; + LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, + REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition); + if (lRet != ERROR_SUCCESS) { + QMessageBox::critical(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("ÒƳý¿ª»úÆô¶¯Ïîʧ°Ü¡£")); + return; + } + QString app = QApplication::applicationFilePath(); + lRet = RegDeleteValue(hKey, LENG_NAME); + if (lRet == ERROR_SUCCESS) + { + QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("ÒƳý¿ª»úÆô¶¯Ïî³É¹¦¡£")); + } + RegCloseKey(hKey); + } +} + +void MySettingsDialog::law() +{ + QString path = QApplication::applicationDirPath(); + QString license = path + "/license.txt"; + license.replace("/", "\\"); + ShellExecute(GetDesktopWindow(), L"open", L"notepad.exe" , license.toStdWString().c_str(), nullptr, SW_SHOW); +} + +void MySettingsDialog::copyToCLipboard() { + QClipboard *clip = QApplication::clipboard(); + clip->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex())); +} +void MySettingsDialog::createShortcut() { + QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); + deskTopPath = deskTopPath + QString::fromLocal8Bit("/"); + deskTopPath = deskTopPath + QString::fromLocal8Bit(NAME); + deskTopPath = deskTopPath + QString::fromLocal8Bit(".lnk"); + QString srcFile = QApplication::applicationFilePath(); + bool succeed=QFile::link(srcFile, deskTopPath); + if (succeed) { + QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ì½Ý·½Ê½³É¹¦¡£")); + } + else { + QMessageBox::information(this, QString::fromLocal8Bit("Ìáʾ"), QString::fromLocal8Bit("´´½¨¿ì½Ý·½Ê½Ê§°Ü¡£")); + } } \ No newline at end of file diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index e3e7add..1420b19 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -14,8 +14,10 @@ #include "globalvariables.h" #ifdef _DEBUG #pragma comment(lib, "Qt5Svgd.lib") +#pragma comment(lib, "Qt5Sqld.lib") #else #pragma comment(lib, "Qt5Svg.lib") +#pragma comment(lib, "Qt5Sql.lib") #endif QString url_param; void ConvertImageToTransparent(QImage &img) @@ -46,7 +48,7 @@ NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *p setStyleSheet(style);*/ //setStyleSheet("margin:0"); setContentsMargins(0, 0, 0, 0); - if (configResponse->succeed&&configResponse->menus.empty()!=true) { + if (configResponse->succeed&&configResponse->buttons.empty()!=true) { getLogoFromInternet(configResponse); } else { @@ -141,7 +143,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { logo = new QImage(); logo->loadFromData(*buffer); buffer->clear(); - for (auto button : configResponse->menus) { + for (auto button : configResponse->buttons) { QUrl url_image(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 a7b7cd5..46f6db2 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -23,6 +23,7 @@ #include #include #include "globalvariables.h" +#include "buttonstruct.h" #pragma comment(lib, "wbemuuid.lib") #ifdef _DEBUG #pragma comment(lib, "Qt5Networkd.lib") @@ -221,7 +222,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { delete httpMgr; return; } - qDebug() << result.toJson(); + //qDebug() << result.toJson(); //Èç¹ûÊý¾ÝÍêÕû if(result.isObject()){ @@ -240,13 +241,15 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { auto i=0; for(auto value:array){ QJsonObject object=value.toObject(); - 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; + Button button; + button.img=object.value("img").toString(); + // button.img_cover=object.value("img_cover").toString(); + button.title=object.value("title").toString(); + button.categroy_id = object.value("category_id").toString(); + button.op = object.value("op").toString(); + button.func=object.value("func").toString(); + button.url=object.value("url").toString(); + configResponse->buttons << button; i++; } configResponse->succeed = true; @@ -572,3 +575,70 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() { eventLoop.exec(); delete httpMgr; } +bool SoftwareRequest::sendRequest(QHash *records) +{ + timer = new QTimer(this); + QNetworkAccessManager* httpMgr = new QNetworkAccessManager(); + QNetworkRequest requestInfo; + //HTTPÇëÇó + //ÇëÇóÍ· + QJsonArray array; + for(auto record : *records) + { + array.append(record.orig_name); + } + QJsonObject obj_root = qJsonDocument.object(); + obj_root.insert("orig_names", array); + qJsonDocument.setObject(obj_root); + QString url = SOFTWARE_URL; + requestInfo.setUrl(url); + 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, &SoftwareRequest::cancelDownload); + timer->start(5000); + //Æô¶¯Ñ­»· + eventLoop.exec(); + timer->stop(); + QJsonDocument result; + // auto error = reply->error(); + //Èç¹ûûÓдíÎó + if (reply->error() == QNetworkReply::NoError) { + result = QJsonDocument::fromJson(reply->readAll()); + } + else { + //Èç¹ûÓдíÎó + delete timer; + delete httpMgr; + return false; + } + //qDebug() << result.toJson(); + + //Èç¹ûÊý¾ÝÍêÕû + if (result.isObject()) { + QJsonObject obj_root2 = result.object(); + QJsonArray array = obj_root2.value("data").toObject().value("menu").toArray(); + for (auto value : array) { + QJsonObject object = value.toObject(); + QString orig_name = object.value("orig_name").toString(); + (*records)[orig_name].logo = object.value("img").toString(); + (*records)[orig_name].op = object.value("op").toString(); + (*records)[orig_name].func = object.value("func").toString(); + (*records)[orig_name].url = object.value("url").toString(); + } + } + else { + //Êý¾Ý²»ÍêÕû + //delete reply; + delete timer; + delete httpMgr; + return false; + } + delete httpMgr; + return true; +} + diff --git a/OfficeAssistant_msvc/netio.h b/OfficeAssistant_msvc/netio.h index 0799869..b217fc6 100644 --- a/OfficeAssistant_msvc/netio.h +++ b/OfficeAssistant_msvc/netio.h @@ -12,15 +12,19 @@ #include #include #include - +#include "buttonstruct.h" +#include "sqlitehelper.h" typedef struct { QString img; QString img_cover; QString title; + QString orig_name; + QString categroy_id; + QString op; QString func; QString url; -} Menu; +} Button; typedef struct { bool succeed; struct { @@ -32,7 +36,7 @@ typedef struct { QString title_color; QString title_cover_color; }basic; - QList menus; + QList