added: new command "XBMC.RestartApp" for skinners to restart only the application
[xbmc:xbmc-antiquated.git] / xbmc / GUIWindowHome.cpp
1 #include "stdafx.h"
2 #include "guiwindowhome.h"
3 #include "localizestrings.h"
4 #include "texturemanager.h"
5 #include "xbox/iosupport.h"
6 #include "xbox/undocumented.h"
7 #include "xbox/xkutils.h"
8 #include "settings.h"
9 #include "sectionloader.h"
10 #include "util.h"
11 #include "application.h"
12 #include "Credits.h"
13
14 #define CONTROL_BTN_SHUTDOWN            10
15 #define CONTROL_BTN_DASHBOARD           11
16 #define CONTROL_BTN_REBOOT                      12
17 #define CONTROL_BTN_CREDITS                     13
18 #define CONTROL_BTN_ONLINE                      14
19
20
21 CGUIWindowHome::CGUIWindowHome(void) : CGUIWindow(0)
22 {
23         m_iLastControl=-1;
24         m_iLastMenuOption=-1;
25
26         ON_CLICK_MESSAGE(CONTROL_BTN_SHUTDOWN,  CGUIWindowHome, OnClickShutdown);       
27         ON_CLICK_MESSAGE(CONTROL_BTN_DASHBOARD, CGUIWindowHome, OnClickDashboard);      
28         ON_CLICK_MESSAGE(CONTROL_BTN_REBOOT,    CGUIWindowHome, OnClickReboot); 
29         ON_CLICK_MESSAGE(CONTROL_BTN_CREDITS,   CGUIWindowHome, OnClickCredits);        
30         ON_CLICK_MESSAGE(CONTROL_BTN_ONLINE,    CGUIWindowHome, OnClickOnlineGaming);   
31 }
32
33 CGUIWindowHome::~CGUIWindowHome(void)
34 {
35 }
36
37
38 bool CGUIWindowHome::OnMessage(CGUIMessage& message)
39 {
40         switch ( message.GetMessage() )
41         {
42                 case GUI_MSG_WINDOW_INIT:
43                 {
44                         int iFocusControl=m_iLastControl;
45                         CGUIWindow::OnMessage(message);
46       
47                         // make controls 101-120 invisible...
48                         for (int iControl=102; iControl < 120; iControl++)
49                         {
50                                 SET_CONTROL_HIDDEN(GetID(), iControl);
51                         }
52
53                         if (m_iLastMenuOption>0)
54                         {
55                                 SET_CONTROL_VISIBLE(GetID(), m_iLastMenuOption+100);
56                         }
57
58                         if (iFocusControl<0)
59                         {
60                                 iFocusControl=GetFocusedControl();
61                                 m_iLastControl=iFocusControl;
62                         }
63
64                         SET_CONTROL_FOCUS(GetID(), iFocusControl, 0);
65                         return true;
66                 }
67
68                 case GUI_MSG_SETFOCUS:
69                 {
70                         int iControl = message.GetControlId();
71                         m_iLastControl=iControl;
72                         if (iControl>=2 && iControl <=9)
73                         {
74                                 m_iLastMenuOption = m_iLastControl;
75
76                                 // make controls 101-120 invisible...
77                                 for (int i=102; i < 120; i++)
78                                 {
79                                                 SET_CONTROL_HIDDEN(GetID(), i);
80                                 }
81                 
82                                 SET_CONTROL_VISIBLE(GetID(), iControl+100);
83                             break;
84                         }
85                 }
86
87                 case GUI_MSG_CLICKED:
88                 {
89                         m_iLastControl = message.GetSenderId();
90                         break;
91                 }
92         }
93         return CGUIWindow::OnMessage(message);
94 }
95
96 void CGUIWindowHome::OnClickShutdown(CGUIMessage& aMessage)
97 {
98         g_applicationMessenger.Shutdown();
99 }
100
101 void CGUIWindowHome::OnClickDashboard(CGUIMessage& aMessage)
102 {
103         CUtil::RunXBE(g_stSettings.szDashboard);
104 }
105
106 void CGUIWindowHome::OnClickReboot(CGUIMessage& aMessage)
107 {
108         CGUIDialogYesNo* dlgYesNo = (CGUIDialogYesNo*)m_gWindowManager.GetWindow(WINDOW_DIALOG_YES_NO);
109         if (dlgYesNo)
110         {
111                 dlgYesNo->SetHeading(13313);
112                 dlgYesNo->SetLine(0, 13308);
113                 dlgYesNo->SetLine(1, 13309);
114                 dlgYesNo->SetLine(2, "");
115                 dlgYesNo->DoModal(GetID());
116
117     if(dlgYesNo->IsConfirmed())
118       g_applicationMessenger.Restart();
119     else
120       g_applicationMessenger.RestartApp();
121   }
122 }
123
124 void CGUIWindowHome::OnClickCredits(CGUIMessage& aMessage)
125 {
126         RunCredits();
127 }
128
129 void CGUIWindowHome::OnClickOnlineGaming(CGUIMessage& aMessage)
130 {
131         m_gWindowManager.ActivateWindow( WINDOW_BUDDIES );
132 }
133
134 void CGUIWindowHome::OnAction(const CAction &action)
135 {
136         CGUIWindow::OnAction(action);
137 }
138
139 void CGUIWindowHome::Render()
140 {
141   WCHAR szText[128];
142
143   SYSTEMTIME time;
144         GetLocalTime(&time);
145
146   GetDate(szText,&time);
147         
148         SET_CONTROL_LABEL(GetID(), 200,szText);
149         SET_CONTROL_LABEL(GetID(), 201,szText);
150
151         GetTime(szText,&time);
152
153         SET_CONTROL_LABEL(GetID(), 201,szText);
154
155   CGUIWindow::Render();
156 }
157
158
159 VOID CGUIWindowHome::GetDate(WCHAR* wszDate, LPSYSTEMTIME pTime)
160 {
161         if (!pTime) return;
162         if (!wszDate) return;
163         const WCHAR* day;
164         switch (pTime->wDayOfWeek)
165         {
166     case 1 :    day = g_localizeStrings.Get(11).c_str();        break;
167                 case 2 :        day = g_localizeStrings.Get(12).c_str();        break;
168                 case 3 :        day = g_localizeStrings.Get(13).c_str();        break;
169                 case 4 :        day = g_localizeStrings.Get(14).c_str();        break;
170                 case 5 :        day = g_localizeStrings.Get(15).c_str();        break;
171                 case 6 :        day = g_localizeStrings.Get(16).c_str();        break;
172                 default:        day = g_localizeStrings.Get(17).c_str();        break;
173         }
174
175         const WCHAR* month;
176         switch (pTime->wMonth)
177         {
178                 case 1 :        month= g_localizeStrings.Get(21).c_str();       break;
179                 case 2 :        month= g_localizeStrings.Get(22).c_str();       break;
180                 case 3 :        month= g_localizeStrings.Get(23).c_str();       break;
181                 case 4 :        month= g_localizeStrings.Get(24).c_str();       break;
182                 case 5 :        month= g_localizeStrings.Get(25).c_str();       break;
183                 case 6 :        month= g_localizeStrings.Get(26).c_str();       break;
184                 case 7 :        month= g_localizeStrings.Get(27).c_str();       break;
185                 case 8 :        month= g_localizeStrings.Get(28).c_str();       break;
186                 case 9 :        month= g_localizeStrings.Get(29).c_str();       break;
187                 case 10:        month= g_localizeStrings.Get(30).c_str();       break;
188                 case 11:        month= g_localizeStrings.Get(31).c_str();       break;
189                 default:        month= g_localizeStrings.Get(32).c_str();       break;
190         }
191
192         if (day && month)
193                 swprintf(wszDate,L"%s, %s %d", day, month, pTime->wDay);
194         else
195                 swprintf(wszDate,L"no date");
196 }
197
198 VOID CGUIWindowHome::GetTime(WCHAR* szTime, LPSYSTEMTIME pTime)
199 {
200         if (!szTime) return;
201         if (!pTime) return;
202         INT iHour = pTime->wHour;
203         swprintf(szTime,L"%02d:%02d", iHour, pTime->wMinute);
204 }