Template magic \o/

This commit is contained in:
John Maguire 2010-05-27 23:34:05 +00:00
parent 791534703c
commit 98c97d13d6
2 changed files with 11 additions and 4 deletions

View File

@ -44,6 +44,14 @@ class RadioModel : public SimpleTreeModel<RadioItem> {
// Needs to be static for RadioPlaylistItem::restore
static RadioService* ServiceByName(const QString& name);
template<typename T>
static T* Service() {
if (sServices.contains(T::kServiceName)) {
return static_cast<T*>(sServices[T::kServiceName]);
}
return NULL;
}
// This is special because Player needs it for scrobbling
LastFMService* GetLastFMService() const;

View File

@ -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<SavedRadio*>(
RadioModel::ServiceByName(SavedRadio::kServiceName));
add_stream_dialog_->set_add_on_accept(saved_radio_);
SavedRadio* saved_radio = RadioModel::Service<SavedRadio>();
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