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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* 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 2, 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 XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "GUIDialogSongInfo.h"
#include "utils/URIUtils.h"
#include "utils/StringUtils.h"
#include "dialogs/GUIDialogFileBrowser.h"
#include "GUIPassword.h"
#include "GUIUserMessages.h"
#include "music/MusicDatabase.h"
#include "music/windows/GUIWindowMusicBase.h"
#include "music/tags/MusicInfoTag.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/Key.h"
#include "filesystem/File.h"
#include "filesystem/CurlFile.h"
#include "FileItem.h"
#include "settings/AdvancedSettings.h"
#include "settings/MediaSourceSettings.h"
#include "settings/Settings.h"
#include "guilib/LocalizeStrings.h"
#include "TextureCache.h"
#include "music/Album.h"
#include "storage/MediaManager.h"
#include "GUIDialogMusicInfo.h"
using namespace XFILE;
#define CONTROL_OK 10
#define CONTROL_CANCEL 11
#define CONTROL_ALBUMINFO 12
#define CONTROL_GETTHUMB 13
CGUIDialogSongInfo::CGUIDialogSongInfo(void)
: CGUIDialog(WINDOW_DIALOG_SONG_INFO, "DialogSongInfo.xml")
, m_song(new CFileItem)
{
m_cancelled = false;
m_needsUpdate = false;
m_startRating = -1;
m_loadType = KEEP_IN_MEMORY;
}
CGUIDialogSongInfo::~CGUIDialogSongInfo(void)
{
}
bool CGUIDialogSongInfo::OnMessage(CGUIMessage& message)
{
switch (message.GetMessage())
{
case GUI_MSG_WINDOW_DEINIT:
{
if (!m_cancelled && m_startRating != m_song->GetMusicInfoTag()->GetRating())
{
CMusicDatabase db;
if (db.Open()) // OpenForWrite() ?
{
db.SetSongRating(m_song->GetPath(), m_song->GetMusicInfoTag()->GetRating());
db.Close();
}
m_needsUpdate = true;
}
else
{ // cancelled - reset the song rating
SetRating(m_startRating);
m_needsUpdate = false;
}
break;
}
case GUI_MSG_WINDOW_INIT:
m_cancelled = false;
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_CANCEL)
{
m_cancelled = true;
Close();
return true;
}
else if (iControl == CONTROL_OK)
{
m_cancelled = false;
Close();
return true;
}
else if (iControl == CONTROL_ALBUMINFO)
{
CGUIWindowMusicBase *window = (CGUIWindowMusicBase *)g_windowManager.GetWindow(WINDOW_MUSIC_NAV);
if (window)
{
CFileItem item(*m_song);
CStdString path = StringUtils::Format("musicdb://albums/%li",m_albumId);
item.SetPath(path);
item.m_bIsFolder = true;
window->OnInfo(&item, true);
}
return true;
}
else if (iControl == CONTROL_GETTHUMB)
{
OnGetThumb();
return true;
}
}
break;
}
return CGUIDialog::OnMessage(message);
}
bool CGUIDialogSongInfo::OnAction(const CAction &action)
{
char rating = m_song->GetMusicInfoTag()->GetRating();
if (action.GetID() == ACTION_INCREASE_RATING)
{
if (rating < '5')
SetRating(rating + 1);
return true;
}
else if (action.GetID() == ACTION_DECREASE_RATING)
{
if (rating > '0')
SetRating(rating - 1);
return true;
}
else if (action.GetID() == ACTION_SHOW_INFO)
{
Close();
return true;
}
return CGUIDialog::OnAction(action);
}
bool CGUIDialogSongInfo::OnBack(int actionID)
{
m_cancelled = true;
return CGUIDialog::OnBack(actionID);
}
void CGUIDialogSongInfo::OnInitWindow()
{
CMusicDatabase db;
db.Open();
// no known db info - check if parent dir is an album
if (m_song->GetMusicInfoTag()->GetDatabaseId() == -1)
{
CStdString path = URIUtils::GetDirectory(m_song->GetPath());
m_albumId = db.GetAlbumIdByPath(path);
}
else
{
CAlbum album;
db.GetAlbumFromSong(m_song->GetMusicInfoTag()->GetDatabaseId(),album);
m_albumId = album.idAlbum;
}
CONTROL_ENABLE_ON_CONDITION(CONTROL_ALBUMINFO, m_albumId > -1);
CGUIDialog::OnInitWindow();
}
void CGUIDialogSongInfo::SetRating(char rating)
{
if (rating < '0') rating = '0';
if (rating > '5') rating = '5';
if (rating != m_song->GetMusicInfoTag()->GetRating())
{
m_song->GetMusicInfoTag()->SetRating(rating);
// send a message to all windows to tell them to update the fileitem (eg playlistplayer, media windows)
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_UPDATE_ITEM, 0, m_song);
g_windowManager.SendMessage(msg);
}
}
void CGUIDialogSongInfo::SetSong(CFileItem *item)
{
*m_song = *item;
m_song->LoadMusicTag();
m_startRating = m_song->GetMusicInfoTag()->GetRating();
MUSIC_INFO::CMusicInfoLoader::LoadAdditionalTagInfo(m_song.get());
// set artist thumb as well
CMusicDatabase db;
db.Open();
if (item->IsMusicDb())
{
std::vector<int> artists;
CVariant artistthumbs;
db.GetArtistsBySong(item->GetMusicInfoTag()->GetDatabaseId(), true, artists);
for (std::vector<int>::const_iterator artistId = artists.begin(); artistId != artists.end(); ++artistId)
{
std::string thumb = db.GetArtForItem(*artistId, MediaTypeArtist, "thumb");
if (!thumb.empty())
artistthumbs.push_back(thumb);
}
if (artistthumbs.size())
{
m_song->SetProperty("artistthumbs", artistthumbs);
m_song->SetProperty("artistthumb", artistthumbs[0]);
}
}
else if (m_song->HasMusicInfoTag() && !m_song->GetMusicInfoTag()->GetArtist().empty())
{
int idArtist = db.GetArtistByName(m_song->GetMusicInfoTag()->GetArtist()[0]);
std::string thumb = db.GetArtForItem(idArtist, MediaTypeArtist, "thumb");
if (!thumb.empty())
m_song->SetProperty("artistthumb", thumb);
}
m_needsUpdate = false;
}
CFileItemPtr CGUIDialogSongInfo::GetCurrentListItem(int offset)
{
return m_song;
}
bool CGUIDialogSongInfo::DownloadThumbnail(const CStdString &thumbFile)
{
// TODO: Obtain the source...
CStdString source;
CCurlFile http;
http.Download(source, thumbFile);
return true;
}
// Get Thumb from user choice.
// Options are:
// 1. Current thumb
// 2. AllMusic.com thumb
// 3. Local thumb
// 4. No thumb (if no Local thumb is available)
// TODO: Currently no support for "embedded thumb" as there is no easy way to grab it
// without sending a file that has this as it's album to this class
void CGUIDialogSongInfo::OnGetThumb()
{
CFileItemList items;
// Grab the thumbnail from the web
/*
CStdString thumbFromWeb;
thumbFromWeb = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "allmusicThumb.jpg");
if (DownloadThumbnail(thumbFromWeb))
{
CFileItemPtr item(new CFileItem("thumb://allmusic.com", false));
item->SetArt("thumb", thumbFromWeb);
item->SetLabel(g_localizeStrings.Get(20055));
items.Add(item);
}*/
// Current thumb
if (CFile::Exists(m_song->GetArt("thumb")))
{
CFileItemPtr item(new CFileItem("thumb://Current", false));
item->SetArt("thumb", m_song->GetArt("thumb"));
item->SetLabel(g_localizeStrings.Get(20016));
items.Add(item);
}
// local thumb
CStdString cachedLocalThumb;
CStdString localThumb(m_song->GetUserMusicThumb(true));
if (m_song->IsMusicDb())
{
CFileItem item(m_song->GetMusicInfoTag()->GetURL(), false);
localThumb = item.GetUserMusicThumb(true);
}
if (CFile::Exists(localThumb))
{
CFileItemPtr item(new CFileItem("thumb://Local", false));
item->SetArt("thumb", localThumb);
item->SetLabel(g_localizeStrings.Get(20017));
items.Add(item);
}
else
{ // no local thumb exists, so we are just using the allmusic.com thumb or cached thumb
// which is probably the allmusic.com thumb. These could be wrong, so allow the user
// to delete the incorrect thumb
CFileItemPtr item(new CFileItem("thumb://None", false));
item->SetArt("thumb", "DefaultAlbumCover.png");
item->SetLabel(g_localizeStrings.Get(20018));
items.Add(item);
}
CStdString result;
VECSOURCES sources(*CMediaSourceSettings::Get().GetSources("music"));
CGUIDialogMusicInfo::AddItemPathToFileBrowserSources(sources, *m_song);
g_mediaManager.GetLocalDrives(sources);
if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(1030), result))
return; // user cancelled
if (result == "thumb://Current")
return; // user chose the one they have
// delete the thumbnail if that's what the user wants, else overwrite with the
// new thumbnail
CStdString newThumb;
if (result == "thumb://None")
newThumb = "-";
else if (result == "thumb://allmusic.com")
newThumb.clear();
else if (result == "thumb://Local")
newThumb = localThumb;
else
newThumb = result;
// update thumb in the database
CMusicDatabase db;
if (db.Open())
{
db.SetArtForItem(m_song->GetMusicInfoTag()->GetDatabaseId(), m_song->GetMusicInfoTag()->GetType(), "thumb", newThumb);
db.Close();
}
m_song->SetArt("thumb", newThumb);
// tell our GUI to completely reload all controls (as some of them
// are likely to have had this image in use so will need refreshing)
CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_REFRESH_THUMBS);
g_windowManager.SendMessage(msg);
// m_hasUpdatedThumb = true;
}
|