/
GUIWindowLoginScreen.cpp
319 lines (279 loc) · 9.24 KB
/
GUIWindowLoginScreen.cpp
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
/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.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 "system.h"
#include "Application.h"
#include "ApplicationMessenger.h"
#include "GUIWindowLoginScreen.h"
#include "settings/GUIWindowSettingsProfile.h"
#include "dialogs/GUIDialogContextMenu.h"
#include "settings/GUIDialogProfileSettings.h"
#include "GUIPassword.h"
#ifdef HAS_PYTHON
#include "interfaces/python/XBPython.h"
#endif
#ifdef HAS_JSONRPC
#include "interfaces/json-rpc/JSONRPC.h"
#endif
#include "interfaces/Builtins.h"
#include "utils/Weather.h"
#include "network/Network.h"
#include "addons/Skin.h"
#include "settings/Profile.h"
#include "guilib/GUIMessage.h"
#include "GUIUserMessages.h"
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogOK.h"
#include "settings/Settings.h"
#include "settings/GUISettings.h"
#include "FileItem.h"
#include "guilib/LocalizeStrings.h"
#include "addons/AddonManager.h"
#define CONTROL_BIG_LIST 52
#define CONTROL_LABEL_HEADER 2
#define CONTROL_LABEL_SELECTED_PROFILE 3
CGUIWindowLoginScreen::CGUIWindowLoginScreen(void)
: CGUIWindow(WINDOW_LOGIN_SCREEN, "LoginScreen.xml")
{
watch.StartZero();
m_vecItems = new CFileItemList;
m_iSelectedItem = -1;
m_loadType = KEEP_IN_MEMORY;
}
CGUIWindowLoginScreen::~CGUIWindowLoginScreen(void)
{
delete m_vecItems;
}
bool CGUIWindowLoginScreen::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
m_viewControl.Reset();
m_vecItems->Clear();
}
break;
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_BIG_LIST)
{
int iAction = message.GetParam1();
// iItem is checked for validity inside these routines
if (iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
{
int iItem = m_viewControl.GetSelectedItem();
bool bResult = OnPopupMenu(m_viewControl.GetSelectedItem());
if (bResult)
{
Update();
CGUIMessage msg(GUI_MSG_ITEM_SELECT,GetID(),CONTROL_BIG_LIST,iItem);
OnMessage(msg);
}
return bResult;
}
else if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
{
int iItem = m_viewControl.GetSelectedItem();
bool bCanceled;
bool bOkay = g_passwordManager.IsProfileLockUnlocked(iItem, bCanceled);
if (bOkay)
{
LoadProfile(iItem);
}
else
{
if (!bCanceled && iItem != 0)
CGUIDialogOK::ShowAndGetInput(20068,20117,20022,20022);
}
}
}
}
break;
case GUI_MSG_SETFOCUS:
{
if (m_viewControl.HasControl(message.GetControlId()) && m_viewControl.GetCurrentControl() != message.GetControlId())
{
m_viewControl.SetFocused();
return true;
}
}
default:
break;
}
return CGUIWindow::OnMessage(message);
}
bool CGUIWindowLoginScreen::OnAction(const CAction &action)
{
// don't allow built in actions to act here except shutdown related ones.
// this forces only navigation type actions to be performed.
if (action.GetID() == ACTION_BUILT_IN_FUNCTION)
{
CStdString actionName = action.GetName();
actionName.ToLower();
if (actionName.Find("shutdown") != -1)
CBuiltins::Execute(action.GetName());
return true;
}
return CGUIWindow::OnAction(action);
}
bool CGUIWindowLoginScreen::OnBack(int actionID)
{
// no escape from the login window
return false;
}
void CGUIWindowLoginScreen::FrameMove()
{
if (GetFocusedControlID() == CONTROL_BIG_LIST && g_windowManager.GetTopMostModalDialogID() == WINDOW_INVALID)
if (m_viewControl.HasControl(CONTROL_BIG_LIST))
m_iSelectedItem = m_viewControl.GetSelectedItem();
CStdString strLabel;
strLabel.Format(g_localizeStrings.Get(20114),m_iSelectedItem+1,g_settings.GetNumProfiles());
SET_CONTROL_LABEL(CONTROL_LABEL_SELECTED_PROFILE,strLabel);
CGUIWindow::FrameMove();
}
void CGUIWindowLoginScreen::OnInitWindow()
{
m_iSelectedItem = (int)g_settings.GetLastUsedProfileIndex();
// Update list/thumb control
m_viewControl.SetCurrentView(DEFAULT_VIEW_LIST);
Update();
m_viewControl.SetFocused();
SET_CONTROL_LABEL(CONTROL_LABEL_HEADER,g_localizeStrings.Get(20115));
SET_CONTROL_VISIBLE(CONTROL_BIG_LIST);
CGUIWindow::OnInitWindow();
}
void CGUIWindowLoginScreen::OnWindowLoaded()
{
CGUIWindow::OnWindowLoaded();
m_viewControl.Reset();
m_viewControl.SetParentWindow(GetID());
m_viewControl.AddView(GetControl(CONTROL_BIG_LIST));
}
void CGUIWindowLoginScreen::Update()
{
m_vecItems->Clear();
for (unsigned int i=0;i<g_settings.GetNumProfiles(); ++i)
{
const CProfile *profile = g_settings.GetProfile(i);
CFileItemPtr item(new CFileItem(profile->getName()));
CStdString strLabel;
if (profile->getDate().IsEmpty())
strLabel = g_localizeStrings.Get(20113);
else
strLabel.Format(g_localizeStrings.Get(20112), profile->getDate());
item->SetLabel2(strLabel);
item->SetArt("thumb", profile->getThumb());
if (profile->getThumb().IsEmpty() || profile->getThumb().Equals("-"))
item->SetArt("thumb", "unknown-user.png");
item->SetLabelPreformated(true);
m_vecItems->Add(item);
}
m_viewControl.SetItems(*m_vecItems);
m_viewControl.SetSelectedItem(m_iSelectedItem);
}
bool CGUIWindowLoginScreen::OnPopupMenu(int iItem)
{
if ( iItem < 0 || iItem >= m_vecItems->Size() ) return false;
bool bSelect = m_vecItems->Get(iItem)->IsSelected();
// mark the item
m_vecItems->Get(iItem)->Select(true);
CContextButtons choices;
choices.Add(1, 20067);
/* if (m_viewControl.GetSelectedItem() != 0) // no deleting the default profile
choices.Add(2, 117); */
if (iItem == 0 && g_passwordManager.iMasterLockRetriesLeft == 0)
choices.Add(3, 12334);
int choice = CGUIDialogContextMenu::ShowAndGetChoice(choices);
if (choice == 3)
{
if (g_passwordManager.CheckLock(g_settings.GetMasterProfile().getLockMode(),g_settings.GetMasterProfile().getLockCode(),20075))
g_passwordManager.iMasterLockRetriesLeft = g_guiSettings.GetInt("masterlock.maxretries");
else // be inconvenient
CApplicationMessenger::Get().Shutdown();
return true;
}
if (!g_passwordManager.IsMasterLockUnlocked(true))
return false;
if (choice == 1)
CGUIDialogProfileSettings::ShowForProfile(m_viewControl.GetSelectedItem());
if (choice == 2)
{
int iDelete = m_viewControl.GetSelectedItem();
m_viewControl.Clear();
g_settings.DeleteProfile(iDelete);
Update();
m_viewControl.SetSelectedItem(0);
}
//NOTE: this can potentially (de)select the wrong item if the filelisting has changed because of an action above.
if (iItem < (int)g_settings.GetNumProfiles())
m_vecItems->Get(iItem)->Select(bSelect);
return (choice > 0);
}
CFileItemPtr CGUIWindowLoginScreen::GetCurrentListItem(int offset)
{
int item = m_viewControl.GetSelectedItem();
if (item < 0 || !m_vecItems->Size()) return CFileItemPtr();
item = (item + offset) % m_vecItems->Size();
if (item < 0) item += m_vecItems->Size();
return m_vecItems->Get(item);
}
void CGUIWindowLoginScreen::LoadProfile(unsigned int profile)
{
// stop service addons and give it some time before we start it again
ADDON::CAddonMgr::Get().StopServices(true);
// stop PVR related services
g_application.StopPVRManager();
if (profile != 0 || !g_settings.IsMasterUser())
{
g_application.getNetwork().NetworkMessage(CNetwork::SERVICES_DOWN,1);
g_settings.LoadProfile(profile);
}
else
{
CGUIWindow* pWindow = g_windowManager.GetWindow(WINDOW_HOME);
if (pWindow)
pWindow->ResetControlStates();
}
g_application.getNetwork().NetworkMessage(CNetwork::SERVICES_UP,1);
g_settings.UpdateCurrentProfileDate();
g_settings.SaveProfiles(PROFILES_FILE);
if (g_settings.GetLastUsedProfileIndex() != profile)
{
g_playlistPlayer.ClearPlaylist(PLAYLIST_VIDEO);
g_playlistPlayer.ClearPlaylist(PLAYLIST_MUSIC);
g_playlistPlayer.SetCurrentPlaylist(PLAYLIST_NONE);
}
// reload the add-ons, or we will first load all add-ons from the master account without checking disabled status
ADDON::CAddonMgr::Get().ReInit();
g_weatherManager.Refresh();
#ifdef HAS_PYTHON
g_pythonParser.m_bLogin = true;
#endif
#ifdef HAS_JSONRPC
JSONRPC::CJSONRPC::Initialize();
#endif
// start services which should run on login
ADDON::CAddonMgr::Get().StartServices(false);
// start PVR related services
g_application.StartPVRManager();
g_windowManager.ChangeActiveWindow(g_SkinInfo->GetFirstWindow());
g_application.UpdateLibraries();
}