diff --git a/src/sview/popups.c b/src/sview/popups.c index 87c182f28142464a62401e6db2606f497b8abbbb..f9c7baecec715154d79efe3ea074ae40869bcf21 100644 --- a/src/sview/popups.c +++ b/src/sview/popups.c @@ -48,6 +48,100 @@ void *_refresh_thr(gpointer arg) return NULL; } +/* Creates a tree model containing the completions */ +void _search_entry(GtkEntry *entry, GtkComboBox *combo) +{ + GtkTreeModel *model = NULL; + GtkTreeIter iter; + int id; + char *data = xstrdup(gtk_entry_get_text(entry)); + char title[100]; + ListIterator itr = NULL; + popup_info_t *popup_win = NULL; + GError *error = NULL; + job_step_num_t *job_step = NULL; + + gtk_entry_set_text(entry, ""); + + if(!strlen(data)) { + g_print("nothing given to search for.\n"); + return; + } + if(!gtk_combo_box_get_active_iter(combo, &iter)) { + g_print("nothing selected\n"); + return; + } + model = gtk_combo_box_get_model(combo); + if(!model) { + g_print("nothing selected\n"); + return; + } + + gtk_tree_model_get(model, &iter, 0, &id, -1); + + switch(id) { + case JOB_PAGE: + snprintf(title, 100, "Job %s info", data); + break; + case PART_PAGE: + snprintf(title, 100, "Partition %s info", data); + break; + case BLOCK_PAGE: + snprintf(title, 100, "BG Block %s info", data); + break; + case NODE_PAGE: +#ifdef HAVE_BG + snprintf(title, 100, + "Base partition(s) %s info", data); +#else + snprintf(title, 100, "Node(s) %s info", data); +#endif + break; + default: + g_print("unknown selection %s\n", data); + break; + } + + itr = list_iterator_create(popup_list); + while((popup_win = list_next(itr))) { + if(popup_win->spec_info) + if(!strcmp(popup_win->spec_info->title, title)) { + break; + } + } + list_iterator_destroy(itr); + + if(!popup_win) { + popup_win = create_popup_info(id, id, title); + } + + switch(id) { + case JOB_PAGE: + id = atoi(data); + xfree(data); + job_step = g_malloc(sizeof(job_step_num_t)); + job_step->jobid = id; + job_step->stepid = NO_VAL; + popup_win->spec_info->data = job_step; + break; + case PART_PAGE: + case BLOCK_PAGE: + case NODE_PAGE: + popup_win->spec_info->data = data; + break; + default: + g_print("unknown selection %d\n", id); + return; + } + if (!g_thread_create((gpointer)popup_thr, popup_win, FALSE, &error)) + { + g_printerr ("Failed to create main popup thread: %s\n", + error->message); + return; + } + return; +} + extern void create_config_popup(GtkToggleAction *action, gpointer user_data) { GtkWidget *table = gtk_table_new(1, 2, FALSE); @@ -169,56 +263,45 @@ extern void create_deamon_popup(GtkToggleAction *action, gpointer user_data) extern void create_search_popup(GtkToggleAction *action, gpointer user_data) { GtkWidget *table = gtk_table_new(1, 2, FALSE); - GtkWidget *label = gtk_label_new("Interval in Seconds "); - GtkObject *adjustment = gtk_adjustment_new(global_sleep_time, - 1, 10000, - 5, 60, - 1); - GtkWidget *spin_button = - gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 1, 0); GtkWidget *popup = gtk_dialog_new_with_buttons( - "Refresh Interval", - GTK_WINDOW (user_data), + "Search", + GTK_WINDOW(user_data), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); - GError *error = NULL; int response = 0; - char *temp = NULL; - + display_data_t pulldown_display_data[] = { + {G_TYPE_NONE, JOB_PAGE, "Job", TRUE, -1}, + {G_TYPE_NONE, PART_PAGE, "Partition", TRUE, -1}, +#ifdef HAVE_BG + {G_TYPE_NONE, BLOCK_PAGE, "BG Block", TRUE, -1}, + {G_TYPE_NONE, NODE_PAGE, "Base Partitions", TRUE, -1}, +#else + {G_TYPE_NONE, NODE_PAGE, "Node", TRUE, -1}, +#endif + {G_TYPE_NONE, -1, NULL, FALSE, -1} + }; + GtkWidget *combo = + create_pulldown_combo(pulldown_display_data, PAGE_CNT); + GtkWidget *entry = gtk_entry_new(); + gtk_container_set_border_width(GTK_CONTAINER(table), 10); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(popup)->vbox), table, FALSE, FALSE, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); - gtk_table_attach_defaults(GTK_TABLE(table), spin_button, 1, 2, 0, 1); - + gtk_table_attach_defaults(GTK_TABLE(table), combo, 0, 1, 0, 1); + gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 0, 1); + gtk_widget_show_all(popup); response = gtk_dialog_run (GTK_DIALOG(popup)); if (response == GTK_RESPONSE_OK) - { - global_sleep_time = - gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_button)); - temp = g_strdup_printf("Refresh Interval set to %d seconds.", - global_sleep_time); - gtk_statusbar_pop(GTK_STATUSBAR(main_statusbar), - STATUS_REFRESH); - response = gtk_statusbar_push(GTK_STATUSBAR(main_statusbar), - STATUS_REFRESH, - temp); - g_free(temp); - if (!g_thread_create(_refresh_thr, GINT_TO_POINTER(response), - FALSE, &error)) - { - g_printerr ("Failed to create refresh thread: %s\n", - error->message); - } - } + _search_entry(GTK_ENTRY(entry), GTK_COMBO_BOX(combo)); + gtk_widget_destroy(popup); diff --git a/src/sview/sview.c b/src/sview/sview.c index f268b5347f0015b66262c15fb904561938a51d2a..20cf771d27e3d05c9586e86bd6cb2463caad7fb2 100644 --- a/src/sview/sview.c +++ b/src/sview/sview.c @@ -255,9 +255,10 @@ static GtkWidget *_get_menubar_menu(GtkWidget *window, GtkWidget *notebook) " <menuitem action='exit'/>" " </menu>" " <menu action='displays'>" + " <menuitem action='search'/>" + " <separator/>" " <menuitem action='config'/>" " <menuitem action='deamons'/>" - " <menuitem action='search'/>" " </menu>" " <menu action='help'>" " <menuitem action='about'/>" @@ -345,122 +346,13 @@ void *_popup_thr_main(void *arg) return NULL; } - -/* Creates a tree model containing the completions */ -void _search_entry(GtkEntry *entry, GtkComboBox *combo) -{ - GtkTreeModel *model = NULL; - GtkTreeIter iter; - int id; - char *data = xstrdup(gtk_entry_get_text(entry)); - char title[100]; - ListIterator itr = NULL; - popup_info_t *popup_win = NULL; - GError *error = NULL; - job_step_num_t *job_step = NULL; - - gtk_entry_set_text(entry, ""); - - if(!strlen(data)) { - g_print("nothing given to search for.\n"); - return; - } - if(!gtk_combo_box_get_active_iter(combo, &iter)) { - g_print("nothing selected\n"); - return; - } - model = gtk_combo_box_get_model(combo); - if(!model) { - g_print("nothing selected\n"); - return; - } - - gtk_tree_model_get(model, &iter, 0, &id, -1); - - switch(id) { - case JOB_PAGE: - snprintf(title, 100, "Job %s info", data); - break; - case PART_PAGE: - snprintf(title, 100, "Partition %s info", data); - break; - case BLOCK_PAGE: - snprintf(title, 100, "BG Block %s info", data); - break; - case NODE_PAGE: -#ifdef HAVE_BG - snprintf(title, 100, - "Base partition(s) %s info", data); -#else - snprintf(title, 100, "Node(s) %s info", data); -#endif - break; - default: - g_print("unknown selection %s\n", data); - break; - } - - itr = list_iterator_create(popup_list); - while((popup_win = list_next(itr))) { - if(popup_win->spec_info) - if(!strcmp(popup_win->spec_info->title, title)) { - break; - } - } - list_iterator_destroy(itr); - - if(!popup_win) { - popup_win = create_popup_info(id, id, title); - } - - switch(id) { - case JOB_PAGE: - id = atoi(data); - xfree(data); - job_step = g_malloc(sizeof(job_step_num_t)); - job_step->jobid = id; - job_step->stepid = NO_VAL; - popup_win->spec_info->data = job_step; - break; - case PART_PAGE: - case BLOCK_PAGE: - case NODE_PAGE: - popup_win->spec_info->data = data; - break; - default: - g_print("unknown selection %d\n", id); - return; - } - if (!g_thread_create((gpointer)popup_thr, popup_win, FALSE, &error)) - { - g_printerr ("Failed to create main popup thread: %s\n", - error->message); - return; - } - return; -} - - int main(int argc, char *argv[]) { GtkWidget *menubar = NULL; GtkWidget *table = NULL; - GtkWidget *label = NULL; - GtkWidget *combo = NULL; - GtkWidget *entry = NULL; + GtkWidget *button = NULL; int i=0; - display_data_t pulldown_display_data[] = { - {G_TYPE_NONE, JOB_PAGE, "Job", TRUE, -1}, - {G_TYPE_NONE, PART_PAGE, "Partition", TRUE, -1}, -#ifdef HAVE_BG - {G_TYPE_NONE, BLOCK_PAGE, "BG Block", TRUE, -1}, - {G_TYPE_NONE, NODE_PAGE, "Base Partitions", TRUE, -1}, -#else - {G_TYPE_NONE, NODE_PAGE, "Node", TRUE, -1}, -#endif - {G_TYPE_NONE, -1, NULL, FALSE, -1} - }; _init_pages(); g_thread_init(NULL); @@ -482,32 +374,24 @@ int main(int argc, char *argv[]) g_signal_connect(G_OBJECT(main_notebook), "switch_page", G_CALLBACK(_page_switched), NULL); - table = gtk_table_new(1, 4, FALSE); + table = gtk_table_new(1, 2, FALSE); gtk_table_set_homogeneous(GTK_TABLE(table), FALSE); gtk_container_set_border_width(GTK_CONTAINER(table), 1); /* Create a menu */ menubar = _get_menubar_menu(main_window, main_notebook); gtk_table_attach_defaults(GTK_TABLE(table), menubar, 0, 1, 0, 1); - label = gtk_label_new("Search "); - gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1, - GTK_SHRINK, GTK_EXPAND | GTK_FILL, - 0, 0); + /*create search button */ + button = gtk_button_new_with_label("Search"); + g_signal_connect(G_OBJECT(button), + "pressed", + G_CALLBACK(create_search_popup), + main_window); - combo = create_pulldown_combo(pulldown_display_data, PAGE_CNT); - gtk_table_attach(GTK_TABLE(table), combo, 2, 3, 0, 1, + gtk_table_attach(GTK_TABLE(table), button, 1, 2, 0, 1, GTK_SHRINK, GTK_EXPAND | GTK_FILL, 0, 0); - - entry = gtk_entry_new(); - gtk_table_attach(GTK_TABLE(table), entry, 3, 4, 0, 1, - GTK_SHRINK, GTK_EXPAND | GTK_FILL, - 0, 0); - - g_signal_connect(G_OBJECT(entry), "activate", - G_CALLBACK(_search_entry), - combo); - + gtk_notebook_popup_enable(GTK_NOTEBOOK(main_notebook)); gtk_notebook_set_scrollable(GTK_NOTEBOOK(main_notebook), TRUE); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(main_notebook), GTK_POS_TOP);