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