35 Default constructor. |
35 Default constructor. |
36 */ |
36 */ |
37 SettingsUtility::SettingsUtility(QObject *parent) |
37 SettingsUtility::SettingsUtility(QObject *parent) |
38 :QObject(parent) |
38 :QObject(parent) |
39 { |
39 { |
40 qDebug("clock: SettingsUtility::SettingsUtility -->"); |
|
41 |
|
42 mTimeSeparatorList << tr(".") << tr(":"); |
40 mTimeSeparatorList << tr(".") << tr(":"); |
43 mClockTypeList << tr("Analog") << tr("Digital"); |
41 mClockTypeList << hbTrId("txt_clock_button_digital") << hbTrId("txt_clock_button_analog"); |
44 mTimeFormatList << hbTrId("txt_clk_setlabel_val_24_hour") << hbTrId("txt_clk_setlabel_val_12_hour"); |
42 mTimeFormatList << hbTrId("txt_clk_setlabel_val_24_hour") << hbTrId("txt_clk_setlabel_val_12_hour"); |
45 mDateFormatList << hbTrId("txt_clk_setlabel_val_dd_mm_yyyy") << hbTrId("txt_clk_setlabel_val_mm_dd_yyyy") << hbTrId("txt_clk_setlabel_val_yyyy_mm_dd"); |
43 mDateFormatList << hbTrId("txt_clk_setlabel_val_dd_mm_yyyy") << hbTrId("txt_clk_setlabel_val_mm_dd_yyyy") << hbTrId("txt_clk_setlabel_val_yyyy_mm_dd"); |
46 mDateSeparatorList << tr(".") << tr(":") << tr("/") << tr("-"); |
44 mDateSeparatorList << tr(".") << tr(":") << tr("/") << tr("-"); |
47 mAutoUpdateValueList << tr("ON") << tr("OFF"); |
45 mAutoUpdateValueList << tr("ON") << tr("OFF"); |
48 mSnoozeValueList << tr("5 minutes") << tr("15 minutes") << tr(" 30 minutes") << tr("1 hour"); |
46 mSnoozeValueList << tr("5 minutes") << tr("15 minutes") << tr(" 30 minutes") << tr("1 hour"); |
49 |
|
50 mTimeZoneClient = new TimezoneClient(this); |
|
51 |
|
52 qDebug("clock: SettingsUtility::SettingsUtility <--"); |
|
53 |
|
54 // mSettingsMamager = new XQSettingsManager(this); |
|
55 } |
47 } |
56 |
48 |
57 /*! |
49 /*! |
58 Destructor. |
50 Destructor. |
59 */ |
51 */ |
60 SettingsUtility::~SettingsUtility() |
52 SettingsUtility::~SettingsUtility() |
61 { |
53 { |
62 // Nothing yet. |
54 // Nothing. |
63 } |
55 } |
64 |
56 |
65 /*! |
57 /*! |
66 |
58 Returns the current time in the device. |
67 */ |
|
68 void SettingsUtility::setTime(const QString &time) |
|
69 { |
|
70 QTime newTime = QTime::fromString(time, timeFormatString()); |
|
71 |
|
72 if (newTime.isValid()) { |
|
73 mTimeZoneClient->setDateTime(QDateTime(QDate::currentDate(), newTime)); |
|
74 } |
|
75 } |
|
76 |
|
77 /*! |
|
78 |
|
79 */ |
59 */ |
80 QString SettingsUtility::time() |
60 QString SettingsUtility::time() |
81 { |
61 { |
82 return QTime::currentTime().toString(timeFormatString()); |
62 return QTime::currentTime().toString(timeFormatString()); |
83 } |
|
84 |
|
85 /*! |
|
86 |
|
87 */ |
|
88 void SettingsUtility::setTimeZone(const QString &timezone) |
|
89 { |
|
90 Q_UNUSED(timezone) |
|
91 } |
|
92 |
|
93 /*! |
|
94 |
|
95 */ |
|
96 QString SettingsUtility::timeZone() |
|
97 { |
|
98 QStringList dummyList; |
|
99 |
|
100 // Get the current zone info. |
|
101 LocationInfo currentZoneInfo = mTimeZoneClient->getCurrentZoneInfoL(); |
|
102 |
|
103 // Construct the GMT +/- X string. |
|
104 QString gmtOffset(hbTrId("txt_common_common_gmt")); |
|
105 |
|
106 int utcOffset = currentZoneInfo.zoneOffset; |
|
107 int offsetInHours (utcOffset/60); |
|
108 int offsetInMinutes (utcOffset%60); |
|
109 |
|
110 // Check wether the offset is +ve or -ve. |
|
111 if (0 < utcOffset) { |
|
112 // We have a positive offset. Append the '+' character. |
|
113 gmtOffset += tr("+ "); |
|
114 } else if (0 > utcOffset) { |
|
115 // We have a negative offset. Append the '-' character. |
|
116 gmtOffset += tr("- "); |
|
117 offsetInHours = -offsetInHours; |
|
118 } else { |
|
119 // We dont have an offset. We are at GMT zone. |
|
120 } |
|
121 |
|
122 // Append the hour component. |
|
123 gmtOffset += QString::number(offsetInHours); |
|
124 |
|
125 // Append the time separator. |
|
126 gmtOffset += mTimeSeparatorList.at(timeSeparator(dummyList)); |
|
127 |
|
128 // Append the minute component. |
|
129 // If minute component is less less than 10, append a '00' |
|
130 if (0 <= offsetInMinutes && offsetInMinutes < 10) { |
|
131 gmtOffset += tr("00"); |
|
132 } else { |
|
133 gmtOffset += QString::number(offsetInMinutes); |
|
134 } |
|
135 |
|
136 gmtOffset += tr(" "); |
|
137 // TODO: append city name when more than one cities else country name. |
|
138 gmtOffset += currentZoneInfo.cityName; |
|
139 |
|
140 return gmtOffset; |
|
141 } |
63 } |
142 |
64 |
143 /*! |
65 /*! |
144 |
66 |
145 */ |
67 */ |
247 } else { |
167 } else { |
248 // Nothing to do. |
168 // Nothing to do. |
249 } |
169 } |
250 |
170 |
251 list = mTimeSeparatorList; |
171 list = mTimeSeparatorList; |
252 |
|
253 qDebug() << "clock: SettingsUtility::timeSeparator <--"; |
|
254 |
|
255 return value; |
172 return value; |
256 } |
173 } |
257 |
174 |
258 /*! |
175 /*! |
259 |
176 |
260 */ |
177 */ |
261 void SettingsUtility::setAutoUpdate(const QString &value) |
|
262 { |
|
263 // TODO: implement the changes after server is in place. |
|
264 // 1. Inform the server about the setting. |
|
265 // 2. Get the status of the change from server |
|
266 // 3. Emit the signal to inform the clients of the change in the settings item, |
|
267 // pass the enum of settings item changed and the updated value. |
|
268 |
|
269 if (0 == value.compare(tr("ON"), Qt::CaseInsensitive)) { |
|
270 mTimeZoneClient->setTimeUpdateOn(true); |
|
271 } else { |
|
272 mTimeZoneClient->setTimeUpdateOn(false); |
|
273 } |
|
274 |
|
275 emit settingsChanged(AutoTimeUpdate, value); |
|
276 } |
|
277 |
|
278 /*! |
|
279 |
|
280 */ |
|
281 int SettingsUtility::autoUpdate(QStringList &list) |
|
282 { |
|
283 // TODO: implement properly. this is jst a dummy implementation. |
|
284 int value = 1; |
|
285 |
|
286 bool autoUpdate = mTimeZoneClient->timeUpdateOn(); |
|
287 |
|
288 if (autoUpdate) { |
|
289 value = 0; |
|
290 } |
|
291 list = mAutoUpdateValueList; |
|
292 return value; |
|
293 } |
|
294 |
|
295 /*! |
|
296 |
|
297 */ |
|
298 void SettingsUtility::setDate(const QString &date) |
|
299 { |
|
300 QDate newDate = QDate::fromString(date, dateFormatString()); |
|
301 |
|
302 if (newDate.isValid()) { |
|
303 mTimeZoneClient->setDateTime(QDateTime(newDate, QTime::currentTime())); |
|
304 } |
|
305 } |
|
306 |
|
307 /*! |
|
308 |
|
309 */ |
|
310 QString SettingsUtility::date() |
178 QString SettingsUtility::date() |
311 { |
179 { |
312 qDebug() << "clock: SettingsUtility::date -->"; |
|
313 |
|
314 qDebug() << "clock: SettingsUtility::date <--"; |
|
315 |
|
316 return QDate::currentDate().toString(dateFormatString()); |
180 return QDate::currentDate().toString(dateFormatString()); |
317 } |
181 } |
318 |
182 |
319 /*! |
183 /*! |
320 |
184 |
454 QString format; |
318 QString format; |
455 TLocale locale; |
319 TLocale locale; |
456 QStringList dummyList; |
320 QStringList dummyList; |
457 |
321 |
458 if (ETime24 == locale.TimeFormat()) { |
322 if (ETime24 == locale.TimeFormat()) { |
459 format = QString("h:mm"); |
323 format = QString("hh:mm"); |
460 } else if (ETime12 == locale.TimeFormat()) { |
324 } else if (ETime12 == locale.TimeFormat()) { |
461 format = QString("h:mm ap"); |
325 format = QString("hh:mm ap"); |
462 } |
326 } |
463 |
327 |
464 QString separator = mTimeSeparatorList.at(timeSeparator(dummyList)); |
328 QString separator = mTimeSeparatorList.at(timeSeparator(dummyList)); |
465 |
329 |
466 format.replace(QString(":"), separator); |
330 format.replace(QString(":"), separator); |