Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- pidgin-libnotify-0.14/src/pidgin-libnotify.c.orig 2011-08-24 01:17:29.944020511 -0400
- +++ pidgin-libnotify-0.14/src/pidgin-libnotify.c 2011-08-24 01:31:44.539545179 -0400
- @@ -44,6 +44,10 @@
- static GHashTable *buddy_hash;
- +static gboolean notify_supports_actions = FALSE;
- +static gboolean notify_supports_append = FALSE;
- +static gboolean notify_supports_truncation = FALSE;
- +
- static PurplePluginPrefFrame *
- get_plugin_pref_frame (PurplePlugin *plugin)
- {
- @@ -222,7 +226,7 @@
- {
- gchar *escaped_str;
- - if (g_utf8_strlen (str, num_chars*2+1) > num_chars) {
- + if (!notify_supports_truncation && g_utf8_strlen (str, num_chars*2+1) > num_chars) {
- gchar *truncated_str;
- gchar *str2;
- @@ -255,9 +259,44 @@
- }
- static void
- +notify_check_caps_helper (gpointer data, gpointer user_data)
- +{
- + gchar * cap = (gchar *)data;
- +
- + if (cap == NULL) return;
- +
- + if (!strcmp(cap, "actions")) {
- + notify_supports_actions = TRUE;
- + } else if (!strcmp(cap, "append")) {
- + notify_supports_append = TRUE;
- + } else if (!strcmp(cap, "x-canonical-append")) {
- + notify_supports_append = TRUE;
- + } else if (!strcmp(cap, "truncation")) {
- + notify_supports_truncation = TRUE;
- + } else if (!strcmp(cap, "x-canonical-truncation")) {
- + notify_supports_truncation = TRUE;
- + }
- +
- + return;
- +}
- +
- +static void
- +notify_check_caps(void)
- +{
- + GList * caps = notify_get_server_caps();
- +
- + g_list_foreach(caps, notify_check_caps_helper, NULL);
- + g_list_foreach(caps, (GFunc)g_free, NULL);
- + g_list_free(caps);
- +
- + return;
- +}
- +
- +static void
- notify (const gchar *title,
- const gchar *body,
- - PurpleBuddy *buddy)
- + PurpleBuddy *buddy,
- + PurpleConversation *conv)
- {
- NotifyNotification *notification = NULL;
- GdkPixbuf *icon;
- @@ -272,8 +311,13 @@
- else
- tr_body = NULL;
- - notification = g_hash_table_lookup (buddy_hash, contact);
- + /* If we're appending we shouldn't update an already
- + existing notification */
- + if (conv == NULL && contact != NULL) {
- + notification = g_hash_table_lookup (buddy_hash, contact);
- + }
- + /* This will only happen if we're a login message */
- if (notification != NULL) {
- notify_notification_update (notification, title, tr_body, NULL);
- /* this shouldn't be necessary, file a bug */
- @@ -286,13 +330,19 @@
- g_free (tr_body);
- return;
- }
- - notification = notify_notification_new (title, tr_body, NULL, NULL);
- + notification = notify_notification_new (title, tr_body, NULL);
- purple_debug_info (PLUGIN_ID, "notify(), new: "
- "title: '%s', body: '%s', buddy: '%s'\n",
- title, tr_body, best_name (buddy));
- g_free (tr_body);
- + if (notify_supports_append) {
- + if (conv != NULL) {
- + notify_notification_set_hint_string(notification, "x-canonical-append", "allow");
- + }
- + }
- +
- buddy_icon = purple_buddy_get_icon (buddy);
- if (buddy_icon) {
- icon = pixbuf_from_buddy_icon (buddy_icon);
- @@ -316,8 +366,12 @@
- g_signal_connect (notification, "closed", G_CALLBACK(closed_cb), NULL);
- notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
- -
- - notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);
- +
- + /* Check if notification server can use actions */
- + if (notify_supports_actions)
- + {
- + notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);
- + }
- if (!notify_notification_show (notification, NULL)) {
- purple_debug_error (PLUGIN_ID, "notify(), failed to send notification\n");
- @@ -329,7 +383,7 @@
- notify_buddy_signon_cb (PurpleBuddy *buddy,
- gpointer data)
- {
- - gchar *tr_name, *title;
- + gchar *tr_name;
- gboolean blocked;
- g_return_if_fail (buddy);
- @@ -349,19 +403,16 @@
- tr_name = truncate_escape_string (best_name (buddy), 25);
- - title = g_strdup_printf (_("%s signed on"), tr_name);
- -
- - notify (title, NULL, buddy);
- + notify (tr_name, "signed on", buddy, NULL);
- g_free (tr_name);
- - g_free (title);
- }
- static void
- notify_buddy_signoff_cb (PurpleBuddy *buddy,
- gpointer data)
- {
- - gchar *tr_name, *title;
- + gchar *tr_name;
- gboolean blocked;
- g_return_if_fail (buddy);
- @@ -381,18 +432,16 @@
- tr_name = truncate_escape_string (best_name (buddy), 25);
- - title = g_strdup_printf (_("%s signed off"), tr_name);
- -
- - notify (title, NULL, buddy);
- + notify (tr_name, "signed off", buddy, NULL);
- g_free (tr_name);
- - g_free (title);
- }
- static void
- notify_msg_sent (PurpleAccount *account,
- const gchar *sender,
- - const gchar *message)
- + const gchar *message,
- + PurpleConversation *conv)
- {
- PurpleBuddy *buddy;
- gchar *title, *body, *tr_name;
- @@ -411,7 +460,7 @@
- title = g_strdup_printf (_("%s says:"), tr_name);
- body = purple_markup_strip_html (message);
- - notify (title, body, buddy);
- + notify (title, body, buddy, conv);
- g_free (tr_name);
- g_free (title);
- @@ -447,7 +496,7 @@
- if (!should_notify_unavailable (account))
- return;
- - notify_msg_sent (account, sender, message);
- + notify_msg_sent (account, sender, message, conv);
- }
- static void
- @@ -466,7 +515,7 @@
- if (!g_strstr_len (message, strlen(message), nick))
- return;
- - notify_msg_sent (account, sender, message);
- + notify_msg_sent (account, sender, message, conv);
- }
- static gboolean
- @@ -479,6 +528,8 @@
- return FALSE;
- }
- + notify_check_caps();
- +
- conv_handle = purple_conversations_get_handle ();
- blist_handle = purple_blist_get_handle ();
- conn_handle = purple_connections_get_handle();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement