+static void show_info_dialog(struct gui *ui, const char *title,
+ const char *message)
+{
+ GtkWidget *dialog, *content, *label;
+
+ dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+
+ content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ label = gtk_label_new(message);
+ gtk_container_add(GTK_CONTAINER(content), label);
+ gtk_widget_show_all(dialog);
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+}
+
+/*
+ * Update sensitivity of job buttons and job menu items, based on the
+ * state of the client.
+ */
+static void update_button_states(struct gui *ui, struct gui_entry *ge)
+{
+ unsigned int connect_state, send_state, start_state, edit_state;
+ const char *connect_str = NULL;
+ GtkWidget *w;
+
+ switch (ge->state) {
+ default: {
+ char tmp[80];
+
+ sprintf(tmp, "Bad client state: %u\n", ge->state);
+ show_info_dialog(ui, "Error", tmp);
+ /* fall through to new state */
+ }
+
+ case GE_STATE_NEW:
+ connect_state = 1;
+ edit_state = 0;
+ connect_str = "Connect";
+ send_state = 0;
+ start_state = 0;
+ break;
+ case GE_STATE_CONNECTED:
+ connect_state = 1;
+ edit_state = 0;
+ connect_str = "Disconnect";
+ send_state = 1;
+ start_state = 0;
+ break;
+ case GE_STATE_JOB_SENT:
+ connect_state = 1;
+ edit_state = 0;
+ connect_str = "Disconnect";
+ send_state = 0;
+ start_state = 1;
+ break;
+ case GE_STATE_JOB_STARTED:
+ connect_state = 1;
+ edit_state = 1;
+ connect_str = "Disconnect";
+ send_state = 0;
+ start_state = 1;
+ break;
+ case GE_STATE_JOB_RUNNING:
+ connect_state = 1;
+ edit_state = 0;
+ connect_str = "Disconnect";
+ send_state = 0;
+ start_state = 0;
+ break;
+ case GE_STATE_JOB_DONE:
+ connect_state = 1;
+ edit_state = 0;
+ connect_str = "Connect";
+ send_state = 0;
+ start_state = 0;
+ break;
+ }
+
+ gtk_widget_set_sensitive(ge->button[CONNECT_BUTTON], connect_state);
+ gtk_widget_set_sensitive(ge->button[SEND_BUTTON], send_state);
+ gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], start_state);
+ gtk_button_set_label(GTK_BUTTON(ge->button[CONNECT_BUTTON]), connect_str);
+
+ /*
+ * So the below doesn't work at all, how to set those menu items
+ * invisibible...
+ */
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Connect");
+ gtk_widget_set_sensitive(w, connect_state);
+ gtk_menu_item_set_label(GTK_MENU_ITEM(w), connect_str);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Edit job");
+ gtk_widget_set_sensitive(w, edit_state);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Send job");
+ gtk_widget_set_sensitive(w, send_state);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Start job");
+ gtk_widget_set_sensitive(w, start_state);
+}
+
+static void gfio_set_state(struct gui_entry *ge, unsigned int state)
+{
+ ge->state = state;
+ update_button_states(ge->ui, ge);
+}
+