From 59896497977040f03aaa0b2c293c265ed2e0c4e7 Mon Sep 17 00:00:00 2001 From: Jason Conti Date: Fri, 19 Aug 2011 13:32:25 -0400 Subject: * Add a WITH_GTK (2, 3) definition to handle some of the minor differences between gtk2 and 3 * Replace gtk_hbox_new with gtk_box_new in the gtk3 version * GtkLabel has a new (and much nicer) wrapping mechanism - use gtk_label_set_max_width_chars in gtk3 version --- src/Makefile.am | 3 ++- src/indicator-notifications.c | 29 +++++++++++++++++++++-------- src/notifications-service.c | 5 +++++ 3 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 486770f..708b030 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,5 @@ -AM_CPPFLAGS = -DICONS_DIR='"$(INDICATORICONSDIR)"' +AM_CPPFLAGS = -DICONS_DIR='"$(INDICATORICONSDIR)"' \ + -DWITH_GTK='$(GTK_VERSION)' libexec_PROGRAMS = indicator-notifications-service diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c index eb7fe03..237c4d0 100644 --- a/src/indicator-notifications.c +++ b/src/indicator-notifications.c @@ -40,8 +40,13 @@ with this program. If not, see . #include /* DBusMenu */ +#if WITH_GTK == 3 +#include +#include +#else #include #include +#endif #include "dbus-shared.h" #include "settings-shared.h" @@ -172,7 +177,10 @@ indicator_notifications_init(IndicatorNotifications *self) DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(self->priv->menu); - dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), NOTIFICATION_MENUITEM_TYPE, new_notification_menuitem, self, NULL); + dbusmenu_client_add_type_handler_full(DBUSMENU_CLIENT(client), + NOTIFICATION_MENUITEM_TYPE, + new_notification_menuitem, + self, NULL); self->priv->service_proxy_cancel = g_cancellable_new(); @@ -189,9 +197,6 @@ indicator_notifications_init(IndicatorNotifications *self) return; } -/* Callback from trying to create the proxy for the serivce, this - could include starting the service. Sometime it'll fail and - we'll try to start that dang service again! */ static void service_proxy_cb(GObject *object, GAsyncResult *res, gpointer user_data) { @@ -215,8 +220,6 @@ service_proxy_cb(GObject *object, GAsyncResult *res, gpointer user_data) return; } - /* Okay, we're good to grab the proxy at this point, we're - sure that it's ours. */ priv->service_proxy = proxy; g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); @@ -272,7 +275,6 @@ indicator_notifications_finalize(GObject *object) return; } -/* Receives all signals from the service, routed to the appropriate functions */ static void receive_signal(GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) @@ -315,15 +317,26 @@ new_notification_menuitem(DbusmenuMenuitem *new_item, DbusmenuMenuitem *parent, g_free(body); g_free(timestamp_string); +#if WITH_GTK == 3 + GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); +#else GtkWidget *hbox = gtk_hbox_new(FALSE, 0); +#endif GtkWidget *label = gtk_label_new(NULL); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD_CHAR); + +#if WITH_GTK == 3 + gtk_label_set_max_width_chars(GTK_LABEL(label), 42); +#else gtk_widget_set_size_request(label, 300, -1); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); +#endif + + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); gtk_widget_show(label); g_free(markup); diff --git a/src/notifications-service.c b/src/notifications-service.c index a5a4ef2..d3c7da2 100644 --- a/src/notifications-service.c +++ b/src/notifications-service.c @@ -26,7 +26,12 @@ with this program. If not, see . #include #include +#if WITH_GTK == 3 +#include +#else #include +#endif + #include #include #include -- cgit v1.2.3