diff --git a/src/bin/clouseau_client.c b/src/bin/clouseau_client.c index 8b95371..f7a30c4 100644 --- a/src/bin/clouseau_client.c +++ b/src/bin/clouseau_client.c @@ -53,15 +53,6 @@ static const char *_conn_strs[] = "Remote" }; -typedef struct -{ - const char *name; - int port; - /* Not eet */ - const char *file_name; - Eo *menu_item; -} Profile; - typedef struct { Eina_Debug_Session *session; @@ -107,13 +98,11 @@ static Eina_Debug_Session *_session = NULL; static Eina_List *_apps = NULL; static App_Info *_selected_app = NULL; -static Eet_Data_Descriptor *_profile_edd = NULL, *_config_edd = NULL, *_snapshot_edd = NULL; -static Eina_List *_profiles = NULL; +static Eet_Data_Descriptor *_config_edd = NULL, *_snapshot_edd = NULL; static Config *_config = NULL; static Eina_List *_extensions = NULL; -static Eo *_menu_remote_item = NULL; -static Profile *_selected_profile = NULL; +static int _selected_port = -1; static Eina_Debug_Error _clients_info_added_cb(Eina_Debug_Session *, int, void *, int); static Eina_Debug_Error _clients_info_deleted_cb(Eina_Debug_Session *, int, void *, int); @@ -169,62 +158,6 @@ _config_save() eet_close(file); } -static void -_profile_eet_load() -{ - if (_profile_edd) return; - Eet_Data_Descriptor_Class eddc; - - EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Profile); - _profile_edd = eet_data_descriptor_stream_new(&eddc); - -#define CFG_ADD_BASIC(member, eet_type)\ - EET_DATA_DESCRIPTOR_ADD_BASIC\ - (_profile_edd, Profile, # member, member, eet_type) - - CFG_ADD_BASIC(name, EET_T_STRING); - CFG_ADD_BASIC(port, EET_T_INT); - -#undef CFG_ADD_BASIC -} - -static Profile * -_profile_find(const char *name) -{ - Eina_List *itr; - Profile *p; - EINA_LIST_FOREACH(_profiles, itr, p) - if (p->name == name || !strcmp(p->name, name)) return p; - return NULL; -} - -static void -_profile_save(const Profile *p) -{ - char path[1024]; - if (!p) return; - sprintf(path, "%s/clouseau/profiles/%s", efreet_config_home_get(), p->file_name); - Eet_File *file = eet_open(path, EET_FILE_MODE_WRITE); - _profile_eet_load(); - eet_data_write(file, _profile_edd, _EET_ENTRY, p, EINA_TRUE); - eet_close(file); - _profiles = eina_list_append(_profiles, p); -} - -static void -_profile_remove(Profile *p) -{ - char path[1024]; - if (!p) return; - if (p->menu_item) efl_del(p->menu_item); - sprintf(path, "%s/clouseau/profiles/%s", efreet_config_home_get(), p->file_name); - if (remove(path) == -1) perror("Remove"); - _profiles = eina_list_remove(_profiles, p); - eina_stringshare_del(p->file_name); - eina_stringshare_del(p->name); - free(p); -} - static void _snapshot_eet_load() { @@ -287,23 +220,11 @@ static void _configs_load() { Extension_Config *ext_cfg; - char path[1024], *filename; + Eina_List *itr; + char path[1024]; + sprintf(path, "%s/clouseau", efreet_config_home_get()); if (!_mkdir(path)) return; - sprintf(path, "%s/clouseau/profiles", efreet_config_home_get()); - if (!_mkdir(path)) return; - Eina_List *files = ecore_file_ls(path), *itr; - if (files) _profile_eet_load(); - - EINA_LIST_FOREACH(files, itr, filename) - { - sprintf(path, "%s/clouseau/profiles/%s", efreet_config_home_get(), filename); - Eet_File *file = eet_open(path, EET_FILE_MODE_READ); - Profile *p = eet_data_read(file, _profile_edd, _EET_ENTRY); - p->file_name = eina_stringshare_add(filename); - eet_close(file); - _profiles = eina_list_append(_profiles, p); - } sprintf(path, "%s/clouseau/config", efreet_config_home_get()); _config_eet_load(); @@ -532,51 +453,6 @@ _post_register_handle(void *data EINA_UNUSED, Eina_Bool flag) eina_debug_session_send(_session, 0, _cl_stat_reg_op, NULL, 0); } -static void -_profile_create_cb(void *data EINA_UNUSED, const Efl_Event *event) -{ - Gui_New_Profile_Win_Widgets *wdgs = NULL; - Profile *p = NULL; - Eo *save_bt = event->object; - wdgs = efl_key_data_get(save_bt, "_wdgs"); - const char *name = elm_object_text_get(wdgs->name_entry); - const char *port_str = elm_object_text_get(wdgs->port_entry); - if (!name || !*name) return; - if (!port_str || !*port_str) return; - p = calloc(1, sizeof(*p)); - p->file_name = eina_stringshare_add(name); /* FIXME: Have to format name to conform to file names convention */ - p->name = eina_stringshare_add(name); - p->port = atoi(port_str); - _profile_save(p); - efl_del(wdgs->inwin); -} - -static void -_profile_modify_cb(void *data, const Efl_Event *event) -{ - Profile *p = data; - Eo *save_bt = event->object; - Gui_New_Profile_Win_Widgets *wdgs = efl_key_data_get(save_bt, "_wdgs"); - const char *name = elm_object_text_get(wdgs->name_entry); - const char *port_str = elm_object_text_get(wdgs->port_entry); - if (!name || !*name) return; - if (!port_str || !*port_str) return; - _profile_remove(p); - p = calloc(1, sizeof(*p)); - p->file_name = eina_stringshare_add(name); /* FIXME: Have to format name to conform to file names convention */ - p->name = eina_stringshare_add(name); - p->port = atoi(port_str); - _profile_save(p); - efl_del(wdgs->inwin); -} - -void -gui_new_profile_win_create_done(Gui_New_Profile_Win_Widgets *wdgs) -{ - efl_key_data_set(wdgs->save_button, "_wdgs", wdgs); - efl_key_data_set(wdgs->cancel_button, "_wdgs", wdgs); -} - static void _session_populate() { @@ -601,7 +477,7 @@ _session_populate() } case REMOTE_CONNECTION: { - ext->session = eina_debug_remote_connect(_selected_profile->port); + ext->session = eina_debug_remote_connect(_selected_port); eina_debug_session_dispatch_override(ext->session, _disp_cb); if (ext->session_changed_cb) ext->session_changed_cb(ext); break; @@ -631,13 +507,13 @@ _connection_type_change(Connection_Type conn_type) { case OFFLINE: { - _selected_profile = NULL; + _selected_port = -1; elm_object_item_disabled_set(_main_widgets->apps_selector, EINA_TRUE); break; } case LOCAL_CONNECTION: { - _selected_profile = NULL; + _selected_port = -1; elm_object_item_disabled_set(_main_widgets->apps_selector, EINA_FALSE); _session = eina_debug_local_connect(EINA_TRUE); eina_debug_session_dispatch_override(_session, _disp_cb); @@ -646,7 +522,7 @@ _connection_type_change(Connection_Type conn_type) case REMOTE_CONNECTION: { elm_object_item_disabled_set(_main_widgets->apps_selector, EINA_FALSE); - _session = eina_debug_remote_connect(_selected_profile->port); + _session = eina_debug_remote_connect(_selected_port); eina_debug_session_dispatch_override(_session, _disp_cb); break; } @@ -670,70 +546,25 @@ _connection_type_change(Connection_Type conn_type) } } +void +remote_port_entry_changed(void *data, const Efl_Event *event) +{ + Eo *inwin = data; + const char *ptr = elm_entry_entry_get(event->object); + _selected_port = atoi(ptr); + _connection_type_change(REMOTE_CONNECTION); + efl_del(inwin); +} + static void _menu_selected_conn(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - _connection_type_change((uintptr_t)data); -} - -static void -_menu_profile_selected(void *data, - Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - _selected_profile = data; - _connection_type_change(REMOTE_CONNECTION); -} - -static void -_menu_profile_modify(void *data, - Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - char port_str[16]; - Profile *p = data; - Gui_New_Profile_Win_Widgets *wdgs = gui_new_profile_win_create(_main_widgets->main_win); - gui_new_profile_win_create_done(wdgs); - efl_event_callback_add(wdgs->save_button, EFL_UI_EVENT_CLICKED, _profile_modify_cb, p); - elm_object_text_set(wdgs->name_entry, p->name); - sprintf(port_str, "%d", p->port); - elm_object_text_set(wdgs->port_entry, port_str); -} - -static void -_menu_profile_delete(void *data, - Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - Profile *p = data; - _profile_remove(p); -} - -void -conn_menu_show(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - Eina_List *itr; - Profile *p; - - EINA_LIST_FOREACH(_profiles, itr, p) - { - if (p->menu_item) continue; - p->menu_item = elm_menu_item_add(_main_widgets->conn_selector_menu, - _menu_remote_item, NULL, p->name, - _menu_profile_selected, p); - efl_wref_add(p->menu_item, &p->menu_item); - elm_menu_item_add(_main_widgets->conn_selector_menu, - p->menu_item, NULL, "Modify", _menu_profile_modify, p); - elm_menu_item_add(_main_widgets->conn_selector_menu, - p->menu_item, NULL, "Delete", _menu_profile_delete, p); - } -} - -static void -_profile_new_clicked(void *data EINA_UNUSED, - Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) -{ - Gui_New_Profile_Win_Widgets *wdgs = gui_new_profile_win_create(_main_widgets->main_win); - gui_new_profile_win_create_done(wdgs); - efl_event_callback_add(wdgs->save_button, EFL_UI_EVENT_CLICKED, _profile_create_cb, NULL); + Connection_Type ctype = (uintptr_t)data; + if (ctype == REMOTE_CONNECTION) + gui_remote_port_win_create(_main_widgets->main_win); + else + _connection_type_change(ctype); } static void @@ -1053,12 +884,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) case 'r': { conn_type = REMOTE_CONNECTION; - _selected_profile = _profile_find(optarg); - if (!_selected_profile) - { - printf("Profile %s not found\n", optarg); - help = EINA_TRUE; - } + _selected_port = atoi(optarg); break; } case 'f': @@ -1076,7 +902,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) printf("Usage: %s [-h/--help] [-v/--verbose] [options]\n", argv[0]); printf(" --help/-h Print that help\n"); printf(" --local/-l Create a local connection\n"); - printf(" --remote/-r Create a remote connection by using the given profile name\n"); + printf(" --remote/-r Create a remote connection by using the given port\n"); printf(" --file/-f Run in offline mode and load the given file\n"); return 0; } @@ -1086,20 +912,9 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) for (i = 0; i < LAST_CONNECTION; i++) { - if (i == REMOTE_CONNECTION) - { - _menu_remote_item = elm_menu_item_add(_main_widgets->conn_selector_menu, - NULL, NULL, _conn_strs[i], NULL, NULL); - elm_menu_item_add(_main_widgets->conn_selector_menu, - _menu_remote_item, NULL, "New profile...", - _profile_new_clicked, NULL); - } - else - { - elm_menu_item_add(_main_widgets->conn_selector_menu, - NULL, NULL, _conn_strs[i], - _menu_selected_conn, (void *)(uintptr_t)i); - } + elm_menu_item_add(_main_widgets->conn_selector_menu, + NULL, NULL, _conn_strs[i], + _menu_selected_conn, (void *)(uintptr_t)i); } EINA_LIST_FOREACH(_config->extensions_cfgs, itr, ext_cfg) diff --git a/src/bin/gui.c b/src/bin/gui.c index eca6564..6490c77 100644 --- a/src/bin/gui.c +++ b/src/bin/gui.c @@ -14,12 +14,12 @@ #include "elm_interface_fileselector.h" #include "gui.h" -extern void gui_new_profile_win_create_done(Gui_New_Profile_Win_Widgets *wdgs); - extern void conn_menu_show(void *data, Evas_Object *obj, void *event_info); extern void save_load_perform(void *data, Evas_Object *obj, void *event_info); +extern void +remote_port_entry_changed(void *data, const Efl_Event *event); static void _pubs_free_cb(void *data, const Efl_Event *event EINA_UNUSED) @@ -63,7 +63,7 @@ gui_main_win_create(Eo *__main_parent) evas_object_size_hint_align_set(tb, -1, 0); elm_toolbar_menu_parent_set(tb, main_win); - pub_widgets->conn_selector = elm_toolbar_item_append(tb, "call-start", "Connection", conn_menu_show, NULL); + pub_widgets->conn_selector = elm_toolbar_item_append(tb, "call-start", "Connection", NULL, NULL); elm_toolbar_item_menu_set(pub_widgets->conn_selector, EINA_TRUE); pub_widgets->conn_selector_menu = elm_toolbar_item_menu_get(pub_widgets->conn_selector); @@ -113,92 +113,26 @@ gui_main_win_create(Eo *__main_parent) return pub_widgets; } -static void -_profile_cancel_cb(void *data, const Efl_Event *event EINA_UNUSED) +Gui_Remote_Port_Win_Widgets * +gui_remote_port_win_create(Eo *__main_parent) { - Eo *inwin = data; - efl_del(inwin); -} - -Gui_New_Profile_Win_Widgets * -gui_new_profile_win_create(Eo *__main_parent) -{ - Gui_New_Profile_Win_Widgets *pub_widgets = calloc(1, sizeof(*pub_widgets)); + Gui_Remote_Port_Win_Widgets *pub_widgets = calloc(1, sizeof(*pub_widgets)); Eo *inwin; - Eo *box; - Eo *cancel_button; - Eo *save_button; - Eo *bts_box; - Eo *name_entry; - Eo *port_entry; - Eo *name_label; - Eo *port_label; + Eo *entry; inwin = elm_win_inwin_add(__main_parent); pub_widgets->inwin = inwin; - box = elm_box_add(inwin); - evas_object_size_hint_align_set(box, -1.000000, -1.000000); - evas_object_size_hint_weight_set(box, 1.000000, 1.000000); - efl_gfx_visible_set(box, EINA_TRUE); + entry = elm_entry_add(inwin); + elm_entry_scrollable_set(entry, EINA_TRUE); + elm_entry_single_line_set(entry, EINA_TRUE); + elm_object_part_text_set(entry, "guide", "Port to connect to remote device"); + efl_event_callback_add(entry, ELM_ENTRY_EVENT_ACTIVATED, remote_port_entry_changed, inwin); + evas_object_show(entry); + + elm_win_inwin_content_set(inwin, entry); elm_win_inwin_activate(inwin); - elm_win_inwin_content_set(inwin, box); - - name_label = efl_add(ELM_LABEL_CLASS, box); - elm_object_text_set(name_label, "Name:"); - evas_object_size_hint_align_set(name_label, 0, -1); - evas_object_size_hint_weight_set(name_label, 1, 1); - efl_gfx_visible_set(name_label, EINA_TRUE); - name_entry = efl_add(ELM_ENTRY_CLASS, box); - pub_widgets->name_entry = name_entry; - evas_object_size_hint_align_set(name_entry, -1, -1); - evas_object_size_hint_weight_set(name_entry, 1, 1); - elm_entry_scrollable_set(name_entry, EINA_TRUE); - elm_entry_single_line_set(name_entry, EINA_TRUE); - elm_entry_editable_set(name_entry, EINA_TRUE); - elm_object_text_set(name_entry, ""); - efl_gfx_visible_set(name_entry, EINA_TRUE); - elm_box_pack_end(box, name_label); - elm_box_pack_end(box, name_entry); - - port_label = efl_add(ELM_LABEL_CLASS, box); - evas_object_size_hint_align_set(port_label, 0, -1); - evas_object_size_hint_weight_set(port_label, 1, 1); - efl_gfx_visible_set(port_label, EINA_TRUE); - elm_object_text_set(port_label, "Port:"); - port_entry = efl_add(ELM_ENTRY_CLASS, box); - pub_widgets->port_entry = port_entry; - elm_entry_scrollable_set(port_entry, EINA_TRUE); - elm_entry_single_line_set(port_entry, EINA_TRUE); - evas_object_size_hint_align_set(port_entry, -1, -1); - evas_object_size_hint_weight_set(port_entry, 1, 1); - efl_gfx_visible_set(port_entry, EINA_TRUE); - elm_box_pack_end(box, port_label); - elm_box_pack_end(box, port_entry); - - bts_box = elm_box_add(box); - elm_box_padding_set(bts_box, 7, 0); - evas_object_size_hint_align_set(bts_box, -1, -1); - evas_object_size_hint_weight_set(bts_box, 1, 1); - efl_gfx_visible_set(bts_box, EINA_TRUE); - elm_box_horizontal_set(bts_box, EINA_TRUE); - elm_box_pack_end(box, bts_box); - - save_button = efl_add(ELM_BUTTON_CLASS, bts_box); - pub_widgets->save_button = save_button; - evas_object_size_hint_weight_set(save_button, 1.000000, 1.000000); - elm_object_text_set(save_button, "Save"); - efl_gfx_visible_set(save_button, EINA_TRUE); - elm_box_pack_end(bts_box, save_button); - - cancel_button = efl_add(ELM_BUTTON_CLASS, bts_box); - pub_widgets->cancel_button = cancel_button; - evas_object_size_hint_weight_set(cancel_button, 1.000000, 1.000000); - efl_gfx_visible_set(cancel_button, EINA_TRUE); - elm_object_text_set(cancel_button, "Cancel"); - efl_event_callback_add(cancel_button, EFL_UI_EVENT_CLICKED, _profile_cancel_cb, inwin); - elm_box_pack_end(bts_box, cancel_button); efl_event_callback_add(inwin, EFL_EVENT_DEL, _pubs_free_cb, pub_widgets); diff --git a/src/bin/gui.h b/src/bin/gui.h index f82ea9d..a65885c 100644 --- a/src/bin/gui.h +++ b/src/bin/gui.h @@ -24,10 +24,10 @@ typedef struct Eo *save_button; Eo *name_entry; Eo *port_entry; -} Gui_New_Profile_Win_Widgets; +} Gui_Remote_Port_Win_Widgets; Gui_Main_Win_Widgets *gui_main_win_create(Eo *parent); -Gui_New_Profile_Win_Widgets *gui_new_profile_win_create(Eo *parent); +Gui_Remote_Port_Win_Widgets *gui_remote_port_win_create(Eo *parent); #endif