comparison src/prpl.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 777f56b95a92
children 0241d6b6702d
comparison
equal deleted inserted replaced
5204:44de70702205 5205:fefad67de2c7
34 #endif 34 #endif
35 35
36 GSList *protocols = NULL; 36 GSList *protocols = NULL;
37 37
38 GtkWidget *protomenu = NULL; 38 GtkWidget *protomenu = NULL;
39 int prpl_accounts[PROTO_UNTAKEN];
40 39
41 struct _prompt { 40 struct _prompt {
42 GtkWidget *window; 41 GtkWidget *window;
43 GtkWidget *entry; 42 GtkWidget *entry;
44 void (*doit)(void *, const char *); 43 void (*doit)(void *, const char *);
45 void (*dont)(void *); 44 void (*dont)(void *);
46 void *data; 45 void *data;
47 }; 46 };
48 47
49 struct prpl *find_prpl(GaimProtocol type) 48 GaimPlugin *
50 { 49 gaim_find_prpl(GaimProtocol type)
51 GSList *e = protocols; 50 {
52 struct prpl *r; 51 GSList *l;
53 52 GaimPlugin *plugin;
54 while (e) { 53
55 r = (struct prpl *)e->data; 54 for (l = protocols; l != NULL; l = l->next) {
56 if (r->protocol == type) 55 plugin = (GaimPlugin *)l->data;
57 return r; 56
58 e = e->next; 57 /* Just In Case (TM) */
58 if (GAIM_IS_PROTOCOL_PLUGIN(plugin)) {
59
60 if (GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol == type)
61 return plugin;
62 }
59 } 63 }
60 64
61 return NULL; 65 return NULL;
62 } 66 }
63
64 gint proto_compare(struct prpl *a, struct prpl *b)
65 {
66 /* neg if a before b, 0 if equal, pos if a after b */
67 return a->protocol - b->protocol;
68 }
69
70 #ifdef GAIM_PLUGINS
71 gboolean load_prpl(struct prpl *p)
72 {
73 char *(*gaim_prpl_init)(struct prpl *);
74 debug_printf("Loading protocol %d\n", p->protocol);
75
76 if (!p->plug)
77 return TRUE;
78
79 p->plug->handle = g_module_open(p->plug->path, 0);
80 if (!p->plug->handle) {
81 debug_printf("%s is unloadable: %s\n", p->plug->path, g_module_error());
82 return TRUE;
83 }
84
85 if (!g_module_symbol(p->plug->handle, "gaim_prpl_init", (gpointer *)&gaim_prpl_init)) {
86 return TRUE;
87 }
88
89 gaim_prpl_init(p);
90 return FALSE;
91 }
92 #endif
93
94 /* This is used only by static protocols */
95 void load_protocol(proto_init pi)
96 {
97 struct prpl *p = g_new0(struct prpl, 1);
98
99 if (p->protocol == PROTO_ICQ)
100 do_error_dialog(_("ICQ Protocol detected."),
101 _("Gaim has loaded the ICQ plugin. This plugin has been deprecated. "
102 "As such, it was probably not compiled from the same version of the "
103 "source as this application was, and cannot be guaranteed to work. "
104 "It is recommended that you use the AIM/ICQ protocol to connect to ICQ"),
105 GAIM_WARNING);
106 pi(p);
107 protocols = g_slist_insert_sorted(protocols, p, (GCompareFunc)proto_compare);
108 regenerate_user_list();
109 }
110
111 void unload_protocol(struct prpl *p)
112 {
113 GList *c;
114 struct proto_user_split *pus;
115 struct proto_user_opt *puo;
116 if (p->name)
117 g_free(p->name);
118
119 c = p->user_splits;
120 while (c) {
121 pus = c->data;
122 g_free(pus->label);
123 g_free(pus->def);
124 g_free(pus);
125 c = c->next;
126 }
127 g_list_free(p->user_splits);
128 p->user_splits = NULL;
129
130 c = p->user_opts;
131 while (c) {
132 puo = c->data;
133 g_free(puo->label);
134 g_free(puo->def);
135 g_free(puo);
136 c = c->next;
137 }
138 g_list_free(p->user_opts);
139 p->user_opts = NULL;
140 }
141
142 STATIC_PROTO_INIT
143 67
144 static void des_win(GtkWidget *a, GtkWidget *b) 68 static void des_win(GtkWidget *a, GtkWidget *b)
145 { 69 {
146 gtk_widget_destroy(b); 70 gtk_widget_destroy(b);
147 } 71 }
154 void (*yesfunc)(gpointer); 78 void (*yesfunc)(gpointer);
155 void (*nofunc)(gpointer); 79 void (*nofunc)(gpointer);
156 gpointer data; 80 gpointer data;
157 }; 81 };
158 82
159 void do_ask_cancel_by_handle(GModule *handle) 83 void do_ask_cancel_by_handle(void *handle)
160 { 84 {
161 GSList *d = do_ask_dialogs; 85 GSList *d = do_ask_dialogs;
162 86
163 debug_printf("%d dialogs to search\n", g_slist_length(d)); 87 debug_printf("%d dialogs to search\n", g_slist_length(d));
164 88
333 257
334 void do_proto_menu() 258 void do_proto_menu()
335 { 259 {
336 GtkWidget *menuitem; 260 GtkWidget *menuitem;
337 GtkWidget *submenu; 261 GtkWidget *submenu;
262 GaimPluginProtocolInfo *prpl_info = NULL;
338 GList *l; 263 GList *l;
339 GSList *c = connections; 264 GSList *c = connections;
340 struct proto_actions_menu *pam; 265 struct proto_actions_menu *pam;
341 struct gaim_connection *gc = NULL; 266 struct gaim_connection *gc = NULL;
342 int count = 0; 267 int count = 0;
355 l = l->next; 280 l = l->next;
356 } 281 }
357 282
358 while (c) { 283 while (c) {
359 gc = c->data; 284 gc = c->data;
360 if (gc->prpl->actions && gc->login_time) 285
286 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
287
288 if (prpl_info->actions && gc->login_time)
361 count++; 289 count++;
290
362 c = g_slist_next(c); 291 c = g_slist_next(c);
363 } 292 }
364 c = connections; 293 c = connections;
365 294
366 if (!count) { 295 if (!count) {
373 302
374 if (count == 1) { 303 if (count == 1) {
375 GList *act; 304 GList *act;
376 while (c) { 305 while (c) {
377 gc = c->data; 306 gc = c->data;
378 if (gc->prpl->actions && gc->login_time) 307
308 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
309
310 if (prpl_info->actions && gc->login_time)
379 break; 311 break;
312
380 c = g_slist_next(c); 313 c = g_slist_next(c);
381 } 314 }
382 315
383 act = gc->prpl->actions(gc); 316 act = prpl_info->actions(gc);
384 317
385 while (act) { 318 while (act) {
386 if (act->data) { 319 if (act->data) {
387 struct proto_actions_menu *pam = act->data; 320 struct proto_actions_menu *pam = act->data;
388 menuitem = gtk_menu_item_new_with_label(pam->label); 321 menuitem = gtk_menu_item_new_with_label(pam->label);
401 GList *act; 334 GList *act;
402 GdkPixbuf *pixbuf, *scale; 335 GdkPixbuf *pixbuf, *scale;
403 GtkWidget *image; 336 GtkWidget *image;
404 337
405 gc = c->data; 338 gc = c->data;
406 if (!gc->prpl->actions || !gc->login_time) { 339
340 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
341
342 if (!prpl_info->actions || !gc->login_time) {
407 c = g_slist_next(c); 343 c = g_slist_next(c);
408 continue; 344 continue;
409 } 345 }
410 346
411 g_snprintf(buf, sizeof(buf), "%s (%s)", gc->username, gc->prpl->name); 347 g_snprintf(buf, sizeof(buf), "%s (%s)",
348 gc->username, gc->prpl->info->name);
412 menuitem = gtk_image_menu_item_new_with_label(buf); 349 menuitem = gtk_image_menu_item_new_with_label(buf);
413 350
414 pixbuf = create_prpl_icon(gc->account); 351 pixbuf = create_prpl_icon(gc->account);
415 if(pixbuf) { 352 if(pixbuf) {
416 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16, 353 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
427 364
428 submenu = gtk_menu_new(); 365 submenu = gtk_menu_new();
429 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); 366 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
430 gtk_widget_show(submenu); 367 gtk_widget_show(submenu);
431 368
432 act = gc->prpl->actions(gc); 369 act = prpl_info->actions(gc);
433 370
434 while (act) { 371 while (act) {
435 if (act->data) { 372 if (act->data) {
436 struct proto_actions_menu *pam = act->data; 373 struct proto_actions_menu *pam = act->data;
437 menuitem = gtk_menu_item_new_with_label(pam->label); 374 menuitem = gtk_menu_item_new_with_label(pam->label);
780 while (GTK_BOX(reg_area)->children) 717 while (GTK_BOX(reg_area)->children)
781 gtk_container_remove(GTK_CONTAINER(reg_area), 718 gtk_container_remove(GTK_CONTAINER(reg_area),
782 ((GtkBoxChild *)GTK_BOX(reg_area)->children->data)->widget); 719 ((GtkBoxChild *)GTK_BOX(reg_area)->children->data)->widget);
783 720
784 while (P) { 721 while (P) {
785 struct prpl *p = P->data; 722 GaimPlugin *p = P->data;
786 if (p->register_user) 723
724 if (GAIM_PLUGIN_PROTOCOL_INFO(p)->register_user)
787 break; 725 break;
726
788 P = P->next; 727 P = P->next;
789 } 728 }
790 729
791 if (!P) { 730 if (!P) {
792 GtkWidget *no = gtk_label_new(_("You do not currently have any protocols available" 731 GtkWidget *no = gtk_label_new(_("You do not currently have any protocols available"
800 } 739 }
801 740
802 gtk_widget_set_sensitive(reg_reg, TRUE); 741 gtk_widget_set_sensitive(reg_reg, TRUE);
803 742
804 while (P) { /* we can safely ignore all the previous ones */ 743 while (P) { /* we can safely ignore all the previous ones */
805 struct prpl *p = P->data; 744 GaimPlugin *p = P->data;
806 P = P->next; 745 P = P->next;
807 746
808 if (!p->register_user) 747 if (GAIM_PLUGIN_PROTOCOL_INFO(p)->register_user)
809 continue; 748 continue;
810 749
811 /* do stuff */ 750 /* do stuff */
812 } 751 }
813 } 752 }
858 reset_reg_dlg(); 797 reset_reg_dlg();
859 798
860 gtk_widget_show_all(regdlg); 799 gtk_widget_show_all(regdlg);
861 } 800 }
862 801
863 static gboolean delayed_unload(void *handle) {
864 g_module_close(handle);
865 return FALSE;
866 }
867
868 gboolean ref_protocol(struct prpl *p) {
869 #ifdef GAIM_PLUGINS
870 if(p->plug) { /* This protocol is a plugin */
871 prpl_accounts[p->protocol]++;
872 debug_printf("Protocol %s refcount now %d\n", p->name, prpl_accounts[p->protocol]);
873 if(!p->plug->handle) { /*But the protocol isn't yet loaded */
874 unload_protocol(p);
875 if (load_prpl(p))
876 return FALSE;
877 }
878 }
879 #endif /* GAIM_PLUGINS */
880 return TRUE;
881 }
882
883 void unref_protocol(struct prpl *p) {
884 #ifdef GAIM_PLUGINS
885 if(p->plug) { /* This protocol is a plugin */
886 prpl_accounts[p->protocol]--;
887 debug_printf("Protocol %s refcount now %d\n", p->name, prpl_accounts[p->protocol]);
888 if(prpl_accounts[p->protocol] == 0) { /* No longer needed */
889 debug_printf("Throwing out %s protocol plugin\n", p->name);
890 do_ask_cancel_by_handle(p->plug->handle);
891 g_timeout_add(0, delayed_unload, p->plug->handle);
892 p->plug->handle = NULL;
893 }
894 }
895 #endif /* GAIM_PLUGINS */
896 }
897