Exemplo n.º 1
0
static void _set_ruled(GtkToggleAction *action)
{
	char *tmp;
	if (action)
		working_sview_config.ruled_treeview
			= gtk_toggle_action_get_active(action);
	if (!working_sview_config.ruled_treeview)
		tmp = g_strdup_printf(
			"Tables not ruled");
	else
		tmp = g_strdup_printf(
			"Tables ruled");

	/* get rid of each existing table */
	cluster_change_block();
	cluster_change_front_end();
	cluster_change_resv();
	cluster_change_part();
	cluster_change_job();
	cluster_change_node();
	cluster_change_bb();

	refresh_main(NULL, NULL);
	display_edit_note(tmp);
	g_free(tmp);
	return;
}
Exemplo n.º 2
0
extern void _change_cluster_main(GtkComboBox *combo, gpointer extra)
{
	GtkTreeModel *model;
	display_data_t *display_data;
	GtkTreeIter iter;
	slurmdb_cluster_rec_t *cluster_rec = NULL;
	char *tmp, *ui_description;
	GError *error = NULL;
	GtkWidget *node_tab = NULL;
	int rc;
	bool got_grid = 0;

	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, 1, &cluster_rec, -1);
	if (!cluster_rec) {
		g_print("no cluster_rec pointer here!");
		return;
	}

	/* From testing it doesn't appear you can get here without a
	   legitimate change, so there isn't a need to check if we are
	   going back to the same cluster we were just at.
	*/
	/* if (working_cluster_rec) { */
	/*	if (!xstrcmp(cluster_rec->name, working_cluster_rec->name)) */
	/*		return; */
	/* } */

	/* free old info under last cluster */
	slurm_free_block_info_msg(g_block_info_ptr);
	g_block_info_ptr = NULL;
	slurm_free_front_end_info_msg(g_front_end_info_ptr);
	g_front_end_info_ptr = NULL;
	slurm_free_burst_buffer_info_msg(g_bb_info_ptr);
	g_bb_info_ptr = NULL;
	slurm_free_job_info_msg(g_job_info_ptr);
	g_job_info_ptr = NULL;
	slurm_free_node_info_msg(g_node_info_ptr);
	g_node_info_ptr = NULL;
	slurm_free_partition_info_msg(g_part_info_ptr);
	g_part_info_ptr = NULL;
	slurm_free_reservation_info_msg(g_resv_info_ptr);
	g_resv_info_ptr = NULL;
	slurm_free_ctl_conf(g_ctl_info_ptr);
	g_ctl_info_ptr = NULL;
	slurm_free_job_step_info_response_msg(g_step_info_ptr);
	g_step_info_ptr = NULL;
	slurm_free_topo_info_msg(g_topo_info_msg_ptr);
	g_topo_info_msg_ptr = NULL;

	/* set up working_cluster_rec */
	if (cluster_dims > 1) {
		/* reset from a multi-dim cluster */
		working_sview_config.grid_x_width =
			default_sview_config.grid_x_width;
		working_sview_config.grid_hori = default_sview_config.grid_hori;
		working_sview_config.grid_vert = default_sview_config.grid_vert;
	}
	gtk_table_set_col_spacings(main_grid_table, 0);
	gtk_table_set_row_spacings(main_grid_table, 0);

	if (!orig_cluster_name)
		orig_cluster_name = slurm_get_cluster_name();
	if (!xstrcmp(cluster_rec->name, orig_cluster_name))
		working_cluster_rec = NULL;
	else
		working_cluster_rec = cluster_rec;
	cluster_dims = slurmdb_setup_cluster_dims();
	cluster_flags = slurmdb_setup_cluster_flags();

	display_data = main_display_data;
	while (display_data++) {
		if (display_data->id == -1)
			break;
		if (cluster_flags & CLUSTER_FLAG_BG) {
			switch(display_data->id) {
			case BLOCK_PAGE:
				display_data->show = true;
				break;
			case NODE_PAGE:
				display_data->name = "Midplanes";
				break;
			default:
				break;
			}
		} else {
			switch(display_data->id) {
			case BLOCK_PAGE:
				display_data->show = false;
				break;
			case NODE_PAGE:
				display_data->name = "Nodes";
				break;
			default:
				break;
			}
		}
	}

	/* set up menu */
	ui_description = _get_ui_description();
	gtk_ui_manager_remove_ui(g_ui_manager, g_menu_id);
	if (!(g_menu_id = gtk_ui_manager_add_ui_from_string(
		      g_ui_manager, ui_description, -1, &error))) {
		xfree(ui_description);
		g_error("building menus failed: %s", error->message);
		g_error_free (error);
		exit (0);
	}
	xfree(ui_description);

	/* make changes for each object */
	cluster_change_block();
	cluster_change_front_end();
	cluster_change_resv();
	cluster_change_part();
	cluster_change_job();
	cluster_change_node();
	cluster_change_bb();

	/* destroy old stuff */
	if (grid_button_list) {
		FREE_NULL_LIST(grid_button_list);
		got_grid = 1;
	}

	select_g_ba_fini();

	/* sorry popups can't survive a cluster change */
	if (popup_list)
		list_flush(popup_list);
	if (signal_params_list)
		list_flush(signal_params_list);
	if (signal_params_list)
		list_flush(signal_params_list);
	if (g_switch_nodes_maps)
		free_switch_nodes_maps(g_switch_nodes_maps);

	/* change the node tab name if needed */
	node_tab = gtk_notebook_get_nth_page(
		GTK_NOTEBOOK(main_notebook), NODE_PAGE);
	node_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(main_notebook),
					      node_tab);
#ifdef GTK2_USE_GET_FOCUS

	/* ok, now we have a table which we have set up to contain an
	 * event_box which contains the label we are interested.  We
	 * setup this label to be the focus child of the table, so all
	 * we have to do is grab that and we are set. */
	node_tab = gtk_container_get_focus_child(GTK_CONTAINER(node_tab));
#else
	/* See above comment.  Since gtk_container_get_focus_child
	 * doesn't exist yet we will just traverse the children until
	 * we find the label widget and then break.
	 */
	{
		int i = 0;
		GList *children = gtk_container_get_children(
			GTK_CONTAINER(node_tab));
		while ((node_tab = g_list_nth_data(children, i++))) {
			int j = 0;
			GList *children2 = gtk_container_get_children(
				GTK_CONTAINER(node_tab));
			while ((node_tab = g_list_nth_data(children2, j++))) {
				if (GTK_IS_LABEL(node_tab))
					break;
			}
			g_list_free(children2);
			if (node_tab)
				break;
		}
		g_list_free(children);
	}
#endif
	if (node_tab)
		gtk_label_set_text(GTK_LABEL(node_tab),
				   main_display_data[NODE_PAGE].name);

	/* The name in the visible tabs is easier since it is really
	   just a button with a label on it.
	*/
	if (default_sview_config.page_check_widget[NODE_PAGE]) {
		gtk_button_set_label(GTK_BUTTON(default_sview_config.
						page_check_widget[NODE_PAGE]),
				     main_display_data[NODE_PAGE].name);
	}

	/* reinit */
	rc = get_system_stats(main_grid_table);

	if (rc == SLURM_SUCCESS) {
		/* It turns out if we didn't have the grid (cluster
		   not responding) before the
		   new grid doesn't get set up correctly.  Redoing the
		   system_stats fixes it.  There is probably a better
		   way of doing this, but it doesn't happen very often
		   and isn't that bad to handle every once in a while.
		*/
		if (!got_grid) {
			/* I know we just did this before, but it
			   needs to be done again here.
			*/
			FREE_NULL_LIST(grid_button_list);
			get_system_stats(main_grid_table);
		}

		refresh_main(NULL, NULL);
	}

	tmp = g_strdup_printf("Cluster changed to %s", cluster_rec->name);
	display_edit_note(tmp);
	g_free(tmp);
}
Exemplo n.º 3
0
extern int configure_defaults(void)
{
	GtkScrolledWindow *window = create_scrolled_window();
	GtkWidget *popup = gtk_dialog_new_with_buttons(
		"Sview Defaults",
		GTK_WINDOW(main_window),
		GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
		NULL);
	GtkWidget *label = gtk_dialog_add_button(GTK_DIALOG(popup),
						 GTK_STOCK_OK, GTK_RESPONSE_OK);
	GtkBin *bin = NULL;
	GtkViewport *view = NULL;
	GtkTable *table = NULL;
	int i = 0, row = 0;
	char tmp_char[100];
	char *tmp_char_ptr;
	display_data_t *display_data = display_data_defaults;
	sview_config_t tmp_config;
	int response = 0;
	int rc = SLURM_SUCCESS;
	uint32_t width = 150;
	uint32_t height = 700;

	apply_hidden_change = TRUE;

	memcpy(&tmp_config, &default_sview_config, sizeof(sview_config_t));
	gtk_window_set_default(GTK_WINDOW(popup), label);
	gtk_dialog_add_button(GTK_DIALOG(popup),
			      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);

	/*
	  for(i=0;; i++) {
	  if (main_popup_positioner[i].width == -1)
	  break;
	  if (strstr("Sview Defaults", main_popup_positioner[i].name)) {
	  pos_x = main_popup_positioner[i].width;
	  pos_y = main_popup_positioner[i].height;
	  break;
	  }
	  }
	*/

	gtk_window_set_default_size(GTK_WINDOW(popup), width, height);
	snprintf(tmp_char, sizeof(tmp_char),
		 "Default Settings for Sview");
	label = gtk_label_new(tmp_char);

	gtk_scrolled_window_set_policy(window,
				       GTK_POLICY_NEVER,
				       GTK_POLICY_AUTOMATIC);
	bin = GTK_BIN(&window->container);
	view = GTK_VIEWPORT(bin->child);
	bin = GTK_BIN(&view->bin);
	table = GTK_TABLE(bin->child);
	gtk_table_resize(table, SORTID_CNT, 2);

	gtk_table_set_homogeneous(table, FALSE);

	for (i = 0; i < SORTID_CNT; i++) {
		while (display_data++) {
			if (display_data->id == -1)
				break;
			if (!display_data->name)
				continue;
			if (display_data->id != i)
				continue;

			_local_display_admin_edit(
				table, &tmp_config, &row,
				display_data);
			break;
		}
		display_data = display_data_defaults;
	}
	gtk_table_resize(table, row, 2);

	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(popup)->vbox),
			   label, FALSE, FALSE, 0);
	if (window)
		gtk_box_pack_start(GTK_BOX(GTK_DIALOG(popup)->vbox),
				   GTK_WIDGET(window), TRUE, TRUE, 0);
	gtk_widget_show_all(popup);
	response = gtk_dialog_run (GTK_DIALOG(popup));
	if (response == GTK_RESPONSE_OK) {
		tmp_char_ptr = g_strdup_printf(
			"Defaults updated successfully");
		if (global_edit_error)
			tmp_char_ptr = global_edit_error_msg;
		else if (!global_send_update_msg)
			tmp_char_ptr = g_strdup_printf(
				"No change detected.");
		else {
			int action = 0;
			gdk_window_set_cursor(main_window->window,
					      in_process_cursor);
			if (tmp_config.ruled_treeview
			    != working_sview_config.ruled_treeview) {
				/* get rid of each existing table */
				cluster_change_block();
				cluster_change_resv();
				cluster_change_part();
				cluster_change_job();
				cluster_change_node();
				cluster_change_front_end();
			} else if (tmp_config.grid_topological !=
				   working_sview_config.grid_topological) {
				apply_hidden_change = FALSE;
				if (tmp_config.grid_topological) {
					default_sview_config.grid_topological =
						tmp_config.grid_topological;
					if (!g_switch_nodes_maps)
						rc = get_topo_conf();
					if (rc != SLURM_SUCCESS) {
						/*denied*/
						tmp_char_ptr = g_strdup_printf(
							"Valid topology not "
							"detected");
						tmp_config.grid_topological =
							FALSE;
						goto denied_change;
					}
				}
				/*force fresh grid and
				 * node state check
				 * */
				FREE_NULL_LIST(grid_button_list);
				slurm_free_node_info_msg(g_node_info_ptr);
				g_node_info_ptr = NULL;
			}


			/*apply change*/

			memcpy(&default_sview_config, &tmp_config,
			       sizeof(sview_config_t));
			memcpy(&working_sview_config, &tmp_config,
			       sizeof(sview_config_t));

			/* set the current display to the default */
			gtk_toggle_action_set_active(
				default_sview_config.action_admin,
				working_sview_config.admin_mode);
			gtk_toggle_action_set_active(
				default_sview_config.action_ruled,
				working_sview_config.ruled_treeview);
			gtk_toggle_action_set_active(
				default_sview_config.action_grid,
				working_sview_config.show_grid);
			gtk_toggle_action_set_active(
				default_sview_config.action_hidden,
				working_sview_config.show_hidden);
			apply_hidden_change = TRUE;
			gtk_toggle_action_set_active(
				default_sview_config.action_page_opts,
				working_sview_config.save_page_opts);
#ifdef GTK2_USE_RADIO_SET
			/* Since this value isn't a simple 0->n we
			   need to translate if we don't have the
			   newer gtk.
			*/
			action = working_sview_config.tab_pos;
#else
			/* If using older gtk we need to translate the
			   tab position to that of the position in the
			   radio list.
			*/
			action = _trans_tab_pos(working_sview_config.tab_pos);
#endif

			sview_radio_action_set_current_value(
				default_sview_config.action_tab, action);


			for (i=0; i<PAGE_CNT; i++) {
				if (main_display_data[i].id == -1)
					break;

				if (!main_display_data[i].name
				    || (i == TAB_PAGE))
					continue;

				toggle_tab_visiblity(NULL, main_display_data+i);
			}
			get_system_stats(main_grid_table);
			/******************************************/
			save_defaults(false);
		}
	denied_change:
		display_edit_note(tmp_char_ptr);
		g_free(tmp_char_ptr);
	}

	global_entry_changed = 0;

	gtk_widget_destroy(popup);

	if (main_window && main_window->window)
		gdk_window_set_cursor(main_window->window, NULL);

	return rc;
}