1 Star 0 Fork 0

Shurong Zhang/zuolin_client

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
client_backend.cpp 2.99 KB
一键复制 编辑 原始数据 按行查看 历史
Shurong Zhang 提交于 2018-05-08 20:29 . init
#include "client_backend.h"
#include "requestmaneger.h"
#include <QJsonArray>
ClientBackend::ClientBackend(QObject *parent) : QObject(parent)
{
}
/*
* curl -H "Content-Type: application/json" -X POST
* --data '{
* "username":"vergil","token":"..",
* "command":"ls",
* "dir":"zhang"}'
* https://cvzhang.cn/files
*/
void ClientBackend::file_ls(QString path)
{
RequestManeger *requestManeger = new RequestManeger();
QJsonObject object
{
{"username", RequestManeger::username},
{"token", RequestManeger::token},
{"command", "ls"},
{"dir", "zhang"}
};
typedef void (*CALLBACK_FUNC)(void*, QJsonObject& obj);
requestManeger->set_callback((CALLBACK_FUNC)&ClientBackend::handle_file_ls, this);
requestManeger->send(object, "files");
}
void ClientBackend::handle_file_ls(QJsonObject &res_json)
{
if(res_json.isEmpty()|| !res_json.contains("error")) {
return;
}
int err = res_json["error"].toInt();
if(err!=0) {
fprintf(stderr, "Error code is %d\n", err);
}
QJsonArray filename_list = res_json["data"].toArray();
QVariantList names;
QVariantList authors;
QVariantList filesizes;
for(auto filename : filename_list) {
names << filename.toString();
authors << "zsr";
filesizes << "1000";
}
emit fileLoaded(names, authors, filesizes);
}
void ClientBackend::file_history()
{
RequestManeger* requestManeger = new RequestManeger();
QJsonObject object {
{"username", RequestManeger::username},
{"token", RequestManeger::token},
{"command", "history"}
};
typedef void (*CALLBACK_FUNC)(void*, QJsonObject& obj);
requestManeger->set_callback((CALLBACK_FUNC)&ClientBackend::handle_file_history, this);
requestManeger->send(object, "files");
}
void ClientBackend::file_upload(QString filename)
{
}
void ClientBackend::file_download(QString filename)
{
}
void ClientBackend::file_rm(QString filename)
{
}
void ClientBackend::file_mv(QString filename)
{
}
void ClientBackend::file_detail(QString filename)
{
}
void ClientBackend::handle_file_history(QJsonObject &res_json)
{
if(res_json.isEmpty()|| !res_json.contains("error")) {
return;
}
int err = res_json["error"].toInt();
if(err!=0) {
fprintf(stderr, "Error code is %d\n", err);
return;
}
QJsonArray filename_list = res_json["files"].toArray();
QVariantList names;
QVariantList authors;
QVariantList filesizes;
for(auto filename : filename_list) {
names << filename.toString();
authors << "zsr";
filesizes << "1000";
}
emit historyLoaded(names, authors, filesizes);
}
void ClientBackend::handle_file_upload(QJsonObject &res_json)
{
}
void ClientBackend::handle_file_download(QJsonObject &res_json)
{
}
void ClientBackend::handle_file_rm(QJsonObject &res_json)
{
}
void ClientBackend::handle_file_mv(QJsonObject &res_json)
{
}
void ClientBackend::handle_file_detail(QJsonObject &res_json)
{
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Alfred_Zhang/zuolin_client.git
git@gitee.com:Alfred_Zhang/zuolin_client.git
Alfred_Zhang
zuolin_client
zuolin_client
master

搜索帮助