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