+/*
+ * 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");
+ if (w)
+ gtk_widget_set_sensitive(w, connect_state);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Edit Job");
+ if (w)
+ gtk_widget_set_sensitive(w, edit_state);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Send Job");
+ if (w)
+ gtk_widget_set_sensitive(w, send_state);
+
+ w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Start Job");
+ if (w)
+ 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);
+}
+