WorldClock: Set initial timezone on map. 54/104854/2
authorRadoslaw Czerski <r.czerski@samsung.com>
Fri, 16 Dec 2016 14:05:16 +0000 (15:05 +0100)
committerRadoslaw Czerski <r.czerski@samsung.com>
Fri, 16 Dec 2016 14:05:16 +0000 (15:05 +0100)
Change-Id: Ia1148960f846a35a17603e6b420c1b7921cd7abb
Signed-off-by: Radoslaw Czerski <r.czerski@samsung.com>
clock/src/Model/WorldClock.cpp

index 098dbfd..a77e16b 100644 (file)
 #include <algorithm>
 #include <string>
 #include <sstream>
+#include <system_settings.h>
 
 #include "Model/WorldClock.h"
 #include "Model/Location.h"
 #include "Utils/Log.h"
+#include "Utils/Time.h"
 
 using namespace model;
 
@@ -137,17 +139,26 @@ std::vector<Timezone> WorldClock::time_zones_ = {
 
 WorldClock::WorldClock()
 {
+       char *tz;
+       int current_tz = 11; //GMT+0
+
        parameter_signals_.resize((int)ParameterSignalType::MAX);
        signals_.resize((int)SignalType::MAX);
        LoadItemsList();
 
-       int current_tz = 1;
        int ret = preference_get_int("WORLD_CLOCK_MAP_CURRENT_TIMEZONE", &current_tz);
        if (ret != PREFERENCE_ERROR_NONE) {
-               preference_set_int("WORLD_CLOCK_MAP_CURRENT_TIMEZONE", 12); // This timezone 'no' need to be retrieved using current position
-       }
 
-       SetCurrentTimezone(&time_zones_.at(current_tz));
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &tz);
+               if (ret == SYSTEM_SETTINGS_ERROR_NONE) {
+                       int offset = utils::Time::GetTimezoneOffset(tz);
+                       SetCurrentTimezone(GetTimezoneByOffset(offset));
+                       DBG("Current timezone set to:%s", tz);
+               }
+               else
+                       SetCurrentTimezone(&time_zones_.at(current_tz));
+       } else
+               SetCurrentTimezone(&time_zones_.at(current_tz));
 }
 
 WorldClock::~WorldClock()
@@ -156,7 +167,7 @@ WorldClock::~WorldClock()
 
        int ret = preference_set_int("WORLD_CLOCK_MAP_CURRENT_TIMEZONE", GetCurrentTimezoneNo());
        if (ret != PREFERENCE_ERROR_NONE) {
-               DBG("preference_set_int failed[%d]: %s", ret, get_error_message(ret));
+               ERR("preference_set_int failed[%d]: %s", ret, get_error_message(ret));
        }
 }