-/*
- * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-
-#include <Evas.h>
-#include <Elementary.h>
-#include <Eina.h>
-#include <E_DBus.h>
-
-#include <app.h>
-
-#include "sys_lock.h"
-#include "log.h"
-
-/* This application, password and UI are just examples for lazy-mount process */
-
-#define STR_PASSWORD "0430"
-#define BUF_SIZE 10
-static bool isUnlocked;
-static char buf[BUF_SIZE];
-static int now;
-
-void _input_password(Evas_Object *ly, const char *txt)
-{
- char tmp[BUF_SIZE] = { 0, };
-
- if (now >= 4 || isUnlocked)
- return;
-
- snprintf(tmp, BUF_SIZE, "%s%s", buf, txt);
- strncpy(buf,tmp,BUF_SIZE);
- now++;
-
- if (!strcmp(STR_PASSWORD, buf)) {
- _dbus_send_sys_lock_unlock_signal();
- isUnlocked = true;
- _update_password_view(ly, 5);
- } else {
- _update_password_view(ly, now);
- }
-}
-
-void _clear_password(Evas_Object *ly)
-{
- if (now <= 0)
- return;
-
- now--;
- buf[now] = '\0';
-
- _update_password_view(ly, now);
-}
-
-void _clear_all_password(Evas_Object *ly)
-{
- memset(buf, 0, BUF_SIZE);
- now = 0;
-
- _update_password_view(ly, now);
-}
-
-void _update_password_view(Evas_Object *ly, int num)
-{
- if (num == 0)
- elm_object_part_text_set(ly, "sw.entry", "_ _ _ _");
- else if (num == 1)
- elm_object_part_text_set(ly, "sw.entry", "* _ _ _");
- else if (num == 2)
- elm_object_part_text_set(ly, "sw.entry", "* * _ _");
- else if (num == 3)
- elm_object_part_text_set(ly, "sw.entry", "* * * _");
- else if (num == 4)
- elm_object_part_text_set(ly, "sw.entry", "* * * *");
- else if (num == 5)
- elm_object_part_text_set(ly, "sw.entry", "= Password OK! =");
-}
-
-void _dbus_send_sys_lock_unlock_signal(void)
-{
- int ret = 0;
- E_DBus_Connection *conn;
- DBusMessage *msg;
-
- conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
- if (conn == NULL) {
- ERR("e_dbus_bus_get error");
- }
-
- msg = dbus_message_new_signal(SYS_LOCK_OBJECT_PATH, SYS_LOCK_INTERFACE_UNLOCK, SYS_LOCK_MEMBER_UNLOCK);
-
- dbus_message_append_args(msg, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID);
-
- e_dbus_message_send(conn, msg, NULL, -1, NULL);
- dbus_message_unref(msg);
-
- DBG("%s-%s", SYS_LOCK_INTERFACE_UNLOCK, SYS_LOCK_MEMBER_UNLOCK);
-}
-
-int _dbus_receive_lazy_mount_status(void (*changed_cb)(void *data, DBusMessage *msg), void *data)
-{
- E_DBus_Connection *conn;
- E_DBus_Signal_Handler *handler;
-
- conn = e_dbus_bus_get(DBUS_BUS_SYSTEM);
- if (conn == NULL) {
- ERR("e_dbus_bus_get error");
- return -1;
- }
-
- handler = e_dbus_signal_handler_add(conn, NULL, SYS_LOCK_OBJECT_PATH,
- SYS_LOCK_INTERFACE_TERMINATE, SYS_LOCK_MEMBER_TERMINATE,
- changed_cb, data);
- if (handler == NULL) {
- ERR("e_dbus_signal_handler_add error");
- return -1;
- }
-
- return 0;
-}
-
-static void _lazy_mount_status_changed_cb(void *data, DBusMessage *msg)
-{
- int is_unlock = 0;
-
- DBG("sys-lock signal is received %s : %s", dbus_message_get_interface(msg), dbus_message_get_member(msg));
-
- is_unlock = dbus_message_is_signal(msg, SYS_LOCK_INTERFACE_TERMINATE, SYS_LOCK_MEMBER_TERMINATE);
-
- if (is_unlock) {
- ui_app_exit();
- }
-}
-
-char *_get_resource_full_path(const char *file_path)
-{
- char *ret = NULL;
- char full_path[PATH_MAX] = { 0, };
- char *res_path = app_get_resource_path();
-
- if (res_path) {
- snprintf(full_path, sizeof(full_path) - 1, "%s%s", res_path, file_path);
-
- ret = strdup(full_path);
- free(res_path);
- }
-
- return ret;
-}
-
-Evas_Object *_window_create(void)
-{
- Evas_Object *win = elm_win_add(NULL, "FOTALOCK", ELM_WIN_BASIC);
- char *full_path = NULL;
-
- if (!win) return NULL;
-
- elm_win_borderless_set(win, EINA_TRUE);
- elm_win_autodel_set(win, EINA_TRUE);
- elm_win_fullscreen_set(win, EINA_TRUE);
-
- Evas_Object *ly = elm_layout_add(win);
-
- full_path = _get_resource_full_path("edje/main.edj");
- if (!elm_layout_file_set(ly, full_path, "lockscreen-bg"))
- ERR("elm_layout_file_set failed %s", full_path);
- free(full_path);
-
- evas_object_show(ly);
- elm_win_resize_object_add(win, ly);
-
- Evas_Object *bg = elm_image_add(win);
- elm_image_aspect_fixed_set(bg, EINA_TRUE);
- elm_image_fill_outside_set(bg, EINA_TRUE);
- evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
- full_path = _get_resource_full_path("images/Home_default.jpg");
- if (!elm_image_file_set(bg, full_path, NULL)) {
- ERR("elm_image_file_set failed %s", full_path);
- }
- free(full_path);
-
- evas_object_show(bg);
- elm_object_part_content_set(ly, "sw.bg", bg);
-
- evas_object_show(win);
-
- return win;
-}
-
-static Evas_Object *_conformant_create(Evas_Object *win)
-{
- Evas_Object *conformant = elm_conformant_add(win);
- evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
- elm_win_resize_object_add(win, conformant);
-
- elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
-
- evas_object_show(conformant);
- elm_win_conformant_set(win, EINA_TRUE);
-
- return conformant;
-}
-
-static void
-_pin_button_setup(Evas_Object *ly, int row, int col, const char *text, const char *subtext, Edje_Signal_Cb cb)
-{
- Evas_Object *edje = elm_layout_edje_get(ly);
- Evas_Object *child = edje_object_part_table_child_get(edje, "pinpad", col, row);
- edje_object_part_text_set(child, "text.number", text);
- edje_object_part_text_set(child, "text.letters", subtext);
- if (cb) edje_object_signal_callback_add(child, "button,clicked", "pinpaditem", cb, ly);
-}
-
-static void
-_cancel_button_clicked(void *data, Evas_Object *obj, void *event_info)
-{
- if (isUnlocked) return; //Disable key input after unlocked.
-
- _clear_all_password(data);
-}
-
-static void
-_pin_button_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
-{
- if (isUnlocked) return; //Disable key input after unlocked.
-
- const char *txt = edje_object_part_text_get(obj, "text.number");
- DBG("_pin_button_clicked!! [%s]", txt);
-
- _input_password(data, txt);
-}
-
-static void
-_clear_button_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
-{
- if (isUnlocked) return; //Disable key input after unlocked.
-
- _clear_password(data);
-}
-
-static Evas_Object *_view_create(Evas_Object *win)
-{
- char *full_path = NULL;
- Evas_Object *layout = elm_layout_add(win);
-
- full_path = _get_resource_full_path("edje/main.edj");
- if (!elm_layout_file_set(layout, full_path, "lock-simple-password")) {
- FAT("Failed to set edje file for main view.");
- return NULL;
- }
- free(full_path);
-
- Evas_Object *btn = elm_button_add(layout);
- if (!elm_object_style_set(btn, "panel"))
- ERR("elm_object_style_set failed");
- elm_object_text_set(btn, _("CANCEL"));
- evas_object_smart_callback_add(btn, "clicked", _cancel_button_clicked, layout);
-
- elm_object_part_content_set(layout, "sw.cancel", btn);
- evas_object_show(btn);
- evas_object_show(layout);
-
- // Setup PIN pad
- _pin_button_setup(layout, 1, 1, "1", NULL, _pin_button_clicked);
- _pin_button_setup(layout, 1, 2, "2", "ABC" , _pin_button_clicked);
- _pin_button_setup(layout, 1, 3, "3", "DEF" , _pin_button_clicked);
- _pin_button_setup(layout, 2, 1, "4", "GHI" , _pin_button_clicked);
- _pin_button_setup(layout, 2, 2, "5", "JKL" , _pin_button_clicked);
- _pin_button_setup(layout, 2, 3, "6", "MNO" , _pin_button_clicked);
- _pin_button_setup(layout, 3, 1, "7", "PQRS" , _pin_button_clicked);
- _pin_button_setup(layout, 3, 2, "8", "TUV" , _pin_button_clicked);
- _pin_button_setup(layout, 3, 3, "9", "WXYZ" , _pin_button_clicked);
- _pin_button_setup(layout, 4, 3, NULL, NULL, _clear_button_clicked);
- _pin_button_setup(layout, 4, 2, "0", NULL , _pin_button_clicked);
- _pin_button_setup(layout, 4, 1, NULL, NULL , NULL);
-
- elm_object_signal_emit(layout, "layout,pinpad,show", "lockscreen");
-
- return layout;
-}
-
-static bool _init(void)
-{
- DBG("_init");
-
- Evas_Object *win;
- Evas_Object *conformant;
- Evas_Object *view;
-
- win = _window_create();
- if (!win) {
- FAT("_window_create failed.");
- return false;
- }
-
- conformant = _conformant_create(win);
- if (!conformant) {
- FAT("_conformant_create failed.");
- return false;
- }
-
- view = _view_create(win);
- if (!view) {
- FAT("_view_create failed.");
- return false;
- }
-
- elm_object_part_content_set(conformant, NULL, view);
-
- e_dbus_init();
- _dbus_receive_lazy_mount_status(_lazy_mount_status_changed_cb, NULL);
-
- return true;
-}
-
-
-bool _create_app(void *data)
-{
- DBG("Syslock launch request.");
- elm_config_scale_set(2.6);
-
- DBG("base scale : %f", elm_app_base_scale_get());
- DBG("edje scale : %f", edje_scale_get());
-
- return _init();
-}
-
-void _terminate_app(void *data)
-{
- DBG("Syslock terminated request.");
-}
-
-void _resume_app(void *data)
-{
-}
-
-void _pause_app(void *data)
-{
-}
-
-EAPI int main(int argc, char *argv[])
-{
- int ret = 0;
-
- ui_app_lifecycle_callback_s lifecycle_callback = {0,};
-
- lifecycle_callback.create = _create_app;
- lifecycle_callback.terminate = _terminate_app;
- lifecycle_callback.resume = _resume_app;
- lifecycle_callback.pause = _pause_app;
-
- ret = ui_app_main(argc, argv, &lifecycle_callback, NULL);
- if (ret != APP_ERROR_NONE) {
- ERR("ui_app_main failed: %s", get_error_message(ret));
- }
-
- return ret;
-}