阶段性完成,还差独立浏览器和几个别的需求。
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <fstream>
|
||||
#include <QFile>
|
||||
#include "applicationmanager.h"
|
||||
#define MAX_KEY_LENGTH 255
|
||||
@ -30,6 +31,7 @@
|
||||
#pragma comment (lib,"Shell32.lib")
|
||||
|
||||
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||
#include <iostream>
|
||||
#include <experimental/filesystem>
|
||||
namespace fs= std::experimental::filesystem;
|
||||
|
||||
@ -768,6 +770,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
{
|
||||
background_color = config_response->basic.backgroud_color;
|
||||
text_color = config_response->basic.title_color;
|
||||
text_cover_color = config_response->basic.title_cover_color;
|
||||
title_color = config_response->basic.title_color;
|
||||
title_cover_color = config_response->basic.title_cover_color;
|
||||
|
||||
@ -789,7 +792,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
array = obj_root.value("data").toObject().value("menu").toArray();
|
||||
qDebug() << array;
|
||||
QJsonObject obj_data = obj_root.value("data").toObject();
|
||||
QJsonObject obj_basic=QJsonDocument::fromJson(obj_data.value("basic").toString().toUtf8()).object();
|
||||
QJsonObject obj_basic = obj_data.value("basic").toObject();
|
||||
background_color = obj_basic.value("backgroud_color").toString();
|
||||
title_color = obj_basic.value("title_color").toString();
|
||||
text_color = obj_basic.value("title_color").toString();
|
||||
@ -865,7 +868,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
QUrl url_png(menu.png);
|
||||
QNetworkRequest* request_png = new QNetworkRequest(url_logo);
|
||||
QNetworkRequest* request_png = new QNetworkRequest(url_png);
|
||||
manager = new QNetworkAccessManager;
|
||||
reply = manager->get(*request_png);
|
||||
QTimer timer_png;
|
||||
@ -877,15 +880,15 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
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))
|
||||
//没仔细研究QFile,貌似读写二进制文件挺麻烦,先用标准库吧
|
||||
std::ofstream out(png_path.toStdString(), std::ios::binary);
|
||||
if(out.is_open())
|
||||
{
|
||||
file.write(buffer_png);
|
||||
file.close();
|
||||
out.write(buffer_png.data(), buffer_png.size());
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -905,8 +908,9 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs, ConfigRespo
|
||||
buffer_png = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reply->close();
|
||||
delete manager;
|
||||
manager = nullptr;
|
||||
bool categories[CATEGORIES_NUM] = { false };
|
||||
@ -1044,7 +1048,7 @@ bool SQLiteHelper::get_software(QList<ButtonStruct>* button_structs,QString back
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
QString icon = QApplication::applicationDirPath() + DEFAULT_SVG_PATH + query.value("orig_name").toString() + ".svg";
|
||||
QString icon = QApplication::applicationDirPath() + query.value("logo").toString();
|
||||
ButtonStruct button_struct;
|
||||
button_struct.path = query.value("path").toString();
|
||||
button_struct.text = query.value("name").toString();
|
||||
@ -1260,40 +1264,41 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||
{
|
||||
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())
|
||||
query_sel.bindValue(":orig_name", orig_name);
|
||||
if (query_sel.exec())
|
||||
{
|
||||
if(query_sel.next())
|
||||
if (query_sel.next())
|
||||
{
|
||||
QString sql="update kmd_menu"
|
||||
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(":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())
|
||||
if (!query.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1335,7 +1340,50 @@ bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path
|
||||
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::insert_software(QString name, QString orig_name, QString path, QString sort, bool* categories) {
|
||||
QSqlQuery begin(db);
|
||||
begin.exec("BEGIN;");
|
||||
QSqlQuery query(db);
|
||||
QString categories_str = "";
|
||||
categories[ALL - 1] = 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,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(categories_str);
|
||||
query.addBindValue(name);
|
||||
query.addBindValue(orig_name);
|
||||
time_t create_time;
|
||||
time(&create_time);
|
||||
query.addBindValue(create_time);
|
||||
query.addBindValue("app");
|
||||
query.addBindValue("open");
|
||||
query.addBindValue(path);
|
||||
query.addBindValue("");
|
||||
query.addBindValue("");
|
||||
query.addBindValue(true);
|
||||
query.addBindValue(QApplication::applicationDirPath() + DEFAULT_IMAGE);
|
||||
query.addBindValue(QApplication::applicationDirPath() + DEFAULT_PNG);
|
||||
query.addBindValue(false);
|
||||
query.addBindValue(false);
|
||||
query.addBindValue("");
|
||||
if (!query.exec())
|
||||
{
|
||||
QSqlQuery rollback(db);
|
||||
rollback.exec("ROLLBACK;");
|
||||
return false;
|
||||
}
|
||||
update_total();
|
||||
QSqlQuery commit(db);
|
||||
commit.exec("COMMIT;");
|
||||
|
||||
return true;
|
||||
}
|
||||
bool SQLiteHelper::set_category(QList<Categrory>& categrories)
|
||||
{
|
||||
QSqlQuery work(db);
|
||||
|
Reference in New Issue
Block a user