javamanager/javasettings/appsettingsview_qt/src/javaapplicationsettingsview_p.cpp
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15 *
       
    16 */
       
    17 #include <hbmessagebox.h>
       
    18 #include <hbdataformviewitem.h>
       
    19 #include <hbcombobox.h>
       
    20 #include <hbdataform.h>
       
    21 #include <hbdataformmodel.h>
       
    22 #include <hbdataformmodelitem.h>
       
    23 #include <hblabel.h>
       
    24 #include <QApplication>
       
    25 #include <QTranslator>
       
    26 
       
    27 #include "javaapplicationsettings.h"
       
    28 #include "javaapplicationsettingsview.h"
       
    29 #include "javaapplicationsettingsview_p.h"
       
    30 
       
    31 #include "securitystoragedatadefs.h"
       
    32 #include "javastoragenames.h"
       
    33 
       
    34 using namespace java::storage;
       
    35 using namespace std;
       
    36 
       
    37 const wchar_t ON_SCREEN_KEYPAD_VALUE_NO[] = L"0";
       
    38 const wchar_t ON_SCREEN_KEYPAD_VALUE_GAMEACTIONS[] = L"1";
       
    39 const wchar_t ON_SCREEN_KEYPAD_VALUE_NAVIGATION[] = L"2";
       
    40 
       
    41 JavaApplicationSettingsViewPrivate::JavaApplicationSettingsViewPrivate(const QString& aJavaAppUid):
       
    42         mainForm(0), model(0), generalSettingsGroup(0), securitySettingsGroup(0), iJavaAppUid(aJavaAppUid.toStdWString())
       
    43 {
       
    44     // load the correct translation of the localized strings
       
    45     QTranslator translator;
       
    46     // Current solution reads it from Z only (this does not work with IAD)
       
    47     // -> check if translator can handle path without drive letter (e.g. the resource
       
    48     // is loaded from the same drive where the DLL is loaded)
       
    49     if (translator.load("z:/resource/qt/translations/javaruntimeapplicationsettings_" + QLocale::system().name()))
       
    50     {
       
    51         qApp->installTranslator(&translator);
       
    52     }
       
    53     // init strings
       
    54     BLANKET = hbTrId("txt_java_sett_setlabel_permission_val_blanket");
       
    55     SESSION = hbTrId("txt_java_sett_setlabel_permission_val_session");
       
    56     ONESHOT = hbTrId("txt_java_sett_setlabel_permission_val_oneshot");
       
    57     DENIED = hbTrId("txt_java_sett_setlabel_permission_val_no");
       
    58     SECURITY_LEVEL = hbTrId("txt_java_sett_setlabel_security_level");
       
    59     USER_DEFINED = hbTrId("txt_java_sett_setlabel_security_level_val_user_defined");
       
    60     SENSITIVE_SETTINGS = hbTrId("txt_java_sett_info_query_perm_sec");
       
    61     SENSITIVE_SETTINGS_NET_USAGE = hbTrId("txt_java_sett_info_query_perm_net");
       
    62     MUTUALLY_EXCLUSIVE_SETTINGS = hbTrId("txt_java_sett_info_query_perm_warn");
       
    63     OK = hbTrId("txt_java_sett_button_settings_ok");
       
    64     CANCEL = hbTrId("txt_java_sett_button_settings_cancel");
       
    65     SECURITY_WARNING_TITLE = hbTrId("txt_java_sett_title_note_security_warn");
       
    66     NET_ACCESS = hbTrId("txt_java_sett_setlabel_net_access");
       
    67     LOW_LEVEL_NET_ACCESS = hbTrId("txt_java_sett_setlabel_low_level_net_access");
       
    68 
       
    69     // storage
       
    70     iStorage.reset(JavaStorage::createInstance());
       
    71     try
       
    72     {
       
    73         iStorage->open();
       
    74     }
       
    75     catch (JavaStorageException& aJse) {}
       
    76 
       
    77     // read all settings
       
    78     readAllSettings();
       
    79 
       
    80     // init form
       
    81     mainForm = new HbDataForm();
       
    82     mainForm->setHeading(hbTrId("txt_java_sett_title_settings"));
       
    83     model = new HbDataFormModel();
       
    84 
       
    85     // init settings
       
    86     generalSettingsGroup = model->appendDataFormGroup(
       
    87                                hbTrId("txt_java_sett_subtitle_general"), model->invisibleRootItem());
       
    88     initSettings(generalSettings, generalSettingsGroup);
       
    89     securitySettingsGroup = model->appendDataFormGroup(
       
    90                                 hbTrId("txt_java_sett_subtitle_security"), model->invisibleRootItem());
       
    91     initSettings(securitySettings, securitySettingsGroup);
       
    92 
       
    93     // if security warnings is user defined -> add the extra settings, expand
       
    94     if (securitySettings[0].getCurrentValue() == 1)
       
    95     {
       
    96         securityWarningsChanged(USER_DEFINED);
       
    97     }
       
    98 
       
    99     // link form and model
       
   100     mainForm->setModel(model);
       
   101     mainForm->setExpanded(model->indexFromItem(generalSettingsGroup), true);
       
   102     mainForm->setExpanded(model->indexFromItem(securitySettingsGroup), (securitySettings[0].getCurrentValue() == 1));
       
   103 }
       
   104 
       
   105 void JavaApplicationSettingsViewPrivate::init(JavaApplicationSettingsView* aPublicView)
       
   106 {
       
   107     iPublicView = aPublicView;
       
   108 
       
   109     // do the connect for the main form
       
   110     iPublicView->connect(mainForm, SIGNAL(activated(const QModelIndex)),
       
   111                          iPublicView, SLOT(_q_dataItemDisplayed(const QModelIndex)));
       
   112 
       
   113     // set the form as view's widget
       
   114     iPublicView->setWidget(mainForm);
       
   115 
       
   116     // set title
       
   117     iPublicView->setTitle(QString::fromStdWString(readFromStorage(PACKAGE_NAME, L"", L"", APPLICATION_PACKAGE_TABLE)));
       
   118 }
       
   119 
       
   120 JavaApplicationSettingsViewPrivate::~JavaApplicationSettingsViewPrivate()
       
   121 {
       
   122     delete mainForm;
       
   123     delete model;
       
   124 }
       
   125 
       
   126 void JavaApplicationSettingsViewPrivate::readAllSettings()
       
   127 {
       
   128     // general settings
       
   129     QStringList settingsValues;
       
   130     vector<wstring> storageValues;
       
   131     if (!findFromStorage(VALUE, NAME, L"Nokia-MIDlet-On-Screen-Keypad", APPLICATION_PACKAGE_ATTRIBUTES_TABLE))
       
   132     {
       
   133         // if the on screen keypad is predefined, it should not be changable by user
       
   134         // -> right now it is not added to settings list. It should be changed so that
       
   135         // the setting should not be editable by user
       
   136         settingsValues<<hbTrId("txt_java_sett_setlabel_osk_val_no")<<hbTrId("txt_java_sett_setlabel_osk_val_game")<<hbTrId("txt_java_sett_setlabel_osk_val_navigation");
       
   137         storageValues.push_back(ON_SCREEN_KEYPAD_VALUE_NO);
       
   138         storageValues.push_back(ON_SCREEN_KEYPAD_VALUE_GAMEACTIONS);
       
   139         storageValues.push_back(ON_SCREEN_KEYPAD_VALUE_NAVIGATION);
       
   140         generalSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_osk"), settingsValues, ON_SCREEN_KEYPAD, MIDP_PACKAGE_TABLE, storageValues));
       
   141     }
       
   142     settingsValues = QStringList();
       
   143     settingsValues<<hbTrId("txt_java_sett_setlabel_network_conn_val_default")<<hbTrId("txt_java_sett_setlabel_network_conn_val_ask_user");
       
   144     generalSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_network_conn"), settingsValues));
       
   145 
       
   146     // security settings
       
   147     settingsValues = QStringList();
       
   148     storageValues.clear();
       
   149     settingsValues<<hbTrId("txt_java_sett_setlabel_security_level_val_default")<<hbTrId("txt_java_sett_setlabel_security_level_val_user_defined");
       
   150     storageValues.push_back(SECURITY_WARNINGS_DEFAULT_MODE);
       
   151     storageValues.push_back(SECURITY_WARNINGS_USER_DEFINED_MODE);
       
   152     securitySettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_security_level"), settingsValues, SECURITY_WARNINGS, MIDP_PACKAGE_TABLE, storageValues));
       
   153 
       
   154     // extra settings
       
   155     int i=0;
       
   156     settingsValues = QStringList();
       
   157     storageValues.clear();
       
   158     settingsValues<<hbTrId("txt_java_sett_setlabel_permission_val_oneshot")<<hbTrId("txt_java_sett_setlabel_permission_val_session")<<hbTrId("txt_java_sett_setlabel_permission_val_blanket")<<hbTrId("txt_java_sett_setlabel_permission_val_no");
       
   159     storageValues.push_back(ONESHOT_INTERACTION_MODE);
       
   160     storageValues.push_back(SESSION_INTERACTION_MODE);
       
   161     storageValues.push_back(BLANKET_INTERACTION_MODE);
       
   162     storageValues.push_back(DENIED_INTERACTION_MODE);
       
   163     extraSettings.append(JavaApplicationSettings(NET_ACCESS, settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, NET_ACCESS_SETTINGS));
       
   164     readFromStorage(extraSettings[i]);
       
   165     i++;
       
   166     extraSettings.append(JavaApplicationSettings(LOW_LEVEL_NET_ACCESS, settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, LOW_LEVEL_NET_ACCESS_SETTINGS));
       
   167     readFromStorage(extraSettings[i]);
       
   168     i++;
       
   169     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_messaging"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, MESSAGING_SETTINGS));
       
   170     readFromStorage(extraSettings[i]);
       
   171     i++;
       
   172     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_restricted_messaging"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, RESTRICTED_MESSAGING_SETTINGS));
       
   173     readFromStorage(extraSettings[i]);
       
   174     i++;
       
   175     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_call_control"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, CALL_CONTROL_SETTINGS));
       
   176     readFromStorage(extraSettings[i]);
       
   177     i++;
       
   178     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_local_conn"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, LOCAL_CONNECTIVITY_SETTINGS));
       
   179     readFromStorage(extraSettings[i]);
       
   180     i++;
       
   181     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_mm_record"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, MULTIMEDIA_RECORDING_SETTINGS));
       
   182     readFromStorage(extraSettings[i]);
       
   183     i++;
       
   184     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_write_data"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, WRITE_USER_DATA_ACCESS_SETTINGS));
       
   185     readFromStorage(extraSettings[i]);
       
   186     i++;
       
   187     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_read_data"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, READ_USER_DATA_ACCESS_SETTINGS));
       
   188     readFromStorage(extraSettings[i]);
       
   189     i++;
       
   190     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_location"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, LOCATION_SETTINGS));
       
   191     readFromStorage(extraSettings[i]);
       
   192     i++;
       
   193     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_landmarks"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, LANDMARK_SETTINGS));
       
   194     readFromStorage(extraSettings[i]);
       
   195     i++;
       
   196     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_auth"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, AUTHENTICATION_SETTINGS));
       
   197     readFromStorage(extraSettings[i]);
       
   198     i++;
       
   199     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_smartcard"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, SMART_CARD_COMMUNICATION_SETTINGS));
       
   200     readFromStorage(extraSettings[i]);
       
   201     i++;
       
   202     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_app_auto_invoc"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, APPLICATION_AUTO_INVOCATION_SETTINGS));
       
   203     readFromStorage(extraSettings[i]);
       
   204     i++;
       
   205     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_broadcast"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, BROADCAST_SETTINGS));
       
   206     readFromStorage(extraSettings[i]);
       
   207     i++;
       
   208     extraSettings.append(JavaApplicationSettings(hbTrId("txt_java_sett_setlabel_nfc_write_access"), settingsValues, CURRENT_SETTING, MIDP_FUNC_GRP_SETTINGS_TABLE, storageValues, FUNCTION_GROUP, NFC_WRITE_ACCESS_SETTINGS));
       
   209     readFromStorage(extraSettings[i]);
       
   210     i++;
       
   211 
       
   212     // configure the high risk lists
       
   213     QList<JavaApplicationSettings*> highRiskList;
       
   214     // net access with multimedia and read user data
       
   215     highRiskList << &(extraSettings[6]) << &(extraSettings[8]);
       
   216     extraSettings[0].setHighRiskList(highRiskList);
       
   217     // low level net access with multimedia and read user data
       
   218     extraSettings[1].setHighRiskList(highRiskList);
       
   219     // messaging with multimedia and read user data
       
   220     extraSettings[2].setHighRiskList(highRiskList);
       
   221     // restricted messaging with multimedia and read user data
       
   222     extraSettings[3].setHighRiskList(highRiskList);
       
   223     // call control with multimedia and read user data
       
   224     extraSettings[4].setHighRiskList(highRiskList);
       
   225     // local connectivity with multimedia and read user data
       
   226     extraSettings[5].setHighRiskList(highRiskList);
       
   227     // multimedia with net access, low level net access, messaging,
       
   228     // restricted messaging, call control and local connectivity
       
   229     highRiskList.clear();
       
   230     highRiskList << &(extraSettings[0]) << &(extraSettings[1])
       
   231     << &(extraSettings[2]) << &(extraSettings[3])
       
   232     << &(extraSettings[4]) << &(extraSettings[5]);
       
   233     extraSettings[6].setHighRiskList(highRiskList);
       
   234     // read user data with net access, low level net access, messaging,
       
   235     // restricted messaging, call control and local connectivity
       
   236     extraSettings[8].setHighRiskList(highRiskList);
       
   237 
       
   238     // configure the mutually exclusive list
       
   239     QList<JavaApplicationSettings*> mutuallyExclusiveList;
       
   240     //net access with application auto invocation
       
   241     mutuallyExclusiveList << &(extraSettings[13]);
       
   242     extraSettings[0].setMutuallyExclusiveList(mutuallyExclusiveList);
       
   243     //low level net access with application auto invocation
       
   244     extraSettings[1].setMutuallyExclusiveList(mutuallyExclusiveList);
       
   245     //application auto invocation with net access and low level net access
       
   246     mutuallyExclusiveList.clear();
       
   247     mutuallyExclusiveList << &(extraSettings[0]) << &(extraSettings[1]);
       
   248     extraSettings[13].setMutuallyExclusiveList(mutuallyExclusiveList);
       
   249 }
       
   250 
       
   251 void JavaApplicationSettingsViewPrivate::initSettings(QVector<JavaApplicationSettings>& settings, HbDataFormModelItem * parent)
       
   252 {
       
   253     for (int i=0; i<settings.size(); i++)
       
   254     {
       
   255         HbDataFormModelItem * appSettings = model->appendDataFormItem(
       
   256                                                 HbDataFormModelItem::ComboBoxItem,
       
   257                                                 settings[i].getName(), parent);
       
   258         settings[i].setId(appSettings);
       
   259         appSettings->setContentWidgetData(QString("items"), settings[i].getValues());
       
   260         appSettings->setContentWidgetData(QString("currentIndex"),readFromStorage(settings[i]));
       
   261     }
       
   262 }
       
   263 
       
   264 void JavaApplicationSettingsViewPrivate::writeSettings(JavaApplicationSettings& settings, const QString &aNewValue)
       
   265 {
       
   266     QStringList values = settings.getValues();
       
   267     int currentValue = settings.getCurrentValue();
       
   268     int newValue = settings.getValue(aNewValue);
       
   269     if (newValue != -1 && currentValue != newValue)
       
   270     {
       
   271         // handle blanket settings
       
   272         if (aNewValue == BLANKET)
       
   273         {
       
   274             // check blanket settings
       
   275             if (!blanketAllowed(settings))
       
   276             {
       
   277                 // change back to the old value
       
   278                 HbComboBox * settingsCombo = itemToComboBox(settings.getId());
       
   279                 settingsCombo->setCurrentIndex(currentValue);
       
   280                 return;
       
   281             }
       
   282         }
       
   283         settings.setCurrentValue(newValue);
       
   284         writeToStorage(settings);
       
   285     }
       
   286 }
       
   287 
       
   288 bool JavaApplicationSettingsViewPrivate::blanketAllowed(const JavaApplicationSettings &settings)
       
   289 {
       
   290     // handle the high risk items
       
   291     QList<JavaApplicationSettings*> highRiskList = settings.getHighRiskList();
       
   292     if (highRiskList.size() > 0)
       
   293     {
       
   294         // go through the list and see if any of the setings are in blanket
       
   295         for (int i=0; i<highRiskList.size(); i++)
       
   296         {
       
   297             if (highRiskList[i]->getValue(highRiskList[i]->getCurrentValue())
       
   298                     == BLANKET)
       
   299             {
       
   300                 QString secWarning = SENSITIVE_SETTINGS;
       
   301                 if (settings.getName() == NET_ACCESS
       
   302                         || highRiskList[i]->getName() == NET_ACCESS
       
   303                         || settings.getName() == LOW_LEVEL_NET_ACCESS
       
   304                         || highRiskList[i]->getName() == LOW_LEVEL_NET_ACCESS)
       
   305                 {
       
   306                     secWarning = SENSITIVE_SETTINGS_NET_USAGE;
       
   307                 }
       
   308                 /*if (!(HbMessageBox::launchQuestionMessageBox(
       
   309                         secWarning,OK,CANCEL ,new HbLabel(SECURITY_WARNING_TITLE))))
       
   310                 {
       
   311                     return false;
       
   312                 }*/
       
   313                 break;
       
   314             }
       
   315         }
       
   316     }
       
   317     // handle the mutually exclusive rules
       
   318     QList<JavaApplicationSettings*> mutuallyExclusiveList = settings
       
   319             .getMutuallyExclusiveList();
       
   320     if (mutuallyExclusiveList.size() > 0)
       
   321     {
       
   322         // go through the list and see if any of the setings are in blanket
       
   323         for (int i=0; i<mutuallyExclusiveList.size(); i++)
       
   324         {
       
   325             if (mutuallyExclusiveList[i]->getValue(
       
   326                         mutuallyExclusiveList[i]->getCurrentValue()) == BLANKET)
       
   327             {
       
   328                 bool isBlanketAllowed = true /*(HbMessageBox::launchQuestionMessageBox(
       
   329                         MUTUALLY_EXCLUSIVE_SETTINGS,OK,CANCEL, new HbLabel(SECURITY_WARNING_TITLE)))*/;
       
   330                 if (isBlanketAllowed)
       
   331                 {
       
   332                     // change  the current value to the maximum allowed
       
   333                     bool isBlanket = true;
       
   334                     do
       
   335                     {
       
   336                         if (isBlanket)
       
   337                         {
       
   338                             QStringList allowedValues = mutuallyExclusiveList[i]->getValues();
       
   339                             int selectedValue = mutuallyExclusiveList[i]->getCurrentValue();
       
   340                             // select the maximum allowed value
       
   341                             for (int j=0; j<allowedValues.size(); j++)
       
   342                             {
       
   343                                 if (allowedValues[j] == SESSION)
       
   344                                 {
       
   345                                     selectedValue = j;
       
   346                                     break;
       
   347                                 }
       
   348                                 if (allowedValues[j] == ONESHOT)
       
   349                                 {
       
   350                                     selectedValue = j;
       
   351                                 }
       
   352                                 else if (allowedValues[j] == DENIED
       
   353                                          && allowedValues[selectedValue] == BLANKET)
       
   354                                 {
       
   355                                     selectedValue = j;
       
   356                                 }
       
   357                             }
       
   358                             // set the maximum allowed value
       
   359                             mutuallyExclusiveList[i]->setCurrentValue(selectedValue);
       
   360                             HbComboBox * settingsCombo = itemToComboBox(
       
   361                                                              mutuallyExclusiveList[i]->getId());
       
   362                             settingsCombo->setCurrentIndex(selectedValue);
       
   363                             writeToStorage(*mutuallyExclusiveList[i]);
       
   364                         }
       
   365                         i++;
       
   366                         // end of list?
       
   367                         if (i >= mutuallyExclusiveList.size())
       
   368                         {
       
   369                             break;
       
   370                         }
       
   371                         // move on into the list
       
   372                         isBlanket = (mutuallyExclusiveList[i]->getValue(
       
   373                                          mutuallyExclusiveList[i]->getCurrentValue()) == BLANKET);
       
   374                     }
       
   375                     while (true);
       
   376                 }
       
   377                 return isBlanketAllowed;
       
   378             }
       
   379         }
       
   380     }
       
   381     return true;
       
   382 }
       
   383 
       
   384 void JavaApplicationSettingsViewPrivate::_q_settingsChanged(const QString &newValue)
       
   385 {
       
   386     HbComboBox * sender = static_cast<HbComboBox*>(iPublicView->sender());
       
   387     if (sender)
       
   388     {
       
   389         JavaApplicationSettings* settings = findSettings(sender);
       
   390         if (settings != NULL)
       
   391         {
       
   392             // security warnings
       
   393             if (settings->getName() == SECURITY_LEVEL)
       
   394             {
       
   395                 securityWarningsChanged(newValue);
       
   396 //                return;
       
   397             }
       
   398             // any other settings are treated same
       
   399             writeSettings(*settings, newValue);
       
   400         }
       
   401     }
       
   402 }
       
   403 
       
   404 void JavaApplicationSettingsViewPrivate::securityWarningsChanged(const QString &newValue)
       
   405 {
       
   406     if (newValue == USER_DEFINED)
       
   407     {
       
   408         // append the extra settings and values
       
   409         for (int i=0; i<extraSettings.size(); i++)
       
   410         {
       
   411             if (extraSettings[i].getCurrentValue() >= 0)
       
   412             {
       
   413                 HbDataFormModelItem * appSettings = model->appendDataFormItem(
       
   414                                                         HbDataFormModelItem::ComboBoxItem,
       
   415                                                         extraSettings[i].getName(), securitySettingsGroup);
       
   416                 extraSettings[i].setId(appSettings);
       
   417                 appSettings->setContentWidgetData(QString("currentIndex"),extraSettings[i].getCurrentValue());
       
   418             }
       
   419         }
       
   420     }
       
   421     else
       
   422     {
       
   423         // remove the extra settings
       
   424         for (int i=0; i<extraSettings.size(); i++)
       
   425         {
       
   426             if (extraSettings[i].getId())
       
   427             {
       
   428                 HbComboBox * extraSettingsId = itemToComboBox(extraSettings[i].getId());
       
   429                 if (extraSettingsId)
       
   430                 {
       
   431                     JavaApplicationSettingsView::disconnect(extraSettingsId, 0, 0, 0);
       
   432                     model->removeItem(model->indexFromItem(extraSettings[i].getId()));
       
   433                     extraSettings[i].setId(0);
       
   434                 }
       
   435             }
       
   436         }
       
   437     }
       
   438 }
       
   439 
       
   440 void JavaApplicationSettingsViewPrivate::_q_dataItemDisplayed(const QModelIndex dataItemIndex)
       
   441 {
       
   442     HbDataFormModelItem *item = static_cast<HbDataFormModel*>(
       
   443                                     mainForm->model())->itemFromIndex(dataItemIndex);
       
   444     int itemType = item->data(HbDataFormModelItem::ItemTypeRole).toInt();
       
   445     if (HbDataFormModelItem::DataItemType(itemType)
       
   446             == HbDataFormModelItem::ComboBoxItem)
       
   447     {
       
   448         HbComboBox * comboBox = static_cast<HbComboBox*>(
       
   449                                     mainForm->dataFormViewItem(dataItemIndex)->dataItemContentWidget());
       
   450         // add the extra settings values
       
   451         for (int i=0; i<extraSettings.size(); i++)
       
   452         {
       
   453             if (extraSettings[i].getId() == item)
       
   454             {
       
   455                 if (comboBox->count() == 0)
       
   456                 {
       
   457                     comboBox->addItems(extraSettings[i].getValues());
       
   458                 }
       
   459                 comboBox->setCurrentIndex(extraSettings[i].getCurrentValue());
       
   460                 break;
       
   461             }
       
   462         }
       
   463         iPublicView->connect(comboBox,
       
   464                              SIGNAL(currentIndexChanged(const QString &)),
       
   465                              iPublicView, SLOT(_q_settingsChanged(const QString &)));
       
   466     }
       
   467 }
       
   468 
       
   469 JavaApplicationSettings* JavaApplicationSettingsViewPrivate::findSettings(HbComboBox* id)
       
   470 {
       
   471     JavaApplicationSettings* settings = findSettings(id, generalSettings);
       
   472     if (settings == NULL)
       
   473     {
       
   474         settings = findSettings(id, securitySettings);
       
   475         if (settings == NULL)
       
   476         {
       
   477             settings = findSettings(id, extraSettings);
       
   478         }
       
   479     }
       
   480     return settings;
       
   481 }
       
   482 
       
   483 JavaApplicationSettings* JavaApplicationSettingsViewPrivate::findSettings(HbComboBox* id, QVector<JavaApplicationSettings>& allSettings)
       
   484 {
       
   485     for (int i=0; i<allSettings.size(); i++)
       
   486     {
       
   487         if (itemToComboBox(allSettings[i].getId()) == id)
       
   488         {
       
   489             return &allSettings[i];
       
   490         }
       
   491     }
       
   492     return NULL;
       
   493 }
       
   494 
       
   495 HbComboBox * JavaApplicationSettingsViewPrivate::itemToComboBox(const HbDataFormModelItem * item)
       
   496 {
       
   497     HbDataFormViewItem * viewItem = mainForm->dataFormViewItem(
       
   498                                         model->indexFromItem(item));
       
   499     if (viewItem)
       
   500     {
       
   501         return static_cast<HbComboBox*>(viewItem->dataItemContentWidget());
       
   502     }
       
   503     return NULL;
       
   504 }
       
   505 
       
   506 int JavaApplicationSettingsViewPrivate::readFromStorage(JavaApplicationSettings& settings)
       
   507 {
       
   508     int currentValue = -1;
       
   509     if (settings.getColumnName().size() > 0 && settings.getTableName().size() > 0)
       
   510     {
       
   511         wstring value = L"";
       
   512 
       
   513         JavaStorageApplicationEntry_t query;
       
   514         JavaStorageApplicationList_t queryResult;
       
   515         JavaStorageEntry attr;
       
   516         attr.setEntry(ID, iJavaAppUid);
       
   517         query.insert(attr);
       
   518         if (settings.getFilterColumnName().size() > 0)
       
   519         {
       
   520             attr.setEntry(settings.getFilterColumnName(), settings.getFilterColumnValue());
       
   521             query.insert(attr);
       
   522         }
       
   523         attr.setEntry(settings.getColumnName(), L"");
       
   524         query.insert(attr);
       
   525 
       
   526         try
       
   527         {
       
   528             iStorage->search(settings.getTableName(), query, queryResult);
       
   529         }
       
   530         catch (JavaStorageException& aJse)
       
   531         {
       
   532             // Don't leave. Set defaults.
       
   533         }
       
   534 
       
   535         findEntry(queryResult, settings.getColumnName(), value);
       
   536 
       
   537         if (value.size() > 0)
       
   538         {
       
   539             vector<wstring> storageValues = settings.getStorageValues();
       
   540             for (int i=0; i<storageValues.size(); i++)
       
   541             {
       
   542                 if (storageValues[i] == value)
       
   543                 {
       
   544                     currentValue = i;
       
   545                     break;
       
   546                 }
       
   547             }
       
   548         }
       
   549     }
       
   550 
       
   551     settings.setCurrentValue(currentValue);
       
   552     return currentValue;
       
   553 }
       
   554 
       
   555 void JavaApplicationSettingsViewPrivate::writeToStorage(JavaApplicationSettings& settings)
       
   556 {
       
   557     JavaStorageApplicationEntry_t oldEntry;
       
   558     JavaStorageEntry attr;
       
   559     attr.setEntry(ID, iJavaAppUid);
       
   560     oldEntry.insert(attr);
       
   561     JavaStorageApplicationEntry_t entry;
       
   562     if (settings.getFilterColumnName().size() > 0)
       
   563     {
       
   564         attr.setEntry(settings.getFilterColumnName(), settings.getFilterColumnValue());
       
   565         oldEntry.insert(attr);
       
   566     }
       
   567     attr.setEntry(settings.getColumnName(), settings.getStorageValues()[settings.getCurrentValue()]);
       
   568     entry.insert(attr);
       
   569 
       
   570     try
       
   571     {
       
   572         iStorage->update(settings.getTableName(), entry, oldEntry);
       
   573     }
       
   574     catch (JavaStorageException& aJse)
       
   575     {
       
   576     }
       
   577 }
       
   578 
       
   579 void JavaApplicationSettingsViewPrivate::findEntry(const JavaStorageApplicationList_t& queryResult,
       
   580         const std::wstring& eName,
       
   581         std::wstring& eValue)
       
   582 {
       
   583     if (queryResult.size() > 0)
       
   584     {
       
   585         JavaStorageApplicationEntry_t entry = queryResult.front();
       
   586         JavaStorageEntry findPattern;
       
   587         findPattern.setEntry(eName, L"");
       
   588         JavaStorageApplicationEntry_t::const_iterator findIterator =
       
   589             entry.find(findPattern);
       
   590         if (findIterator != entry.end())
       
   591         {
       
   592             eValue = findIterator->entryValue();
       
   593         }
       
   594     }
       
   595 }
       
   596 
       
   597 bool JavaApplicationSettingsViewPrivate::findFromStorage(const std::wstring& aColumnName, const std::wstring& aColumnFilterName, const std::wstring& aColumnFilterValue, const std::string& aTableName)
       
   598 {
       
   599     wstring value = readFromStorage(aColumnName, aColumnFilterName, aColumnFilterValue, aTableName);
       
   600 
       
   601     return (value.size() > 0);
       
   602 }
       
   603 
       
   604 wstring JavaApplicationSettingsViewPrivate::readFromStorage(const std::wstring& aColumnName, const std::wstring& aColumnFilterName, const std::wstring& aColumnFilterValue, const std::string& aTableName)
       
   605 {
       
   606     wstring value = L"";
       
   607 
       
   608     JavaStorageApplicationEntry_t query;
       
   609     JavaStorageApplicationList_t queryResult;
       
   610     JavaStorageEntry attr;
       
   611     attr.setEntry(ID, iJavaAppUid);
       
   612     query.insert(attr);
       
   613     if (aColumnFilterName.size() > 0)
       
   614     {
       
   615         attr.setEntry(aColumnFilterName, aColumnFilterValue);
       
   616         query.insert(attr);
       
   617     }
       
   618     attr.setEntry(aColumnName, L"");
       
   619     query.insert(attr);
       
   620 
       
   621     try
       
   622     {
       
   623         iStorage->search(aTableName, query, queryResult);
       
   624     }
       
   625     catch (JavaStorageException& aJse)
       
   626     {
       
   627         // Don't leave. Set defaults.
       
   628     }
       
   629 
       
   630     findEntry(queryResult, aColumnName, value);
       
   631 
       
   632     return value;
       
   633 }
       
   634 
       
   635 
       
   636 #ifdef WIN32
       
   637 #include "./moc/moc_javaapplicationsettingsview.cpp"
       
   638 #else
       
   639 #include "moc_javaapplicationsettingsview.cpp"
       
   640 #endif