1 /* GUI_Stream.cpp */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "GUI_Stream.h"
22 #include "ConfigureStreamDialog.h"
23 #include "GUI_StationSearcher.h"
24 #include "Gui/Plugins/ui_GUI_Stream.h"
25 
26 #include "Components/Streaming/Streams/StreamHandler.h"
27 
28 #include "Utils/Language/Language.h"
29 #include "Gui/Utils/Icons.h"
UI_FWD(GUI_StationSearcher)30 
31 #include <QAction>
32 
33 struct GUI_Stream::Private
34 {
35 	PlaylistCreator* playlistCreator;
36 	GUI_StationSearcher* searcher = nullptr;
37 	QAction* actionSearchRadioStation = nullptr;
38 
39 	Private(PlaylistCreator* playlistCreator) :
40 		playlistCreator(playlistCreator) {}
41 };
42 
43 GUI_Stream::GUI_Stream(PlaylistCreator* playlistCreator, QWidget* parent) :
44 	Gui::AbstractStationPlugin(playlistCreator, parent)
45 {
46 	m = Pimpl::make<Private>(playlistCreator);
47 }
48 
49 GUI_Stream::~GUI_Stream()
50 {
51 	if(ui)
52 	{
53 		delete ui;
54 		ui = nullptr;
55 	}
56 }
57 
58 QString GUI_Stream::name() const
59 {
60 	return "Webstreams";
61 }
62 
63 QString GUI_Stream::displayName() const
64 {
65 	return Lang::get(Lang::Streams);
66 }
67 
68 void GUI_Stream::retranslate()
69 {
70 	Gui::AbstractStationPlugin::retranslate();
71 	ui->retranslateUi(this);
72 
73 	QString action_text = tr("Search radio station");
74 
75 	if(m->actionSearchRadioStation)
76 	{
77 		m->actionSearchRadioStation->setText(action_text);
78 	}
79 
80 	ui->btnSearch->setText(Lang::get(Lang::SearchVerb));
81 	ui->btnSearch->setToolTip(action_text);
82 }
83 
84 void GUI_Stream::initUi()
85 {
86 	setupParent(this, &ui);
87 	Gui::AbstractStationPlugin::initUi();
88 
89 	m->actionSearchRadioStation = new QAction(ui->btnTool);
90 	ui->btnTool->registerAction(m->actionSearchRadioStation);
91 
92 	connect(m->actionSearchRadioStation, &QAction::triggered, this, &GUI_Stream::searchRadioTriggered);
93 	connect(ui->btnSearch, &QPushButton::clicked, this, &GUI_Stream::searchRadioTriggered);
94 
95 	retranslate();
96 }
97 
98 QString GUI_Stream::titleFallbackName() const
99 {
100 	return Lang::get(Lang::Radio);
101 }
102 
103 QComboBox* GUI_Stream::comboStream()
104 {
105 	return ui->comboStream;
106 }
107 
108 QPushButton* GUI_Stream::btnPlay()
109 {
110 	return ui->btnListen;
111 }
112 
113 Gui::MenuToolButton* GUI_Stream::btnMenu()
114 {
115 	return ui->btnTool;
116 }
117 
118 AbstractStationHandler* GUI_Stream::streamHandler() const
119 {
120 	return new StreamHandler(m->playlistCreator);
121 }
122 
123 void GUI_Stream::skinChanged()
124 {
125 	Gui::AbstractStationPlugin::skinChanged();
126 
127 	if(m->actionSearchRadioStation)
128 	{
129 		m->actionSearchRadioStation->setIcon(Gui::Icons::icon(Gui::Icons::Search));
130 	}
131 
132 	if(ui)
133 	{
134 		ui->btnSearch->setIcon(Gui::Icons::icon(Gui::Icons::Search));
135 	}
136 }
137 
138 void GUI_Stream::searchRadioTriggered()
139 {
140 	if(!m->searcher)
141 	{
142 		m->searcher = new GUI_StationSearcher(this);
143 		connect(m->searcher, &GUI_StationSearcher::sigStreamSelected, this, &GUI_Stream::streamSelected);
144 	}
145 
146 	m->searcher->show();
147 }
148 
149 void GUI_Stream::streamSelected(const QString& name, const QString& url, bool save)
150 {
151 	int index = addStream(name, url);
152 	if(save && index >= 0)
153 	{
154 		currentIndexChanged(index);
155 		saveClicked();
156 	}
157 }
158 
159 GUI_ConfigureStation* GUI_Stream::createConfigDialog()
160 {
161 	return new ConfigureStreamDialog(m->playlistCreator, this);
162 }
163