[9175b5]: xbmc / GUIWindowSettingsProfile.cpp Maximize Restore History

Repo status: analyzing...

Download this file

GUIWindowSettingsProfile.cpp    231 lines (207 with data), 7.0 kB

  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
#include "stdafx.h"
#include "GUIWindowSettingsProfile.h"
#include "Profile.h"
#include "Settings.h"
#include "../guilib/GUIListItem.h"
#include "keyboard/virtualkeyboard.h"
#include "util.h"
#include "application.h"
#define CONTROL_PROFILES 2
CGUIWindowSettingsProfile::CGUIWindowSettingsProfile(void)
:CGUIWindow(0)
{
m_iLastControl=-1;
}
CGUIWindowSettingsProfile::~CGUIWindowSettingsProfile(void)
{
}
void CGUIWindowSettingsProfile::OnAction(const CAction &action)
{
if (action.wID == ACTION_PREVIOUS_MENU)
{
m_gWindowManager.PreviousWindow();
return;
}
else if (action.wID == ACTION_RENAME_ITEM)
{
int i = GetSelectedItem();
if (i < (int)g_settings.m_vecProfiles.size()) // do nothing when <new profile> is selected
{
CStdString strProfileName;
if (GetKeyboard(strProfileName)) {
CProfile& profile = g_settings.m_vecProfiles.at(i);
profile.setName(strProfileName);
g_settings.Save();
LoadList();
}
}
return;
}
else if (action.wID == ACTION_DELETE_ITEM)
{
int i = GetSelectedItem();
if (i < (int)g_settings.m_vecProfiles.size()) // do nothing when <new profile> is selected
{
{
CGUIDialogYesNo* dlgYesNo = (CGUIDialogYesNo*)m_gWindowManager.GetWindow(WINDOW_DIALOG_YES_NO);
if (dlgYesNo)
{
CStdString message;
CStdString str = g_localizeStrings.Get(13201);
message.Format(str.c_str(), g_settings.m_vecProfiles.at(i).getName());
dlgYesNo->SetHeading(13200);
dlgYesNo->SetLine(0, message);
dlgYesNo->SetLine(1, "");
dlgYesNo->SetLine(2, "");
dlgYesNo->DoModal(GetID());
if (dlgYesNo->IsConfirmed())
{
//delete profile
for (IVECPROFILES iProfile = g_settings.m_vecProfiles.begin(); iProfile != g_settings.m_vecProfiles.end(); ++iProfile)
{
if (iProfile == &g_settings.m_vecProfiles.at(i))
{
::DeleteFile("T:\\" + iProfile->getFileName());
g_settings.m_vecProfiles.erase(iProfile);
g_settings.Save();
break;
}
}
LoadList();
}
}
}
}
return;
}
CGUIWindow::OnAction(action);
}
int CGUIWindowSettingsProfile::GetSelectedItem()
{
CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_PROFILES,0,0,NULL);
g_graphicsContext.SendMessage(msg);
return msg.GetParam1();
}
bool CGUIWindowSettingsProfile::OnMessage(CGUIMessage& message)
{
switch ( message.GetMessage() )
{
case GUI_MSG_WINDOW_DEINIT:
{
m_iLastControl=GetFocusedControl();
}
break;
case GUI_MSG_WINDOW_INIT:
{
CGUIWindow::OnMessage(message);
LoadList();
if (m_iLastControl>-1)
SET_CONTROL_FOCUS(GetID(), m_iLastControl, 0);
return true;
}
break;
case GUI_MSG_CLICKED:
{
int iControl=message.GetSenderId();
if (iControl==CONTROL_PROFILES)
{
int iAction=message.GetParam1();
if (iAction == ACTION_SELECT_ITEM) {
CGUIMessage msg(GUI_MSG_ITEM_SELECTED,GetID(),CONTROL_PROFILES,0,0,NULL);
g_graphicsContext.SendMessage(msg);
int iItem=msg.GetParam1();
if (iItem > (int)g_settings.m_vecProfiles.size() - 1) {
//new profile
CStdString strProfileName;
if (GetKeyboard(strProfileName)) {
CProfile profile;
profile.setName(strProfileName);
CStdString str = "";
int i = 0;
str.Format("T:\\profile%i.xml", i);
while (CUtil::FileExists(str)) {
i++;
str.Format("T:\\profile%i.xml", i);
}
str.Format("profile%i.xml", i);
profile.setFileName(str);
g_settings.m_vecProfiles.push_back(profile);
g_settings.SaveSettingsToProfile(iItem);
g_settings.Save();
LoadList();
return true;
}
}
CSettings::stSettings prevSettings = g_stSettings;
g_application.StopPlaying();
g_settings.LoadProfile(iItem);
//reload stuff
CStdString strLanguagePath;
strLanguagePath.Format("Q:\\language\\%s\\strings.xml", g_stSettings.szDefaultLanguage);
g_localizeStrings.Load(strLanguagePath);
g_graphicsContext.SetD3DParameters(&g_application.m_d3dpp, g_settings.m_ResInfo);
g_graphicsContext.SetGUIResolution(g_stSettings.m_GUIResolution);
g_graphicsContext.SetOffset(g_stSettings.m_iUIOffsetX, g_stSettings.m_iUIOffsetY);
if (
(prevSettings.m_GUIResolution != g_stSettings.m_GUIResolution) ||
(CUtil::cmpnocase(prevSettings.szDefaultSkin, g_stSettings.szDefaultSkin))
)
{
g_application.LoadSkin(g_stSettings.szDefaultSkin);
m_gWindowManager.ActivateWindow(GetID());
}
g_application.StopServices();
g_application.StartServices();
CGUIDialogOK* dlgOK = (CGUIDialogOK*)m_gWindowManager.GetWindow(WINDOW_DIALOG_OK);
if (dlgOK)
{
CStdString message;
CStdString str = g_localizeStrings.Get(13203);
message.Format(str.c_str(), g_settings.m_vecProfiles.at(iItem).getName());
dlgOK->SetHeading(13200);
dlgOK->SetLine(0, message);
dlgOK->SetLine(1, "");
dlgOK->SetLine(2, "");
dlgOK->DoModal(GetID());
}
return true;
}
}
}
break;
}
return CGUIWindow::OnMessage(message);
}
void CGUIWindowSettingsProfile::LoadList()
{
CGUIMessage msg1(GUI_MSG_LABEL_RESET,GetID(),CONTROL_PROFILES,0,0,NULL);
g_graphicsContext.SendMessage(msg1);
for (UCHAR i = 0; i < g_settings.m_vecProfiles.size(); i++) {
CProfile& profile = g_settings.m_vecProfiles.at(i);
CGUIListItem* item = new CGUIListItem(profile.getName());
CGUIMessage msg(GUI_MSG_LABEL_ADD,GetID(),CONTROL_PROFILES,0,0,(void*)item);
g_graphicsContext.SendMessage(msg);
}
CGUIListItem* item = new CGUIListItem(g_localizeStrings.Get(13202));
CGUIMessage msg(GUI_MSG_LABEL_ADD,GetID(),CONTROL_PROFILES,0,0,(void*)item);
g_graphicsContext.SendMessage(msg);
}
bool CGUIWindowSettingsProfile::GetKeyboard(CStdString& strInput)
{
CXBVirtualKeyboard* pKeyboard = (CXBVirtualKeyboard*)m_gWindowManager.GetWindow(WINDOW_VIRTUAL_KEYBOARD);
if (!pKeyboard) return false;
pKeyboard->Reset();
WCHAR wsString[1024];
swprintf( wsString,L"%S", strInput.c_str() );
pKeyboard->SetText(wsString);
pKeyboard->DoModal(m_gWindowManager.GetActiveWindow());
if (pKeyboard->IsConfirmed())
{
const WCHAR* pSearchString=pKeyboard->GetText();
CUtil::Unicode2Ansi(pSearchString,strInput);
if (strInput.IsEmpty())
return false;
return true;
}
return false;
}