From 29b8d308b31f8367fea1577d6cbb52d82ed2920d Mon Sep 17 00:00:00 2001 From: Arun Narayanankutty Date: Thu, 14 Jan 2016 03:40:26 -0600 Subject: [PATCH] Use icon loader for remaining icons --- src/covers/currentartloader.cpp | 5 +++- src/globalsearch/globalsearchmodel.cpp | 5 ++-- src/internet/spotify/spotifyservice.cpp | 6 +++-- src/library/librarymodel.cpp | 7 +++--- src/library/libraryview.cpp | 3 ++- src/playlist/playlistcontainer.cpp | 4 ++-- src/playlist/playlistview.cpp | 7 ++++-- src/ui/albumcovermanager.cpp | 10 +++++--- src/ui/edittagdialog.cpp | 5 +++- src/ui/iconloader.cpp | 32 ++++++++++++++++--------- src/ui/iconloader.h | 4 +++- src/ui/notificationssettingspage.cpp | 4 +++- src/ui/systemtrayicon.cpp | 8 +++++-- src/widgets/favoritewidget.cpp | 5 ++-- src/widgets/ratingwidget.cpp | 6 +++-- 15 files changed, 75 insertions(+), 36 deletions(-) diff --git a/src/covers/currentartloader.cpp b/src/covers/currentartloader.cpp index e1de2f3a8..4de0a2d2d 100644 --- a/src/covers/currentartloader.cpp +++ b/src/covers/currentartloader.cpp @@ -26,6 +26,7 @@ #include "core/application.h" #include "covers/albumcoverloader.h" #include "playlist/playlistmanager.h" +#include "ui/iconloader.h" CurrentArtLoader::CurrentArtLoader(Application* app, QObject* parent) : QObject(parent), @@ -34,7 +35,9 @@ CurrentArtLoader::CurrentArtLoader(Application* app, QObject* parent) id_(0) { options_.scale_output_image_ = false; options_.pad_output_image_ = false; - options_.default_output_image_ = QImage(":nocover.png"); + options_.default_output_image_ = IconLoader::Load("nocover", + IconLoader::Other) + .pixmap(300).toImage(); connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)), SLOT(TempArtLoaded(quint64, QImage))); diff --git a/src/globalsearch/globalsearchmodel.cpp b/src/globalsearch/globalsearchmodel.cpp index 9584ab75b..d16e98770 100644 --- a/src/globalsearch/globalsearchmodel.cpp +++ b/src/globalsearch/globalsearchmodel.cpp @@ -33,8 +33,9 @@ GlobalSearchModel::GlobalSearchModel(GlobalSearch* engine, QObject* parent) group_by_[1] = LibraryModel::GroupBy_Album; group_by_[2] = LibraryModel::GroupBy_None; - no_cover_icon_ = QPixmap(":nocover.png").scaled( - LibraryModel::kPrettyCoverSize, LibraryModel::kPrettyCoverSize, + no_cover_icon_ = QPixmap(IconLoader::Load("nocover", IconLoader::Other) + .pixmap(300)).scaled(LibraryModel::kPrettyCoverSize, + LibraryModel::kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } diff --git a/src/internet/spotify/spotifyservice.cpp b/src/internet/spotify/spotifyservice.cpp index 551ec8f7e..4f9b69ef3 100644 --- a/src/internet/spotify/spotifyservice.cpp +++ b/src/internet/spotify/spotifyservice.cpp @@ -413,7 +413,8 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) { search_->setData(InternetModel::PlayBehaviour_MultipleItems, InternetModel::Role_PlayBehaviour); - starred_ = new QStandardItem(QIcon(":/star-on.png"), tr("Starred")); + starred_ = new QStandardItem(IconLoader::Load("star-on", IconLoader::Other), + tr("Starred")); starred_->setData(Type_StarredPlaylist, InternetModel::Role_Type); starred_->setData(true, InternetModel::Role_CanLazyLoad); starred_->setData(InternetModel::PlayBehaviour_MultipleItems, @@ -610,7 +611,8 @@ QList SpotifyService::playlistitem_actions(const Song& song) { } QAction* add_to_starred = - new QAction(QIcon(":/star-on.png"), tr("Add to Spotify starred"), this); + new QAction(IconLoader::Load("star-on", IconLoader::Other), + tr("Add to Spotify starred"), this); connect(add_to_starred, SIGNAL(triggered()), SLOT(AddCurrentSongToStarredPlaylist())); playlistitem_actions_.append(add_to_starred); diff --git a/src/library/librarymodel.cpp b/src/library/librarymodel.cpp index 2ee9c21ad..2f88e967f 100644 --- a/src/library/librarymodel.cpp +++ b/src/library/librarymodel.cpp @@ -107,9 +107,10 @@ LibraryModel::LibraryModel(LibraryBackend* backend, Application* app, Utilities::GetConfigPath(Utilities::Path_CacheRoot) + "/pixmapcache"); icon_cache_->setMaximumCacheSize(LibraryModel::kIconCacheSize); - no_cover_icon_ = QPixmap(":nocover.png") - .scaled(kPrettyCoverSize, kPrettyCoverSize, - Qt::KeepAspectRatio, Qt::SmoothTransformation); + no_cover_icon_ = QPixmap(IconLoader::Load("nocover", IconLoader::Other) + .pixmap(300)).scaled(kPrettyCoverSize, + kPrettyCoverSize, Qt::KeepAspectRatio, + Qt::SmoothTransformation); connect(backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList))); diff --git a/src/library/libraryview.cpp b/src/library/libraryview.cpp index 8de99fcc4..ef4027709 100644 --- a/src/library/libraryview.cpp +++ b/src/library/libraryview.cpp @@ -173,7 +173,8 @@ LibraryView::LibraryView(QWidget* parent) app_(nullptr), filter_(nullptr), total_song_count_(-1), - nomusic_(":nomusic.png"), + nomusic_(IconLoader::Load("nocover", + IconLoader::Other).pixmap(300)), context_menu_(nullptr), is_in_keyboard_search_(false) { setItemDelegate(new LibraryItemDelegate(this)); diff --git a/src/playlist/playlistcontainer.cpp b/src/playlist/playlistcontainer.cpp index d0145f20d..c150f13e2 100644 --- a/src/playlist/playlistcontainer.cpp +++ b/src/playlist/playlistcontainer.cpp @@ -224,11 +224,11 @@ void PlaylistContainer::SetViewModel(Playlist* playlist) { } void PlaylistContainer::ActivePlaying() { - UpdateActiveIcon(QIcon(":tiny-start.png")); + UpdateActiveIcon(IconLoader::Load("tiny-start", IconLoader::Other)); } void PlaylistContainer::ActivePaused() { - UpdateActiveIcon(QIcon(":tiny-pause.png")); + UpdateActiveIcon(IconLoader::Load("tiny-pause", IconLoader::Other)); } void PlaylistContainer::ActiveStopped() { UpdateActiveIcon(QIcon()); } diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 6608f0e78..e34c2c53f 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -26,6 +26,7 @@ #include "core/player.h" #include "covers/currentartloader.h" #include "ui/qt_blurimage.h" +#include "ui/iconloader.h" #include #include @@ -127,8 +128,10 @@ PlaylistView::PlaylistView(QWidget* parent) inhibit_autoscroll_(false), currently_autoscrolling_(false), row_height_(-1), - currenttrack_play_(":currenttrack_play.png"), - currenttrack_pause_(":currenttrack_pause.png"), + currenttrack_play_(IconLoader::Load("currenttrack_play", + IconLoader::Other).pixmap(16)), + currenttrack_pause_(IconLoader::Load("currenttrack_pause", + IconLoader::Other).pixmap(16)), cached_current_row_row_(-1), drop_indicator_row_(-1), drag_over_(false), diff --git a/src/ui/albumcovermanager.cpp b/src/ui/albumcovermanager.cpp index 9f6e0df34..51ecf2bbd 100644 --- a/src/ui/albumcovermanager.cpp +++ b/src/ui/albumcovermanager.cpp @@ -34,6 +34,7 @@ #include "widgets/forcescrollperpixel.h" #include "ui/albumcoverchoicecontroller.h" #include "ui/albumcoverexport.h" +#include "ui/iconloader.h" #include #include @@ -88,7 +89,8 @@ AlbumCoverManager::AlbumCoverManager(Application* app, album_cover_choice_controller_->SetApplication(app_); // Get a square version of nocover.png - QImage nocover(":/nocover.png"); + QImage nocover(IconLoader::Load("nocover", IconLoader::Other).pixmap(300) + .toImage()); nocover = nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage square_nocover(120, 120, QImage::Format_ARGB32); @@ -599,7 +601,8 @@ void AlbumCoverManager::SaveCoverToFile() { // load the image from disk if (song.has_manually_unset_cover()) { - image = QImage(":/nocover.png"); + image = IconLoader::Load("nocover", IconLoader::Other).pixmap(300) + .toImage(); } else { if (!song.art_manual().isEmpty() && QFile::exists(song.art_manual())) { image = QImage(song.art_manual()); @@ -607,7 +610,8 @@ void AlbumCoverManager::SaveCoverToFile() { QFile::exists(song.art_automatic())) { image = QImage(song.art_automatic()); } else { - image = QImage(":/nocover.png"); + image = IconLoader::Load("nocover", IconLoader::Other).pixmap(300) + .toImage(); } } diff --git a/src/ui/edittagdialog.cpp b/src/ui/edittagdialog.cpp index de8a606ad..d1e0d3a83 100644 --- a/src/ui/edittagdialog.cpp +++ b/src/ui/edittagdialog.cpp @@ -62,7 +62,10 @@ EditTagDialog::EditTagDialog(Application* app, QWidget* parent) cover_art_is_set_(false), results_dialog_(new TrackSelectionDialog(this)) { cover_options_.default_output_image_ = - AlbumCoverLoader::ScaleAndPad(cover_options_, QImage(":nocover.png")); + AlbumCoverLoader::ScaleAndPad(cover_options_, + IconLoader::Load("nocover", + IconLoader::Other).pixmap(300) + .toImage()); connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage, QImage)), diff --git a/src/ui/iconloader.cpp b/src/ui/iconloader.cpp index 426d4b896..c992a2cf0 100644 --- a/src/ui/iconloader.cpp +++ b/src/ui/iconloader.cpp @@ -1,5 +1,6 @@ /* This file is part of Clementine. Copyright 2010, David Sansome + Copyright 2015 - 2016, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,7 +32,7 @@ void IconLoader::Init() { sizes_ << 22 << 32 << 48; custom_icon_path_ = Utilities::GetConfigPath(Utilities::Path_Icons); icon_sub_path_.clear(); - icon_sub_path_ << "/icons" << "/providers" << "/last.fm"; + icon_sub_path_ << "/icons" << "/providers" << "/last.fm" << ""; } QIcon IconLoader::Load(const QString& name, const IconType& icontype) { @@ -48,22 +49,30 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) { case Base: case Provider: break; - case Lastfm: { + case Lastfm: case Other: { // lastfm icons location - const QString custom_lastfm_icon_location = custom_icon_path_ + "/last.fm"; - if (QDir(custom_lastfm_icon_location).exists()) { + const QString custom_fm_other_icon_location = custom_icon_path_ + + icon_sub_path_.at(icontype); + if (QDir(custom_fm_other_icon_location).exists()) { // Try to load icons from the custom icon location initially const QString locate_file( - custom_lastfm_icon_location + "/" + name + ".png"); + custom_fm_other_icon_location + "/" + name + ".png"); if (QFile::exists(locate_file)) ret.addFile(locate_file); if (!ret.isNull()) return ret; } - // Otherwise use our fallback theme - const QString lastfm_path_file(":/last.fm/" + name + ".png"); +#if QT_VERSION >= 0x040600 + // Then try to load it from the system theme + ret = QIcon::fromTheme(name); + if (!ret.isNull()) return ret; +#endif - if (QFile::exists(lastfm_path_file)) ret.addFile(lastfm_path_file); + // Otherwise use our fallback theme + const QString path_file(":" + icon_sub_path_.at(icontype) + + "/" + name + ".png"); + + if (QFile::exists(path_file)) ret.addFile(path_file); if (ret.isNull()) qLog(Warning) << "Couldn't load icon" << name; return ret; } @@ -74,14 +83,16 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) { return ret; } - const QString custom_icon_location = custom_icon_path_ + icon_sub_path_.at(icontype); + const QString custom_icon_location = custom_icon_path_ + + icon_sub_path_.at(icontype); if (QDir(custom_icon_location).exists()) { // Try to load icons from the custom icon location initially const QString locate(custom_icon_location + "/%1x%2/%3.png"); for (int size : sizes_) { QString filename_custom(locate.arg(size).arg(size).arg(name)); - if (QFile::exists(filename_custom)) ret.addFile(filename_custom, QSize(size, size)); + if (QFile::exists(filename_custom)) ret.addFile(filename_custom, + QSize(size, size)); } if (!ret.isNull()) return ret; } @@ -103,4 +114,3 @@ QIcon IconLoader::Load(const QString& name, const IconType& icontype) { if (ret.isNull()) qLog(Warning) << "Couldn't load icon" << name; return ret; } - diff --git a/src/ui/iconloader.h b/src/ui/iconloader.h index a854f0524..b6f994321 100644 --- a/src/ui/iconloader.h +++ b/src/ui/iconloader.h @@ -1,5 +1,6 @@ /* This file is part of Clementine. Copyright 2010, David Sansome + Copyright 2015 - 2016, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,7 +26,8 @@ class IconLoader { enum IconType { Base = 0, Provider = 1, - Lastfm = 2 + Lastfm = 2, + Other = 3 }; static void Init(); diff --git a/src/ui/notificationssettingspage.cpp b/src/ui/notificationssettingspage.cpp index a4826505e..060d75ad3 100644 --- a/src/ui/notificationssettingspage.cpp +++ b/src/ui/notificationssettingspage.cpp @@ -19,6 +19,7 @@ #include "notificationssettingspage.h" #include "settingsdialog.h" #include "ui_notificationssettingspage.h" +#include "ui/iconloader.h" #include "widgets/osdpretty.h" #include @@ -34,7 +35,8 @@ NotificationsSettingsPage::NotificationsSettingsPage(SettingsDialog* dialog) setWindowIcon(IconLoader::Load("help-hint", IconLoader::Base)); pretty_popup_->SetMessage(tr("OSD Preview"), tr("Drag to reposition"), - QImage(":nocover.png")); + IconLoader::Load("nocover", IconLoader::Other) + .pixmap(300).toImage()); ui_->notifications_bg_preset->setItemData(0, QColor(OSDPretty::kPresetBlue), Qt::DecorationRole); diff --git a/src/ui/systemtrayicon.cpp b/src/ui/systemtrayicon.cpp index d3fabf650..109bfca70 100644 --- a/src/ui/systemtrayicon.cpp +++ b/src/ui/systemtrayicon.cpp @@ -28,11 +28,15 @@ #include +#include "ui/iconloader.h" + SystemTrayIcon::SystemTrayIcon(QObject* parent) : QObject(parent), percentage_(0), - playing_icon_(":/tiny-start.png"), - paused_icon_(":/tiny-pause.png") {} + playing_icon_(IconLoader::Load("tiny-start", + IconLoader::Other).pixmap(64)), + paused_icon_(IconLoader::Load("tiny-pause", + IconLoader::Other).pixmap(64)) {} QPixmap SystemTrayIcon::CreateIcon(const QPixmap& icon, const QPixmap& grey_icon) { diff --git a/src/widgets/favoritewidget.cpp b/src/widgets/favoritewidget.cpp index ed5e88e74..271a11f76 100644 --- a/src/widgets/favoritewidget.cpp +++ b/src/widgets/favoritewidget.cpp @@ -25,6 +25,7 @@ #include #include "core/logging.h" +#include "ui/iconloader.h" const int FavoriteWidget::kStarSize = 16; @@ -32,8 +33,8 @@ FavoriteWidget::FavoriteWidget(int tab_index, bool favorite, QWidget* parent) : QWidget(parent), tab_index_(tab_index), favorite_(favorite), - on_(":/star-on.png"), - off_(":/star-off.png") {} + on_(IconLoader::Load("star-on", IconLoader::Other).pixmap(16)), + off_(IconLoader::Load("star-off", IconLoader::Other).pixmap(16)) {} void FavoriteWidget::SetFavorite(bool favorite) { if (favorite_ != favorite) { diff --git a/src/widgets/ratingwidget.cpp b/src/widgets/ratingwidget.cpp index 43973eb97..0efbd1edb 100644 --- a/src/widgets/ratingwidget.cpp +++ b/src/widgets/ratingwidget.cpp @@ -22,13 +22,15 @@ #include #include +#include "ui/iconloader.h" + const int RatingPainter::kStarCount; const int RatingPainter::kStarSize; RatingPainter::RatingPainter() { // Load the base pixmaps - QPixmap on(":/star-on.png"); - QPixmap off(":/star-off.png"); + QPixmap on(IconLoader::Load("star-on", IconLoader::Other).pixmap(16)); + QPixmap off(IconLoader::Load("star-off", IconLoader::Other).pixmap(16)); // Generate the 10 states, better to do it now than on the fly for (int i = 0; i < kStarCount * 2 + 1; ++i) {