phoneplugins/infowidgetplugin/infowidget/src/infowidgetpreferences.cpp
branchRCL_3
changeset 24 41a7f70b3818
equal deleted inserted replaced
23:40a3f856b14d 24:41a7f70b3818
       
     1 /*
       
     2  * Copyright (c) 2009 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 
       
    18 #include "infowidgetpreferences.h"
       
    19 #include "infowidgetlogging.h"
       
    20 
       
    21 /*!
       
    22   \class InfoWidgetPreferences
       
    23   \brief Preference store for widget  
       
    24          display etc. options   
       
    25 */
       
    26 
       
    27 
       
    28 /*!
       
    29     InfoWidgetPreferences::InfoWidgetPreferences() 
       
    30 */
       
    31 InfoWidgetPreferences::InfoWidgetPreferences(QObject *parent): 
       
    32     QObject(parent)
       
    33 {
       
    34     DPRINT;
       
    35 }
       
    36 
       
    37 /*!
       
    38     InfoWidgetPreferences::~InfoWidgetPreferences() 
       
    39 */
       
    40 InfoWidgetPreferences::~InfoWidgetPreferences()
       
    41 {
       
    42     DPRINT;
       
    43 }
       
    44 
       
    45 /*!
       
    46     InfoWidgetPreferences::storePreferences()
       
    47     
       
    48     Store acceptable preference set  
       
    49 */
       
    50 bool InfoWidgetPreferences::storePreferences()
       
    51 {
       
    52     DPRINT;
       
    53     bool changed(false); 
       
    54     
       
    55     if (validate() && 
       
    56         m_validatedOptions != m_options){
       
    57             m_validatedOptions = m_options;
       
    58             changed = true;
       
    59             emit preferencesChanged(m_validatedOptions);
       
    60         }
       
    61     else if (visibleItemCount() <= 0) { 
       
    62         DPRINT << ": invalid options, restoring initial options";
       
    63         restorePreferences();
       
    64     }
       
    65 
       
    66     return changed; 
       
    67 }
       
    68 
       
    69 /*!
       
    70     InfoWidgetPreferences::restorePreferences()
       
    71     
       
    72     Restores last acceptable preference set 
       
    73 */
       
    74 void InfoWidgetPreferences::restorePreferences()
       
    75 {
       
    76     DPRINT;
       
    77     m_options = m_validatedOptions; 
       
    78 }
       
    79 
       
    80 /*!
       
    81     InfoWidgetPreferences::preference() 
       
    82 */
       
    83 QString InfoWidgetPreferences::preference(Option preferenceId) const
       
    84 {
       
    85     DPRINT << ": preference id: " << static_cast<int>(preferenceId); 
       
    86     
       
    87     QString preferenceString;
       
    88     if (m_options.testFlag(preferenceId)) {
       
    89         preferenceString = DISPLAY_SETTING_ON; 
       
    90     } else {
       
    91         preferenceString = DISPLAY_SETTING_OFF;  
       
    92     } 
       
    93     
       
    94     return preferenceString;
       
    95 }
       
    96 
       
    97 /*!
       
    98     InfoWidgetPreferences::isPreferenceSet()
       
    99 */
       
   100 bool InfoWidgetPreferences::isPreferenceSet(Option preferenceId) const
       
   101 {
       
   102     DPRINT << ": preference id: " << static_cast<int>(preferenceId); 
       
   103     return m_options.testFlag(preferenceId); 
       
   104 }
       
   105 
       
   106 /*!
       
   107     InfoWidgetPreferences::preferences()
       
   108 */
       
   109 InfoWidgetPreferences::Options InfoWidgetPreferences::preferences() const
       
   110 {
       
   111     return m_options; 
       
   112 }
       
   113 
       
   114 /*!
       
   115     InfoWidgetPreferences::setPreference() 
       
   116 */
       
   117 void InfoWidgetPreferences::setPreference(Option preferenceId, 
       
   118     const QString& preferenceString)
       
   119 {
       
   120     DPRINT << ": preference id: " << static_cast<int>(preferenceId);
       
   121     DPRINT << ": preference string: " << preferenceString; 
       
   122     DPRINT << ": initial options: " << m_options;
       
   123     
       
   124     if (preferenceString.compare(DISPLAY_SETTING_ON) == 0) {
       
   125         m_options |= preferenceId; 
       
   126     } else {
       
   127         m_options &= ~preferenceId;
       
   128     }
       
   129     
       
   130     DPRINT << ": modified options: " << m_options;
       
   131 }
       
   132 
       
   133 /*!
       
   134     InfoWidgetPreferences::visibleItemCount() 
       
   135 */
       
   136 int InfoWidgetPreferences::visibleItemCount() 
       
   137 {
       
   138     DPRINT << ": IN";
       
   139     
       
   140     int visibleItems = 0;
       
   141     if (m_options.testFlag(DisplayHomeZone)){
       
   142         visibleItems++; 
       
   143     }
       
   144     if (m_options.testFlag(DisplayMcn)){
       
   145         visibleItems++; 
       
   146     }
       
   147     if (m_options.testFlag(DisplayActiveLine)){
       
   148         visibleItems++; 
       
   149     }
       
   150     if (m_options.testFlag(DisplaySatText)){
       
   151         visibleItems++; 
       
   152     }
       
   153     if (m_options.testFlag(DisplaySpn)){
       
   154         visibleItems++; 
       
   155     }
       
   156     
       
   157     DPRINT << ": visible item count: " << visibleItems;
       
   158     return visibleItems; 
       
   159 }
       
   160 
       
   161 /*!
       
   162     InfoWidgetPreferences::validate() 
       
   163 */
       
   164 bool InfoWidgetPreferences::validate() 
       
   165 {
       
   166     return visibleItemCount() > 0; 
       
   167 }
       
   168 
       
   169 /*!
       
   170    InfoWidgetPreferences::preferenceNames()
       
   171    
       
   172    Convenience function for getting all preference names
       
   173 */
       
   174 QStringList InfoWidgetPreferences::preferenceNames()
       
   175 {
       
   176     QStringList preferenceList; 
       
   177     preferenceList << "spnDisplay" << "homeZoneDisplay" << 
       
   178             "activeLineDisplay" << "satDisplay" << "mcnDisplay";
       
   179     return preferenceList; 
       
   180 }
       
   181 
       
   182 
       
   183 // End of File. 
       
   184