Hi.

Attached is a patch that displays a dialog when the dbus session bus is
not available, or if trackerd is unable to connect to it.  I think that
this is useful, as otherwise, trackerd silently fails to start.

In order to display the dialog, there is a dependency on GTK+, but it
does NOT require any GNOME specific libraries.

As for the issue of running trackerd when no UI is available, it should
be a non-issue.  If there is no UI available, it will fall back to the
console only version.  It will however, still fail if no dbus session
bus is available.

Suggestions to improve this are welcome.

Thanks.

Saleem Abdulrasool
compnerd (at) gentoo (dot) org
Index: configure.in
===================================================================
--- configure.in        (revision 382)
+++ configure.in        (working copy)
@@ -29,10 +29,15 @@
 
 dnl Library Checks
 DBUS_REQUIRED=0.60
+GTK_REQUIRED=2.10.0
 GLIB_REQUIRED=2.9.1
 PANGO_REQUIRED=1.0.0
 GMIME_REQUIRED=2.1.0
 
+PKG_CHECK_MODULES(GTK2, [ gtk+-2.0 >= $GTK_REQUIRED ])
+AC_SUBST([GTK2_CFLAGS])
+AC_SUBST([GTK2_LIBS])
+
 PKG_CHECK_MODULES(GLIB2, [ glib-2.0 >= $GLIB_REQUIRED ])
 AC_SUBST(GLIB2_CFLAGS)
 AC_SUBST(GLIB2_LIBS)
Index: src/trackerd/tracker-dialogs.c
===================================================================
--- src/trackerd/tracker-dialogs.c      (revision 0)
+++ src/trackerd/tracker-dialogs.c      (revision 0)
@@ -0,0 +1,22 @@
+#include "tracker-dialogs.h"
+
+void
+tracker_critical_error(const gchar *format, ...)
+{
+   va_list args;
+   gchar *message = NULL;
+   GtkWidget *dialog = NULL;
+
+   va_start(args, format);
+   message = g_strdup_vprintf(format, args);
+   va_end(args);
+
+   dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, 
GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, NULL);
+   gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), "<span 
size='larger'><b>Tracker Daemon</b></span>");
+   gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), 
message);
+
+   gtk_dialog_run(GTK_DIALOG(dialog));
+
+   g_free(message);
+   gtk_widget_destroy(dialog);
+}
Index: src/trackerd/tracker-dialogs.h
===================================================================
--- src/trackerd/tracker-dialogs.h      (revision 0)
+++ src/trackerd/tracker-dialogs.h      (revision 0)
@@ -0,0 +1,11 @@
+#ifndef __TRACKER_DIALOGS_H__
+#define __TRACKER_DIALOGS_H__
+
+#include <glib.h>
+
+#include <gtk/gtk.h>
+
+void
+tracker_critical_error(const gchar *format, ...);
+
+#endif
Index: src/trackerd/tracker-dbus.c
===================================================================
--- src/trackerd/tracker-dbus.c (revision 382)
+++ src/trackerd/tracker-dbus.c (working copy)
@@ -47,10 +47,21 @@
 
        connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
 
-       if ((connection == NULL) || dbus_error_is_set (&error)) {
-               tracker_log ("tracker_dbus_init() could not get the session 
bus");
+       if (dbus_error_is_set(&error)) {
+               tracker_log("tracker_dbus_init() could not get the session 
bus");
+               tracker_critical_error("Unable to connect to the Session Bus "
+                                      "due to the following error:\n\n%s\n\n"
+                                      "Please ensure that DBus is running, and 
"
+                                      "then start trackerd.", error.message);
                connection = NULL;
                goto out;
+       } else if (connection == NULL) {
+               tracker_log("tracker_dbus_init() could not get the session 
bus");
+               tracker_critical_error("This program cannot start until you 
start "
+                                      "the dbus system service.\n"
+                                      "It is <b>strongly</b> recommended you 
set "
+                                      "this service to autostart on boot.");
+               goto out;
        }
 
        dbus_connection_setup_with_g_main (connection, NULL);
Index: src/trackerd/tracker-dbus.h
===================================================================
--- src/trackerd/tracker-dbus.h (revision 382)
+++ src/trackerd/tracker-dbus.h (working copy)
@@ -27,6 +27,7 @@
 #include <dbus/dbus-glib-lowlevel.h>
 #include <dbus/dbus-glib.h>
 
+#include "tracker-dialogs.h"
 
 #define TRACKER_SERVICE                                        
"org.freedesktop.Tracker"
 #define TRACKER_OBJECT                                 
"/org/freedesktop/tracker"
Index: src/trackerd/trackerd.c
===================================================================
--- src/trackerd/trackerd.c     (revision 382)
+++ src/trackerd/trackerd.c     (working copy)
@@ -2696,6 +2696,10 @@
 #endif /* HAVE_RECENT_GLIB */
 
        g_option_context_add_main_entries (context, entries, NULL);
+
+        /* Call this to allow the dialog */
+       gtk_init_check(&argc, &argv);
+
        g_option_context_parse (context, &argc, &argv, &error);
 
        g_option_context_free (context);
@@ -3004,6 +3008,9 @@
 
        main_connection = tracker_dbus_init ();
 
+       if (!main_connection)
+               return EXIT_FAILURE;
+
        add_local_dbus_connection_monitoring (main_connection);
 
 
Index: src/trackerd/Makefile.am
===================================================================
--- src/trackerd/Makefile.am    (revision 382)
+++ src/trackerd/Makefile.am    (working copy)
@@ -19,6 +19,7 @@
        -DPIC=1                         \
        -D_REENTRANT=1                  \
        -DNDEBUG                        \
+       $(GTK2_CFLAGS)                  \
        $(GLIB2_CFLAGS)                 \
        $(PANGO_CFLAGS)                 \
        $(GMIME_CFLAGS)                 \
@@ -99,6 +100,8 @@
        tracker-db.h                    \
        tracker-dbus.c                  \
        tracker-dbus.h                  \
+       tracker-dialogs.c               \
+       tracker-dialogs.h               \
        tracker-dbus-files.c            \
        tracker-dbus-files.h            \
        tracker-dbus-methods.c          \
@@ -148,6 +151,7 @@
 
 trackerd_LDADD =                       \
        $(GLIB2_LIBS)                   \
+       $(GTK2_LIBS)                    \
        $(FAM_LIBS)                     \
        $(DBUS_LIBS)                    \
        $(MYSQL_LIBS)                   \

Attachment: pgpEbNaBq3O0Q.pgp
Description: PGP signature

_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list

Reply via email to