*/
#include <Elementary.h>
+#include <system_settings.h>
+#include <utils_i18n.h>
#include <layoutmgr.h>
+#include <inputmgr.h>
+#include <app_debug.h>
#include "define.h"
#include "layout.h"
+#include "utils.h"
+#include "menumgr.h"
+
+#define PADDING_X 26
+#define PADDING_Y 26
+
+#define CLOCK_AUTO "Auto"
+#define CLOCK_MANUAL "Manual"
+#define TIMER_OFF "Off"
+#define TIMER_ON "On"
+#define LOCALE_UNKNOWN "Unknown"
+
+struct _priv {
+ Evas_Object *base;
+ Evas_Object *ly;
+ Evas_Object *table;
+ layoutmgr *lmgr;
+ struct menumgr *menu;
+};
+
+enum {
+ MENU_CLOCK,
+ MENU_SLEEP_TIMER,
+ MENU_WAKEUP_TIMER,
+ MENU_CHANGE_PINCODE,
+ MENU_LANGUAGE,
+ MENU_SUBTITLE,
+ MENU_LOCATION,
+ MENU_RESET
+};
+
+static char *_get_status(void *data, int id);
+static char *_get_clock_mode(void *data, int id);
+static char *_get_sleep_timer(void *data, int id);
+static char *_get_language(void *data, int id);
+static char *_get_location(void *data, int id);
+static void _selected(void *data, int id);
+
+static struct menumgr_info menu_info[] = {
+ {
+ .id = MENU_CLOCK,
+ .title = "Clock",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_clock_mode,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_SLEEP_TIMER,
+ .title = "Sleep timer",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_sleep_timer,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_WAKEUP_TIMER,
+ .title = "Wake up timer",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_status,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_CHANGE_PINCODE,
+ .title = "Change Pincode",
+ .style = STYLE_NORMAL_BTN,
+ .disabled = EINA_TRUE,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_LANGUAGE,
+ .title = "Language",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_language,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_SUBTITLE,
+ .title = "Subtitile",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_status,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_LOCATION,
+ .title = "Location",
+ .style = STYLE_STATUS_BTN,
+ .disabled = EINA_TRUE,
+ .status = _get_location,
+ .selected = _selected,
+ },
+ {
+ .id = MENU_RESET,
+ .title = "Reset",
+ .style = STYLE_NORMAL_BTN,
+ .disabled = EINA_TRUE,
+ .selected = _selected,
+ },
+};
+
+static char *_get_status(void *data, int id)
+{
+ return NULL;
+}
+static char *_get_clock_mode(void *data, int id)
+{
+ return strdup(CLOCK_AUTO);
+}
+
+static char *_get_sleep_timer(void *data, int id)
+{
+ return strdup(TIMER_OFF);
+}
+
+static char *_get_language(void *data, int id)
+{
+ char *lang;
+ char name[64];
+ i18n_uchar res[64];
+ int r;
+
+ r = system_settings_get_value_string(
+ SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
+ if (r != SYSTEM_SETTINGS_ERROR_NONE) {
+ _ERR("failed to get language");
+ return strdup(LOCALE_UNKNOWN);
+ }
+
+ r = i18n_ulocale_get_display_language(lang, lang, res, sizeof(res));
+ if (r < 0) {
+ _ERR("failed to get display language: %s", get_last_result());
+ free(lang);
+ return strdup(LOCALE_UNKNOWN);
+ }
+
+ i18n_ustring_copy_au(name, res);
+
+ free(lang);
+
+ return strdup(name);
+}
+
+static char *_get_location(void *data, int id)
+{
+ char *country;
+ char *lang;
+ char name[64];
+ i18n_uchar res[64];
+ int r;
+
+ r = system_settings_get_value_string(
+ SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &lang);
+ if (r != SYSTEM_SETTINGS_ERROR_NONE) {
+ _ERR("failed to get language");
+ return strdup(LOCALE_UNKNOWN);
+ }
+
+ r = system_settings_get_value_string(
+ SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &country);
+ if (r != SYSTEM_SETTINGS_ERROR_NONE) {
+ _ERR("failed to get country");
+ free(lang);
+ return strdup(LOCALE_UNKNOWN);
+ }
+
+ r = i18n_ulocale_get_display_country(country, lang, res, sizeof(res));
+ if (r < 0) {
+ _ERR("failed to get display country: %s", get_last_result());
+ free(lang);
+ free(country);
+ return strdup(LOCALE_UNKNOWN);
+ }
+
+ i18n_ustring_copy_au(name, res);
+
+ free(lang);
+ free(country);
+
+ return strdup(name);
+}
+
+static void _selected(void *data, int id)
+{
+}
+
+static bool _add_layout_contents(struct _priv *priv)
+{
+ Evas_Object *table;
+ struct menumgr *menu;
+
+ table = utils_add_table(priv->ly, PADDING_X, PADDING_Y);
+ if (!table) {
+ _ERR("failed to add table");
+ return false;
+ }
+
+ priv->table = table;
+
+ elm_object_part_content_set(priv->ly, PART_SYSTEM, table);
+
+ menu = menumgr_create(table, menu_info, ARRAY_SIZE(menu_info), priv);
+ if (!menu) {
+ _ERR("failed to create menu manager");
+ evas_object_del(table);
+ return false;
+ }
+
+ priv->menu = menu;
+
+ return true;
+}
static bool _create(layoutmgr *lmgr, void *data)
{
- /* It will be implemented later */
+ struct _priv *priv;
+ Evas_Object *base, *ly;
+
+ if (!lmgr) {
+ _ERR("Invalid argument.");
+ return false;
+ }
+
+ base = layoutmgr_get_base(lmgr);
+ if (!base) {
+ _ERR("Get base layout failed.");
+ return false;
+ }
+
+ ly = utils_add_layout(base, GRP_LAYOUT_SYSTEM, EINA_FALSE);
+ if (!ly) {
+ _ERR("Add layout failed.");
+ return false;
+ }
+
+ priv = calloc(1, sizeof(*priv));
+ if (!priv) {
+ _ERR("Calloc failed.");
+ evas_object_del(ly);
+ return false;
+ }
+
+ priv->lmgr = lmgr;
+ priv->base = base;
+ priv->ly = ly;
+
+ if (!_add_layout_contents(priv)) {
+ _ERR("Add layout contents failed.");
+ evas_object_del(ly);
+ free(priv);
+ return false;
+ }
+
+ layoutmgr_set_layout_data(lmgr, LAYOUT_ID_SYSTEM, priv);
+
return true;
}
static void _show(void *layout_data)
{
- /* It will be implemented later */
+ struct _priv *priv;
+
+ if (!layout_data) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ priv = layout_data;
+
+ if (priv->ly) {
+ menumgr_update(priv->menu);
+
+ evas_object_show(priv->ly);
+ elm_object_part_content_set(priv->base, PART_CONTENT, priv->ly);
+ }
}
static void _hide(void *layout_data)
{
- /* It will be implemented later */
+ struct _priv *priv;
+
+ if (!layout_data) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ priv = layout_data;
+
+ if (priv->ly) {
+ evas_object_hide(priv->ly);
+ elm_object_part_content_unset(priv->base, PART_CONTENT);
+ }
}
static void _destroy(void *layout_data)
{
- /* It will be implemented later */
+ struct _priv *priv;
+
+ if (!layout_data) {
+ _ERR("Invalid argument.");
+ return;
+ }
+
+ priv = layout_data;
+
+ menumgr_destroy(priv->menu);
+
+ evas_object_del(priv->ly);
+
+ free(priv);
}
static layout_class _lclass = {