File indexing completed on 2024-05-19 04:47:19

0001 #include "youtubemodel.h"
0002 #include "controllers/youtube.h"
0003 
0004 YouTubeModel::YouTubeModel(QObject *parent) : MauiList(parent)
0005   , m_yt(new YouTube(this))
0006 {
0007     connect(m_yt, &YouTube::queryResultsReady, this, &YouTubeModel::setList);
0008 }
0009 
0010 void YouTubeModel::componentComplete()
0011 {
0012     connect(this, &YouTubeModel::queryChanged, this, &YouTubeModel::request);
0013     this->request(m_query);
0014 }
0015 
0016 const FMH::MODEL_LIST &YouTubeModel::items() const
0017 {
0018     return m_list;
0019 }
0020 
0021 QString YouTubeModel::query() const
0022 {
0023     return m_query;
0024 }
0025 
0026 QString YouTubeModel::key() const
0027 {
0028     return m_key;
0029 }
0030 
0031 int YouTubeModel::limit() const
0032 {
0033     return m_limit;
0034 }
0035 
0036 void YouTubeModel::setQuery(QString query)
0037 {
0038     if (m_query == query)
0039         return;
0040 
0041     m_query = query;
0042     Q_EMIT queryChanged(m_query);
0043 }
0044 
0045 void YouTubeModel::setKey(QString key)
0046 {
0047     if (m_key == key)
0048         return;
0049 
0050     m_key = key;
0051     Q_EMIT keyChanged(m_key);
0052 }
0053 
0054 void YouTubeModel::setLimit(int limit)
0055 {
0056     if (m_limit == limit)
0057         return;
0058 
0059     m_limit = limit;
0060     Q_EMIT limitChanged(m_limit);
0061 }
0062 
0063 void YouTubeModel::setList(const FMH::MODEL_LIST &data)
0064 {
0065     this->m_list.clear();
0066     Q_EMIT this->preListChanged();
0067 
0068     this->m_list = data;
0069 
0070     Q_EMIT this->postListChanged();
0071 }
0072 
0073 void YouTubeModel::request(const QString &query)
0074 {
0075     if(query.isEmpty())
0076         return;
0077 
0078     this->m_yt->setKey(m_key);
0079     this->m_yt->getQuery(query, m_limit);
0080 }