]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tray-monitor/tray-monitor.c
Fix typo.
[bacula/bacula] / bacula / src / tray-monitor / tray-monitor.c
index a20e9ca9a2af64914c8e252a291a44bf58b8fed7..4037272618160337acb7f11974e2ffa47bd37c6a 100644 (file)
@@ -1,44 +1,43 @@
-/*
- *
- *   Bacula Gnome Tray Monitor
- *
- *     Nicolas Boichat, August MMIV
- *
- *     Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2004-2009 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 plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero 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
+   You should have received a copy of the GNU Affero 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 John Walker.
+   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.
 */
+/*
+ *
+ *   Bacula Gnome Tray Monitor
+ *
+ *     Nicolas Boichat, August MMIV
+ *
+ *     Version $Id$
+ */
+
 
 #include "bacula.h"
 #include "tray-monitor.h"
 
-#include "eggstatusicon.h"
-
 #include "generic.xpm"
 
 #define TRAY_DEBUG_MEMORY 0
@@ -47,6 +46,7 @@
 int authenticate_director(JCR *jcr, MONITOR *monitor, DIRRES *director);
 int authenticate_file_daemon(JCR *jcr, MONITOR *monitor, CLIENT* client);
 int authenticate_storage_daemon(JCR *jcr, MONITOR *monitor, STORE* store);
+extern bool parse_tmon_config(CONFIG *config, const char *configfile, int exit_code);
 
 /* Dummy functions */
 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
@@ -64,6 +64,7 @@ static int nitems = 0;
 static int fullitem = 0; //Item to be display in detailled status window
 static int lastupdated = -1; //Last item updated
 static monitoritem items[32];
+static CONFIG *config;
 
 /* Data received from DIR/FD/SD */
 static char OKqstatus[]   = "%c000 OK .status\n";
@@ -92,15 +93,18 @@ static void DaemonChanged(GtkWidget *widget, monitoritem* data);
 static gboolean delete_event(GtkWidget *widget, GdkEvent  *event, gpointer   data);
 
 static guint timerTag;
-static EggStatusIcon *mTrayIcon;
+static GtkStatusIcon *mTrayIcon;
 static GtkWidget *mTrayMenu;
 static GtkWidget *window;
 static GtkWidget *textview;
 static GtkTextBuffer *buffer;
 static GtkWidget *timeoutspinner;
+static GtkWidget *scrolledWindow;
 char** xpm_generic_var;
 static gboolean blinkstate = TRUE;
 
+PangoFontDescription *font_desc = NULL;
+
 #define CONFIG_FILE "./tray-monitor.conf"   /* default configuration file */
 
 static void usage()
@@ -111,14 +115,16 @@ PROG_COPYRIGHT
 "\nVersion: %s (%s) %s %s %s\n\n"
 "Usage: tray-monitor [-c config_file] [-d debug_level]\n"
 "       -c <file>     set configuration file to file\n"
-"       -dnn          set debug level to nn\n"
+"       -d <nn>       set debug level to <nn>\n"
+"       -dt           print timestamp in debug output\n"
 "       -t            test - read configuration and exit\n"
 "       -?            print this message.\n"
 "\n"), 2004, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
 }
 
 static GtkWidget *new_image_button(const gchar *stock_id,
-                                   const gchar *label_text) {
+                                   const gchar *label_text)
+{
     GtkWidget *button;
     GtkWidget *box;
     GtkWidget *label;
@@ -188,6 +194,7 @@ int main(int argc, char *argv[])
    DIRRES* dird;
    CLIENT* filed;
    STORE* stored;
+   CONFONTRES *con_font;
 
    setlocale(LC_ALL, "");
    bindtextdomain("bacula", LOCALEDIR);
@@ -204,7 +211,7 @@ int main(int argc, char *argv[])
    sigfillset(&sigignore.sa_mask);
    sigaction(SIGPIPE, &sigignore, NULL);
 
-   gtk_init (&argc, &argv);
+   gtk_init(&argc, &argv);
 
    while ((ch = getopt(argc, argv, "bc:d:th?f:s:")) != -1) {
       switch (ch) {
@@ -216,9 +223,13 @@ int main(int argc, char *argv[])
          break;
 
       case 'd':
-         debug_level = atoi(optarg);
-         if (debug_level <= 0) {
-            debug_level = 1;
+         if (*optarg == 't') {
+            dbg_timestamp = true;
+         } else {
+            debug_level = atoi(optarg);
+            if (debug_level <= 0) {
+               debug_level = 1;
+            }
          }
          break;
 
@@ -245,7 +256,8 @@ int main(int argc, char *argv[])
       configfile = bstrdup(CONFIG_FILE);
    }
 
-   parse_config(configfile);
+   config = new_config_parser();
+   parse_tmon_config(config, configfile, M_ERROR_TERM);
 
    LockRes();
    nitems = 0;
@@ -255,7 +267,7 @@ int main(int argc, char *argv[])
 
    if (nitems != 1) {
       Emsg2(M_ERROR_TERM, 0,
-         _("Error: %d Monitor resource defined in %s. You must define one and only one Monitor resource.\n"), nitems, configfile);
+         _("Error: %d Monitor resources defined in %s. You must define one and only one Monitor resource.\n"), nitems, configfile);
    }
 
    nitems = 0;
@@ -286,7 +298,7 @@ int main(int argc, char *argv[])
    UnlockRes();
 
    if (nitems == 0) {
-      Emsg1(M_ERROR_TERM, 0, _("No Client, Storage nor Director resource defined in %s\n"
+      Emsg1(M_ERROR_TERM, 0, _("No Client, Storage or Director resource defined in %s\n"
 "Without that I don't how to get status from the File, Storage or Director Daemon :-(\n"), configfile);
    }
 
@@ -313,8 +325,9 @@ int main(int argc, char *argv[])
    }
 
    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_xpm_data(generateXPM(warn, warn));
-   // This should be ideally replaced by a completely libpr0n-based icon rendering.
-   mTrayIcon = egg_status_icon_new_from_pixbuf(pixbuf);
+
+   mTrayIcon = gtk_status_icon_new_from_pixbuf(pixbuf);
+   gtk_status_icon_set_tooltip(mTrayIcon, _("Bacula daemon status monitor"));
    g_signal_connect(G_OBJECT(mTrayIcon), "activate", G_CALLBACK(TrayIconActivate), NULL);
    g_signal_connect(G_OBJECT(mTrayIcon), "popup-menu", G_CALLBACK(TrayIconPopupMenu), NULL);
    g_object_unref(G_OBJECT(pixbuf));
@@ -337,7 +350,7 @@ int main(int argc, char *argv[])
 
    timerTag = g_timeout_add( 1000*monitor->RefreshInterval/nitems, fd_read, NULL );
 
-   g_timeout_add( 1000, blink, NULL );
+   g_timeout_add( 1000, blink, NULL);
 
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
@@ -405,14 +418,47 @@ int main(int argc, char *argv[])
    }
 
    gtk_box_pack_start(GTK_BOX(vbox), daemon_table, FALSE, FALSE, 0);
-
+  
    textview = gtk_text_view_new();
 
+   scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
+   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+   gtk_container_add(GTK_CONTAINER (scrolledWindow), textview);
+   
    buffer = gtk_text_buffer_new(NULL);
 
    gtk_text_buffer_set_text(buffer, "", -1);
 
-   PangoFontDescription *font_desc = pango_font_description_from_string ("Fixed 10");
+  /*
+   * Gtk2/pango have different font names. Gnome2 comes with "Monospace 10"
+   */
+
+   LockRes();
+   foreach_res(con_font, R_CONSOLE_FONT) {
+       if (!con_font->fontface) {
+          Dmsg1(400, "No fontface for %s\n", con_font->hdr.name);
+          continue;
+       }
+       Dmsg1(100, "Now loading: %s\n",con_font->fontface);
+       font_desc = pango_font_description_from_string(con_font->fontface);
+       if (font_desc == NULL) {
+           Dmsg2(400, "Load of requested ConsoleFont \"%s\" (%s) failed!\n",
+                  con_font->hdr.name, con_font->fontface);
+       } else {
+           Dmsg2(400, "ConsoleFont \"%s\" (%s) loaded.\n",
+                  con_font->hdr.name, con_font->fontface);
+           break;
+       }
+   }
+   UnlockRes();
+
+   if (!font_desc) {
+      font_desc = pango_font_description_from_string("Monospace 10");
+   }
+   if (!font_desc) {
+      font_desc = pango_font_description_from_string("monospace");
+   }
+
    gtk_widget_modify_font(textview, font_desc);
    pango_font_description_free(font_desc);
 
@@ -423,7 +469,7 @@ int main(int argc, char *argv[])
 
    gtk_text_view_set_buffer(GTK_TEXT_VIEW(textview), buffer);
 
-   gtk_box_pack_start(GTK_BOX(vbox), textview, TRUE, TRUE, 0);
+   gtk_box_pack_start(GTK_BOX(vbox), scrolledWindow, TRUE, TRUE, 0);
 
    GtkWidget* hbox = gtk_hbox_new(FALSE, 10);
 
@@ -491,6 +537,9 @@ int main(int argc, char *argv[])
    
    gtk_object_destroy(GTK_OBJECT(window));
    gtk_object_destroy(GTK_OBJECT(mTrayMenu));
+   config->free_resources();
+   free(config);
+   config = NULL;
    term_msg();
 
 #if TRAY_DEBUG_MEMORY
@@ -500,7 +549,8 @@ int main(int argc, char *argv[])
    return 0;
 }
 
-static void MonitorAbout(GtkWidget *widget, gpointer data) {
+static void MonitorAbout(GtkWidget *widget, gpointer data)
+{
 #if HAVE_GTK_2_4
    GtkWidget* about = gtk_message_dialog_new_with_markup(GTK_WINDOW(window),GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
       "<span size='x-large' weight='bold'>%s</span>\n\n"
@@ -528,33 +578,46 @@ static void MonitorAbout(GtkWidget *widget, gpointer data) {
    gtk_widget_destroy(about);
 }
 
-static void MonitorRefresh(GtkWidget *widget, gpointer data) {
+static void MonitorRefresh(GtkWidget *widget, gpointer data)
+{
    for (int i = 0; i < nitems; i++) {
       fd_read(NULL);
    }
 }
 
-static gboolean delete_event( GtkWidget *widget,
-                              GdkEvent  *event,
-                              gpointer   data ) {
+static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
    gtk_widget_hide(window);
    return TRUE; /* do not destroy the window */
 }
 
-static void TrayIconActivate(GtkWidget *widget, gpointer data) {
-    gtk_widget_show(window);
+/*
+ * Come here when the user right clicks on the icon.
+ *   We display the icon menu.
+ */
+static void TrayIconActivate(GtkWidget *widget, gpointer data)
+{
+   gtk_widget_show(window);
 }
 
-static void TrayIconPopupMenu(unsigned int activateTime, unsigned int button) {
-  gtk_menu_popup(GTK_MENU(mTrayMenu), NULL, NULL, NULL, NULL, 1, 0);
-  gtk_widget_show_all(mTrayMenu);
+/*
+ * Come here when the user left clicks on the icon. 
+ *  We popup the status window.
+ */
+static void TrayIconPopupMenu(unsigned int activateTime, unsigned int button) 
+{
+   gtk_menu_popup(GTK_MENU(mTrayMenu), NULL, NULL, NULL, NULL, button,
+                  gtk_get_current_event_time());
+   gtk_widget_show(mTrayMenu);
 }
 
-static void TrayIconExit(unsigned int activateTime, unsigned int button) {
+static void TrayIconExit(unsigned int activateTime, unsigned int button)
+{
    gtk_main_quit();
 }
 
-static void IntervalChanged(GtkWidget *widget, gpointer data) {
+static void IntervalChanged(GtkWidget *widget, gpointer data)
+{
    g_source_remove(timerTag);
    timerTag = g_timeout_add(
       (guint)(
@@ -562,7 +625,8 @@ static void IntervalChanged(GtkWidget *widget, gpointer data) {
       ), fd_read, NULL );
 }
 
-static void DaemonChanged(GtkWidget *widget, monitoritem* data) {
+static void DaemonChanged(GtkWidget *widget, monitoritem* data) 
+{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
       fullitem = -1;
       for (int i = 0; i < nitems; i++) {
@@ -1014,9 +1078,9 @@ void trayMessage(const char *fmt,...)
    bvsnprintf(buf, sizeof(buf), (char *)fmt, arg_ptr);
    va_end(arg_ptr);
 
-   fprintf(stderr, buf);
+   fprintf(stderr, "%s", buf);
 
-   egg_tray_icon_send_message(egg_status_icon_get_tray_icon(mTrayIcon), 5000, (const char*)&buf, -1);
+// gtk_tray_icon_send_message(gtk_status_icon_get_tray_icon(mTrayIcon), 5000, (const char*)&buf, -1);
 }
 
 void changeStatusMessage(monitoritem* item, const char *fmt,...) {
@@ -1075,7 +1139,7 @@ void updateStatusIcon(monitoritem* item) {
 
    GdkPixbuf* pixbuf = gdk_pixbuf_new_from_xpm_data(xpm);
    if (item == NULL) {
-      egg_status_icon_set_from_pixbuf(mTrayIcon, pixbuf);
+      gtk_status_icon_set_from_pixbuf(mTrayIcon, pixbuf);
       gtk_window_set_icon(GTK_WINDOW(window), pixbuf);
    }
    else {
@@ -1085,7 +1149,8 @@ void updateStatusIcon(monitoritem* item) {
 }
 
 /* Note: result should not be stored, as it is a reference to xpm_generic_var */
-static const char** generateXPM(stateenum newstate, stateenum oldstate) {
+static const char** generateXPM(stateenum newstate, stateenum oldstate) 
+{
    char* address = &xpm_generic_var[xpm_generic_first_color][xpm_generic_column];
    switch (newstate) {
    case error: