From 09d68bf41523354bb4b11d56caf167a10614a25e Mon Sep 17 00:00:00 2001 From: "Krzysztof A. Sobiecki" Date: Tue, 28 Jan 2014 16:04:17 +0100 Subject: [PATCH] Scrub the auto usage, use unique_ptr, use correct types instead of QList --- src/core/organise.cpp | 10 +++---- src/podcasts/podcastbackend.cpp | 2 +- src/podcasts/podcastbackend.h | 4 +-- src/podcasts/podcastdownloader.cpp | 10 +++---- src/podcasts/podcastservice.cpp | 46 +++++++++++++++--------------- src/podcasts/podcastservice.h | 8 +++--- src/ui/organisedialog.cpp | 10 +++---- src/ui/organisedialog.h | 5 ++-- 8 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/core/organise.cpp b/src/core/organise.cpp index ca63fbfdb..76fe82192 100644 --- a/src/core/organise.cpp +++ b/src/core/organise.cpp @@ -53,7 +53,7 @@ Organise::Organise(TaskManager* task_manager, { original_thread_ = thread(); - for (const auto& song : songs) { + for (const Song& song : songs) { tasks_pending_ << Task(song); } } @@ -79,7 +79,7 @@ void Organise::ProcessSomeFiles() { if (!destination_->StartCopy(&supported_filetypes_)) { // Failed to start - mark everything as failed :( - for (const auto& task : tasks_pending_) + for (const Task& task : tasks_pending_) files_with_errors_ << task.song_.url().toLocalFile(); tasks_pending_.clear(); } @@ -237,7 +237,7 @@ void Organise::UpdateProgress() { // Update transcoding progress QMap transcode_progress = transcoder_->GetProgress(); - for (const auto& filename : transcode_progress.keys()) { + for (const QString& filename : transcode_progress.keys()) { if (!tasks_transcoding_.contains(filename)) continue; tasks_transcoding_[filename].transcode_progress_ = transcode_progress[filename]; @@ -248,10 +248,10 @@ void Organise::UpdateProgress() { // only need to be copied total 100. int progress = tasks_complete_ * 100; - for (const auto& task : tasks_pending_) { + for (const Task& task : tasks_pending_) { progress += qBound(0, static_cast(task.transcode_progress_ * 50), 50); } - for (const auto& task : tasks_transcoding_.values()) { + for (const Task& task : tasks_transcoding_.values()) { progress += qBound(0, static_cast(task.transcode_progress_ * 50), 50); } diff --git a/src/podcasts/podcastbackend.cpp b/src/podcasts/podcastbackend.cpp index 467918540..cd3b13578 100644 --- a/src/podcasts/podcastbackend.cpp +++ b/src/podcasts/podcastbackend.cpp @@ -141,7 +141,7 @@ void PodcastBackend::UpdateEpisodes(const PodcastEpisodeList& episodes) { " local_url = :local_url" " WHERE ROWID = :id", db); - for (const auto& episode : episodes) { + for (const PodcastEpisode& episode : episodes) { q.bindValue(":listened", episode.listened()); q.bindValue(":listened_date", episode.listened_date().toTime_t()); q.bindValue(":downloaded", episode.downloaded()); diff --git a/src/podcasts/podcastbackend.h b/src/podcasts/podcastbackend.h index bd6e85ba8..87f5264a0 100644 --- a/src/podcasts/podcastbackend.h +++ b/src/podcasts/podcastbackend.h @@ -74,10 +74,10 @@ signals: void SubscriptionRemoved(const Podcast& podcast); // Emitted when episodes are added to a subscription that *already exists*. - void EpisodesAdded(const QList& episodes); + void EpisodesAdded(const PodcastEpisodeList& episodes); // Emitted when existing episodes are updated. - void EpisodesUpdated(const QList& episodes); + void EpisodesUpdated(const PodcastEpisodeList& episodes); private: // Adds each episode to the database, setting their IDs after inserting each diff --git a/src/podcasts/podcastdownloader.cpp b/src/podcasts/podcastdownloader.cpp index 30d232b89..be281a0f7 100644 --- a/src/podcasts/podcastdownloader.cpp +++ b/src/podcasts/podcastdownloader.cpp @@ -56,8 +56,8 @@ PodcastDownloader::PodcastDownloader(Application* app, QObject* parent) last_progress_signal_(0), auto_delete_timer_(new QTimer(this)) { - connect(backend_, SIGNAL(EpisodesAdded(QList)), - SLOT(EpisodesAdded(QList))); + connect(backend_, SIGNAL(EpisodesAdded(PodcastEpisodeList)), + SLOT(EpisodesAdded(PodcastEpisodeList))); connect(backend_, SIGNAL(SubscriptionAdded(Podcast)), SLOT(SubscriptionAdded(Podcast))); connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings())); @@ -282,9 +282,9 @@ void PodcastDownloader::SubscriptionAdded(const Podcast& podcast) { EpisodesAdded(podcast.episodes()); } -void PodcastDownloader::EpisodesAdded(const QList& episodes) { +void PodcastDownloader::EpisodesAdded(const PodcastEpisodeList& episodes) { if (auto_download_) { - for (const auto& episode : episodes) { + for (const PodcastEpisode& episode : episodes) { DownloadEpisode(episode); } } @@ -307,7 +307,7 @@ void PodcastDownloader::AutoDelete() { << (delete_after_secs_ / kSecsPerDay) << "days ago"; - for (const auto& episode : old_episodes) { + for (const PodcastEpisode& episode : old_episodes) { DeleteEpisode(episode); } } diff --git a/src/podcasts/podcastservice.cpp b/src/podcasts/podcastservice.cpp index fe5a15c34..72d92c643 100644 --- a/src/podcasts/podcastservice.cpp +++ b/src/podcasts/podcastservice.cpp @@ -69,8 +69,8 @@ PodcastService::PodcastService(Application* app, InternetModel* parent) connect(backend_, SIGNAL(SubscriptionAdded(Podcast)), SLOT(SubscriptionAdded(Podcast))); connect(backend_, SIGNAL(SubscriptionRemoved(Podcast)), SLOT(SubscriptionRemoved(Podcast))); - connect(backend_, SIGNAL(EpisodesAdded(QList)), SLOT(EpisodesAdded(QList))); - connect(backend_, SIGNAL(EpisodesUpdated(QList)), SLOT(EpisodesUpdated(QList))); + connect(backend_, SIGNAL(EpisodesAdded(PodcastEpisodeList)), SLOT(EpisodesAdded(PodcastEpisodeList))); + connect(backend_, SIGNAL(EpisodesUpdated(PodcastEpisodeList)), SLOT(EpisodesUpdated(PodcastEpisodeList))); connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), SLOT(CurrentSongChanged(Song))); } @@ -127,9 +127,9 @@ void PodcastService::CopyToDevice() { } void PodcastService::CopyToDevice(const PodcastEpisodeList& episodes_list) { - QList songs; + SongList songs; Podcast podcast; - for (const auto& episode : episodes_list) { + for (const PodcastEpisode& episode : episodes_list) { podcast = backend_->GetSubscriptionById(episode.podcast_database_id()); songs.append(episode.ToSong(podcast)); } @@ -143,16 +143,16 @@ void PodcastService::CopyToDevice(const PodcastEpisodeList& episodes_list) { void PodcastService::CopyToDevice(const QModelIndexList& episode_indexes, const QModelIndexList& podcast_indexes) { PodcastEpisode episode_tmp; - QList songs; + SongList songs; PodcastEpisodeList episodes; Podcast podcast; - for (const auto& index : episode_indexes) { + for (const QModelIndex& index : episode_indexes) { episode_tmp = index.data(Role_Episode).value(); if (episode_tmp.downloaded()) episodes << episode_tmp; } - for (const auto& podcast : podcast_indexes) { + for (const QModelIndex& podcast : podcast_indexes) { for (int i = 0; i < podcast.model()->rowCount(podcast); ++i) { const QModelIndex& index = podcast.child(i, 0); episode_tmp = index.data(Role_Episode).value(); @@ -160,7 +160,7 @@ void PodcastService::CopyToDevice(const QModelIndexList& episode_indexes, episodes << episode_tmp; } } - for (const auto& episode : episodes) { + for (const PodcastEpisode& episode : episodes) { podcast = backend_->GetSubscriptionById(episode.podcast_database_id()); songs.append(episode.ToSong(podcast)); } @@ -190,7 +190,7 @@ void PodcastService::PopulatePodcastList(QStandardItem* parent) { default_icon_ = QIcon(":providers/podcast16.png"); } - for (const auto& podcast : backend_->GetAllSubscriptions()) { + for (const Podcast& podcast : backend_->GetAllSubscriptions()) { parent->appendRow(CreatePodcastItem(podcast)); } } @@ -270,7 +270,7 @@ QStandardItem* PodcastService::CreatePodcastItem(const Podcast& podcast) { // Add the episodes in this podcast and gather aggregate stats. int unlistened_count = 0; - for (const auto& episode : backend_->GetEpisodes(podcast.database_id())) { + for (const PodcastEpisode& episode : backend_->GetEpisodes(podcast.database_id())) { if (!episode.listened()) { unlistened_count++; } @@ -360,7 +360,7 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { explicitly_selected_podcasts_.clear(); QSet podcast_ids; - for (const auto& index : model()->selected_indexes()) { + for (const QModelIndex& index : model()->selected_indexes()) { switch (index.data(InternetModel::Role_Type).toInt()) { case Type_Podcast: { const int id = index.data(Role_Podcast).value().database_id(); @@ -431,14 +431,14 @@ void PodcastService::ShowContextMenu(const QPoint& global_pos) { } void PodcastService::UpdateSelectedPodcast() { - for (const auto& index : selected_podcasts_) { + for (const QModelIndex& index : selected_podcasts_) { app_->podcast_updater()->UpdatePodcastNow( index.data(Role_Podcast).value()); } } void PodcastService::RemoveSelectedPodcast() { - for (const auto& index : selected_podcasts_) { + for (const QModelIndex& index : selected_podcasts_) { backend_->Unsubscribe(index.data(Role_Podcast).value()); } } @@ -494,10 +494,10 @@ void PodcastService::SubscriptionRemoved(const Podcast& podcast) { } } -void PodcastService::EpisodesAdded(const QList& episodes) { +void PodcastService::EpisodesAdded(const PodcastEpisodeList& episodes) { QSet seen_podcast_ids; - for (const auto& episode : episodes) { + for (const PodcastEpisode& episode : episodes) { const int database_id = episode.podcast_database_id(); QStandardItem* parent = podcasts_by_database_id_[database_id]; if (!parent) @@ -508,7 +508,7 @@ void PodcastService::EpisodesAdded(const QList& episodes) { if (!seen_podcast_ids.contains(database_id)) { // Update the unlistened count text once for each podcast int unlistened_count = 0; - for (const auto& episode : backend_->GetEpisodes(database_id)) { + for (const PodcastEpisode& episode : backend_->GetEpisodes(database_id)) { if (!episode.listened()) { unlistened_count++; } @@ -520,10 +520,10 @@ void PodcastService::EpisodesAdded(const QList& episodes) { } } -void PodcastService::EpisodesUpdated(const QList& episodes) { +void PodcastService::EpisodesUpdated(const PodcastEpisodeList& episodes) { QSet seen_podcast_ids; - for (const auto& episode : episodes) { + for (const PodcastEpisode& episode : episodes) { const int podcast_database_id = episode.podcast_database_id(); QStandardItem* item = episodes_by_database_id_[episode.database_id()]; QStandardItem* parent = podcasts_by_database_id_[podcast_database_id]; @@ -538,7 +538,7 @@ void PodcastService::EpisodesUpdated(const QList& episodes) { if (!seen_podcast_ids.contains(podcast_database_id)) { // Update the unlistened count text once for each podcast int unlistened_count = 0; - for (const auto& episode : backend_->GetEpisodes(podcast_database_id)) { + for (const PodcastEpisode& episode : backend_->GetEpisodes(podcast_database_id)) { if (!episode.listened()) { unlistened_count++; } @@ -551,14 +551,14 @@ void PodcastService::EpisodesUpdated(const QList& episodes) { } void PodcastService::DownloadSelectedEpisode() { - for (const auto& index : selected_episodes_) { + for (const QModelIndex& index : selected_episodes_) { app_->podcast_downloader()->DownloadEpisode( index.data(Role_Episode).value()); } } void PodcastService::DeleteDownloadedData() { - for (const auto& index : selected_episodes_) { + for (const QModelIndex& index : selected_episodes_) { app_->podcast_downloader()->DeleteEpisode( index.data(Role_Episode).value()); } @@ -607,7 +607,7 @@ void PodcastService::SetListened(const PodcastEpisodeList& episodes_list, bool listened) { PodcastEpisodeList episodes; QDateTime current_date_time = QDateTime::currentDateTime(); - for (auto episode : episodes_list) { + for (PodcastEpisode episode : episodes_list) { episode.set_listened(listened); if (listened) { episode.set_listened_date(current_date_time); @@ -624,7 +624,7 @@ void PodcastService::SetListened(const QModelIndexList& episode_indexes, PodcastEpisodeList episodes; // Get all the episodes from the indexes. - for (auto& index : episode_indexes) { + for (const QModelIndex& index : episode_indexes) { episodes << index.data(Role_Episode).value(); } diff --git a/src/podcasts/podcastservice.h b/src/podcasts/podcastservice.h index 92c864b11..40e135748 100644 --- a/src/podcasts/podcastservice.h +++ b/src/podcasts/podcastservice.h @@ -22,8 +22,8 @@ #include "internet/internetmodel.h" #include "internet/internetservice.h" +#include #include -#include class AddPodcastDialog; class OrganiseDialog; @@ -80,8 +80,8 @@ private slots: void SubscriptionAdded(const Podcast& podcast); void SubscriptionRemoved(const Podcast& podcast); - void EpisodesAdded(const QList& episodes); - void EpisodesUpdated(const QList& episodes); + void EpisodesAdded(const PodcastEpisodeList& episodes); + void EpisodesUpdated(const PodcastEpisodeList& episodes); void DownloadProgressChanged(const PodcastEpisode& episode, PodcastDownloader::State state, @@ -141,7 +141,7 @@ private: QAction* set_listened_action_; QAction* copy_to_device_; QStandardItem* root_; - boost::scoped_ptr organise_dialog_; + std::unique_ptr organise_dialog_; QModelIndexList explicitly_selected_podcasts_; QModelIndexList selected_podcasts_; diff --git a/src/ui/organisedialog.cpp b/src/ui/organisedialog.cpp index 247f6d85b..01bf74e96 100644 --- a/src/ui/organisedialog.cpp +++ b/src/ui/organisedialog.cpp @@ -85,7 +85,7 @@ OrganiseDialog::OrganiseDialog(TaskManager* task_manager, QWidget *parent) // Build the insert menu QMenu* tag_menu = new QMenu(this); QSignalMapper* tag_mapper = new QSignalMapper(this); - for (const auto& title : tag_titles) { + for (const QString& title : tag_titles) { QAction* action = tag_menu->addAction(title, tag_mapper, SLOT(map())); tag_mapper->setMapping(action, tags[title]); } @@ -108,7 +108,7 @@ int OrganiseDialog::SetSongs(const SongList& songs) { total_size_ = 0; songs_.clear(); - for (const auto& song : songs) { + for (const Song& song : songs) { if (song.url().scheme() != "file") { continue; } @@ -130,7 +130,7 @@ int OrganiseDialog::SetUrls(const QList &urls, quint64 total_size) { Song song; // Only add file:// URLs - for (const auto& url : urls) { + for (const QUrl& url : urls) { if (url.scheme() != "file") continue; TagReaderClient::Instance()->ReadFileBlocking(url.toLocalFile(), &song); @@ -146,7 +146,7 @@ int OrganiseDialog::SetFilenames(const QStringList& filenames, quint64 total_siz Song song; // Load some of the songs to show in the preview - for (const auto& filename : filenames) { + for (const QString& filename : filenames) { TagReaderClient::Instance()->ReadFileBlocking(song.basefilename(), &song); if (song.is_valid()) songs << song; @@ -210,7 +210,7 @@ void OrganiseDialog::UpdatePreviews() { ui_->preview_group->setVisible(has_local_destination); ui_->naming_group->setVisible(has_local_destination); if (has_local_destination) { - for (const auto& song : songs_) { + for (const Song& song : songs_) { QString filename = storage->LocalPath() + "/" + format_.GetFilenameForSong(song); ui_->preview->addItem(QDir::toNativeSeparators(filename)); diff --git a/src/ui/organisedialog.h b/src/ui/organisedialog.h index 48ff86454..3b545ccd7 100644 --- a/src/ui/organisedialog.h +++ b/src/ui/organisedialog.h @@ -18,6 +18,7 @@ #ifndef ORGANISEDIALOG_H #define ORGANISEDIALOG_H +#include #include #include #include @@ -25,8 +26,6 @@ #include "core/organiseformat.h" #include "core/song.h" -#include - class LibraryWatcher; class OrganiseErrorDialog; class TaskManager; @@ -77,7 +76,7 @@ private: SongList songs_; quint64 total_size_; - boost::scoped_ptr error_dialog_; + std::unique_ptr error_dialog_; bool resized_by_user_; };