[Utils] Create SystemSettings class 51/126151/4
authorKamil Lipiszko <k.lipiszko@samsung.com>
Thu, 20 Apr 2017 08:37:46 +0000 (10:37 +0200)
committerKamil Lipiszko <k.lipiszko@samsung.com>
Fri, 21 Apr 2017 10:45:34 +0000 (12:45 +0200)
SystemSettings class handles incoming changes in system such as
prefered time change or language change and fires events on
above appearance.

Change-Id: I8d0742dfa03fa7e11c9b738fae65487394deba2d

13 files changed:
clock/inc/Utils/SystemSettings.h [new file with mode: 0644]
clock/inc/Utils/Time.h
clock/inc/View/WorldClockView.h
clock/src/Clock.cpp
clock/src/Presenter/RingPresenter.cpp
clock/src/Utils/SystemSettings.cpp [new file with mode: 0644]
clock/src/Utils/Time.cpp
clock/src/View/AlarmView.cpp
clock/src/View/DeleteAlarmView.cpp
clock/src/View/EditAlarmView.cpp
clock/src/View/WorldClockDeleteItemsView.cpp
clock/src/View/WorldClockReorderView.cpp
clock/src/View/WorldClockView.cpp

diff --git a/clock/inc/Utils/SystemSettings.h b/clock/inc/Utils/SystemSettings.h
new file mode 100644 (file)
index 0000000..9ce1151
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+* Copyright 2016  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef _CLOCK_SYSTEM_SETTINGS_H_
+#define _CLOCK_SYSTEM_SETTINGS_H_
+
+#include <string>
+#include <system_settings.h>
+
+#include "Utils/EventBus.h"
+
+namespace utils {
+
+class SystemSettings {
+public:
+       /**
+        * @brief Event indicate that system language setting
+        * has changed.
+        */
+       class LanguageChanged : public Event {
+       };
+
+       /**
+        * @brief Event indicate that system-wide time fromat setting
+        * has changed.
+        */
+       class TimeFormatChanged : public Event {
+       };
+
+       /**
+        * @brief Returns current locale string
+        *
+        * @return string with currently set locale
+        */
+       static const char *GetLocale();
+
+       /**
+        * @brief Indicates whether the 24-hour clock is system-prefered.
+        *
+        * @return true if system prefers 24-hour clock, false if 12-hour.
+        */
+       static bool Is24HourFormatPrefered();
+
+       /**
+        * @brief Registers callbacks on system configuration change
+        *
+        * @return true on success, otherwise false
+        *
+        * @see Unregister()
+        */
+       static bool Register();
+
+       /**
+        * @brief Unregisters callbacks on system configuration change
+        *
+        * @see Register()
+        */
+       static void Unregister();
+
+       SystemSettings() = delete;
+       SystemSettings(const SystemSettings &) = delete;
+       SystemSettings &operator=(const SystemSettings &) = delete;
+       ~SystemSettings();
+
+private:
+       static void OnLanguageChanged(system_settings_key_e key, void *user_data);
+       static void OnTimeFormatChanged(system_settings_key_e key, void *user_data);
+
+       static char *locale_;
+       static bool is_24hour_format_prefered_;
+       static bool is_registered;
+};
+
+}
+
+#endif //_CLOCK_SYSTEM_SETTINGS_H_
index f6d76c8c53f670cf35ced30efeb47055b3edff42..b9249e302845a2fe2b125fc120d8fbd82cc9becc 100644 (file)
@@ -20,6 +20,7 @@
 #include "Common/Defines.h"
 #include "Utils/EventBus.h"
 #include "Utils/Serialization.h"
+#include "Utils/SystemSettings.h"
 
 #include <map>
 #include <ctime>
@@ -31,13 +32,6 @@ namespace utils {
         */
        class Time : public utils::ISerializable {
                public:
-                       /**
-                        * @brief Event indicate that system-wide time fromat setting
-                        * has changed. The current prefered time format
-                        * can be obtained with Is24HourFormat function.
-                        */
-                       class PreferedTimeFormatChanged : public utils::Event {
-                       };
                        /** @brief Predefined string for 12-hour format */
                        static const char *FORMAT_TIME_12H;// = "h:mm";
                        /** @brief Predefined string for 32-hour format */
@@ -208,13 +202,6 @@ namespace utils {
                         */
                        static const std::string &GetCurrentTimezone();
 
-                       /**
-                        * @brief Indicates whether the 24-hour clock is system-prefered.
-                        *
-                        * @return true if system prefers 24-hour clock, false if 12-hour.
-                        */
-                       static bool Is24HourFormatPrefered();
-
                private:
                        Time(double milliseconds, const std::string &tz);
 
index cfdb50e51e664a98c96fa6c3a19177a57cb8b135..02db9498ee50a70803fd039a1a08418e0b1e5606 100644 (file)
@@ -173,6 +173,31 @@ namespace view {
                        int GetItemsCount();
 
                private:
+
+                       /**
+                        * @brief Genlist item data model
+                        */
+                       struct LocationItemData {
+                                       /** container view */
+                                       WorldClockView *wc_view;
+                                       /** elm_time table */
+                                       Evas_Object *time;
+
+                                       /** location pointer */
+                                       const model::Location *location;
+
+                                       /** date to be displayed */
+                                       char *date;
+                                       /** city to be displayed */
+                                       char *city_country;
+                                       /** time offset to be displayed */
+                                       char *gmt_offset_relative;
+                                       /** time offset from GMT+0 in minutes */
+                                       int gmt_offset;
+                                       /** elm_genlist item handle */
+                                       Elm_Object_Item *it;
+                       };
+
                        void CreateTimezoneDetails();
                        void CreateCustomLocationsList(Evas_Object *parent);
                        void CreateTimezoneCitiesList();
@@ -186,6 +211,9 @@ namespace view {
                        void UpdateTimezoneRelativeToLocal(int timezone_offset);
                        void UpdateTimezoneCitiesList(const model::Timezone *timezone);
 
+                       void UpdateLocationItemLanguage(LocationItemData *data);
+                       void UpdateCustomList();
+
                        static void ChangeTimezoneCb(void *data, Evas_Object *obj,
                                const char *emission, const char *source);
                        static void ItemClicked(void *data, Evas_Object *obj, void *event_info);
@@ -245,7 +273,9 @@ namespace view {
                        WorldClockMap *map_;
 
                        utils::Connection time_format_change_listener_;
+                       utils::Connection language_change_listener_;
                        void TimeFormatChanged();
+                       void LanguageChanged();
 
                        model::Timezone current_timezone_; /* Currently displayed timezone */
        };
index 039998c59f03d5fce49f52057a260087a7caa56c..5b56d6b278392a6c7a7e69aafb8d5fce8514800e 100644 (file)
 #include "app.h"
 #include "Clock.h"
 #include "Utils/TizenApp.h"
+#include "Utils/SystemSettings.h"
 
 bool ClockApp::OnCreate()
 {
+       if (!utils::SystemSettings::Register()) {
+               ERR("Could not register SystemSettings callbacks");
+               return false;
+       }
+
        elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
        provider_ = new model::AlarmProvider();
        main_ctrl_ = new controller::MainController(provider_);
        ring_ctrl_ = new controller::RingController(provider_->GetAlarms());
+
        return true;
 }
 
@@ -44,6 +51,9 @@ void ClockApp::OnLanguageChanged(app_event_info_h event)
        if (language != NULL) {
                elm_language_set(language);
                free(language);
+
+               utils::SystemSettings::LanguageChanged languageChangedEvent;
+               utils::EventBus::FireEvent(languageChangedEvent);
        }
 }
 
@@ -53,6 +63,8 @@ void ClockApp::OnTerminate()
        delete provider_;
        delete main_ctrl_;
        delete ring_ctrl_;
+
+       utils::SystemSettings::Unregister();
 }
 
 void ClockApp::OnResume()
index 159dbc3f56b9c480a44386a3663cbf9f1f4cc20f..67c1b6318ecbba1f8e50f7fcd76f99afb93cac71 100644 (file)
@@ -88,7 +88,7 @@ void RingPresenter::AlarmHandle(utils::Event &e)
        view_->SetTitle(alarm->GetName().c_str());
        utils::Time time = alarm->GetTime();
 
-       if (utils::Time::Is24HourFormatPrefered()) {
+       if (utils::SystemSettings::Is24HourFormatPrefered()) {
                view_->SetTimeLabel(nullptr, time.Format("HH:mm").c_str(),
                                time.Format("EEE, d MMMM").c_str());
        } else {
diff --git a/clock/src/Utils/SystemSettings.cpp b/clock/src/Utils/SystemSettings.cpp
new file mode 100644 (file)
index 0000000..4c1f6ff
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+* Copyright 2016  Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "Utils/SystemSettings.h"
+#include "Utils/Log.h"
+
+namespace utils {
+
+char *SystemSettings::locale_;
+bool SystemSettings::is_24hour_format_prefered_;
+bool SystemSettings::is_registered;
+
+
+void SystemSettings::Unregister()
+{
+       system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR);
+       system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE);
+
+       free(locale_);
+       locale_ = nullptr;
+       is_24hour_format_prefered_ = true;
+       is_registered = false;
+}
+
+bool SystemSettings::Register()
+{
+       if (is_registered)
+               return true;
+
+       int err = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
+                       OnTimeFormatChanged, NULL);
+       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_set_changed_cb failed: %s", get_error_message(err));
+               return false;
+       }
+
+       err = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE,
+                       OnLanguageChanged, NULL);
+       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_set_changed_cb failed: %s", get_error_message(err));
+               system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR);
+               return false;
+       }
+
+       err = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale_);
+       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_get_value_string failed[%d]: %s", err, get_error_message(err));
+               locale_ = getenv("LOCALE") ? strdup(getenv("LOCALE")) : strdup("");
+       }
+
+       err = system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
+                       &is_24hour_format_prefered_);
+       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_get_value_string failed[%d]: %s", err, get_error_message(err));
+               is_24hour_format_prefered_ = true;
+       }
+
+       is_registered = true;
+
+       return is_registered;
+}
+
+
+void SystemSettings::OnLanguageChanged(system_settings_key_e key, void *user_data)
+{
+       free(locale_);
+
+       int ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale_);
+       if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_get_value_string failed: %s", get_error_message(ret));
+               locale_ = getenv("LOCALE") ? strdup(getenv("LOCALE")) : strdup("");
+       }
+
+       LanguageChanged event;
+       EventBus::FireEvent(event);
+}
+
+void SystemSettings::OnTimeFormatChanged(system_settings_key_e key, void *user_data)
+{
+       int err = system_settings_get_value_bool(
+                       SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &is_24hour_format_prefered_);
+       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
+               ERR("system_settings_get_value_string failed[%d]: %s", err, get_error_message(err));
+               is_24hour_format_prefered_ = true;
+       }
+
+       TimeFormatChanged event;
+       EventBus::FireEvent(event);
+}
+
+const char *SystemSettings::GetLocale()
+{
+       return locale_;
+}
+
+bool SystemSettings::Is24HourFormatPrefered()
+{
+       return is_24hour_format_prefered_;
+}
+
+} //namespace utils
index f46de593d12ec177f5455a7a5fc4d4c5265ce3c8..54b80625108709acd8959bf0b011855d5f48bfb0 100644 (file)
@@ -21,7 +21,6 @@
 #include <cmath>
 #include <ctime>
 #include <Elementary.h>
-#include <system_settings.h>
 
 
 using namespace utils;
@@ -197,18 +196,18 @@ std::string Time::LocalFormat(const char *format) const
 {
        if (!format) return "";
 
-       const std::string *pattern = GetBestPattern(GetLocale(), format);
+       const std::string *pattern = GetBestPattern(SystemSettings::GetLocale(), format);
        if (!pattern) {
                ERR("Unable to get localized format.");
                return "";
        }
-       return FormatInternal(milliseconds_, timezone_, GetLocale(), pattern->c_str());
+       return FormatInternal(milliseconds_, timezone_, SystemSettings::GetLocale(), pattern->c_str());
 }
 
 std::string Time::Format(const char *format) const
 {
        if (!format) return "";
-       return FormatInternal(milliseconds_, timezone_, GetLocale(), format);
+       return FormatInternal(milliseconds_, timezone_, SystemSettings::GetLocale(), format);
 }
 
 std::string Time::FormatInternal(double time, const std::string &timezone,
@@ -300,40 +299,6 @@ Time Time::Now(void)
        return Time(double(handle), GetCurrentTimezone());
 }
 
-static void TimeSystemSettingsLocaleLanguageChanged(system_settings_key_e key, void *user_data)
-{
-       char **locale = static_cast<char**>(user_data);
-       free(*locale); *locale = nullptr;
-       int ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, locale);
-       if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
-               ERR("system_settings_get_value_string failed: %s", get_error_message(ret));
-       }
-}
-
-const char *Time::GetLocale()
-{
-       static const char *locale;
-
-       if (!locale) {
-               char *l;
-               int ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, TimeSystemSettingsLocaleLanguageChanged, &locale);
-               if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
-                       ERR("system_settings_set_changed_cb failed: %s", get_error_message(ret));
-               }
-               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &l);
-               if (ret != SYSTEM_SETTINGS_ERROR_NONE) {
-                       ERR("system_settings_get_value_string failed: %s", get_error_message(ret));
-                       system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE);
-                       locale = getenv("LOCALE") ? strdup(getenv("LOCALE")) : "";
-               } else {
-                       locale = l;
-               }
-               if (!locale)
-                       FAT("Unable to get current locale.");
-       }
-       return locale;
-}
-
 Time Time::Local() const
 {
        return Time(milliseconds_, GetCurrentTimezone());
@@ -419,32 +384,32 @@ static int GetCalendarField(double milliseconds, const char *zone, const char *l
 
 unsigned int Time::GetYear() const
 {
-       return GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_YEAR);
+       return GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_YEAR);
 }
 
 Time::Month Time::GetMonth() const
 {
-       return (Time::Month)GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_MONTH);
+       return (Time::Month)GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_MONTH);
 }
 
 unsigned int Time::GetDay() const
 {
-       return GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_DAY_OF_MONTH);
+       return GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_DAY_OF_MONTH);
 }
 
 unsigned int Time::GetHour() const
 {
-       return GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_HOUR_OF_DAY);
+       return GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_HOUR_OF_DAY);
 }
 
 unsigned int Time::GetMinute() const
 {
-       return GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_MINUTE);
+       return GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_MINUTE);
 }
 
 unsigned int Time::GetSecond() const
 {
-       return GetCalendarField(milliseconds_, timezone_.c_str(), GetLocale(), I18N_UCALENDAR_SECOND);
+       return GetCalendarField(milliseconds_, timezone_.c_str(), SystemSettings::GetLocale(), I18N_UCALENDAR_SECOND);
 }
 
 unsigned int Time::GetMilliSec() const
@@ -491,7 +456,7 @@ std::tm Time::GetTmStruct() const
        I18nString u_zone(timezone_);
        int32_t value;
 
-       int err = i18n_ucalendar_create(u_zone.i18n_str(), -1, GetLocale(),
+       int err = i18n_ucalendar_create(u_zone.i18n_str(), -1, SystemSettings::GetLocale(),
                        I18N_UCALENDAR_GREGORIAN, &calendar);
        if (err != I18N_ERROR_NONE) {
                ERR("i18n_ucalendar_create failed: %s", get_error_message(err));
@@ -567,40 +532,3 @@ Time Time::Truncate(double milliseconds) const
                return *this;
        return Time(std::trunc(milliseconds_ / milliseconds) * milliseconds, timezone_);
 }
-
-static void time_system_default_timeformat_changed(system_settings_key_e key, void *user_data)
-{
-       bool *prefer_24h_format = static_cast<bool*>(user_data);
-       int err = system_settings_get_value_bool(
-                       SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, prefer_24h_format);
-       if (err != SYSTEM_SETTINGS_ERROR_NONE) {
-               ERR("system_settings_get_value_string failed[%d]: %s", err, get_error_message(err));
-       } else {
-               Time::PreferedTimeFormatChanged event;
-               EventBus::FireEvent(event);
-       }
-}
-
-bool Time::Is24HourFormatPrefered()
-{
-       static bool prefer_24h_format;
-       static bool init;
-
-       if (!init) {
-               int err = system_settings_get_value_bool(
-                               SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &prefer_24h_format);
-               if (err != SYSTEM_SETTINGS_ERROR_NONE) {
-                       ERR("system_settings_get_value_string failed[%d]: %s", err, get_error_message(err));
-                       prefer_24h_format = true;
-               }
-               err = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR,
-                               time_system_default_timeformat_changed, &prefer_24h_format);
-               if (err != SYSTEM_SETTINGS_ERROR_NONE) {
-                       ERR("system_settings_set_changed_cb failed[%d]: %s", err, get_error_message(err));
-               } else {
-                       init = true;
-               }
-       }
-
-       return prefer_24h_format;
-}
index b21be85836ed0fd0143eaceb9e209ec39472e660..a8cd605acbe22ba9a0e592e2f6fec7a84c28d36e 100644 (file)
@@ -27,6 +27,7 @@
 #include "Utils/ThemeExtension.h"
 #include "Utils/Translate.h"
 #include "Utils/Accessibility.h"
+#include "Utils/SystemSettings.h"
 
 using namespace view;
 using namespace model;
@@ -176,7 +177,7 @@ static char *Time2FormattedString(const Time &time)
 {
        std::stringstream formatted_time;
 
-       if (Time::Is24HourFormatPrefered()) {
+       if (SystemSettings::Is24HourFormatPrefered()) {
                formatted_time << time.Format(Time::FORMAT_TIME_24H);
        } else {
                formatted_time << time.Format(Time::FORMAT_TIME_12H);
@@ -247,7 +248,7 @@ AlarmView::AlarmView(ui::IView &main) : label_(nullptr), popup_(nullptr)
        eext_object_event_callback_add(content_, EEXT_CALLBACK_MORE,
                         AlarmView::MoreButtonClicked, this);
 
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&AlarmView::TimeFormatChanged, this));
 }
 
index 7059d6d0d299d4ffc35f65c014932c50697a3bb0..c290ba4362bd4bb2dd42cb554e75fba89f9ee60a 100644 (file)
@@ -17,6 +17,7 @@
 #include "View/DeleteAlarmView.h"
 #include "Utils/Log.h"
 #include "Utils/Translate.h"
+#include "Utils/SystemSettings.h"
 
 #include <sstream>
 
@@ -102,7 +103,7 @@ static char *Time2FormattedString(const Time &time)
 {
        std::stringstream formatted_time;
 
-       if (time.Is24HourFormatPrefered()) {
+       if (SystemSettings::Is24HourFormatPrefered()) {
                formatted_time << time.Format(Time::FORMAT_TIME_24H);
        } else {
                formatted_time << time.Format(Time::FORMAT_TIME_12H);
@@ -117,7 +118,7 @@ static char *Time2FormattedString(const Time &time)
 DeleteAlarmView::DeleteAlarmView(view::MainView &main)
        : PageView(main), all_selected_(false)
 {
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&DeleteAlarmView::TimeFormatChanged, this));
 }
 
index 7595493b172e1fb35dacd37e4bf42b84c223ddeb..4d9458605f5dd2288b9cbd97835917dfa0382ae4 100644 (file)
@@ -22,6 +22,7 @@
 #include "Utils/Translate.h"
 #include "Utils/PopupManager.h"
 #include "Utils/Accessibility.h"
+#include "Utils/SystemSettings.h"
 
 #include <efl_extension.h>
 #include <Elementary.h>
@@ -43,7 +44,7 @@ EditAlarmView::EditAlarmView(view::MainView &main)
                        std::bind(&EditAlarmView::OnWeekFlagsPagePopped, this));
        picker_conn_ = picker_.OnPathUpdated.Connect(
                        std::bind(&EditAlarmView::RingtonePathUpdateCallback, this));
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&EditAlarmView::TimeFormatChanged, this));
 }
 
@@ -374,7 +375,7 @@ void EditAlarmView::CreateGenlistItems()
        itc->func.content_get = [](void *data, Evas_Object *o, const char *part) -> Evas_Object* {
                EditAlarmView *view = static_cast<EditAlarmView*>(data);
                Evas_Object *dt = elm_datetime_add(o);
-               elm_datetime_format_set(dt, Time::Is24HourFormatPrefered() ? "%k %M" : "%l %M %p");
+               elm_datetime_format_set(dt, SystemSettings::Is24HourFormatPrefered() ? "%k %M" : "%l %M %p");
                elm_object_style_set(dt, "time_layout"); // from tizen-theme
                evas_object_smart_callback_add(dt, "changed"
                                , EditAlarmView::DateTimeChangedCallback, view);
index 8b3a8ac48218467db10e4534bf9aee914ba9da7c..03ea43c7a102e4e3f8e26ef1f1871b643459f13b 100644 (file)
@@ -26,6 +26,7 @@
 #include "Utils/Log.h"
 #include "Utils/WorldClock.h"
 #include "Utils/ThemeExtension.h"
+#include "Utils/SystemSettings.h"
 
 using namespace view;
 using namespace utils;
@@ -150,7 +151,7 @@ char *WorldClockDeleteItemsView::TextGet(void *data, Evas_Object *obj, const cha
                Time t = Time::Now().InTimezone(ldid->location->tzpath.c_str());
 
                std::string timezone_time;
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        timezone_time = t.Format("HH:mm");
                else
                        timezone_time = t.Format("h:mm");
@@ -162,7 +163,7 @@ char *WorldClockDeleteItemsView::TextGet(void *data, Evas_Object *obj, const cha
                return strdup(time_formatted);
        }
        if (!strcmp(part, "ampm")) {
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        return NULL;
 
                char ampm_formatted[MAX_STYLE_LEN] = { 0, };
@@ -206,7 +207,7 @@ Evas_Object *WorldClockDeleteItemsView::CreatePaddingObject(Evas_Object *parent,
 WorldClockDeleteItemsView::WorldClockDeleteItemsView(view::MainView &main):
                PageView(main), all_selected_(false)
 {
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&WorldClockDeleteItemsView::TimeFormatChanged, this));
 }
 
index 7700b8a6f0c96d8d215fdc0f72d2e47f843e86a6..ac9faac4bff68af8c90c3ba5f2e0f7e8b9797e52 100644 (file)
@@ -24,6 +24,7 @@
 #include "Utils/Time.h"
 #include "Utils/Log.h"
 #include "Utils/TizenAppUtils.h"
+#include "Utils/SystemSettings.h"
 
 namespace view {
 
@@ -71,7 +72,7 @@ Elm_Genlist_Item_Class WorldClockReorderView::world_clock_reorder_items_view_itc
 WorldClockReorderView::WorldClockReorderView(view::MainView &main) :
                PageView(main)
 {
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&WorldClockReorderView::TimeFormatChanged, this));
 }
 
@@ -218,7 +219,7 @@ char* WorldClockReorderView::TextGet(void* data, Evas_Object* obj,
                Time t = Time::Now().InTimezone(lrid->location->tzpath.c_str());
 
                std::string timezone_time;
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        timezone_time = t.Format("HH:mm");
                else
                        timezone_time = t.Format("h:mm");
@@ -230,7 +231,7 @@ char* WorldClockReorderView::TextGet(void* data, Evas_Object* obj,
                return strdup(time_formatted);
        }
        if (!strcmp(part, "ampm")) {
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        return NULL;
 
                char ampm_formatted[MAX_STYLE_LEN] = { 0, };
index 54507ead1e334388b3c810ed9149b03739c4d017..ca2c338104615ab367c78b8872589d99c7f4c6e9 100644 (file)
 #include "Utils/ThemeExtension.h"
 #include "Utils/Translate.h"
 #include "Utils/Accessibility.h"
+#include "Utils/SystemSettings.h"
 
 using namespace view;
 using namespace utils;
 
-/**
- * @brief Genlist item data model
- */
-struct LocationItemData {
-               /** container view */
-               WorldClockView *wc_view;
-               /** elm_time table */
-               Evas_Object *time;
-
-               /** location pointer */
-               const model::Location *location;
-
-               /** date to be displayed */
-               char *date;
-               /** city to be displayed */
-               char *city_country;
-               /** time offset to be displayed */
-               char *gmt_offset_relative;
-               /** time offset from GMT+0 in minutes */
-               int gmt_offset;
-               /** elm_genlist item handle */
-               Elm_Object_Item *it;
-};
-
 
 /* Custom list View */
 
@@ -87,10 +64,23 @@ void WorldClockView::CreateCustomLocationsList(Evas_Object *parent)
        elm_layout_content_set(world_clock_, TIMEZONE_CUSTOM_LOCATIONS_LIST_PART, custom_locations_list_);
 }
 
+void WorldClockView::UpdateLocationItemLanguage(LocationItemData *data)
+{
+       const model::Location *location = data->location;
+       Time t = Time::Now().InTimezone(location->tzpath.c_str());
+       int local_timezone_offset = Time::GetTimezoneOffset(Time::GetCurrentTimezone().c_str());
+
+       free(data->gmt_offset_relative);
+       free(data->date);
+
+       data->gmt_offset_relative = strdup(
+                       GetTimezoneDiffDescription(local_timezone_offset, location->gmt_offset_).c_str());
+       data->date = strdup(t.Format("E d MMM").c_str());
+}
+
 void WorldClockView::AppendItemToCustomList(const model::Location *location)
 {
        LocationItemData *data = new LocationItemData;
-
        Time t = Time::Now().InTimezone(location->tzpath.c_str());
        int local_timezone_offset = Time::GetTimezoneOffset(Time::GetCurrentTimezone().c_str());
        std::stringstream ss;
@@ -162,7 +152,7 @@ char *WorldClockView::TextGet(void *data, Evas_Object *obj, const char *part)
                std::string timezone_time;
                char time_formatted[MAX_STYLE_LEN] = { 0, };
 
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        timezone_time = t.Format("HH:mm");
                else
                        timezone_time = t.Format("h:mm");
@@ -173,7 +163,7 @@ char *WorldClockView::TextGet(void *data, Evas_Object *obj, const char *part)
                return strdup(time_formatted);
        }
        if (!strcmp(part, "ampm")) {
-               if (Time::Is24HourFormatPrefered())
+               if (SystemSettings::Is24HourFormatPrefered())
                        return NULL;
 
                char ampm_formatted[MAX_STYLE_LEN] = { 0, };
@@ -286,9 +276,12 @@ WorldClockView::WorldClockView(ui::IView &main)
        map_ = new WorldClockMap(*this);
        elm_object_part_content_set(world_clock_map_, "map", map_->GetEvasObject());
 
-       time_format_change_listener_ = EventBus::AddListener<Time::PreferedTimeFormatChanged>(
+       time_format_change_listener_ = EventBus::AddListener<SystemSettings::TimeFormatChanged>(
                        std::bind(&WorldClockView::TimeFormatChanged, this));
 
+       language_change_listener_ = EventBus::AddListener<SystemSettings::LanguageChanged>(
+                       std::bind(&WorldClockView::LanguageChanged, this));
+
        elm_object_translatable_part_text_set(world_clock_, "main.locations.list:emptylist.label",
                        "IDS_CLOCK_BODY_AFTER_YOU_ADD_CITIES_THEY_WILL_BE_SHOWN_HERE");
 }
@@ -350,6 +343,34 @@ void WorldClockView::TimeFormatChanged()
        UpdateMapAndTimezoneDetails(&current_timezone_);
 }
 
+void WorldClockView::UpdateCustomList()
+{
+       unsigned count = elm_genlist_items_count(custom_locations_list_);
+       if (count == 0)
+               return;
+
+       Elm_Object_Item *item = nullptr;
+       void *data = nullptr;
+
+       for (int i = 0; i < count; ++i) {
+               item = elm_genlist_nth_item_get(custom_locations_list_, i);
+               data = elm_object_item_data_get(item);
+               if (!data) {
+                       ERR("Item data is not set");
+                       continue;
+               }
+               UpdateLocationItemLanguage(static_cast<LocationItemData *>(data));
+       }
+}
+
+void WorldClockView::LanguageChanged()
+{
+       UpdateCustomList();
+
+       elm_genlist_realized_items_update(custom_locations_list_);
+       UpdateMapAndTimezoneDetails(&current_timezone_);
+}
+
 WorldClockView::~WorldClockView()
 {
        ecore_timer_del(timer_);
@@ -648,7 +669,7 @@ void WorldClockView::UpdateTimezoneTime(int timezone_offset)
                                timezone_offset).c_str());
        std::string timezone_time;
 
-       if (Time::Is24HourFormatPrefered())
+       if (SystemSettings::Is24HourFormatPrefered())
                timezone_time = t.Format("HH:mm");
        else
                timezone_time = t.Format("h:mm");
@@ -674,7 +695,7 @@ void WorldClockView::UpdateTimezoneXMeridiem(int timezone_offset)
        char ampm_formatted[MAX_STYLE_LEN] = { 0, };
        Time t = Time::Now().InTimezone(Time::GetTimezoneNameByOffset(timezone_offset).c_str());
 
-       if (!Time::Is24HourFormatPrefered()) {
+       if (!SystemSettings::Is24HourFormatPrefered()) {
                std::string meridiem = t.Format(Time::FORMAT_TIME_AMPM);
                snprintf(ampm_formatted, sizeof(ampm_formatted),
                                TIMEZONE_DETAILS_FIRST_LINE_AMPM_STYLE("%s"), meridiem.c_str());