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
22 void terminate_console(int sig);
25 on_console_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
32 on_connect_activate(GtkMenuItem *menuitem, gpointer user_data)
34 if (connect_to_director(user_data)) {
35 start_director_reader(user_data);
41 on_disconnect_activate(GtkMenuItem *menuitem, gpointer user_data)
43 if (disconnect_from_director(user_data)) {
44 stop_director_reader(user_data);
50 on_exit_activate(GtkMenuItem *menuitem, gpointer user_data)
57 on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
64 on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
71 on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
78 on_clear1_activate(GtkMenuItem *menuitem, gpointer user_data)
84 on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
90 on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
92 gtk_widget_show(about1);
98 on_connect_button_clicked(GtkButton *button, gpointer user_data)
100 if (connect_to_director(user_data)) {
101 start_director_reader(user_data);
105 /* Define max length of history and how many to delete when it gets there.
106 * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot.
108 #define HIST_MAX 2500
111 static GList *hist = NULL;
112 static GList *hc = NULL;
113 static int hist_len = 0;
115 static void add_to_history(gchar *ecmd)
117 int len = strlen(ecmd);
120 hist = g_list_append(hist, bstrdup(ecmd));
123 if (hist_len >= HIST_MAX) {
126 for (i=0; i<HIST_DEL; i++) {
127 hp = g_list_next(hist);
129 hist = g_list_remove(hist, hp->data);
131 hist_len -= HIST_DEL;
137 * Note, apparently there is a bug in GNOME where some of the
138 * key press events are lost -- at least it loses every other
142 on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
144 if (event->keyval == KEY_Enter) {
145 char *ecmd = (char *)gtk_entry_get_text((GtkEntry *)entry1);
146 set_text(ecmd, strlen(ecmd));
148 add_to_history(ecmd);
149 write_director(ecmd);
150 gtk_entry_set_text((GtkEntry *)entry1, "");
151 } else if (event->keyval == KEY_Up) {
153 hc = g_list_last(hist);
155 hc = g_list_previous(hc);
158 hc = g_list_first(hist);
160 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
161 } else if (event->keyval == KEY_Down) {
163 hc = g_list_first(hist);
165 hc = g_list_next(hc);
168 hc = g_list_last(hist);
170 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
172 // gtk_entry_set_position((GtkEntry *)entry1, -1);
173 // gtk_window_set_focus((GtkWindow *)app1, entry1);
179 on_app1_show(GtkWidget *widget, gpointer user_data)
186 on_msgs_button_clicked(GtkButton *button, gpointer user_data)
188 write_director("messages");
192 on_msgs_activate(GtkMenuItem *menuitem, gpointer user_data)
194 write_director("messages");
198 on_about_button_clicked(GtkButton *button, gpointer user_data)
200 gtk_widget_hide(about1);
206 on_select_director_OK_clicked(GtkButton *button, gpointer user_data)
209 gtk_widget_hide(dir_dialog);
216 on_select_director_cancel_clicked(GtkButton *button, gpointer user_data)
219 gtk_widget_hide(dir_dialog);
225 * Compare list string items
227 static gint compare_func(const void *data1, const void *data2)
229 return strcmp((const char *)data1, (const char *)data2);
232 static GList *find_combo_list(char *name)
234 if (strcmp(name, "job") == 0) {
237 if (strcmp(name, "pool") == 0) {
240 if (strcmp(name, "client") == 0) {
243 if (strcmp(name, "storage") == 0) {
246 if (strcmp(name, "fileset") == 0) {
249 if (strcmp(name, "messages") == 0) {
250 return messages_list;
252 if (strcmp(name, "type") == 0) {
255 if (strcmp(name, "level") == 0) {
262 * Set correct default values in the Run dialog box
264 static void set_run_defaults()
266 GtkWidget *combo, *entry;
272 stop_director_reader(NULL);
274 combo = lookup_widget(run_dialog, "combo_job");
275 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
276 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
278 while (bnet_recv(UA_sock) > 0) {
279 def = strchr(UA_sock->msg, '=');
284 if (strcmp(UA_sock->msg, "job") == 0 ||
285 strcmp(UA_sock->msg, "when") == 0) {
288 /* Where is an entry box */
289 if (strcmp(UA_sock->msg, "where") == 0) {
290 entry = lookup_widget(run_dialog, "entry_where");
291 gtk_entry_set_text(GTK_ENTRY(entry), def);
295 /* Now handle combo boxes */
296 list = find_combo_list(UA_sock->msg);
300 item = g_list_find_custom(list, def, compare_func);
301 bsnprintf(cmd, sizeof(cmd), "combo_%s", UA_sock->msg);
302 combo = lookup_widget(run_dialog, cmd);
306 pos = g_list_position(list, item);
307 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
309 start_director_reader(NULL);
313 on_entry_job_changed(GtkEditable *editable, gpointer user_data)
320 on_run_button_clicked(GtkButton *button, gpointer user_data)
325 bstrutime(dt, sizeof(dt), time(NULL));
326 entry = lookup_widget(run_dialog, "entry_when");
327 gtk_entry_set_text(GTK_ENTRY(entry), dt);
329 gtk_widget_show(run_dialog);
334 static char *get_combo_text(GtkWidget *dialog, const char *combo_name)
337 combo = lookup_widget(dialog, combo_name);
341 return (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
344 static char *get_entry_text(GtkWidget *dialog, const char *entry_name)
347 entry = lookup_widget(dialog, entry_name);
351 return (char *)gtk_entry_get_text(GTK_ENTRY(entry));
354 static char *get_spin_text(GtkWidget *dialog, const char *spin_name)
357 spin = (GtkSpinButton *)lookup_widget(dialog, spin_name);
361 return (char *)gtk_entry_get_text(GTK_ENTRY(&spin->entry));
368 on_run_ok_clicked(GtkButton *button, gpointer user_data)
370 char *job, *fileset, *level, *client, *pool, *when, *where, *storage;
372 gtk_widget_hide(run_dialog);
375 job = get_combo_text(run_dialog, "combo_job");
376 fileset = get_combo_text(run_dialog, "combo_fileset");
377 client = get_combo_text(run_dialog, "combo_client");
378 pool = get_combo_text(run_dialog, "combo_pool");
379 storage = get_combo_text(run_dialog, "combo_storage");
380 level = get_combo_text(run_dialog, "combo_level");
382 when = get_entry_text(run_dialog, "entry_when");
383 where = get_entry_text(run_dialog, "entry_where");
385 if (!job || !fileset || !client || !pool || !storage ||
386 !level || !when || !where) {
391 bsnprintf(cmd, sizeof(cmd),
392 "run job=\"%s\" fileset=\"%s\" level=%s client=\"%s\" pool=\"%s\" "
393 "when=\"%s\" where=\"%s\" storage=\"%s\"",
394 job, fileset, level, client, pool, when, where, storage);
396 set_text(cmd, strlen(cmd));
397 write_director("yes");
403 on_run_cancel_clicked(GtkButton *button, gpointer user_data)
405 gtk_widget_hide(run_dialog);
411 on_entry1_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
417 on_restore_button_clicked(GtkButton *button, gpointer user_data)
419 gtk_widget_show(restore_dialog);
424 on_view_fileset_clicked(GtkButton *button, gpointer user_data)
430 on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
432 gtk_widget_hide(restore_dialog);
439 on_label_button_clicked(GtkButton *button, gpointer user_data)
441 gtk_widget_show(label_dialog);
446 on_label_ok_clicked(GtkButton *button, gpointer user_data)
448 char *pool, *volume, *storage, *slot;
450 gtk_widget_hide(label_dialog);
453 pool = get_combo_text(label_dialog, "label_combo_pool");
454 storage = get_combo_text(label_dialog, "label_combo_storage");
456 volume = get_entry_text(label_dialog, "label_entry_volume");
458 slot = get_spin_text(label_dialog, "label_slot");
460 if (!pool || !storage || !volume || !(*volume)) {
465 bsnprintf(cmd, sizeof(cmd),
466 "label name=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s",
467 volume, pool, storage, slot);
469 set_text(cmd, strlen(cmd));
474 on_label_cancel_clicked(GtkButton *button, gpointer user_data)
476 gtk_widget_hide(label_dialog);
483 on_select_files_button_clicked(GtkButton *button, gpointer user_data)
485 char *job, *fileset, *client, *pool, *before, *storage;
487 gtk_widget_hide(restore_dialog);
489 job = get_combo_text(restore_dialog, "combo_restore_job");
490 fileset = get_combo_text(restore_dialog, "combo_restore_fileset");
491 client = get_combo_text(restore_dialog, "combo_restore_client");
492 pool = get_combo_text(restore_dialog, "combo_restore_pool");
493 storage = get_combo_text(restore_dialog, "combo_restore_storage");
495 before = get_entry_text(restore_dialog, "restore_before_entry");
497 if (!job || !fileset || !client || !pool || !storage || !before) {
502 bsnprintf(cmd, sizeof(cmd),
503 "restore select current fileset=\"%s\" client=\"%s\" pool=\"%s\" "
504 "storage=\"%s\"", fileset, client, pool, storage);
506 set_text(cmd, strlen(cmd));
507 gtk_widget_show(restore_file_selection);
508 select_restore_files(); /* put up select files dialog */
512 on_restore_select_ok_clicked(GtkButton *button, gpointer user_data)
514 gtk_widget_hide(restore_file_selection);
515 write_director("done");
522 on_restore_select_cancel_clicked(GtkButton *button, gpointer user_data)
524 gtk_widget_hide(restore_file_selection);
525 write_director("quit");
531 on_restore_files_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
533 gtk_widget_hide(restore_file_selection);
541 on_new1_activate (GtkMenuItem *menuitem,
549 on_open1_activate (GtkMenuItem *menuitem,
557 on_save1_activate (GtkMenuItem *menuitem,
565 on_save_as1_activate (GtkMenuItem *menuitem,
573 on_quit1_activate (GtkMenuItem *menuitem,
581 on_cut2_activate (GtkMenuItem *menuitem,
589 on_copy2_activate (GtkMenuItem *menuitem,
597 on_paste2_activate (GtkMenuItem *menuitem,
605 on_clear2_activate (GtkMenuItem *menuitem,
613 on_properties1_activate (GtkMenuItem *menuitem,
621 on_preferences2_activate (GtkMenuItem *menuitem,
629 on_about2_activate (GtkMenuItem *menuitem,
636 * Set correct default values in the Restore dialog box
638 void set_restore_dialog_defaults()
646 stop_director_reader(NULL);
648 combo = lookup_widget(restore_dialog, "combo_restore_job");
649 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
650 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
652 while (bnet_recv(UA_sock) > 0) {
653 def = strchr(UA_sock->msg, '=');
658 if (strcmp(UA_sock->msg, "job") == 0 ||
659 strcmp(UA_sock->msg, "when") == 0 ||
660 strcmp(UA_sock->msg, "where") == 0 ||
661 strcmp(UA_sock->msg, "messages") == 0 ||
662 strcmp(UA_sock->msg, "level") == 0 ||
663 strcmp(UA_sock->msg, "type") == 0) {
667 /* Now handle combo boxes */
668 list = find_combo_list(UA_sock->msg);
672 item = g_list_find_custom(list, def, compare_func);
673 bsnprintf(cmd, sizeof(cmd), "combo_restore_%s", UA_sock->msg);
674 combo = lookup_widget(restore_dialog, cmd);
678 pos = g_list_position(list, item);
679 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
681 start_director_reader(NULL);
686 on_restore_job_entry_changed(GtkEditable *editable, gpointer user_data)
688 /* Set defaults that correspond to new job selection */
689 set_restore_dialog_defaults();