2 Copyright (C) 2000-2006 Kern Sibbald
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as amended with additional clauses defined in the
7 file LICENSE in the main source directory.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 the file LICENSE for additional details.
25 #include "callbacks.h"
26 #include "interface.h"
29 #define KEY_Enter 65293
31 #define KEY_Down 65364
32 #define KEY_Left 65361
33 #define KEY_Right 65363
35 void terminate_console(int sig);
37 extern "C" gint compare_func(const void *data1, const void *data2);
40 on_console_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
48 on_connect_activate(GtkMenuItem *menuitem, gpointer user_data)
50 if (connect_to_director(user_data)) {
51 start_director_reader(user_data);
57 on_disconnect_activate(GtkMenuItem *menuitem, gpointer user_data)
59 if (disconnect_from_director(user_data)) {
60 stop_director_reader(user_data);
66 on_exit_activate(GtkMenuItem *menuitem, gpointer user_data)
73 on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
80 on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
87 on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
94 on_clear1_activate(GtkMenuItem *menuitem, gpointer user_data)
100 on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
106 on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
108 gtk_widget_show(about1);
114 on_connect_button_clicked(GtkButton *button, gpointer user_data)
116 if (connect_to_director(user_data)) {
117 start_director_reader(user_data);
121 /* Define max length of history and how many to delete when it gets there.
122 * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot.
124 #define HIST_MAX 2500
127 static GList *hist = NULL;
128 static GList *hc = NULL;
129 static int hist_len = 0;
131 static void add_to_history(gchar *ecmd)
133 int len = strlen(ecmd);
136 hist = g_list_append(hist, bstrdup(ecmd));
139 if (hist_len >= HIST_MAX) {
142 for (i=0; i<HIST_DEL; i++) {
143 hp = g_list_next(hist);
145 hist = g_list_remove(hist, hp->data);
147 hist_len -= HIST_DEL;
153 * Note, apparently there is a bug in GNOME where some of the
154 * key press events are lost -- at least it loses every other
158 on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
160 if (event->keyval == KEY_Enter) {
161 char *ecmd = (char *)gtk_entry_get_text((GtkEntry *)entry1);
162 set_text(ecmd, strlen(ecmd));
164 add_to_history(ecmd);
165 write_director(ecmd);
166 gtk_entry_set_text((GtkEntry *)entry1, "");
167 } else if (event->keyval == KEY_Up) {
172 hc = g_list_last(hist);
174 hc = g_list_previous(hc);
180 hc = g_list_first(hist);
182 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
183 } else if (event->keyval == KEY_Down) {
188 hc = g_list_first(hist);
190 hc = g_list_next(hc);
196 hc = g_list_last(hist);
198 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
200 // gtk_entry_set_position((GtkEntry *)entry1, -1);
201 // gtk_window_set_focus((GtkWindow *)app1, entry1);
207 on_app1_show(GtkWidget *widget, gpointer user_data)
214 on_msgs_button_clicked(GtkButton *button, gpointer user_data)
216 write_director("messages");
220 on_msgs_activate(GtkMenuItem *menuitem, gpointer user_data)
222 write_director("messages");
226 on_about_button_clicked(GtkButton *button, gpointer user_data)
228 gtk_widget_hide(about1);
234 on_select_director_OK_clicked(GtkButton *button, gpointer user_data)
237 gtk_widget_hide(dir_dialog);
244 on_select_director_cancel_clicked(GtkButton *button, gpointer user_data)
247 gtk_widget_hide(dir_dialog);
253 * Compare list string items
256 gint compare_func(const void *data1, const void *data2)
258 return strcmp((const char *)data1, (const char *)data2);
261 static GList *find_combo_list(char *name)
263 if (strcmp(name, "job") == 0) {
266 if (strcmp(name, "pool") == 0) {
269 if (strcmp(name, "client") == 0) {
272 if (strcmp(name, "storage") == 0) {
275 if (strcmp(name, "fileset") == 0) {
278 if (strcmp(name, "messages") == 0) {
279 return messages_list;
281 if (strcmp(name, "type") == 0) {
284 if (strcmp(name, "level") == 0) {
291 * Set correct default values in the Run dialog box
293 static void set_run_defaults()
295 GtkWidget *combo, *entry;
301 stop_director_reader(NULL);
303 combo = lookup_widget(run_dialog, "combo_job");
304 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
305 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
307 while (bnet_recv(UA_sock) > 0) {
308 def = strchr(UA_sock->msg, '=');
313 if (strcmp(UA_sock->msg, "job") == 0 ||
314 strcmp(UA_sock->msg, "when") == 0) {
317 /* Where is an entry box */
318 if (strcmp(UA_sock->msg, "where") == 0) {
319 entry = lookup_widget(run_dialog, "entry_where");
320 gtk_entry_set_text(GTK_ENTRY(entry), def);
324 /* Now handle combo boxes */
325 list = find_combo_list(UA_sock->msg);
329 item = g_list_find_custom(list, def, compare_func);
330 bsnprintf(cmd, sizeof(cmd), "combo_%s", UA_sock->msg);
331 combo = lookup_widget(run_dialog, cmd);
335 pos = g_list_position(list, item);
336 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
338 start_director_reader(NULL);
342 on_entry_job_changed(GtkEditable *editable, gpointer user_data)
349 on_run_button_clicked(GtkButton *button, gpointer user_data)
354 bstrutime(dt, sizeof(dt), time(NULL));
355 entry = lookup_widget(run_dialog, "entry_when");
356 gtk_entry_set_text(GTK_ENTRY(entry), dt);
358 gtk_widget_show(run_dialog);
363 static char *get_combo_text(GtkWidget *dialog, const char *combo_name)
366 combo = lookup_widget(dialog, combo_name);
370 return (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
373 static char *get_entry_text(GtkWidget *dialog, const char *entry_name)
376 entry = lookup_widget(dialog, entry_name);
380 return (char *)gtk_entry_get_text(GTK_ENTRY(entry));
383 static char *get_spin_text(GtkWidget *dialog, const char *spin_name)
386 spin = (GtkSpinButton *)lookup_widget(dialog, spin_name);
390 return (char *)gtk_entry_get_text(GTK_ENTRY(&spin->entry));
397 on_run_ok_clicked(GtkButton *button, gpointer user_data)
399 char *job, *fileset, *level, *client, *pool, *when, *where, *storage, *priority;
401 gtk_widget_hide(run_dialog);
404 job = get_combo_text(run_dialog, "combo_job");
405 fileset = get_combo_text(run_dialog, "combo_fileset");
406 client = get_combo_text(run_dialog, "combo_client");
407 pool = get_combo_text(run_dialog, "combo_pool");
408 storage = get_combo_text(run_dialog, "combo_storage");
409 level = get_combo_text(run_dialog, "combo_level");
410 priority = get_spin_text(run_dialog, "spinbutton1");
411 when = get_entry_text(run_dialog, "entry_when");
412 where = get_entry_text(run_dialog, "entry_where");
414 if (!job || !fileset || !client || !pool || !storage ||
415 !level || !priority || !when || !where) {
420 bsnprintf(cmd, sizeof(cmd),
421 "run job=\"%s\" fileset=\"%s\" level=%s client=\"%s\" pool=\"%s\" "
422 "when=\"%s\" where=\"%s\" storage=\"%s\" priority=\"%s\"",
423 job, fileset, level, client, pool, when, where, storage, priority);
425 set_text(cmd, strlen(cmd));
426 write_director("yes");
432 on_run_cancel_clicked(GtkButton *button, gpointer user_data)
434 gtk_widget_hide(run_dialog);
440 on_entry1_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
446 on_restore_button_clicked(GtkButton *button, gpointer user_data)
448 gtk_widget_show(restore_dialog);
453 on_view_fileset_clicked(GtkButton *button, gpointer user_data)
459 on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
461 gtk_widget_hide(restore_dialog);
468 on_label_button_clicked(GtkButton *button, gpointer user_data)
470 gtk_widget_show(label_dialog);
475 on_label_ok_clicked(GtkButton *button, gpointer user_data)
477 char *pool, *volume, *storage, *slot;
479 gtk_widget_hide(label_dialog);
482 pool = get_combo_text(label_dialog, "label_combo_pool");
483 storage = get_combo_text(label_dialog, "label_combo_storage");
485 volume = get_entry_text(label_dialog, "label_entry_volume");
487 slot = get_spin_text(label_dialog, "label_slot");
489 if (!pool || !storage || !volume || !(*volume)) {
494 bsnprintf(cmd, sizeof(cmd),
495 "label volume=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s",
496 volume, pool, storage, slot);
498 set_text(cmd, strlen(cmd));
503 on_label_cancel_clicked(GtkButton *button, gpointer user_data)
505 gtk_widget_hide(label_dialog);
512 on_select_files_button_clicked(GtkButton *button, gpointer user_data)
514 char *job, *fileset, *client, *pool, *before, *storage;
516 gtk_widget_hide(restore_dialog);
518 job = get_combo_text(restore_dialog, "combo_restore_job");
519 fileset = get_combo_text(restore_dialog, "combo_restore_fileset");
520 client = get_combo_text(restore_dialog, "combo_restore_client");
521 pool = get_combo_text(restore_dialog, "combo_restore_pool");
522 storage = get_combo_text(restore_dialog, "combo_restore_storage");
524 before = get_entry_text(restore_dialog, "restore_before_entry");
526 if (!job || !fileset || !client || !pool || !storage || !before) {
531 bsnprintf(cmd, sizeof(cmd),
532 "restore select current fileset=\"%s\" client=\"%s\" pool=\"%s\" "
533 "storage=\"%s\"", fileset, client, pool, storage);
535 set_text(cmd, strlen(cmd));
536 gtk_widget_show(restore_file_selection);
537 select_restore_files(); /* put up select files dialog */
541 on_restore_select_ok_clicked(GtkButton *button, gpointer user_data)
543 gtk_widget_hide(restore_file_selection);
544 write_director("done");
551 on_restore_select_cancel_clicked(GtkButton *button, gpointer user_data)
553 gtk_widget_hide(restore_file_selection);
554 write_director("quit");
560 on_restore_files_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
562 gtk_widget_hide(restore_file_selection);
570 on_new1_activate (GtkMenuItem *menuitem,
578 on_open1_activate (GtkMenuItem *menuitem,
586 on_save1_activate (GtkMenuItem *menuitem,
594 on_save_as1_activate (GtkMenuItem *menuitem,
602 on_quit1_activate (GtkMenuItem *menuitem,
610 on_cut2_activate (GtkMenuItem *menuitem,
618 on_copy2_activate (GtkMenuItem *menuitem,
626 on_paste2_activate (GtkMenuItem *menuitem,
634 on_clear2_activate (GtkMenuItem *menuitem,
642 on_properties1_activate (GtkMenuItem *menuitem,
650 on_preferences2_activate (GtkMenuItem *menuitem,
658 on_about2_activate (GtkMenuItem *menuitem,
665 * Set correct default values in the Restore dialog box
667 void set_restore_dialog_defaults()
675 stop_director_reader(NULL);
677 combo = lookup_widget(restore_dialog, "combo_restore_job");
678 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
679 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
681 while (bnet_recv(UA_sock) > 0) {
682 def = strchr(UA_sock->msg, '=');
687 if (strcmp(UA_sock->msg, "job") == 0 ||
688 strcmp(UA_sock->msg, "when") == 0 ||
689 strcmp(UA_sock->msg, "where") == 0 ||
690 strcmp(UA_sock->msg, "messages") == 0 ||
691 strcmp(UA_sock->msg, "level") == 0 ||
692 strcmp(UA_sock->msg, "type") == 0) {
696 /* Now handle combo boxes */
697 list = find_combo_list(UA_sock->msg);
701 item = g_list_find_custom(list, def, compare_func);
702 bsnprintf(cmd, sizeof(cmd), "combo_restore_%s", UA_sock->msg);
703 combo = lookup_widget(restore_dialog, cmd);
707 pos = g_list_position(list, item);
708 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
710 start_director_reader(NULL);
715 on_restore_job_entry_changed(GtkEditable *editable, gpointer user_data)
717 /* Set defaults that correspond to new job selection */
718 set_restore_dialog_defaults();
722 on_dir_button_clicked(GtkButton *toolbutton, gpointer user_data)
724 write_director("status dir");