Fri, 23 May 2014 09:20:34 +0200
Split PurpleMessage into incoming, outgoing and system
| 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 | |
|
35534
8e72593def2c
Fix gtk_[hv]box_new gtk3 deprecation warnings in unity plugin
Ankit Vani <a@nevitus.org>
parents:
35378
diff
changeset
|
24 | #include "gtk3compat.h" |
| 35122 | 25 | #include "gtkplugin.h" |
| 26 | #include "gtkconv.h" | |
| 27 | #include "gtkutils.h" | |
| 28 | ||
| 29 | #include <unity.h> | |
| 30 | #include <messaging-menu.h> | |
| 31 | ||
| 32 | #define UNITY_PLUGIN_ID "gtk-unity-integration" | |
| 33 | ||
| 34 | static MessagingMenuApp *mmapp = NULL; | |
| 35 | static UnityLauncherEntry *launcher = NULL; | |
| 36 | static guint n_sources = 0; | |
| 37 | static gint launcher_count; | |
| 38 | static gint messaging_menu_text; | |
| 39 | static gboolean alert_chat_nick = TRUE; | |
| 40 | ||
| 41 | enum { | |
| 42 | LAUNCHER_COUNT_DISABLE, | |
| 43 | LAUNCHER_COUNT_MESSAGES, | |
| 44 | LAUNCHER_COUNT_SOURCES, | |
| 45 | }; | |
| 46 | ||
| 47 | enum { | |
| 48 | MESSAGING_MENU_COUNT, | |
| 49 | MESSAGING_MENU_TIME, | |
| 50 | }; | |
| 51 | ||
| 52 | static int attach_signals(PurpleConversation *conv); | |
| 53 | static void detach_signals(PurpleConversation *conv); | |
| 54 | ||
| 55 | static void | |
| 56 | update_launcher() | |
| 57 | { | |
| 58 | guint count = 0; | |
| 59 | GList *convs = NULL; | |
| 35124 | 60 | g_return_if_fail(launcher != NULL); |
| 61 | if (launcher_count == LAUNCHER_COUNT_DISABLE) | |
| 62 | return; | |
| 35122 | 63 | |
| 64 | if (launcher_count == LAUNCHER_COUNT_MESSAGES) { | |
| 35123 | 65 | for (convs = purple_conversations_get_all(); convs != NULL; convs = convs->next) { |
| 35122 | 66 | PurpleConversation *conv = convs->data; |
| 35123 | 67 | count += GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 68 | "unity-message-count")); | |
| 35122 | 69 | } |
| 70 | } else { | |
| 71 | count = n_sources; | |
| 72 | } | |
| 73 | ||
| 74 | if (launcher != NULL) { | |
| 75 | if (count > 0) | |
| 76 | unity_launcher_entry_set_count_visible(launcher, TRUE); | |
| 77 | else | |
| 78 | unity_launcher_entry_set_count_visible(launcher, FALSE); | |
| 79 | unity_launcher_entry_set_count(launcher, count); | |
| 80 | } | |
| 81 | } | |
| 82 | ||
| 83 | static gchar * | |
| 84 | conversation_id(PurpleConversation *conv) | |
| 85 | { | |
| 86 | PurpleAccount *account = purple_conversation_get_account(conv); | |
| 87 | ||
| 35123 | 88 | return g_strconcat((PURPLE_IS_IM_CONVERSATION(conv) ? "im" : |
| 89 | PURPLE_IS_CHAT_CONVERSATION(conv) ? "chat" : "misc"), ":", | |
| 90 | purple_conversation_get_name(conv), ":", | |
| 91 | purple_account_get_username(account), ":", | |
| 92 | purple_account_get_protocol_id(account), NULL); | |
| 35122 | 93 | } |
| 94 | ||
| 95 | static void | |
| 96 | messaging_menu_add_conversation(PurpleConversation *conv, gint count) | |
| 97 | { | |
| 98 | gchar *id; | |
| 99 | g_return_if_fail(count > 0); | |
| 100 | id = conversation_id(conv); | |
| 101 | ||
| 102 | /* GBytesIcon may be useful for messaging menu source icons using buddy | |
| 103 | icon data for IMs */ | |
| 104 | if (!messaging_menu_app_has_source(mmapp, id)) | |
| 105 | messaging_menu_app_append_source(mmapp, id, NULL, | |
| 35123 | 106 | purple_conversation_get_title(conv)); |
| 35122 | 107 | |
| 108 | if (messaging_menu_text == MESSAGING_MENU_TIME) | |
| 109 | messaging_menu_app_set_source_time(mmapp, id, g_get_real_time()); | |
| 110 | else if (messaging_menu_text == MESSAGING_MENU_COUNT) | |
| 111 | messaging_menu_app_set_source_count(mmapp, id, count); | |
| 112 | messaging_menu_app_draw_attention(mmapp, id); | |
| 113 | ||
| 114 | g_free(id); | |
| 115 | } | |
| 116 | ||
| 117 | static void | |
| 118 | messaging_menu_remove_conversation(PurpleConversation *conv) | |
| 119 | { | |
| 120 | gchar *id = conversation_id(conv); | |
| 121 | if (messaging_menu_app_has_source(mmapp, id)) | |
| 122 | messaging_menu_app_remove_source(mmapp, id); | |
| 123 | g_free(id); | |
| 124 | } | |
| 125 | ||
| 126 | static void | |
| 127 | refill_messaging_menu() | |
| 128 | { | |
| 129 | GList *convs; | |
| 130 | ||
| 35123 | 131 | for (convs = purple_conversations_get_all(); convs != NULL; convs = convs->next) { |
| 35122 | 132 | PurpleConversation *conv = convs->data; |
| 133 | messaging_menu_add_conversation(conv, | |
| 35123 | 134 | GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 135 | "unity-message-count"))); | |
| 35122 | 136 | } |
| 137 | } | |
| 138 | ||
| 139 | static int | |
| 140 | alert(PurpleConversation *conv) | |
| 141 | { | |
| 142 | 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
|
143 | PidginConvWindow *purplewin = NULL; |
| 35122 | 144 | if (conv == NULL || PIDGIN_CONVERSATION(conv) == NULL) |
| 145 | return 0; | |
| 146 | ||
| 147 | purplewin = PIDGIN_CONVERSATION(conv)->win; | |
| 148 | ||
| 149 | if (!pidgin_conv_window_has_focus(purplewin) || | |
| 150 | !pidgin_conv_window_is_active_conversation(conv)) | |
| 151 | { | |
| 35123 | 152 | count = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), |
| 153 | "unity-message-count")); | |
| 35122 | 154 | if (!count++) |
| 155 | ++n_sources; | |
| 156 | ||
| 35123 | 157 | g_object_set_data(G_OBJECT(conv), "unity-message-count", |
| 158 | GINT_TO_POINTER(count)); | |
| 35122 | 159 | messaging_menu_add_conversation(conv, count); |
| 160 | update_launcher(); | |
| 161 | } | |
| 162 | ||
| 163 | return 0; | |
| 164 | } | |
| 165 | ||
| 166 | static void | |
| 167 | unalert(PurpleConversation *conv) | |
| 168 | { | |
| 35123 | 169 | if (GPOINTER_TO_INT(g_object_get_data(G_OBJECT(conv), "unity-message-count")) > 0) |
| 35122 | 170 | --n_sources; |
| 35123 | 171 | |
| 172 | g_object_set_data(G_OBJECT(conv), "unity-message-count", | |
| 173 | GINT_TO_POINTER(0)); | |
| 35122 | 174 | messaging_menu_remove_conversation(conv); |
| 175 | update_launcher(); | |
| 176 | } | |
| 177 | ||
| 178 | static int | |
| 179 | unalert_cb(GtkWidget *widget, gpointer data, PurpleConversation *conv) | |
| 180 | { | |
| 181 | unalert(conv); | |
| 182 | return 0; | |
| 183 | } | |
| 184 | ||
| 185 | static gboolean | |
| 186 | message_displayed_cb(PurpleAccount *account, const char *who, char *message, | |
| 35123 | 187 | PurpleConversation *conv, PurpleMessageFlags flags) |
| 35122 | 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( |
|
6764e037a308
Switch sent-im-msg to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35610
diff
changeset
|
204 | purple_message_get_who(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 | ||
| 507 | static gboolean | |
| 508 | plugin_load(PurplePlugin *plugin) | |
| 509 | { | |
| 35123 | 510 | GList *convs = purple_conversations_get_all(); |
| 35122 | 511 | PurpleSavedStatus *saved_status; |
| 512 | void *conv_handle = purple_conversations_get_handle(); | |
| 513 | void *gtk_conv_handle = pidgin_conversations_get_handle(); | |
| 514 | void *savedstat_handle = purple_savedstatuses_get_handle(); | |
| 515 | ||
| 516 | alert_chat_nick = purple_prefs_get_bool("/plugins/gtk/unity/alert_chat_nick"); | |
| 517 | ||
| 518 | mmapp = messaging_menu_app_new("pidgin.desktop"); | |
| 519 | g_object_ref(mmapp); | |
| 520 | messaging_menu_app_register(mmapp); | |
| 521 | messaging_menu_text = purple_prefs_get_int("/plugins/gtk/unity/messaging_menu_text"); | |
| 522 | ||
| 523 | g_signal_connect(mmapp, "activate-source", | |
| 35123 | 524 | G_CALLBACK(message_source_activated), NULL); |
| 35122 | 525 | g_signal_connect(mmapp, "status-changed", |
| 35123 | 526 | G_CALLBACK(messaging_menu_status_changed), NULL); |
| 35122 | 527 | |
| 528 | saved_status = purple_savedstatus_get_current(); | |
| 529 | status_changed_cb(saved_status); | |
| 530 | ||
| 531 | purple_signal_connect(savedstat_handle, "savedstatus-changed", plugin, | |
| 35123 | 532 | PURPLE_CALLBACK(status_changed_cb), NULL); |
| 35122 | 533 | |
| 534 | launcher = unity_launcher_entry_get_for_desktop_id("pidgin.desktop"); | |
| 535 | g_object_ref(launcher); | |
| 536 | launcher_count = purple_prefs_get_int("/plugins/gtk/unity/launcher_count"); | |
| 537 | ||
| 538 | purple_signal_connect(gtk_conv_handle, "displayed-im-msg", plugin, | |
| 35123 | 539 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 540 | purple_signal_connect(gtk_conv_handle, "displayed-chat-msg", plugin, |
| 35123 | 541 | PURPLE_CALLBACK(message_displayed_cb), NULL); |
| 35122 | 542 | purple_signal_connect(conv_handle, "sent-im-msg", plugin, |
| 35123 | 543 | PURPLE_CALLBACK(im_sent_im), NULL); |
| 35122 | 544 | purple_signal_connect(conv_handle, "sent-chat-msg", plugin, |
| 35123 | 545 | PURPLE_CALLBACK(chat_sent_im), NULL); |
| 35122 | 546 | purple_signal_connect(conv_handle, "conversation-created", plugin, |
| 35123 | 547 | PURPLE_CALLBACK(conv_created), NULL); |
| 35122 | 548 | purple_signal_connect(conv_handle, "deleting-conversation", plugin, |
| 35123 | 549 | PURPLE_CALLBACK(deleting_conv), NULL); |
| 35122 | 550 | |
| 551 | while (convs) { | |
| 552 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 553 | attach_signals(conv); | |
| 554 | convs = convs->next; | |
| 555 | } | |
| 556 | ||
| 557 | return TRUE; | |
| 558 | } | |
| 559 | ||
| 560 | static gboolean | |
| 561 | plugin_unload(PurplePlugin *plugin) | |
| 562 | { | |
| 35123 | 563 | GList *convs = purple_conversations_get_all(); |
| 35122 | 564 | while (convs) { |
| 565 | PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 566 | unalert(conv); | |
| 567 | detach_signals(conv); | |
| 568 | convs = convs->next; | |
| 569 | } | |
| 35123 | 570 | |
| 35122 | 571 | unity_launcher_entry_set_count_visible(launcher, FALSE); |
| 572 | messaging_menu_app_unregister(mmapp); | |
| 573 | ||
| 574 | g_object_unref(launcher); | |
| 575 | g_object_unref(mmapp); | |
| 576 | return TRUE; | |
| 577 | } | |
| 578 | ||
| 579 | static PidginPluginUiInfo ui_info = | |
| 580 | { | |
| 581 | get_config_frame, | |
| 582 | ||
| 583 | /* padding */ | |
| 584 | NULL, | |
| 585 | NULL, | |
| 586 | NULL, | |
| 587 | NULL | |
| 588 | }; | |
| 589 | ||
| 590 | static PurplePluginInfo info = | |
| 591 | { | |
| 592 | PURPLE_PLUGIN_MAGIC, | |
| 593 | PURPLE_MAJOR_VERSION, | |
| 594 | PURPLE_MINOR_VERSION, | |
| 595 | PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 596 | PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ | |
| 597 | 0, /**< flags */ | |
| 598 | NULL, /**< dependencies */ | |
| 599 | PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
| 600 | ||
| 601 | UNITY_PLUGIN_ID, /**< id */ | |
| 602 | N_("Unity Integration"), /**< name */ | |
| 603 | DISPLAY_VERSION, /**< version */ | |
| 604 | /** summary */ | |
| 605 | N_("Provides integration with Unity."), | |
| 606 | /** description */ | |
| 607 | N_("Provides integration with Unity's messaging " | |
| 608 | "menu and launcher."), | |
| 609 | /**< author */ | |
| 610 | "Ankit Vani <a@nevitus.org>", | |
| 611 | PURPLE_WEBSITE, /**< homepage */ | |
| 612 | ||
| 613 | plugin_load, /**< load */ | |
| 614 | plugin_unload, /**< unload */ | |
| 615 | NULL, /**< destroy */ | |
| 616 | ||
| 617 | &ui_info, /**< ui_info */ | |
| 618 | NULL, /**< extra_info */ | |
| 619 | NULL, | |
| 620 | NULL, | |
| 621 | ||
| 622 | /* padding */ | |
| 623 | NULL, | |
| 624 | NULL, | |
| 625 | NULL, | |
| 626 | NULL | |
| 627 | }; | |
| 628 | ||
| 629 | static void | |
| 630 | init_plugin(PurplePlugin *plugin) | |
| 631 | { | |
| 632 | purple_prefs_add_none("/plugins/gtk"); | |
| 633 | purple_prefs_add_none("/plugins/gtk/unity"); | |
| 634 | purple_prefs_add_int("/plugins/gtk/unity/launcher_count", LAUNCHER_COUNT_SOURCES); | |
| 635 | purple_prefs_add_int("/plugins/gtk/unity/messaging_menu_text", MESSAGING_MENU_COUNT); | |
| 636 | purple_prefs_add_bool("/plugins/gtk/unity/alert_chat_nick", TRUE); | |
| 637 | } | |
| 638 | ||
| 639 | PURPLE_INIT_PLUGIN(unity, init_plugin, info) |