Sun, 02 Feb 2014 01:22:13 +0530
Merged gtkdoc-conversion branch
| 35122 | 1 | /* |
| 2 | * Integration with Unity's messaging menu and launcher | |
| 3 | * Copyright (C) 2013 Ankit Vani <a@nevitus.org> | |
| 4 | * | |
| 5 | * This program is free software; you can redistribute it and/or modify | |
| 6 | * it under the terms of the GNU General Public License as published by | |
| 7 | * the Free Software Foundation; either version 2 of the License, or | |
| 8 | * (at your option) any later version. | |
| 9 | * | |
| 10 | * This program is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with this program; if not, write to the Free Software | |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
| 18 | */ | |
| 19 | #include "internal.h" | |
| 20 | #include "version.h" | |
| 21 | #include "account.h" | |
| 22 | #include "savedstatuses.h" | |
| 23 | ||
| 24 | #include "gtkplugin.h" | |
| 25 | #include "gtkconv.h" | |
| 26 | #include "gtkutils.h" | |
| 27 | ||
| 28 | #include <unity.h> | |
| 29 | #include <messaging-menu.h> | |
| 30 | ||
| 31 | #define UNITY_PLUGIN_ID "gtk-unity-integration" | |
| 32 | ||
| 33 | static MessagingMenuApp *mmapp = NULL; | |
| 34 | static UnityLauncherEntry *launcher = NULL; | |
| 35 | static guint n_sources = 0; | |
| 36 | static gint launcher_count; | |
| 37 | static gint messaging_menu_text; | |
| 38 | static gboolean alert_chat_nick = TRUE; | |
| 39 | ||
| 40 | enum { | |
| 41 | LAUNCHER_COUNT_DISABLE, | |
| 42 | LAUNCHER_COUNT_MESSAGES, | |
| 43 | LAUNCHER_COUNT_SOURCES, | |
| 44 | }; | |
| 45 | ||
| 46 | enum { | |
| 47 | MESSAGING_MENU_COUNT, | |
| 48 | MESSAGING_MENU_TIME, | |
| 49 | }; | |
| 50 | ||
| 51 | static int attach_signals(PurpleConversation *conv); | |
| 52 | static void detach_signals(PurpleConversation *conv); | |
| 53 | ||
| 54 | static void | |
| 55 | update_launcher() | |
| 56 | { | |
| 57 | guint count = 0; | |
| 58 | GList *convs = NULL; | |
| 35124 | 59 | g_return_if_fail(launcher != NULL); |
| 60 | if (launcher_count == LAUNCHER_COUNT_DISABLE) | |
| 61 | return; | |
| 35122 | 62 | |
| 63 | if (launcher_count == LAUNCHER_COUNT_MESSAGES) { | |
| 35123 | 64 | for (convs = purple_conversations_get_all(); convs != NULL; convs = convs->next) { |
| 35122 | 65 | PurpleConversation *conv = convs->data; |
| 35123 | 66 | count += GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 67 | "unity-message-count")); | |
| 35122 | 68 | } |
| 69 | } else { | |
| 70 | count = n_sources; | |
| 71 | } | |
| 72 | ||
| 73 | if (launcher != NULL) { | |
| 74 | if (count > 0) | |
| 75 | unity_launcher_entry_set_count_visible(launcher, TRUE); | |
| 76 | else | |
| 77 | unity_launcher_entry_set_count_visible(launcher, FALSE); | |
| 78 | unity_launcher_entry_set_count(launcher, count); | |
| 79 | } | |
| 80 | } | |
| 81 | ||
| 82 | static gchar * | |
| 83 | conversation_id(PurpleConversation *conv) | |
| 84 | { | |
| 85 | PurpleAccount *account = purple_conversation_get_account(conv); | |
| 86 | ||
| 35123 | 87 | return g_strconcat((PURPLE_IS_IM_CONVERSATION(conv) ? "im" : |
| 88 | PURPLE_IS_CHAT_CONVERSATION(conv) ? "chat" : "misc"), ":", | |
| 89 | purple_conversation_get_name(conv), ":", | |
| 90 | purple_account_get_username(account), ":", | |
| 91 | purple_account_get_protocol_id(account), NULL); | |
| 35122 | 92 | } |
| 93 | ||
| 94 | static void | |
| 95 | messaging_menu_add_conversation(PurpleConversation *conv, gint count) | |
| 96 | { | |
| 97 | gchar *id; | |
| 98 | g_return_if_fail(count > 0); | |
| 99 | id = conversation_id(conv); | |
| 100 | ||
| 101 | /* GBytesIcon may be useful for messaging menu source icons using buddy | |
| 102 | icon data for IMs */ | |
| 103 | if (!messaging_menu_app_has_source(mmapp, id)) | |
| 104 | messaging_menu_app_append_source(mmapp, id, NULL, | |
| 35123 | 105 | purple_conversation_get_title(conv)); |
| 35122 | 106 | |
| 107 | if (messaging_menu_text == MESSAGING_MENU_TIME) | |
| 108 | messaging_menu_app_set_source_time(mmapp, id, g_get_real_time()); | |
| 109 | else if (messaging_menu_text == MESSAGING_MENU_COUNT) | |
| 110 | messaging_menu_app_set_source_count(mmapp, id, count); | |
| 111 | messaging_menu_app_draw_attention(mmapp, id); | |
| 112 | ||
| 113 | g_free(id); | |
| 114 | } | |
| 115 | ||
| 116 | static void | |
| 117 | messaging_menu_remove_conversation(PurpleConversation *conv) | |
| 118 | { | |
| 119 | gchar *id = conversation_id(conv); | |
| 120 | if (messaging_menu_app_has_source(mmapp, id)) | |
| 121 | messaging_menu_app_remove_source(mmapp, id); | |
| 122 | g_free(id); | |
| 123 | } | |
| 124 | ||
| 125 | static void | |
| 126 | refill_messaging_menu() | |
| 127 | { | |
| 128 | GList *convs; | |
| 129 | ||
| 35123 | 130 | for (convs = purple_conversations_get_all(); convs != NULL; convs = convs->next) { |
| 35122 | 131 | PurpleConversation *conv = convs->data; |
| 132 | messaging_menu_add_conversation(conv, | |
| 35123 | 133 | GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 134 | "unity-message-count"))); | |
| 35122 | 135 | } |
| 136 | } | |
| 137 | ||
| 138 | static int | |
| 139 | alert(PurpleConversation *conv) | |
| 140 | { | |
| 141 | gint count; | |
| 142 | PidginWindow *purplewin = NULL; | |
| 143 | if (conv == NULL || PIDGIN_CONVERSATION(conv) == NULL) | |
| 144 | return 0; | |
| 145 | ||
| 146 | purplewin = PIDGIN_CONVERSATION(conv)->win; | |
| 147 | ||
| 148 | if (!pidgin_conv_window_has_focus(purplewin) || | |
| 149 | !pidgin_conv_window_is_active_conversation(conv)) | |
| 150 | { | |
| 35123 | 151 | count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 152 | "unity-message-count")); | |
| 35122 | 153 | if (!count++) |
| 154 | ++n_sources; | |
| 155 | ||
| 35123 | 156 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 157 | GINT_TO_POINTER(count)); | |
| 35122 | 158 | messaging_menu_add_conversation(conv, count); |
| 159 | update_launcher(); | |
| 160 | } | |
| 161 | ||
| 162 | return 0; | |
| 163 | } | |
| 164 | ||
| 165 | static void | |
| 166 | unalert(PurpleConversation *conv) | |
| 167 | { | |
| 35123 | 168 | if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-message-count")) > 0) |
| 35122 | 169 | --n_sources; |
| 35123 | 170 | |
| 171 | g_object_set_data(G_OBJECT(conv), "unity-message-count", | |
| 172 | GINT_TO_POINTER(0)); | |
| 35122 | 173 | messaging_menu_remove_conversation(conv); |
| 174 | update_launcher(); | |
| 175 | } | |
| 176 | ||
| 177 | static int | |
| 178 | unalert_cb(GtkWidget *widget, gpointer data, PurpleConversation *conv) | |
| 179 | { | |
| 180 | unalert(conv); | |
| 181 | return 0; | |
| 182 | } | |
| 183 | ||
| 184 | static gboolean | |
| 185 | message_displayed_cb(PurpleAccount *account, const char *who, char *message, | |
| 35123 | 186 | PurpleConversation *conv, PurpleMessageFlags flags) |
| 35122 | 187 | { |
| 35123 | 188 | if ((PURPLE_IS_CHAT_CONVERSATION(conv) && alert_chat_nick && |
| 189 | !(flags & PURPLE_MESSAGE_NICK))) | |
| 35122 | 190 | return FALSE; |
| 191 | ||
| 192 | if ((flags & PURPLE_MESSAGE_RECV) && !(flags & PURPLE_MESSAGE_DELAYED)) | |
| 193 | alert(conv); | |
| 194 | ||
| 195 | return FALSE; | |
| 196 | } | |
| 197 | ||
| 198 | static void | |
| 199 | im_sent_im(PurpleAccount *account, const char *receiver, const char *message) | |
| 200 | { | |
| 35123 | 201 | PurpleIMConversation *im = NULL; |
| 202 | im = purple_conversations_find_im_with_account(receiver, account); | |
| 203 | unalert(PURPLE_CONVERSATION(im)); | |
| 35122 | 204 | } |
| 205 | ||
| 206 | static void | |
| 207 | chat_sent_im(PurpleAccount *account, const char *message, int id) | |
| 208 | { | |
| 35123 | 209 | PurpleChatConversation *chat = NULL; |
| 210 | chat = purple_conversations_find_chat(purple_account_get_connection(account), id); | |
| 211 | unalert(PURPLE_CONVERSATION(chat)); | |
| 35122 | 212 | } |
| 213 | ||
| 214 | static void | |
| 215 | conv_created(PurpleConversation *conv) | |
| 216 | { | |
| 35123 | 217 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 218 | GINT_TO_POINTER(0)); | |
| 35122 | 219 | attach_signals(conv); |
| 220 | } | |
| 221 | ||
| 222 | static void | |
| 223 | deleting_conv(PurpleConversation *conv) | |
| 224 | { | |
| 225 | detach_signals(conv); | |
| 226 | unalert(conv); | |
| 227 | } | |
| 228 | ||
| 229 | static void | |
| 230 | message_source_activated(MessagingMenuApp *app, const gchar *id, | |
| 35123 | 231 | gpointer user_data) |
| 35122 | 232 | { |
| 233 | gchar **sections = g_strsplit(id, ":", 0); | |
| 234 | PurpleConversation *conv = NULL; | |
| 235 | PurpleAccount *account; | |
| 236 | PidginWindow *purplewin = NULL; | |
| 237 | ||
| 238 | char *type = sections[0]; | |
| 239 | char *cname = sections[1]; | |
| 240 | char *aname = sections[2]; | |
| 241 | char *protocol = sections[3]; | |
| 242 | ||
| 243 | account = purple_accounts_find(aname, protocol); | |
| 35123 | 244 | |
| 245 | if (g_strcmp0(type, "im") == 0) | |
| 246 | conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(cname, account)); | |
| 247 | else if (g_strcmp0(type, "chat") == 0) | |
| 248 | conv = PURPLE_CONVERSATION(purple_conversations_find_chat_with_account(cname, account)); | |
| 249 | else | |
| 250 | conv = purple_conversations_find_with_account(cname, account); | |
| 35122 | 251 | |
| 252 | if (conv) { | |
| 253 | unalert(conv); | |
| 254 | purplewin = PIDGIN_CONVERSATION(conv)->win; | |
| 255 | pidgin_conv_window_switch_gtkconv(purplewin, PIDGIN_CONVERSATION(conv)); | |
| 256 | gdk_window_focus(gtk_widget_get_window(purplewin->window), time(NULL)); | |
| 257 | } | |
| 258 | g_strfreev (sections); | |
| 259 | } | |
| 260 | ||
| 261 | static PurpleSavedStatus * | |
| 262 | create_transient_status(PurpleStatusPrimitive primitive, PurpleStatusType *status_type) | |
| 263 | { | |
| 264 | PurpleSavedStatus *saved_status = purple_savedstatus_new(NULL, primitive); | |
| 265 | ||
| 266 | if(status_type != NULL) { | |
| 267 | GList *tmp, *active_accts = purple_accounts_get_all_active(); | |
| 268 | for (tmp = active_accts; tmp != NULL; tmp = tmp->next) { | |
| 269 | purple_savedstatus_set_substatus(saved_status, | |
| 270 | (PurpleAccount*) tmp->data, status_type, NULL); | |
| 271 | } | |
| 272 | g_list_free(active_accts); | |
| 273 | } | |
| 274 | ||
| 275 | return saved_status; | |
| 276 | } | |
| 277 | ||
| 278 | static void | |
| 279 | status_changed_cb(PurpleSavedStatus *saved_status) | |
| 280 | { | |
| 281 | MessagingMenuStatus status = MESSAGING_MENU_STATUS_AVAILABLE; | |
| 282 | ||
| 283 | switch (purple_savedstatus_get_type(saved_status)) { | |
| 284 | case PURPLE_STATUS_AVAILABLE: | |
| 285 | case PURPLE_STATUS_MOOD: | |
| 286 | case PURPLE_STATUS_TUNE: | |
| 287 | case PURPLE_STATUS_UNSET: | |
| 288 | status = MESSAGING_MENU_STATUS_AVAILABLE; | |
| 289 | break; | |
| 290 | ||
| 291 | case PURPLE_STATUS_AWAY: | |
| 292 | case PURPLE_STATUS_EXTENDED_AWAY: | |
| 293 | status = MESSAGING_MENU_STATUS_AWAY; | |
| 294 | break; | |
| 295 | ||
| 296 | case PURPLE_STATUS_INVISIBLE: | |
| 297 | status = MESSAGING_MENU_STATUS_INVISIBLE; | |
| 298 | break; | |
| 299 | ||
| 300 | case PURPLE_STATUS_MOBILE: | |
| 301 | case PURPLE_STATUS_OFFLINE: | |
| 302 | status = MESSAGING_MENU_STATUS_OFFLINE; | |
| 303 | break; | |
| 304 | ||
| 305 | case PURPLE_STATUS_UNAVAILABLE: | |
| 306 | status = MESSAGING_MENU_STATUS_BUSY; | |
| 307 | break; | |
| 308 | ||
| 309 | default: | |
| 310 | g_assert_not_reached(); | |
| 311 | } | |
| 312 | messaging_menu_app_set_status(mmapp, status); | |
| 313 | } | |
| 314 | ||
| 315 | static void | |
| 316 | messaging_menu_status_changed(MessagingMenuApp *mmapp, | |
| 35123 | 317 | MessagingMenuStatus mm_status, gpointer user_data) |
| 35122 | 318 | { |
| 319 | PurpleSavedStatus *saved_status; | |
| 320 | PurpleStatusPrimitive primitive = PURPLE_STATUS_UNSET; | |
| 321 | ||
| 322 | switch (mm_status) { | |
| 323 | case MESSAGING_MENU_STATUS_AVAILABLE: | |
| 324 | primitive = PURPLE_STATUS_AVAILABLE; | |
| 325 | break; | |
| 326 | ||
| 327 | case MESSAGING_MENU_STATUS_AWAY: | |
| 328 | primitive = PURPLE_STATUS_AWAY; | |
| 329 | break; | |
| 330 | ||
| 331 | case MESSAGING_MENU_STATUS_BUSY: | |
| 332 | primitive = PURPLE_STATUS_UNAVAILABLE; | |
| 333 | break; | |
| 334 | ||
| 335 | case MESSAGING_MENU_STATUS_INVISIBLE: | |
| 336 | primitive = PURPLE_STATUS_INVISIBLE; | |
| 337 | break; | |
| 338 | ||
| 339 | case MESSAGING_MENU_STATUS_OFFLINE: | |
| 340 | primitive = PURPLE_STATUS_OFFLINE; | |
| 341 | break; | |
| 342 | ||
| 343 | default: | |
| 344 | g_assert_not_reached(); | |
| 345 | } | |
| 346 | ||
| 347 | saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL); | |
| 348 | if (saved_status == NULL) | |
| 349 | saved_status = create_transient_status(primitive, NULL); | |
| 350 | purple_savedstatus_activate(saved_status); | |
| 351 | } | |
| 352 | ||
| 353 | static void | |
| 354 | alert_config_cb(GtkWidget *widget, gpointer data) | |
| 355 | { | |
| 356 | gboolean on = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
| 357 | purple_prefs_set_bool("/plugins/gtk/unity/alert_chat_nick", on); | |
| 358 | alert_chat_nick = on; | |
| 359 | } | |
| 360 | ||
| 361 | static void | |
| 362 | launcher_config_cb(GtkWidget *widget, gpointer data) | |
| 363 | { | |
| 364 | gint option = GPOINTER_TO_INT(data); | |
| 35124 | 365 | if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) |
| 366 | return; | |
| 35122 | 367 | |
| 368 | purple_prefs_set_int("/plugins/gtk/unity/launcher_count", option); | |
| 369 | launcher_count = option; | |
| 370 | if (option == LAUNCHER_COUNT_DISABLE) | |
| 371 | unity_launcher_entry_set_count_visible(launcher, FALSE); | |
| 372 | else | |
| 373 | update_launcher(); | |
| 374 | } | |
| 375 | ||
| 376 | static void | |
| 377 | messaging_menu_config_cb(GtkWidget *widget, gpointer data) | |
| 378 | { | |
| 379 | gint option = GPOINTER_TO_INT(data); | |
| 35124 | 380 | if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) |
| 381 | return; | |
| 35122 | 382 | |
| 383 | purple_prefs_set_int("/plugins/gtk/unity/messaging_menu_text", option); | |
| 384 | messaging_menu_text = option; | |
| 385 | refill_messaging_menu(); | |
| 386 | } | |
| 387 | ||
| 388 | static int | |
| 389 | attach_signals(PurpleConversation *conv) | |
| 390 | { | |
| 391 | PidginConversation *gtkconv = NULL; | |
| 392 | guint id; | |
| 393 | ||
| 394 | gtkconv = PIDGIN_CONVERSATION(conv); | |
| 395 | if (!gtkconv) | |
| 396 | return 0; | |
| 397 | ||
| 398 | id = g_signal_connect(G_OBJECT(gtkconv->entry), "focus-in-event", | |
| 35123 | 399 | G_CALLBACK(unalert_cb), conv); |
| 400 | g_object_set_data(G_OBJECT(conv), "unity-entry-signal", GUINT_TO_POINTER(id)); | |
| 35122 | 401 | |
| 35123 | 402 | id = g_signal_connect(G_OBJECT(gtkconv->webview), "focus-in-event", |
| 403 | G_CALLBACK(unalert_cb), conv); | |
| 404 | g_object_set_data(G_OBJECT(conv), "unity-webview-signal", GUINT_TO_POINTER(id)); | |
| 35122 | 405 | |
| 406 | return 0; | |
| 407 | } | |
| 408 | ||
| 409 | static void | |
| 410 | detach_signals(PurpleConversation *conv) | |
| 411 | { | |
| 412 | PidginConversation *gtkconv = NULL; | |
| 413 | guint id; | |
| 414 | gtkconv = PIDGIN_CONVERSATION(conv); | |
| 415 | if (!gtkconv) | |
| 416 | return; | |
| 417 | ||
| 35123 | 418 | id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-webview-signal")); |
| 419 | g_signal_handler_disconnect(gtkconv->webview, id); | |
| 35122 | 420 | |
| 35123 | 421 | id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-entry-signal")); |
| 35122 | 422 | g_signal_handler_disconnect(gtkconv->entry, id); |
| 423 | ||
| 35123 | 424 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 425 | GINT_TO_POINTER(0)); | |
| 35122 | 426 | } |
| 427 | ||
| 428 | static GtkWidget * | |
| 429 | get_config_frame(PurplePlugin *plugin) | |
| 430 | { | |
| 431 | GtkWidget *ret = NULL, *frame = NULL; | |
| 432 | GtkWidget *vbox = NULL, *toggle = NULL; | |
| 433 | ||
| 434 | ret = gtk_vbox_new(FALSE, 18); | |
| 435 | gtk_container_set_border_width(GTK_CONTAINER (ret), 12); | |
| 436 | ||
| 437 | /* Alerts */ | |
| 438 | ||
| 439 | frame = pidgin_make_frame(ret, _("Chatroom alerts")); | |
| 440 | vbox = gtk_vbox_new(FALSE, 5); | |
| 441 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 442 | ||
| 443 | toggle = gtk_check_button_new_with_mnemonic(_("Chatroom message alerts _only where someone says your username")); | |
| 444 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
| 445 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 35123 | 446 | purple_prefs_get_bool("/plugins/gtk/unity/alert_chat_nick")); |
| 35122 | 447 | g_signal_connect(G_OBJECT(toggle), "toggled", |
| 35123 | 448 | G_CALLBACK(alert_config_cb), NULL); |
| 35122 | 449 | |
| 450 | /* Launcher integration */ | |
| 451 | ||
| 452 | frame = pidgin_make_frame(ret, _("Launcher Icon")); | |
| 453 | vbox = gtk_vbox_new(FALSE, 5); | |
| 454 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 455 | ||
| 456 | toggle = gtk_radio_button_new_with_mnemonic(NULL, _("_Disable launcher integration")); | |
| 457 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
| 458 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 459 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_DISABLE); | |
| 460 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 461 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_DISABLE)); |
| 35122 | 462 | |
| 463 | toggle = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(toggle), | |
| 35123 | 464 | _("Show number of unread _messages on launcher icon")); |
| 35122 | 465 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 466 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 467 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_MESSAGES); | |
| 468 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 469 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_MESSAGES)); |
| 35122 | 470 | |
| 471 | toggle = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(toggle), | |
|
35317
3c9c77b80a6c
Merge the release-2.x.y branch into default.
Mark Doliner <mark@kingant.net>
diff
changeset
|
472 | _("Show number of unread co_nversations on launcher icon")); |
| 35122 | 473 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 474 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 475 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_SOURCES); | |
| 476 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 477 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_SOURCES)); |
| 35122 | 478 | |
| 479 | /* Messaging menu integration */ | |
| 480 | ||
| 481 | frame = pidgin_make_frame(ret, _("Messaging Menu")); | |
| 482 | vbox = gtk_vbox_new(FALSE, 5); | |
| 483 | gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 484 | ||
| 485 | toggle = gtk_radio_button_new_with_mnemonic(NULL, | |
| 35123 | 486 | _("Show number of _unread messages for conversations in messaging menu")); |
| 35122 | 487 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 488 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 489 | purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text") == MESSAGING_MENU_COUNT); | |
| 490 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 491 | G_CALLBACK(messaging_menu_config_cb), GUINT_TO_POINTER(MESSAGING_MENU_COUNT)); |
| 35122 | 492 | |
| 493 | toggle = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(toggle), | |
| 35123 | 494 | _("Show _elapsed time for unread conversations in messaging menu")); |
| 35122 | 495 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 496 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 497 | purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text") == MESSAGING_MENU_TIME); | |
| 498 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 499 | G_CALLBACK(messaging_menu_config_cb), GUINT_TO_POINTER(MESSAGING_MENU_TIME)); |
| 35122 | 500 | |
| 501 | gtk_widget_show_all(ret); | |
| 502 | return ret; | |
| 503 | } | |
| 504 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
505 | static PidginPluginInfo * |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
506 | plugin_query(GError **error) |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
507 | { |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
508 | const gchar * const authors[] = { |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
509 | "Ankit Vani <a@nevitus.org>", |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
510 | NULL |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
511 | }; |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
512 | |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
513 | return pidgin_plugin_info_new( |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
514 | "id", UNITY_PLUGIN_ID, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
515 | "name", N_("Unity Integration"), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
516 | "version", DISPLAY_VERSION, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
517 | "category", N_("Notification"), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
518 | "summary", N_("Provides integration with Unity."), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
519 | "description", N_("Provides integration with Unity's " |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
520 | "messaging menu and launcher."), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
521 | "authors", authors, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
522 | "website", PURPLE_WEBSITE, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
523 | "abi-version", PURPLE_ABI_VERSION, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
524 | "gtk-config-frame-cb", get_config_frame, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
525 | NULL |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
526 | ); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
527 | } |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
528 | |
| 35122 | 529 | static gboolean |
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
530 | plugin_load(PurplePlugin *plugin, GError **error) |
| 35122 | 531 | { |
| 35123 | 532 | GList *convs = purple_conversations_get_all(); |
| 35122 | 533 | PurpleSavedStatus *saved_status; |
| 534 | void *conv_handle = purple_conversations_get_handle(); | |
| 535 | void *gtk_conv_handle = pidgin_conversations_get_handle(); | |
| 536 | void *savedstat_handle = purple_savedstatuses_get_handle(); | |
| 537 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
538 | purple_prefs_add_none("/plugins/gtk"); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
539 | purple_prefs_add_none("/plugins/gtk/unity"); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
540 | purple_prefs_add_int("/plugins/gtk/unity/launcher_count", LAUNCHER_COUNT_SOURCES); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
541 | purple_prefs_add_int("/plugins/gtk/unity/messaging_menu_text", MESSAGING_MENU_COUNT); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
542 | purple_prefs_add_bool("/plugins/gtk/unity/alert_chat_nick", TRUE); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
543 | |
| 35122 | 544 | alert_chat_nick = purple_prefs_get_bool("/plugins/gtk/unity/alert_chat_nick"); |
| 545 | ||
| 546 | mmapp = messaging_menu_app_new("pidgin.desktop"); | |
| 547 | g_object_ref(mmapp); | |
| 548 | messaging_menu_app_register(mmapp); | |
| 549 | messaging_menu_text = purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text"); | |
| 550 | ||
| 551 | g_signal_connect(mmapp, "activate-source", | |
| 35123 | 552 | G_CALLBACK(message_source_activated), NULL); |
| 35122 | 553 | g_signal_connect(mmapp, "status-changed", |
| 35123 | 554 | G_CALLBACK(messaging_menu_status_changed), NULL); |
| 35122 | 555 | |
| 556 | saved_status = purple_savedstatus_get_current(); | |
| 557 | status_changed_cb(saved_status); | |
| 558 | ||
| 559 | purple_signal_connect(savedstat_handle, "savedstatus-changed", plugin, | |
| 35123 | 560 | PURPLE_CALLBACK(status_changed_cb), NULL); |
| 35122 | 561 | |
| 562 | launcher = unity_launcher_entry_get_for_desktop_id("pidgin.desktop"); | |
| 563 | g_object_ref(launcher); | |
| 564 | launcher_count = purple_prefs_get_int("/plugins/gtk/unity/launcher_count"); | |
| 565 | ||
| 566 | purple_signal_connect(gtk_conv_handle, "displayed-im-msg", plugin, | |
| 35123 | 567 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 568 | purple_signal_connect(gtk_conv_handle, "displayed-chat-msg", plugin, |
| 35123 | 569 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 570 | purple_signal_connect(conv_handle, "sent-im-msg", plugin, |
| 35123 | 571 | PURPLE_CALLBACK(im_sent_im), NULL); |
| 35122 | 572 | purple_signal_connect(conv_handle, "sent-chat-msg", plugin, |
| 35123 | 573 | PURPLE_CALLBACK(chat_sent_im), NULL); |
| 35122 | 574 | purple_signal_connect(conv_handle, "conversation-created", plugin, |
| 35123 | 575 | PURPLE_CALLBACK(conv_created), NULL); |
| 35122 | 576 | purple_signal_connect(conv_handle, "deleting-conversation", plugin, |
| 35123 | 577 | PURPLE_CALLBACK(deleting_conv), NULL); |
| 35122 | 578 | |
| 579 | while (convs) { | |
| 580 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 581 | attach_signals(conv); | |
| 582 | convs = convs->next; | |
| 583 | } | |
| 584 | ||
| 585 | return TRUE; | |
| 586 | } | |
| 587 | ||
| 588 | static gboolean | |
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
589 | plugin_unload(PurplePlugin *plugin, GError **error) |
| 35122 | 590 | { |
| 35123 | 591 | GList *convs = purple_conversations_get_all(); |
| 35122 | 592 | while (convs) { |
| 593 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 594 | unalert(conv); | |
| 595 | detach_signals(conv); | |
| 596 | convs = convs->next; | |
| 597 | } | |
| 35123 | 598 | |
| 35122 | 599 | unity_launcher_entry_set_count_visible(launcher, FALSE); |
| 600 | messaging_menu_app_unregister(mmapp); | |
| 601 | ||
| 602 | g_object_unref(launcher); | |
| 603 | g_object_unref(mmapp); | |
| 604 | return TRUE; | |
| 605 | } | |
| 606 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
607 | PURPLE_PLUGIN_INIT(unity, plugin_query, plugin_load, plugin_unload); |