comparison src/buddy.c @ 5205:fefad67de2c7

[gaim-migrate @ 5573] I had a damn good commit message, but it was eaten. Let's try it again. Announcing, Gaim Plugin API version 2.0, or GPAPIV2.0 for short. There are lots'a cool thingies here. Okay now, this isn't as cool as the previous message, but: 1) There's now a single entry function for all plugin types. It returns a detailed information structure on the plugin. This removes a lot of the ugliness from old plugins. Oh yeah, libicq wasn't converted to this, so if you use it, well, you shouldn't have used it anyway, but now you can't! bwahahaha. Use AIM/ICQ. 2) There are now 3 types of plugins: Standard, Loader, and Protocol plugins. Standard plugins are, well, standard, compiled plugins. Loader plugins load other plugins. For example, the perl support is now a loader plugin. It loads perl scripts. In the future, we'll have Ruby and Python loader plugins. Protocol plugins are, well, protocol plugins... yeah... 3) Plugins have unique IDs, so they can be referred to or automatically updated from a plugin database in the future. Neat, huh? 4) Plugins will have dependency support in the future, and can be hidden, so if you have, say, a logging core plugin, it won't have to show up, but then you load the GTK+ logging plugin and it'll auto-load the core plugin. Core/UI split plugins! 5) There will eventually be custom plugin signals and RPC of some sort, for the core/ui split plugins. So, okay, back up .gaimrc. I'd like to thank my parents for their support, javabsp for helping convert a bunch of protocol plugins, and Etan for helping convert a bunch of standard plugins. Have fun. If you have any problems, please let me know, but you probably won't have anything major happen. You will have to convert your plugins, though, and I'm not guaranteeing that all perl scripts will still work. I'll end up changing the perl script API eventually, so I know they won't down the road. Don't worry, though. It'll be mass cool. faceprint wants me to just commit the damn code already. So, here we go!!! .. .. I need a massage. From a young, cute girl. Are there any young, cute girls in the audience? IM me plz k thx. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 25 Apr 2003 06:47:33 +0000
parents b81e3c496598
children 0241d6b6702d
comparison
equal deleted inserted replaced
5204:44de70702205 5205:fefad67de2c7
313 GValue val = { 0, }; 313 GValue val = { 0, };
314 GtkTreeIter iter; 314 GtkTreeIter iter;
315 GtkWidget *menu, *menuitem; 315 GtkWidget *menu, *menuitem;
316 GtkTreeSelection *sel; 316 GtkTreeSelection *sel;
317 GList *list; 317 GList *list;
318 struct prpl *prpl; 318 GaimPlugin *prpl = NULL;
319 GaimPluginProtocolInfo *prpl_info = NULL;
319 320
320 if (event->button != 3) 321 if (event->button != 3)
321 return FALSE; 322 return FALSE;
322 323
323 /* Here we figure out which node was clicked */ 324 /* Here we figure out which node was clicked */
332 gaim_new_item_from_stock(menu, _("_Add a Buddy"), GTK_STOCK_ADD, G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL); 333 gaim_new_item_from_stock(menu, _("_Add a Buddy"), GTK_STOCK_ADD, G_CALLBACK(gaim_gtk_blist_add_buddy_cb), node, 0, 0, NULL);
333 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); 334 gaim_new_item_from_stock(menu, _("_Delete Group"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
334 gaim_new_item_from_stock(menu, _("_Rename"), NULL, G_CALLBACK(show_rename_group), node, 0, 0, NULL); 335 gaim_new_item_from_stock(menu, _("_Rename"), NULL, G_CALLBACK(show_rename_group), node, 0, 0, NULL);
335 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) { 336 } else if (GAIM_BLIST_NODE_IS_BUDDY(node)) {
336 /* Protocol specific options */ 337 /* Protocol specific options */
337 prpl = find_prpl(((struct buddy*)node)->account->protocol); 338 prpl = gaim_find_prpl(((struct buddy*)node)->account->protocol);
338 339
339 if (prpl && prpl->get_info) 340 if (prpl != NULL)
341 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
342
343 if (prpl && prpl_info->get_info)
340 gaim_new_item_from_stock(menu, _("_Get Info"), GAIM_STOCK_INFO, G_CALLBACK(gtk_blist_menu_info_cb), node, 0, 0, NULL); 344 gaim_new_item_from_stock(menu, _("_Get Info"), GAIM_STOCK_INFO, G_CALLBACK(gtk_blist_menu_info_cb), node, 0, 0, NULL);
341 345
342 gaim_new_item_from_stock(menu, _("_IM"), GAIM_STOCK_IM, G_CALLBACK(gtk_blist_menu_im_cb), node, 0, 0, NULL); 346 gaim_new_item_from_stock(menu, _("_IM"), GAIM_STOCK_IM, G_CALLBACK(gtk_blist_menu_im_cb), node, 0, 0, NULL);
343 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, G_CALLBACK(gtk_blist_menu_bp_cb), node, 0, 0, NULL); 347 gaim_new_item_from_stock(menu, _("Add Buddy _Pounce"), NULL, G_CALLBACK(gtk_blist_menu_bp_cb), node, 0, 0, NULL);
344 gaim_new_item_from_stock(menu, _("View _Log"), NULL, G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL); 348 gaim_new_item_from_stock(menu, _("View _Log"), NULL, G_CALLBACK(gtk_blist_menu_showlog_cb), node, 0, 0, NULL);
345 349
346 if (prpl) { 350 if (prpl) {
347 list = prpl->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name); 351 list = prpl_info->buddy_menu(((struct buddy*)node)->account->gc, ((struct buddy*)node)->name);
348 while (list) { 352 while (list) {
349 struct proto_buddy_menu *pbm = list->data; 353 struct proto_buddy_menu *pbm = list->data;
350 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label); 354 menuitem = gtk_menu_item_new_with_mnemonic(pbm->label);
351 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm); 355 g_object_set_data(G_OBJECT(menuitem), "gaimcallback", pbm);
352 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node); 356 g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(gaim_proto_menu_cb), node);
353 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); 357 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
354 list = list->next; 358 list = list->next;
355 } 359 }
356 } 360 }
357 361
358 plugin_event (event_draw_menu, menu, ((struct buddy *) node)->name); 362 gaim_event_broadcast (event_draw_menu, menu, ((struct buddy *) node)->name);
359 363
360 gaim_separator(menu); 364 gaim_separator(menu);
361 gaim_new_item_from_stock(menu, _("_Alias"), GAIM_STOCK_EDIT, G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL); 365 gaim_new_item_from_stock(menu, _("_Alias"), GAIM_STOCK_EDIT, G_CALLBACK(gtk_blist_menu_alias_cb), node, 0, 0, NULL);
362 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL); 366 gaim_new_item_from_stock(menu, _("_Remove"), GTK_STOCK_REMOVE, G_CALLBACK(gaim_gtk_blist_remove_cb), node, 0, 0, NULL);
363 } 367 }
674 * Private Utility functions * 678 * Private Utility functions *
675 *********************************************************/ 679 *********************************************************/
676 680
677 static char *gaim_get_tooltip_text(struct buddy *b) 681 static char *gaim_get_tooltip_text(struct buddy *b)
678 { 682 {
683 GaimPlugin *prpl;
684 GaimPluginProtocolInfo *prpl_info = NULL;
679 char *text = NULL; 685 char *text = NULL;
680 struct prpl* prpl = find_prpl(b->account->protocol);
681 char *statustext = NULL; 686 char *statustext = NULL;
682 char *aliastext = NULL, *nicktext = NULL; 687 char *aliastext = NULL, *nicktext = NULL;
683 char *warning = NULL, *idletime = NULL; 688 char *warning = NULL, *idletime = NULL;
684 689
685 if (prpl->tooltip_text) { 690 prpl = gaim_find_prpl(b->account->protocol);
691 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
692
693 if (prpl_info->tooltip_text) {
686 const char *end; 694 const char *end;
687 statustext = prpl->tooltip_text(b); 695 statustext = prpl_info->tooltip_text(b);
688 696
689 if(statustext && !g_utf8_validate(statustext, -1, &end)) { 697 if(statustext && !g_utf8_validate(statustext, -1, &end)) {
690 char *new = g_strndup(statustext, 698 char *new = g_strndup(statustext,
691 g_utf8_pointer_to_offset(statustext, end)); 699 g_utf8_pointer_to_offset(statustext, end));
692 g_free(statustext); 700 g_free(statustext);
758 766
759 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL; 767 char *se = NULL, *sw = NULL ,*nw = NULL ,*ne = NULL;
760 768
761 int scalesize = 30; 769 int scalesize = 30;
762 770
763 struct prpl* prpl = find_prpl(b->account->protocol); 771 GaimPlugin *prpl;
772 GaimPluginProtocolInfo *prpl_info = NULL;
773
774 prpl = gaim_find_prpl(b->account->protocol);
764 775
765 if (!prpl) 776 if (!prpl)
766 return NULL; 777 return NULL;
767 778
768 if (prpl->list_icon) 779 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
769 protoname = prpl->list_icon(b->account, b); 780
770 if (b->present != GAIM_BUDDY_SIGNING_OFF && prpl->list_emblems) 781 if (prpl_info->list_icon)
771 prpl->list_emblems(b, &se, &sw, &nw, &ne); 782 protoname = prpl_info->list_icon(b->account, b);
783 if (b->present != GAIM_BUDDY_SIGNING_OFF && prpl_info->list_emblems)
784 prpl_info->list_emblems(b, &se, &sw, &nw, &ne);
772 785
773 if (size == GAIM_STATUS_ICON_SMALL) { 786 if (size == GAIM_STATUS_ICON_SMALL) {
774 scalesize = 15; 787 scalesize = 15;
775 sw = nw = ne = NULL; /* So that only the se icon will composite */ 788 sw = nw = ne = NULL; /* So that only the se icon will composite */
776 } 789 }
927 940
928 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected) 941 static gchar *gaim_gtk_blist_get_name_markup(struct buddy *b, gboolean selected)
929 { 942 {
930 char *name = gaim_get_buddy_alias(b); 943 char *name = gaim_get_buddy_alias(b);
931 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL; 944 char *esc = g_markup_escape_text(name, strlen(name)), *text = NULL;
932 struct prpl* prpl = find_prpl(b->account->protocol); 945 GaimPlugin *prpl;
933 946 GaimPluginProtocolInfo *prpl_info = NULL;
934 /* XXX Clean up this crap */ 947 /* XXX Clean up this crap */
935 948
936 int ihrs, imin; 949 int ihrs, imin;
937 char *idletime = NULL, *warning = NULL, *statustext = NULL; 950 char *idletime = NULL, *warning = NULL, *statustext = NULL;
938 time_t t; 951 time_t t;
952
953 prpl = gaim_find_prpl(b->account->protocol);
954
955 if (prpl != NULL)
956 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
939 957
940 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) { 958 if (!(blist_options & OPT_BLIST_SHOW_ICONS)) {
941 if ((b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || !GAIM_BUDDY_IS_ONLINE(b)) { 959 if ((b->idle && blist_options & OPT_BLIST_GREY_IDLERS && !selected) || !GAIM_BUDDY_IS_ONLINE(b)) {
942 text = g_strdup_printf("<span color='dim grey'>%s</span>", 960 text = g_strdup_printf("<span color='dim grey'>%s</span>",
943 esc); 961 esc);
950 968
951 time(&t); 969 time(&t);
952 ihrs = (t - b->idle) / 3600; 970 ihrs = (t - b->idle) / 3600;
953 imin = ((t - b->idle) / 60) % 60; 971 imin = ((t - b->idle) / 60) % 60;
954 972
955 if (prpl && prpl->status_text) { 973 if (prpl && prpl_info->status_text) {
956 char *tmp = prpl->status_text(b); 974 char *tmp = prpl_info->status_text(b);
957 const char *end; 975 const char *end;
958 976
959 if(tmp && !g_utf8_validate(tmp, -1, &end)) { 977 if(tmp && !g_utf8_validate(tmp, -1, &end)) {
960 char *new = g_strndup(tmp, 978 char *new = g_strndup(tmp,
961 g_utf8_pointer_to_offset(tmp, end)); 979 g_utf8_pointer_to_offset(tmp, end));
1753 *********************************************************************/ 1771 *********************************************************************/
1754 1772
1755 GdkPixbuf * 1773 GdkPixbuf *
1756 create_prpl_icon(struct gaim_account *account) 1774 create_prpl_icon(struct gaim_account *account)
1757 { 1775 {
1758 struct prpl *prpl = find_prpl(account->protocol); 1776 GaimPlugin *prpl;
1777 GaimPluginProtocolInfo *prpl_info = NULL;
1759 GdkPixbuf *status = NULL; 1778 GdkPixbuf *status = NULL;
1760 char *filename = NULL; 1779 char *filename = NULL;
1761 const char *protoname = NULL; 1780 const char *protoname = NULL;
1762 1781 char buf[256];
1763 /* this is so we can get the icon when the prpl isn't loaded. 1782
1764 * it's not as bad as it looks, since most of the time this function 1783 prpl = gaim_find_prpl(account->protocol);
1765 * is called, the prpl is already loaded, so it'll just increment and 1784
1766 * decrement the refcount, won't have to go through the hassle of 1785 if (prpl != NULL) {
1767 * actually loading and unloading the prpl. the few times it actually 1786 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
1768 * does that, it saves us from crashing */ 1787
1769 if(prpl && prpl->list_icon) { 1788 if (prpl_info->list_icon != NULL)
1770 ref_protocol(prpl); 1789 protoname = prpl_info->list_icon(account, NULL);
1771 protoname = prpl->list_icon(account, NULL); 1790 }
1772 unref_protocol(prpl); 1791
1773 } 1792 if (protoname == NULL)
1774
1775 if (!protoname)
1776 return NULL; 1793 return NULL;
1777 1794
1778 /* "Hey, what's all this crap?" you ask. Status icons will be themeable too, and 1795 /*
1779 then it will look up protoname from the theme */ 1796 * Status icons will be themeable too, and then it will look up
1780 if (!strcmp(protoname, "aim")) { 1797 * protoname from the theme
1781 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "aim.png", NULL); 1798 */
1782 status = gdk_pixbuf_new_from_file(filename,NULL); 1799 g_snprintf(buf, sizeof(buf), "%s.png", protoname);
1783 g_free(filename); 1800
1784 } else if (!strcmp(protoname, "yahoo")) { 1801 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
1785 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "yahoo.png", NULL); 1802 "default", buf, NULL);
1786 status = gdk_pixbuf_new_from_file(filename,NULL); 1803 status = gdk_pixbuf_new_from_file(filename, NULL);
1787 g_free(filename); 1804 g_free(filename);
1788 } else if (!strcmp(protoname, "msn")) { 1805
1789 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "msn.png", NULL);
1790 status = gdk_pixbuf_new_from_file(filename,NULL);
1791 g_free(filename);
1792 } else if (!strcmp(protoname, "jabber")) {
1793 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "jabber.png", NULL);
1794 status = gdk_pixbuf_new_from_file(filename,NULL);
1795 g_free(filename);
1796 } else if (!strcmp(protoname, "icq")) {
1797 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "icq.png", NULL);
1798 status = gdk_pixbuf_new_from_file(filename,NULL);
1799 g_free(filename);
1800 } else if (!strcmp(protoname, "gadu-gadu")) {
1801 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "gadu-gadu.png", NULL);
1802 status = gdk_pixbuf_new_from_file(filename,NULL);
1803 g_free(filename);
1804 } else if (!strcmp(protoname, "napster")) {
1805 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "napster.png", NULL);
1806 status = gdk_pixbuf_new_from_file(filename,NULL);
1807 g_free(filename);
1808 } else if (!strcmp(protoname, "irc")) {
1809 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status", "default", "irc.png", NULL);
1810 status = gdk_pixbuf_new_from_file(filename,NULL);
1811 g_free(filename);
1812 }
1813 return status; 1806 return status;
1814 } 1807 }
1815 1808