comparison src/plugins.c @ 3472:d33ec392a5e1

[gaim-migrate @ 3523] Rob McQueen went and removed all the GTK version preprocessor statements. Thanks! committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 29 Aug 2002 21:40:08 +0000
parents 7a3f16a375a5
children cfbdfe334975
comparison
equal deleted inserted replaced
3471:7fb93ecd631c 3472:d33ec392a5e1
88 static void load_file(GtkWidget *, gpointer); 88 static void load_file(GtkWidget *, gpointer);
89 static void load_which_plugin(GtkWidget *, gpointer); 89 static void load_which_plugin(GtkWidget *, gpointer);
90 void update_show_plugins(); 90 void update_show_plugins();
91 static void hide_plugins(GtkWidget *, gpointer); 91 static void hide_plugins(GtkWidget *, gpointer);
92 static void clear_plugin_display(); 92 static void clear_plugin_display();
93 #if GTK_CHECK_VERSION(1,3,0)
94 static struct gaim_plugin *get_selected_plugin(GtkWidget *); 93 static struct gaim_plugin *get_selected_plugin(GtkWidget *);
95 static void select_plugin(GtkWidget *w, struct gaim_plugin *p); 94 static void select_plugin(GtkWidget *w, struct gaim_plugin *p);
96 static void list_clicked(GtkWidget *, gpointer); 95 static void list_clicked(GtkWidget *, gpointer);
97 #else
98 static void list_clicked(GtkWidget *, struct gaim_plugin *);
99 #endif
100 96
101 /* ------------------ Code Below ---------------------------- */ 97 /* ------------------ Code Below ---------------------------- */
102 98
103 static void destroy_plugins(GtkWidget *w, gpointer data) 99 static void destroy_plugins(GtkWidget *w, gpointer data)
104 { 100 {
163 159
164 update_show_plugins(); 160 update_show_plugins();
165 /* Select newly loaded plugin */ 161 /* Select newly loaded plugin */
166 if(p == NULL) 162 if(p == NULL)
167 return; 163 return;
168 #if GTK_CHECK_VERSION(1,3,0)
169 select_plugin(pluglist, p); 164 select_plugin(pluglist, p);
170 #else
171 gtk_list_select_item(GTK_LIST(pluglist), g_list_index(plugins, p));
172 #endif
173 } 165 }
174 166
175 void show_plugins(GtkWidget *w, gpointer data) 167 void show_plugins(GtkWidget *w, gpointer data)
176 { 168 {
177 /* most of this code was shamelessly stolen from Glade */ 169 /* most of this code was shamelessly stolen from Glade */
183 GtkWidget *frame; 175 GtkWidget *frame;
184 GtkWidget *scrolledwindow; 176 GtkWidget *scrolledwindow;
185 GtkWidget *label; 177 GtkWidget *label;
186 GtkWidget *add; 178 GtkWidget *add;
187 GtkWidget *close; 179 GtkWidget *close;
188 #if GTK_CHECK_VERSION(1,3,0)
189 /* stuff needed for GtkTreeView *pluglist */ 180 /* stuff needed for GtkTreeView *pluglist */
190 GtkListStore *store; 181 GtkListStore *store;
191 GtkCellRenderer *renderer; 182 GtkCellRenderer *renderer;
192 GtkTreeViewColumn *column; 183 GtkTreeViewColumn *column;
193 GtkTreeSelection *selection; 184 GtkTreeSelection *selection;
194 /* needed for GtkTextView *plugtext */ 185 /* needed for GtkTextView *plugtext */
195 GtkTextBuffer *buffer; 186 GtkTextBuffer *buffer;
196 #endif 187
197 188 if (plugwindow) {
198 if (plugwindow) 189 gtk_window_present(GTK_WINDOW(plugwindow));
199 return; 190 return;
191 }
200 192
201 GAIM_DIALOG(plugwindow); 193 GAIM_DIALOG(plugwindow);
202 gtk_window_set_wmclass(GTK_WINDOW(plugwindow), "plugins", "Gaim"); 194 gtk_window_set_wmclass(GTK_WINDOW(plugwindow), "plugins", "Gaim");
203 gtk_widget_realize(plugwindow); 195 gtk_widget_realize(plugwindow);
204 aol_icon(plugwindow->window); 196 aol_icon(plugwindow->window);
205 gtk_window_set_title(GTK_WINDOW(plugwindow), _("Gaim - Plugins")); 197 gtk_window_set_title(GTK_WINDOW(plugwindow), _("Gaim - Plugins"));
206 #if !GTK_CHECK_VERSION(1,3,0)
207 gtk_widget_set_usize(plugwindow, 515, 300);
208 #endif
209 gtk_signal_connect(GTK_OBJECT(plugwindow), "destroy", GTK_SIGNAL_FUNC(hide_plugins), NULL); 198 gtk_signal_connect(GTK_OBJECT(plugwindow), "destroy", GTK_SIGNAL_FUNC(hide_plugins), NULL);
210 199
211 mainvbox = gtk_vbox_new(FALSE, 0); 200 mainvbox = gtk_vbox_new(FALSE, 0);
212 gtk_container_add(GTK_CONTAINER(plugwindow), mainvbox); 201 gtk_container_add(GTK_CONTAINER(plugwindow), mainvbox);
213 gtk_widget_show(mainvbox); 202 gtk_widget_show(mainvbox);
218 gtk_widget_show(tophbox); 207 gtk_widget_show(tophbox);
219 208
220 /* Left side: frame with list of plugin file names */ 209 /* Left side: frame with list of plugin file names */
221 frame = gtk_frame_new(_("Loaded Plugins")); 210 frame = gtk_frame_new(_("Loaded Plugins"));
222 gtk_box_pack_start(GTK_BOX(tophbox), frame, FALSE, FALSE, 0); 211 gtk_box_pack_start(GTK_BOX(tophbox), frame, FALSE, FALSE, 0);
223 #if !GTK_CHECK_VERSION(1,3,0)
224 gtk_widget_set_usize(frame, 140, -1);
225 #endif
226 gtk_container_set_border_width(GTK_CONTAINER(frame), 6); 212 gtk_container_set_border_width(GTK_CONTAINER(frame), 6);
227 gtk_frame_set_label_align(GTK_FRAME(frame), 0.05, 0.5); 213 gtk_frame_set_label_align(GTK_FRAME(frame), 0.05, 0.5);
228 gtk_widget_show(frame); 214 gtk_widget_show(frame);
229 215
230 scrolledwindow = gtk_scrolled_window_new(NULL, NULL); 216 scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
231 gtk_container_add(GTK_CONTAINER(frame), scrolledwindow); 217 gtk_container_add(GTK_CONTAINER(frame), scrolledwindow);
232 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), 218 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
233 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 219 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
234 gtk_widget_show(scrolledwindow); 220 gtk_widget_show(scrolledwindow);
235 #if GTK_CHECK_VERSION(1,3,0)
236 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), 221 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
237 GTK_SHADOW_IN); 222 GTK_SHADOW_IN);
238 223
239 /* Create & show plugin list */ 224 /* Create & show plugin list */
240 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); 225 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
250 235
251 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pluglist)); 236 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pluglist));
252 g_signal_connect(G_OBJECT(selection), "changed", 237 g_signal_connect(G_OBJECT(selection), "changed",
253 G_CALLBACK(list_clicked), 238 G_CALLBACK(list_clicked),
254 NULL); 239 NULL);
255 #else
256 pluglist = gtk_list_new();
257 gtk_list_set_selection_mode(GTK_LIST(pluglist), GTK_SELECTION_BROWSE);
258 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow),
259 pluglist);
260 #endif /* GTK_CHECK_VERSION */
261 240
262 gtk_widget_show(pluglist); 241 gtk_widget_show(pluglist);
263 242
264 /* Right side: frame with description and the filepath of plugin */ 243 /* Right side: frame with description and the filepath of plugin */
265 frame = gtk_frame_new(_("Selected Plugin")); 244 frame = gtk_frame_new(_("Selected Plugin"));
275 scrolledwindow = gtk_scrolled_window_new(NULL, NULL); 254 scrolledwindow = gtk_scrolled_window_new(NULL, NULL);
276 gtk_box_pack_start(GTK_BOX(vbox), scrolledwindow, TRUE, TRUE, 0); 255 gtk_box_pack_start(GTK_BOX(vbox), scrolledwindow, TRUE, TRUE, 0);
277 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow), 256 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow),
278 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); 257 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
279 gtk_widget_show(scrolledwindow); 258 gtk_widget_show(scrolledwindow);
280 #if GTK_CHECK_VERSION(1,3,0)
281 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow), 259 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow),
282 GTK_SHADOW_IN); 260 GTK_SHADOW_IN);
283 261
284 /* Create & show the plugin description widget */ 262 /* Create & show the plugin description widget */
285 plugtext = gtk_text_view_new(); 263 plugtext = gtk_text_view_new();
289 gtk_widget_set_size_request(GTK_WIDGET(plugtext), -1, 200); 267 gtk_widget_set_size_request(GTK_WIDGET(plugtext), -1, 200);
290 268
291 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(plugtext)); 269 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(plugtext));
292 gtk_text_buffer_create_tag(buffer, "bold", "weight", 270 gtk_text_buffer_create_tag(buffer, "bold", "weight",
293 PANGO_WEIGHT_BOLD, NULL); 271 PANGO_WEIGHT_BOLD, NULL);
294 #else
295 plugtext = gtk_text_new(NULL, NULL);
296 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledwindow),
297 plugtext);
298 gtk_text_set_word_wrap(GTK_TEXT(plugtext), TRUE);
299 gtk_text_set_editable(GTK_TEXT(plugtext), FALSE);
300 #endif
301 gtk_widget_show(plugtext); 272 gtk_widget_show(plugtext);
302 273
303 hbox = gtk_hbox_new(FALSE, 5); 274 hbox = gtk_hbox_new(FALSE, 5);
304 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); 275 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
305 gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); 276 gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
355 326
356 void update_show_plugins() 327 void update_show_plugins()
357 { 328 {
358 GList *plugs = plugins; 329 GList *plugs = plugins;
359 struct gaim_plugin *p; 330 struct gaim_plugin *p;
360 #if GTK_CHECK_VERSION(1,3,0)
361 int pnum = 0; 331 int pnum = 0;
362 GtkListStore *store; 332 GtkListStore *store;
363 GtkTreeIter iter; 333 GtkTreeIter iter;
364 #else
365 GtkWidget *label;
366 GtkWidget *list_item;
367 GtkWidget *hbox;
368 #endif
369 334
370 if (plugwindow == NULL) 335 if (plugwindow == NULL)
371 return; 336 return;
372 337
373 #if GTK_CHECK_VERSION(1,3,0)
374 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pluglist))); 338 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pluglist)));
375 gtk_list_store_clear(store); 339 gtk_list_store_clear(store);
376 #else
377 gtk_list_clear_items(GTK_LIST(pluglist), 0, -1);
378 #endif
379 while (plugs) { 340 while (plugs) {
380 p = (struct gaim_plugin *)plugs->data; 341 p = (struct gaim_plugin *)plugs->data;
381 #if GTK_CHECK_VERSION(1,3,0)
382 gtk_list_store_append(store, &iter); 342 gtk_list_store_append(store, &iter);
383 gtk_list_store_set(store, &iter, 0, plugin_makelistname(p->handle), -1); 343 gtk_list_store_set(store, &iter, 0, plugin_makelistname(p->handle), -1);
384 gtk_list_store_set(store, &iter, 1, pnum++, -1); 344 gtk_list_store_set(store, &iter, 1, pnum++, -1);
385 #else
386 label = gtk_label_new(plugin_makelistname(p->handle));
387 hbox = gtk_hbox_new(FALSE, 0); /* for left justification */
388 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
389
390 list_item = gtk_list_item_new();
391 gtk_container_add(GTK_CONTAINER(list_item), hbox);
392 gtk_signal_connect(GTK_OBJECT(list_item), "select",
393 GTK_SIGNAL_FUNC(list_clicked), p);
394 gtk_object_set_user_data(GTK_OBJECT(list_item), p);
395
396 gtk_widget_show(hbox);
397 gtk_widget_show(label);
398 gtk_container_add(GTK_CONTAINER(pluglist), list_item);
399 gtk_widget_show(list_item);
400 #endif
401 plugs = g_list_next(plugs); 345 plugs = g_list_next(plugs);
402 } 346 }
403 347
404 clear_plugin_display(); 348 clear_plugin_display();
405 } 349 }
406 350
407 static void unload_plugin_cb(GtkWidget *w, gpointer data) 351 static void unload_plugin_cb(GtkWidget *w, gpointer data)
408 { 352 {
409 struct gaim_plugin *p; 353 struct gaim_plugin *p;
410 #if GTK_CHECK_VERSION(1,3,0)
411 p = get_selected_plugin(pluglist); 354 p = get_selected_plugin(pluglist);
412 if(p == NULL) 355 if(p == NULL)
413 return; 356 return;
414 #else
415 GList *i;
416
417 i = GTK_LIST(pluglist)->selection;
418
419 if (i == NULL)
420 return;
421
422 p = gtk_object_get_user_data(GTK_OBJECT(i->data));
423 #endif
424 unload_plugin(p); 357 unload_plugin(p);
425 update_show_plugins(); 358 update_show_plugins();
426 } 359 }
427 360
428 static void plugin_reload_cb(GtkWidget *w, gpointer data) 361 static void plugin_reload_cb(GtkWidget *w, gpointer data)
429 { 362 {
430 struct gaim_plugin *p; 363 struct gaim_plugin *p;
431 #if GTK_CHECK_VERSION(1,3,0)
432 p = get_selected_plugin(pluglist); 364 p = get_selected_plugin(pluglist);
433 if(p == NULL) 365 if(p == NULL)
434 return; 366 return;
435 p = reload_plugin(p); 367 p = reload_plugin(p);
436 #else
437 GList *i;
438
439 i = GTK_LIST(pluglist)->selection;
440 if (i == NULL)
441 return;
442
443 /* Just pass off plugin to the actual function */
444 p = reload_plugin(gtk_object_get_user_data(GTK_OBJECT(i->data)));
445 #endif
446 update_show_plugins(); 368 update_show_plugins();
447 369
448 /* Try and reselect the plugin in list */ 370 /* Try and reselect the plugin in list */
449 if (!pluglist) 371 if (!pluglist)
450 return; 372 return;
451 #if GTK_CHECK_VERSION(1,3,0)
452 select_plugin(pluglist, p); 373 select_plugin(pluglist, p);
453 #else 374 }
454 gtk_list_select_item(GTK_LIST(pluglist), g_list_index(plugins, p)); 375
455 #endif 376
456 }
457
458
459 #if GTK_CHECK_VERSION(1,3,0)
460 static void list_clicked(GtkWidget *w, gpointer data) 377 static void list_clicked(GtkWidget *w, gpointer data)
461 #else
462 static void list_clicked(GtkWidget *w, struct gaim_plugin *p)
463 #endif
464 { 378 {
465 void (*gaim_plugin_config)(); 379 void (*gaim_plugin_config)();
466 #if GTK_CHECK_VERSION(1,3,0)
467 struct gaim_plugin *p; 380 struct gaim_plugin *p;
468 GtkTextBuffer *buffer; 381 GtkTextBuffer *buffer;
469 GtkTextIter iter; 382 GtkTextIter iter;
470 #else
471 gchar *temp;
472 guint text_len;
473 #endif
474 383
475 if (confighandle != 0) { 384 if (confighandle != 0) {
476 gtk_signal_disconnect(GTK_OBJECT(config), confighandle); 385 gtk_signal_disconnect(GTK_OBJECT(config), confighandle);
477 confighandle = 0; 386 confighandle = 0;
478 } 387 }
479 388
480 #if GTK_CHECK_VERSION(1,3,0)
481 p = get_selected_plugin(pluglist); 389 p = get_selected_plugin(pluglist);
482 if(p == NULL) { /* No selected plugin */ 390 if(p == NULL) { /* No selected plugin */
483 clear_plugin_display(); 391 clear_plugin_display();
484 return; 392 return;
485 } 393 }
499 gtk_text_buffer_insert(buffer, &iter, "\n", -1); 407 gtk_text_buffer_insert(buffer, &iter, "\n", -1);
500 gtk_text_buffer_insert(buffer, &iter, 408 gtk_text_buffer_insert(buffer, &iter,
501 (p->description != NULL) ? p->description : "", -1); 409 (p->description != NULL) ? p->description : "", -1);
502 410
503 gtk_entry_set_text(GTK_ENTRY(plugentry), g_module_name(p->handle)); 411 gtk_entry_set_text(GTK_ENTRY(plugentry), g_module_name(p->handle));
504 #else
505 text_len = gtk_text_get_length(GTK_TEXT(plugtext));
506 gtk_text_set_point(GTK_TEXT(plugtext), 0);
507 gtk_text_forward_delete(GTK_TEXT(plugtext), text_len);
508
509 temp = g_strdup_printf("Name: %s\n\nDescription:\n%s",
510 (p->name != NULL) ? p->name : "",
511 (p->description != NULL) ? p->description : "");
512 gtk_text_insert(GTK_TEXT(plugtext), NULL, NULL, NULL, temp, -1);
513 g_free(temp);
514 gtk_entry_set_text(GTK_ENTRY(plugentry), g_module_name(p->handle));
515 #endif
516 /* Find out if this plug-in has a configuration function */ 412 /* Find out if this plug-in has a configuration function */
517 if (g_module_symbol(p->handle, "gaim_plugin_config", (gpointer *)&gaim_plugin_config)) { 413 if (g_module_symbol(p->handle, "gaim_plugin_config", (gpointer *)&gaim_plugin_config)) {
518 confighandle = gtk_signal_connect(GTK_OBJECT(config), "clicked", 414 confighandle = gtk_signal_connect(GTK_OBJECT(config), "clicked",
519 GTK_SIGNAL_FUNC(gaim_plugin_config), NULL); 415 GTK_SIGNAL_FUNC(gaim_plugin_config), NULL);
520 gtk_widget_set_sensitive(config, TRUE); 416 gtk_widget_set_sensitive(config, TRUE);
557 filename[strlen(filename) - 3] = '\0'; 453 filename[strlen(filename) - 3] = '\0';
558 454
559 return filename; 455 return filename;
560 } 456 }
561 457
562 #if GTK_CHECK_VERSION(1,3,0)
563 static struct gaim_plugin *get_selected_plugin(GtkWidget *w) { 458 static struct gaim_plugin *get_selected_plugin(GtkWidget *w) {
564 /* Given the pluglist widget, this will return a pointer to the plugin 459 /* Given the pluglist widget, this will return a pointer to the plugin
565 * currently selected in the list, and NULL if none is selected. */ 460 * currently selected in the list, and NULL if none is selected. */
566 gint index; 461 gint index;
567 GList *plugs = plugins; 462 GList *plugs = plugins;
598 gtk_tree_model_get_iter_from_string(model, 493 gtk_tree_model_get_iter_from_string(model,
599 &iter, temp); 494 &iter, temp);
600 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); 495 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
601 gtk_tree_selection_select_iter(sel, &iter); 496 gtk_tree_selection_select_iter(sel, &iter);
602 } 497 }
603 #endif /* GTK_CHECK_VERSION */
604 498
605 static void clear_plugin_display() { 499 static void clear_plugin_display() {
606 #if GTK_CHECK_VERSION(1,3,0)
607 GtkTreeSelection *selection; 500 GtkTreeSelection *selection;
608 GtkTextBuffer *buffer; 501 GtkTextBuffer *buffer;
609 502
610 /* Clear the plugin display if nothing's selected */ 503 /* Clear the plugin display if nothing's selected */
611 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pluglist)); 504 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pluglist));
616 509
617 gtk_widget_set_sensitive(config, FALSE); 510 gtk_widget_set_sensitive(config, FALSE);
618 gtk_widget_set_sensitive(reload, FALSE); 511 gtk_widget_set_sensitive(reload, FALSE);
619 gtk_widget_set_sensitive(unload, FALSE); 512 gtk_widget_set_sensitive(unload, FALSE);
620 } 513 }
621 #else 514 }
622 /* Clear the display if nothing's selected */ 515
623 if (GTK_LIST(pluglist)->selection == NULL) {
624 guint text_len = gtk_text_get_length(GTK_TEXT(plugtext));
625 gtk_text_set_point(GTK_TEXT(plugtext), 0);
626 gtk_text_forward_delete(GTK_TEXT(plugtext), text_len);
627 gtk_entry_set_text(GTK_ENTRY(plugentry), "");
628
629 gtk_widget_set_sensitive(config, FALSE);
630 gtk_widget_set_sensitive(reload, FALSE);
631 gtk_widget_set_sensitive(unload, FALSE);
632 }
633 #endif 516 #endif
634 }
635
636 #endif