camerauis/cameraxui/cxui/src/cxuisettingxmlreader.cpp
changeset 43 0e652f8f1fbd
parent 28 3075d9b614e6
child 52 7e18d488ac5f
equal deleted inserted replaced
28:3075d9b614e6 43:0e652f8f1fbd
    16 */
    16 */
    17 
    17 
    18 #include <QPair>
    18 #include <QPair>
    19 #include <QtXml>
    19 #include <QtXml>
    20 #include <QFile>
    20 #include <QFile>
       
    21 #include <hbparameterlengthlimiter.h>
    21 
    22 
    22 
    23 
    23 #include "cxutils.h"
    24 #include "cxutils.h"
    24 #include "cxuienums.h"
    25 #include "cxuienums.h"
    25 #include "cxuisettingxmlreader.h"
    26 #include "cxuisettingxmlreader.h"
    32     static const char *TAG_ROOT                           = "cxui";
    33     static const char *TAG_ROOT                           = "cxui";
    33     static const char *TAG_SETTINGS                       = "settings";
    34     static const char *TAG_SETTINGS                       = "settings";
    34     static const char *TAG_SETTING_LIST                   = "setting_list";
    35     static const char *TAG_SETTING_LIST                   = "setting_list";
    35     static const char *TAG_SETTING_SLIDER                 = "setting_slider";
    36     static const char *TAG_SETTING_SLIDER                 = "setting_slider";
    36     static const char *TAG_ITEM                           = "item";
    37     static const char *TAG_ITEM                           = "item";
    37     static const char *TAG_ITEM_VARIANT                   = "lnItem";
    38     static const char *TAG_ITEM_VARIANT_LN                = "lnItem";
       
    39     static const char *TAG_ITEM_VARIANT_L1                = "l1Item";
    38     static const char *TAG_SETUP                          = "setup";
    40     static const char *TAG_SETUP                          = "setup";
    39 
    41 
    40     static const char *ATTRIBUTE_ID                       = "id";
    42     static const char *ATTRIBUTE_ID                       = "id";
    41     static const char *ATTRIBUTE_HEADING                  = "heading";
    43     static const char *ATTRIBUTE_HEADING                  = "heading";
    42     static const char *ATTRIBUTE_PREVIEW                  = "preview";
    44     static const char *ATTRIBUTE_PREVIEW                  = "preview";
    45     static const char *ATTRIBUTE_ICON                     = "icon";
    47     static const char *ATTRIBUTE_ICON                     = "icon";
    46 
    48 
    47     static const char *ATTRIBUTE_VALUE                    = "value";
    49     static const char *ATTRIBUTE_VALUE                    = "value";
    48     static const char *ATTRIBUTE_LOCALIZATION_ID          = "string";
    50     static const char *ATTRIBUTE_LOCALIZATION_ID          = "string";
    49     static const char *ATTRIBUTE_LOCALIZATION_ID_LN_VALUE = "lnValue";
    51     static const char *ATTRIBUTE_LOCALIZATION_ID_LN_VALUE = "lnValue";
       
    52     static const char *ATTRIBUTE_LOCALIZATION_ID_L1_VALUE = "l1Value";
    50 
    53 
    51     static const char *ATTRIBUTE_SLIDER_MIN               = "min";
    54     static const char *ATTRIBUTE_SLIDER_MIN               = "min";
    52     static const char *ATTRIBUTE_SLIDER_MAX               = "max";
    55     static const char *ATTRIBUTE_SLIDER_MAX               = "max";
    53     static const char *ATTRIBUTE_SLIDER_MINOR_STEP        = "minorStep";
    56     static const char *ATTRIBUTE_SLIDER_MINOR_STEP        = "minorStep";
    54     static const char *ATTRIBUTE_SLIDER_MAJOR_STEP        = "majorStep";
    57     static const char *ATTRIBUTE_SLIDER_MAJOR_STEP        = "majorStep";
   308             value.setValue(intValue);
   311             value.setValue(intValue);
   309         } else {
   312         } else {
   310             value.setValue(string);
   313             value.setValue(string);
   311         }
   314         }
   312 
   315 
   313 
       
   314         // get the string text id from the xml, and format based on type.
   316         // get the string text id from the xml, and format based on type.
   315         string = e.attribute(ATTRIBUTE_LOCALIZATION_ID);
   317         string = e.attribute(ATTRIBUTE_LOCALIZATION_ID);
   316         if (e.tagName() == TAG_ITEM) {
   318         if (e.tagName() == TAG_ITEM) {
   317             // get the localizable string from the hbtrid
   319             // string without parameters: get localised string
   318             string = hbTrId(string.toAscii().constData());
   320             string = hbTrId(string.toAscii().constData());
   319         } else if (e.tagName() == TAG_ITEM_VARIANT) {
   321             CX_DEBUG(("tag name <%s>", e.tagName().toAscii().constData()));
       
   322         } else if (e.tagName() == TAG_ITEM_VARIANT_L1) {
       
   323             // string with numeric parameter: get localised string and add numeric parameter
       
   324             QString l1Value = e.attribute(ATTRIBUTE_LOCALIZATION_ID_L1_VALUE);
       
   325             string = hbTrId(string.toAscii().constData()).arg(l1Value.toInt());
       
   326             CX_DEBUG(("tag name <%s>", e.tagName().toAscii().constData()));
       
   327             CX_DEBUG(("attribute [%s] value[%s]", ATTRIBUTE_LOCALIZATION_ID_L1_VALUE,
       
   328                      string.toAscii().constData()));
       
   329         } else if (e.tagName() == TAG_ITEM_VARIANT_LN) {
   320             QString lnValue = e.attribute(ATTRIBUTE_LOCALIZATION_ID_LN_VALUE);
   330             QString lnValue = e.attribute(ATTRIBUTE_LOCALIZATION_ID_LN_VALUE);
   321             // format the setting string
   331             // string with count parameter: get localised string and add plural form numeric parameter
   322             string = hbTrId(string.toAscii().constData(), lnValue.toInt());
   332             string = HbParameterLengthLimiter(string.toAscii().constData(), lnValue.toInt());
   323         }
   333             CX_DEBUG(("tag name <%s>", e.tagName().toAscii().constData()));
   324         CX_DEBUG(("attribute [%s] value[%s]", ATTRIBUTE_LOCALIZATION_ID, string.toAscii().constData()));
   334             CX_DEBUG(("attribute [%s] value[%s]", ATTRIBUTE_LOCALIZATION_ID_LN_VALUE, string.toAscii().constData()));
       
   335         }
   325 
   336 
   326         if (!string.isNull()) {
   337         if (!string.isNull()) {
   327             CxUiSettings::SettingItem setting;
   338             CxUiSettings::SettingItem setting;
   328             setting.mItem = string;
   339             setting.mItem = string;
   329             setting.mValue = value;
   340             setting.mValue = value;
   380         QVariant stepString = e.attribute(ATTRIBUTE_SLIDER_MINOR_STEP);
   391         QVariant stepString = e.attribute(ATTRIBUTE_SLIDER_MINOR_STEP);
   381         p->mMinorStep = stepString.toReal();
   392         p->mMinorStep = stepString.toReal();
   382         stepString = e.attribute(ATTRIBUTE_SLIDER_MAJOR_STEP);
   393         stepString = e.attribute(ATTRIBUTE_SLIDER_MAJOR_STEP);
   383         p->mMajorStep = stepString.toReal();
   394         p->mMajorStep = stepString.toReal();
   384 
   395 
   385         // get the ln value from xml to generate strings for slider
   396         // get the l1 value from xml to generate strings for slider
   386         QString lnValue = e.attribute(ATTRIBUTE_LOCALIZATION_ID_LN_VALUE);
   397         QString l1Value = e.attribute(ATTRIBUTE_LOCALIZATION_ID_L1_VALUE);
   387 
   398 
   388         // Don't create labels for slider if no strings are defined in settinsg xml
   399         // Don't create labels for slider if no strings are defined in settinsg xml
   389         // Create labels only for major ticks
   400         // Create labels only for major ticks
   390         if (!minString.isEmpty() && !maxString.isEmpty()) {
   401         if (!minString.isEmpty() && !maxString.isEmpty()) {
   391             qreal step = p->mMajorStep;
   402             qreal step = p->mMajorStep;
   392             qreal value = lnValue.toDouble();
   403             qreal value = l1Value.toDouble();
   393             // generating all negative valued strings for slider setting
   404             // generating all negative valued strings for slider setting
   394             while (value > 0) {
   405             while (value > 0) {
   395                 // format the setting string
   406                 // format the setting string
   396                 QString str =  hbTrId(minString.toAscii().constData()).arg(value,0,'f',1);
   407                 QString str =  hbTrId(minString.toAscii().constData()).arg(value,0,'f',1);
   397                 p->mSettingStrings.append(str);
   408                 p->mSettingStrings.append(str);
   399             }
   410             }
   400 
   411 
   401             // generating all non-negative valued strings for slider setting
   412             // generating all non-negative valued strings for slider setting
   402             step = p->mMajorStep;
   413             step = p->mMajorStep;
   403             value = 0;
   414             value = 0;
   404             while(value <= lnValue.toInt()) {
   415             while(value <= l1Value.toInt()) {
   405                 // format the setting string
   416                 // format the setting string
   406                 QString str = hbTrId(maxString.toAscii().constData()).arg(value,0,'f',1);
   417                 QString str = hbTrId(maxString.toAscii().constData()).arg(value,0,'f',1);
   407                 p->mSettingStrings.append(str);
   418                 p->mSettingStrings.append(str);
   408                 value = value + step;
   419                 value = value + step;
   409             }
   420             }
   410         }
   421         }
   411 
   422 
   412         int min = -lnValue.toInt();
   423         int min = -l1Value.toInt();
   413         int max = lnValue.toInt();
   424         int max = l1Value.toInt();
   414 
   425 
   415         p->mRange = qMakePair(min, max);
   426         p->mRange = qMakePair(min, max);
   416     }
   427     }
   417 
   428 
   418     CX_DEBUG_EXIT_FUNCTION();
   429     CX_DEBUG_EXIT_FUNCTION();