homescreenapp/widgetplugins/hsclockwidgetplugin/src/hsclocksettingsnotifier_symbian.cpp
changeset 98 e6f74eb7f69f
parent 46 23b5d6a29cce
equal deleted inserted replaced
97:66b5fe3c07fd 98:e6f74eb7f69f
    17 
    17 
    18 #include <QTimer>
    18 #include <QTimer>
    19 #include "hsclocksettingsnotifier_symbian.h"
    19 #include "hsclocksettingsnotifier_symbian.h"
    20 
    20 
    21 #include <bacntf.h> // CEnvironmentChangeNotifier
    21 #include <bacntf.h> // CEnvironmentChangeNotifier
       
    22 #include <xqsettingsmanager.h>
       
    23 #include <xqsettingskey.h>
       
    24 #include <clockdomaincrkeys.h>
    22 
    25 
    23 
    26 
    24 namespace
    27 namespace
    25 {
    28 {
    26     const char ANALOG[] = "analog";
    29     const char ANALOG[] = "analog";
    42 */
    45 */
    43 HsClockSettingsNotifier::HsClockSettingsNotifier(QObject *parent)
    46 HsClockSettingsNotifier::HsClockSettingsNotifier(QObject *parent)
    44     : QObject(parent),
    47     : QObject(parent),
    45       mDateTimeNotifier(0)
    48       mDateTimeNotifier(0)
    46 {
    49 {
    47     mClockFormat = clockFormatString();
       
    48     mTimeFormat = timeFormatString();
    50     mTimeFormat = timeFormatString();
    49     createObserver();
    51     createSystemChangeObserver();
       
    52     
       
    53 	// Connect for the clock type changes to refresh the view
       
    54 	mSettingsManager = new XQSettingsManager();
       
    55 	mClockTypeSettingsKey = new XQSettingsKey(
       
    56 							XQSettingsKey::TargetCentralRepository,
       
    57 							KCRUidClockApp,
       
    58 							KClockType);
       
    59 	
       
    60     mClockType = clockTypeString();
       
    61 	
       
    62 	mSettingsManager->startMonitoring(*mClockTypeSettingsKey);
       
    63 	connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
       
    64 				this, SLOT(onClockTypeChanged(XQSettingsKey, QVariant)));
       
    65 
    50 }
    66 }
    51 
    67 
    52 
    68 
    53 
    69 
    54 /*!
    70 /*!
    55     Destructor.
    71     Destructor.
    56 */
    72 */
    57 HsClockSettingsNotifier::~HsClockSettingsNotifier()
    73 HsClockSettingsNotifier::~HsClockSettingsNotifier()
    58 {
    74 {
    59     delete mDateTimeNotifier;
    75     delete mDateTimeNotifier;
       
    76     mSettingsManager->stopMonitoring(*mClockTypeSettingsKey);
       
    77     delete mClockTypeSettingsKey;
       
    78     delete mSettingsManager;
    60 }
    79 }
    61 
    80 
    62 /*!
    81 /*!
    63     Returns the clock format ('analog'/'digital')
    82     Returns the clock format ('analog'/'digital')
    64 */
    83 */
    65 QString HsClockSettingsNotifier::clockFormat() const
    84 QString HsClockSettingsNotifier::clockType() const
    66 {
    85 {
    67     return mClockFormat;
    86     return mClockType;
    68 }
    87 }
    69 
    88 
    70 /*!
    89 /*!
    71     Returns the time format ('12'/'24')
    90     Returns the time format ('12'/'24')
    72 */
    91 */
    89     }
   108     }
    90     return KErrNone;        
   109     return KErrNone;        
    91 }
   110 }
    92 
   111 
    93 /*!
   112 /*!
       
   113 	Slot which is called when the value changes in cenrep.
       
   114 
       
   115 	\param key The key which got changed in cenrep.
       
   116 	\param value The new value of that key.
       
   117  */
       
   118 void HsClockSettingsNotifier::onClockTypeChanged( const XQSettingsKey& key, const QVariant& value )
       
   119 {
       
   120     Q_UNUSED(value)
       
   121 	if (key.uid() == KCRUidClockApp && key.key() == KClockType) {
       
   122 		onSettingsChanged();
       
   123 	}
       
   124 }
       
   125 
       
   126 /*!
    94  Creates CEnvironmentChangeNotifier object to listen system settings changes.
   127  Creates CEnvironmentChangeNotifier object to listen system settings changes.
    95 */
   128 */
    96 void HsClockSettingsNotifier::createObserver() 
   129 void HsClockSettingsNotifier::createSystemChangeObserver() 
    97 {
   130 {
    98     if ( !mDateTimeNotifier ){
   131     if ( !mDateTimeNotifier ){
    99         mDateTimeNotifier = CEnvironmentChangeNotifier::NewL( 
   132         mDateTimeNotifier = CEnvironmentChangeNotifier::NewL( 
   100             CActive::EPriorityLow,
   133             CActive::EPriorityLow,
   101             TCallBack( EnvironmentChanged, this ) );
   134             TCallBack( EnvironmentChanged, this ) );
   105 }   
   138 }   
   106 
   139 
   107 /*!
   140 /*!
   108     Reads clock format from system locale settings
   141     Reads clock format from system locale settings
   109 */
   142 */
   110 QString HsClockSettingsNotifier::clockFormatString() const
   143 QString HsClockSettingsNotifier::clockTypeString() const
   111 {
   144 {
   112     TLocale locale;
   145 	int clockType = -1;
   113     TClockFormat clockFormat = locale.ClockFormat();
   146 	// Read the clocktype value from the cenrep
   114     if ( clockFormat==EClockAnalog ) {
   147 	// 0 is for Analogue type and 1 for Digital
       
   148 	QVariant value = mSettingsManager->readItemValue(*mClockTypeSettingsKey);
       
   149 	clockType = value.toInt();
       
   150 
       
   151     if ( clockType == 0 ) {
   115         return QString(ANALOG);
   152         return QString(ANALOG);
   116     } else {
   153     } else {
   117         return QString(DIGITAL);
   154         return QString(DIGITAL);
   118     }
   155     }
   119 }
   156 }
   123 */
   160 */
   124 QString HsClockSettingsNotifier::timeFormatString() const
   161 QString HsClockSettingsNotifier::timeFormatString() const
   125 {
   162 {
   126     TLocale locale;
   163     TLocale locale;
   127     TTimeFormat timeFormat = locale.TimeFormat();
   164     TTimeFormat timeFormat = locale.TimeFormat();
   128     if ( timeFormat==ETime12 ) {
   165     if ( timeFormat == ETime12 ) {
   129         return QString(TIME12);
   166         return QString(TIME12);
   130     } else {
   167     } else {
   131         return QString(TIME24);
   168         return QString(TIME24);
   132     }
   169     }
   133 }
   170 }
   134 
   171 
   135 /*!
   172 /*!
   136 */
   173 */
   137 void HsClockSettingsNotifier::onSettingsChanged()
   174 void HsClockSettingsNotifier::onSettingsChanged()
   138 {
   175 {
   139     QString clockFormat = clockFormatString();
   176     QString clockType = clockTypeString();
   140     QString timeFormat = timeFormatString();
   177     QString timeFormat = timeFormatString();
   141     if ( clockFormat != mClockFormat || timeFormat != mTimeFormat ) {
   178     if ( clockType != mClockType || timeFormat != mTimeFormat ) {
   142         mClockFormat = clockFormat;
   179         mClockType = clockType;
   143         mTimeFormat = timeFormat;
   180         mTimeFormat = timeFormat;
   144         emit settingsChanged(mClockFormat, mTimeFormat);
   181         emit settingsChanged(mClockType, mTimeFormat);
   145     }
   182     }
   146 }
   183 }
   147 
   184