diff -r f5050f1da672 -r 04becd199f91 javamanager/javasettings/appsettingsview_qt/src/javaapplicationsettingsview_p.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javamanager/javasettings/appsettingsview_qt/src/javaapplicationsettingsview_p.cpp Tue Apr 27 16:30:29 2010 +0300 @@ -0,0 +1,640 @@ +/* +* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "javaapplicationsettings.h" +#include "javaapplicationsettingsview.h" +#include "javaapplicationsettingsview_p.h" + +#include "securitystoragedatadefs.h" +#include "javastoragenames.h" + +using namespace java::storage; +using namespace std; + +const wchar_t ON_SCREEN_KEYPAD_VALUE_NO[] = L"0"; +const wchar_t ON_SCREEN_KEYPAD_VALUE_GAMEACTIONS[] = L"1"; +const wchar_t ON_SCREEN_KEYPAD_VALUE_NAVIGATION[] = L"2"; + +JavaApplicationSettingsViewPrivate::JavaApplicationSettingsViewPrivate(const QString& aJavaAppUid): + mainForm(0), model(0), generalSettingsGroup(0), securitySettingsGroup(0), iJavaAppUid(aJavaAppUid.toStdWString()) +{ + // load the correct translation of the localized strings + QTranslator translator; + // Current solution reads it from Z only (this does not work with IAD) + // -> check if translator can handle path without drive letter (e.g. the resource + // is loaded from the same drive where the DLL is loaded) + if (translator.load("z:/resource/qt/translations/javaruntimeapplicationsettings_" + QLocale::system().name())) + { + qApp->installTranslator(&translator); + } + // init strings + BLANKET = hbTrId("txt_java_sett_setlabel_permission_val_blanket"); + SESSION = hbTrId("txt_java_sett_setlabel_permission_val_session"); + ONESHOT = hbTrId("txt_java_sett_setlabel_permission_val_oneshot"); + DENIED = hbTrId("txt_java_sett_setlabel_permission_val_no"); + SECURITY_LEVEL = hbTrId("txt_java_sett_setlabel_security_level"); + USER_DEFINED = hbTrId("txt_java_sett_setlabel_security_level_val_user_defined"); + SENSITIVE_SETTINGS = hbTrId("txt_java_sett_info_query_perm_sec"); + SENSITIVE_SETTINGS_NET_USAGE = hbTrId("txt_java_sett_info_query_perm_net"); + MUTUALLY_EXCLUSIVE_SETTINGS = hbTrId("txt_java_sett_info_query_perm_warn"); + OK = hbTrId("txt_java_sett_button_settings_ok"); + CANCEL = hbTrId("txt_java_sett_button_settings_cancel"); + SECURITY_WARNING_TITLE = hbTrId("txt_java_sett_title_note_security_warn"); + NET_ACCESS = hbTrId("txt_java_sett_setlabel_net_access"); + LOW_LEVEL_NET_ACCESS = hbTrId("txt_java_sett_setlabel_low_level_net_access"); + + // storage + iStorage.reset(JavaStorage::createInstance()); + try + { + iStorage->open(); + } + catch (JavaStorageException& aJse) {} + + // read all settings + readAllSettings(); + + // init form + mainForm = new HbDataForm(); + mainForm->setHeading(hbTrId("txt_java_sett_title_settings")); + model = new HbDataFormModel(); + + // init settings + generalSettingsGroup = model->appendDataFormGroup( + hbTrId("txt_java_sett_subtitle_general"), model->invisibleRootItem()); + initSettings(generalSettings, generalSettingsGroup); + securitySettingsGroup = model->appendDataFormGroup( + hbTrId("txt_java_sett_subtitle_security"), model->invisibleRootItem()); + initSettings(securitySettings, securitySettingsGroup); + + // if security warnings is user defined -> add the extra settings, expand + if (securitySettings[0].getCurrentValue() == 1) + { + securityWarningsChanged(USER_DEFINED); + } + + // link form and model + mainForm->setModel(model); + mainForm->setExpanded(model->indexFromItem(generalSettingsGroup), true); + mainForm->setExpanded(model->indexFromItem(securitySettingsGroup), (securitySettings[0].getCurrentValue() == 1)); +} + +void JavaApplicationSettingsViewPrivate::init(JavaApplicationSettingsView* aPublicView) +{ + iPublicView = aPublicView; + + // do the connect for the main form + iPublicView->connect(mainForm, SIGNAL(activated(const QModelIndex)), + iPublicView, SLOT(_q_dataItemDisplayed(const QModelIndex))); + + // set the form as view's widget + iPublicView->setWidget(mainForm); + + // set title + iPublicView->setTitle(QString::fromStdWString(readFromStorage(PACKAGE_NAME, L"", L"", APPLICATION_PACKAGE_TABLE))); +} + +JavaApplicationSettingsViewPrivate::~JavaApplicationSettingsViewPrivate() +{ + delete mainForm; + delete model; +} + +void JavaApplicationSettingsViewPrivate::readAllSettings() +{ + // general settings + QStringList settingsValues; + vector storageValues; + if (!findFromStorage(VALUE, NAME, L"Nokia-MIDlet-On-Screen-Keypad", APPLICATION_PACKAGE_ATTRIBUTES_TABLE)) + { + // if the on screen keypad is predefined, it should not be changable by user + // -> right now it is not added to settings list. It should be changed so that + // the setting should not be editable by user + settingsValues< highRiskList; + // net access with multimedia and read user data + highRiskList << &(extraSettings[6]) << &(extraSettings[8]); + extraSettings[0].setHighRiskList(highRiskList); + // low level net access with multimedia and read user data + extraSettings[1].setHighRiskList(highRiskList); + // messaging with multimedia and read user data + extraSettings[2].setHighRiskList(highRiskList); + // restricted messaging with multimedia and read user data + extraSettings[3].setHighRiskList(highRiskList); + // call control with multimedia and read user data + extraSettings[4].setHighRiskList(highRiskList); + // local connectivity with multimedia and read user data + extraSettings[5].setHighRiskList(highRiskList); + // multimedia with net access, low level net access, messaging, + // restricted messaging, call control and local connectivity + highRiskList.clear(); + highRiskList << &(extraSettings[0]) << &(extraSettings[1]) + << &(extraSettings[2]) << &(extraSettings[3]) + << &(extraSettings[4]) << &(extraSettings[5]); + extraSettings[6].setHighRiskList(highRiskList); + // read user data with net access, low level net access, messaging, + // restricted messaging, call control and local connectivity + extraSettings[8].setHighRiskList(highRiskList); + + // configure the mutually exclusive list + QList mutuallyExclusiveList; + //net access with application auto invocation + mutuallyExclusiveList << &(extraSettings[13]); + extraSettings[0].setMutuallyExclusiveList(mutuallyExclusiveList); + //low level net access with application auto invocation + extraSettings[1].setMutuallyExclusiveList(mutuallyExclusiveList); + //application auto invocation with net access and low level net access + mutuallyExclusiveList.clear(); + mutuallyExclusiveList << &(extraSettings[0]) << &(extraSettings[1]); + extraSettings[13].setMutuallyExclusiveList(mutuallyExclusiveList); +} + +void JavaApplicationSettingsViewPrivate::initSettings(QVector& settings, HbDataFormModelItem * parent) +{ + for (int i=0; iappendDataFormItem( + HbDataFormModelItem::ComboBoxItem, + settings[i].getName(), parent); + settings[i].setId(appSettings); + appSettings->setContentWidgetData(QString("items"), settings[i].getValues()); + appSettings->setContentWidgetData(QString("currentIndex"),readFromStorage(settings[i])); + } +} + +void JavaApplicationSettingsViewPrivate::writeSettings(JavaApplicationSettings& settings, const QString &aNewValue) +{ + QStringList values = settings.getValues(); + int currentValue = settings.getCurrentValue(); + int newValue = settings.getValue(aNewValue); + if (newValue != -1 && currentValue != newValue) + { + // handle blanket settings + if (aNewValue == BLANKET) + { + // check blanket settings + if (!blanketAllowed(settings)) + { + // change back to the old value + HbComboBox * settingsCombo = itemToComboBox(settings.getId()); + settingsCombo->setCurrentIndex(currentValue); + return; + } + } + settings.setCurrentValue(newValue); + writeToStorage(settings); + } +} + +bool JavaApplicationSettingsViewPrivate::blanketAllowed(const JavaApplicationSettings &settings) +{ + // handle the high risk items + QList highRiskList = settings.getHighRiskList(); + if (highRiskList.size() > 0) + { + // go through the list and see if any of the setings are in blanket + for (int i=0; igetValue(highRiskList[i]->getCurrentValue()) + == BLANKET) + { + QString secWarning = SENSITIVE_SETTINGS; + if (settings.getName() == NET_ACCESS + || highRiskList[i]->getName() == NET_ACCESS + || settings.getName() == LOW_LEVEL_NET_ACCESS + || highRiskList[i]->getName() == LOW_LEVEL_NET_ACCESS) + { + secWarning = SENSITIVE_SETTINGS_NET_USAGE; + } + /*if (!(HbMessageBox::launchQuestionMessageBox( + secWarning,OK,CANCEL ,new HbLabel(SECURITY_WARNING_TITLE)))) + { + return false; + }*/ + break; + } + } + } + // handle the mutually exclusive rules + QList mutuallyExclusiveList = settings + .getMutuallyExclusiveList(); + if (mutuallyExclusiveList.size() > 0) + { + // go through the list and see if any of the setings are in blanket + for (int i=0; igetValue( + mutuallyExclusiveList[i]->getCurrentValue()) == BLANKET) + { + bool isBlanketAllowed = true /*(HbMessageBox::launchQuestionMessageBox( + MUTUALLY_EXCLUSIVE_SETTINGS,OK,CANCEL, new HbLabel(SECURITY_WARNING_TITLE)))*/; + if (isBlanketAllowed) + { + // change the current value to the maximum allowed + bool isBlanket = true; + do + { + if (isBlanket) + { + QStringList allowedValues = mutuallyExclusiveList[i]->getValues(); + int selectedValue = mutuallyExclusiveList[i]->getCurrentValue(); + // select the maximum allowed value + for (int j=0; jsetCurrentValue(selectedValue); + HbComboBox * settingsCombo = itemToComboBox( + mutuallyExclusiveList[i]->getId()); + settingsCombo->setCurrentIndex(selectedValue); + writeToStorage(*mutuallyExclusiveList[i]); + } + i++; + // end of list? + if (i >= mutuallyExclusiveList.size()) + { + break; + } + // move on into the list + isBlanket = (mutuallyExclusiveList[i]->getValue( + mutuallyExclusiveList[i]->getCurrentValue()) == BLANKET); + } + while (true); + } + return isBlanketAllowed; + } + } + } + return true; +} + +void JavaApplicationSettingsViewPrivate::_q_settingsChanged(const QString &newValue) +{ + HbComboBox * sender = static_cast(iPublicView->sender()); + if (sender) + { + JavaApplicationSettings* settings = findSettings(sender); + if (settings != NULL) + { + // security warnings + if (settings->getName() == SECURITY_LEVEL) + { + securityWarningsChanged(newValue); +// return; + } + // any other settings are treated same + writeSettings(*settings, newValue); + } + } +} + +void JavaApplicationSettingsViewPrivate::securityWarningsChanged(const QString &newValue) +{ + if (newValue == USER_DEFINED) + { + // append the extra settings and values + for (int i=0; i= 0) + { + HbDataFormModelItem * appSettings = model->appendDataFormItem( + HbDataFormModelItem::ComboBoxItem, + extraSettings[i].getName(), securitySettingsGroup); + extraSettings[i].setId(appSettings); + appSettings->setContentWidgetData(QString("currentIndex"),extraSettings[i].getCurrentValue()); + } + } + } + else + { + // remove the extra settings + for (int i=0; iremoveItem(model->indexFromItem(extraSettings[i].getId())); + extraSettings[i].setId(0); + } + } + } + } +} + +void JavaApplicationSettingsViewPrivate::_q_dataItemDisplayed(const QModelIndex dataItemIndex) +{ + HbDataFormModelItem *item = static_cast( + mainForm->model())->itemFromIndex(dataItemIndex); + int itemType = item->data(HbDataFormModelItem::ItemTypeRole).toInt(); + if (HbDataFormModelItem::DataItemType(itemType) + == HbDataFormModelItem::ComboBoxItem) + { + HbComboBox * comboBox = static_cast( + mainForm->dataFormViewItem(dataItemIndex)->dataItemContentWidget()); + // add the extra settings values + for (int i=0; icount() == 0) + { + comboBox->addItems(extraSettings[i].getValues()); + } + comboBox->setCurrentIndex(extraSettings[i].getCurrentValue()); + break; + } + } + iPublicView->connect(comboBox, + SIGNAL(currentIndexChanged(const QString &)), + iPublicView, SLOT(_q_settingsChanged(const QString &))); + } +} + +JavaApplicationSettings* JavaApplicationSettingsViewPrivate::findSettings(HbComboBox* id) +{ + JavaApplicationSettings* settings = findSettings(id, generalSettings); + if (settings == NULL) + { + settings = findSettings(id, securitySettings); + if (settings == NULL) + { + settings = findSettings(id, extraSettings); + } + } + return settings; +} + +JavaApplicationSettings* JavaApplicationSettingsViewPrivate::findSettings(HbComboBox* id, QVector& allSettings) +{ + for (int i=0; idataFormViewItem( + model->indexFromItem(item)); + if (viewItem) + { + return static_cast(viewItem->dataItemContentWidget()); + } + return NULL; +} + +int JavaApplicationSettingsViewPrivate::readFromStorage(JavaApplicationSettings& settings) +{ + int currentValue = -1; + if (settings.getColumnName().size() > 0 && settings.getTableName().size() > 0) + { + wstring value = L""; + + JavaStorageApplicationEntry_t query; + JavaStorageApplicationList_t queryResult; + JavaStorageEntry attr; + attr.setEntry(ID, iJavaAppUid); + query.insert(attr); + if (settings.getFilterColumnName().size() > 0) + { + attr.setEntry(settings.getFilterColumnName(), settings.getFilterColumnValue()); + query.insert(attr); + } + attr.setEntry(settings.getColumnName(), L""); + query.insert(attr); + + try + { + iStorage->search(settings.getTableName(), query, queryResult); + } + catch (JavaStorageException& aJse) + { + // Don't leave. Set defaults. + } + + findEntry(queryResult, settings.getColumnName(), value); + + if (value.size() > 0) + { + vector storageValues = settings.getStorageValues(); + for (int i=0; i 0) + { + attr.setEntry(settings.getFilterColumnName(), settings.getFilterColumnValue()); + oldEntry.insert(attr); + } + attr.setEntry(settings.getColumnName(), settings.getStorageValues()[settings.getCurrentValue()]); + entry.insert(attr); + + try + { + iStorage->update(settings.getTableName(), entry, oldEntry); + } + catch (JavaStorageException& aJse) + { + } +} + +void JavaApplicationSettingsViewPrivate::findEntry(const JavaStorageApplicationList_t& queryResult, + const std::wstring& eName, + std::wstring& eValue) +{ + if (queryResult.size() > 0) + { + JavaStorageApplicationEntry_t entry = queryResult.front(); + JavaStorageEntry findPattern; + findPattern.setEntry(eName, L""); + JavaStorageApplicationEntry_t::const_iterator findIterator = + entry.find(findPattern); + if (findIterator != entry.end()) + { + eValue = findIterator->entryValue(); + } + } +} + +bool JavaApplicationSettingsViewPrivate::findFromStorage(const std::wstring& aColumnName, const std::wstring& aColumnFilterName, const std::wstring& aColumnFilterValue, const std::string& aTableName) +{ + wstring value = readFromStorage(aColumnName, aColumnFilterName, aColumnFilterValue, aTableName); + + return (value.size() > 0); +} + +wstring JavaApplicationSettingsViewPrivate::readFromStorage(const std::wstring& aColumnName, const std::wstring& aColumnFilterName, const std::wstring& aColumnFilterValue, const std::string& aTableName) +{ + wstring value = L""; + + JavaStorageApplicationEntry_t query; + JavaStorageApplicationList_t queryResult; + JavaStorageEntry attr; + attr.setEntry(ID, iJavaAppUid); + query.insert(attr); + if (aColumnFilterName.size() > 0) + { + attr.setEntry(aColumnFilterName, aColumnFilterValue); + query.insert(attr); + } + attr.setEntry(aColumnName, L""); + query.insert(attr); + + try + { + iStorage->search(aTableName, query, queryResult); + } + catch (JavaStorageException& aJse) + { + // Don't leave. Set defaults. + } + + findEntry(queryResult, aColumnName, value); + + return value; +} + + +#ifdef WIN32 +#include "./moc/moc_javaapplicationsettingsview.cpp" +#else +#include "moc_javaapplicationsettingsview.cpp" +#endif