5 Bacula® - The Network Backup Solution
7 Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
9 The main author of Bacula is Kern Sibbald, with contributions from
10 many others, a complete list can be found in the file AUTHORS.
11 This program is Free Software; you can redistribute it and/or
12 modify it under the terms of version two of the GNU General Public
13 License as published by the Free Software Foundation plus additions
14 that are listed in the file LICENSE.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 Bacula® is a registered trademark of John Walker.
27 The licensor of Bacula is the Free Software Foundation Europe
28 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
29 Switzerland, email:ftf@fsfeurope.org.
40 #include "callbacks.h"
41 #include "interface.h"
44 #define KEY_Enter 65293
46 #define KEY_Down 65364
47 #define KEY_Left 65361
48 #define KEY_Right 65363
50 void terminate_console(int sig);
52 extern "C" gint compare_func(const void *data1, const void *data2);
55 on_console_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
63 on_connect_activate(GtkMenuItem *menuitem, gpointer user_data)
65 if (connect_to_director(user_data)) {
66 start_director_reader(user_data);
72 on_disconnect_activate(GtkMenuItem *menuitem, gpointer user_data)
74 if (disconnect_from_director(user_data)) {
75 stop_director_reader(user_data);
81 on_exit_activate(GtkMenuItem *menuitem, gpointer user_data)
88 on_cut1_activate(GtkMenuItem *menuitem, gpointer user_data)
95 on_copy1_activate(GtkMenuItem *menuitem, gpointer user_data)
102 on_paste1_activate(GtkMenuItem *menuitem, gpointer user_data)
109 on_clear1_activate(GtkMenuItem *menuitem, gpointer user_data)
115 on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
121 on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
123 gtk_widget_show(about1);
129 on_connect_button_clicked(GtkButton *button, gpointer user_data)
131 if (connect_to_director(user_data)) {
132 start_director_reader(user_data);
136 /* Define max length of history and how many to delete when it gets there.
137 * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot.
139 #define HIST_MAX 2500
142 static GList *hist = NULL;
143 static GList *hc = NULL;
144 static int hist_len = 0;
146 static void add_to_history(gchar *ecmd)
148 int len = strlen(ecmd);
151 hist = g_list_append(hist, bstrdup(ecmd));
154 if (hist_len >= HIST_MAX) {
157 for (i=0; i<HIST_DEL; i++) {
158 hp = g_list_next(hist);
160 hist = g_list_remove(hist, hp->data);
162 hist_len -= HIST_DEL;
168 * Note, apparently there is a bug in GNOME where some of the
169 * key press events are lost -- at least it loses every other
173 on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
175 if (event->keyval == KEY_Enter) {
176 char *ecmd = (char *)gtk_entry_get_text((GtkEntry *)entry1);
177 set_text(ecmd, strlen(ecmd));
179 add_to_history(ecmd);
180 write_director(ecmd);
181 gtk_entry_set_text((GtkEntry *)entry1, "");
182 } else if (event->keyval == KEY_Up) {
187 hc = g_list_last(hist);
189 hc = g_list_previous(hc);
195 hc = g_list_first(hist);
197 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
198 } else if (event->keyval == KEY_Down) {
203 hc = g_list_first(hist);
205 hc = g_list_next(hc);
211 hc = g_list_last(hist);
213 gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
215 // gtk_entry_set_position((GtkEntry *)entry1, -1);
216 // gtk_window_set_focus((GtkWindow *)app1, entry1);
222 on_app1_show(GtkWidget *widget, gpointer user_data)
229 on_msgs_button_clicked(GtkButton *button, gpointer user_data)
231 write_director("messages");
235 on_msgs_activate(GtkMenuItem *menuitem, gpointer user_data)
237 write_director("messages");
241 on_about_button_clicked(GtkButton *button, gpointer user_data)
243 gtk_widget_hide(about1);
249 on_select_director_OK_clicked(GtkButton *button, gpointer user_data)
252 gtk_widget_hide(dir_dialog);
259 on_select_director_cancel_clicked(GtkButton *button, gpointer user_data)
262 gtk_widget_hide(dir_dialog);
268 * Compare list string items
271 gint compare_func(const void *data1, const void *data2)
273 return strcmp((const char *)data1, (const char *)data2);
276 static GList *find_combo_list(char *name)
278 if (strcmp(name, "job") == 0) {
281 if (strcmp(name, "pool") == 0) {
284 if (strcmp(name, "client") == 0) {
287 if (strcmp(name, "storage") == 0) {
290 if (strcmp(name, "fileset") == 0) {
293 if (strcmp(name, "messages") == 0) {
294 return messages_list;
296 if (strcmp(name, "type") == 0) {
299 if (strcmp(name, "level") == 0) {
306 * Set correct default values in the Run dialog box
308 static void set_run_defaults()
310 GtkWidget *combo, *entry;
316 stop_director_reader(NULL);
318 combo = lookup_widget(run_dialog, "combo_job");
319 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
320 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
322 while (bnet_recv(UA_sock) > 0) {
323 def = strchr(UA_sock->msg, '=');
328 if (strcmp(UA_sock->msg, "job") == 0 ||
329 strcmp(UA_sock->msg, "when") == 0) {
332 /* Where is an entry box */
333 if (strcmp(UA_sock->msg, "where") == 0) {
334 entry = lookup_widget(run_dialog, "entry_where");
335 gtk_entry_set_text(GTK_ENTRY(entry), def);
339 /* Now handle combo boxes */
340 list = find_combo_list(UA_sock->msg);
344 item = g_list_find_custom(list, def, compare_func);
345 bsnprintf(cmd, sizeof(cmd), "combo_%s", UA_sock->msg);
346 combo = lookup_widget(run_dialog, cmd);
350 pos = g_list_position(list, item);
351 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
353 start_director_reader(NULL);
357 on_entry_job_changed(GtkEditable *editable, gpointer user_data)
364 on_run_button_clicked(GtkButton *button, gpointer user_data)
369 bstrutime(dt, sizeof(dt), time(NULL));
370 entry = lookup_widget(run_dialog, "entry_when");
371 gtk_entry_set_text(GTK_ENTRY(entry), dt);
373 gtk_widget_show(run_dialog);
378 static char *get_combo_text(GtkWidget *dialog, const char *combo_name)
381 combo = lookup_widget(dialog, combo_name);
385 return (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
388 static char *get_entry_text(GtkWidget *dialog, const char *entry_name)
391 entry = lookup_widget(dialog, entry_name);
395 return (char *)gtk_entry_get_text(GTK_ENTRY(entry));
398 static char *get_spin_text(GtkWidget *dialog, const char *spin_name)
401 spin = (GtkSpinButton *)lookup_widget(dialog, spin_name);
405 return (char *)gtk_entry_get_text(GTK_ENTRY(&spin->entry));
412 on_run_ok_clicked(GtkButton *button, gpointer user_data)
414 char *job, *fileset, *level, *client, *pool, *when, *where, *storage, *priority;
416 gtk_widget_hide(run_dialog);
419 job = get_combo_text(run_dialog, "combo_job");
420 fileset = get_combo_text(run_dialog, "combo_fileset");
421 client = get_combo_text(run_dialog, "combo_client");
422 pool = get_combo_text(run_dialog, "combo_pool");
423 storage = get_combo_text(run_dialog, "combo_storage");
424 level = get_combo_text(run_dialog, "combo_level");
425 priority = get_spin_text(run_dialog, "spinbutton1");
426 when = get_entry_text(run_dialog, "entry_when");
427 where = get_entry_text(run_dialog, "entry_where");
429 if (!job || !fileset || !client || !pool || !storage ||
430 !level || !priority || !when || !where) {
435 bsnprintf(cmd, sizeof(cmd),
436 "run job=\"%s\" fileset=\"%s\" level=%s client=\"%s\" pool=\"%s\" "
437 "when=\"%s\" where=\"%s\" storage=\"%s\" priority=\"%s\"",
438 job, fileset, level, client, pool, when, where, storage, priority);
440 set_text(cmd, strlen(cmd));
441 write_director("yes");
447 on_run_cancel_clicked(GtkButton *button, gpointer user_data)
449 gtk_widget_hide(run_dialog);
455 on_entry1_key_release_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
461 on_restore_button_clicked(GtkButton *button, gpointer user_data)
463 gtk_widget_show(restore_dialog);
468 on_view_fileset_clicked(GtkButton *button, gpointer user_data)
474 on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
476 gtk_widget_hide(restore_dialog);
483 on_label_button_clicked(GtkButton *button, gpointer user_data)
485 gtk_widget_show(label_dialog);
490 on_label_ok_clicked(GtkButton *button, gpointer user_data)
492 char *pool, *volume, *storage, *slot;
494 gtk_widget_hide(label_dialog);
497 pool = get_combo_text(label_dialog, "label_combo_pool");
498 storage = get_combo_text(label_dialog, "label_combo_storage");
500 volume = get_entry_text(label_dialog, "label_entry_volume");
502 slot = get_spin_text(label_dialog, "label_slot");
504 if (!pool || !storage || !volume || !(*volume)) {
509 bsnprintf(cmd, sizeof(cmd),
510 "label volume=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s",
511 volume, pool, storage, slot);
513 set_text(cmd, strlen(cmd));
518 on_label_cancel_clicked(GtkButton *button, gpointer user_data)
520 gtk_widget_hide(label_dialog);
527 on_select_files_button_clicked(GtkButton *button, gpointer user_data)
529 char *job, *fileset, *client, *pool, *before, *storage;
531 gtk_widget_hide(restore_dialog);
533 job = get_combo_text(restore_dialog, "combo_restore_job");
534 fileset = get_combo_text(restore_dialog, "combo_restore_fileset");
535 client = get_combo_text(restore_dialog, "combo_restore_client");
536 pool = get_combo_text(restore_dialog, "combo_restore_pool");
537 storage = get_combo_text(restore_dialog, "combo_restore_storage");
539 before = get_entry_text(restore_dialog, "restore_before_entry");
541 if (!job || !fileset || !client || !pool || !storage || !before) {
546 bsnprintf(cmd, sizeof(cmd),
547 "restore select current fileset=\"%s\" client=\"%s\" pool=\"%s\" "
548 "storage=\"%s\"", fileset, client, pool, storage);
550 set_text(cmd, strlen(cmd));
551 gtk_widget_show(restore_file_selection);
552 select_restore_files(); /* put up select files dialog */
556 on_restore_select_ok_clicked(GtkButton *button, gpointer user_data)
558 gtk_widget_hide(restore_file_selection);
559 write_director("done");
566 on_restore_select_cancel_clicked(GtkButton *button, gpointer user_data)
568 gtk_widget_hide(restore_file_selection);
569 write_director("quit");
575 on_restore_files_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
577 gtk_widget_hide(restore_file_selection);
585 on_new1_activate (GtkMenuItem *menuitem,
593 on_open1_activate (GtkMenuItem *menuitem,
601 on_save1_activate (GtkMenuItem *menuitem,
609 on_save_as1_activate (GtkMenuItem *menuitem,
617 on_quit1_activate (GtkMenuItem *menuitem,
625 on_cut2_activate (GtkMenuItem *menuitem,
633 on_copy2_activate (GtkMenuItem *menuitem,
641 on_paste2_activate (GtkMenuItem *menuitem,
649 on_clear2_activate (GtkMenuItem *menuitem,
657 on_properties1_activate (GtkMenuItem *menuitem,
665 on_preferences2_activate (GtkMenuItem *menuitem,
673 on_about2_activate (GtkMenuItem *menuitem,
680 * Set correct default values in the Restore dialog box
682 void set_restore_dialog_defaults()
690 stop_director_reader(NULL);
692 combo = lookup_widget(restore_dialog, "combo_restore_job");
693 job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
694 bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
696 while (bnet_recv(UA_sock) > 0) {
697 def = strchr(UA_sock->msg, '=');
702 if (strcmp(UA_sock->msg, "job") == 0 ||
703 strcmp(UA_sock->msg, "when") == 0 ||
704 strcmp(UA_sock->msg, "where") == 0 ||
705 strcmp(UA_sock->msg, "messages") == 0 ||
706 strcmp(UA_sock->msg, "level") == 0 ||
707 strcmp(UA_sock->msg, "type") == 0) {
711 /* Now handle combo boxes */
712 list = find_combo_list(UA_sock->msg);
716 item = g_list_find_custom(list, def, compare_func);
717 bsnprintf(cmd, sizeof(cmd), "combo_restore_%s", UA_sock->msg);
718 combo = lookup_widget(restore_dialog, cmd);
722 pos = g_list_position(list, item);
723 gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
725 start_director_reader(NULL);
730 on_restore_job_entry_changed(GtkEditable *editable, gpointer user_data)
732 /* Set defaults that correspond to new job selection */
733 set_restore_dialog_defaults();
737 on_dir_button_clicked(GtkButton *toolbutton, gpointer user_data)
739 write_director("status dir");