Advertisement
Guest User

Untitled

a guest
Aug 24th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.47 KB | None | 0 0
  1. --- pidgin-libnotify-0.14/src/pidgin-libnotify.c.orig   2011-08-24 01:17:29.944020511 -0400
  2. +++ pidgin-libnotify-0.14/src/pidgin-libnotify.c    2011-08-24 01:31:44.539545179 -0400
  3. @@ -44,6 +44,10 @@
  4.  
  5.  static GHashTable *buddy_hash;
  6.  
  7. +static gboolean  notify_supports_actions = FALSE;
  8. +static gboolean  notify_supports_append = FALSE;
  9. +static gboolean  notify_supports_truncation = FALSE;
  10. +
  11.  static PurplePluginPrefFrame *
  12.  get_plugin_pref_frame (PurplePlugin *plugin)
  13.  {
  14. @@ -222,7 +226,7 @@
  15.  {
  16.     gchar *escaped_str;
  17.  
  18. -   if (g_utf8_strlen (str, num_chars*2+1) > num_chars) {
  19. +   if (!notify_supports_truncation && g_utf8_strlen (str, num_chars*2+1) > num_chars) {
  20.         gchar *truncated_str;
  21.         gchar *str2;
  22.  
  23. @@ -255,9 +259,44 @@
  24.  }
  25.  
  26.  static void
  27. +notify_check_caps_helper (gpointer data, gpointer user_data)
  28. +{
  29. +   gchar * cap = (gchar *)data;
  30. +
  31. +   if (cap == NULL) return;
  32. +
  33. +   if (!strcmp(cap, "actions")) {
  34. +       notify_supports_actions = TRUE;
  35. +   } else if (!strcmp(cap, "append")) {
  36. +       notify_supports_append = TRUE;
  37. +   } else if (!strcmp(cap, "x-canonical-append")) {
  38. +       notify_supports_append = TRUE;
  39. +   } else if (!strcmp(cap, "truncation")) {
  40. +       notify_supports_truncation = TRUE;
  41. +   } else if (!strcmp(cap, "x-canonical-truncation")) {
  42. +       notify_supports_truncation = TRUE;
  43. +   }
  44. +
  45. +   return;
  46. +}
  47. +
  48. +static void
  49. +notify_check_caps(void)
  50. +{
  51. +   GList * caps = notify_get_server_caps();
  52. +
  53. +   g_list_foreach(caps, notify_check_caps_helper, NULL);
  54. +   g_list_foreach(caps, (GFunc)g_free, NULL);
  55. +   g_list_free(caps);
  56. +
  57. +   return;
  58. +}
  59. +
  60. +static void
  61.  notify (const gchar *title,
  62.         const gchar *body,
  63. -       PurpleBuddy *buddy)
  64. +       PurpleBuddy *buddy,
  65. +       PurpleConversation *conv)
  66.  {
  67.     NotifyNotification *notification = NULL;
  68.     GdkPixbuf *icon;
  69. @@ -272,8 +311,13 @@
  70.     else
  71.         tr_body = NULL;
  72.  
  73. -   notification = g_hash_table_lookup (buddy_hash, contact);
  74. +   /* If we're appending we shouldn't update an already
  75. +     existing notification */
  76. +   if (conv == NULL && contact != NULL) {
  77. +       notification = g_hash_table_lookup (buddy_hash, contact);
  78. +   }
  79.  
  80. +   /* This will only happen if we're a login message */
  81.     if (notification != NULL) {
  82.         notify_notification_update (notification, title, tr_body, NULL);
  83.         /* this shouldn't be necessary, file a bug */
  84. @@ -286,13 +330,19 @@
  85.         g_free (tr_body);
  86.         return;
  87.     }
  88. -   notification = notify_notification_new (title, tr_body, NULL, NULL);
  89. +   notification = notify_notification_new (title, tr_body, NULL);
  90.     purple_debug_info (PLUGIN_ID, "notify(), new: "
  91.                      "title: '%s', body: '%s', buddy: '%s'\n",
  92.                      title, tr_body, best_name (buddy));
  93.  
  94.     g_free (tr_body);
  95.  
  96. +   if (notify_supports_append) {
  97. +       if (conv != NULL) {
  98. +           notify_notification_set_hint_string(notification, "x-canonical-append", "allow");
  99. +       }
  100. +   }
  101. +
  102.     buddy_icon = purple_buddy_get_icon (buddy);
  103.     if (buddy_icon) {
  104.         icon = pixbuf_from_buddy_icon (buddy_icon);
  105. @@ -316,8 +366,12 @@
  106.     g_signal_connect (notification, "closed", G_CALLBACK(closed_cb), NULL);
  107.  
  108.     notify_notification_set_urgency (notification, NOTIFY_URGENCY_NORMAL);
  109. -
  110. -   notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);
  111. +  
  112. +   /* Check if notification server can use actions */
  113. +   if (notify_supports_actions)
  114. +   {
  115. +       notify_notification_add_action (notification, "show", _("Show"), action_cb, NULL, NULL);
  116. +   }
  117.  
  118.     if (!notify_notification_show (notification, NULL)) {
  119.         purple_debug_error (PLUGIN_ID, "notify(), failed to send notification\n");
  120. @@ -329,7 +383,7 @@
  121.  notify_buddy_signon_cb (PurpleBuddy *buddy,
  122.                         gpointer data)
  123.  {
  124. -   gchar *tr_name, *title;
  125. +   gchar *tr_name;
  126.     gboolean blocked;
  127.  
  128.     g_return_if_fail (buddy);
  129. @@ -349,19 +403,16 @@
  130.  
  131.     tr_name = truncate_escape_string (best_name (buddy), 25);
  132.  
  133. -   title = g_strdup_printf (_("%s signed on"), tr_name);
  134. -
  135. -   notify (title, NULL, buddy);
  136. +   notify (tr_name, "signed on", buddy, NULL);
  137.  
  138.     g_free (tr_name);
  139. -   g_free (title);
  140.  }
  141.  
  142.  static void
  143.  notify_buddy_signoff_cb (PurpleBuddy *buddy,
  144.                          gpointer data)
  145.  {
  146. -   gchar *tr_name, *title;
  147. +   gchar *tr_name;
  148.     gboolean blocked;
  149.  
  150.     g_return_if_fail (buddy);
  151. @@ -381,18 +432,16 @@
  152.  
  153.     tr_name = truncate_escape_string (best_name (buddy), 25);
  154.  
  155. -   title = g_strdup_printf (_("%s signed off"), tr_name);
  156. -
  157. -   notify (title, NULL, buddy);
  158. +   notify (tr_name, "signed off", buddy, NULL);
  159.  
  160.     g_free (tr_name);
  161. -   g_free (title);
  162.  }
  163.  
  164.  static void
  165.  notify_msg_sent (PurpleAccount *account,
  166.                  const gchar *sender,
  167. -                const gchar *message)
  168. +                const gchar *message,
  169. +                PurpleConversation *conv)
  170.  {
  171.     PurpleBuddy *buddy;
  172.     gchar *title, *body, *tr_name;
  173. @@ -411,7 +460,7 @@
  174.     title = g_strdup_printf (_("%s says:"), tr_name);
  175.     body = purple_markup_strip_html (message);
  176.  
  177. -   notify (title, body, buddy);
  178. +   notify (title, body, buddy, conv);
  179.  
  180.     g_free (tr_name);
  181.     g_free (title);
  182. @@ -447,7 +496,7 @@
  183.     if (!should_notify_unavailable (account))
  184.         return;
  185.  
  186. -   notify_msg_sent (account, sender, message);
  187. +   notify_msg_sent (account, sender, message, conv);
  188.  }
  189.  
  190.  static void
  191. @@ -466,7 +515,7 @@
  192.     if (!g_strstr_len (message, strlen(message), nick))
  193.         return;
  194.  
  195. -   notify_msg_sent (account, sender, message);
  196. +   notify_msg_sent (account, sender, message, conv);
  197.  }
  198.  
  199.  static gboolean
  200. @@ -479,6 +528,8 @@
  201.         return FALSE;
  202.     }
  203.  
  204. +   notify_check_caps();
  205. +
  206.     conv_handle = purple_conversations_get_handle ();
  207.     blist_handle = purple_blist_get_handle ();
  208.     conn_handle = purple_connections_get_handle();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement