dont show music overlay info on some screens
[xbmc:xbmc-antiquated.git] / xbmc / GuiWindowMusicInfo.cpp
1
2 #include "GUIWindowMusicInfo.h"
3 #include "graphiccontext.h"
4 #include "localizestrings.h"
5 #include "utils/http.h"
6 #include "util.h"
7 #include "picture.h"
8 #include "application.h"
9
10 #define CONTROL_ALBUM           20
11 #define CONTROL_ARTIST  21
12 #define CONTROL_DATE            22
13 #define CONTROL_RATING  23
14 #define CONTROL_GENRE           24
15 #define CONTROL_TONE            25
16 #define CONTROL_STYLES  26
17
18 #define CONTROL_IMAGE            3
19 #define CONTROL_TEXTAREA 4
20
21 #define CONTROL_BTN_TRACKS      5
22 #define CONTROL_BTN_REFRESH     6
23
24 CGUIWindowMusicInfo::CGUIWindowMusicInfo(void)
25 :CGUIDialog(0)
26 {
27         m_pTexture=NULL;
28 }
29
30 CGUIWindowMusicInfo::~CGUIWindowMusicInfo(void)
31 {
32 }
33
34
35 void CGUIWindowMusicInfo::OnKey(const CKey& key)
36 {
37   if (key.IsButton())
38   {
39     if ( key.GetButtonCode() == KEY_BUTTON_BACK  || key.GetButtonCode() == KEY_REMOTE_BACK)
40     {
41       Close();
42       return;
43     }
44   }
45   CGUIWindow::OnKey(key);
46 }
47
48 bool CGUIWindowMusicInfo::OnMessage(CGUIMessage& message)
49 {
50   switch ( message.GetMessage() )
51   {
52                 case GUI_MSG_WINDOW_DEINIT:
53                 {
54                         m_pAlbum=NULL;
55                         if (m_pTexture)
56                         {
57                                 m_pTexture->Release();
58                                 m_pTexture=NULL;
59                         }
60                         g_application.EnableOverlay();
61                 }
62                 break;
63
64     case GUI_MSG_WINDOW_INIT:
65     {
66                         g_application.DisableOverlay();
67                         m_pTexture=NULL;
68                         m_bViewReview=true;
69                         Refresh();
70     }
71                 break;
72
73
74     case GUI_MSG_CLICKED:
75     {
76       int iControl=message.GetSenderId();
77                         if (iControl==CONTROL_BTN_REFRESH)
78                         {
79                                 if ( m_pAlbum->Load())
80                                 {
81                                         CStdString strThumb;
82                                         CStdString strImage=m_pAlbum->GetImageURL();
83                                         CUtil::GetThumbnail(strImage,strThumb);
84                                         DeleteFile(strThumb.c_str());
85                                 }
86                                 Refresh();
87                         }
88
89                         if (iControl==CONTROL_BTN_TRACKS)
90                         {
91                                 m_bViewReview=!m_bViewReview;
92                                 Update();
93                         }
94     }
95     break;
96   }
97
98   return CGUIWindow::OnMessage(message);
99 }
100
101 void CGUIWindowMusicInfo::SetAlbum(CMusicAlbumInfo& album)
102 {
103                 m_pAlbum=&album;
104 }
105
106 void CGUIWindowMusicInfo::Update()
107 {
108         if (!m_pAlbum) return;
109         SetLabel(CONTROL_ALBUM, m_pAlbum->GetTitle() );
110         SetLabel(CONTROL_ARTIST, m_pAlbum->GetArtist() );
111         SetLabel(CONTROL_DATE, m_pAlbum->GetDateOfRelease() );
112         //SetLabel(CONTROL_RATING, m_pAlbum->GetRating() );
113         SetLabel(CONTROL_GENRE, m_pAlbum->GetGenre() );
114         SetLabel(CONTROL_TONE, m_pAlbum->GetTones() );
115         SetLabel(CONTROL_STYLES, m_pAlbum->GetStyles() );
116
117         if (m_bViewReview)
118         {
119                         SET_CONTROL_LABEL(GetID(), CONTROL_TEXTAREA,m_pAlbum->GetReview());
120                         SET_CONTROL_LABEL(GetID(), CONTROL_BTN_TRACKS,182);
121         }
122         else
123         {
124                 CStdString strLine;
125                 for (int i=0; i < m_pAlbum->GetNumberOfSongs();++i)
126                 {
127                         const CMusicSong& song=m_pAlbum->GetSong(i);
128                         CStdString strTmp;
129                         strTmp.Format("%i. %-30s\n",
130                                                         song.GetTrack(), 
131                                                         song.GetSongName().c_str());
132                         strLine+=strTmp;
133                 };
134
135                 SET_CONTROL_LABEL(GetID(), CONTROL_TEXTAREA,strLine);
136
137                 for (int i=0; i < m_pAlbum->GetNumberOfSongs();++i)
138                 {
139                         const CMusicSong& song=m_pAlbum->GetSong(i);
140                         CStdString strTmp;
141                         int iSec=song.GetDuration();
142                         int iMin=iSec/60;
143                         iSec = iSec%60;
144                         strTmp.Format("%i:%02.2i",iMin,iSec);
145                         CGUIMessage msg3(GUI_MSG_LABEL2_SET,GetID(),CONTROL_TEXTAREA,i,0);
146                         msg3.SetLabel(strTmp);
147                         g_graphicsContext.SendMessage(msg3);
148                 }
149
150                 SET_CONTROL_LABEL(GetID(), CONTROL_BTN_TRACKS,183);
151
152         }
153
154 }
155
156 void CGUIWindowMusicInfo::SetLabel(int iControl, const CStdString& strLabel)
157 {
158         if (strLabel.size()==0) return;
159         
160         CGUIMessage msg(GUI_MSG_LABEL_SET,GetID(),iControl);
161         msg.SetLabel(strLabel);
162         OnMessage(msg);
163
164 }
165
166 void  CGUIWindowMusicInfo::Render()
167 {
168         CGUIDialog::Render();
169   if (!m_pTexture) return;
170
171         const CGUIControl* pControl=GetControl(CONTROL_IMAGE);
172         DWORD x=pControl->GetXPosition();
173         DWORD y=pControl->GetYPosition();
174         DWORD width=pControl->GetWidth();
175         DWORD height=pControl->GetHeight();
176
177         CPicture picture;
178         picture.RenderImage(m_pTexture,x,y,width,height,m_iTextureWidth,m_iTextureHeight);
179 }
180
181
182 void CGUIWindowMusicInfo::Refresh()
183 {
184         if (m_pTexture)
185         {
186                 m_pTexture->Release();
187                 m_pTexture=NULL;
188         }
189
190         CStdString strThumb;
191         CStdString strImage=m_pAlbum->GetImageURL();
192         CUtil::GetAlbumThumb(m_pAlbum->GetTitle(),strThumb);
193         if (!CUtil::FileExists(strThumb) )
194         {
195                 CHTTP http;
196                 http.Download(strImage,strThumb);
197         }
198         CStdString strAlbum;
199         CUtil::GetAlbumInfo(m_pAlbum->GetTitle(),strAlbum);
200         m_pAlbum->Save(strAlbum);
201
202         if (CUtil::FileExists(strThumb) )
203         {
204                 CPicture picture;
205                 m_pTexture=picture.Load(strThumb);
206                 m_iTextureWidth=picture.GetWidth();
207                 m_iTextureHeight=picture.GetWidth();
208         }
209         Update();
210 }