Mercurial > pidgin.yaz
comparison pidgin/gtkutils.c @ 32779:d72f2f13b60f
merge of 'c8c73eea7431e6f940916315ace40a41c8da3faa'
and 'fec428131bde0ae8247941bd6a3d996c984c9189'
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Fri, 21 Oct 2011 14:36:18 +0000 |
parents | 2ec94166be43 |
children | b6276b10cb10 |
comparison
equal
deleted
inserted
replaced
32778:14787acaf9d7 | 32779:d72f2f13b60f |
---|---|
65 #include "gtkimhtml.h" | 65 #include "gtkimhtml.h" |
66 #include "gtkimhtmltoolbar.h" | 66 #include "gtkimhtmltoolbar.h" |
67 #include "pidginstock.h" | 67 #include "pidginstock.h" |
68 #include "gtkthemes.h" | 68 #include "gtkthemes.h" |
69 #include "gtkutils.h" | 69 #include "gtkutils.h" |
70 #include "gtkwebview.h" | |
70 #include "pidgin/minidialog.h" | 71 #include "pidgin/minidialog.h" |
71 | 72 |
72 typedef struct { | 73 typedef struct { |
73 GtkWidget *menu; | 74 GtkWidget *menu; |
74 gint default_item; | 75 gint default_item; |
264 sw = pidgin_make_scrollable(imhtml, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_NONE, -1, -1); | 265 sw = pidgin_make_scrollable(imhtml, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_NONE, -1, -1); |
265 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | 266 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); |
266 | 267 |
267 if (imhtml_ret != NULL) | 268 if (imhtml_ret != NULL) |
268 *imhtml_ret = imhtml; | 269 *imhtml_ret = imhtml; |
270 | |
271 if (editable && (toolbar_ret != NULL)) | |
272 *toolbar_ret = toolbar; | |
273 | |
274 if (sw_ret != NULL) | |
275 *sw_ret = sw; | |
276 | |
277 return frame; | |
278 } | |
279 | |
280 GtkWidget * | |
281 pidgin_create_webview(gboolean editable, GtkWidget **webview_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret) | |
282 { | |
283 GtkWidget *frame; | |
284 GtkWidget *webview; | |
285 GtkWidget *sep; | |
286 GtkWidget *sw; | |
287 GtkWidget *toolbar = NULL; | |
288 GtkWidget *vbox; | |
289 | |
290 frame = gtk_frame_new(NULL); | |
291 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
292 | |
293 vbox = gtk_vbox_new(FALSE, 0); | |
294 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
295 gtk_widget_show(vbox); | |
296 | |
297 if (editable) { | |
298 toolbar = gtk_imhtmltoolbar_new(); | |
299 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | |
300 gtk_widget_show(toolbar); | |
301 | |
302 sep = gtk_hseparator_new(); | |
303 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0); | |
304 g_signal_connect_swapped(G_OBJECT(toolbar), "show", G_CALLBACK(gtk_widget_show), sep); | |
305 g_signal_connect_swapped(G_OBJECT(toolbar), "hide", G_CALLBACK(gtk_widget_hide), sep); | |
306 gtk_widget_show(sep); | |
307 } | |
308 | |
309 webview = gtk_webview_new(); | |
310 #if 0 | |
311 /* TODO WEBKIT: Don't have editable webview yet. */ | |
312 gtk_webview_set_editable(GTK_WEBVIEW(webview), editable); | |
313 #endif /* if 0 */ | |
314 #ifdef USE_GTKSPELL | |
315 if (editable && purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/spellcheck")) | |
316 pidgin_setup_gtkspell(GTK_TEXT_VIEW(webview)); | |
317 #endif | |
318 gtk_widget_show(webview); | |
319 | |
320 if (editable) { | |
321 gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), webview); | |
322 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default"); | |
323 } | |
324 | |
325 sw = pidgin_make_scrollable(webview, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC, GTK_SHADOW_NONE, -1, -1); | |
326 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
327 | |
328 gtk_webview_set_vadjustment(GTK_WEBVIEW(webview), | |
329 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sw))); | |
330 | |
331 if (webview_ret != NULL) | |
332 *webview_ret = webview; | |
269 | 333 |
270 if (editable && (toolbar_ret != NULL)) | 334 if (editable && (toolbar_ret != NULL)) |
271 *toolbar_ret = toolbar; | 335 *toolbar_ret = toolbar; |
272 | 336 |
273 if (sw_ret != NULL) | 337 if (sw_ret != NULL) |
920 g_object_set_data(G_OBJECT(optmenu), "filter_func", filter_func); | 984 g_object_set_data(G_OBJECT(optmenu), "filter_func", filter_func); |
921 | 985 |
922 return optmenu; | 986 return optmenu; |
923 } | 987 } |
924 | 988 |
925 gboolean | |
926 pidgin_check_if_dir(const char *path, GtkFileSelection *filesel) | |
927 { | |
928 char *dirname = NULL; | |
929 | |
930 if (g_file_test(path, G_FILE_TEST_IS_DIR)) { | |
931 /* append a / if needed */ | |
932 if (path[strlen(path) - 1] != G_DIR_SEPARATOR) { | |
933 dirname = g_strconcat(path, G_DIR_SEPARATOR_S, NULL); | |
934 } | |
935 gtk_file_selection_set_filename(filesel, (dirname != NULL) ? dirname : path); | |
936 g_free(dirname); | |
937 return TRUE; | |
938 } | |
939 | |
940 return FALSE; | |
941 } | |
942 | |
943 void | 989 void |
944 pidgin_setup_gtkspell(GtkTextView *textview) | 990 pidgin_setup_gtkspell(GtkTextView *textview) |
945 { | 991 { |
946 #ifdef USE_GTKSPELL | 992 #ifdef USE_GTKSPELL |
947 GError *error = NULL; | 993 GError *error = NULL; |
1000 | 1046 |
1001 static void | 1047 static void |
1002 show_retrieveing_info(PurpleConnection *conn, const char *name) | 1048 show_retrieveing_info(PurpleConnection *conn, const char *name) |
1003 { | 1049 { |
1004 PurpleNotifyUserInfo *info = purple_notify_user_info_new(); | 1050 PurpleNotifyUserInfo *info = purple_notify_user_info_new(); |
1005 purple_notify_user_info_add_pair(info, _("Information"), _("Retrieving...")); | 1051 purple_notify_user_info_add_pair_plaintext(info, _("Information"), _("Retrieving...")); |
1006 purple_notify_userinfo(conn, name, info, NULL, NULL); | 1052 purple_notify_userinfo(conn, name, info, NULL, NULL); |
1007 purple_notify_user_info_destroy(info); | 1053 purple_notify_user_info_destroy(info); |
1008 } | 1054 } |
1009 | 1055 |
1010 void pidgin_retrieve_user_info(PurpleConnection *conn, const char *name) | 1056 void pidgin_retrieve_user_info(PurpleConnection *conn, const char *name) |
1021 if (chat < 0) { | 1067 if (chat < 0) { |
1022 pidgin_retrieve_user_info(conn, name); | 1068 pidgin_retrieve_user_info(conn, name); |
1023 return; | 1069 return; |
1024 } | 1070 } |
1025 | 1071 |
1026 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(conn->prpl); | 1072 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(conn)); |
1027 if (prpl_info != NULL && prpl_info->get_cb_real_name) | 1073 if (prpl_info != NULL && prpl_info->get_cb_real_name) |
1028 who = prpl_info->get_cb_real_name(conn, chat, name); | 1074 who = prpl_info->get_cb_real_name(conn, chat, name); |
1029 if (prpl_info == NULL || prpl_info->get_cb_info == NULL) { | 1075 if (prpl_info == NULL || prpl_info->get_cb_info == NULL) { |
1030 pidgin_retrieve_user_info(conn, who ? who : name); | 1076 pidgin_retrieve_user_info(conn, who ? who : name); |
1031 g_free(who); | 1077 g_free(who); |
1147 else | 1193 else |
1148 { | 1194 { |
1149 gc = (PurpleConnection *)l->data; | 1195 gc = (PurpleConnection *)l->data; |
1150 account = purple_connection_get_account(gc); | 1196 account = purple_connection_get_account(gc); |
1151 | 1197 |
1152 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); | 1198 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); |
1153 } | 1199 } |
1154 | 1200 |
1155 protoname = prpl_info->list_icon(account, NULL); | 1201 protoname = prpl_info->list_icon(account, NULL); |
1156 | 1202 |
1157 if (!strcmp(protoname, protocol)) | 1203 if (!strcmp(protoname, protocol)) |
1189 else | 1235 else |
1190 { | 1236 { |
1191 gc = (PurpleConnection *)l->data; | 1237 gc = (PurpleConnection *)l->data; |
1192 account = purple_connection_get_account(gc); | 1238 account = purple_connection_get_account(gc); |
1193 | 1239 |
1194 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); | 1240 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); |
1195 } | 1241 } |
1196 | 1242 |
1197 protoname = prpl_info->list_icon(account, NULL); | 1243 protoname = prpl_info->list_icon(account, NULL); |
1198 | 1244 |
1199 if (!strcmp(protoname, "aim") || !strcmp(protoname, "icq")) | 1245 if (!strcmp(protoname, "aim") || !strcmp(protoname, "icq")) |
1306 */ | 1352 */ |
1307 gtk_widget_size_request (widget, &requisition); | 1353 gtk_widget_size_request (widget, &requisition); |
1308 | 1354 |
1309 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); | 1355 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); |
1310 | 1356 |
1311 push_in = FALSE; | 1357 *push_in = FALSE; |
1312 | 1358 |
1313 /* | 1359 /* |
1314 * The placement of popup menus horizontally works like this (with | 1360 * The placement of popup menus horizontally works like this (with |
1315 * RTL in parentheses) | 1361 * RTL in parentheses) |
1316 * | 1362 * |
1601 data->who = g_strdup(who); | 1647 data->who = g_strdup(who); |
1602 data->filename = g_strdup(filename); | 1648 data->filename = g_strdup(filename); |
1603 data->account = account; | 1649 data->account = account; |
1604 | 1650 |
1605 if (gc) | 1651 if (gc) |
1606 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); | 1652 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc)); |
1607 | 1653 |
1608 if (prpl_info && prpl_info->options & OPT_PROTO_IM_IMAGE) | 1654 if (prpl_info && prpl_info->options & OPT_PROTO_IM_IMAGE) |
1609 im = TRUE; | 1655 im = TRUE; |
1610 | 1656 |
1611 if (prpl_info && prpl_info->can_receive_file) | 1657 if (prpl_info && prpl_info->can_receive_file) |
1832 GtkWidget * | 1878 GtkWidget * |
1833 pidgin_append_menu_action(GtkWidget *menu, PurpleMenuAction *act, | 1879 pidgin_append_menu_action(GtkWidget *menu, PurpleMenuAction *act, |
1834 gpointer object) | 1880 gpointer object) |
1835 { | 1881 { |
1836 GtkWidget *menuitem; | 1882 GtkWidget *menuitem; |
1883 GList *list; | |
1837 | 1884 |
1838 if (act == NULL) { | 1885 if (act == NULL) { |
1839 return pidgin_separator(menu); | 1886 return pidgin_separator(menu); |
1840 } | 1887 } |
1841 | 1888 |
1842 if (act->children == NULL) { | 1889 list = purple_menu_action_get_children(act); |
1843 menuitem = gtk_menu_item_new_with_mnemonic(act->label); | 1890 menuitem = gtk_menu_item_new_with_mnemonic(purple_menu_action_get_label(act)); |
1844 | 1891 |
1845 if (act->callback != NULL) { | 1892 if (list == NULL) { |
1893 PurpleCallback callback; | |
1894 | |
1895 callback = purple_menu_action_get_callback(act); | |
1896 | |
1897 if (callback != NULL) { | |
1846 g_object_set_data(G_OBJECT(menuitem), | 1898 g_object_set_data(G_OBJECT(menuitem), |
1847 "purplecallback", | 1899 "purplecallback", |
1848 act->callback); | 1900 callback); |
1849 g_object_set_data(G_OBJECT(menuitem), | 1901 g_object_set_data(G_OBJECT(menuitem), |
1850 "purplecallbackdata", | 1902 "purplecallbackdata", |
1851 act->data); | 1903 purple_menu_action_get_data(act)); |
1852 g_signal_connect(G_OBJECT(menuitem), "activate", | 1904 g_signal_connect(G_OBJECT(menuitem), "activate", |
1853 G_CALLBACK(menu_action_cb), | 1905 G_CALLBACK(menu_action_cb), |
1854 object); | 1906 object); |
1855 } else { | 1907 } else { |
1856 gtk_widget_set_sensitive(menuitem, FALSE); | 1908 gtk_widget_set_sensitive(menuitem, FALSE); |
1860 } else { | 1912 } else { |
1861 GList *l = NULL; | 1913 GList *l = NULL; |
1862 GtkWidget *submenu = NULL; | 1914 GtkWidget *submenu = NULL; |
1863 GtkAccelGroup *group; | 1915 GtkAccelGroup *group; |
1864 | 1916 |
1865 menuitem = gtk_menu_item_new_with_mnemonic(act->label); | |
1866 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); | 1917 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); |
1867 | 1918 |
1868 submenu = gtk_menu_new(); | 1919 submenu = gtk_menu_new(); |
1869 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | 1920 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); |
1870 | 1921 |
1871 group = gtk_menu_get_accel_group(GTK_MENU(menu)); | 1922 group = gtk_menu_get_accel_group(GTK_MENU(menu)); |
1872 if (group) { | 1923 if (group) { |
1873 char *path = g_strdup_printf("%s/%s", GTK_MENU_ITEM(menuitem)->accel_path, act->label); | 1924 char *path = g_strdup_printf("%s/%s", GTK_MENU_ITEM(menuitem)->accel_path, |
1925 purple_menu_action_get_label(act)); | |
1874 gtk_menu_set_accel_path(GTK_MENU(submenu), path); | 1926 gtk_menu_set_accel_path(GTK_MENU(submenu), path); |
1875 g_free(path); | 1927 g_free(path); |
1876 gtk_menu_set_accel_group(GTK_MENU(submenu), group); | 1928 gtk_menu_set_accel_group(GTK_MENU(submenu), group); |
1877 } | 1929 } |
1878 | 1930 |
1879 for (l = act->children; l; l = l->next) { | 1931 for (l = list; l; l = l->next) { |
1880 PurpleMenuAction *act = (PurpleMenuAction *)l->data; | 1932 PurpleMenuAction *act = (PurpleMenuAction *)l->data; |
1881 | 1933 |
1882 pidgin_append_menu_action(submenu, act, object); | 1934 pidgin_append_menu_action(submenu, act, object); |
1883 } | 1935 } |
1884 g_list_free(act->children); | 1936 g_list_free(list); |
1885 act->children = NULL; | 1937 purple_menu_action_set_children(act, NULL); |
1886 } | 1938 } |
1887 purple_menu_action_free(act); | 1939 purple_menu_action_free(act); |
1888 return menuitem; | 1940 return menuitem; |
1889 } | 1941 } |
1890 | 1942 |
2178 return all || purple_account_is_connected(completion_entry->entry.buddy->account); | 2230 return all || purple_account_is_connected(completion_entry->entry.buddy->account); |
2179 } else { | 2231 } else { |
2180 return all || (completion_entry->entry.logged_buddy->account != NULL && purple_account_is_connected(completion_entry->entry.logged_buddy->account)); | 2232 return all || (completion_entry->entry.logged_buddy->account != NULL && purple_account_is_connected(completion_entry->entry.logged_buddy->account)); |
2181 } | 2233 } |
2182 } | 2234 } |
2183 | |
2184 void | |
2185 pidgin_setup_screenname_autocomplete(GtkWidget *entry, GtkWidget *accountopt, gboolean all) { | |
2186 pidgin_setup_screenname_autocomplete_with_filter(entry, accountopt, pidgin_screenname_autocomplete_default_filter, GINT_TO_POINTER(all)); | |
2187 } | |
2188 | |
2189 | |
2190 | 2235 |
2191 void pidgin_set_cursor(GtkWidget *widget, GdkCursorType cursor_type) | 2236 void pidgin_set_cursor(GtkWidget *widget, GdkCursorType cursor_type) |
2192 { | 2237 { |
2193 GdkCursor *cursor; | 2238 GdkCursor *cursor; |
2194 | 2239 |
2529 path, plugin->info->name); | 2574 path, plugin->info->name); |
2530 purple_notify_error(NULL, _("Icon Error"), _("Could not set icon"), tmp); | 2575 purple_notify_error(NULL, _("Icon Error"), _("Could not set icon"), tmp); |
2531 g_free(tmp); | 2576 g_free(tmp); |
2532 | 2577 |
2533 return NULL; | 2578 return NULL; |
2534 } | |
2535 | |
2536 void pidgin_set_custom_buddy_icon(PurpleAccount *account, const char *who, const char *filename) | |
2537 { | |
2538 PurpleBuddy *buddy; | |
2539 PurpleContact *contact; | |
2540 | |
2541 buddy = purple_find_buddy(account, who); | |
2542 if (!buddy) { | |
2543 purple_debug_info("custom-icon", "You can only set custom icon for someone in your buddylist.\n"); | |
2544 return; | |
2545 } | |
2546 | |
2547 contact = purple_buddy_get_contact(buddy); | |
2548 purple_buddy_icons_node_set_custom_icon_from_file((PurpleBlistNode*)contact, filename); | |
2549 } | 2579 } |
2550 | 2580 |
2551 char *pidgin_make_pretty_arrows(const char *str) | 2581 char *pidgin_make_pretty_arrows(const char *str) |
2552 { | 2582 { |
2553 char *ret; | 2583 char *ret; |
3284 int code; | 3314 int code; |
3285 if (purple_str_has_prefix(uri, "file://")) | 3315 if (purple_str_has_prefix(uri, "file://")) |
3286 { | 3316 { |
3287 gchar *escaped = g_shell_quote(uri); | 3317 gchar *escaped = g_shell_quote(uri); |
3288 gchar *param = g_strconcat("/select,\"", uri, "\"", NULL); | 3318 gchar *param = g_strconcat("/select,\"", uri, "\"", NULL); |
3289 gchar *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); | 3319 wchar_t *wc_param = g_utf8_to_utf16(param, -1, NULL, NULL, NULL); |
3290 | 3320 |
3291 code = (int)ShellExecuteW(NULL, "OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); | 3321 code = (int)ShellExecuteW(NULL, L"OPEN", L"explorer.exe", wc_param, NULL, SW_NORMAL); |
3292 | 3322 |
3293 g_free(wc_param); | 3323 g_free(wc_param); |
3294 g_free(param); | 3324 g_free(param); |
3295 g_free(escaped); | 3325 g_free(escaped); |
3296 } else { | 3326 } else { |
3448 PidginConversation *conv = g_object_get_data(G_OBJECT(item), "gtkconv"); | 3478 PidginConversation *conv = g_object_get_data(G_OBJECT(item), "gtkconv"); |
3449 if (!conv) | 3479 if (!conv) |
3450 return TRUE; | 3480 return TRUE; |
3451 purple_request_file(conv->active_conv, _("Save File"), NULL, TRUE, | 3481 purple_request_file(conv->active_conv, _("Save File"), NULL, TRUE, |
3452 G_CALLBACK(savefile_write_cb), NULL, | 3482 G_CALLBACK(savefile_write_cb), NULL, |
3453 conv->active_conv->account, NULL, conv->active_conv, | 3483 purple_conversation_get_account(conv->active_conv), NULL, conv->active_conv, |
3454 (void *)url); | 3484 (void *)url); |
3455 return TRUE; | 3485 return TRUE; |
3456 } | 3486 } |
3457 | 3487 |
3458 static gboolean | 3488 static gboolean |