40
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0""
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Language plugin view class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "cplanguageview.h"
|
|
19 |
#include <QDebug>
|
|
20 |
#include <QStringList>
|
|
21 |
#include <QLocale>
|
|
22 |
#include <QDir>
|
|
23 |
#include <QPluginLoader>
|
|
24 |
#include <hbdataform.h>
|
|
25 |
#include <hbdataformmodel.h>
|
|
26 |
#include <hbmessagebox.h>
|
|
27 |
#include <cpsettingformentryitemdata.h>
|
|
28 |
#include <ClockSettingsViewInterface>
|
|
29 |
#include <hbinpututils.h>
|
|
30 |
#include <hbinputsettingproxy>
|
|
31 |
#include <hblocaleutil.h>
|
|
32 |
#include <starterclient.h>
|
|
33 |
#include <hbdevicemessagebox>
|
|
34 |
#include <hbaction.h>
|
|
35 |
#include "cplanguageplugin.h"
|
|
36 |
#include "cplanguagepluginlog.h"
|
|
37 |
|
|
38 |
static int PRIMARY_INPUT_ITEM_INDEX = 0;
|
|
39 |
static int SECONDARY_INPUT_ITEM_INDEX = 1;
|
|
40 |
static int REGION_ITEM_INDEX = 2;
|
|
41 |
|
|
42 |
/*
|
|
43 |
* Constructor
|
|
44 |
*/
|
|
45 |
CpLanguageView::CpLanguageView(QGraphicsItem *parent) :
|
|
46 |
CpBaseSettingView(0,parent),
|
|
47 |
mModel(0),
|
|
48 |
mCurrentLanguagePage(0),
|
|
49 |
mCurrentRegionItem(0),
|
|
50 |
mCurrentPrimaryInputLanguageItem(0),
|
|
51 |
mCurrentSecondaryInputLanguageItem(0),
|
|
52 |
mClockPluginLoader(0)
|
|
53 |
{
|
|
54 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::CpLanguageView")
|
|
55 |
|
|
56 |
mChineseVariant = CpLanguagePluginUtil::isChineseVariant();
|
|
57 |
if (mChineseVariant) {
|
|
58 |
PRIMARY_INPUT_ITEM_INDEX = 0;
|
|
59 |
SECONDARY_INPUT_ITEM_INDEX = -1; // no secondary writing language in Chinese variant
|
|
60 |
REGION_ITEM_INDEX = 1;
|
|
61 |
}
|
|
62 |
|
|
63 |
HbDataForm *form = qobject_cast<HbDataForm*>(widget());
|
|
64 |
if (form) {
|
|
65 |
mModel = new HbDataFormModel;
|
|
66 |
|
|
67 |
form->setHeading(hbTrId("txt_cp_subhead_display_language"));
|
|
68 |
form->setDescription(hbTrId("txt_cp_info_after_changign_deivce_language_device"));
|
|
69 |
|
|
70 |
mLanguageRegionMapping = ExtendedLocaleUtil::localeMappings(true);
|
|
71 |
|
|
72 |
mSupportedLanguages = HbLocaleUtil::supportedLanguages();
|
|
73 |
QStringList localizedLanguages = CpLanguagePluginUtil::localizedLanguageNames(mSupportedLanguages);
|
|
74 |
|
|
75 |
mSupportedRegions = HbLocaleUtil::supportedRegions();
|
|
76 |
QStringList localizedRegions = CpLanguagePluginUtil::localizedRegionNames(mSupportedRegions);
|
|
77 |
|
|
78 |
CPLANG_LOG ( QString("map count:%1").arg(mLanguageRegionMapping.count()) );
|
|
79 |
CPLANG_LOG ( QString("support language count:%1").arg(mSupportedLanguages.count()) );
|
|
80 |
CPLANG_LOG ( QString("support region count:%1").arg(mSupportedRegions.count()) );
|
|
81 |
|
|
82 |
HbInputUtils::listSupportedInputLanguages(mPrimaryInputLanguages);
|
|
83 |
QStringList localizedInputLanguages = CpLanguagePluginUtil::localizedInputLanguageNames(mPrimaryInputLanguages);
|
|
84 |
|
|
85 |
QString currentLanguage = HbLocaleUtil::currentLanguage();
|
|
86 |
|
|
87 |
//prvious setting
|
|
88 |
mPreviousSetting.languageId = currentLanguage;
|
|
89 |
mPreviousSetting.regionId = HbLocaleUtil::currentRegion();
|
|
90 |
mPreviousSetting.primaryWritingLan = HbInputSettingProxy::instance()->globalInputLanguage();
|
|
91 |
mPreviousSetting.secondaryWritingLan = HbInputSettingProxy::instance()->globalSecondaryInputLanguage();
|
|
92 |
|
|
93 |
mCurrentSetting = mPreviousSetting;
|
|
94 |
|
|
95 |
//update with current setting
|
|
96 |
if (LanguageRegionMapping *setting = languageRegionMapping(currentLanguage)) {
|
|
97 |
*setting = mCurrentSetting;
|
|
98 |
}
|
|
99 |
|
|
100 |
for (int index = 0; index < mLanguageRegionMapping.count();index++) {
|
|
101 |
const LanguageRegionMapping &setting = mLanguageRegionMapping.at(index);
|
|
102 |
HbDataFormModelItem *languageAndRegionPage = mModel->appendDataFormPage( HbLocaleUtil::localisedLanguageName(setting.languageId) );
|
|
103 |
mLanguagePages.append(languageAndRegionPage);
|
|
104 |
|
|
105 |
/*
|
|
106 |
* Create primary writing language item.
|
|
107 |
*/
|
|
108 |
HbDataFormModelItem *primaryInputLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
|
|
109 |
hbTrId("txt_cp_setlabel_primary_writing_language"));
|
|
110 |
|
|
111 |
|
|
112 |
int primaryInputLanguageIndex = mPrimaryInputLanguages.indexOf(setting.primaryWritingLan);
|
|
113 |
|
|
114 |
CPLANG_LOG(QLatin1String("Primary input Language:") + setting.primaryWritingLan.asString());
|
|
115 |
CPLANG_LOG(QString("Index of primary input language: %1").arg(primaryInputLanguageIndex));
|
|
116 |
|
|
117 |
fillDataFormComboBoxItem(primaryInputLanguageItem,localizedInputLanguages,primaryInputLanguageIndex);
|
|
118 |
|
|
119 |
form->addConnection(primaryInputLanguageItem, SIGNAL(currentIndexChanged (int)),
|
|
120 |
this,SLOT(onPrimaryInputLanguageChanged(int)));
|
|
121 |
languageAndRegionPage->appendChild(primaryInputLanguageItem);
|
|
122 |
|
|
123 |
/*
|
|
124 |
* Create secondary writing language item.
|
|
125 |
* (No secondary writing language for Chinese variant)
|
|
126 |
*/
|
|
127 |
if (!mChineseVariant) {
|
|
128 |
HbDataFormModelItem *secondaryInputLanguageItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
|
|
129 |
hbTrId("txt_cp_setlabel_secondary_writing_language"));
|
|
130 |
|
|
131 |
form->addConnection(secondaryInputLanguageItem, SIGNAL(currentIndexChanged (int)),
|
|
132 |
this,SLOT(onSecondaryInputLanguageChanged(int)));
|
|
133 |
languageAndRegionPage->appendChild(secondaryInputLanguageItem);
|
|
134 |
}
|
|
135 |
|
|
136 |
/*
|
|
137 |
* Create region item.
|
|
138 |
*/
|
|
139 |
HbDataFormModelItem *regionItem = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem,
|
|
140 |
hbTrId("Region"));
|
|
141 |
|
|
142 |
int regionIndex = mSupportedRegions.indexOf(setting.regionId);
|
|
143 |
|
|
144 |
CPLANG_LOG(QLatin1String("Current region:") + setting.regionId);
|
|
145 |
CPLANG_LOG(QString("Index of current region: %1").arg(regionIndex));
|
|
146 |
|
|
147 |
fillDataFormComboBoxItem(regionItem,localizedRegions,regionIndex);
|
|
148 |
|
|
149 |
form->addConnection(regionItem, SIGNAL(currentIndexChanged (int)),
|
|
150 |
this,SLOT(onRegionChanged(int)));
|
|
151 |
languageAndRegionPage->appendChild(regionItem);
|
|
152 |
|
|
153 |
if (mSupportedLanguages.at(index) == currentLanguage) {
|
|
154 |
mCurrentLanguagePage = languageAndRegionPage;
|
|
155 |
mCurrentRegionItem = mCurrentLanguagePage->childAt(REGION_ITEM_INDEX);
|
|
156 |
mCurrentPrimaryInputLanguageItem = mCurrentLanguagePage->childAt(PRIMARY_INPUT_ITEM_INDEX);
|
|
157 |
mCurrentSecondaryInputLanguageItem = mCurrentLanguagePage->childAt(SECONDARY_INPUT_ITEM_INDEX);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
// update secondary input language item according to primary input language
|
|
162 |
updateSecondaryInputLanguageItem();
|
|
163 |
|
|
164 |
/*
|
|
165 |
* Create region settings item.
|
|
166 |
*/
|
|
167 |
HbDataFormModelItem *regionalSettingsItem = new HbDataFormModelItem(
|
|
168 |
static_cast<HbDataFormModelItem::DataItemType>(CpSettingFormEntryItemData::ButtonEntryItem));
|
|
169 |
regionalSettingsItem->setContentWidgetData("text",hbTrId("txt_cp_button_regional_settings"));
|
|
170 |
regionalSettingsItem->setContentWidgetData("textAlignment",
|
|
171 |
QVariant(Qt::AlignHCenter | Qt::AlignVCenter));
|
|
172 |
form->addConnection(regionalSettingsItem,SIGNAL(clicked()),
|
|
173 |
this,SLOT(launchRegionalSettingsView()));
|
|
174 |
|
|
175 |
mModel->appendDataFormItem(regionalSettingsItem);
|
|
176 |
|
|
177 |
form->setModel(mModel);
|
|
178 |
// active current language page
|
|
179 |
form->setExpanded(mModel->indexFromItem(mCurrentLanguagePage),true);
|
|
180 |
|
|
181 |
|
|
182 |
/*
|
|
183 |
* observe input language changed event
|
|
184 |
*/
|
|
185 |
connect(HbInputSettingProxy::instance(),
|
|
186 |
SIGNAL(globalInputLanguageChanged(HbInputLanguage)),
|
|
187 |
this,
|
|
188 |
SLOT(onPrimaryInputLanguageChanged(HbInputLanguage)));
|
|
189 |
|
|
190 |
connect(HbInputSettingProxy::instance(),
|
|
191 |
SIGNAL(globalSecondaryInputLanguageChanged(HbInputLanguage)),
|
|
192 |
this,
|
|
193 |
SLOT(onSecondaryInputLanguageChanged(HbInputLanguage)));
|
|
194 |
|
|
195 |
connect(form,
|
|
196 |
SIGNAL(activated(QModelIndex)),
|
|
197 |
this,
|
|
198 |
SLOT(onDataFormItemActivated(QModelIndex)));
|
|
199 |
|
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
/*
|
|
204 |
* Destructor
|
|
205 |
*/
|
|
206 |
CpLanguageView::~CpLanguageView()
|
|
207 |
{
|
|
208 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::~CpLanguageView")
|
|
209 |
// Unload RegionalSettingsView plugin
|
|
210 |
if (mClockPluginLoader) {
|
|
211 |
mClockPluginLoader->unload();
|
|
212 |
delete mClockPluginLoader;
|
|
213 |
}
|
|
214 |
delete mModel;
|
|
215 |
}
|
|
216 |
|
|
217 |
/*!
|
|
218 |
* Handle region changed
|
|
219 |
*/
|
|
220 |
void CpLanguageView::onRegionChanged(int index)
|
|
221 |
{
|
|
222 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onRegionChanged")
|
|
223 |
|
|
224 |
CPLANG_LOG(QLatin1String("Before change region:") + HbLocaleUtil::currentRegion());
|
|
225 |
|
|
226 |
if (index >= 0 && index < mSupportedRegions.count()) {
|
|
227 |
HbLocaleUtil::changeRegion( mSupportedRegions.at(index) );
|
|
228 |
mCurrentSetting.regionId = mSupportedRegions.at(index);
|
|
229 |
if (LanguageRegionMapping *setting = languageRegionMapping(mCurrentSetting.languageId)) {
|
|
230 |
setting->regionId = mCurrentSetting.regionId;
|
|
231 |
}
|
|
232 |
|
|
233 |
CPLANG_LOG(QLatin1String("After change region:") + HbLocaleUtil::currentRegion());
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
|
|
238 |
/*
|
|
239 |
* prompt user to restart device.
|
|
240 |
*/
|
|
241 |
bool CpLanguageView::promptRestart()
|
|
242 |
{
|
|
243 |
HbDeviceMessageBox messageBox(
|
|
244 |
hbTrId("txt_cp_text_edit_device_will_be_restarted_to_chang"),
|
|
245 |
HbMessageBox::MessageTypeQuestion, this);
|
|
246 |
|
|
247 |
QString okText = hbTrId("txt_cp_button_restart");
|
|
248 |
QString cancelText = hbTrId("txt_cp_button_discard_changes");
|
|
249 |
messageBox.setAction(new QAction(okText,&messageBox),
|
|
250 |
HbDeviceMessageBox::AcceptButtonRole);
|
|
251 |
messageBox.setAction(new QAction(cancelText,&messageBox),
|
|
252 |
HbDeviceMessageBox::RejectButtonRole);
|
|
253 |
messageBox.setIconVisible(false);
|
|
254 |
|
|
255 |
return (messageBox.exec()
|
|
256 |
== messageBox.action(HbDeviceMessageBox::AcceptButtonRole) );
|
|
257 |
}
|
|
258 |
|
|
259 |
/*!
|
|
260 |
* Handle primary language changed.
|
|
261 |
*/
|
|
262 |
void CpLanguageView::onPrimaryInputLanguageChanged(int index)
|
|
263 |
{
|
|
264 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onPrimaryInputLanguageChanged(int index)")
|
|
265 |
|
|
266 |
CPLANG_LOG(QLatin1String("Before change primary input language:") + HbInputSettingProxy::instance()->globalInputLanguage().asString());
|
|
267 |
|
|
268 |
if (index >= 0 && index < mPrimaryInputLanguages.count()) {
|
|
269 |
HbInputLanguage inputLanguage = mPrimaryInputLanguages.at(index);
|
|
270 |
if (inputLanguage != HbInputSettingProxy::instance()->globalInputLanguage()) {
|
|
271 |
HbInputSettingProxy::instance()->setGlobalInputLanguage(inputLanguage);
|
|
272 |
mCurrentSetting.primaryWritingLan = inputLanguage;
|
|
273 |
if (LanguageRegionMapping *setting = languageRegionMapping(mCurrentSetting.languageId)) {
|
|
274 |
setting->primaryWritingLan = mCurrentSetting.primaryWritingLan;
|
|
275 |
}
|
|
276 |
|
|
277 |
updateSecondaryInputLanguageItem();
|
|
278 |
CPLANG_LOG(QLatin1String("After change primary input language:") + HbInputSettingProxy::instance()->globalInputLanguage().asString());
|
|
279 |
}
|
|
280 |
}
|
|
281 |
}
|
|
282 |
|
|
283 |
/*!
|
|
284 |
* Handle secondary language changed.
|
|
285 |
*/
|
|
286 |
void CpLanguageView::onSecondaryInputLanguageChanged(int index)
|
|
287 |
{
|
|
288 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onSecondaryInputLanguageChanged(int index)")
|
|
289 |
|
|
290 |
CPLANG_LOG(QLatin1String("Before change secondary input language:") + HbInputSettingProxy::instance()->globalSecondaryInputLanguage().asString());
|
|
291 |
|
|
292 |
if (index >= 0 && index < mSecondaryInputLanguages.count()) {
|
|
293 |
HbInputLanguage inputLanguage = mSecondaryInputLanguages.at(index);
|
|
294 |
if (inputLanguage != HbInputSettingProxy::instance()->globalSecondaryInputLanguage() ) {
|
|
295 |
HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(inputLanguage);
|
|
296 |
mCurrentSetting.secondaryWritingLan = inputLanguage;
|
|
297 |
if (LanguageRegionMapping *setting = languageRegionMapping(mCurrentSetting.languageId)) {
|
|
298 |
setting->secondaryWritingLan = mCurrentSetting.secondaryWritingLan;
|
|
299 |
}
|
|
300 |
|
|
301 |
CPLANG_LOG(QLatin1String("After change secondary input language:") + HbInputSettingProxy::instance()->globalSecondaryInputLanguage().asString());
|
|
302 |
}
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
/*!
|
|
307 |
* Observe primary input language changed event and update the ui, if it is being changed from outside of this plugin
|
|
308 |
*/
|
|
309 |
void CpLanguageView::onPrimaryInputLanguageChanged(const HbInputLanguage &inputLanguage)
|
|
310 |
{
|
|
311 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onPrimaryInputLanguageChanged(const HbInputLanguage &inputLanguage)")
|
|
312 |
if (mCurrentPrimaryInputLanguageItem) {
|
|
313 |
int index = mPrimaryInputLanguages.indexOf(inputLanguage);
|
|
314 |
if (index != mCurrentPrimaryInputLanguageItem->contentWidgetData("currentIndex").toInt() ) {
|
|
315 |
CPLANG_LOG( QString("New Index: %1").arg(index) )
|
|
316 |
|
|
317 |
mCurrentSetting.primaryWritingLan = inputLanguage;
|
|
318 |
mCurrentPrimaryInputLanguageItem->setContentWidgetData("currentIndex",index);
|
|
319 |
updateSecondaryInputLanguageItem();
|
|
320 |
}
|
|
321 |
}
|
|
322 |
}
|
|
323 |
|
|
324 |
/*!
|
|
325 |
* Observe secondary input language changed event and update the ui, if it is being changed from outside of this plugin
|
|
326 |
*/
|
|
327 |
void CpLanguageView::onSecondaryInputLanguageChanged(const HbInputLanguage &inputLanguage)
|
|
328 |
{
|
|
329 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onSecondaryInputLanguageChanged(const HbInputLanguage &inputLanguage)")
|
|
330 |
|
|
331 |
if (mCurrentSecondaryInputLanguageItem) {
|
|
332 |
int index = mSecondaryInputLanguages.indexOf(inputLanguage);
|
|
333 |
if (index != mCurrentSecondaryInputLanguageItem->contentWidgetData("currentIndex").toInt()) {
|
|
334 |
CPLANG_LOG( QString("New Index: %1").arg(index) )
|
|
335 |
mCurrentSetting.secondaryWritingLan = inputLanguage;
|
|
336 |
mCurrentSecondaryInputLanguageItem->setContentWidgetData("currentIndex",index);
|
|
337 |
}
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
|
|
342 |
/*!
|
|
343 |
* Fill contents in the data form model items.
|
|
344 |
* \param comboBoxItem a data form model item whose type is HbDataFormModelItem::ComboBoxItem
|
|
345 |
* \param items items showing in the combobox
|
|
346 |
* \param currentIndex index of the selected item
|
|
347 |
*/
|
|
348 |
void CpLanguageView::fillDataFormComboBoxItem(HbDataFormModelItem *comboBoxItem,
|
|
349 |
const QStringList &items,
|
|
350 |
int currentIndex /*= -1*/)
|
|
351 |
{
|
|
352 |
Q_ASSERT(comboBoxItem);
|
|
353 |
Q_ASSERT(comboBoxItem->type() == HbDataFormModelItem::ComboBoxItem);
|
|
354 |
|
|
355 |
comboBoxItem->setContentWidgetData("items", items);
|
|
356 |
comboBoxItem->setContentWidgetData("currentIndex",currentIndex);
|
|
357 |
}
|
|
358 |
|
|
359 |
/*!
|
|
360 |
* Update secondary input language item according to primary input language
|
|
361 |
*/
|
|
362 |
void CpLanguageView::updateSecondaryInputLanguageItem()
|
|
363 |
{
|
|
364 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::updateSecondaryInputLanguageItem")
|
|
365 |
|
|
366 |
// no secondary writing language in Chinese variant.
|
|
367 |
if (mChineseVariant) {
|
|
368 |
return;
|
|
369 |
}
|
|
370 |
|
|
371 |
HbInputLanguage primaryInputLanguage = HbInputSettingProxy::instance()->globalInputLanguage();
|
|
372 |
|
|
373 |
mSecondaryInputLanguages.clear();
|
|
374 |
// append a "none set" item
|
|
375 |
mSecondaryInputLanguages.append(HbInputLanguage());
|
|
376 |
|
|
377 |
// Chinese input doesn't have secondary input language
|
|
378 |
if (primaryInputLanguage.language() == QLocale::Chinese) {
|
|
379 |
HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(HbInputLanguage());
|
|
380 |
CPLANG_LOG("Primary input language: Chinese");
|
|
381 |
}
|
|
382 |
else {
|
|
383 |
foreach(const HbInputLanguage &inputLanguage,mPrimaryInputLanguages) {
|
|
384 |
if ( inputLanguage != primaryInputLanguage // Secondary input language can't be set the same as primary input language
|
|
385 |
&& inputLanguage.language() != QLocale::Chinese) { // Chinese input can't be set as secondary input language
|
|
386 |
mSecondaryInputLanguages.append(inputLanguage);
|
|
387 |
}
|
|
388 |
}
|
|
389 |
}
|
|
390 |
|
|
391 |
QStringList localisedNames = CpLanguagePluginUtil::localizedInputLanguageNames(mSecondaryInputLanguages);
|
|
392 |
|
|
393 |
// if the secondary input language is the same as primary input language, set it as "none set"
|
|
394 |
HbInputLanguage secondaryInputLanguage = HbInputSettingProxy::instance()->globalSecondaryInputLanguage();
|
|
395 |
|
|
396 |
if (secondaryInputLanguage == primaryInputLanguage) {
|
|
397 |
secondaryInputLanguage = HbInputLanguage();
|
|
398 |
HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(HbInputLanguage());
|
|
399 |
|
|
400 |
CPLANG_LOG("secondary == primary, set secondary input as \"None\"");
|
|
401 |
}
|
|
402 |
|
|
403 |
mCurrentSetting.secondaryWritingLan = secondaryInputLanguage;
|
|
404 |
if (LanguageRegionMapping *setting = languageRegionMapping(mCurrentSetting.languageId)) {
|
|
405 |
setting->secondaryWritingLan = mCurrentSetting.secondaryWritingLan;
|
|
406 |
}
|
|
407 |
|
|
408 |
fillDataFormComboBoxItem(mCurrentSecondaryInputLanguageItem,localisedNames,mSecondaryInputLanguages.indexOf(secondaryInputLanguage));
|
|
409 |
}
|
|
410 |
|
|
411 |
/*!
|
|
412 |
* Restart the device.
|
|
413 |
*/
|
|
414 |
int CpLanguageView::restartDevice()
|
|
415 |
{
|
|
416 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::restartDevice")
|
|
417 |
#ifdef Q_OS_SYMBIAN
|
|
418 |
RStarterSession session;
|
|
419 |
TInt error = session.Connect();
|
|
420 |
|
|
421 |
if (error == KErrNone) {
|
|
422 |
session.Reset( RStarterSession::ELanguageSwitchReset );
|
|
423 |
session.Close();
|
|
424 |
}
|
|
425 |
|
|
426 |
return error;
|
|
427 |
#else
|
|
428 |
return 0;
|
|
429 |
#endif
|
|
430 |
}
|
|
431 |
|
|
432 |
/*!
|
|
433 |
Launch the regional settings view.
|
|
434 |
*/
|
|
435 |
void CpLanguageView::launchRegionalSettingsView()
|
|
436 |
{
|
|
437 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::launchRegionalSettingsView")
|
|
438 |
|
|
439 |
//Load the clock settings view plugin if it is not loaded
|
|
440 |
if (!mClockPluginLoader) {
|
|
441 |
QDir dir(CLOCK_SETTINGSVIEW_PLUGIN_PATH);
|
|
442 |
QString pluginName = dir.absoluteFilePath(CLOCK_SETTINGSVIEW_PLUGIN_NAME);
|
|
443 |
mClockPluginLoader = new QPluginLoader(pluginName);
|
|
444 |
mClockPluginLoader->load();
|
|
445 |
}
|
|
446 |
|
|
447 |
//Launch the settings view
|
|
448 |
ClockSettingsViewInterface *clockSettingsViewInterface
|
|
449 |
= qobject_cast<ClockSettingsViewInterface*>(mClockPluginLoader->instance());
|
|
450 |
if (clockSettingsViewInterface) {
|
|
451 |
clockSettingsViewInterface->launchRegionalSettingsView();
|
|
452 |
}
|
|
453 |
else {
|
|
454 |
CPLANG_LOG("Load clocksettingsviewplugin failed.");
|
|
455 |
}
|
|
456 |
}
|
|
457 |
|
|
458 |
/*!
|
|
459 |
* handle data form page changed event
|
|
460 |
*/
|
|
461 |
void CpLanguageView::onDataFormItemActivated(const QModelIndex &modelIndex)
|
|
462 |
{
|
|
463 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::onDataFormItemActivated")
|
|
464 |
|
|
465 |
mCurrentLanguagePage = mModel->itemFromIndex(modelIndex);
|
|
466 |
|
|
467 |
mCurrentRegionItem = mCurrentLanguagePage->childAt(REGION_ITEM_INDEX);
|
|
468 |
mCurrentPrimaryInputLanguageItem = mCurrentLanguagePage->childAt(PRIMARY_INPUT_ITEM_INDEX);
|
|
469 |
mCurrentSecondaryInputLanguageItem = mCurrentLanguagePage->childAt(SECONDARY_INPUT_ITEM_INDEX);
|
|
470 |
|
|
471 |
int index = mLanguagePages.indexOf(mCurrentLanguagePage);
|
|
472 |
|
|
473 |
if (index >= 0) {
|
|
474 |
QString newLanguage = mSupportedLanguages.at(index);
|
|
475 |
LanguageRegionMapping *setting = languageRegionMapping(newLanguage);
|
|
476 |
if (setting) {
|
|
477 |
setting->secondaryWritingLan = HbInputSettingProxy::instance()->globalSecondaryInputLanguage();
|
|
478 |
mCurrentSetting = *setting;
|
|
479 |
|
|
480 |
HbLocaleUtil::changeRegion(mCurrentSetting.regionId);
|
|
481 |
HbInputSettingProxy::instance()->setGlobalInputLanguage(mCurrentSetting.primaryWritingLan);
|
|
482 |
|
|
483 |
//update combobox
|
|
484 |
mCurrentPrimaryInputLanguageItem->setContentWidgetData("currentIndex",mPrimaryInputLanguages.indexOf(mCurrentSetting.primaryWritingLan));
|
|
485 |
mCurrentRegionItem->setContentWidgetData("currentIndex",mSupportedRegions.indexOf(mCurrentSetting.regionId));
|
|
486 |
|
|
487 |
CPLANG_LOG(QString("Primary writing:") + HbInputSettingProxy::instance()->globalInputLanguage().asString());
|
|
488 |
CPLANG_LOG(QString("Secondary writing:") + HbInputSettingProxy::instance()->globalSecondaryInputLanguage().asString());
|
|
489 |
|
|
490 |
updateSecondaryInputLanguageItem();
|
|
491 |
}
|
|
492 |
}
|
|
493 |
|
|
494 |
}
|
|
495 |
|
|
496 |
/*!
|
|
497 |
* From CpBaseSettingView, prompt user to restart device before exiting the view
|
|
498 |
*/
|
|
499 |
void CpLanguageView::close()
|
|
500 |
{
|
|
501 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::close()")
|
|
502 |
|
|
503 |
CPLANG_LOG( QString("mCurrentSetting.languageId :") + mCurrentSetting.languageId )
|
|
504 |
CPLANG_LOG( QString("HbLocaleUtil::currentLanguage():") + HbLocaleUtil::currentLanguage() )
|
|
505 |
|
|
506 |
if (mCurrentSetting.languageId != HbLocaleUtil::currentLanguage()) {
|
|
507 |
// apply new settings
|
|
508 |
if (promptRestart()) {
|
|
509 |
HbLocaleUtil::changeLocale(mCurrentSetting.languageId);
|
|
510 |
|
|
511 |
/*
|
|
512 |
* change other settings.
|
|
513 |
*/
|
|
514 |
if (mSupportedRegions.contains(mCurrentSetting.regionId,Qt::CaseInsensitive)) {
|
|
515 |
HbLocaleUtil::changeRegion(mCurrentSetting.regionId);
|
|
516 |
}
|
|
517 |
CpLanguagePlugin::updateEntryItem();
|
|
518 |
HbInputSettingProxy::instance()->setGlobalInputLanguage(mCurrentSetting.primaryWritingLan);
|
|
519 |
HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(mCurrentSetting.secondaryWritingLan);
|
|
520 |
|
|
521 |
restartDevice();
|
|
522 |
}
|
|
523 |
// restore previous values
|
|
524 |
else {
|
|
525 |
if (mCurrentSetting.regionId != mPreviousSetting.regionId) {
|
|
526 |
HbLocaleUtil::changeRegion(mPreviousSetting.regionId);
|
|
527 |
}
|
|
528 |
if (mCurrentSetting.primaryWritingLan != mPreviousSetting.primaryWritingLan) {
|
|
529 |
HbInputSettingProxy::instance()->setGlobalInputLanguage(mPreviousSetting.primaryWritingLan);
|
|
530 |
}
|
|
531 |
if (mCurrentSetting.secondaryWritingLan != mPreviousSetting.secondaryWritingLan) {
|
|
532 |
HbInputSettingProxy::instance()->setGlobalSecondaryInputLanguage(mPreviousSetting.secondaryWritingLan);
|
|
533 |
}
|
|
534 |
}
|
|
535 |
}
|
|
536 |
|
|
537 |
CpBaseSettingView::close();
|
|
538 |
}
|
|
539 |
|
|
540 |
/*!
|
|
541 |
* get the language-region mapping table
|
|
542 |
*/
|
|
543 |
LanguageRegionMapping *CpLanguageView::languageRegionMapping(const QString &language)
|
|
544 |
{
|
|
545 |
CPLANG_LOG_FUNC_ENTRY("CpLanguageView::languageRegionMapping(const QString &language)")
|
|
546 |
|
|
547 |
foreach(const LanguageRegionMapping &setting,mLanguageRegionMapping) {
|
|
548 |
if (setting.languageId.compare(language,Qt::CaseInsensitive) == 0) {
|
|
549 |
return const_cast<LanguageRegionMapping*>(&setting);
|
|
550 |
}
|
|
551 |
}
|
|
552 |
|
|
553 |
CPLANG_LOG("Not found.")
|
|
554 |
|
|
555 |
return 0;
|
|
556 |
}
|
|
557 |
|
|
558 |
//End of File
|