diff options
author | Carsten Haitzler <raster@rasterman.com> | 2011-05-01 03:09:10 +0000 |
---|---|---|
committer | Carsten Haitzler <raster@rasterman.com> | 2011-05-01 03:09:10 +0000 |
commit | 1a3f544f5442a0b5edb4ef00f236f379b18b0096 (patch) | |
tree | 6674cab351cb5cea78bb121dacf5d26b9992edd9 /src/modules/conf_dialogs | |
parent | 86805db0a98a56d1c41185a8c13f5a6c4af24b6d (diff) | |
download | enlightenment-1a3f544f5442a0b5edb4ef00f236f379b18b0096.tar.gz |
more module merging.
SVN revision: 59058
Diffstat (limited to 'src/modules/conf_dialogs')
-rw-r--r-- | src/modules/conf_dialogs/Makefile.am | 4 | ||||
-rw-r--r-- | src/modules/conf_dialogs/e_int_config_profiles.c | 442 | ||||
-rw-r--r-- | src/modules/conf_dialogs/e_int_config_profiles.h | 9 | ||||
-rw-r--r-- | src/modules/conf_dialogs/e_mod_main.c | 3 | ||||
-rw-r--r-- | src/modules/conf_dialogs/e_mod_main.h | 2 |
5 files changed, 459 insertions, 1 deletions
diff --git a/src/modules/conf_dialogs/Makefile.am b/src/modules/conf_dialogs/Makefile.am index 5bf34e8d8f..e70381000a 100644 --- a/src/modules/conf_dialogs/Makefile.am +++ b/src/modules/conf_dialogs/Makefile.am @@ -21,7 +21,9 @@ pkg_LTLIBRARIES = module.la module_la_SOURCES = e_mod_main.c \ e_mod_main.h \ e_int_config_dialogs.c \ - e_int_config_dialogs.h + e_int_config_dialogs.h \ + e_int_config_profiles.c \ + e_int_config_profiles.h module_la_LIBADD = @e_libs@ @dlopen_libs@ module_la_LDFLAGS = -module -avoid-version diff --git a/src/modules/conf_dialogs/e_int_config_profiles.c b/src/modules/conf_dialogs/e_int_config_profiles.c new file mode 100644 index 0000000000..6d62c5f3c3 --- /dev/null +++ b/src/modules/conf_dialogs/e_int_config_profiles.c @@ -0,0 +1,442 @@ +#include "e.h" + +static void *_create_data(E_Config_Dialog *cfd); +static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static int _apply_cfdata(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata); +static Evas_Object *_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata); +static void _ilist_fill(E_Config_Dialog_Data *cfdata); +static void _ilist_cb_selected(void *data); +static void _cb_add(void *data, void *data2); +static void _cb_delete(void *data, void *data2); +static void _cb_reset(void *data, void *data2); +static void _cb_dialog_yes(void *data); +static void _cb_dialog_destroy(void *data); + +E_Dialog *_dia_new_profile(E_Config_Dialog_Data *cfdata); +static void _new_profile_cb_close(void *data, E_Dialog *dia); +static void _new_profile_cb_ok(void *data, E_Dialog *dia); +static void _new_profile_cb_dia_del(void *obj); + +struct _E_Config_Dialog_Data +{ + E_Config_Dialog *cfd; + Evas_Object *o_list; + Evas_Object *o_delete; + Evas_Object *o_reset; + Evas_Object *o_text; + Evas_Object *o_textlabel; + const char *sel_profile; + + E_Dialog *dia_new_profile; + char *new_profile; +}; + +typedef struct _Del_Profile_Confirm_Data Del_Profile_Confirm_Data; +struct _Del_Profile_Confirm_Data +{ + E_Config_Dialog_Data *cfdata; +}; + +E_Config_Dialog * +e_int_config_profiles(E_Container *con, const char *params __UNUSED__) +{ + E_Config_Dialog *cfd; + E_Config_Dialog_View *v; + + if (e_config_dialog_find("E", "settings/profiles")) return NULL; + v = E_NEW(E_Config_Dialog_View, 1); + if (!v) return NULL; + v->create_cfdata = _create_data; + v->free_cfdata = _free_data; + v->basic.apply_cfdata = _apply_cfdata; + v->basic.create_widgets = _create_widgets; + + cfd = e_config_dialog_new(con, _("Profile Selector"), + "E", "settings/profiles", + "preferences-profiles", 0, v, NULL); + e_config_dialog_changed_auto_set(cfd, 0); + return cfd; +} + +static void * +_create_data(E_Config_Dialog *cfd) +{ + E_Config_Dialog_Data *cfdata; + + cfdata = E_NEW(E_Config_Dialog_Data, 1); + cfdata->cfd = cfd; + return cfdata; +} + +static void +_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) +{ + E_FREE(cfdata); +} + +static int +_apply_cfdata(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata) +{ + const char *cur_profile; + E_Action *a; + + cur_profile = e_config_profile_get(); + if (strcmp (cur_profile, cfdata->sel_profile) == 0) + return 1; + + e_config_save_flush(); + e_config_profile_set(cfdata->sel_profile); + e_config_profile_save(); + e_config_save_block_set(1); + + a = e_action_find("restart"); + if ((a) && (a->func.go)) a->func.go(NULL, NULL); + return 1; +} + +static Evas_Object * +_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) +{ + Evas_Object *o, *of, *ot, *ob; + Evas_Coord mw, mh; + char buf[PATH_MAX]; + + o = e_widget_list_add(evas, 0, 0); + + of = e_widget_framelist_add(evas, _("Available Profiles"), 0); + cfdata->o_list = e_widget_ilist_add(evas, 24, 24, &(cfdata->sel_profile)); + e_widget_size_min_set(cfdata->o_list, 140 * e_scale, 80 * e_scale); + e_widget_framelist_object_append(of, cfdata->o_list); + + cfdata->o_textlabel = e_widget_label_add(evas, ""); + e_widget_size_min_get(cfdata->o_textlabel, &mw, &mh); + e_widget_framelist_object_append_full(of, cfdata->o_textlabel, + 1, 1, /* fill */ + 1, 0, /* expand */ + 0.5, 0.5, /* align */ + mw, mh, /* min */ + 99999, 99999 /* max */ + ); + + ob = e_widget_textblock_add(evas); + e_widget_textblock_markup_set(ob, _("Select a profile")); + cfdata->o_text = ob; + e_widget_framelist_object_append_full(of, cfdata->o_text, + 1, 1, /* fill */ + 1, 0, /* expand */ + 0.5, 0.5, /* align */ + 140 * e_scale, 60 * e_scale, /* min */ + 99999, 99999 /* max */ + ); + + ot = e_widget_table_add(evas, 0); + ob = e_widget_button_add(evas, _("Add"), "list-add", _cb_add, cfdata, NULL); + e_widget_table_object_append(ot, ob, 0, 0, 1, 1, 1, 1, 0, 0); + cfdata->o_delete = e_widget_button_add(evas, _("Delete"), "list-remove", + _cb_delete, cfdata, NULL); + e_widget_table_object_append(ot, cfdata->o_delete, 1, 0, 1, 1, 1, 1, 0, 0); + cfdata->o_reset = e_widget_button_add(evas, _("Reset"), "system-restart", + _cb_reset, cfdata, NULL); + e_widget_table_object_align_append(ot, cfdata->o_reset, 2, 0, 1, 1, 0, 1, 1, 1, 1.0, 0.5); + + e_widget_list_object_append(o, of, 1, 1, 0.5); + + // if there is a system version of the profile - allow reset + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", e_config_profile_get()); + if (ecore_file_is_dir(buf)) + e_widget_disabled_set(cfdata->o_reset, 0); + else + e_widget_disabled_set(cfdata->o_reset, 1); + + e_widget_disabled_set(cfdata->o_delete, 1); + + e_widget_list_object_append(o, ot, 1, 0, 0.0); + + _ilist_fill(cfdata); + + e_dialog_resizable_set(cfd->dia, 1); + return o; +} + +static void +_ilist_fill(E_Config_Dialog_Data *cfdata) +{ + Evas *evas; + Eina_List *l, *profiles; + int selected = -1, i; + + if (!cfdata) return; + if (!cfdata->o_list) return; + + evas = evas_object_evas_get(cfdata->o_list); + evas_event_freeze(evas); + edje_freeze(); + e_widget_ilist_freeze(cfdata->o_list); + + e_widget_ilist_clear(cfdata->o_list); + e_widget_ilist_go(cfdata->o_list); + + profiles = e_config_profile_list(); + for (i = 0, l = profiles; l; l = l->next, i++) + { + Efreet_Desktop *desk = NULL; + Evas_Object *ic; + char buf[PATH_MAX], *prof, *pdir; + const char *label; + + prof = l->data; + if (e_config_profile_get()) + { + if (!strcmp(prof, e_config_profile_get())) selected = i; + } + pdir = e_config_profile_dir_get(prof); + snprintf(buf, sizeof(buf), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buf); + if (!desk) + { + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", prof); + pdir = strdup(buf); + if (pdir) + { + snprintf(buf, sizeof(buf), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buf); + } + } + label = prof; + if ((desk) && (desk->name)) label = desk->name; + buf[0] = 0; + if (pdir) + snprintf(buf, sizeof(buf), "%s/icon.edj", pdir); + if ((desk) && (desk->icon) && (pdir)) + snprintf(buf, sizeof(buf), "%s/%s", pdir, desk->icon); + else + e_prefix_data_concat_static(buf, "data/images/enlightenment.png"); + ic = e_util_icon_add(buf, evas); + e_widget_ilist_append(cfdata->o_list, ic, label, _ilist_cb_selected, cfdata, prof); + if (pdir) free(pdir); + free(prof); + if (desk) efreet_desktop_free(desk); + } + if (profiles) eina_list_free(profiles); + if (selected >= 0) + e_widget_ilist_selected_set(cfdata->o_list, selected); + e_widget_size_min_set(cfdata->o_list, 155, 250); + e_widget_ilist_go(cfdata->o_list); + + e_widget_ilist_thaw(cfdata->o_list); + edje_thaw(); + evas_event_thaw(evas); +} + +static void +_ilist_cb_selected(void *data) +{ + E_Config_Dialog_Data *cfdata; + const char *cur_profile; + unsigned char v; + Efreet_Desktop *desk = NULL; + char *pdir, buf[PATH_MAX]; + const char *name; + + cfdata = data; + if (!cfdata) return; + + cur_profile = e_config_profile_get(); + + v = (strcmp(cur_profile, cfdata->sel_profile) == 0); + e_widget_disabled_set(cfdata->o_delete, v); + e_config_dialog_changed_set(cfdata->cfd, !v); + + pdir = e_config_profile_dir_get(cfdata->sel_profile); + snprintf(buf, sizeof(buf), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buf); + if (!desk) + { + e_prefix_data_snprintf(buf, sizeof(buf), "data/config/%s/", cfdata->sel_profile); + pdir = strdup(buf); + if (pdir) + { + snprintf(buf, sizeof(buf), "%s/profile.desktop", pdir); + desk = efreet_desktop_new(buf); + } + } + + if ((desk) && (desk->name)) + name = desk->name; + else + name = cur_profile; + snprintf(buf, sizeof(buf), _("Selected profile: %s"), name); + e_widget_label_text_set(cfdata->o_textlabel, buf); + + if (desk) + e_widget_textblock_markup_set(cfdata->o_text, desk->comment); + else + e_widget_textblock_markup_set(cfdata->o_text, _("Unknown")); + if (desk) efreet_desktop_free(desk); +} + +static void +_cb_add(void *data, void *data2 __UNUSED__) +{ + E_Config_Dialog_Data *cfdata; + + cfdata = data; + if (!cfdata) return; + + if (cfdata->dia_new_profile) + e_win_raise(cfdata->dia_new_profile->win); + else + cfdata->dia_new_profile = _dia_new_profile(cfdata); +} + +static void +_cb_delete(void *data, void *data2 __UNUSED__) +{ + Del_Profile_Confirm_Data *d; + char buf[4096]; + + d = E_NEW(Del_Profile_Confirm_Data, 1); + if (!d) return; + d->cfdata = data; + if (!d->cfdata) return; + + snprintf(buf, sizeof(buf), + _("You want to delete the \"%s\" profile.<br><br>" + "Are you sure?"), d->cfdata->sel_profile); + e_confirm_dialog_show(_("Delete OK?"), + "dialog-warning", buf, NULL, NULL, + _cb_dialog_yes, NULL, d, NULL, + _cb_dialog_destroy, d); +} + +static void +_cb_reset(void *data __UNUSED__, void *data2 __UNUSED__) +{ + E_Action *a; + char *pdir; + + e_config_save_flush(); + e_config_save_block_set(1); + + pdir = e_config_profile_dir_get(e_config_profile_get()); + if (pdir) + { + ecore_file_recursive_rm(pdir); + free(pdir); + } + a = e_action_find("restart"); + if ((a) && (a->func.go)) a->func.go(NULL, NULL); +} + +static void +_cb_dialog_yes(void *data) +{ + Del_Profile_Confirm_Data *d; + + d = data; + if (!data) return; + + e_config_profile_del(d->cfdata->sel_profile); + e_config_save_queue(); + _ilist_fill(d->cfdata); +} + +static void +_cb_dialog_destroy(void *data) +{ + Del_Profile_Confirm_Data *d; + + d = data; + if (!data) return; + + E_FREE(d); +} + +E_Dialog * +_dia_new_profile(E_Config_Dialog_Data *cfdata) +{ + E_Dialog *dia; + Evas *evas; + Evas_Coord mw, mh; + Evas_Object *ot, *ob; + + dia = e_dialog_new(cfdata->cfd->con, "E", "profiles_new_profile_dialog"); + if (!dia) return NULL; + dia->data = cfdata; + + e_object_del_attach_func_set(E_OBJECT(dia), _new_profile_cb_dia_del); + e_win_centered_set(dia->win, 1); + + evas = e_win_evas_get(dia->win); + + e_dialog_title_set(dia, _("Add New Profile")); + + ot = e_widget_table_add(evas, 0); + ob = e_widget_label_add(evas, _("Name:")); + e_widget_table_object_append(ot, ob, + 0, 0, 1, 1, + 0, 1, 0, 0); + ob = e_widget_entry_add(evas, &(cfdata->new_profile), NULL, NULL, NULL); + e_widget_size_min_set(ob, 100, 1); + e_widget_table_object_append(ot, ob, + 1, 0, 1, 1, + 1, 1, 1, 0); + e_widget_size_min_get(ot, &mw, &mh); + e_dialog_content_set(dia, ot, mw, mh); + + e_dialog_button_add(dia, _("OK"), NULL, _new_profile_cb_ok, cfdata); + e_dialog_button_add(dia, _("Cancel"), NULL, _new_profile_cb_close, cfdata); + + e_dialog_resizable_set(dia, 0); + e_dialog_show(dia); + + return dia; +} + +static void +_new_profile_cb_close(void *data, E_Dialog *dia) +{ + E_Config_Dialog_Data *cfdata; + cfdata = data; + if (!cfdata) return; + + e_object_unref(E_OBJECT(dia)); + cfdata->dia_new_profile = NULL; + cfdata->new_profile = NULL; +} + +static void +_new_profile_cb_ok(void *data, E_Dialog *dia) +{ + E_Config_Dialog_Data *cfdata; + char cur_profile[1024]; + + cfdata = data; + if (!cfdata) return; + + snprintf(cur_profile, sizeof(cur_profile), "%s", e_config_profile_get()); + + if (cfdata->new_profile) + { + e_config_profile_add(cfdata->new_profile); + e_config_profile_set(cfdata->new_profile); + e_config_save(); + e_config_profile_set(cur_profile); + } + + e_object_unref(E_OBJECT(dia)); + cfdata->dia_new_profile = NULL; + cfdata->new_profile = NULL; + _ilist_fill(cfdata); +} + +static void +_new_profile_cb_dia_del(void *obj) +{ + E_Dialog *dia = obj; + E_Config_Dialog_Data *cfdata = dia->data; + + cfdata->dia_new_profile = NULL; + cfdata->new_profile = NULL; + e_object_unref(E_OBJECT(dia)); +} diff --git a/src/modules/conf_dialogs/e_int_config_profiles.h b/src/modules/conf_dialogs/e_int_config_profiles.h new file mode 100644 index 0000000000..ff18335f85 --- /dev/null +++ b/src/modules/conf_dialogs/e_int_config_profiles.h @@ -0,0 +1,9 @@ +#ifdef E_TYPEDEFS +#else +#ifndef E_INT_CONFIG_PROFILES_H +#define E_INT_CONFIG_PROFILES_H + +E_Config_Dialog *e_int_config_profiles(E_Container *con, const char *params __UNUSED__); + +#endif +#endif diff --git a/src/modules/conf_dialogs/e_mod_main.c b/src/modules/conf_dialogs/e_mod_main.c index 9ba06947ed..62d8479634 100644 --- a/src/modules/conf_dialogs/e_mod_main.c +++ b/src/modules/conf_dialogs/e_mod_main.c @@ -16,6 +16,7 @@ e_modapi_init(E_Module *m) { e_configure_registry_category_add("settings", 80, _("Settings"), NULL, "preferences-system"); e_configure_registry_item_add("settings/dialogs", 10, _("Dialogs"), NULL, "preferences-system", e_int_config_dialogs); + e_configure_registry_item_add("settings/profiles", 50, _("Profiles"), NULL, "preferences-profiles", e_int_config_profiles); conf_module = m; e_module_delayed_set(m, 1); return m; @@ -25,7 +26,9 @@ EAPI int e_modapi_shutdown(E_Module *m __UNUSED__) { E_Config_Dialog *cfd; + while ((cfd = e_config_dialog_get("E", "settings/profiles"))) e_object_del(E_OBJECT(cfd)); while ((cfd = e_config_dialog_get("E", "settings/dialogs"))) e_object_del(E_OBJECT(cfd)); + e_configure_registry_item_del("settings/profiles"); e_configure_registry_item_del("settings/dialogs"); e_configure_registry_category_del("settings"); conf_module = NULL; diff --git a/src/modules/conf_dialogs/e_mod_main.h b/src/modules/conf_dialogs/e_mod_main.h index 0ecc3c3356..e8df8445e8 100644 --- a/src/modules/conf_dialogs/e_mod_main.h +++ b/src/modules/conf_dialogs/e_mod_main.h @@ -3,9 +3,11 @@ #define E_TYPEDEFS 1 #include "e_int_config_dialogs.h" +#include "e_int_config_profiles.h" #undef E_TYPEDEFS #include "e_int_config_dialogs.h" +#include "e_int_config_profiles.h" EAPI extern E_Module_Api e_modapi; |