]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/gnome2-console/console.c
Add missing ;
[bacula/bacula] / bacula / src / gnome2-console / console.c
index 63f3925ed141a60c32b09f355f92f833c913694f..1fb76c08d4eded258c87f46eaadb72d6675e585b 100644 (file)
@@ -40,6 +40,7 @@ GtkWidget *text1;          /* text window */
 GtkWidget *entry1;          /* entry box */
 GtkWidget *status1;         /* status bar */
 GtkWidget *combo1;          /* director combo */
+GtkWidget *scroll1;         /* main scroll bar */
 GtkWidget *run_dialog;      /* run dialog */
 GtkWidget *dir_dialog;      /* director selection dialog */
 GtkWidget *restore_dialog;   /* restore dialog */
@@ -48,10 +49,10 @@ GtkWidget *dir_select;
 GtkWidget *about1;          /* about box */
 GtkWidget *label_dialog;
 GdkFont   *text_font = NULL;
+PangoFontDescription *font_desc;
 pthread_mutex_t cmd_mutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t cmd_wait;
 char cmd[1000];
-int cmd_ready = FALSE;
 int reply;
 BSOCK *UA_sock = NULL;
 GList *job_list, *client_list, *fileset_list;
@@ -62,6 +63,7 @@ GList *type_list, *level_list;
 static void terminate_console(int sig);
 static gint message_handler(gpointer data);
 static int initial_connect_to_director(gpointer data);
+static void set_scroll_bar_to_end(void);
 
 /* Static variables */
 static char *configfile = NULL;
@@ -69,9 +71,9 @@ static DIRRES *dir;
 static CONRES *con; 
 static int ndir;
 static int director_reader_running = FALSE;
-static int at_prompt = FALSE;
-static int ready = FALSE;
-static int quit = FALSE;
+static bool at_prompt = false;
+static bool ready = false;
+static bool quit = false;
 static guint initial;
 
 #define CONFIG_FILE "./gnome-console.conf"   /* default configuration file */
@@ -79,14 +81,14 @@ static guint initial;
 static void usage()
 {
    fprintf(stderr, _(
-"\nVersion: " VERSION " (" BDATE ")\n\n"
+"\nVersion: " VERSION " (" BDATE ") %s %s %s\n\n"
 "Usage: gnome-console [-s] [-c config_file] [-d debug_level] [config_file]\n"
 "       -c <file>   set configuration file to file\n"
 "       -dnn        set debug level to nn\n"
 "       -s          no signals\n"
 "       -t          test - read configuration and exit\n"
 "       -?          print this message.\n"
-"\n"));
+"\n"), HOST_OS, DISTNAME, DISTVER);
 
    exit(1);
 }
@@ -187,7 +189,7 @@ Without that I don't how to speak to the Director :-(\n"), configfile);
 
 
    app1 = create_app1();
-   gtk_window_set_default_size(GTK_WINDOW(app1), 500, 700);
+   gtk_window_set_default_size(GTK_WINDOW(app1), 800, 700);
    run_dialog = create_RunDialog();
    label_dialog = create_label_dialog();
    restore_dialog = create_restore_dialog();
@@ -199,6 +201,7 @@ Without that I don't how to speak to the Director :-(\n"), configfile);
    text1 = lookup_widget(app1, "text1");
    entry1 = lookup_widget(app1, "entry1");
    status1 = lookup_widget(app1, "status1");
+   scroll1 = lookup_widget(app1, "scroll1");
 
 /*
  * Thanks to Phil Stracchino for providing the font configuration code.
@@ -228,11 +231,18 @@ Without that I don't how to speak to the Director :-(\n"), configfile);
               "-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-1");
        text_font = gdk_font_load("-misc-fixed-medium-r-normal-*-*-130-*-*-c-*-iso8859-1");
    }
+   font_desc = pango_font_description_from_string("LucidaTypewriter 9");
+   gtk_widget_modify_font (app1, font_desc);
+   gtk_widget_modify_font (text1, font_desc);
+   gtk_widget_modify_font (entry1, font_desc);
+   gtk_widget_modify_font (status1, font_desc);
+   pango_font_description_free (font_desc);
+
 
    initial = gtk_timeout_add(100, initial_connect_to_director, (gpointer)NULL);
 
    gtk_main();
-   quit = TRUE;
+   quit = true;
    disconnect_from_director((gpointer)NULL);
    return 0;
 }
@@ -376,12 +386,12 @@ int connect_to_director(gpointer data)
 
    memset(&jcr, 0, sizeof(jcr));
    
-   set_statusf(_(" Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
-   set_textf(_("Connecting to Director %s:%d\n"), dir->address,dir->DIRport);
+   set_statusf(_(" Connecting to Director %s:%d"), dir->address,dir->DIRport);
+   set_textf(_("Connecting to Director %s:%d\n\n"), dir->address,dir->DIRport);
 
-// while (gtk_events_pending()) {     /* fully paint screen */
-//    gtk_main_iteration();
-// }
+   while (gtk_events_pending()) {     /* fully paint screen */
+      gtk_main_iteration();
+   }
    UA_sock = bnet_connect(NULL, 5, 15, "Director daemon", dir->address, 
                          NULL, dir->DIRport, 0);
    if (UA_sock == NULL) {
@@ -428,7 +438,7 @@ int connect_to_director(gpointer data)
 void write_director(gchar *msg)
 {
    if (UA_sock) {
-      at_prompt = FALSE;
+      at_prompt = false;
       set_status(_(" Processing command ..."));
       UA_sock->msglen = strlen(msg);
       pm_strcpy(&UA_sock->msg, msg);
@@ -451,7 +461,7 @@ void read_director(gpointer data, gint fd, GdkInputCondition condition)
    if (stat >= 0) {
       if (at_prompt) {
          set_text("\n", 1);
-        at_prompt = FALSE;
+        at_prompt = false;
       }
       set_text(UA_sock->msg, UA_sock->msglen);
       return;
@@ -462,7 +472,7 @@ void read_director(gpointer data, gint fd, GdkInputCondition condition)
    }
    /* Must be a signal -- either do something or ignore it */
    if (UA_sock->msglen == BNET_PROMPT) {
-      at_prompt = TRUE;
+      at_prompt = true;
       set_status(_(" At prompt waiting for input ..."));
    }
    if (UA_sock->msglen == BNET_EOD) {
@@ -515,11 +525,19 @@ static int text_chars = 0;
 
 static void truncate_text_chars()
 {
+   GtkTextBuffer *textbuf;
+   GtkTextIter iter, iter2;
+   guint len;
    int del_chars = MAX_TEXT_CHARS / 4;
-   gtk_text_set_point(GTK_TEXT(text1), del_chars);
-   gtk_text_backward_delete(GTK_TEXT(text1), del_chars);
+
+   textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text1));
+   len = gtk_text_buffer_get_char_count(textbuf);
+   gtk_text_buffer_get_iter_at_offset (textbuf, &iter, 0);
+   gtk_text_buffer_get_iter_at_offset (textbuf, &iter2, del_chars);
+   gtk_text_buffer_delete (textbuf, &iter, &iter2);
    text_chars -= del_chars;
-   gtk_text_set_point(GTK_TEXT(text1), text_chars);
+   len = gtk_text_buffer_get_char_count(textbuf);
+   gtk_text_iter_set_offset(&iter, len);
 }
 
 void set_textf(char *fmt, ...)
@@ -529,16 +547,25 @@ void set_textf(char *fmt, ...)
    int len;
    va_start(arg_ptr, fmt);
    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+   va_end(arg_ptr);
    set_text(buf, len);
 }
 
 void set_text(char *buf, int len)
 {
-   gtk_text_insert(GTK_TEXT(text1), text_font, NULL, NULL, buf, -1);
+   GtkTextBuffer *textbuf;
+   GtkTextIter iter;
+   guint buf_len;
+
+   textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text1));
+   buf_len = gtk_text_buffer_get_char_count(textbuf);
+   gtk_text_buffer_get_iter_at_offset(textbuf, &iter, buf_len - 1);
+   gtk_text_buffer_insert(textbuf, &iter, buf, -1);
    text_chars += len;
    if (text_chars > MAX_TEXT_CHARS) {
       truncate_text_chars();
    }
+   set_scroll_bar_to_end();
 }
 
 void set_statusf(char *fmt, ...)
@@ -548,18 +575,38 @@ void set_statusf(char *fmt, ...)
    int len;
    va_start(arg_ptr, fmt);
    len = bvsnprintf(buf, sizeof(buf), fmt, arg_ptr);
+   va_end(arg_ptr);
    gtk_label_set_text(GTK_LABEL(status1), buf);
-   ready = FALSE;
+// set_scroll_bar_to_end();
+   ready = false;
 }
 
 void set_status_ready()    
 {
    gtk_label_set_text(GTK_LABEL(status1), " Ready");
-   ready = TRUE;
+   ready = true;
+// set_scroll_bar_to_end();
 }
 
 void set_status(char *buf)
 {
    gtk_label_set_text(GTK_LABEL(status1), buf);
-   ready = FALSE;
+// set_scroll_bar_to_end();
+   ready = false;
+}
+
+static void set_scroll_bar_to_end(void)
+{
+   GtkTextBuffer* textbuf = NULL;
+   GtkTextIter iter;
+   guint buf_len;
+
+   textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text1));
+   buf_len = gtk_text_buffer_get_char_count(textbuf);
+   gtk_text_buffer_get_iter_at_offset(textbuf, &iter, buf_len - 1);
+   gtk_text_iter_set_offset(&iter, buf_len);
+   gtk_text_buffer_place_cursor(textbuf, &iter);
+   gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text1),
+              gtk_text_buffer_get_mark(textbuf, "insert"), 
+             0, TRUE, 0.0, 1.0);
 }