-
Notifications
You must be signed in to change notification settings - Fork 0
/
videolistmodel.cpp
executable file
·71 lines (62 loc) · 2.37 KB
/
videolistmodel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "videolistmodel.h"
#include <QProcess>
#include <QDebug>
#include <QJsonObject>
#include <QFutureWatcher>
#include <QtConcurrent/QtConcurrent>
#include "youtubesearcher.h"
VideoListModel::VideoListModel(QObject *parent)
:QJsonListModel(parent)
{
connect(&m_queryWatcher, &QFutureWatcher<QByteArray>::finished,
this, &VideoListModel::finishedQuery);
}
void VideoListModel::query(QString query, int count)
{
qDebug() << "Searching for: " << query;
this->m_isBusy = true;
emit isBusyChanged(true);
QFuture<QByteArray> fu = QtConcurrent::run(&m_yt, &YoutubeDl::query, query, count);
m_queryWatcher.setFuture(fu);
}
void VideoListModel::setModelData(QByteArray jsonBa)
{
QByteArray *json = &jsonBa;
qDebug() << "Read query size: " << json->size();
auto jd = QJsonDocument{};
QJsonParseError err;
jd = QJsonDocument::fromJson(*json, &err);
if(err.error != QJsonParseError::NoError || jd.isNull())
qDebug() <<"Parsing Error: " << err.error << err.offset;
qDebug() << "Is Arr, Is Obj, IsEmpty: " << jd.isArray() << jd.isObject() << jd.isEmpty();
qDebug() << "Keys: " << jd.object().keys() << jd.object().count();
qDebug() << "Arr?: " << jd["entries"].toArray().size() << jd.array().count();
qDebug() << "Entries size: " << jd.object()["entries"].toArray().size();
load(jd["entries"].toArray());
//qDebug() << m_roleNumbers.keys();
emit listChanged();
this->m_isBusy = false;
emit isBusyChanged(false);
}
void VideoListModel::addModelData(QByteArray json)
{
qDebug() << "Read query size: " << json.size();
auto jd = QJsonDocument{};
QJsonParseError err;
jd = QJsonDocument::fromJson(json, &err);
if(err.error != QJsonParseError::NoError || jd.isNull())
qDebug() <<"Parsing Error: " << err.error << err.offset;
qDebug() << "Is Arr, Is Obj, IsEmpty: " << jd.isArray() << jd.isObject() << jd.isEmpty();
qDebug() << "Keys: " << jd.object().keys() << jd.object().count();
qDebug() << "Arr?: " << jd["entries"].toArray().size() << jd.array().count();
qDebug() << "Entries size: " << jd.object()["entries"].toArray().size();
load(jd["entries"].toArray());
//qDebug() << m_roleNumbers.keys();
emit listChanged();
this->m_isBusy = false;
emit isBusyChanged(false);
}
void VideoListModel::finishedQuery()
{
setModelData(m_queryWatcher.result());
}