几乎完成
This commit is contained in:
@ -32,6 +32,9 @@
|
||||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||
#include <experimental/filesystem>
|
||||
namespace fs= std::experimental::filesystem;
|
||||
|
||||
|
||||
|
||||
bool getMenu(std::wstring &path_str,QHash<QString,QString> *paths)
|
||||
{
|
||||
fs::directory_iterator* it = new fs::directory_iterator(path_str);
|
||||
@ -139,39 +142,6 @@ bool SQLiteHelper::update_software()
|
||||
{
|
||||
HKEY hKeyUninstall = nullptr;
|
||||
QHash<QString, QString>* paths = new QHash<QString, QString>;
|
||||
/*QSqlQuery query;
|
||||
QString sql = "select * from kmd_menu;";
|
||||
query.exec(sql);
|
||||
while(query.next())
|
||||
{
|
||||
Record record;
|
||||
record.id = query.value("id").toInt();
|
||||
record.sort = query.value("sort").toInt();
|
||||
record.app_id = query.value("app_id").toString();
|
||||
record.locked = query.value("locked").toBool();
|
||||
record.type = query.value("type").toString();
|
||||
record.category_id = query.value("category_id").toString();
|
||||
record.name = query.value("name").toString();
|
||||
record.orig_name = query.value("orig_name").toString();
|
||||
record.version = query.value("version").toString();
|
||||
record.dev = query.value("dev").toString();
|
||||
record.create_time = query.value("create_time").toLongLong();
|
||||
record.use_time = query.value("use_time").toLongLong();
|
||||
record.op = query.value("op").toString();
|
||||
record.func = query.value("func").toString();
|
||||
record.path = query.value("path").toString();
|
||||
record.url = query.value("url").toString();
|
||||
QStringList path_list = record.path.split("\\");
|
||||
path_list.removeLast();
|
||||
QString path;
|
||||
for(auto str : path_list)
|
||||
{
|
||||
path.append(str);
|
||||
path.append("\\");
|
||||
}
|
||||
path.remove(path.length() - 1, 1);
|
||||
records.insert(path, record);
|
||||
}*/
|
||||
//开始菜单中已安装软件列表
|
||||
WCHAR path[MAX_PATH];
|
||||
HRESULT hr = SHGetFolderPathW(nullptr, CSIDL_COMMON_PROGRAMS, nullptr, 0, path);//获取ProgramData中开始菜单的路径
|
||||
@ -622,31 +592,7 @@ bool SQLiteHelper::update_software()
|
||||
}
|
||||
}
|
||||
|
||||
//对比两个路径,找出公共部分(划掉)
|
||||
QHash<QString, Record> public_programs_list;
|
||||
/*for(auto path:*paths)
|
||||
{
|
||||
QStringList path_list = path.split("\\");
|
||||
path_list.removeLast();
|
||||
QString path2;
|
||||
for(auto str : path_list)
|
||||
{
|
||||
path2.append(str);
|
||||
path2.append("\\");
|
||||
}
|
||||
if(reg_records.contains(path2))
|
||||
{
|
||||
reg_records[path2].path = path;
|
||||
public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]);
|
||||
}
|
||||
path2.remove(path2.length() - 1, 1);
|
||||
if(reg_records.contains(path2))
|
||||
{
|
||||
reg_records[path2].path = path;
|
||||
public_programs_list.insert(reg_records[path2].orig_name, reg_records[path2]);
|
||||
}
|
||||
}
|
||||
delete paths;*/
|
||||
for (auto key : reg_records.keys())
|
||||
{
|
||||
public_programs_list.insert(reg_records[key].orig_name, reg_records[key]);
|
||||
@ -674,7 +620,8 @@ bool SQLiteHelper::update_software()
|
||||
obj.insert("initial_position", find2.value("initial_position").toString());
|
||||
obj.insert("logo", find2.value("logo").toString());
|
||||
obj.insert("status", find2.value("status").toBool());
|
||||
obj.insert("is_delete", find2.value("is_delete").toBool());
|
||||
obj.insert("is_navbar", find2.value("is_navbar").toBool());
|
||||
obj.insert("is_elite", find2.value("is_elite").toBool());
|
||||
array.append(obj);
|
||||
}
|
||||
}
|
||||
@ -695,7 +642,7 @@ bool SQLiteHelper::update_software()
|
||||
}
|
||||
for(auto key : public_programs_list.keys())
|
||||
{
|
||||
|
||||
QSqlQuery query(db);
|
||||
QString sql_find = "select sort from kmd_menu where orig_name='";
|
||||
sql_find += key;
|
||||
sql_find += "';";
|
||||
@ -726,76 +673,32 @@ bool SQLiteHelper::update_software()
|
||||
}
|
||||
else
|
||||
{
|
||||
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) values (";
|
||||
sql += "50";
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].app_id;
|
||||
sql += "',";
|
||||
sql += QString::number(public_programs_list[key].locked);
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].type;
|
||||
sql += "','";
|
||||
sql += QString::number(ALL, 10);
|
||||
sql += ",";
|
||||
sql += QString::number(SOFT, 10);
|
||||
sql += ",";
|
||||
sql += QString::number(OTHERS, 10);
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].name;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].orig_name;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].version;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].dev;
|
||||
sql += "',";
|
||||
sql += QString::number(public_programs_list[key].create_time);
|
||||
sql += ",";
|
||||
sql += QString::number(public_programs_list[key].use_time);
|
||||
sql += ",'";
|
||||
sql += public_programs_list[key].op;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].func;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].path;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].url;
|
||||
sql += "','";
|
||||
sql += public_programs_list[key].status;
|
||||
sql += "');";
|
||||
bool categories[8] = { false };
|
||||
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); ";
|
||||
query.prepare(sql);
|
||||
query.bindValue(":sort", 50);
|
||||
query.bindValue(":app_id", public_programs_list[key].app_id);
|
||||
query.bindValue(":locked", public_programs_list[key].locked);
|
||||
query.bindValue(":type", public_programs_list[key].type);
|
||||
query.bindValue(":category_id", public_programs_list[key].category_id);
|
||||
query.bindValue(":name", public_programs_list[key].name);
|
||||
query.bindValue(":orig_name", public_programs_list[key].orig_name);
|
||||
query.bindValue(":version", public_programs_list[key].version);
|
||||
query.bindValue(":dev", public_programs_list[key].dev);
|
||||
query.bindValue(":create_time", public_programs_list[key].create_time);
|
||||
query.bindValue(":use_time", public_programs_list[key].use_time);
|
||||
query.bindValue(":op", public_programs_list[key].op);
|
||||
query.bindValue(":func", public_programs_list[key].func);
|
||||
query.bindValue(":path", public_programs_list[key].path);
|
||||
query.bindValue(":url", public_programs_list[key].url);
|
||||
query.bindValue(":is_navbar", public_programs_list[key].is_navbar);
|
||||
query.bindValue(":is_elite", public_programs_list[key].is_elite);
|
||||
query.bindValue(":status", true);
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
categories[ALL - 1] = true;
|
||||
categories[SOFT - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
update_total();
|
||||
if(!query.exec(sql))
|
||||
{
|
||||
QSqlQuery rollback("rollback;");
|
||||
@ -817,37 +720,10 @@ bool SQLiteHelper::update_software()
|
||||
del.prepare("update kmd_menu set status=0 where orig_name=:orig_name;");
|
||||
del.bindValue(":orig_value", find.value("orig_name"));
|
||||
del.exec();
|
||||
bool categories[8] = { false };
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
categories[ALL - 1] = true;
|
||||
categories[SOFT - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query2.bindValue(":total", total - 1);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -883,10 +759,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;";
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString background_color;
|
||||
QString title_color;
|
||||
QString title_cover_color;
|
||||
@ -896,6 +769,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
background_color = config_response->basic.backgroud_color;
|
||||
title_color = config_response->basic.title_color;
|
||||
title_cover_color = config_response->basic.title_cover_color;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -913,25 +787,11 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
|
||||
array = obj_root.value("data").toObject().value("menu").toArray();
|
||||
qDebug() << array;
|
||||
QJsonObject obj_basic = obj_root.value("data").toObject().value("basic").toObject();
|
||||
QJsonObject obj_data = obj_root.value("data").toObject();
|
||||
QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object();
|
||||
background_color = obj_basic.value("backgroud_color").toString();
|
||||
title_color = obj_basic.value("title_color").toString();
|
||||
title_cover_color = obj_basic.value("title_cover_color").toString();
|
||||
auto i = 0;
|
||||
for (auto value : array) {
|
||||
QJsonObject object = value.toObject();
|
||||
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.orig_name = object.value("orig_name").toString();
|
||||
button.op = object.value("op").toString();
|
||||
button.func = object.value("func").toString();
|
||||
button.url = object.value("url").toString();
|
||||
buttons << button;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
background_color = DEFAULT_BACKGROUND_COLOR;
|
||||
@ -940,13 +800,14 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray* buffer = new QByteArray;
|
||||
QHash<QString, ButtonStruct> button_map;
|
||||
QNetworkAccessManager* manager;
|
||||
for (auto menu : buttons)
|
||||
{
|
||||
ButtonStruct button_struct;
|
||||
button_struct.text = menu.title;
|
||||
button_struct.text = menu.name;
|
||||
button_struct.orig_name = menu.orig_name;
|
||||
button_struct.op = menu.op;
|
||||
button_struct.func = menu.func;
|
||||
@ -968,8 +829,9 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
*buffer = reply->readAll();
|
||||
delete request_logo;
|
||||
reply->close();
|
||||
QString svg_path = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg";;
|
||||
if ((reply->error() == QNetworkReply::NoError)&&(downloadSuccess == true)) {
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg");
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg");
|
||||
if (file.open(QIODevice::Text | QIODevice::WriteOnly))
|
||||
{
|
||||
file.write(*buffer);
|
||||
@ -978,8 +840,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.orig_name + ".svg";
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name+".svg";
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
@ -1000,37 +861,78 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
}
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
|
||||
QSvgRenderer* render_image = new QSvgRenderer(*buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(*buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
QUrl url_png(menu.png);
|
||||
QNetworkRequest* request_png = new QNetworkRequest(url_logo);
|
||||
manager = new QNetworkAccessManager;
|
||||
reply = manager->get(*request_png);
|
||||
QTimer timer_png;
|
||||
timer_png.setInterval(5000);
|
||||
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
|
||||
connect(&timer_png, &QTimer::timeout, this, &SQLiteHelper::cancelDownload);
|
||||
eventLoop.exec();
|
||||
timer_png.stop();
|
||||
QByteArray buffer_png;
|
||||
buffer_png = reply->readAll();
|
||||
delete request_png;
|
||||
reply->close();
|
||||
QString png_path = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";;
|
||||
if ((reply->error() == QNetworkReply::NoError) && (downloadSuccess == true))
|
||||
{
|
||||
QFile file(QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png");
|
||||
if (file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
file.write(buffer_png);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_PNG_PATH + menu.img_name + ".png";
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
buffer_png = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_PNG;
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
buffer_png = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
for(int i=0;i<CATEGORIES_NUM;i++)
|
||||
{
|
||||
if (menu.categroy_id.contains(QString::number(i+1)))
|
||||
{
|
||||
categories[i] = true;
|
||||
}
|
||||
}
|
||||
if(menu.is_delete)
|
||||
{
|
||||
delete_software(menu.orig_name);
|
||||
}else
|
||||
{
|
||||
insert_software(menu.name, menu.orig_name, "", QString::number(menu.sort),
|
||||
categories, QApplication::applicationDirPath() + DEFAULT_SVG_PATH + menu.img_name + ".svg",
|
||||
QApplication::applicationDirPath() + 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);
|
||||
}
|
||||
|
||||
}
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + "/images/svg/" + query.value("orig_name").toString() + ".svg";
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
@ -1095,6 +997,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
delete render_image_cover;
|
||||
}
|
||||
}
|
||||
button_struct.png = new QImage(query.value("png").toString());
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
@ -1102,8 +1005,101 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
}
|
||||
QSqlQuery begin_query(db);
|
||||
begin_query.exec("BEGIN;");
|
||||
update_total();
|
||||
QSqlQuery commit_query(db);
|
||||
commit_query.exec("COMMIT;");
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs,QString background_color,QString title_color,QString title_cover_color)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;";
|
||||
if (!query.exec(sql))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg";
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
button_struct.orig_name = query.value("orig_name").toString();
|
||||
button_struct.op = query.value("op").toString();
|
||||
button_struct.func = query.value("func").toString();
|
||||
button_struct.url = query.value("url").toString();
|
||||
button_struct.initial_position = query.value("initial_position").toString();
|
||||
QImage* image = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QImage* image_cover = new QImage(200, 200, QImage::Format_ARGB32);
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QByteArray svg_buffer = file.readAll();
|
||||
file.close();
|
||||
QSvgRenderer* render_image = new QSvgRenderer(svg_buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = QApplication::applicationDirPath() + DEFAULT_IMAGE;
|
||||
QFile file(icon);
|
||||
if (file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QByteArray svg_buffer = file.readAll();
|
||||
file.close();
|
||||
QSvgRenderer* render_image = new QSvgRenderer(svg_buffer);
|
||||
QPainter painter_image(image);
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image.fillRect(image->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image->render(&painter_image);
|
||||
//修改颜色
|
||||
QDomDocument doc;
|
||||
doc.setContent(svg_buffer);
|
||||
SetSVGBackColor(doc.documentElement(), "path", "fill", title_cover_color);
|
||||
QSvgRenderer* render_image_cover = new QSvgRenderer(doc.toByteArray());
|
||||
QPainter painter_image_cover(image_cover);
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
|
||||
painter_image_cover.fillRect(image_cover->rect(), Qt::transparent); // 填充透明色
|
||||
painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
|
||||
render_image_cover->render(&painter_image_cover);
|
||||
|
||||
delete render_image;
|
||||
delete render_image_cover;
|
||||
}
|
||||
}
|
||||
button_struct.png = new QImage(query.value("png").toString());
|
||||
button_struct.image = image;
|
||||
button_struct.image_cover = image_cover;
|
||||
button_struct.background_color = background_color;
|
||||
button_struct.text_color = QColor(title_color);
|
||||
button_struct.text_cover_color = QColor(title_cover_color);
|
||||
*button_structs << button_struct;
|
||||
}
|
||||
QSqlQuery begin_query(db);
|
||||
begin_query.exec("BEGIN;");
|
||||
update_total();
|
||||
QSqlQuery commit_query(db);
|
||||
commit_query.exec("COMMIT;");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1122,7 +1118,7 @@ bool SQLiteHelper::update_app()
|
||||
{
|
||||
if(fs::is_directory(dir))
|
||||
{
|
||||
QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config.json";
|
||||
QString config_path = QString::fromWCharArray(dir.path().wstring().c_str())+"/kmd_config/config.json";
|
||||
config_path.replace("/", "\\");
|
||||
QFile config_file(config_path);
|
||||
if(!config_file.open(QIODevice::Text|QIODevice::ReadOnly))
|
||||
@ -1150,7 +1146,7 @@ bool SQLiteHelper::update_app()
|
||||
QString sql = "insert into kmd_menu "
|
||||
"(sort, app_id, locked, type, category_id, name, orig_name,"
|
||||
" version, dev, create_time, op, func, path, url, "
|
||||
"logo, initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
"logo, initial_position,status,img,is_navbar,is_elite) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(50);
|
||||
query.addBindValue(obj_root.value("app_id").toString());
|
||||
@ -1169,32 +1165,14 @@ bool SQLiteHelper::update_app()
|
||||
query.addBindValue(obj_root.value("logo").toString());
|
||||
query.addBindValue(obj_root.value("initial_position").toString());
|
||||
query.addBindValue(obj_root.value("status").toBool());
|
||||
query.addBindValue(obj_root.value("img").toString());
|
||||
query.addBindValue(false);
|
||||
query.addBindValue(false);
|
||||
query.exec();
|
||||
bool categories[8]={false};
|
||||
bool categories[CATEGORIES_NUM]={false};
|
||||
categories[ALL - 1] = true;
|
||||
categories[INNER - 1] = true;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
}
|
||||
|
||||
|
||||
@ -1225,66 +1203,103 @@ bool SQLiteHelper::get_buttons(QList<ButtonStruct> &buttons)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories) {
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort,bool *categories, QString logo, QString img,QString type,bool locked,QString op,QString func,QString url,bool is_navbar,bool is_elite,QString dev) {
|
||||
QSqlQuery begin(db);
|
||||
begin.exec("BEGIN;");
|
||||
QSqlQuery query(db);
|
||||
QString categories_str="";
|
||||
for(int i=0;i<8;i++)
|
||||
categories[ALL - 1] = true;
|
||||
if(is_elite)
|
||||
{
|
||||
categories[ELITE - 1] = true;
|
||||
}
|
||||
for(int i=0;i< CATEGORIES_NUM;i++)
|
||||
{
|
||||
if(categories[i])
|
||||
{
|
||||
categories_str = categories_str + QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
if(logo.isEmpty())
|
||||
{
|
||||
logo = QApplication::applicationDirPath()+DEFAULT_IMAGE;
|
||||
}
|
||||
if(img.isEmpty())
|
||||
{
|
||||
img = QApplication::applicationDirPath()+DEFAULT_PNG;
|
||||
}
|
||||
QSqlQuery query_sel(db);
|
||||
query_sel.prepare("select id from kmd_menu where orig_name = :orig_name;");
|
||||
query_sel.bindValue(":orig_name",orig_name);
|
||||
if(query_sel.exec())
|
||||
{
|
||||
if(query_sel.next())
|
||||
{
|
||||
QString sql="update kmd_menu"
|
||||
" set sort=:sort,locked=:locked,type=:type,category_id=:category_id,"
|
||||
"name=:name,orig_name=:orig_name,op=:op,"
|
||||
"func=:func,path=:path,url=:url,logo=:logo,img=:img,is_navbar=:is_navbar,is_elite=:is_elite,dev=:dev where orig_name=:orig_name;";
|
||||
query.prepare(sql);
|
||||
query.bindValue(":sort",sort);
|
||||
query.bindValue(":locked",locked);
|
||||
query.bindValue(":type",type);
|
||||
query.bindValue(":category_id",categories_str);
|
||||
query.bindValue(":name",name);
|
||||
query.bindValue(":orig_name",orig_name);
|
||||
query.bindValue(":op",op);
|
||||
query.bindValue(":func",func);
|
||||
query.bindValue(":path",path);
|
||||
query.bindValue(":url",url);
|
||||
query.bindValue(":logo",logo);
|
||||
query.bindValue(":img",img);
|
||||
query.bindValue(":is_navbar",is_navbar);
|
||||
query.bindValue(":is_elite", is_elite);
|
||||
query.bindValue(":dev", dev);
|
||||
if(!query.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
QString sql = "insert into kmd_menu "
|
||||
"(sort, app_id, locked, type, category_id, name, orig_name,"
|
||||
" create_time, op, func, path, url, "
|
||||
"initial_position,status) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
"initial_position,status,logo,img,is_navbar,is_elite,dev) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
|
||||
query.prepare(sql);
|
||||
query.addBindValue(sort.toInt());
|
||||
query.addBindValue("");
|
||||
query.addBindValue(false);
|
||||
query.addBindValue("app");
|
||||
query.addBindValue(locked);
|
||||
query.addBindValue(type);
|
||||
query.addBindValue(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(orig_name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
query.addBindValue("soft");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(op);
|
||||
query.addBindValue(func);
|
||||
query.addBindValue(path);
|
||||
query.addBindValue("");
|
||||
query.addBindValue(url);
|
||||
query.addBindValue("");
|
||||
query.addBindValue(true);
|
||||
query.addBindValue(logo);
|
||||
query.addBindValue(img);
|
||||
query.addBindValue(is_navbar);
|
||||
query.addBindValue(is_elite);
|
||||
query.addBindValue(dev);
|
||||
if(!query.exec())
|
||||
{
|
||||
//QMessageBox::critical(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("写入数据库失败"));
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
qDebug()<< query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("COMMIT;");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1293,6 +1308,20 @@ bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery work(db);
|
||||
work.exec("begin;");
|
||||
QSqlQuery query2(db);
|
||||
bool ok=query2.exec("update kmd_category set status=0;");
|
||||
Categrory categrory_all;
|
||||
categrory_all.id = ALL;
|
||||
categrory_all.name = QString::fromLocal8Bit("全部");
|
||||
categrory_all.sort = 0;
|
||||
categrory_all.display = true;
|
||||
categrories << categrory_all;
|
||||
Categrory categrory_elite;
|
||||
categrory_elite.id = ELITE;
|
||||
categrory_elite.name = QString::fromLocal8Bit("推荐");
|
||||
categrory_elite.sort = 1;
|
||||
categrory_elite.display = true;
|
||||
categrories << categrory_elite;
|
||||
for(Categrory categrory:categrories)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
@ -1355,16 +1384,12 @@ bool SQLiteHelper::get_category(QList<Categrory>& categrories,bool is_edit,bool
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category;"))
|
||||
if (!query.exec("select id,name,status,sort,total from kmd_category where status=1 order by sort;"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
if (query.value("name") == QString::fromLocal8Bit("全部"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Categrory categrory;
|
||||
categrory.name = query.value("name").toString();
|
||||
categrory.id = query.value("id").toInt();
|
||||
@ -1382,13 +1407,17 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
|
||||
QString sql;
|
||||
if(category==ALL)
|
||||
{
|
||||
sql = "select * from kmd_menu where status=1 and not type='app_manage' and not op='self' order by sort;";
|
||||
sql = "select * from kmd_menu where type='app' and status=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
else if(category==ELITE)
|
||||
{
|
||||
sql = "select * from kmd_menu where type='app' and status=1 and is_elite=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = "select * from kmd_menu where category_id like '%";
|
||||
sql += QString::number(category, 10);
|
||||
sql += "%' and not type='app_manage' and status=1 order by sort;";
|
||||
sql += "%' and type='app' and status=1 order by is_navbar desc,sort asc;";
|
||||
}
|
||||
QSqlQuery query(db);
|
||||
if(!query.exec(sql))
|
||||
@ -1400,6 +1429,9 @@ bool SQLiteHelper::get_all_software(QList<Record> &softwares,int category)
|
||||
|
||||
Record record;
|
||||
record.id = query.value("id").toInt();
|
||||
record.logo=query.value("logo").toString();
|
||||
record.is_navbar=query.value("is_navbar").toBool();
|
||||
record.img = query.value("img").toString();
|
||||
record.sort = query.value("sort").toInt();
|
||||
record.app_id = query.value("app_id").toString();
|
||||
record.locked = query.value("locked").toBool();
|
||||
@ -1433,7 +1465,7 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
@ -1450,47 +1482,35 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
}
|
||||
qDebug() << query.lastError();
|
||||
QSqlQuery categories_sql(db);
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId;");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
qDebug() << query2.lastError();
|
||||
if (!query2.exec())
|
||||
{
|
||||
query.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,type=:type where orig_name=:orig_name;";
|
||||
QString sql = "update kmd_menu set name=:name,path=:path,sort=:sort,category_id=:categories,is_navbar=:is_navbar where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
query.prepare(sql);
|
||||
query.bindValue(":name", name);
|
||||
query.bindValue(":path", path);
|
||||
query.bindValue(":sort", sort);
|
||||
QString categories_str = "";
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
if (categories[i])
|
||||
{
|
||||
categories_str += QString::number(i + 1) + ",";
|
||||
}
|
||||
}
|
||||
query.bindValue(":type", type);
|
||||
if(type=="navbar")
|
||||
{
|
||||
query.bindValue(":is_navbar", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
query.bindValue(":is_navbar", false);
|
||||
}
|
||||
query.bindValue(":categories", categories_str);
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
@ -1499,44 +1519,27 @@ bool SQLiteHelper::edit_software(QString name, QString orig_name, QString path,
|
||||
}
|
||||
qDebug() << query.lastError();
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if (categories[i])
|
||||
{
|
||||
query2.prepare("select total from kmd_category where id=:id;");
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
if (query2.next())
|
||||
{
|
||||
QSqlQuery total(db);
|
||||
QSqlQuery query3(db);
|
||||
QString total_sql = "select id from kmd_menu where category_id like '%";
|
||||
total_sql += QString::number(i + 1);
|
||||
total_sql += "%';";
|
||||
total.exec(total_sql);
|
||||
query3.prepare("update kmd_category set total=:total where id=:id;");
|
||||
query3.bindValue(":total", total.size()+1);
|
||||
query3.bindValue(":id", i + 1);
|
||||
if (!query3.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("rollback;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("commit;");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SQLiteHelper::delete_software(QString orig_name)
|
||||
{
|
||||
QSqlQuery query(db);;
|
||||
query.prepare("delete from kmd_menu where orig_name=:orig_name;");
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if(!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
||||
QString sql = "select * from kmd_menu where orig_name=:orig_name;";
|
||||
QSqlQuery query(db);
|
||||
@ -1567,3 +1570,53 @@ bool SQLiteHelper::get_a_software(QString orig_name, Record2 *record) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//警告:这个函数必须用于事务中
|
||||
inline bool SQLiteHelper::update_total()
|
||||
{
|
||||
|
||||
for (int i = 0; i < CATEGORIES_NUM; i++)
|
||||
{
|
||||
QSqlQuery query2(db);
|
||||
if(i==ELITE-1)
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE is_elite=1 AND type='app';");
|
||||
}
|
||||
else if(i==ALL-1)
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE type='app';");
|
||||
}
|
||||
else
|
||||
{
|
||||
query2.prepare("SELECT COUNT(*) AS total FROM kmd_menu WHERE category_id LIKE :categoryId AND type='app';");
|
||||
query2.bindValue(":categoryId", "%" + QString::number(i + 1) + "%");
|
||||
}
|
||||
if (query2.exec() && query2.first())
|
||||
{
|
||||
int total = query2.value("total").toInt();
|
||||
query2.prepare("UPDATE kmd_category SET total=:total WHERE id=:id;");
|
||||
query2.bindValue(":total", total);
|
||||
query2.bindValue(":id", i + 1);
|
||||
if (!query2.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLiteHelper::use_software(QString orig_name)
|
||||
{
|
||||
QSqlQuery query(db);
|
||||
query.prepare("update kmd_menu set use_time=:use_time where orig_name=:orig_name;");
|
||||
query.bindValue(":use_time", QDateTime::currentDateTime().toTime_t());
|
||||
query.bindValue(":orig_name", orig_name);
|
||||
if (!query.exec())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user