Git-Url:
http://git.frugalware.org/gitweb/gitweb.cgi?p=fun.git;a=commitdiff;h=415ff211372f3460b9f67b5f66d4ca76c9e31245
commit 415ff211372f3460b9f67b5f66d4ca76c9e31245
Author: Priyank <[EMAIL PROTECTED]>
Date: Thu Dec 20 00:40:35 2007 +0530
migrated to libnotify (for notifications)
* libnotify seems to be easier to use and more flexible
* Dropped eggtrayicon, libsexy
diff --git a/configure.ac b/configure.ac
index 5226e64..d37f6b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ if test "x$DBUSBINDINGTOOL" = "xno"; then
fi
AC_SUBST(DBUS_BINDING_TOOL)
-ui_modules="gtk+-2.0 >= 2.12.0 libglade-2.0 >= 2.6.0"
+ui_modules="gtk+-2.0 >= 2.12.0 libglade-2.0 >= 2.6.0 libnotify"
PKG_CHECK_MODULES([FUND], [dbus-glib-1 >= 0.73])
PKG_CHECK_MODULES([FUN], [$ui_modules])
diff --git a/src/Makefile.am b/src/Makefile.am
index 155302c..14c8501 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,8 +9,6 @@ bin_PROGRAMS = fun
fund_SOURCES = fund.c
fun_SOURCES = wejpconfig.c \
fun-config.c \
- eggtrayicon.c \
- sexy-tooltip.c \
fun-tooltip.c \
fun-messages.c \
fun-ui.c \
diff --git a/src/fun-tooltip.c b/src/fun-tooltip.c
index 2f7c558..bc65edb 100644
--- a/src/fun-tooltip.c
+++ b/src/fun-tooltip.c
@@ -21,145 +21,50 @@
*/
#include <gtk/gtk.h>
-#include <stdio.h>
#include "fun-tooltip.h"
-FunTooltip *fun_tooltip_new (void)
+NotifyNotification *fun_tooltip_new (GtkStatusIcon *icon)
{
- FunTooltip *tooltip;
- GtkWidget *label1;
- GtkWidget *label2;
+ NotifyNotification *tooltip = NULL;
- /* main tooltip window */
- tooltip = g_malloc (sizeof(FunTooltip));
- tooltip->window = gtk_window_new (GTK_WINDOW_POPUP);
-
- gtk_window_set_resizable (GTK_WINDOW(tooltip->window), FALSE);
- gtk_window_set_decorated (GTK_WINDOW(tooltip->window), FALSE);
- gtk_window_set_skip_taskbar_hint (GTK_WINDOW(tooltip->window), TRUE);
- gtk_window_set_skip_pager_hint (GTK_WINDOW(tooltip->window), TRUE);
-
- /* the two main layout boxes */
- tooltip->hbox = gtk_hbox_new (FALSE, 4);
- tooltip->vbox = gtk_vbox_new (FALSE, 0);
-
- /* pack the boxes */
- gtk_container_add (GTK_CONTAINER(tooltip->window), tooltip->hbox);
- gtk_box_pack_end (GTK_BOX(tooltip->hbox), tooltip->vbox, FALSE, FALSE,
2);
-
- /* tooltip icon */
- tooltip->icon = gtk_image_new_from_pixbuf (NULL);
- gtk_misc_set_padding (GTK_MISC(tooltip->icon), 4, 4);
- gtk_box_pack_start (GTK_BOX(tooltip->hbox), tooltip->icon, TRUE, TRUE,
0);
-
- /* labels */
- label1 = gtk_label_new (NULL);
- g_object_set (G_OBJECT(label1), "use-markup", TRUE, NULL);
- gtk_box_pack_start (GTK_BOX(tooltip->vbox), label1, TRUE, FALSE, 1);
- gtk_misc_set_alignment (GTK_MISC(label1), 0, 0);
- label2 = gtk_label_new (NULL);
- g_object_set (G_OBJECT(label2), "use-markup", TRUE, NULL);
- gtk_box_pack_start (GTK_BOX(tooltip->vbox), label2, TRUE, FALSE, 1);
- gtk_misc_set_alignment (GTK_MISC(label2), 0, 0);
+ tooltip = notify_notification_new ("Frugalware Update Notifier",
+
NULL,
+
"fun",
+
NULL);
+ notify_notification_set_category (tooltip, "information");
+ notify_notification_set_timeout (tooltip, NOTIFY_EXPIRES_DEFAULT);
+ notify_notification_set_urgency (tooltip, NOTIFY_URGENCY_NORMAL);
+ notify_notification_attach_to_status_icon (tooltip, icon);
return tooltip;
}
-void fun_tooltip_set_text1 (FunTooltip *tooltip, const gchar *text, gboolean
formatting)
+void fun_tooltip_set_text (NotifyNotification *tooltip, const gchar *summary,
const gchar *body)
{
- GList *list;
- gchar *markup;
-
- if ( (list = gtk_container_get_children (GTK_CONTAINER(tooltip->vbox)))
!= NULL )
- {
- if (text == NULL)
- {
- gtk_label_set_text (GTK_LABEL(list->data), NULL);
- gtk_widget_hide (GTK_WIDGET(list->data));
- return;
- }
-
- if (formatting == TRUE)
- {
- markup = g_markup_printf_escaped ("<span size=\"large\"
weight=\"bold\">%s</span>", text);
- gtk_label_set_markup (GTK_LABEL(list->data), markup);
- g_free (markup);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL(list->data), text);
- }
-
- g_list_free (list);
- }
+ if (tooltip)
+ notify_notification_update (tooltip, summary, body, "fun");
return;
}
-void fun_tooltip_set_text2 (FunTooltip *tooltip, const gchar *text, gboolean
formatting)
+void fun_tooltip_show (GtkStatusIcon *icon, NotifyNotification *tooltip)
{
- GList *list;
- gchar *markup;
-
- if ( (list = gtk_container_get_children (GTK_CONTAINER(tooltip->vbox)))
!= NULL )
+ if (tooltip)
{
- if ((list = g_list_nth (list, 1)) == NULL)
- return;
-
- if (text == NULL)
- {
- gtk_label_set_text (GTK_LABEL(list->data), NULL);
- gtk_widget_hide (GTK_WIDGET(list->data));
- return;
- }
- if (formatting == TRUE)
- {
- markup = g_markup_printf_escaped ("<span
size=\"medium\"><i>%s</i></span>", text);
- gtk_label_set_markup (GTK_LABEL(list->data), markup);
- g_free (markup);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL(list->data), text);
- }
- gtk_widget_show (GTK_WIDGET(list->data));
- g_list_free (list);
- }
-
- return;
-}
-
-void fun_tooltip_set_icon (FunTooltip *tooltip, GdkPixbuf *pixbuf)
-{
- gtk_image_set_from_pixbuf (GTK_IMAGE(tooltip->icon), pixbuf);
-
- return;
-}
-
-void fun_tooltip_show (FunTooltip *tooltip)
-{
- if (tooltip != NULL)
- {
- gtk_widget_show (GTK_WIDGET(tooltip->hbox));
- gtk_widget_show (GTK_WIDGET(tooltip->window));
+ GdkScreen *screen = NULL;
+ GdkRectangle area;
+
+ gtk_status_icon_get_geometry (icon, &screen, &area, NULL);
+ notify_notification_set_geometry_hints (tooltip, screen,
area.x, area.y);
+ notify_notification_show (tooltip, NULL);
}
- return;
-}
-void fun_tooltip_hide (FunTooltip *tooltip)
-{
- if (tooltip != NULL)
- gtk_widget_hide (GTK_WIDGET(tooltip->window));
-
return;
}
-void fun_tooltip_destroy (FunTooltip *tooltip)
+void fun_tooltip_destroy (NotifyNotification *tooltip)
{
- gtk_widget_destroy (GTK_WIDGET(tooltip->vbox));
- gtk_widget_destroy (GTK_WIDGET(tooltip->hbox));
- gtk_widget_destroy (GTK_WIDGET(tooltip->window));
- g_free (tooltip);
+ g_object_unref (tooltip);
return;
}
diff --git a/src/fun-tooltip.h b/src/fun-tooltip.h
index b9ac4ae..429cb6c 100644
--- a/src/fun-tooltip.h
+++ b/src/fun-tooltip.h
@@ -2,37 +2,22 @@
#define _FUN_TOOLTIP_H
#include <gtk/gtk.h>
-
-/* FunTooltip structure */
-typedef struct {
- GtkWidget *window;
- GtkWidget *hbox;
- GtkWidget *vbox;
- GtkWidget *icon;
-} FunTooltip;
+#include <libnotify/notification.h>
+#include <libnotify/notify.h>
/* Fun Tooltip Functions */
/* Create a new tooltip */
-FunTooltip *fun_tooltip_new (void);
+NotifyNotification *fun_tooltip_new (GtkStatusIcon *icon);
/* Sets the tooltip text (label1) */
-void fun_tooltip_set_text1 (FunTooltip *tooltip, const gchar *text, gboolean
formatting);
-
-/* Sets the tooltip text (label2) */
-void fun_tooltip_set_text2 (FunTooltip *tooltip, const gchar *text, gboolean
formatting);
-
-/* Sets the icon for the tooltip */
-void fun_tooltip_set_icon (FunTooltip *tooltip, GdkPixbuf *pixbuf);
+void fun_tooltip_set_text (NotifyNotification *tooltip, const gchar *summary,
const gchar *body);
/* Show the tooltip */
-void fun_tooltip_show (FunTooltip *tooltip);
-
-/* Hide the tooltip */
-void fun_tooltip_hide (FunTooltip *tooltip);
+void fun_tooltip_show (GtkStatusIcon *icon, NotifyNotification *tooltip);
/* Destroy the tooltip object and free the memory */
-void fun_tooltip_destroy (FunTooltip *tooltip);
+void fun_tooltip_destroy (NotifyNotification *tooltip);
#endif
diff --git a/src/fun-ui.c b/src/fun-ui.c
index 38ace3c..43da8cb 100644
--- a/src/fun-ui.c
+++ b/src/fun-ui.c
@@ -25,8 +25,6 @@
#include "fun-messages.h"
#include "fun-tooltip.h"
#include "fun-dbus.h"
-#include "sexy-tooltip.h"
-#include "eggtrayicon.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -35,6 +33,7 @@
static void fun_about_show (void);
static void fun_about_hide (void);
static void fun_main_window_init (void);
+static void fun_main_window_show (void);
static void fun_main_window_hide (void);
static void fun_launch_gfpm (void);
static void fun_populate_updates_tvw (gchar *plist);
@@ -44,11 +43,9 @@ static void fun_populate_updates_tvw (gchar *plist);
extern GladeXML *xml;
-EggTrayIcon *icon = NULL;
-FunTooltip *tooltip = NULL;
-GtkWidget *stooltip;
+static GtkStatusIcon *icon = NULL;
+static NotifyNotification *tooltip = NULL;
-static GtkStatusIcon *fun_icon = NULL;
static GtkWidget *fun_about_dlg = NULL;
static GtkWidget *fun_main_window = NULL;
static GtkWidget *fun_statusbar = NULL;
@@ -103,125 +100,30 @@ static void fun_restart (void);
static GdkPixbuf * fun_get_icon (const char *icon, int size);
static void fun_update_status (const char *message);
-static gboolean cb_fun_systray_icon_clicked (GtkWidget *widget,
GdkEventButton *event, gpointer data);
-static gboolean cb_fun_systray_enter_notify (GtkWidget *widget,
GdkEventCrossing *event, gpointer data);
-static gboolean cb_fun_systray_leave_notify (GtkWidget *widget,
GdkEventCrossing *event, gpointer data);
+static gboolean cb_fun_systray_icon_clicked (GtkStatusIcon *widget,
guint button, guint activate_time, gpointer data);
static void cb_fun_config_dlg_close_clicked (GtkWidget *button, gpointer data);
void
fun_systray_create (void)
{
- gchar *icon_file;
- GdkPixbuf *icon_image;
- GdkPixbuf *icon_tooltip;
- GtkWidget *systray_icon;
- GdkColor color;
-
/* create the tray icon */
- icon = egg_tray_icon_new ("Frugalware Update Notifier");
- icon_image = fun_get_icon ("fun", 24);
- systray_icon = gtk_image_new_from_pixbuf (icon_image);
- gtk_container_add (GTK_CONTAINER (icon), systray_icon);
- g_object_unref (icon_image);
-
- stooltip = sexy_tooltip_new ();
- gdk_color_parse ("white", &color);
- gtk_widget_modify_bg (GTK_WIDGET(stooltip), GTK_STATE_NORMAL, &color);
+ icon = gtk_status_icon_new_from_icon_name ("fun");
/* set the default tooltip */
- tooltip = fun_tooltip_new ();
- fun_tooltip_set_text1 (tooltip, "Frugalware Update Notifier", TRUE);
- icon_tooltip = fun_get_icon ("fun", 32);
- fun_tooltip_set_icon (tooltip, icon_tooltip);
- g_object_unref (icon_tooltip);
-
- g_signal_connect (icon, "button-press-event", G_CALLBACK
(cb_fun_systray_icon_clicked), NULL);
- g_signal_connect (icon, "enter-notify-event",
G_CALLBACK(cb_fun_systray_enter_notify), NULL);
- g_signal_connect (icon, "leave-notify-event",
G_CALLBACK(cb_fun_systray_leave_notify), NULL);
- gtk_widget_show (GTK_WIDGET(systray_icon));
- gtk_widget_show (GTK_WIDGET(icon));
-
- gtk_widget_ref (tooltip->hbox);
- gtk_container_remove (GTK_CONTAINER(tooltip->window), tooltip->hbox);
- gtk_container_add (GTK_CONTAINER(stooltip), tooltip->hbox);
- gtk_widget_unref (tooltip->hbox);
-
- return;
-}
-
-static gboolean
-cb_fun_systray_enter_notify (GtkWidget *widget, GdkEventCrossing *event,
gpointer data)
-{
- GdkScreen *screen = NULL;
- GdkScreen *def_screen = NULL;
- GdkRectangle rectangle;
- gint x, y;
- gint w, h;
- gint top;
+ tooltip = fun_tooltip_new (icon);
+ fun_tooltip_set_text (tooltip, "Frugalware Update Notifier", NULL);
- /* Check where to place our tooltip */
- def_screen = gdk_screen_get_default ();
- w = gdk_screen_get_width (def_screen);
- h = gdk_screen_get_height (def_screen);
- /* Get the location of the system tray icon */
- gdk_window_get_origin ((GTK_WIDGET(icon)->window), &x, &y);
- if (h-y >= 100)
- top = 1; /* tooltip should be placed on top */
- else
- top = 0; /* tooltip should be placed on bottom */
- w = h = 0;
-
- /* Move the tooltip off-screen to calculate the exact co-ordinates */
- rectangle.x = 2500;
- rectangle.y = 2500;
- rectangle.width = 100;
- rectangle.height = 70;
- screen = gtk_widget_get_screen (GTK_WIDGET(icon));
- sexy_tooltip_position_to_rect (SEXY_TOOLTIP(stooltip), &rectangle,
screen);
- gtk_widget_show_all (stooltip);
- gtk_window_get_size (GTK_WINDOW(stooltip), &w, &h);
-
- /* Good, now lets move it back to where it should be */
- if (top == 1)
- {
- rectangle.x = x-(w/4);
- rectangle.y = y-25;
- }
- else
- {
- rectangle.x = x-(w/4);
- rectangle.y = y-130;
- }
-
- sexy_tooltip_position_to_rect (SEXY_TOOLTIP(stooltip), &rectangle,
screen);
+ g_signal_connect (icon, "activate", G_CALLBACK (fun_main_window_show),
NULL);
+ g_signal_connect (icon, "popup-menu", G_CALLBACK
(cb_fun_systray_icon_clicked), NULL);
- return TRUE;
-}
-
-static gboolean
-cb_fun_systray_leave_notify (GtkWidget *widget, GdkEventCrossing *event,
gpointer data)
-{
- fun_tooltip_hide (tooltip);
- gtk_widget_hide (stooltip);
-
- return TRUE;
+ return;
}
static gboolean
-cb_fun_systray_icon_clicked (GtkWidget *widget, GdkEventButton *event,
gpointer data)
+cb_fun_systray_icon_clicked (GtkStatusIcon *widget, guint button, guint
activate_time, gpointer data)
{
- /* Left Click */
- if (event->button == 1)
- {
- /* Toggle window visibility */
- if (!GTK_WIDGET_VISIBLE(fun_main_window))
- gtk_widget_show (GTK_WIDGET(fun_main_window));
- else
- fun_main_window_hide ();
- return TRUE;
- }
/* Right Click */
- if (event->button == 3)
+ if (button == 3)
{
GtkWidget *menu = NULL;
GtkWidget *menu_item = NULL;
@@ -326,7 +228,7 @@ fun_ui_cleanup (void)
{
if (icon == NULL)
return;
- gtk_widget_destroy (GTK_WIDGET(icon));
+ g_object_unref (icon);
gtk_widget_destroy (GTK_WIDGET(fun_config_dlg));
gtk_widget_destroy (GTK_WIDGET(fun_main_window));
fun_tooltip_destroy (tooltip);
@@ -486,7 +388,7 @@ fun_ui_init (void)
"to reconnect to the daemon every 45 seconds. \n\nYou can start the "
"update notifier daemon by running the following command as root: \n\n"
"'service fun start'");
-
+ notify_init ("fun");
fun_systray_create ();
fun_main_window_init ();
fun_config_dialog_init ();
@@ -494,7 +396,7 @@ fun_ui_init (void)
if (fun_dbus_perform_service (TEST_SERVICE, NULL, NULL, NULL) == FALSE)
{
g_print (_("Failed to connect to the fun daemon\n"));
- fun_tooltip_set_text2 (tooltip, _("Not connected to fun
daemon"), FALSE);
+ //fun_tooltip_set_text2 (tooltip, _("Not connected to fun
daemon"), FALSE);
connected = FALSE;
/* set the status */
fun_update_status (_("The frugalware update notifier daemon is not running.
Update checking is disabled"));
@@ -534,7 +436,7 @@ fun_timeout_conn (void)
{
connected = TRUE;
g_timeout_add_seconds (20, (GSourceFunc)fun_timeout_func, NULL);
- fun_tooltip_set_text2 (tooltip, "", FALSE);
+ //fun_tooltip_set_text2 (tooltip, "", FALSE);
/* set the status to Idle */
fun_update_status (_("Idle"));
return FALSE;
@@ -566,10 +468,9 @@ fun_timeout_func (void)
if (fun_dbus_perform_service (PERFORM_UPDATE, NULL, &plist, NULL)==TRUE)
{
//g_print ("\nlist is\n %s", plist);
- fun_tooltip_set_text1 (tooltip, _("Updates are available"),
TRUE);
- fun_tooltip_set_text2 (tooltip, _("Click here to know more.."),
TRUE);
- fun_tooltip_show (tooltip);
- cb_fun_systray_enter_notify (NULL, NULL, NULL);
+ fun_tooltip_set_text (tooltip, _("Updates are available"),
_("Yeah updates are available"));
+ //fun_tooltip_set_text2 (tooltip, _("Click here to know
more.."), TRUE);
+ fun_tooltip_show (icon, tooltip);
/* display the notification popup for notification_timeout seconds */
/* we do this by registering a timeout for x seconds which will simply hide the
* tooltip when fired and destroy itself */
@@ -589,7 +490,7 @@ fun_timeout_func (void)
static gboolean
fun_timeout_notification (void)
{
- cb_fun_systray_leave_notify (NULL, NULL, NULL);
+ //cb_fun_systray_leave_notify (NULL, NULL, NULL);
return FALSE;
}
@@ -679,6 +580,18 @@ fun_main_window_hide (void)
return;
}
+static void
+fun_main_window_show (void)
+{
+ /* Toggle window visibility */
+ if (!GTK_WIDGET_VISIBLE(fun_main_window))
+ gtk_widget_show (GTK_WIDGET(fun_main_window));
+ else
+ fun_main_window_hide ();
+
+ return;
+}
+
static GdkPixbuf *
fun_get_icon (const char *icon, int size)
{
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git