aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Conti <jason.conti@gmail.com>2011-05-17 16:15:41 -0400
committerJason Conti <jason.conti@gmail.com>2011-05-17 16:15:41 -0400
commit425bde705a072effe6232cb3fa4fecdcb8849639 (patch)
tree453adb3ed0c348dba733b419ea8ec1131e1c6850 /src
parentc802236c56882bbfbb773801a7351a9e6cc11ba9 (diff)
downloadayatana-indicator-notifications-425bde705a072effe6232cb3fa4fecdcb8849639.tar.gz
ayatana-indicator-notifications-425bde705a072effe6232cb3fa4fecdcb8849639.tar.bz2
ayatana-indicator-notifications-425bde705a072effe6232cb3fa4fecdcb8849639.zip
Adding a timestamp to the messages. Currently sends a timestamp string across dbus, but ideally it will send an integer, and the indicator can decide how to display it (time ago in words, custom time format, etc).
Diffstat (limited to 'src')
-rw-r--r--src/dbus-shared.h11
-rw-r--r--src/indicator-notifications.c33
-rw-r--r--src/notification.c21
-rw-r--r--src/notification.h24
-rw-r--r--src/notifications-service.c4
5 files changed, 61 insertions, 32 deletions
diff --git a/src/dbus-shared.h b/src/dbus-shared.h
index 76d30ab..da93e73 100644
--- a/src/dbus-shared.h
+++ b/src/dbus-shared.h
@@ -24,8 +24,9 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define MENU_OBJ "/com/launchpad/RecentNotifications/indicator/menu"
-#define NOTIFICATION_MENUITEM_TYPE "notification-menuitem"
-#define NOTIFICATION_MENUITEM_PROP_APP_NAME "notification-menuitem-prop-app-name"
-#define NOTIFICATION_MENUITEM_PROP_APP_ICON "notification-menuitem-prop-app-icon"
-#define NOTIFICATION_MENUITEM_PROP_SUMMARY "notification-menuitem-prop-summary"
-#define NOTIFICATION_MENUITEM_PROP_BODY "notification-menuitem-prop-body"
+#define NOTIFICATION_MENUITEM_TYPE "notification-menuitem"
+#define NOTIFICATION_MENUITEM_PROP_APP_NAME "notification-menuitem-prop-app-name"
+#define NOTIFICATION_MENUITEM_PROP_APP_ICON "notification-menuitem-prop-app-icon"
+#define NOTIFICATION_MENUITEM_PROP_SUMMARY "notification-menuitem-prop-summary"
+#define NOTIFICATION_MENUITEM_PROP_BODY "notification-menuitem-prop-body"
+#define NOTIFICATION_MENUITEM_PROP_TIMESTAMP_STRING "notification-menuitem-prop-timestamp-string"
diff --git a/src/indicator-notifications.c b/src/indicator-notifications.c
index 9178958..72e806c 100644
--- a/src/indicator-notifications.c
+++ b/src/indicator-notifications.c
@@ -290,23 +290,22 @@ new_notification_menuitem(DbusmenuMenuitem *new_item, DbusmenuMenuitem *parent,
g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);
g_return_val_if_fail(IS_INDICATOR_NOTIFICATIONS(user_data), FALSE);
- const gchar *app_name = dbusmenu_menuitem_property_get(new_item,
- NOTIFICATION_MENUITEM_PROP_APP_NAME);
- const gchar *summary = dbusmenu_menuitem_property_get(new_item,
- NOTIFICATION_MENUITEM_PROP_SUMMARY);
- const gchar *body = dbusmenu_menuitem_property_get(new_item,
- NOTIFICATION_MENUITEM_PROP_BODY);
-
- gchar *escaped_app_name = g_markup_escape_text(app_name, strlen(app_name));
- gchar *escaped_summary = g_markup_escape_text(summary, strlen(summary));
- gchar *escaped_body = g_markup_escape_text(body, strlen(body));
-
- gchar *markup = g_strdup_printf("<b>%s</b>\n%s\n<small><i>%s <b>%s</b></i></small>",
- escaped_summary, escaped_body, _("from"), escaped_app_name);
-
- g_free(escaped_app_name);
- g_free(escaped_summary);
- g_free(escaped_body);
+ gchar *app_name = g_markup_escape_text(dbusmenu_menuitem_property_get(new_item,
+ NOTIFICATION_MENUITEM_PROP_APP_NAME), -1);
+ gchar *summary = g_markup_escape_text(dbusmenu_menuitem_property_get(new_item,
+ NOTIFICATION_MENUITEM_PROP_SUMMARY), -1);
+ gchar *body = g_markup_escape_text(dbusmenu_menuitem_property_get(new_item,
+ NOTIFICATION_MENUITEM_PROP_BODY), -1);
+ gchar *timestamp_string = g_markup_escape_text(dbusmenu_menuitem_property_get(new_item,
+ NOTIFICATION_MENUITEM_PROP_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(timestamp_string);
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
diff --git a/src/notification.c b/src/notification.c
index 10f83e8..d99a1f8 100644
--- a/src/notification.c
+++ b/src/notification.c
@@ -42,6 +42,7 @@ notification_init(Notification *self)
self->priv->summary = NULL;
self->priv->body = NULL;
self->priv->expire_timeout = 0;
+ self->priv->timestamp = NULL;
}
static void
@@ -69,6 +70,11 @@ notification_dispose(GObject *object)
self->priv->body = NULL;
}
+ if(self->priv->timestamp != NULL) {
+ g_date_time_unref(self->priv->timestamp);
+ self->priv->timestamp = NULL;
+ }
+
G_OBJECT_CLASS(notification_parent_class)->dispose(object);
}
@@ -83,6 +89,9 @@ notification_new_from_dbus_message(GDBusMessage *message)
{
Notification *self = notification_new();
+ /* timestamp */
+ self->priv->timestamp = g_date_time_new_now_local();
+
GVariant *body = g_dbus_message_get_body(message);
GVariant *child = NULL;
g_assert(g_variant_is_of_type(body, G_VARIANT_TYPE_TUPLE));
@@ -146,6 +155,18 @@ notification_get_body(Notification *self)
return self->priv->body;
}
+gint64
+notification_get_timestamp(Notification *self)
+{
+ return g_date_time_to_unix(self->priv->timestamp);
+}
+
+gchar*
+notification_timestamp_for_locale(Notification *self)
+{
+ return g_date_time_format(self->priv->timestamp, "%X %x");
+}
+
void
notification_print(Notification *self)
{
diff --git a/src/notification.h b/src/notification.h
index a11036f..d9a67fe 100644
--- a/src/notification.h
+++ b/src/notification.h
@@ -8,6 +8,7 @@
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
+#include <time.h>
G_BEGIN_DECLS
@@ -33,16 +34,17 @@ struct _NotificationClass
};
struct _NotificationPrivate {
- gchar *app_name;
- gsize app_name_length;
- guint32 replaces_id;
- gchar *app_icon;
- gsize app_icon_length;
- gchar *summary;
- gsize summary_length;
- gchar *body;
- gsize body_length;
- gint expire_timeout;
+ gchar *app_name;
+ gsize app_name_length;
+ guint32 replaces_id;
+ gchar *app_icon;
+ gsize app_icon_length;
+ gchar *summary;
+ gsize summary_length;
+ gchar *body;
+ gsize body_length;
+ gint expire_timeout;
+ GDateTime *timestamp;
};
#define NOTIFICATION_GET_PRIVATE(o) \
@@ -55,6 +57,8 @@ const gchar *notification_get_app_name(Notification *);
const gchar *notification_get_app_icon(Notification *);
const gchar *notification_get_summary(Notification *);
const gchar *notification_get_body(Notification *);
+gint64 notification_get_timestamp(Notification *);
+gchar *notification_timestamp_for_locale(Notification *);
void notification_print(Notification *);
G_END_DECLS
diff --git a/src/notifications-service.c b/src/notifications-service.c
index 72f6dee..38fa247 100644
--- a/src/notifications-service.c
+++ b/src/notifications-service.c
@@ -75,11 +75,14 @@ add_notification_item(gpointer user_data)
dbusmenu_menuitem_child_delete(root, empty_item);
}
+ gchar *timestamp_string = notification_timestamp_for_locale(note);
+
item = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_TYPE, NOTIFICATION_MENUITEM_TYPE);
dbusmenu_menuitem_property_set(item, NOTIFICATION_MENUITEM_PROP_APP_NAME, notification_get_app_name(note));
dbusmenu_menuitem_property_set(item, NOTIFICATION_MENUITEM_PROP_SUMMARY, notification_get_summary(note));
dbusmenu_menuitem_property_set(item, NOTIFICATION_MENUITEM_PROP_BODY, notification_get_body(note));
+ dbusmenu_menuitem_property_set(item, NOTIFICATION_MENUITEM_PROP_TIMESTAMP_STRING, timestamp_string);
dbusmenu_menuitem_child_prepend(root, item);
g_queue_push_head(notification_items, item);
length++;
@@ -97,6 +100,7 @@ add_notification_item(gpointer user_data)
/* Notify the indicator that a new message has been added */
notifications_interface_message_added(dbus);
+ g_free(timestamp_string);
g_object_unref(note);
return FALSE;