From 98c97d13d655bcc4d0cbd7fabc2151430460e7fd Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 27 May 2010 23:34:05 +0000 Subject: [PATCH] Template magic \o/ --- src/radio/radiomodel.h | 8 ++++++++ src/ui/mainwindow.cpp | 7 +++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/radio/radiomodel.h b/src/radio/radiomodel.h index 180b7802c..d9be1455d 100644 --- a/src/radio/radiomodel.h +++ b/src/radio/radiomodel.h @@ -44,6 +44,14 @@ class RadioModel : public SimpleTreeModel { // Needs to be static for RadioPlaylistItem::restore static RadioService* ServiceByName(const QString& name); + template + static T* Service() { + if (sServices.contains(T::kServiceName)) { + return static_cast(sServices[T::kServiceName]); + } + return NULL; + } + // This is special because Player needs it for scrobbling LastFMService* GetLastFMService() const; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 9e58bc6f8..555565a70 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -327,11 +327,10 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg LastFMButtonVisibilityChanged(radio_model_->GetLastFMService()->AreButtonsVisible()); // Connections to the saved streams service - SavedRadio* saved_radio_ = qobject_cast( - RadioModel::ServiceByName(SavedRadio::kServiceName)); - add_stream_dialog_->set_add_on_accept(saved_radio_); + SavedRadio* saved_radio = RadioModel::Service(); + add_stream_dialog_->set_add_on_accept(saved_radio); - connect(saved_radio_, SIGNAL(ShowAddStreamDialog()), + connect(saved_radio, SIGNAL(ShowAddStreamDialog()), add_stream_dialog_.get(), SLOT(show())); // Tray icon