|
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: Clock widget |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QTimer> |
|
19 #include "hsclocksettingsnotifier_symbian.h" |
|
20 |
|
21 #include <bacntf.h> // CEnvironmentChangeNotifier |
|
22 |
|
23 |
|
24 namespace |
|
25 { |
|
26 const char ANALOG[] = "analog"; |
|
27 const char DIGITAL[] = "digital"; |
|
28 const char TIME12[] = "TIME12"; |
|
29 const char TIME24[] = "TIME24"; |
|
30 } |
|
31 |
|
32 /*! |
|
33 \class HsClockSettingsNotifierType |
|
34 \ingroup group_HsClockSettingsNotifierplugin |
|
35 \brief Implementation for the observation of the system clock settings (analog/digital). |
|
36 |
|
37 */ |
|
38 |
|
39 |
|
40 /*! |
|
41 Constructor |
|
42 */ |
|
43 HsClockSettingsNotifier::HsClockSettingsNotifier(QObject *parent) |
|
44 : QObject(parent), |
|
45 mDateTimeNotifier(0) |
|
46 { |
|
47 mClockFormat = clockFormatString(); |
|
48 mTimeFormat = timeFormatString(); |
|
49 createObserver(); |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 /*! |
|
55 Destructor. |
|
56 */ |
|
57 HsClockSettingsNotifier::~HsClockSettingsNotifier() |
|
58 { |
|
59 delete mDateTimeNotifier; |
|
60 } |
|
61 |
|
62 /*! |
|
63 Returns the clock format ('analog'/'digital') |
|
64 */ |
|
65 QString HsClockSettingsNotifier::clockFormat() const |
|
66 { |
|
67 return mClockFormat; |
|
68 } |
|
69 |
|
70 /*! |
|
71 Returns the time format ('12'/'24') |
|
72 */ |
|
73 QString HsClockSettingsNotifier::timeFormat() const |
|
74 { |
|
75 return mTimeFormat; |
|
76 } |
|
77 |
|
78 /*! |
|
79 Callback function to receive system settings changes. |
|
80 */ |
|
81 TInt HsClockSettingsNotifier::EnvironmentChanged( TAny* aSelf ) |
|
82 { |
|
83 HsClockSettingsNotifier* self = static_cast<HsClockSettingsNotifier*>(aSelf); |
|
84 if ( self ){ |
|
85 TInt change = self->mDateTimeNotifier->Change(); |
|
86 if ( change & EChangesLocale ) { |
|
87 self->onSettingsChanged(); |
|
88 } |
|
89 } |
|
90 return KErrNone; |
|
91 } |
|
92 |
|
93 /*! |
|
94 Creates CEnvironmentChangeNotifier object to listen system settings changes. |
|
95 */ |
|
96 void HsClockSettingsNotifier::createObserver() |
|
97 { |
|
98 if ( !mDateTimeNotifier ){ |
|
99 mDateTimeNotifier = CEnvironmentChangeNotifier::NewL( |
|
100 CActive::EPriorityLow, |
|
101 TCallBack( EnvironmentChanged, this ) ); |
|
102 |
|
103 mDateTimeNotifier->Start(); |
|
104 } |
|
105 } |
|
106 |
|
107 /*! |
|
108 Reads clock format from system locale settings |
|
109 */ |
|
110 QString HsClockSettingsNotifier::clockFormatString() const |
|
111 { |
|
112 TLocale locale; |
|
113 TClockFormat clockFormat = locale.ClockFormat(); |
|
114 if ( clockFormat==EClockAnalog ) { |
|
115 return QString(ANALOG); |
|
116 } else { |
|
117 return QString(DIGITAL); |
|
118 } |
|
119 } |
|
120 |
|
121 /*! |
|
122 Reads time format from system locale settings |
|
123 */ |
|
124 QString HsClockSettingsNotifier::timeFormatString() const |
|
125 { |
|
126 TLocale locale; |
|
127 TTimeFormat timeFormat = locale.TimeFormat(); |
|
128 if ( timeFormat==ETime12 ) { |
|
129 return QString(TIME12); |
|
130 } else { |
|
131 return QString(TIME24); |
|
132 } |
|
133 } |
|
134 |
|
135 /*! |
|
136 */ |
|
137 void HsClockSettingsNotifier::onSettingsChanged() |
|
138 { |
|
139 QString clockFormat = clockFormatString(); |
|
140 QString timeFormat = timeFormatString(); |
|
141 if ( clockFormat != mClockFormat || timeFormat != mTimeFormat ) { |
|
142 mClockFormat = clockFormat; |
|
143 mTimeFormat = timeFormat; |
|
144 emit settingsChanged(mClockFormat, mTimeFormat); |
|
145 } |
|
146 } |
|
147 |