解决兼容性问题

master
Mike Solar 2023-08-21 15:10:19 +08:00
parent 5ec58b3bfb
commit 9ee232cead
9 changed files with 110 additions and 55 deletions

View File

@ -23,33 +23,37 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
setWindowFlags(Qt::WindowCloseButtonHint); setWindowFlags(Qt::WindowCloseButtonHint);
form = new QFormLayout; form = new QFormLayout;
name = new QLineEdit; name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("名称"), name); if(isEdit)
if (isEdit)
{ {
sqlite_helper.get_a_software(row->orig_name, &record); record=*row;//最初为啥这么写我也忘了
name_label = new QLabel(orig_name_str);
form->addRow(QString::fromLocal8Bit("全名"), name_label);
record = *row;//最初为啥这么写我也忘了
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
} }
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
if (record.orig_name.isEmpty()) if (record.orig_name.isEmpty())
{ {
path = new QPushButton(QString::fromLocal8Bit("浏览")); path = new QPushButton(QString::fromLocal8Bit("浏览"));
connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe);
form->addRow(QString::fromLocal8Bit("路径"), path); form->addRow(QString::fromLocal8Bit("路径"), path);
if (isEdit)
{
sqlite_helper.get_a_software(row->orig_name, &record);
name_label = new QLabel(orig_name_str);
form->addRow(QString::fromLocal8Bit("全名"), name_label);
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
}
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
form->addRow(QString::fromLocal8Bit("名称"), name);
sort = new QLineEdit; sort = new QLineEdit;
sort->setValidator(new QIntValidator(10, 100)); sort->setValidator(new QIntValidator(10, 100));
sort->setText("50");
form->addRow(QString::fromLocal8Bit("排序"), sort); form->addRow(QString::fromLocal8Bit("排序"), sort);
QList<Categrory> categrories; QList<Categrory> categrories;
layout_inner = new QVBoxLayout; layout_inner = new QVBoxLayout;
@ -83,6 +87,24 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent)
{ {
form->addRow(QString::fromLocal8Bit("路径"), path); form->addRow(QString::fromLocal8Bit("路径"), path);
} }
if (isEdit)
{
sqlite_helper.get_a_software(row->orig_name, &record);
name_label = new QLabel(orig_name_str);
form->addRow(QString::fromLocal8Bit("全名"), name_label);
if (!record.orig_name.isEmpty())
{
name_label->setText(record.orig_name);
}
orig_name_str = record.orig_name;
}
else
{
orig_name = new QLineEdit;
form->addRow(QString::fromLocal8Bit("全名"), orig_name);
}
form->addRow(QString::fromLocal8Bit("名称"), name);
sort = new QLineEdit; sort = new QLineEdit;
sort->setText(QString::number(record.sort)); sort->setText(QString::number(record.sort));
sort->setValidator(new QIntValidator(10, 100)); sort->setValidator(new QIntValidator(10, 100));
@ -145,7 +167,10 @@ void AddApp::broswer_exe(){
} }
fs::path file(path_str.toStdWString()); fs::path file(path_str.toStdWString());
path->setText(QString::fromStdWString(file.filename().c_str())); path->setText(QString::fromStdWString(file.filename().c_str()));
if(!isEdit)
{
orig_name->setText(QString::fromStdWString(file.filename().c_str()));
}
} }
void AddApp::submit() { void AddApp::submit() {

View File

@ -126,7 +126,7 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名"));
} }
emit refresh(); emit refresh_tab();
} }
} }
else if (func == "app_update") else if (func == "app_update")
@ -237,7 +237,7 @@ void ApplicationManager::onclick2(QString orig_name, QString op)
{ {
QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败")); QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败"));
} }
emit refresh(); emit refresh_tab();
} }
} }

View File

@ -57,6 +57,7 @@ signals:
void refresh(); void refresh();
void refresh_tab(); void refresh_tab();
public: public:
QList<MiniButton*> buttons;
ApplicationManager(QWidget *parent = nullptr); ApplicationManager(QWidget *parent = nullptr);
~ApplicationManager(); ~ApplicationManager();
QWidget* parent; QWidget* parent;
@ -69,7 +70,6 @@ private:
QHBoxLayout* layout_top; QHBoxLayout* layout_top;
QHBoxLayout* layout_bottom; QHBoxLayout* layout_bottom;
QMiniBlink* miniblink; QMiniBlink* miniblink;
QList<MiniButton*> buttons;
QList<Record> softwares; QList<Record> softwares;
QList<ButtonStruct> button_structs; QList<ButtonStruct> button_structs;
ApplicationManagerPage* application_manager_page_all; ApplicationManagerPage* application_manager_page_all;

View File

@ -86,6 +86,10 @@ void ApplicationManagerPage::onclicked(int state)
//刷新页面 //刷新页面
void ApplicationManagerPage::refresh() void ApplicationManagerPage::refresh()
{ {
for(auto button:application_manager->buttons)
{
button->update();
}
int rowcount = table->rowCount(); int rowcount = table->rowCount();
for(auto i : connections) for(auto i : connections)
{ {
@ -141,13 +145,18 @@ void ApplicationManagerPage::refresh()
} }
table->setCellWidget(i, 0, record2.icon); table->setCellWidget(i, 0, record2.icon);
record2.settings = new MiniButton(software.orig_name, "settings");
record2.settings->setText(QString::fromLocal8Bit("设置")); if(!software.locked)
record2.settings->setMaximumSize(60, 40); {
QMetaObject::Connection connect1=connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2); record2.settings = new MiniButton(software.orig_name, "settings");
connections << connect1; record2.settings->setText(QString::fromLocal8Bit("设置"));
QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); record2.settings->setMaximumSize(60, 40);
connections << connect2; QMetaObject::Connection connect1 = connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2);
connections << connect1;
QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2);
connections << connect2;
table->setCellWidget(i, 7, record2.settings);
}
record2.open = new MiniButton(software.orig_name, "open"); record2.open = new MiniButton(software.orig_name, "open");
record2.open->setText(QString::fromLocal8Bit("打开")); record2.open->setText(QString::fromLocal8Bit("打开"));
record2.open->setMaximumSize(60, 40); record2.open->setMaximumSize(60, 40);
@ -203,7 +212,6 @@ void ApplicationManagerPage::refresh()
table->setItem(i, 6, check_box_item); table->setItem(i, 6, check_box_item);
table->setCellWidget(i, 6, record2.check_box); table->setCellWidget(i, 6, record2.check_box);
check_box_item->setTextAlignment(Qt::AlignCenter); check_box_item->setTextAlignment(Qt::AlignCenter);
table->setCellWidget(i, 7, record2.settings);
table->setCellWidget(i, 8, record2.open); table->setCellWidget(i, 8, record2.open);
rows.insert(software.orig_name, record2); rows.insert(software.orig_name, record2);
table->resizeColumnToContents(0); table->resizeColumnToContents(0);

View File

@ -13,5 +13,7 @@ extern MainWindowLayout *mainWindowLayout;
extern QString url_param; extern QString url_param;
extern bool autostart; extern bool autostart;
extern bool agree; extern bool agree;
extern QString background_color;
extern QString text_color;
extern ApplicationManager *application_manager; extern ApplicationManager *application_manager;
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H #endif //OFFICEASSISTANT_GLOBALVARIABLES_H

View File

@ -6,7 +6,6 @@
MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent) MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent)
{ {
this->orig_name = orig_name; this->orig_name = orig_name;
q_color.setNamedColor(DEFAULT_BACKGROUND_COLOR);
this->op = op; this->op = op;
connect(this, &MiniButton::click, this, &MiniButton::onclick2); connect(this, &MiniButton::click, this, &MiniButton::onclick2);
@ -15,11 +14,6 @@ MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent)
: QPushButton(parent) : QPushButton(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
q_color.setNamedColor(DEFAULT_COVER_COLOR);
QString style_sheet = "MiniButton:{background-color:";
style_sheet += DEFAULT_TEXT_COLOR;
style_sheet += ";}";
setStyleSheet(style_sheet);
connect(this, &MiniButton::click, this, &MiniButton::onclick1); connect(this, &MiniButton::click, this, &MiniButton::onclick1);
this->button_struct = button_struct; this->button_struct = button_struct;
} }
@ -33,14 +27,15 @@ void MiniButton::paintEvent(QPaintEvent* event)
setContentsMargins(0, 0, 0, 0); setContentsMargins(0, 0, 0, 0);
QRect rect(0, 0, this->width(), this->height()); QRect rect(0, 0, this->width(), this->height());
QPainter painter(this); QPainter painter(this);
q_color.setNamedColor(background_color);
painter.fillRect(rect, q_color); painter.fillRect(rect, q_color);
int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2; int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2;
int text_y = (height()- TEXT_SIZE * scale * 3)/2; int text_y = (height()- TEXT_SIZE * scale * 3)/2;
QFont ft; QFont ft;
ft.setPixelSize(TEXT_SIZE); ft.setPixelSize(TEXT_SIZE);
QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3); QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3);
painter.setPen(DEFAULT_TEXT_COLOR); painter.setPen(text_color);
painter.drawText(text_rect, Qt::AlignCenter, text()); painter.drawText(text_rect, Qt::AlignCenter, text());
} }

View File

@ -155,8 +155,8 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
timer.stop(); timer.stop();
buffer = new QByteArray; buffer = new QByteArray;
delete request_logo; delete request_logo;
reply->close();
if (downloadSuccess == true) { if (downloadSuccess == true&& reply->error() == QNetworkReply::NoError) {
*buffer = reply->readAll(); *buffer = reply->readAll();
QFile logo(QApplication::applicationDirPath() + DEFAULT_LOGO); QFile logo(QApplication::applicationDirPath() + DEFAULT_LOGO);
if (logo.open(QIODevice::WriteOnly)) { if (logo.open(QIODevice::WriteOnly)) {
@ -164,10 +164,11 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
logo.close(); logo.close();
} }
buffer->clear(); buffer->clear();
reply->close();
} }
delete manager; delete manager;
manager = nullptr; manager = nullptr;
} }
void NavBar::storeToBuffer() { void NavBar::storeToBuffer() {
buffer = new QByteArray; buffer = new QByteArray;

View File

@ -31,6 +31,8 @@
#pragma comment(lib, "Qt5Network.lib") #pragma comment(lib, "Qt5Network.lib")
#endif #endif
#pragma comment(lib,"comsuppw.lib") #pragma comment(lib,"comsuppw.lib")
QString background_color;
QString text_color;
//读取注册表获取MachineUUID //读取注册表获取MachineUUID
bool IsWin11AndLater() bool IsWin11AndLater()
{ {
@ -187,12 +189,9 @@ RequestBodyBase::RequestBodyBase(){
void ConfigRequest::sendRequest(ConfigResponse *configResponse) { void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
timer = new QTimer(this); timer = new QTimer(this);
if(agree) QJsonObject obj_root = qJsonDocument.object();
{ obj_root.insert("autostart", autostart);
QJsonObject obj_root = qJsonDocument.object(); qJsonDocument.setObject(obj_root);
obj_root.insert("autostart", autostart);
qJsonDocument.setObject(obj_root);
}
QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo; QNetworkRequest requestInfo;
@ -238,8 +237,13 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
array = obj_root.value("data").toObject().value("menu").toArray(); array = obj_root.value("data").toObject().value("menu").toArray();
QJsonObject obj_data = obj_root.value("data").toObject(); QJsonObject obj_data = obj_root.value("data").toObject();
QString basic_str= obj_data.value("basic").toString(); if(!obj_data.value("basic").isObject())
QJsonObject obj_basic=QJsonDocument::fromJson(basic_str.toUtf8()).object(); {
configResponse->succeed=false;
delete timer;
return;
}
QJsonObject obj_basic=obj_data.value("basic").toObject();
configResponse->basic.logo_url = obj_basic.value("logo").toString(); configResponse->basic.logo_url = obj_basic.value("logo").toString();
configResponse->basic.device_id = obj_basic.value("device_id").toString(); configResponse->basic.device_id = obj_basic.value("device_id").toString();
configResponse->basic.dev_id = obj_basic.value("dev_id").toString(); configResponse->basic.dev_id = obj_basic.value("dev_id").toString();
@ -247,6 +251,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
configResponse->basic.backgroud_color = obj_basic.value("backgroud_color").toString(); configResponse->basic.backgroud_color = obj_basic.value("backgroud_color").toString();
configResponse->basic.title_color = obj_basic.value("title_color").toString(); configResponse->basic.title_color = obj_basic.value("title_color").toString();
configResponse->basic.title_cover_color = obj_basic.value("title_cover_color").toString(); configResponse->basic.title_cover_color = obj_basic.value("title_cover_color").toString();
auto i=0; auto i=0;
for(auto value:array){ for(auto value:array){
QJsonObject object=value.toObject(); QJsonObject object=value.toObject();

View File

@ -673,6 +673,7 @@ bool SQLiteHelper::update_software()
} }
else else
{ {
public_programs_list[key].img.replace(QApplication::applicationDirPath(), "");
sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status,is_navbar,is_elite) values " sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status,is_navbar,is_elite) values "
"(:sort,:app_id,:locked,:type,:category_id,:name,:orig_name,:version,:dev,:create_time,:use_time,:op,:func,:path,:url,:status,:is_navbar,:is_elite); "; "(:sort,:app_id,:locked,:type,:category_id,:name,:orig_name,:version,:dev,:create_time,:use_time,:op,:func,:path,:url,:status,:is_navbar,:is_elite); ";
query.prepare(sql); query.prepare(sql);
@ -760,13 +761,13 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
QSqlQuery query(db); QSqlQuery query(db);
QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;"; QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;";
QString background_color;
QString title_color; QString title_color;
QString title_cover_color; QString title_cover_color;
QList<Button> buttons = config_response->buttons; QList<Button> buttons = config_response->buttons;
if (config_response->succeed) if (config_response->succeed)
{ {
background_color = config_response->basic.backgroud_color; background_color = config_response->basic.backgroud_color;
text_color = config_response->basic.title_color;
title_color = config_response->basic.title_color; title_color = config_response->basic.title_color;
title_cover_color = config_response->basic.title_cover_color; title_cover_color = config_response->basic.title_cover_color;
@ -791,11 +792,13 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object(); QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object();
background_color = obj_basic.value("backgroud_color").toString(); background_color = obj_basic.value("backgroud_color").toString();
title_color = obj_basic.value("title_color").toString(); title_color = obj_basic.value("title_color").toString();
text_color = obj_basic.value("title_color").toString();
title_cover_color = obj_basic.value("title_cover_color").toString(); title_cover_color = obj_basic.value("title_cover_color").toString();
} }
else { else {
background_color = DEFAULT_BACKGROUND_COLOR; background_color = DEFAULT_BACKGROUND_COLOR;
title_color = DEFAULT_TEXT_COLOR; title_color = DEFAULT_TEXT_COLOR;
text_color = DEFAULT_TEXT_COLOR;
title_cover_color = DEFAULT_COVER_COLOR; title_cover_color = DEFAULT_COVER_COLOR;
} }
} }
@ -920,8 +923,8 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
}else }else
{ {
insert_software(menu.name, menu.orig_name, "", QString::number(menu.sort), insert_software(menu.name, menu.orig_name, "", QString::number(menu.sort),
categories, QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg", categories, DEFAULT_SVG_PATH + menu.img_name + ".svg",
QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png", menu.type, DEFAULT_PNG_PATH + menu.img_name + ".png", menu.type,
menu.locked, menu.op, menu.func, menu.url, menu.is_navbar, menu.is_elite, menu.dev); menu.locked, menu.op, menu.func, menu.url, menu.is_navbar, menu.is_elite, menu.dev);
} }
@ -1008,7 +1011,15 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
delete render_image_cover; delete render_image_cover;
} }
} }
button_struct.png = new QImage(query.value("png").toString()); QFile png(QApplication::applicationDirPath() + query.value("img").toString());
if(png.exists())
{
button_struct.png = new QImage(QApplication::applicationDirPath() + query.value("img").toString());
}else
{
button_struct.png = new QImage(QApplication::applicationDirPath()+DEFAULT_PNG);
}
button_struct.image = image; button_struct.image = image;
button_struct.image_cover = image_cover; button_struct.image_cover = image_cover;
button_struct.background_color = background_color; button_struct.background_color = background_color;
@ -1102,7 +1113,15 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs,QString back
delete render_image_cover; delete render_image_cover;
} }
} }
button_struct.png = new QImage(query.value("png").toString()); QFile png(QApplication::applicationDirPath() + query.value("img").toString());
if (png.exists())
{
button_struct.png = new QImage(QApplication::applicationDirPath() + query.value("img").toString());
}
else
{
button_struct.png = new QImage(QApplication::applicationDirPath() + DEFAULT_PNG);
}
button_struct.image = image; button_struct.image = image;
button_struct.image_cover = image_cover; button_struct.image_cover = image_cover;
button_struct.background_color = background_color; button_struct.background_color = background_color;
@ -1444,7 +1463,7 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
record.id = query.value("id").toInt(); record.id = query.value("id").toInt();
record.logo=query.value("logo").toString(); record.logo=query.value("logo").toString();
record.is_navbar=query.value("is_navbar").toBool(); record.is_navbar=query.value("is_navbar").toBool();
record.img = query.value("img").toString(); record.img = QApplication::applicationDirPath()+query.value("img").toString();
record.sort = query.value("sort").toInt(); record.sort = query.value("sort").toInt();
record.app_id = query.value("app_id").toString(); record.app_id = query.value("app_id").toString();
record.locked = query.value("locked").toBool(); record.locked = query.value("locked").toBool();