summaryrefslogtreecommitdiff
path: root/src/view/dialog_popup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/dialog_popup.c')
-rwxr-xr-xsrc/view/dialog_popup.c405
1 files changed, 405 insertions, 0 deletions
diff --git a/src/view/dialog_popup.c b/src/view/dialog_popup.c
new file mode 100755
index 0000000..161749e
--- /dev/null
+++ b/src/view/dialog_popup.c
@@ -0,0 +1,405 @@
+/*
+ * Copyright (c) 2016 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 <Elementary.h>
+#include <viewmgr.h>
+#include <inputmgr.h>
+#include <layoutmgr.h>
+#include <app_debug.h>
+
+#include "define.h"
+#include "view.h"
+#include "data.h"
+#include "util/utils.h"
+#include "util/file-util.h"
+#include "util/fs-error.h"
+#include "view/select_folder_view.h"
+#include "view/dialog_popup.h"
+#include "view/submenu_view.h"
+
+#define STYLE_TARGET_BTN "target_btn"
+
+static void _key_up_cb(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Up *ev);
+static input_handler popup_handler = {
+ .key_up = _key_up_cb
+};
+
+static void _key_up_cb(int id, void *data, Evas *e, Evas_Object *obj,
+ Evas_Event_Key_Up *ev)
+{
+ if (!data)
+ return;
+
+ struct _priv *priv;
+ priv = (struct _priv *)data;
+
+ if (!strcmp(ev->keyname, KEY_BACK) ||
+ !strcmp(ev->keyname, KEY_ESC)) {
+ inputmgr_remove_callback(priv->popup_win, &popup_handler);
+ evas_object_del(priv->popup_win);
+
+ if (priv->popup_info)
+ free(priv->popup_info);
+ }
+}
+static void _item_focus_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (data == NULL)
+ return;
+
+ char *signal = NULL;
+ signal = (char *)data;
+
+ if (!strcmp(signal, "item,focused"))
+ elm_object_item_signal_emit(event_info, "mouse,in", "elm");
+ else if (!strcmp(signal, "item,unfocused"))
+ elm_object_item_signal_emit(event_info, "mouse,out", "elm");
+
+ return;
+}
+
+static void _rename_file(struct _priv *priv)
+{
+ if (priv == NULL) {
+ _ERR("priv is null. failed to rename file");
+ return;
+ }
+
+ char *src = NULL, *dst = NULL, *dst_f = NULL, *ext = NULL;
+
+ src = utils_get_combined_string(priv->selected_parent_path, priv->selected_folder, NULL);
+ dst = utils_get_combined_string(priv->selected_parent_path, priv->new_folder_name, NULL);
+
+ mf_file_attr_get_file_ext(src, &ext);
+
+ if (strcmp(src, ext))
+ dst_f = utils_get_combined_string(dst, ext, NULL);
+
+ if (mf_fs_oper_rename_file(src, dst_f) != MYFILE_ERR_NONE) {
+ _ERR("error is occured. failed to rename file");
+ goto out;
+ }
+
+out:
+ SAFE_FREE_CHAR(src);
+ SAFE_FREE_CHAR(dst);
+ SAFE_FREE_CHAR(dst_f);
+ SAFE_FREE_CHAR(ext);
+
+ return;
+}
+
+static void _down_btn1_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (data == NULL) {
+ _ERR("data is null. failed select popup menu");
+ return;
+ }
+
+ struct _priv *priv;
+ priv = (struct _priv *)data;
+
+ if (priv->popup_info == NULL)
+ return;
+
+ if (priv->popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_INPUT_NAME) {
+ const char *entry_content = NULL;
+ entry_content = elm_entry_entry_get(priv->popup_info->entry);
+
+ if (entry_content == NULL)
+ _ERR("entry is null");
+ else {
+ priv->new_folder_name = strdup(entry_content);
+ priv->after_input_folder_name = 1;
+ }
+
+ if (priv->submenu_index == SUBMENU_RENAME) {
+ _rename_file(priv);
+ goto out;
+ }
+ } else if (priv->popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_CONFIGURATION) {
+ Evas_Object *check = elm_object_part_content_get(priv->popup_layout, "part_content_swallow");
+ Eina_Bool state = elm_check_state_get(check);
+
+ if (state == EINA_TRUE)
+ mf_util_set_hidden_state(FILE_HIDDEN_SHOW);
+ else
+ mf_util_set_hidden_state(FILE_HIDDEN_HIDE);
+ } else if (priv->popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_NOTIFY_NO_CLOSE)
+ goto out_2;
+ else {
+ if (priv->submenu_index == SUBMENU_DELETE) {
+ char *full_path = NULL;
+
+ full_path = utils_get_combined_string(priv->selected_parent_path, priv->selected_folder, NULL);
+
+ if (mf_remove(full_path))
+ _DBG("file is deleted");
+ else {
+ dialog_popup_info_t *info = calloc(1, sizeof(dialog_popup_info_t));
+
+ info->dialog_popup_type = DIALOG_POPUP_TYPE_NOTIFY;
+ info->content = "Failed to delete file.";
+ info->button_1_text = "OK";
+ info->data = priv;
+
+ dialog_popup_create(info);
+ _ERR("Failed to delete file.");
+ }
+ SAFE_FREE_CHAR(full_path);
+ }
+ }
+
+out:
+ viewmgr_update_view(VIEW_BASE, UPDATE_FILE, priv);
+
+out_2:
+ if (priv->popup_info)
+ free(priv->popup_info);
+
+ evas_object_del(priv->popup_win);
+ evas_object_del(priv->popup_layout);
+
+ return;
+}
+
+static void _down_btn2_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ if (!data)
+ return;
+
+ struct _priv *priv;
+ priv = (struct _priv *)data;
+
+ evas_object_del(priv->popup_win);
+
+ if (priv->submenu_index >= SUBMENU_RENAME && priv->submenu_index <= SUBMENU_SETTING)
+ viewmgr_update_view(VIEW_BASE, UPDATE_FILE, priv);
+
+ if (priv->popup_info)
+ free(priv->popup_info);
+}
+
+Evas_Object *dialog_popup_create(dialog_popup_info_t *dialog_popup_info)
+{
+ Evas_Object *dialog_popup = NULL;
+ Evas_Object *window_layout = NULL;
+ Evas_Object *button_1 = NULL, *button_2 = NULL;
+ Evas_Object *content_label = NULL;
+ Evas_Object *content_check = NULL;
+ Evas_Object *content_entry = NULL;
+ Evas *e = NULL;
+ Ecore_Evas *ee = NULL;
+ Eina_Bool result = EINA_FALSE;
+
+ char *content = NULL;
+ int screen_x = 0, screen_y = 0, screen_w = 0, screen_h = 0;
+
+ if (dialog_popup_info == NULL) {
+ _ERR("dialog_popup_info is null");
+ goto out;
+ }
+
+ if (dialog_popup_info->data == NULL) {
+ _ERR("dialog_popup_info->data is null");
+ goto out;
+ }
+
+ struct _priv *priv;
+ priv = (struct _priv *)dialog_popup_info->data;
+
+ /* Creating a Notification Window */
+ dialog_popup = elm_win_add(NULL, "dialog_popup", ELM_WIN_BASIC);
+
+ if (dialog_popup == NULL) {
+ _ERR("elm_win_add failed");
+ goto out;
+ }
+
+ e = evas_object_evas_get(dialog_popup);
+ if (!e) {
+ _ERR("evas_object_evas_get failed");
+ evas_object_del(dialog_popup);
+ dialog_popup = NULL;
+ goto out;
+ }
+
+ ee = ecore_evas_ecore_evas_get(e);
+ if (!ee) {
+ _ERR("ecore_evas_ecore_evas_get failed");
+ evas_object_del(dialog_popup);
+ dialog_popup = NULL;
+ goto out;
+ }
+
+ priv->popup_win = dialog_popup;
+
+ elm_win_alpha_set(dialog_popup, EINA_TRUE);
+ elm_win_borderless_set(dialog_popup, EINA_TRUE);
+ elm_win_autodel_set(dialog_popup, EINA_TRUE);
+
+ elm_win_screen_size_get(dialog_popup, &screen_x, &screen_y, &screen_w, &screen_h);
+ evas_object_resize(dialog_popup, screen_w, screen_h);
+
+ /* Layout */
+ window_layout = elm_layout_add(dialog_popup);
+ if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_YES_OR_CANCEL)
+ result = elm_layout_file_set(window_layout, EDJEFILE, GRP_DIALOG_POPUP_NO_TITLE);
+ else if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_NOTIFY ||
+ dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_NOTIFY_NO_CLOSE)
+ result = elm_layout_file_set(window_layout, EDJEFILE, GRP_DIALOG_POPUP_NO_TITLE_ONE_BTN);
+ else if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_CONFIGURATION)
+ result = elm_layout_file_set(window_layout, EDJEFILE, GRP_DIALOG_POPUP_SETTING);
+ else
+ result = elm_layout_file_set(window_layout, EDJEFILE, GRP_DIALOG_POPUP);
+
+ _DBG("Layout elm_layout_file_set for [%s] returns [%d]", EDJEFILE, result);
+ evas_object_resize(window_layout, screen_w, screen_h);
+ evas_object_show(window_layout);
+
+ priv->popup_layout = window_layout;
+
+ if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_INPUT_NAME) {
+ content_entry = elm_entry_add(window_layout);
+
+ if (dialog_popup_info->title)
+ elm_object_part_text_set(window_layout, "part_title_label", dialog_popup_info->title);
+
+ if (content_entry == NULL) {
+ _ERR("elm_entry_add failed");
+ goto out;
+ }
+
+ elm_object_part_content_set(window_layout, "part_content_swallow", content_entry);
+ elm_entry_single_line_set(content_entry, EINA_TRUE);
+ elm_entry_editable_set(content_entry, EINA_TRUE);
+
+ if (dialog_popup_info->content)
+ elm_object_part_text_set(content_entry, "guide", dialog_popup_info->content);
+
+ dialog_popup_info->entry = content_entry;
+ evas_object_show(content_entry);
+ } else if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_CONFIGURATION) {
+ if (dialog_popup_info->title)
+ elm_object_part_text_set(window_layout, "part_title_label", dialog_popup_info->title);
+
+ content_check = elm_check_add(window_layout);
+ if (content_check == NULL) {
+ _ERR("elm_check_add failed");
+ goto out;
+ }
+
+ int hidden_value;
+ mf_util_get_hidden_state(&hidden_value);
+
+ if (hidden_value == FILE_HIDDEN_SHOW)
+ elm_check_state_set(content_check, EINA_TRUE);
+ else
+ elm_check_state_set(content_check, EINA_FALSE);
+
+ if (dialog_popup_info->content)
+ elm_object_part_text_set(window_layout, "part_content_text", dialog_popup_info->content);
+ else
+ elm_object_part_text_set(window_layout, "part_content_text", " Show hidden files");
+
+ elm_object_part_content_set(window_layout, "part_content_swallow", content_check);
+ evas_object_show(content_check);
+
+ evas_object_smart_callback_add(content_check, "item,focused", _item_focus_cb, "item,focused");
+ evas_object_smart_callback_add(content_check, "item,unfocused", _item_focus_cb, "item,unfocused");
+
+ elm_object_focus_next_object_set(button_1, content_check, ELM_FOCUS_UP);
+ elm_object_focus_next_object_set(content_check, button_1, ELM_FOCUS_DOWN);
+ elm_object_focus_next_object_set(button_2, content_check, ELM_FOCUS_UP);
+
+ } else if (dialog_popup_info->dialog_popup_type == DIALOG_POPUP_TYPE_YES_OR_CANCEL) {
+ if (dialog_popup_info->content)
+ elm_object_part_text_set(window_layout, "part_content_swallow", dialog_popup_info->content);
+ else
+ elm_object_part_text_set(window_layout, "part_content_swallow", "Delete?");
+ } else {
+ int content_len = 0;
+ int buffer_size = 0;
+ const char *start_tag = "<font=BreezeSans:style=Light color=#686868 align=left left_margin=20 font_size=28>";
+ const char *end_tag = "</font>";
+
+ content_label = elm_label_add(window_layout);
+
+ if (content_label == NULL) {
+ _ERR("elm_label_add failed");
+ goto out;
+ }
+
+ if (dialog_popup_info->content) {
+ content_len = strlen(dialog_popup_info->content);
+ buffer_size = strlen(start_tag) + content_len + strlen(end_tag);
+ content = (char*)calloc(buffer_size + 1, sizeof(char));
+ snprintf(content, buffer_size+1, "%s%s%s", start_tag, dialog_popup_info->content, end_tag);
+ elm_object_text_set(content_label, content);
+ }
+ elm_object_part_content_set(window_layout, "part_content_swallow", content_label);
+ elm_object_scale_set(content_label, 1/edje_scale_get());
+ evas_object_show(content_label);
+ }
+
+ button_1 = elm_button_add(window_layout);
+ elm_object_focus_allow_set(button_1, EINA_TRUE);
+ elm_object_part_content_set(window_layout, "part_button_1", button_1);
+ elm_object_style_set(button_1, STYLE_TARGET_BTN);
+ if (dialog_popup_info->button_1_text)
+ elm_object_part_text_set(button_1, "part_popup_btn_text", dialog_popup_info->button_1_text);
+ else
+ elm_object_part_text_set(button_1, "part_popup_btn_text", "OK");
+
+ evas_object_show(button_1);
+ evas_object_smart_callback_add(button_1, "clicked", _down_btn1_cb, priv);
+
+ if (dialog_popup_info->dialog_popup_type != DIALOG_POPUP_TYPE_NOTIFY) {
+ button_2 = elm_button_add(window_layout);
+ elm_object_focus_allow_set(button_2, EINA_TRUE);
+ elm_object_part_content_set(window_layout, "part_button_2", button_2);
+ elm_object_style_set(button_2, STYLE_TARGET_BTN);
+ if (dialog_popup_info->button_2_text)
+ elm_object_part_text_set(button_2, "part_popup_btn_text", dialog_popup_info->button_2_text);
+ else
+ elm_object_part_text_set(button_2, "part_popup_btn_text", "Cancel");
+
+ evas_object_show(button_2);
+ evas_object_smart_callback_add(button_2, "clicked", _down_btn2_cb, priv);
+
+ evas_object_smart_callback_add(button_1, "item,focused", _item_focus_cb, "item,focused");
+ evas_object_smart_callback_add(button_1, "item,unfocused", _item_focus_cb, "item,unfocused");
+ evas_object_smart_callback_add(button_2, "item,focused", _item_focus_cb, "item,focused");
+ evas_object_smart_callback_add(button_2, "item,unfocused", _item_focus_cb, "item,unfocused");
+
+ elm_object_focus_next_object_set(button_1, button_2, ELM_FOCUS_RIGHT);
+ elm_object_focus_next_object_set(button_2, button_1, ELM_FOCUS_LEFT);
+ }
+
+ evas_object_smart_callback_add(content_entry, "activated", _down_btn1_cb, priv);
+ priv->popup_info = dialog_popup_info;
+
+ inputmgr_add_callback(dialog_popup, 0, &popup_handler, priv);
+
+ evas_object_show(dialog_popup);
+ elm_win_activate(dialog_popup);
+
+out:
+ SAFE_FREE_CHAR(content);
+
+ return dialog_popup;
+}