From f60327b1d16b169fe6167f9d22951255277a33f8 Mon Sep 17 00:00:00 2001 From: "Krzysztof A. Sobiecki" Date: Mon, 30 Dec 2013 16:01:02 +0100 Subject: [PATCH] Initial 'Copy to device' support for podcasts --- src/core/database.cpp | 1 - src/podcasts/podcastservice.cpp | 41 ++++++++++++++++++++++++++++++++- src/podcasts/podcastservice.h | 6 +++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/core/database.cpp b/src/core/database.cpp index 5c6b0203c..2c012f6f4 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -575,7 +575,6 @@ bool Database::CheckErrors(const QSqlQuery& query) { qLog(Error) << "faulty query: " << query.lastQuery(); qLog(Error) << "bound values: " << query.boundValues(); - app_->AddError("LibraryBackend: " + last_error.text()); return true; } diff --git a/src/podcasts/podcastservice.cpp b/src/podcasts/podcastservice.cpp index 9a74fef1b..3975e2d98 100644 --- a/src/podcasts/podcastservice.cpp +++ b/src/podcasts/podcastservice.cpp @@ -29,6 +29,11 @@ #include "library/libraryview.h" #include "ui/iconloader.h" #include "ui/standarditemiconloader.h" +#include "ui/organisedialog.h" +#include "ui/organiseerrordialog.h" +#include "devices/devicemanager.h" +#include "devices/devicestatefiltermodel.h" +#include "devices/deviceview.h" #include #include @@ -54,7 +59,8 @@ PodcastService::PodcastService(Application* app, InternetModel* parent) model_(new PodcastServiceModel(this)), proxy_(new PodcastSortProxyModel(this)), context_menu_(NULL), - root_(NULL) + root_(NULL), + organise_dialog_(new OrganiseDialog(app_->task_manager())) { icon_loader_->SetModel(model_); proxy_->setSourceModel(model_); @@ -112,6 +118,31 @@ QStandardItem* PodcastService::CreateRootItem() { return root_; } +void PodcastService::CopyToDeviceSlot() { + QList url_list; + QList episodes; + + foreach (const QModelIndex& index, selected_episodes_) { + episodes << index.data(Role_Episode).value(); + } + + foreach (const QModelIndex& podcast, explicitly_selected_podcasts_) { + for (int i=0 ; irowCount(podcast) ; ++i) { + const QModelIndex& index = podcast.child(i, 0); + episodes << index.data(Role_Episode).value(); + } + } + + foreach (const PodcastEpisode& episode, episodes) { + if(!episode.local_url().isEmpty()) + url_list.append(episode.local_url()); + } + organise_dialog_->SetDestinationModel(app_->device_manager()->connected_devices_model(), true); + organise_dialog_->SetCopy(true); + if (organise_dialog_->SetUrls(url_list)) + organise_dialog_->show(); +} + void PodcastService::LazyPopulate(QStandardItem* parent) { switch (parent->data(InternetModel::Role_Type).toInt()) { case InternetModel::Type_Service: @@ -273,6 +304,9 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { delete_downloaded_action_ = context_menu_->addAction( IconLoader::Load("edit-delete"), tr("Delete downloaded data"), this, SLOT(DeleteDownloadedData())); + copy_to_device_ = context_menu_->addAction( + IconLoader::Load("multimedia-player-ipod-mini-blue"), tr("Copy to device..."), + this, SLOT(CopyToDeviceSlot())); remove_selected_action_ = context_menu_->addAction( IconLoader::Load("list-remove"), tr("Unsubscribe"), this, SLOT(RemoveSelectedPodcast())); @@ -287,6 +321,11 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { context_menu_->addAction( IconLoader::Load("configure"), tr("Configure podcasts..."), this, SLOT(ShowConfig())); + + copy_to_device_->setDisabled(app_->device_manager()->connected_devices_model()->rowCount() == 0); + connect(app_->device_manager()->connected_devices_model(), SIGNAL(IsEmptyChanged(bool)), + copy_to_device_, SLOT(setDisabled(bool))); + } selected_episodes_.clear(); diff --git a/src/podcasts/podcastservice.h b/src/podcasts/podcastservice.h index e52b546f1..099a61459 100644 --- a/src/podcasts/podcastservice.h +++ b/src/podcasts/podcastservice.h @@ -23,12 +23,14 @@ #include "internet/internetservice.h" #include +#include class AddPodcastDialog; class Podcast; class PodcastBackend; class PodcastEpisode; class StandardItemIconLoader; +class OrganiseDialog; class QSortFilterProxyModel; @@ -86,6 +88,8 @@ private slots: int percent); void CurrentSongChanged(const Song& metadata); + + void CopyToDeviceSlot(); private: void EnsureAddPodcastDialogCreated(); @@ -130,7 +134,9 @@ private: QAction* delete_downloaded_action_; QAction* set_new_action_; QAction* set_listened_action_; + QAction* copy_to_device_; QStandardItem* root_; + boost::scoped_ptr organise_dialog_; QModelIndexList explicitly_selected_podcasts_; QModelIndexList selected_podcasts_;