12 #include "callbacks.h"
13 #include "interface.h"
16 #define KEY_Enter 65293
18 #define KEY_Down 65364
19 #define KEY_Left 65361
20 #define KEY_Right 65363
23 on_app1_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
30 on_connect_activate(GtkMenuItem *menuitem, gpointer user_data)
32 if (connect_to_director(user_data)) {
33 start_director_reader(user_data);
39 on_disconnect_activate(GtkMenuItem *menuitem, gpointer user_data)
41 if (disconnect_from_director(user_data)) {
42 stop_director_reader(user_data);
48 on_exit_activate(GtkMenuItem *menuitem, gpointer user_data)
55 on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
62 on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
69 on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
76 on_clear1_activate(GtkMenuItem *menuitem, gpointer user_data)
83 on_properties1_activate(GtkMenuItem *menuitem, gpointer user_data)
90 on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
96 on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
98 gtk_widget_show(about1);
104 on_connect_button_clicked(GtkButton *button, gpointer user_data)
106 if (connect_to_director(user_data)) {
107 start_director_reader(user_data);
111 /* Define max length of history and how many to delete when it gets there.
112 * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot.
114 #define HIST_MAX 2500
117 static GList *hist = NULL;
118 static GList *hc = NULL;
119 static int hist_len = 0;
121 static void add_to_history(gchar *ecmd)
123 int len = strlen(ecmd);
126 hist = g_list_append(hist, bstrdup(ecmd));
129 if (hist_len >= HIST_MAX) {
132 for (i=0; i<HIST_DEL; i++) {
133 hp = g_list_next(hist);
135 hist = g_list_remove(hist, hp->data);
137 hist_len -= HIST_DEL;
143 * Note, apparently there is a bug in GNOME where some of the
144 * key press events are lost -- at least it loses every other
148 on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
150 if (event->keyval == KEY_Enter) {
151 char *ecmd = (char *)gtk_entry_get_text((GtkEntry *)entry1);
152 set_text(ecmd, strlen(ecmd));
154 add_to_history(ecmd);
155 write_director(ecmd);
156 gtk_entry_set_text((GtkEntry *)entry1, "");
157 } else if (event->keyval == KEY_Up) {
159 hc = g_list_last(hist);
161 hc = g_list_previous(hc);
164 hc = g_list_first(hist);
166 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
167 } else if (event->keyval == KEY_Down) {
169 hc = g_list_first(hist);
171 hc = g_list_next(hc);
174 hc = g_list_last(hist);
176 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
178 // gtk_entry_set_position((GtkEntry *)entry1, -1);
179 // gtk_window_set_focus((GtkWindow *)app1, entry1);
185 on_app1_show(GtkWidget *widget, gpointer user_data)
192 on_msgs_button_clicked(GtkButton *button, gpointer user_data)
194 write_director("messages");
198 on_msgs_activate(GtkMenuItem *menuitem, gpointer user_data)
200 write_director("messages");
204 on_about_button_clicked(GtkButton *button, gpointer user_data)
206 gtk_widget_hide(about1);
212 on_select_director_OK_clicked(GtkButton *button, gpointer user_data)
215 gtk_widget_hide(dir_dialog);
222 on_select_director_cancel_clicked(GtkButton *button, gpointer user_data)
225 gtk_widget_hide(dir_dialog);
231 * Compare list string items
233 static gint compare_func(const void *data1, const void *data2)
235 return strcmp((const char *)data1, (const char *)data2);
238 static GList *find_combo_list(char *name)
240 if (strcmp(name, "job") == 0) {
243 if (strcmp(name, "pool") == 0) {
246 if (strcmp(name, "client") == 0) {
249 if (strcmp(name, "storage") == 0) {
252 if (strcmp(name, "fileset") == 0) {
255 if (strcmp(name, "messages") == 0) {
256 return messages_list;
258 if (strcmp(name, "type") == 0) {
261 if (strcmp(name, "level") == 0) {
268 * Set correct default values in the Run dialog box
270 static void set_run_defaults()
272 GtkWidget *combo, *entry;
278 stop_director_reader(NULL);
280 combo = lookup_widget(run_dialog, "combo_job");
281 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
282 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
284 while (bnet_recv(UA_sock) > 0) {
285 def = strchr(UA_sock->msg, '=');
290 if (strcmp(UA_sock->msg, "job") == 0 ||
291 strcmp(UA_sock->msg, "when") == 0) {
294 /* Where is an entry box */
295 if (strcmp(UA_sock->msg, "where") == 0) {
296 entry = lookup_widget(run_dialog, "entry_where");
297 gtk_entry_set_text(GTK_ENTRY(entry), def);
301 /* Now handle combo boxes */
302 list = find_combo_list(UA_sock->msg);
306 item = g_list_find_custom(list, def, compare_func);
307 bsnprintf(cmd, sizeof(cmd), "combo_%s", UA_sock->msg);
308 combo = lookup_widget(run_dialog, cmd);
312 pos = g_list_position(list, item);
313 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
315 start_director_reader(NULL);
319 on_entry_job_changed(GtkEditable *editable, gpointer user_data)
326 on_run_button_clicked(GtkButton *button, gpointer user_data)
331 bstrutime(dt, sizeof(dt), time(NULL));
332 entry = lookup_widget(run_dialog, "entry_when");
333 gtk_entry_set_text(GTK_ENTRY(entry), dt);
335 gtk_widget_show(run_dialog);
340 static char *get_combo_text(GtkWidget *dialog, char *combo_name)
343 combo = lookup_widget(dialog, combo_name);
347 return (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
350 static char *get_entry_text(GtkWidget *dialog, char *entry_name)
353 entry = lookup_widget(dialog, entry_name);
357 return (char *)gtk_entry_get_text(GTK_ENTRY(entry));
360 static char *get_spin_text(GtkWidget *dialog, char *spin_name)
363 spin = (GtkSpinButton *)lookup_widget(dialog, spin_name);
367 return (char *)gtk_entry_get_text(GTK_ENTRY(&spin->entry));
374 on_run_ok_clicked(GtkButton *button, gpointer user_data)
376 char *job, *fileset, *level, *client, *pool, *when, *where, *storage;
378 gtk_widget_hide(run_dialog);
381 job = get_combo_text(run_dialog, "combo_job");
382 fileset = get_combo_text(run_dialog, "combo_fileset");
383 client = get_combo_text(run_dialog, "combo_client");
384 pool = get_combo_text(run_dialog, "combo_pool");
385 storage = get_combo_text(run_dialog, "combo_storage");
386 level = get_combo_text(run_dialog, "combo_level");
388 when = get_entry_text(run_dialog, "entry_when");
389 where = get_entry_text(run_dialog, "entry_where");
391 if (!job || !fileset || !client || !pool || !storage ||
392 !level || !when || !where) {
397 bsnprintf(cmd, sizeof(cmd),
398 "run job=\"%s\" fileset=\"%s\" level=%s client=\"%s\" pool=\"%s\" "
399 "when=\"%s\" where=\"%s\" storage=\"%s\"",
400 job, fileset, level, client, pool, when, where, storage);
402 write_director("yes");
408 on_run_cancel_clicked(GtkButton *button, gpointer user_data)
410 gtk_widget_hide(run_dialog);
416 on_entry1_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
422 on_restore_button_clicked(GtkButton *button, gpointer user_data)
424 gtk_widget_show(restore_dialog);
429 on_view_fileset_clicked(GtkButton *button, gpointer user_data)
434 on_restore_ok_clicked(GtkButton *button, gpointer user_data)
436 gtk_widget_hide(restore_dialog);
443 on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
445 gtk_widget_hide(restore_dialog);
451 on_apply_button_clicked(GtkButton *button, gpointer user_data)
453 gtk_widget_show(restore_files);
458 on_restore_file_clicked(GtkButton *button, gpointer user_data)
460 gtk_widget_hide(restore_files);
465 on_label_button_clicked(GtkButton *button, gpointer user_data)
467 gtk_widget_show(label_dialog);
472 on_label_ok_clicked(GtkButton *button, gpointer user_data)
474 char *pool, *volume, *storage, *slot;
476 gtk_widget_hide(label_dialog);
479 pool = get_combo_text(label_dialog, "label_combo_pool");
480 storage = get_combo_text(label_dialog, "label_combo_storage");
482 volume = get_entry_text(label_dialog, "label_entry_volume");
484 slot = get_spin_text(label_dialog, "label_slot");
486 if (!pool || !storage || !volume || !(*volume)) {
491 bsnprintf(cmd, sizeof(cmd),
492 "label name=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s",
493 volume, pool, storage, slot);
499 on_label_cancel_clicked(GtkButton *button, gpointer user_data)
501 gtk_widget_hide(label_dialog);