aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/indicator-notifications.c5
-rw-r--r--src/notification-menuitem.c83
-rw-r--r--src/notification-menuitem.h48
4 files changed, 137 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index a648233..5525407 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,8 @@ notificationslib_LTLIBRARIES = libnotifications.la
libnotifications_la_SOURCES = \
dbus-spy.c \
dbus-spy.h \
+ notification-menuitem.c \
+ notification-menuitem.h \
indicator-notifications.c \
notification.c \
notification.h
diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c
index 8d9a070..db37c02 100644
--- a/src/indicator-notifications.c
+++ b/src/indicator-notifications.c
@@ -37,6 +37,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libindicator/indicator-service-manager.h>
#include "dbus-spy.h"
+#include "notification-menuitem.h"
#define INDICATOR_NOTIFICATIONS_TYPE (indicator_notifications_get_type ())
#define INDICATOR_NOTIFICATIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_NOTIFICATIONS_TYPE, IndicatorNotifications))
@@ -577,9 +578,11 @@ message_received_cb(DBusSpy *spy, Notification *note, gpointer user_data)
if(notification_is_private(note) || notification_is_empty(note))
return;
- GtkWidget *item = new_notification_menuitem(note);
+ GtkWidget *item = notification_menuitem_new();
+ notification_menuitem_set_from_notification(NOTIFICATION_MENUITEM(item), note);
g_signal_connect(item, "button-press-event", G_CALLBACK(notification_button_press_cb), self);
g_signal_connect(item, "button-release-event", G_CALLBACK(notification_button_release_cb), self);
+ gtk_widget_show(item);
g_object_unref(note);
insert_menuitem(self, item);
diff --git a/src/notification-menuitem.c b/src/notification-menuitem.c
new file mode 100644
index 0000000..9840c31
--- /dev/null
+++ b/src/notification-menuitem.c
@@ -0,0 +1,83 @@
+/*
+ * notification-menuitem.h - A menuitem to display notifications.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n-lib.h>
+#include "notification-menuitem.h"
+
+#define NOTIFICATION_MENUITEM_MAX_CHARS 42
+
+static void notification_menuitem_class_init(NotificationMenuItemClass *klass);
+static void notification_menuitem_init(NotificationMenuItem *self);
+
+G_DEFINE_TYPE (NotificationMenuItem, notification_menuitem, GTK_TYPE_MENU_ITEM);
+
+static void
+notification_menuitem_class_init(NotificationMenuItemClass *klass)
+{
+ GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS(klass);
+
+ g_type_class_add_private(klass, sizeof(NotificationMenuItemPrivate));
+
+ menu_item_class->hide_on_activate = FALSE;
+}
+
+static void
+notification_menuitem_init(NotificationMenuItem *self)
+{
+ self->priv = NOTIFICATION_MENUITEM_GET_PRIVATE(self);
+
+ GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+
+ self->priv->label = gtk_label_new(NULL);
+ gtk_misc_set_alignment(GTK_MISC(self->priv->label), 0, 0);
+ gtk_label_set_use_markup(GTK_LABEL(self->priv->label), TRUE);
+ gtk_label_set_line_wrap(GTK_LABEL(self->priv->label), TRUE);
+ gtk_label_set_line_wrap_mode(GTK_LABEL(self->priv->label), PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_max_width_chars(GTK_LABEL(self->priv->label), NOTIFICATION_MENUITEM_MAX_CHARS);
+
+ gtk_box_pack_start(GTK_BOX(hbox), self->priv->label, TRUE, TRUE, 0);
+ gtk_widget_show(self->priv->label);
+
+ self->priv->close_image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+ gtk_widget_show(self->priv->close_image);
+ gtk_box_pack_start(GTK_BOX(hbox), self->priv->close_image, FALSE, FALSE, 0);
+
+ gtk_container_add(GTK_CONTAINER(self), hbox);
+ gtk_widget_show(hbox);
+}
+
+GtkWidget *
+notification_menuitem_new(void)
+{
+ return g_object_new(NOTIFICATION_MENUITEM_TYPE, NULL);
+}
+
+void
+notification_menuitem_set_from_notification(NotificationMenuItem *self, Notification *note)
+{
+ g_return_if_fail(IS_NOTIFICATION(note));
+ gchar *unescaped_timestamp_string = notification_timestamp_for_locale(note);
+
+ gchar *app_name = g_markup_escape_text(notification_get_app_name(note), -1);
+ gchar *summary = g_markup_escape_text(notification_get_summary(note), -1);
+ gchar *body = g_markup_escape_text(notification_get_body(note), -1);
+ gchar *timestamp_string = g_markup_escape_text(unescaped_timestamp_string, -1);
+
+ gchar *markup = g_strdup_printf("<b>%s</b>\n%s\n<small><i>%s %s <b>%s</b></i></small>",
+ summary, body, timestamp_string, _("from"), app_name);
+
+ g_free(app_name);
+ g_free(summary);
+ g_free(body);
+ g_free(unescaped_timestamp_string);
+ g_free(timestamp_string);
+
+ gtk_label_set_markup(GTK_LABEL(self->priv->label), markup);
+
+ g_free(markup);
+}
diff --git a/src/notification-menuitem.h b/src/notification-menuitem.h
new file mode 100644
index 0000000..f76704a
--- /dev/null
+++ b/src/notification-menuitem.h
@@ -0,0 +1,48 @@
+/*
+ * notification-menuitem.h - A menuitem to display notifications.
+ */
+
+#ifndef __NOTIFICATION_MENUITEM_H__
+#define __NOTIFICATION_MENUITEM_H__
+
+#include <gtk/gtk.h>
+#include "notification.h"
+
+G_BEGIN_DECLS
+
+#define NOTIFICATION_MENUITEM_TYPE (notification_menuitem_get_type ())
+#define NOTIFICATION_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFICATION_MENUITEM_TYPE, NotificationMenuItem))
+#define NOTIFICATION_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFICATION_MENUITEM_TYPE, NotificationMenuItemClass))
+#define IS_NOTIFICATION_MENUITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFICATION_MENUITEM_TYPE))
+#define IS_NOTIFICATION_MENUITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFICATION_MENUITEM_TYPE))
+
+typedef struct _NotificationMenuItem NotificationMenuItem;
+typedef struct _NotificationMenuItemClass NotificationMenuItemClass;
+typedef struct _NotificationMenuItemPrivate NotificationMenuItemPrivate;
+
+struct _NotificationMenuItem
+{
+ GtkMenuItem parent_instance;
+ NotificationMenuItemPrivate *priv;
+};
+
+struct _NotificationMenuItemClass
+{
+ GtkMenuItemClass parent_class;
+};
+
+struct _NotificationMenuItemPrivate {
+ GtkWidget *label;
+ GtkWidget *close_image;
+};
+
+#define NOTIFICATION_MENUITEM_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), NOTIFICATION_MENUITEM_TYPE, NotificationMenuItemPrivate))
+
+GType notification_menuitem_get_type(void);
+GtkWidget *notification_menuitem_new(void);
+void notification_menuitem_set_from_notification(NotificationMenuItem *self, Notification *note);
+
+G_END_DECLS
+
+#endif /* __NOTIFICATION_MENUITEM_H__ */