2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIWindowSettingsProfile.h"
22 #include "windows/GUIWindowFileManager.h"
24 #include "Application.h"
25 #include "dialogs/GUIDialogContextMenu.h"
26 #include "GUIDialogProfileSettings.h"
27 #include "network/Network.h"
28 #include "utils/URIUtils.h"
29 #include "utils/Weather.h"
30 #include "GUIPassword.h"
31 #include "windows/GUIWindowLoginScreen.h"
32 #include "guilib/GUIWindowManager.h"
33 #include "filesystem/Directory.h"
36 #include "guilib/LocalizeStrings.h"
38 using namespace XFILE;
40 #define CONTROL_PROFILES 2
41 #define CONTROL_LASTLOADED_PROFILE 3
42 #define CONTROL_LOGINSCREEN 4
44 CGUIWindowSettingsProfile::CGUIWindowSettingsProfile(void)
45 : CGUIWindow(WINDOW_SETTINGS_PROFILES, "SettingsProfile.xml")
47 m_listItems = new CFileItemList;
48 m_loadType = KEEP_IN_MEMORY;
51 CGUIWindowSettingsProfile::~CGUIWindowSettingsProfile(void)
56 int CGUIWindowSettingsProfile::GetSelectedItem()
58 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_PROFILES);
59 g_windowManager.SendMessage(msg);
61 return msg.GetParam1();
64 void CGUIWindowSettingsProfile::OnPopupMenu(int iItem)
66 if (iItem == (int)g_settings.GetNumProfiles())
69 // popup the context menu
70 CContextButtons choices;
71 choices.Add(1, 20092); // Load profile
73 choices.Add(2, 117); // Delete
75 int choice = CGUIDialogContextMenu::ShowAndGetChoice(choices);
78 unsigned iCtrlID = GetFocusedControlID();
79 g_application.StopPlaying();
80 CGUIMessage msg2(GUI_MSG_ITEM_SELECTED, g_windowManager.GetActiveWindow(), iCtrlID);
81 g_windowManager.SendMessage(msg2);
82 g_application.getNetwork().NetworkMessage(CNetwork::SERVICES_DOWN,1);
83 g_settings.LoadMasterForLogin();
84 CGUIWindowLoginScreen::LoadProfile(iItem);
90 if (g_settings.DeleteProfile(iItem))
95 CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(),CONTROL_PROFILES,iItem);
99 bool CGUIWindowSettingsProfile::OnMessage(CGUIMessage& message)
101 switch ( message.GetMessage() )
103 case GUI_MSG_WINDOW_DEINIT:
105 CGUIWindow::OnMessage(message);
111 case GUI_MSG_CLICKED:
113 int iControl = message.GetSenderId();
114 if (iControl == CONTROL_PROFILES)
116 int iAction = message.GetParam1();
118 iAction == ACTION_SELECT_ITEM ||
119 iAction == ACTION_MOUSE_LEFT_CLICK ||
120 iAction == ACTION_CONTEXT_MENU ||
121 iAction == ACTION_MOUSE_RIGHT_CLICK
124 CGUIMessage msg(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_PROFILES);
125 g_windowManager.SendMessage(msg);
126 int iItem = msg.GetParam1();
127 if (iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
130 if (iItem <= (int)g_settings.GetNumProfiles() - 1)
136 else if (iItem < (int)g_settings.GetNumProfiles())
138 if (CGUIDialogProfileSettings::ShowForProfile(iItem))
141 CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), 2,iItem);
142 g_windowManager.SendMessage(msg);
149 else if (iItem > (int)g_settings.GetNumProfiles() - 1)
151 CDirectory::Create(URIUtils::AddFileToFolder(g_settings.GetUserDataFolder(),"profiles"));
152 if (CGUIDialogProfileSettings::ShowForProfile(g_settings.GetNumProfiles()))
155 CGUIMessage msg(GUI_MSG_ITEM_SELECT, GetID(), 2,iItem);
156 g_windowManager.SendMessage(msg);
164 else if (iControl == CONTROL_LOGINSCREEN)
166 g_settings.ToggleLoginScreen();
167 g_settings.SaveProfiles(PROFILES_FILE);
174 return CGUIWindow::OnMessage(message);
177 void CGUIWindowSettingsProfile::LoadList()
181 for (unsigned int i = 0; i < g_settings.GetNumProfiles(); i++)
183 const CProfile *profile = g_settings.GetProfile(i);
184 CFileItemPtr item(new CFileItem(profile->getName()));
185 item->SetLabel2(profile->getDate());
186 item->SetArt("thumb", profile->getThumb());
187 item->SetOverlayImage(profile->getLockMode() == LOCK_MODE_EVERYONE ? CGUIListItem::ICON_OVERLAY_NONE : CGUIListItem::ICON_OVERLAY_LOCKED);
188 m_listItems->Add(item);
191 CFileItemPtr item(new CFileItem(g_localizeStrings.Get(20058)));
192 m_listItems->Add(item);
194 CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), CONTROL_PROFILES, 0, 0, m_listItems);
197 if (g_settings.UsingLoginScreen())
199 CONTROL_SELECT(CONTROL_LOGINSCREEN);
203 CONTROL_DESELECT(CONTROL_LOGINSCREEN);
207 void CGUIWindowSettingsProfile::ClearListItems()
209 CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), CONTROL_PROFILES);
210 g_windowManager.SendMessage(msg);
212 m_listItems->Clear();
215 void CGUIWindowSettingsProfile::OnInitWindow()
218 CGUIWindow::OnInitWindow();