diff --git a/src/podcasts/addpodcastdialog.cpp b/src/podcasts/addpodcastdialog.cpp index 96a955373..8a7ffeed1 100644 --- a/src/podcasts/addpodcastdialog.cpp +++ b/src/podcasts/addpodcastdialog.cpp @@ -66,6 +66,7 @@ void AddPodcastDialog::ChangePage(int index) { AddPodcastPage* page = pages_[index]; ui_->stack->setCurrentIndex(index); + ui_->stack->setVisible(page->has_visible_widget()); ui_->results->setModel(page->model()); ui_->results->setRootIsDecorated(page->model()->is_tree()); @@ -76,10 +77,14 @@ void AddPodcastDialog::ChangePage(int index) { SLOT(ChangePodcast(QModelIndex))); ChangePodcast(QModelIndex()); PageBusyChanged(page_is_busy_[index]); + + page->Show(); } void AddPodcastDialog::ChangePodcast(const QModelIndex& current) { - if (!current.isValid()) { + if (!current.isValid() || + current.data(PodcastDiscoveryModel::Role_Type).toInt() != + PodcastDiscoveryModel::Type_Podcast) { ui_->details->hide(); return; } diff --git a/src/podcasts/addpodcastdialog.ui b/src/podcasts/addpodcastdialog.ui index a6ad9b50b..d0031a147 100644 --- a/src/podcasts/addpodcastdialog.ui +++ b/src/podcasts/addpodcastdialog.ui @@ -53,7 +53,7 @@ - 1 + 0 @@ -65,6 +65,12 @@ + + QAbstractItemView::NoEditTriggers + + + true + false diff --git a/src/podcasts/addpodcastpage.h b/src/podcasts/addpodcastpage.h index a9a137606..79736545b 100644 --- a/src/podcasts/addpodcastpage.h +++ b/src/podcasts/addpodcastpage.h @@ -31,6 +31,9 @@ public: PodcastDiscoveryModel* model() const { return model_; } + virtual bool has_visible_widget() const { return true; } + virtual void Show() {} + signals: void Busy(bool busy); diff --git a/src/podcasts/gpoddertoptagsmodel.cpp b/src/podcasts/gpoddertoptagsmodel.cpp index 77fcb0879..509dd497a 100644 --- a/src/podcasts/gpoddertoptagsmodel.cpp +++ b/src/podcasts/gpoddertoptagsmodel.cpp @@ -1,32 +1,82 @@ /* This file is part of Clementine. Copyright 2012, David Sansome - + Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + Clementine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with Clementine. If not, see . */ #include "gpoddertoptagsmodel.h" +#include "gpoddertoptagspage.h" +#include "podcast.h" +#include "core/closure.h" -GPodderTopTagsModel::GPodderTopTagsModel(Application* app, QObject* parent) - : PodcastDiscoveryModel(app, parent) +#include + +GPodderTopTagsModel::GPodderTopTagsModel(mygpo::ApiRequest* api, Application* app, + QObject* parent) + : PodcastDiscoveryModel(app, parent), + api_(api) { set_is_tree(true); } bool GPodderTopTagsModel::hasChildren(const QModelIndex& parent) const { - if (parent.isValid() && parent.data(Role_Type).toInt() == Type_Folder) { + if (parent.isValid() && + parent.data(Role_Type).toInt() == Type_Folder) { return true; } return PodcastDiscoveryModel::hasChildren(parent); } + +bool GPodderTopTagsModel::canFetchMore(const QModelIndex& parent) const { + if (parent.isValid() && + parent.data(Role_Type).toInt() == Type_Folder && + parent.data(Role_HasLazyLoaded).toBool() == false) { + return true; + } + + return PodcastDiscoveryModel::canFetchMore(parent); +} + +void GPodderTopTagsModel::fetchMore(const QModelIndex& parent) { + if (!parent.isValid() || + parent.data(Role_Type).toInt() != Type_Folder || + parent.data(Role_HasLazyLoaded).toBool()) { + return; + } + setData(parent, true, Role_HasLazyLoaded); + + mygpo::PodcastList* list = + api_->podcastsOfTag(GPodderTopTagsPage::kMaxTagCount, parent.data().toString()); + + NewClosure(list, SIGNAL(finished()), + this, SLOT(PodcastsOfTagFinished(QModelIndex,mygpo::PodcastList*)), + parent, list); +} + +void GPodderTopTagsModel::PodcastsOfTagFinished(const QModelIndex& parent, + mygpo::PodcastList* list) { + list->deleteLater(); + + QStandardItem* parent_item = itemFromIndex(parent); + if (!parent_item) + return; + + foreach (mygpo::PodcastPtr gpo_podcast, list->list()) { + Podcast podcast; + podcast.InitFromGpo(gpo_podcast.data()); + + parent_item->appendRow(CreatePodcastItem(podcast)); + } +} diff --git a/src/podcasts/gpoddertoptagsmodel.h b/src/podcasts/gpoddertoptagsmodel.h index 284cdf72d..7eb13517e 100644 --- a/src/podcasts/gpoddertoptagsmodel.h +++ b/src/podcasts/gpoddertoptagsmodel.h @@ -20,13 +20,33 @@ #include "podcastdiscoverymodel.h" +namespace mygpo { + class ApiRequest; + class PodcastList; +} + class GPodderTopTagsModel : public PodcastDiscoveryModel { Q_OBJECT public: - GPodderTopTagsModel(Application* app, QObject* parent = 0); + GPodderTopTagsModel(mygpo::ApiRequest* api, Application* app, + QObject* parent = 0); + + enum Role { + Role_HasLazyLoaded = PodcastDiscoveryModel::RoleCount, + + RoleCount + }; bool hasChildren(const QModelIndex& parent) const; + bool canFetchMore(const QModelIndex& parent) const; + void fetchMore(const QModelIndex& parent); + +private slots: + void PodcastsOfTagFinished(const QModelIndex& parent, mygpo::PodcastList* list); + +private: + mygpo::ApiRequest* api_; }; #endif // GPODDERTOPTAGSMODEL_H diff --git a/src/podcasts/gpoddertoptagspage.cpp b/src/podcasts/gpoddertoptagspage.cpp index 9d8d36faa..1be0afca6 100644 --- a/src/podcasts/gpoddertoptagspage.cpp +++ b/src/podcasts/gpoddertoptagspage.cpp @@ -34,16 +34,14 @@ GPodderTopTagsPage::GPodderTopTagsPage(Application* app, QWidget* parent) setWindowTitle(tr("Browse gpodder.net")); setWindowIcon(QIcon(":providers/mygpo32.png")); - SetModel(new GPodderTopTagsModel(app, this)); + SetModel(new GPodderTopTagsModel(api_, app, this)); } GPodderTopTagsPage::~GPodderTopTagsPage() { delete api_; } -void GPodderTopTagsPage::showEvent(QShowEvent* e) { - QWidget::showEvent(e); - +void GPodderTopTagsPage::Show() { if (!done_initial_load_) { // Start the request for list of top-level tags emit Busy(true); diff --git a/src/podcasts/gpoddertoptagspage.h b/src/podcasts/gpoddertoptagspage.h index c60531f97..66b0b6168 100644 --- a/src/podcasts/gpoddertoptagspage.h +++ b/src/podcasts/gpoddertoptagspage.h @@ -38,8 +38,8 @@ public: static const int kMaxTagCount; -private: - void showEvent(QShowEvent* e); + virtual bool has_visible_widget() const { return false; } + virtual void Show(); private slots: void TagListLoaded(mygpo::TagList* tag_list); diff --git a/src/podcasts/podcast.cpp b/src/podcasts/podcast.cpp index 3c1d18015..bd4b97692 100644 --- a/src/podcasts/podcast.cpp +++ b/src/podcasts/podcast.cpp @@ -20,6 +20,8 @@ #include +#include + const QStringList Podcast::kColumns = QStringList() << "url" << "title" << "description" << "copyright" << "link" << "image_url" << "author" << "owner_name" << "author_email" << "extra"; @@ -140,3 +142,15 @@ void Podcast::BindToQuery(QSqlQuery* query) const { query->bindValue(":extra", extra); } + +void Podcast::InitFromGpo(const mygpo::Podcast* podcast) { + d->url_ = podcast->url(); + d->title_ = podcast->title(); + d->description_ = podcast->description(); + d->link_ = podcast->website(); + d->image_url_ = podcast->logoUrl(); + + set_extra("gpodder:subscribers", podcast->subscribers()); + set_extra("gpodder:subscribers_last_week", podcast->subscribersLastWeek()); + set_extra("gpodder:page", podcast->mygpoUrl()); +} diff --git a/src/podcasts/podcast.h b/src/podcasts/podcast.h index d6a68cd7c..047b50a8b 100644 --- a/src/podcasts/podcast.h +++ b/src/podcasts/podcast.h @@ -25,6 +25,10 @@ #include #include +namespace mygpo { + class Podcast; +} + class Podcast { public: Podcast(); @@ -37,6 +41,8 @@ public: static const QString kUpdateSpec; void InitFromQuery(const QSqlQuery& query); + void InitFromGpo(const mygpo::Podcast* podcast); + void BindToQuery(QSqlQuery* query) const; bool is_valid() const { return database_id() != -1; } diff --git a/src/podcasts/podcastdiscoverymodel.h b/src/podcasts/podcastdiscoverymodel.h index b24ff7a62..dcbb07df9 100644 --- a/src/podcasts/podcastdiscoverymodel.h +++ b/src/podcasts/podcastdiscoverymodel.h @@ -38,7 +38,9 @@ public: enum Role { Role_Podcast = Qt::UserRole, - Role_Type + Role_Type, + + RoleCount }; bool is_tree() const { return is_tree_; }