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