SystemSettings: add FirstDayOfWeek attribute 20/141020/3
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 27 Jul 2017 13:58:30 +0000 (15:58 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Fri, 28 Jul 2017 08:15:49 +0000 (08:15 +0000)
FirstDayOfWeek will be used to implement sorting of week flags
on alarm list page and week flags edition page.

Change-Id: I2f263d60ef537f844d22677723396b648cb42ec3

clock/inc/Model/WeekFlags.h
clock/inc/Utils/SystemSettings.h
clock/src/Utils/SystemSettings.cpp

index 522606832585745a6abd8bbf3a483a14299013fb..770424984bae869a295e8b7b15f8e26d6516a2e5 100644 (file)
@@ -83,7 +83,6 @@ namespace model {
                         */
                        bool IsOn(WeekDay day);
 
-
                        /**
                         * @brief Check if flag is set for any of given day flag.
                         * @param[in] day to check.
@@ -111,6 +110,7 @@ namespace model {
                         * @param[in] a WeekFlags reference.
                         */
                        inline bool operator==(const WeekFlags &a) const { return a.raw_flags == raw_flags; }
+
                private:
                        unsigned int raw_flags;
        };
index 9ce11519f18c779c1d41360c31ed314ed5cf85ef..5ce6fcee1ea5d1833ab27b0eed0bb08b7a31c9db 100644 (file)
@@ -21,6 +21,7 @@
 #include <system_settings.h>
 
 #include "Utils/EventBus.h"
+#include "Model/WeekFlags.h"
 
 namespace utils {
 
@@ -70,6 +71,11 @@ public:
         */
        static void Unregister();
 
+       /**
+        * @brief Gets first day of the week for current calendar.
+        */
+       static model::WeekDay GetFirstDayOfWeek();
+
        SystemSettings() = delete;
        SystemSettings(const SystemSettings &) = delete;
        SystemSettings &operator=(const SystemSettings &) = delete;
index 4c1f6ff835b13393e50321ccead8d30b921a4ad7..5a29af123b50aa1874915c1757928853f7f0b5fb 100644 (file)
@@ -14,6 +14,8 @@
 * limitations under the License.
 */
 
+#include <utils_i18n.h>
+
 #include "Utils/SystemSettings.h"
 #include "Utils/Log.h"
 
@@ -111,4 +113,54 @@ bool SystemSettings::Is24HourFormatPrefered()
        return is_24hour_format_prefered_;
 }
 
+static model::WeekDay ucalendar_weekday_to_clock_weekday(int32_t i18n_weekday)
+{
+       switch (i18n_weekday)
+       {
+               case I18N_UCALENDAR_SUNDAY:
+                       return model::WeekDay::SUNDAY;
+               case I18N_UCALENDAR_MONDAY:
+                       return model::WeekDay::MONDAY;
+               case I18N_UCALENDAR_TUESDAY:
+                       return model::WeekDay::TUESDAY;
+               case I18N_UCALENDAR_WEDNESDAY:
+                       return model::WeekDay::WEDNESDAY;
+               case I18N_UCALENDAR_THURSDAY:
+                       return model::WeekDay::THURSDAY;
+               case I18N_UCALENDAR_FRIDAY:
+                       return model::WeekDay::FRIDAY;
+               case I18N_UCALENDAR_SATURDAY:
+                       return model::WeekDay::SATURDAY;
+               default:
+                       FAT("Invalid I18N weekday value: %d", i18n_weekday);
+                       return model::WeekDay::MONDAY;
+       }
+}
+
+model::WeekDay SystemSettings::GetFirstDayOfWeek()
+{
+       i18n_ucalendar_h calendar;
+       int err;
+       int32_t weekday;
+
+       err = i18n_ucalendar_create(0, -1, SystemSettings::GetLocale(),
+                       I18N_UCALENDAR_DEFAULT, &calendar);
+       if (err != I18N_ERROR_NONE)
+       {
+               ERR("i18n_ucalendar_create failed: %s", get_error_message(err));
+               return model::WeekDay::MONDAY;
+       }
+
+       err = i18n_ucalendar_get_attribute(calendar, I18N_UCALENDAR_FIRST_DAY_OF_WEEK, &weekday);
+       if (err != I18N_ERROR_NONE)
+       {
+               ERR("i18n_ucalendar_get_attribute failed: %s", get_error_message(err));
+               i18n_ucalendar_destroy(calendar);
+               return model::WeekDay::MONDAY;
+       }
+
+       i18n_ucalendar_destroy(calendar);
+       return ucalendar_weekday_to_clock_weekday(weekday);
+}
+
 } //namespace utils