forked from fishpond-haiku/Haiku-Radio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStationPanel.cpp
More file actions
188 lines (174 loc) · 6.22 KB
/
Copy pathStationPanel.cpp
File metadata and controls
188 lines (174 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2017 Kai Niessen <kai.niessen@online.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File: StationPanel.cpp
* Author: Kai Niessen <kai.niessen@online.de>
*
* Created on April 13, 2017, 1:25 PM
*/
#include <LayoutItem.h>
#include "StationPanel.h"
#include "Debug.h"
#include "Utils.h"
#include <Layout.h>
#include <LayoutBuilder.h>
#include <TranslationUtils.h>
#include "MainWindow.h"
StationPanel::StationPanel(MainWindow* mainWindow, bool expanded)
: BView("stationpanel", B_WILL_DRAW),
fStationItem(NULL),
fMainWindow(mainWindow)
{
SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_UNSET));
fLogo = new BView("logo", B_WILL_DRAW);
fLogo->SetExplicitSize(BSize(96, 96));
fLogo->SetViewColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_2_TINT));
fName = new BTextControl("name", "Name", "-", new BMessage(MSG_CHG_NAME));
fUrl = new BTextControl("url", "Stream URL", "-", new BMessage(MSG_CHG_STREAMURL));
fGenre = new BTextControl("genre", "Genre", "-", new BMessage(MSG_CHG_GENRE));
fStationUrl = new BTextControl("surl", "Station URL", "-", new BMessage(MSG_CHG_STATIONURL));
fVisitStation = new BButton("bnVisitStation", "", new BMessage(MSG_VISIT_STATION));
fVisitStation->SetIcon(Utils::ResourceBitmap(RES_BN_WEB));
fVolume = new BSlider("volume", NULL, new BMessage(MSG_CHG_VOLUME), 0, 100, B_VERTICAL);
fVolume->SetModificationMessage(fVolume->Message());
BLayoutBuilder::Grid<>(this, 7, 3)
.SetInsets(B_USE_SMALL_INSETS)
.SetSpacing(B_USE_ITEM_SPACING, B_USE_SMALL_SPACING)
.Add(fLogo, 0, 0, 1, 3)
.AddTextControl(fName, 1, 0, B_ALIGN_LEFT)
.AddTextControl(fGenre, 3, 0, B_ALIGN_RIGHT, 1, 2)
.AddTextControl(fUrl, 1, 1, B_ALIGN_LEFT, 1, 4)
.AddTextControl(fStationUrl, 1, 2, B_ALIGN_LEFT, 1, 3)
.Add(fVisitStation, 5, 2)
.Add(fVolume, 6, 0, 1, 3)
.End();
}
StationPanel::~StationPanel()
{
}
void
StationPanel::AttachedToWindow() {
fLogo->SetNextHandler(this);
fName->SetTarget(this);
fGenre->SetTarget(this);
fUrl->SetTarget(this);
fStationUrl->SetTarget(this);
fVisitStation->SetTarget(this);
fVolume->SetTarget(this);
SetStation(NULL);
}
void
StationPanel::SetStation(StationListViewItem* stationItem) {
if (stationItem == NULL) {
fName->SetText(NULL);
fName->SetEnabled(false);
fGenre->SetText(NULL);
fGenre->SetEnabled(false);
fUrl->SetText(NULL);
fUrl->SetEnabled(false);
fStationUrl->SetText(NULL);
fStationUrl->SetEnabled(false);
fVisitStation->SetEnabled(false);
fLogo->ClearViewBitmap();
fVolume->SetValue(0);
fVolume->SetEnabled(false);
fStationItem = NULL;
} else {
if (stationItem->Player() && stationItem->Player()->State() == StreamPlayer::Playing) {
fVolume->SetEnabled(true);
fVolume->SetValue(stationItem->Player()->Volume() * 100);
} else {
fVolume->SetEnabled(false);
}
fStationItem = stationItem;
Station* station = stationItem->GetStation();
if (station->Logo())
fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), fLogo->Bounds(), 0, B_FILTER_BITMAP_BILINEAR);
else
fLogo->ClearViewBitmap();
fName->SetEnabled(true);
fName->SetText(station->Name()->String());
fGenre->SetEnabled(true);
fGenre->SetText(station->Genre().String());
fUrl->SetEnabled(true);
fUrl->SetText(station->StreamUrl().UrlString());
fStationUrl->SetEnabled(true);
fStationUrl->SetText(station->StationUrl().UrlString());
fVisitStation->SetEnabled(true);
}
}
void
StationPanel::StateChanged(StreamPlayer::PlayState newState) {
if (fStationItem && fStationItem->Player() && fStationItem->Player()->State() == StreamPlayer::Playing) {
fVolume->SetEnabled(true);
fVolume->SetValue(fStationItem->Player()->Volume() * 100);
} else {
fVolume->SetEnabled(false);
fVolume->SetValue(0);
}
}
void
StationPanel::MessageReceived(BMessage* msg) {
Station* station = (fStationItem != NULL) ? fStationItem->GetStation() : NULL;
if (station) {
entry_ref ref;
BBitmap* bm;
if (msg->WasDropped() &&
msg->IsSourceRemote() &&
msg->FindRef("refs", &ref) == B_OK &&
(bm = BTranslationUtils::GetBitmap(&ref))) {
station->SetLogo(bm);
fLogo->SetViewBitmap(station->Logo(), station->Logo()->Bounds(), fLogo->Bounds(), 0, B_FILTER_BITMAP_BILINEAR);
return;
}
switch (msg->what) {
case MSG_CHG_VOLUME: {
StreamPlayer* player = fStationItem->Player();
if (player) {
player->SetVolume(fVolume->Value() / 100.0);
}
break;
}
case MSG_CHG_NAME:
station->SetName(fName->Text());
break;
case MSG_CHG_STREAMURL:
station->SetStreamUrl(fUrl->Text());
break;
case MSG_CHG_GENRE:
station->SetGenre(fGenre->Text());
break;
case MSG_CHG_STATIONURL:
station->SetStation(fStationUrl->Text());
break;
case MSG_VISIT_STATION :
MSG("Trying to launch url %s\n", station->StationUrl().UrlString().String());
if (station->StationUrl().UrlString().IsEmpty()) {
BString search;
search.SetToFormat("http://google.com/search?q=%s", BUrl::UrlEncode(*station->Name()).String());
BUrl searchUrl(search);
searchUrl.OpenWithPreferredApplication(false);
} else
station->StationUrl().OpenWithPreferredApplication(false);
break;
default:
BView::MessageReceived(msg);
}
} else
BView::MessageReceived(msg);
}