File Manager / src / utils /

ui-utils.c

  1. /*
  2. * Copyright 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17.  
  18. #include "utils/ui-utils.h"
  19. #include "utils/model-utils.h"
  20. #include "utils/app-types.h"
  21. #include "utils/config.h"
  22. #include "utils/logger.h"
  23. #include "main-app.h"
  24.  
  25. #include <app.h>
  26.  
  27. Evas_Object *ui_utils_layout_add(Evas_Object *parent, Evas_Object_Event_Cb destroy_cb, void *cb_data)
  28. {
  29. Evas_Object *layout = elm_layout_add(parent);
  30. RETVM_IF(!layout, NULL , "Layout is NULL");
  31.  
  32. elm_layout_theme_set(layout, "layout", "application", "default");
  33. evas_object_event_callback_add(layout, EVAS_CALLBACK_FREE, destroy_cb, cb_data);
  34.  
  35. evas_object_show(layout);
  36.  
  37. return layout;
  38. }
  39.  
  40. Evas_Object *ui_utils_genlist_add(Evas_Object *parent, Evas_Object_Event_Cb destroy_cb, void *cb_data)
  41. {
  42. Evas_Object *genlist = elm_genlist_add(parent);
  43. RETVM_IF(!genlist, NULL, "Genlist is NULL");
  44.  
  45. elm_genlist_homogeneous_set(genlist, EINA_TRUE);
  46. elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
  47. evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
  48. evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
  49.  
  50. evas_object_event_callback_add(genlist, EVAS_CALLBACK_FREE, destroy_cb, cb_data);
  51.  
  52. evas_object_show(genlist);
  53.  
  54. return genlist;
  55. }
  56.  
  57. Evas_Object *ui_utils_navi_add(Evas_Object *parent, Eext_Event_Cb back_cb, void *cb_data)
  58. {
  59. RETVM_IF(!parent, NULL, "Parent is NULL");
  60.  
  61. Evas_Object *navi = elm_naviframe_add(parent);
  62. eext_object_event_callback_add(navi, EEXT_CALLBACK_BACK, back_cb, cb_data);
  63. elm_naviframe_prev_btn_auto_pushed_set(navi, EINA_FALSE);
  64.  
  65. evas_object_show(navi);
  66.  
  67. return navi;
  68. }
  69.  
  70. Evas_Object *ui_utils_navi_layout_get(app_data *app)
  71. {
  72. RETVM_IF(!app, NULL, "App object is NULL");
  73. RETVM_IF(!app->navi, NULL, "Naviframe object is NULL");
  74.  
  75. Elm_Object_Item *item = elm_naviframe_top_item_get(app->navi);
  76. RETVM_IF(!item, NULL, "Item object is NULL");
  77.  
  78. Evas_Object *navi_layout = elm_object_item_data_get(item);
  79. RETVM_IF(!navi_layout, NULL, "Navi layout object is NULL");
  80.  
  81. return navi_layout;
  82. }
  83.  
  84. const char *ui_utils_title_get(const char* curr_path)
  85. {
  86. const char *title = NULL;
  87. const storage_type storage = model_utils_get_storage_type(curr_path);
  88. switch (storage) {
  89. case STORAGE_TYPE_PHONE:
  90. title = FM_PHONE_LABEL;
  91. break;
  92. case STORAGE_TYPE_MMC:
  93. title = FM_MEMORY_LABEL;
  94. break;
  95. default:
  96. ERR("Failed to get title");
  97. break;
  98. }
  99.  
  100. return title;
  101. }
  102.  
  103. static const char *_ui_utils_get_res_path()
  104. {
  105. static char res_folder_path[PATH_MAX] = {'\0'};
  106. if (res_folder_path[0] == '\0') {
  107. char *res_path_buff = app_get_resource_path();
  108. strncpy(res_folder_path, res_path_buff, PATH_MAX-1);
  109. free(res_path_buff);
  110. }
  111. return res_folder_path;
  112. }
  113.  
  114. const char *ui_utils_get_resource(const char *res_name)
  115. {
  116. RETVM_IF(!res_name, NULL, "res_name is NULL");
  117.  
  118. static char res_path[PATH_MAX] = {'\0'};
  119. snprintf(res_path, PATH_MAX, "%s%s", _ui_utils_get_res_path(), res_name);
  120. return res_path;
  121. }