Thu, 26 Mar 2020 20:23:10 -0500
Add a null check to the ui_info unref in jabber
| 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 "account.h" | |
| 21 | #include "savedstatuses.h" | |
|
35534
8e72593def2c
Fix gtk_[hv]box_new gtk3 deprecation warnings in unity plugin
Ankit Vani <a@nevitus.org>
parents:
35378
diff
changeset
|
22 | #include "version.h" |
| 35122 | 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; | |
|
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
|
142 | PidginConvWindow *purplewin = NULL; |
| 35122 | 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 | |
|
36110
63663622e327
Switch write_conv and (displaying|displayed)-(im|chat)-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36103
diff
changeset
|
185 | message_displayed_cb(PurpleConversation *conv, PurpleMessage *msg, gpointer _unused) |
| 35122 | 186 | { |
|
36110
63663622e327
Switch write_conv and (displaying|displayed)-(im|chat)-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36103
diff
changeset
|
187 | 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
|
188 | |
| 35123 | 189 | if ((PURPLE_IS_CHAT_CONVERSATION(conv) && alert_chat_nick && |
| 190 | !(flags & PURPLE_MESSAGE_NICK))) | |
| 35122 | 191 | return FALSE; |
| 192 | ||
| 193 | if ((flags & PURPLE_MESSAGE_RECV) && !(flags & PURPLE_MESSAGE_DELAYED)) | |
| 194 | alert(conv); | |
| 195 | ||
| 196 | return FALSE; | |
| 197 | } | |
| 198 | ||
| 199 | static void | |
|
36081
6764e037a308
Switch sent-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35610
diff
changeset
|
200 | im_sent_im(PurpleAccount *account, PurpleMessage *msg, gpointer _unused) |
| 35122 | 201 | { |
| 35123 | 202 | PurpleIMConversation *im = NULL; |
|
36081
6764e037a308
Switch sent-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35610
diff
changeset
|
203 | im = purple_conversations_find_im_with_account( |
| 36103 | 204 | purple_message_get_recipient(msg), account); |
| 35123 | 205 | unalert(PURPLE_CONVERSATION(im)); |
| 35122 | 206 | } |
| 207 | ||
| 208 | static void | |
|
36082
247d94c903c3
Switch sent-chat-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
36081
diff
changeset
|
209 | chat_sent_im(PurpleAccount *account, PurpleMessage *msg, int id) |
| 35122 | 210 | { |
| 35123 | 211 | PurpleChatConversation *chat = NULL; |
| 212 | chat = purple_conversations_find_chat(purple_account_get_connection(account), id); | |
| 213 | unalert(PURPLE_CONVERSATION(chat)); | |
| 35122 | 214 | } |
| 215 | ||
| 216 | static void | |
| 217 | conv_created(PurpleConversation *conv) | |
| 218 | { | |
| 35123 | 219 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 220 | GINT_TO_POINTER(0)); | |
| 35122 | 221 | attach_signals(conv); |
| 222 | } | |
| 223 | ||
| 224 | static void | |
| 225 | deleting_conv(PurpleConversation *conv) | |
| 226 | { | |
| 227 | detach_signals(conv); | |
| 228 | unalert(conv); | |
| 229 | } | |
| 230 | ||
| 231 | static void | |
| 232 | message_source_activated(MessagingMenuApp *app, const gchar *id, | |
| 35123 | 233 | gpointer user_data) |
| 35122 | 234 | { |
| 235 | gchar **sections = g_strsplit(id, ":", 0); | |
| 236 | PurpleConversation *conv = NULL; | |
| 237 | 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
|
238 | PidginConvWindow *purplewin = NULL; |
| 35122 | 239 | |
| 240 | char *type = sections[0]; | |
| 241 | char *cname = sections[1]; | |
| 242 | char *aname = sections[2]; | |
| 243 | char *protocol = sections[3]; | |
| 244 | ||
| 245 | account = purple_accounts_find(aname, protocol); | |
| 35123 | 246 | |
| 247 | if (g_strcmp0(type, "im") == 0) | |
| 248 | conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(cname, account)); | |
| 249 | else if (g_strcmp0(type, "chat") == 0) | |
| 250 | conv = PURPLE_CONVERSATION(purple_conversations_find_chat_with_account(cname, account)); | |
| 251 | else | |
| 252 | conv = purple_conversations_find_with_account(cname, account); | |
| 35122 | 253 | |
| 254 | if (conv) { | |
| 255 | unalert(conv); | |
| 256 | purplewin = PIDGIN_CONVERSATION(conv)->win; | |
| 257 | pidgin_conv_window_switch_gtkconv(purplewin, PIDGIN_CONVERSATION(conv)); | |
| 258 | gdk_window_focus(gtk_widget_get_window(purplewin->window), time(NULL)); | |
| 259 | } | |
| 260 | g_strfreev (sections); | |
| 261 | } | |
| 262 | ||
| 263 | static PurpleSavedStatus * | |
| 264 | create_transient_status(PurpleStatusPrimitive primitive, PurpleStatusType *status_type) | |
| 265 | { | |
| 266 | PurpleSavedStatus *saved_status = purple_savedstatus_new(NULL, primitive); | |
| 267 | ||
| 268 | if(status_type != NULL) { | |
| 269 | GList *tmp, *active_accts = purple_accounts_get_all_active(); | |
| 270 | for (tmp = active_accts; tmp != NULL; tmp = tmp->next) { | |
| 271 | purple_savedstatus_set_substatus(saved_status, | |
| 272 | (PurpleAccount*) tmp->data, status_type, NULL); | |
| 273 | } | |
| 274 | g_list_free(active_accts); | |
| 275 | } | |
| 276 | ||
| 277 | return saved_status; | |
| 278 | } | |
| 279 | ||
| 280 | static void | |
| 281 | status_changed_cb(PurpleSavedStatus *saved_status) | |
| 282 | { | |
| 283 | MessagingMenuStatus status = MESSAGING_MENU_STATUS_AVAILABLE; | |
| 284 | ||
|
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
|
285 | switch (purple_savedstatus_get_primitive_type(saved_status)) { |
| 35122 | 286 | case PURPLE_STATUS_AVAILABLE: |
| 287 | case PURPLE_STATUS_MOOD: | |
| 288 | case PURPLE_STATUS_TUNE: | |
| 289 | case PURPLE_STATUS_UNSET: | |
| 290 | status = MESSAGING_MENU_STATUS_AVAILABLE; | |
| 291 | break; | |
| 292 | ||
| 293 | case PURPLE_STATUS_AWAY: | |
| 294 | case PURPLE_STATUS_EXTENDED_AWAY: | |
| 295 | status = MESSAGING_MENU_STATUS_AWAY; | |
| 296 | break; | |
| 297 | ||
| 298 | case PURPLE_STATUS_INVISIBLE: | |
| 299 | status = MESSAGING_MENU_STATUS_INVISIBLE; | |
| 300 | break; | |
| 301 | ||
| 302 | case PURPLE_STATUS_MOBILE: | |
| 303 | case PURPLE_STATUS_OFFLINE: | |
| 304 | status = MESSAGING_MENU_STATUS_OFFLINE; | |
| 305 | break; | |
| 306 | ||
| 307 | case PURPLE_STATUS_UNAVAILABLE: | |
| 308 | status = MESSAGING_MENU_STATUS_BUSY; | |
| 309 | break; | |
| 310 | ||
| 311 | default: | |
| 312 | g_assert_not_reached(); | |
| 313 | } | |
| 314 | messaging_menu_app_set_status(mmapp, status); | |
| 315 | } | |
| 316 | ||
| 317 | static void | |
| 318 | messaging_menu_status_changed(MessagingMenuApp *mmapp, | |
| 35123 | 319 | MessagingMenuStatus mm_status, gpointer user_data) |
| 35122 | 320 | { |
| 321 | PurpleSavedStatus *saved_status; | |
| 322 | PurpleStatusPrimitive primitive = PURPLE_STATUS_UNSET; | |
| 323 | ||
| 324 | switch (mm_status) { | |
| 325 | case MESSAGING_MENU_STATUS_AVAILABLE: | |
| 326 | primitive = PURPLE_STATUS_AVAILABLE; | |
| 327 | break; | |
| 328 | ||
| 329 | case MESSAGING_MENU_STATUS_AWAY: | |
| 330 | primitive = PURPLE_STATUS_AWAY; | |
| 331 | break; | |
| 332 | ||
| 333 | case MESSAGING_MENU_STATUS_BUSY: | |
| 334 | primitive = PURPLE_STATUS_UNAVAILABLE; | |
| 335 | break; | |
| 336 | ||
| 337 | case MESSAGING_MENU_STATUS_INVISIBLE: | |
| 338 | primitive = PURPLE_STATUS_INVISIBLE; | |
| 339 | break; | |
| 340 | ||
| 341 | case MESSAGING_MENU_STATUS_OFFLINE: | |
| 342 | primitive = PURPLE_STATUS_OFFLINE; | |
| 343 | break; | |
| 344 | ||
| 345 | default: | |
| 346 | g_assert_not_reached(); | |
| 347 | } | |
| 348 | ||
| 349 | saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL); | |
| 350 | if (saved_status == NULL) | |
| 351 | saved_status = create_transient_status(primitive, NULL); | |
| 352 | purple_savedstatus_activate(saved_status); | |
| 353 | } | |
| 354 | ||
| 355 | static void | |
| 356 | alert_config_cb(GtkWidget *widget, gpointer data) | |
| 357 | { | |
| 358 | gboolean on = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | |
| 359 | purple_prefs_set_bool("/plugins/gtk/unity/alert_chat_nick", on); | |
| 360 | alert_chat_nick = on; | |
| 361 | } | |
| 362 | ||
| 363 | static void | |
| 364 | launcher_config_cb(GtkWidget *widget, gpointer data) | |
| 365 | { | |
| 366 | gint option = GPOINTER_TO_INT(data); | |
| 35124 | 367 | if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) |
| 368 | return; | |
| 35122 | 369 | |
| 370 | purple_prefs_set_int("/plugins/gtk/unity/launcher_count", option); | |
| 371 | launcher_count = option; | |
| 372 | if (option == LAUNCHER_COUNT_DISABLE) | |
| 373 | unity_launcher_entry_set_count_visible(launcher, FALSE); | |
| 374 | else | |
| 375 | update_launcher(); | |
| 376 | } | |
| 377 | ||
| 378 | static void | |
| 379 | messaging_menu_config_cb(GtkWidget *widget, gpointer data) | |
| 380 | { | |
| 381 | gint option = GPOINTER_TO_INT(data); | |
| 35124 | 382 | if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) |
| 383 | return; | |
| 35122 | 384 | |
| 385 | purple_prefs_set_int("/plugins/gtk/unity/messaging_menu_text", option); | |
| 386 | messaging_menu_text = option; | |
| 387 | refill_messaging_menu(); | |
| 388 | } | |
| 389 | ||
| 390 | static int | |
| 391 | attach_signals(PurpleConversation *conv) | |
| 392 | { | |
| 393 | PidginConversation *gtkconv = NULL; | |
| 394 | guint id; | |
| 395 | ||
| 396 | gtkconv = PIDGIN_CONVERSATION(conv); | |
| 397 | if (!gtkconv) | |
| 398 | return 0; | |
| 399 | ||
| 400 | id = g_signal_connect(G_OBJECT(gtkconv->entry), "focus-in-event", | |
| 35123 | 401 | G_CALLBACK(unalert_cb), conv); |
| 402 | g_object_set_data(G_OBJECT(conv), "unity-entry-signal", GUINT_TO_POINTER(id)); | |
| 35122 | 403 | |
| 35123 | 404 | id = g_signal_connect(G_OBJECT(gtkconv->webview), "focus-in-event", |
| 405 | G_CALLBACK(unalert_cb), conv); | |
| 406 | g_object_set_data(G_OBJECT(conv), "unity-webview-signal", GUINT_TO_POINTER(id)); | |
| 35122 | 407 | |
| 408 | return 0; | |
| 409 | } | |
| 410 | ||
| 411 | static void | |
| 412 | detach_signals(PurpleConversation *conv) | |
| 413 | { | |
| 414 | PidginConversation *gtkconv = NULL; | |
| 415 | guint id; | |
| 416 | gtkconv = PIDGIN_CONVERSATION(conv); | |
| 417 | if (!gtkconv) | |
| 418 | return; | |
| 419 | ||
| 35123 | 420 | id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-webview-signal")); |
| 421 | g_signal_handler_disconnect(gtkconv->webview, id); | |
| 35122 | 422 | |
| 35123 | 423 | id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-entry-signal")); |
| 35122 | 424 | g_signal_handler_disconnect(gtkconv->entry, id); |
| 425 | ||
| 35123 | 426 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 427 | GINT_TO_POINTER(0)); | |
| 35122 | 428 | } |
| 429 | ||
| 430 | static GtkWidget * | |
| 431 | get_config_frame(PurplePlugin *plugin) | |
| 432 | { | |
| 433 | GtkWidget *ret = NULL, *frame = NULL; | |
| 434 | GtkWidget *vbox = NULL, *toggle = NULL; | |
| 435 | ||
|
35534
8e72593def2c
Fix gtk_[hv]box_new gtk3 deprecation warnings in unity plugin
Ankit Vani <a@nevitus.org>
parents:
35378
diff
changeset
|
436 | ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18); |
| 35122 | 437 | gtk_container_set_border_width(GTK_CONTAINER (ret), 12); |
| 438 | ||
| 439 | /* Alerts */ | |
| 440 | ||
| 441 | 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
|
442 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 35122 | 443 | gtk_container_add(GTK_CONTAINER(frame), vbox); |
| 444 | ||
| 445 | toggle = gtk_check_button_new_with_mnemonic(_("Chatroom message alerts _only where someone says your username")); | |
| 446 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
| 447 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 35123 | 448 | purple_prefs_get_bool("/plugins/gtk/unity/alert_chat_nick")); |
| 35122 | 449 | g_signal_connect(G_OBJECT(toggle), "toggled", |
| 35123 | 450 | G_CALLBACK(alert_config_cb), NULL); |
| 35122 | 451 | |
| 452 | /* Launcher integration */ | |
| 453 | ||
| 454 | 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
|
455 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 35122 | 456 | gtk_container_add(GTK_CONTAINER(frame), vbox); |
| 457 | ||
| 458 | toggle = gtk_radio_button_new_with_mnemonic(NULL, _("_Disable launcher integration")); | |
| 459 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); | |
| 460 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 461 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_DISABLE); | |
| 462 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 463 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_DISABLE)); |
| 35122 | 464 | |
| 465 | toggle = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(toggle), | |
| 35123 | 466 | _("Show number of unread _messages on launcher icon")); |
| 35122 | 467 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 468 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 469 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_MESSAGES); | |
| 470 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 471 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_MESSAGES)); |
| 35122 | 472 | |
| 473 | 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
|
474 | _("Show number of unread co_nversations on launcher icon")); |
| 35122 | 475 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 476 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 477 | purple_prefs_get_int("/plugins/gtk/unity/launcher_count") == LAUNCHER_COUNT_SOURCES); | |
| 478 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 479 | G_CALLBACK(launcher_config_cb), GUINT_TO_POINTER(LAUNCHER_COUNT_SOURCES)); |
| 35122 | 480 | |
| 481 | /* Messaging menu integration */ | |
| 482 | ||
| 483 | 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
|
484 | vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 35122 | 485 | gtk_container_add(GTK_CONTAINER(frame), vbox); |
| 486 | ||
| 487 | toggle = gtk_radio_button_new_with_mnemonic(NULL, | |
| 35123 | 488 | _("Show number of _unread messages for conversations in messaging menu")); |
| 35122 | 489 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 490 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 491 | purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text") == MESSAGING_MENU_COUNT); | |
| 492 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 493 | G_CALLBACK(messaging_menu_config_cb), GUINT_TO_POINTER(MESSAGING_MENU_COUNT)); |
| 35122 | 494 | |
| 495 | toggle = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(toggle), | |
| 35123 | 496 | _("Show _elapsed time for unread conversations in messaging menu")); |
| 35122 | 497 | gtk_box_pack_start(GTK_BOX(vbox), toggle, FALSE, FALSE, 0); |
| 498 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | |
| 499 | purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text") == MESSAGING_MENU_TIME); | |
| 500 | g_signal_connect(G_OBJECT(toggle), "toggled", | |
| 35123 | 501 | G_CALLBACK(messaging_menu_config_cb), GUINT_TO_POINTER(MESSAGING_MENU_TIME)); |
| 35122 | 502 | |
| 503 | gtk_widget_show_all(ret); | |
| 504 | return ret; | |
| 505 | } | |
| 506 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
507 | static PidginPluginInfo * |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
508 | plugin_query(GError **error) |
|
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 | const gchar * const authors[] = { |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
511 | "Ankit Vani <a@nevitus.org>", |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
512 | NULL |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
513 | }; |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
514 | |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
515 | return pidgin_plugin_info_new( |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
516 | "id", UNITY_PLUGIN_ID, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
517 | "name", N_("Unity Integration"), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
518 | "version", DISPLAY_VERSION, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
519 | "category", N_("Notification"), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
520 | "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
|
521 | "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
|
522 | "messaging menu and launcher."), |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
523 | "authors", authors, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
524 | "website", PURPLE_WEBSITE, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
525 | "abi-version", PURPLE_ABI_VERSION, |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
526 | "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
|
527 | NULL |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
528 | ); |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
529 | } |
|
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
530 | |
| 35122 | 531 | static gboolean |
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
532 | plugin_load(PurplePlugin *plugin, GError **error) |
| 35122 | 533 | { |
| 35123 | 534 | GList *convs = purple_conversations_get_all(); |
| 35122 | 535 | PurpleSavedStatus *saved_status; |
| 536 | void *conv_handle = purple_conversations_get_handle(); | |
| 537 | void *gtk_conv_handle = pidgin_conversations_get_handle(); | |
| 538 | void *savedstat_handle = purple_savedstatuses_get_handle(); | |
| 539 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
540 | 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
|
541 | 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
|
542 | 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
|
543 | 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
|
544 | 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
|
545 | |
| 35122 | 546 | alert_chat_nick = purple_prefs_get_bool("/plugins/gtk/unity/alert_chat_nick"); |
| 547 | ||
| 548 | mmapp = messaging_menu_app_new("pidgin.desktop"); | |
| 549 | g_object_ref(mmapp); | |
| 550 | messaging_menu_app_register(mmapp); | |
| 551 | messaging_menu_text = purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text"); | |
| 552 | ||
| 553 | g_signal_connect(mmapp, "activate-source", | |
| 35123 | 554 | G_CALLBACK(message_source_activated), NULL); |
| 35122 | 555 | g_signal_connect(mmapp, "status-changed", |
| 35123 | 556 | G_CALLBACK(messaging_menu_status_changed), NULL); |
| 35122 | 557 | |
| 558 | saved_status = purple_savedstatus_get_current(); | |
| 559 | status_changed_cb(saved_status); | |
| 560 | ||
| 561 | purple_signal_connect(savedstat_handle, "savedstatus-changed", plugin, | |
| 35123 | 562 | PURPLE_CALLBACK(status_changed_cb), NULL); |
| 35122 | 563 | |
| 564 | launcher = unity_launcher_entry_get_for_desktop_id("pidgin.desktop"); | |
| 565 | g_object_ref(launcher); | |
| 566 | launcher_count = purple_prefs_get_int("/plugins/gtk/unity/launcher_count"); | |
| 567 | ||
| 568 | purple_signal_connect(gtk_conv_handle, "displayed-im-msg", plugin, | |
| 35123 | 569 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 570 | purple_signal_connect(gtk_conv_handle, "displayed-chat-msg", plugin, |
| 35123 | 571 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 572 | purple_signal_connect(conv_handle, "sent-im-msg", plugin, |
| 35123 | 573 | PURPLE_CALLBACK(im_sent_im), NULL); |
| 35122 | 574 | purple_signal_connect(conv_handle, "sent-chat-msg", plugin, |
| 35123 | 575 | PURPLE_CALLBACK(chat_sent_im), NULL); |
| 35122 | 576 | purple_signal_connect(conv_handle, "conversation-created", plugin, |
| 35123 | 577 | PURPLE_CALLBACK(conv_created), NULL); |
| 35122 | 578 | purple_signal_connect(conv_handle, "deleting-conversation", plugin, |
| 35123 | 579 | PURPLE_CALLBACK(deleting_conv), NULL); |
| 35122 | 580 | |
| 581 | while (convs) { | |
| 582 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 583 | attach_signals(conv); | |
| 584 | convs = convs->next; | |
| 585 | } | |
| 586 | ||
| 587 | return TRUE; | |
| 588 | } | |
| 589 | ||
| 590 | static gboolean | |
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
591 | plugin_unload(PurplePlugin *plugin, GError **error) |
| 35122 | 592 | { |
| 35123 | 593 | GList *convs = purple_conversations_get_all(); |
| 35122 | 594 | while (convs) { |
| 595 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 596 | unalert(conv); | |
| 597 | detach_signals(conv); | |
| 598 | convs = convs->next; | |
| 599 | } | |
| 35123 | 600 | |
| 35122 | 601 | unity_launcher_entry_set_count_visible(launcher, FALSE); |
| 602 | messaging_menu_app_unregister(mmapp); | |
| 603 | ||
| 604 | g_object_unref(launcher); | |
| 605 | g_object_unref(mmapp); | |
| 606 | return TRUE; | |
| 607 | } | |
| 608 | ||
|
36969
c78437610c6d
Refactored unity plugin to use the new plugin API
Ankit Vani <a@nevitus.org>
parents:
35125
diff
changeset
|
609 | PURPLE_PLUGIN_INIT(unity, plugin_query, plugin_load, plugin_unload); |