From a7c74a20a69d8777db30f1c9ff4f29590615fd31 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Tue, 15 Aug 2023 11:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E8=AF=A5=E5=AE=8C=E6=88=90=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OfficeAssistant_msvc/addapp.cpp | 109 +++-- OfficeAssistant_msvc/addcategory.cpp | 2 +- OfficeAssistant_msvc/applicationmanager.cpp | 17 +- OfficeAssistant_msvc/applicationmanager.h | 4 + .../applicationmanagerpage.cpp | 83 +++- OfficeAssistant_msvc/applicationmanagerpage.h | 3 +- OfficeAssistant_msvc/config.h | 6 +- OfficeAssistant_msvc/logo.aps | Bin 43740 -> 43840 bytes OfficeAssistant_msvc/mainscreen.cpp | 20 +- OfficeAssistant_msvc/mainscreen.h | 1 + OfficeAssistant_msvc/mainwindowlayout.cpp | 7 +- OfficeAssistant_msvc/navbar.cpp | 5 +- OfficeAssistant_msvc/navbar.h | 2 +- OfficeAssistant_msvc/netio.cpp | 21 +- OfficeAssistant_msvc/netio.h | 2 +- OfficeAssistant_msvc/resource.h | Bin 860 -> 860 bytes OfficeAssistant_msvc/sqlitehelper.cpp | 443 ++++++++++++++++-- OfficeAssistant_msvc/sqlitehelper.h | 2 +- 18 files changed, 587 insertions(+), 140 deletions(-) diff --git a/OfficeAssistant_msvc/addapp.cpp b/OfficeAssistant_msvc/addapp.cpp index cdfdf25..d6e0c5d 100644 --- a/OfficeAssistant_msvc/addapp.cpp +++ b/OfficeAssistant_msvc/addapp.cpp @@ -6,14 +6,11 @@ #include "applicationmanager.h" -#if _MSC_VER >=1936 -#include -namespace fs = std::filesystem; -#else + #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include namespace fs = std::experimental::filesystem; -#endif + AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) : QDialog(parent) @@ -29,6 +26,10 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) { name_label = new QLabel(orig_name_str); form->addRow(QString::fromLocal8Bit("全名"), name_label); + if(row!=nullptr) + { + name_label->setText(row->orig_name); + } } else { @@ -45,14 +46,10 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) form->addRow(QString::fromLocal8Bit("排序"), sort); QList categrories; layout_inner = new QVBoxLayout; - sqlite_helper.get_category(categrories); + sqlite_helper.get_category(categrories,true); for (auto category : categrories) { - if ((category.id == 1) || (category.id == 8) || (category.id == 4) || (category.id == 5 || category.id == 3)) - { - continue; - } QCheckBox* check_box = new QCheckBox(category.name); layout_inner->addWidget(check_box); categories_list.insert(category.id, check_box); @@ -66,6 +63,9 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) this->isEdit = isEdit; }else { + name->setText(row->name); + name_str=row->name; + sort_str=QString::number(row->sort); path = new QPushButton(QString::fromLocal8Bit("浏览")); path_str = row->exe_file; path->setText(QString::fromWCharArray(fs::path(path_str.toStdWString()).filename().c_str())); @@ -77,16 +77,12 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) form->addRow(QString::fromLocal8Bit("排序"), sort); QList categrories; layout_inner = new QVBoxLayout; - sqlite_helper.get_category(categrories); - + sqlite_helper.get_category(categrories,true); + categories = row->categories; for (auto category : categrories) { - if ((category.id == 1) || (category.id == 8) || (category.id == 4) || (category.id == 5 || category.id == 3)) - { - continue; - } QCheckBox* check_box = new QCheckBox(category.name); - if(row->categories[category.id]) + if(row->categories[category.id-1]) { check_box->setCheckState(Qt::Checked); } @@ -122,43 +118,72 @@ AddApp::~AddApp() } void AddApp::broswer_exe(){ - path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), - QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)")); - fs::path file(path_str.toStdWString()); - path->setText(QString::fromStdWString(file.filename().c_str())); -} - -void AddApp::submit() { - if((!orig_name->text().isEmpty())&&(!path->text().isEmpty())) + QString path_str_old = path_str; + if(path_str.isEmpty()) { - orig_name_str = orig_name->text(); - name_str = orig_name_str; - sort_str = sort->text(); + path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), + QApplication::applicationDirPath(), QString::fromLocal8Bit("应用程序 (*.exe)")); } else { - QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写名称或路径")); - return; + path_str = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("选择程序"), + path_str, QString::fromLocal8Bit("应用程序 (*.exe)")); } - categories = new bool[8]; - categories[0] = true; - categories[2] = true; - categories[7] = true; - categories[3] = false; - categories[4] = false; - for(auto key:categories_list.keys()) + if (path_str.isEmpty()) { + path_str = path_str_old; + } + fs::path file(path_str.toStdWString()); + path->setText(QString::fromStdWString(file.filename().c_str())); + +} + +void AddApp::submit() { + if(isEdit) { - if(key==0||key==2||key==7||key==3||key==4) + if (!path->text().isEmpty()) { - continue; + QString name_str_old = name_str; + QString sort_str_old = sort_str; + name_str = name->text(); + sort_str = sort->text(); + + if (name_str.isEmpty()) { + name_str = name_str_old; + } + if (sort_str.isEmpty()) { + sort_str = sort_str_old; + } } else { - categories[key - 1] = categories_list[key]->checkState(); + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写路径")); + return; + } + }else + { + if ((!orig_name->text().isEmpty()) && (!path->text().isEmpty())) + { + orig_name_str = orig_name->text(); + if (name->text().isEmpty()) { + name_str = orig_name_str; + } + name_str = name->text(); + sort_str = sort->text(); + } + else + { + QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("未填写全名或路径")); + return; } } - categories[0] = true; - categories[7] = true; + for(auto key:categories_list.keys()) + { + categories[key - 1] = categories_list[key]->checkState(); + } + for (int i = 0; i < 8; i++) { + qDebug() << categories[i]; + } + changed = true; close(); } diff --git a/OfficeAssistant_msvc/addcategory.cpp b/OfficeAssistant_msvc/addcategory.cpp index 231e46e..cae3239 100644 --- a/OfficeAssistant_msvc/addcategory.cpp +++ b/OfficeAssistant_msvc/addcategory.cpp @@ -11,7 +11,7 @@ AddCategory::AddCategory(QWidget* parent) ui.tableWidget->setColumnCount(3); title << QString::fromLocal8Bit("名称") << QString::fromLocal8Bit("显示") << QString::fromLocal8Bit("排序"); ui.tableWidget->setHorizontalHeaderLabels(title); - sqlite_helper.get_category(categrories); + sqlite_helper.get_category(categrories,false); ui.tableWidget->setRowCount(categrories.count()); int i = 0; for(auto category : categrories) diff --git a/OfficeAssistant_msvc/applicationmanager.cpp b/OfficeAssistant_msvc/applicationmanager.cpp index cf47e2d..ae6104c 100644 --- a/OfficeAssistant_msvc/applicationmanager.cpp +++ b/OfficeAssistant_msvc/applicationmanager.cpp @@ -13,6 +13,7 @@ ApplicationManager::ApplicationManager(QWidget *parent) { ui.setupUi(this); resize(parent->width(), parent->height()); + this->parent = parent; miniblink = new QMiniBlink(this); miniblink->init(); miniblink->show(); @@ -23,7 +24,7 @@ ApplicationManager::ApplicationManager(QWidget *parent) layout_top->setMargin(5); layout_bottom = new QHBoxLayout(this); QList categrories; - sqlite_helper.get_category(categrories); + sqlite_helper.get_category(categrories,false); sqlite_helper.get_buttons(button_structs); for (auto button_struct : button_structs) { @@ -243,10 +244,15 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin void ApplicationManager::onclick2(QString orig_name, QString op) { - if (op == "open") + if (op == "app") { - emit changeUrl(application_manager_page_all->rows[orig_name].url); - WinExec(application_manager_page_all->rows[orig_name].exe_file.toStdString().c_str(), SW_SHOW); + if (application_manager_page_all->rows[orig_name].func == "openwechat") { + emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func, application_manager_page_all->rows[orig_name].exe_file, application_manager_page_all->rows[orig_name].url); + } + else { + emit changeUrl(application_manager_page_all->rows[orig_name].url); + WinExec(application_manager_page_all->rows[orig_name].exe_file.toStdString().c_str(), SW_SHOW); + } } else if (op == "settings") { @@ -261,6 +267,9 @@ void ApplicationManager::onclick2(QString orig_name, QString op) } } } + else { + emit application_manager_page_all->onclick3(application_manager_page_all->rows[orig_name].op, application_manager_page_all->rows[orig_name].func,application_manager_page_all->rows[orig_name].exe_file,application_manager_page_all->rows[orig_name].url); + } } void ApplicationManager::tabChange(int index) diff --git a/OfficeAssistant_msvc/applicationmanager.h b/OfficeAssistant_msvc/applicationmanager.h index 90b2f34..432ad08 100644 --- a/OfficeAssistant_msvc/applicationmanager.h +++ b/OfficeAssistant_msvc/applicationmanager.h @@ -27,6 +27,9 @@ struct Record2 QSvgWidget* icon; MiniButton* settings; MiniButton * open; + QString op; + QString func; + QString name; QString orig_name; QString exe_file; QCheckBox *check_box; @@ -52,6 +55,7 @@ signals: public: ApplicationManager(QWidget *parent = nullptr); ~ApplicationManager(); + QWidget* parent; private: QHash pages; QVBoxLayout* layout; diff --git a/OfficeAssistant_msvc/applicationmanagerpage.cpp b/OfficeAssistant_msvc/applicationmanagerpage.cpp index de77f89..06dcfd2 100644 --- a/OfficeAssistant_msvc/applicationmanagerpage.cpp +++ b/OfficeAssistant_msvc/applicationmanagerpage.cpp @@ -2,9 +2,11 @@ #include #include +#include #include "applicationmanager.h" #include "config.h" - +#include "mainscreen.h" +#include "mainwindowlayout.h" ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent) : QWidget(parent) { @@ -47,8 +49,12 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager date += QString::number(1 + time->tm_mon, 10); date += "/"; date += QString::number(time->tm_mday, 10); + if (software.use_time == 0) { + date.clear(); + } table->setItem(i, 4, new QTableWidgetItem(date)); Record2 record2; + record2.name = software.name; record2.icon = new QSvgWidget; QFile file(software.logo); if(file.exists()) @@ -65,7 +71,7 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager record2.settings->setMaximumSize(60, 40); connect(record2.settings, &MiniButton::click0, record2.settings, &MiniButton::onclick2); connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); - record2.open = new MiniButton(software.orig_name, "open"); + record2.open = new MiniButton(software.orig_name,software.op); record2.open->setText(QString::fromLocal8Bit("打开")); record2.open->setMaximumSize(60, 40); connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2); @@ -73,13 +79,16 @@ ApplicationManagerPage::ApplicationManagerPage(int category, ApplicationManager record2.exe_file = software.path; record2.orig_name = software.orig_name; record2.url = software.url; + record2.op = software.op; + record2.func = software.func; + connect(this, &ApplicationManagerPage::onclick3, (MainWindowLayout*)((MainScreen*)application_manager->parent)->parent, &MainWindowLayout::clickButton); for(int i=0;i<8;i++) { record2.categories[i] = false; } for(int i=0;i<8;i++) { - if (software.category_id.contains(QString::number(i))) + if (software.category_id.contains(QString::number(i+1))) { record2.categories[i] = true; } @@ -129,12 +138,12 @@ void ApplicationManagerPage::onclicked() { for(int i=0;irowCount();i++) { - if(((QCheckBox *)table->cellWidget(i,4))->checkState()==Qt::Checked) + if(((QCheckBox *)table->cellWidget(i,5))->checkState()==Qt::Checked) { - if(!checked[table->item(i,1)->text()]) + if(!checked[table->item(i,2)->text()]) { - QString orig_name = table->item(i, 1)->text(); - bool ok=sqlite_helper.edit_software(table->item(i, 0)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories,"navbar"); + QString orig_name = table->item(i, 2)->text(); + bool ok=sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories,"navbar"); if(!ok) { QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); @@ -143,10 +152,10 @@ void ApplicationManagerPage::onclicked() } }else { - if (checked[table->item(i, 1)->text()]) + if (checked[table->item(i, 2)->text()]) { - QString orig_name = table->item(i, 1)->text(); - bool ok = sqlite_helper.edit_software(table->item(i, 0)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories, "app"); + QString orig_name = table->item(i, 2)->text(); + bool ok = sqlite_helper.edit_software(table->item(i, 1)->text(), orig_name, rows[orig_name].exe_file, QString::number(rows[orig_name].sort), rows[orig_name].categories, "app"); if (!ok) { QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("更新部分或全部失败")); @@ -179,19 +188,35 @@ void ApplicationManagerPage::refresh() for (auto software : softwares) { table->insertRow(i); - table->setItem(i, 0, new QTableWidgetItem(software.name)); - table->setItem(i, 1, new QTableWidgetItem(software.orig_name)); - table->setItem(i, 2, new QTableWidgetItem(software.dev)); + + table->setItem(i, 1, new QTableWidgetItem(software.name)); + table->setItem(i, 2, new QTableWidgetItem(software.orig_name)); + table->setItem(i, 3, new QTableWidgetItem(software.dev)); QString date; std::tm* time; - time = std::localtime(&software.use_time); - date = QString::number(1900 + time->tm_year, 10); - date += "/"; - date += QString::number(1 + time->tm_mon, 10); - date += "/"; - date += QString::number(time->tm_mday, 10); - table->setItem(i, 3, new QTableWidgetItem(date)); + if(software.use_time!=0) + { + time = std::localtime(&software.use_time); + date = QString::number(1900 + time->tm_year, 10); + date += "/"; + date += QString::number(1 + time->tm_mon, 10); + date += "/"; + date += QString::number(time->tm_mday, 10); + table->setItem(i, 4, new QTableWidgetItem(date)); + } Record2 record2; + record2.name = software.name; + record2.icon = new QSvgWidget; + QFile file(software.logo); + if (file.exists()) + { + record2.icon->load(software.logo); + } + else { + record2.icon->load(QApplication::applicationDirPath() + DEFAULT_IMAGE); + } + record2.icon->setMaximumSize(80, 80); + table->setCellWidget(i, 0, record2.icon); record2.settings = new MiniButton(software.orig_name, "settings"); record2.settings->setText(QString::fromLocal8Bit("设置")); record2.settings->setMaximumSize(60, 40); @@ -199,17 +224,19 @@ void ApplicationManagerPage::refresh() connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); record2.open = new MiniButton(software.orig_name, "open"); record2.open->setText(QString::fromLocal8Bit("打开")); - record2.open->setMaximumSize(60, 40); connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2); + record2.open->setMaximumSize(60, 40); + connect(record2.open, &MiniButton::click0, record2.open, &MiniButton::onclick2); connect(record2.open, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); record2.exe_file = software.path; record2.orig_name = software.orig_name; + record2.url = software.url; for (int i = 0; i < 8; i++) { record2.categories[i] = false; } for (int i = 0; i < 8; i++) { - if (software.category_id.contains(QString::number(i))) + if (software.category_id.contains(QString::number(i+1))) { record2.categories[i] = true; } @@ -227,12 +254,18 @@ void ApplicationManagerPage::refresh() checked.insert(software.orig_name, false); } connect(record2.check_box, &QCheckBox::clicked, this, &ApplicationManagerPage::onclicked); - table->setCellWidget(i, 4, record2.check_box); - table->setCellWidget(i, 5, record2.settings); + QTableWidgetItem* check_box_item = new QTableWidgetItem; + table->setItem(i, 5, check_box_item); + table->setCellWidget(i, 5, record2.check_box); + check_box_item->setTextAlignment(Qt::AlignCenter); + table->setCellWidget(i, 6, record2.settings); //table->item(i, 5)->setTextAlignment(Qt::AlignCenter); - table->setCellWidget(i, 6, record2.open); + table->setCellWidget(i, 7, record2.open); //table->item(i, 6)->setTextAlignment(Qt::AlignCenter); rows.insert(software.orig_name, record2); + table->resizeColumnToContents(0); + //table->item(i, 0)->setTextAlignment(Qt::AlignCenter); + //table->verticalHeader()->setSectionResizeMode(i, QHeaderView::ResizeToContents); i++; } } diff --git a/OfficeAssistant_msvc/applicationmanagerpage.h b/OfficeAssistant_msvc/applicationmanagerpage.h index 995a59c..8f10698 100644 --- a/OfficeAssistant_msvc/applicationmanagerpage.h +++ b/OfficeAssistant_msvc/applicationmanagerpage.h @@ -16,7 +16,8 @@ struct Record2; class ApplicationManagerPage : public QWidget { Q_OBJECT - +signals: + void onclick3(QString op, QString func, QString url, QString path,QString initial_position=""); public: ApplicationManagerPage(int category, ApplicationManager *application_manager,QWidget *parent = nullptr); ~ApplicationManagerPage(); diff --git a/OfficeAssistant_msvc/config.h b/OfficeAssistant_msvc/config.h index 6a61b1e..99c686e 100644 --- a/OfficeAssistant_msvc/config.h +++ b/OfficeAssistant_msvc/config.h @@ -9,7 +9,8 @@ #define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址 #define WECHAT_URL " http://softapi.s103.y01.cn/addons/Kmdsoft/Wxdk/open" #define BASE_URL "http://softapi.s103.y01.cn/" //域名 -#define DEFAULT_FILE "/config/default_navbar.kmd" //默认导航栏文件位置 +#define DEFAULT_FILE "/config/config.kmd" //默认配置文件位置 +#define DEFAULT_NAVBAR_FILLE "/config/default_navbar.kmd" #define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key #define NAME "办公助手" //中文名 #define LOGO_TITLEBAR "/images/icon/logo_navbar.png" //标题栏图标 @@ -24,7 +25,8 @@ #define DEFAULT_COLOR "#3399FF" // #define DEFAULT_TEXT_COLOR "#FFFFFF" //默认文字颜色 #define DEFAULT_COVER_COLOR "#0033FF" //鼠标指向后变成的颜色,也是“添加应用”等几个按钮的默认颜色 -#define DEFAULT_IMAGE "/images/icon/default.svg" //默认图标 +#define DEFAULT_IMAGE "/images/svg/default.svg" //默认图标 +#define DEFAULT_SVG_PATH "/images/svg/" #define DEFAULT_LOGO "/images/logo.png" //logo路径 #define TITLE " " //标题栏 #define TEXT_SIZE 7 //字体大小。不是所有字体受此项控制 diff --git a/OfficeAssistant_msvc/logo.aps b/OfficeAssistant_msvc/logo.aps index 0d231317d5608dbbce3575107e5f148180090af3..1a03a68346578774735c3748d993cb63b7ead814 100644 GIT binary patch delta 352 zcmY+AJ4gdj5Jm62ybXfpQ)rs}U2OzqH%h=jszk^(N`yp<1*-%LwMa@UI~&DyAYiLa zcH4jmB19}~Yz+uvZzV(vt=4CnU@@0F40Go5`Yiebah9Q?lhq?-7bq3%TD#F|+m$V6 zb4daiI!CJ!t8DF9rHyqHreQ*3SEgx_-(`lToS(D^flp+d!kninAJYOgxkvNV;TLKo z%#~5o81a8bD33Y#{$Bu+*MvS(LIE~vXrqCaQX3U)@uB$Oy+ECE{1CY2Q<!H&wKg5M~mNdlhuLY2Pw&eg@X zbMQ;`58DknxpN%s=i<$Evw3n-{( AIsgCw delta 291 zcmW-cKTE?<6vfYdNh%tNgPOr=(~^pVPz`ROo1qYtiqyfO;7|g(SZL{2aPH%F6DJ*- z=q5V5x%dYJ9mJvi0M*4&iO&uf&gC5L`Q5uW@$o9Uc`D0-YYqB9;MZ%-POA~M`B;>U zA%G&w*pYo(K4&!#lX8@&DYnQVlS{Nn)4WByd`hbn@jWe5g+~-k6p^NY;8?h`0esX^ zLlYge&_IMX55*ThY5U~yihes62H`=txl{Gvt$Ppzg3fD{CCEpI@ZWa5ZM>YT3MUS! z%tx_1X1h>qE?x0W>|`p6^@sR9&Kc?g4*6GET`nZ9_}19hbB3uBdwiBG@kwG+PpJ(W ajQ7vPHXqdcX=setupUi(this); + this->parent = parent; setContentsMargins(0, 0, 0, 0); widget = new QWidget(this); layout_left = new QVBoxLayout(widget); @@ -78,11 +79,26 @@ MainScreen::~MainScreen() { } void MainScreen::firstUrl(QString url) { - QString url_full = BASE_URL + url + url_param; + QString url_full; + if (url.contains("http")) + { + url_full = url; + } + else + { + url_full = BASE_URL + url + url_param; + } emit changeUrl(url_full); } void MainScreen::clickButton1(QString op,QString url) { - QString url_full = BASE_URL + url + url_param; + QString url_full; + if(url.contains("http")) + { + url_full = url; + }else + { + url_full = BASE_URL + url + url_param; + } if (op == "openwechat") { OpenWeChatRequest open_wechat_request; QString msg = open_wechat_request.sendRequest(); diff --git a/OfficeAssistant_msvc/mainscreen.h b/OfficeAssistant_msvc/mainscreen.h index e6d5e70..a5a633e 100644 --- a/OfficeAssistant_msvc/mainscreen.h +++ b/OfficeAssistant_msvc/mainscreen.h @@ -26,6 +26,7 @@ signals: public: explicit MainScreen(QWidget *parent = nullptr); ~MainScreen() override; + QWidget* parent; public slots: void clickButton1(QString op, QString url); void firstUrl(QString url); diff --git a/OfficeAssistant_msvc/mainwindowlayout.cpp b/OfficeAssistant_msvc/mainwindowlayout.cpp index 7478e2e..5631797 100644 --- a/OfficeAssistant_msvc/mainwindowlayout.cpp +++ b/OfficeAssistant_msvc/mainwindowlayout.cpp @@ -16,16 +16,12 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) : layout=new QVBoxLayout(this); mainWindowLayout = this; QList list; - ConfigRequest *configRequest = new ConfigRequest; - configResponse = new ConfigResponse; - configRequest->sendRequest(configResponse); mainScreen = new MainScreen(this); - navBar=new NavBar(configResponse,mainScreen,this); + navBar=new NavBar(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); @@ -37,7 +33,6 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) : } MainWindowLayout::~MainWindowLayout() { - delete configResponse; layout->removeWidget(mainScreen); layout->removeWidget(navBar); delete mainScreen; diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index 54a60d5..02927d1 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -39,7 +39,7 @@ void ConvertImageToTransparent(QImage &img) } } -NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) : +NavBar::NavBar(MainScreen *mainScreen,QWidget *parent) : QWidget(parent), ui(new Ui::NavBar) { ui->setupUi(this); //this->setAttribute(Qt::WA_DeleteOnClose); @@ -55,9 +55,10 @@ NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *p config_request.sendRequest(&config_response); SQLiteHelper sqlite_helper; sqlite_helper.get_software(&buttonStructs, &config_response); + if(!config_response.succeed) { - qColor.setNamedColor(DEFAULT_BACKGROUND_COLOR); + qColor.setNamedColor(buttonStructs[0].background_color); }else { diff --git a/OfficeAssistant_msvc/navbar.h b/OfficeAssistant_msvc/navbar.h index fef7429..c9448b9 100644 --- a/OfficeAssistant_msvc/navbar.h +++ b/OfficeAssistant_msvc/navbar.h @@ -29,7 +29,7 @@ Q_OBJECT signals: void firstUrl(QString url); public: - NavBar(ConfigResponse *configResponse,MainScreen *mainScreen,QWidget *parent = nullptr); + NavBar(MainScreen *mainScreen,QWidget *parent = nullptr); ~NavBar() override; protected: diff --git a/OfficeAssistant_msvc/netio.cpp b/OfficeAssistant_msvc/netio.cpp index c78f677..34f8283 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -236,7 +236,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { if(result.isObject()){ QJsonObject obj_root=result.object(); QJsonArray array; - + array = obj_root.value("data").toObject().value("menu").toArray(); QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject(); configResponse->basic.logo_url = obj_basic.value("logo").toString(); @@ -251,6 +251,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { QJsonObject object=value.toObject(); Button button; button.img=object.value("img").toString(); + button.orig_name= object.value("orig_name").toString(); // button.img_cover=object.value("img_cover").toString(); button.title=object.value("title").toString(); button.categroy_id = object.value("category_id").toString(); @@ -261,6 +262,12 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { i++; } configResponse->succeed = true; + QFile file(QApplication::applicationDirPath() + DEFAULT_NAVBAR_FILLE); + if (file.open(QIODevice::Text | QIODevice::WriteOnly)) + { + file.write(result.toJson()); + file.close(); + } }else{ //数据不完整 configResponse->succeed=false; @@ -584,7 +591,7 @@ DeviceRequest::DeviceRequest() : RequestBodyBase() { eventLoop.exec(); delete httpMgr; } -bool SoftwareRequest::sendRequest(QHash&startMenu, QHash *records) +bool SoftwareRequest::sendRequest(QHash&startMenu, QHash *records, QJsonArray &software_exists) { timer = new QTimer(this); QNetworkAccessManager* httpMgr = new QNetworkAccessManager(); @@ -611,6 +618,7 @@ bool SoftwareRequest::sendRequest(QHash&startMenu, QHash&startMenu, QHashclose(); - QString dir = QApplication::applicationDirPath() + "/images/software/"; - if (downloadSuccess == true) { + QString dir = QApplication::applicationDirPath() + "/images/svg/"; + if ((reply->error() == QNetworkReply::NoError)&&(downloadSuccess == true)) { buffer = reply->readAll(); QFile file(dir + orig_name + ".svg"); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) @@ -704,6 +712,9 @@ bool SoftwareRequest::sendRequest(QHash&startMenu, QHash&startMenu, QHash*records); + bool sendRequest(QHash&startMenu, QHash*records,QJsonArray &software_exists); }; class OpenWeChatRequest:public RequestBodyBase diff --git a/OfficeAssistant_msvc/resource.h b/OfficeAssistant_msvc/resource.h index 5bfe071e7d60c07fd3cd2e255507a240a86032d8..595836cc29beff6bd2853ae07d54a6ba215002de 100644 GIT binary patch delta 23 fcmcb^c86`kCq|=23~S;$Z{;aTW*H delta 23 fcmcb^c86`kCq~1KpY<6TjV3oT>23~S;$Z{;aQp|= diff --git a/OfficeAssistant_msvc/sqlitehelper.cpp b/OfficeAssistant_msvc/sqlitehelper.cpp index 805091f..89a2a4a 100644 --- a/OfficeAssistant_msvc/sqlitehelper.cpp +++ b/OfficeAssistant_msvc/sqlitehelper.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "navbar.h" #include "config.h" @@ -26,15 +27,10 @@ #pragma comment (lib,"Qt5Xml.lib") #endif #pragma comment (lib,"Shell32.lib") -#if _MSC_VER >=1936 -#include -namespace fs = std::filesystem; -#else + #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include -namespace fs = std::experimental::filesystem; -#endif - +namespace fs= std::experimental::filesystem; bool getMenu(std::wstring &path_str,QHash *paths) { fs::directory_iterator* it = new fs::directory_iterator(path_str); @@ -141,7 +137,7 @@ SQLiteHelper::~SQLiteHelper() bool SQLiteHelper::update_software() { HKEY hKeyUninstall = nullptr; - QHash* paths = new QHash; + QHash* paths = new QHash; /*QSqlQuery query; QString sql = "select * from kmd_menu;"; query.exec(sql); @@ -180,15 +176,15 @@ bool SQLiteHelper::update_software() HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//获取ProgramData中开始菜单的路径 std::wstring path_str(path); getMenu(path_str, paths); - - for(int i=0;i reg_records; HKEY hKey; @@ -230,7 +226,7 @@ bool SQLiteHelper::update_software() &ftLastWriteTime); // last write time // 枚举该列表下所有子键 - for (DWORD i = 0; i* buttons, ConfigResponse* config_response) +bool SQLiteHelper::get_software(QList* button_structs, ConfigResponse* config_response) { QSqlQuery query(db); QString sql = "select * from kmd_menu where type='navbar' order by sort,orig_name asc ;"; @@ -797,7 +889,8 @@ bool SQLiteHelper::get_software(QList* buttons, ConfigResponse* co QString background_color; QString title_color; QString title_cover_color; - if(config_response->succeed) + QList