examples: Fix path to edj theme files (theme examples)
authorJean-Philippe Andre <jp.andre@samsung.com>
Mon, 8 Aug 2016 09:09:58 +0000 (18:09 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 8 Aug 2016 09:15:53 +0000 (18:15 +0900)
A bit complex but should work in most cases (installed & not)

src/examples/elementary/theme_example_01.c
src/examples/elementary/theme_example_02.c

index 61b948c..6fc7c11 100644 (file)
@@ -3,6 +3,8 @@
  */
 #include <Elementary.h>
 
+char edj_path[PATH_MAX];
+
 static void
 btn_extension_click_cb(void *data, Evas_Object *btn, void *ev)
 {
@@ -10,12 +12,12 @@ btn_extension_click_cb(void *data, Evas_Object *btn, void *ev)
 
    if (!strncmp(lbl, "Load", 4))
      {
-        elm_theme_extension_add(NULL, "./theme_example.edj");
+        elm_theme_extension_add(NULL, edj_path);
         elm_object_text_set(btn, "Unload extension");
      }
    else if (!strncmp(lbl, "Unload", 6))
      {
-        elm_theme_extension_del(NULL, "./theme_example.edj");
+        elm_theme_extension_del(NULL, edj_path);
         elm_object_text_set(btn, "Load extension");
      }
 }
@@ -41,7 +43,20 @@ elm_main(int argc, char *argv[])
 
    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
 
-   elm_theme_extension_add(NULL, "./theme_example.edj");
+#ifdef PACKAGE_DATA_DIR
+   elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
+#endif
+   if (ecore_file_exists("./theme_example.edj"))
+     {
+        strcpy(edj_path, "./theme_example.edj");
+     }
+   else
+     {
+        elm_app_info_set(elm_main, "elementary", "examples/theme_example.edj");
+        snprintf(edj_path, sizeof(edj_path), "%s/examples/theme_example.edj",
+                 elm_app_data_dir_get());
+     }
+   elm_theme_extension_add(NULL, edj_path);
 
    win = elm_win_util_standard_add("theme", "Theme example");
    elm_win_autodel_set(win, EINA_TRUE);
index 4269fb0..0dcf172 100644 (file)
@@ -3,14 +3,16 @@
  */
 #include <Elementary.h>
 
+char edj_path[PATH_MAX];
+
 static void
 _btn_clicked_cb(void *data, Evas_Object *obj, void *ev)
 {
    static int loaded = 1;
    if (loaded)
-     elm_theme_overlay_del(NULL, "./theme_example.edj");
+     elm_theme_overlay_del(NULL, edj_path);
    else
-     elm_theme_overlay_add(NULL, "./theme_example.edj");
+     elm_theme_overlay_add(NULL, edj_path);
    loaded = 1 - loaded;
 }
 
@@ -21,7 +23,20 @@ elm_main(int argc, char *argv[])
 
    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
 
-   elm_theme_overlay_add(NULL, "./theme_example.edj");
+#ifdef PACKAGE_DATA_DIR
+   elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
+#endif
+   if (ecore_file_exists("./theme_example.edj"))
+     {
+        strcpy(edj_path, "./theme_example.edj");
+     }
+   else
+     {
+        elm_app_info_set(elm_main, "elementary", "examples/theme_example.edj");
+        snprintf(edj_path, sizeof(edj_path), "%s/examples/theme_example.edj",
+                 elm_app_data_dir_get());
+     }
+   elm_theme_overlay_add(NULL, edj_path);
 
    win = elm_win_util_standard_add("theme", "Theme example");
    elm_win_autodel_set(win, EINA_TRUE);