]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/gnome2-console/callbacks.c
Fix bat to automatically use installed bat.conf
[bacula/bacula] / bacula / src / gnome2-console / callbacks.c
index 782e35906b1567df260e3860f751ae5d63e5ff20..7e1295a7923d7267f3463bd984d70c05ffd416c6 100644 (file)
@@ -1,6 +1,34 @@
-/* 
+/*
  *    Version $Id$
  */
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
+
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #include "support.h"
 
 #define KEY_Enter 65293
-#define KEY_Up   65362
+#define KEY_Up    65362
 #define KEY_Down  65364
 #define KEY_Left  65361
 #define KEY_Right 65363
 
+void terminate_console(int sig);
+
+extern "C" gint compare_func(const void *data1, const void *data2);
+
 gboolean
-on_app1_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
+on_console_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
 {
    gtk_main_quit();
-   return FALSE;
+   terminate_console(0);
+   return TRUE;
 }
 
 void
@@ -78,14 +111,6 @@ on_clear1_activate(GtkMenuItem *menuitem, gpointer user_data)
 
 }
 
-
-void
-on_properties1_activate(GtkMenuItem *menuitem, gpointer user_data)
-{
-
-}
-
-
 void
 on_preferences1_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
@@ -108,8 +133,8 @@ on_connect_button_clicked(GtkButton *button, gpointer user_data)
    }
 }
 
-/* Define max length of history and how many to delete when it gets there.  
- * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot. 
+/* Define max length of history and how many to delete when it gets there.
+ * If you make HIST_DEL > HIST_MAX, you shoot yourself in the foot.
  */
 #define HIST_MAX 2500
 #define HIST_DEL  500
@@ -130,13 +155,13 @@ static void add_to_history(gchar *ecmd)
       int i;
       GList *hp;
       for (i=0; i<HIST_DEL; i++) {
-        hp = g_list_next(hist);
-        free(hp->data);
-        hist = g_list_remove(hist, hp->data);
+         hp = g_list_next(hist);
+         free(hp->data);
+         hist = g_list_remove(hist, hp->data);
       }
       hist_len -= HIST_DEL;
    }
-   hc = NULL;            
+   hc = NULL;
 }
 
 /*
@@ -156,26 +181,39 @@ on_entry1_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer user_d
       gtk_entry_set_text((GtkEntry *)entry1, "");
    } else if (event->keyval == KEY_Up) {
       if (!hc) {
-        hc = g_list_last(hist);
+         if (!hist) {
+            return FALSE;
+         }
+         hc = g_list_last(hist);
       } else {
-        hc = g_list_previous(hc);
+         hc = g_list_previous(hc);
       }
       if (!hc) {
-        hc = g_list_first(hist);
+         if (!hist) {
+            return FALSE;
+         }
+         hc = g_list_first(hist);
       }
       gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
    } else if (event->keyval == KEY_Down) {
       if (!hc) {
-        hc = g_list_first(hist);
+         if (!hist) {
+            return FALSE;
+         }
+         hc = g_list_first(hist);
       } else {
-        hc = g_list_next(hc);
+         hc = g_list_next(hc);
       }
       if (!hc) {
-        hc = g_list_last(hist);
+         if (!hist) {
+            return FALSE;
+         }
+         hc = g_list_last(hist);
       }
       gtk_entry_set_text((GtkEntry *)entry1, (gchar *)hc->data);
    }
-   gtk_window_set_focus((GtkWindow *)app1, entry1);
+// gtk_entry_set_position((GtkEntry *)entry1, -1);
+// gtk_window_set_focus((GtkWindow *)app1, entry1);
    return FALSE;
 }
 
@@ -229,7 +267,8 @@ on_select_director_cancel_clicked(GtkButton *button, gpointer user_data)
 /*
  * Compare list string items
  */
-static gint compare_func(const void *data1, const void *data2)
+extern "C"
+gint compare_func(const void *data1, const void *data2)
 {
    return strcmp((const char *)data1, (const char *)data2);
 }
@@ -283,30 +322,30 @@ static void set_run_defaults()
    while (bnet_recv(UA_sock) > 0) {
       def = strchr(UA_sock->msg, '=');
       if (!def) {
-        continue;
+         continue;
       }
       *def++ = 0;
       if (strcmp(UA_sock->msg, "job") == 0 ||
           strcmp(UA_sock->msg, "when") == 0) {
-        continue;
+         continue;
       }
       /* Where is an entry box */
       if (strcmp(UA_sock->msg, "where") == 0) {
          entry = lookup_widget(run_dialog, "entry_where");
-        gtk_entry_set_text(GTK_ENTRY(entry), def);
-        continue;
+         gtk_entry_set_text(GTK_ENTRY(entry), def);
+         continue;
       }
 
       /* Now handle combo boxes */
       list = find_combo_list(UA_sock->msg);
       if (!list) {
-        continue;
+         continue;
       }
       item = g_list_find_custom(list, def, compare_func);
       bsnprintf(cmd, sizeof(cmd), "combo_%s", UA_sock->msg);
       combo = lookup_widget(run_dialog, cmd);
       if (!combo) {
-        continue;
+         continue;
       }
       pos = g_list_position(list, item);
       gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
@@ -336,7 +375,7 @@ on_run_button_clicked(GtkButton *button, gpointer user_data)
 }
 
 
-static char *get_combo_text(GtkWidget *dialog, char *combo_name)
+static char *get_combo_text(GtkWidget *dialog, const char *combo_name)
 {
    GtkWidget *combo;
    combo = lookup_widget(dialog, combo_name);
@@ -346,7 +385,7 @@ static char *get_combo_text(GtkWidget *dialog, char *combo_name)
    return (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
 }
 
-static char *get_entry_text(GtkWidget *dialog, char *entry_name)
+static char *get_entry_text(GtkWidget *dialog, const char *entry_name)
 {
    GtkWidget *entry;
    entry = lookup_widget(dialog, entry_name);
@@ -356,7 +395,7 @@ static char *get_entry_text(GtkWidget *dialog, char *entry_name)
    return (char *)gtk_entry_get_text(GTK_ENTRY(entry));
 }
 
-static char *get_spin_text(GtkWidget *dialog, char *spin_name)
+static char *get_spin_text(GtkWidget *dialog, const char *spin_name)
 {
    GtkSpinButton *spin;
    spin = (GtkSpinButton *)lookup_widget(dialog, spin_name);
@@ -372,8 +411,8 @@ static char *get_spin_text(GtkWidget *dialog, char *spin_name)
 void
 on_run_ok_clicked(GtkButton *button, gpointer user_data)
 {
-   char *job, *fileset, *level, *client, *pool, *when, *where, *storage;
-
+   char *job, *fileset, *level, *client, *pool, *when, *where, *storage, *priority;
+   
    gtk_widget_hide(run_dialog);
    gtk_main_quit();
 
@@ -383,21 +422,22 @@ on_run_ok_clicked(GtkButton *button, gpointer user_data)
    pool    = get_combo_text(run_dialog, "combo_pool");
    storage = get_combo_text(run_dialog, "combo_storage");
    level   = get_combo_text(run_dialog, "combo_level");
-
+   priority = get_spin_text(run_dialog, "spinbutton1");
    when    = get_entry_text(run_dialog, "entry_when");
    where   = get_entry_text(run_dialog, "entry_where");
 
    if (!job || !fileset || !client || !pool || !storage ||
-       !level || !when || !where) {
+       !level || !priority || !when || !where) {
       set_status_ready();
       return;
    }
-      
-   bsnprintf(cmd, sizeof(cmd), 
+
+   bsnprintf(cmd, sizeof(cmd),
              "run job=\"%s\" fileset=\"%s\" level=%s client=\"%s\" pool=\"%s\" "
-             "when=\"%s\" where=\"%s\" storage=\"%s\"", 
-            job, fileset, level, client, pool, when, where, storage);
+             "when=\"%s\" where=\"%s\" storage=\"%s\" priority=\"%s\"\n",
+             job, fileset, level, client, pool, when, where, storage, priority);
    write_director(cmd);
+   set_text(cmd, strlen(cmd));
    write_director("yes");
    return;
 }
@@ -429,14 +469,6 @@ on_view_fileset_clicked(GtkButton *button, gpointer user_data)
 {
 }
 
-void
-on_restore_ok_clicked(GtkButton *button, gpointer user_data)
-{
-   gtk_widget_hide(restore_dialog);
-   gtk_main_quit();
-   set_status_ready();
-}
-
 
 void
 on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
@@ -446,19 +478,6 @@ on_restore_cancel_clicked(GtkButton *button, gpointer user_data)
    set_status_ready();
 }
 
-void
-on_apply_button_clicked(GtkButton *button, gpointer user_data)
-{
-   gtk_widget_show(restore_files);
-   gtk_main();
-}
-
-void
-on_restore_file_clicked(GtkButton *button, gpointer user_data)
-{
-   gtk_widget_hide(restore_files);
-   gtk_main_quit();
-}
 
 void
 on_label_button_clicked(GtkButton *button, gpointer user_data)
@@ -486,11 +505,12 @@ on_label_ok_clicked(GtkButton *button, gpointer user_data)
       set_status_ready();
       return;
    }
-      
-   bsnprintf(cmd, sizeof(cmd), 
-             "label name=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s", 
-            volume, pool, storage, slot);
+
+   bsnprintf(cmd, sizeof(cmd),
+             "label volume=\"%s\" pool=\"%s\" storage=\"%s\" slot=%s\n", 
+             volume, pool, storage, slot);
    write_director(cmd);
+   set_text(cmd, strlen(cmd));
 }
 
 
@@ -501,3 +521,220 @@ on_label_cancel_clicked(GtkButton *button, gpointer user_data)
    gtk_main_quit();
    set_status_ready();
 }
+
+
+void
+on_select_files_button_clicked(GtkButton *button, gpointer user_data)
+{
+   char *job, *fileset, *client, *pool, *before, *storage;
+
+   gtk_widget_hide(restore_dialog);
+
+   job     = get_combo_text(restore_dialog, "combo_restore_job");
+   fileset = get_combo_text(restore_dialog, "combo_restore_fileset");
+   client  = get_combo_text(restore_dialog, "combo_restore_client");
+   pool    = get_combo_text(restore_dialog, "combo_restore_pool");
+   storage = get_combo_text(restore_dialog, "combo_restore_storage");
+
+   before  = get_entry_text(restore_dialog, "restore_before_entry");
+
+   if (!job || !fileset || !client || !pool || !storage || !before) {
+      set_status_ready();
+      return;
+   }
+
+   bsnprintf(cmd, sizeof(cmd),
+             "restore select current fileset=\"%s\" client=\"%s\" pool=\"%s\" "
+             "storage=\"%s\"\n", fileset, client, pool, storage);
+   write_director(cmd);
+   set_text(cmd, strlen(cmd));
+   gtk_widget_show(restore_file_selection);
+   select_restore_files();            /* put up select files dialog */
+}
+
+void
+on_restore_select_ok_clicked(GtkButton *button, gpointer user_data)
+{
+   gtk_widget_hide(restore_file_selection);
+   write_director("done");
+   gtk_main_quit();
+   set_status_ready();
+}
+
+
+void
+on_restore_select_cancel_clicked(GtkButton *button, gpointer user_data)
+{
+   gtk_widget_hide(restore_file_selection);
+   write_director("quit");
+   gtk_main_quit();
+   set_status_ready();
+}
+
+gboolean
+on_restore_files_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+   gtk_widget_hide(restore_file_selection);
+   gtk_main_quit();
+   set_status_ready();
+   return FALSE;
+}
+
+
+void
+on_new1_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_open1_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_save1_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_save_as1_activate                   (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_quit1_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_cut2_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_copy2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_paste2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_clear2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_properties1_activate                (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_preferences2_activate               (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_about2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+/*
+ * Set correct default values in the Restore dialog box
+ */
+void set_restore_dialog_defaults()
+{
+   GtkWidget *combo;
+   char *job, *def;
+   GList *item, *list;
+   char cmd[1000];
+   int pos;
+
+   stop_director_reader(NULL);
+
+   combo = lookup_widget(restore_dialog, "combo_restore_job");
+   job = (char *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo)->entry));
+   bsnprintf(cmd, sizeof(cmd), ".defaults job=\"%s\"", job);
+   write_director(cmd);
+   while (bnet_recv(UA_sock) > 0) {
+      def = strchr(UA_sock->msg, '=');
+      if (!def) {
+         continue;
+      }
+      *def++ = 0;
+      if (strcmp(UA_sock->msg, "job") == 0 ||
+          strcmp(UA_sock->msg, "when") == 0 ||
+          strcmp(UA_sock->msg, "where") == 0 ||
+          strcmp(UA_sock->msg, "messages") == 0 ||
+          strcmp(UA_sock->msg, "level") == 0 ||
+          strcmp(UA_sock->msg, "type") == 0) {
+         continue;
+      }
+
+      /* Now handle combo boxes */
+      list = find_combo_list(UA_sock->msg);
+      if (!list) {
+         continue;
+      }
+      item = g_list_find_custom(list, def, compare_func);
+      bsnprintf(cmd, sizeof(cmd), "combo_restore_%s", UA_sock->msg);
+      combo = lookup_widget(restore_dialog, cmd);
+      if (!combo) {
+         continue;
+      }
+      pos = g_list_position(list, item);
+      gtk_list_select_item(GTK_LIST(GTK_COMBO(combo)->list), pos);
+   }
+   start_director_reader(NULL);
+}
+
+
+void
+on_restore_job_entry_changed(GtkEditable *editable, gpointer user_data)
+{
+   /* Set defaults that correspond to new job selection */
+   set_restore_dialog_defaults();
+}
+
+void
+on_dir_button_clicked(GtkButton *toolbutton, gpointer user_data)
+{
+   write_director("status dir");
+}