forked from enlightenment/terminology
options_elm: launch elementary_config or terminology.elementaryConfig
Lookup into $PATH to know which one is available. Also use ecore_exe_run() instead of ecore_exe_pipe_run()
This commit is contained in:
parent
a5d0c94071
commit
dbc618ed0b
|
@ -3,7 +3,9 @@
|
|||
#include <Elementary.h>
|
||||
#include "options.h"
|
||||
#include "options_elm.h"
|
||||
#include "utils.h"
|
||||
|
||||
static char *_elementary_config = NULL;
|
||||
static void
|
||||
launch_elm_config(void *_data EINA_UNUSED,
|
||||
Evas_Object *_obj EINA_UNUSED,
|
||||
|
@ -11,7 +13,7 @@ launch_elm_config(void *_data EINA_UNUSED,
|
|||
{
|
||||
Ecore_Exe *exe;
|
||||
|
||||
exe = ecore_exe_pipe_run("elementary_config", ECORE_EXE_NONE, NULL);
|
||||
exe = ecore_exe_run(_elementary_config, NULL);
|
||||
ecore_exe_free(exe);
|
||||
}
|
||||
|
||||
|
@ -41,12 +43,66 @@ _scale_change(void *data EINA_UNUSED,
|
|||
elm_config_all_flush();
|
||||
}
|
||||
|
||||
static void
|
||||
_find_binary(void)
|
||||
{
|
||||
char *path_env = getenv("PATH");
|
||||
char *names[] = { "elementary_config", "terminology.elementaryConfig"};
|
||||
int i, n_names = sizeof(names) / sizeof(names[0]);
|
||||
|
||||
if (!path_env)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < n_names; i++)
|
||||
{
|
||||
char *name = names[i];
|
||||
char *start = path_env;
|
||||
char *end = strchrnul(start, ':');
|
||||
while (*start)
|
||||
{
|
||||
if (end > start)
|
||||
{
|
||||
struct stat st;
|
||||
int res;
|
||||
const char *lookup_path;
|
||||
if (*end == '/')
|
||||
lookup_path = eina_stringshare_printf("%.*s%s",
|
||||
(int)(end - start),
|
||||
start,
|
||||
name);
|
||||
else
|
||||
lookup_path = eina_stringshare_printf("%.*s/%s",
|
||||
(int)(end - start),
|
||||
start,
|
||||
name);
|
||||
res = stat(lookup_path, &st);
|
||||
eina_stringshare_del(lookup_path);
|
||||
if (res == 0 && S_ISREG(st.st_mode) && (S_IXUSR & st.st_mode))
|
||||
{
|
||||
free(_elementary_config);
|
||||
_elementary_config = strdup(name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!*end)
|
||||
break;
|
||||
start = end + 1;
|
||||
end = strchrnul(start, ':');
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
_elementary_config = "elementary_config";
|
||||
}
|
||||
|
||||
void
|
||||
options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
|
||||
{
|
||||
Evas_Object *o, *fr, *bx, *bt, *en, *lbl, *sl, *sp;
|
||||
const char *txt;
|
||||
|
||||
_find_binary();
|
||||
|
||||
fr = o = elm_frame_add(opbox);
|
||||
evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
|
@ -62,8 +118,11 @@ options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
|
|||
elm_entry_context_menu_disabled_set(en, EINA_TRUE);
|
||||
elm_entry_editable_set(en, EINA_FALSE);
|
||||
elm_entry_line_wrap_set(en, ELM_WRAP_MIXED);
|
||||
elm_object_text_set(en, _("<em>Terminology</em> uses the <hilight>elementary</hilight> toolkit.<br>"
|
||||
"The toolkit configuration settings can be accessed by running <keyword>elementary_config</keyword>."));
|
||||
txt = eina_stringshare_printf(
|
||||
_("<em>Terminology</em> uses the <hilight>elementary</hilight> toolkit.<br>"
|
||||
"The toolkit configuration settings can be accessed by running <keyword>%s</keyword>."), _elementary_config);
|
||||
elm_object_text_set(en, txt);
|
||||
eina_stringshare_del(txt);
|
||||
evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, 0);
|
||||
evas_object_size_hint_align_set(en, EVAS_HINT_FILL, 0.5);
|
||||
elm_box_pack_end(bx, en);
|
||||
|
@ -72,7 +131,9 @@ options_elm(Evas_Object *opbox, Evas_Object *_term EINA_UNUSED)
|
|||
bt = elm_button_add(opbox);
|
||||
evas_object_smart_callback_add(bt, "clicked", launch_elm_config, NULL);
|
||||
evas_object_propagate_events_set(bt, EINA_FALSE);
|
||||
elm_layout_text_set(bt, NULL, _("Launch elementary_config"));
|
||||
txt = eina_stringshare_printf(_("Launch %s"), _elementary_config);
|
||||
elm_layout_text_set(bt, NULL, txt);
|
||||
eina_stringshare_del(txt);
|
||||
elm_box_pack_end(bx, bt);
|
||||
evas_object_show(bt);
|
||||
|
||||
|
|
Loading…
Reference in New Issue