comparison src/gtkprefs.c @ 8713:7024b595b6ae

[gaim-migrate @ 9467] " Expansion from my original protocol prefs to plugin prefs. Things are handled a bit different in this iteration of it, but I have already modified msn and jabber to use it, and included an example plugin to show how to use it. It will also generate pages with doxygen. The example plugin doesn't not contain any translatable strings seeing as we're in the string freeze. And it's an example, whats the point of translating it..? Also, I tweaked the documentation for 2 functions in gtkprefs, gaim_gtk_prefs_dropdown and gaim_gtk_prefs_dropdown_from_list. Nothing major in that, just made it say that the list should be a list of pairs label/value. Also there's 5 new files that will need to be added to cvs: src/pluginpref.h src/pluginpref.c src/gtkpluginpref.h src/gtkpluginpref.c plugins/pluginpref_example.c the tarball already has them structured correctly and contains the diff" --Gary Kramlich - amc_grim and the german translator pointed out that sean missed the novell file for POTFILES.in committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 19 Apr 2004 21:12:45 +0000
parents 543b19a96ac5
children 6c0fae7a4f1a
comparison
equal deleted inserted replaced
8712:a4ff6e79c5fc 8713:7024b595b6ae
38 #include "gtkblist.h" 38 #include "gtkblist.h"
39 #include "gtkconv.h" 39 #include "gtkconv.h"
40 #include "gtkdebug.h" 40 #include "gtkdebug.h"
41 #include "gtkimhtml.h" 41 #include "gtkimhtml.h"
42 #include "gtkplugin.h" 42 #include "gtkplugin.h"
43 #include "gtkpluginpref.h"
43 #include "gtkprefs.h" 44 #include "gtkprefs.h"
44 #include "gtksound.h" 45 #include "gtksound.h"
45 #include "gtkutils.h" 46 #include "gtkutils.h"
46 #include "stock.h" 47 #include "stock.h"
47 48
73 static GtkWidget *prefs_proxy_frame = NULL; 74 static GtkWidget *prefs_proxy_frame = NULL;
74 75
75 static GtkWidget *prefs = NULL; 76 static GtkWidget *prefs = NULL;
76 static GtkWidget *debugbutton = NULL; 77 static GtkWidget *debugbutton = NULL;
77 static int notebook_page = 0; 78 static int notebook_page = 0;
78 static GtkTreeIter plugin_iter; 79 static GtkTreeIter proto_iter, plugin_iter;
79 80
80 static guint browser_pref1_id = 0; 81 static guint browser_pref1_id = 0;
81 static guint browser_pref2_id = 0; 82 static guint browser_pref2_id = 0;
82 static guint proxy_pref_id = 0; 83 static guint proxy_pref_id = 0;
83 static guint sound_pref_id = 0; 84 static guint sound_pref_id = 0;
121 hbox = gtk_hbox_new(FALSE, 5); 122 hbox = gtk_hbox_new(FALSE, 5);
122 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5); 123 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 5);
123 gtk_widget_show(hbox); 124 gtk_widget_show(hbox);
124 125
125 label = gtk_label_new_with_mnemonic(title); 126 label = gtk_label_new_with_mnemonic(title);
127 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
126 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 128 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
127 gtk_widget_show(label); 129 gtk_widget_show(label);
128 130
129 adjust = gtk_adjustment_new(val, min, max, 1, 1, 1); 131 adjust = gtk_adjustment_new(val, min, max, 1, 1, 1);
130 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0); 132 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjust), 1, 0);
197 int o = 0; 199 int o = 0;
198 200
199 g_return_val_if_fail(menuitems != NULL, NULL); 201 g_return_val_if_fail(menuitems != NULL, NULL);
200 202
201 hbox = gtk_hbox_new(FALSE, 5); 203 hbox = gtk_hbox_new(FALSE, 5);
202 gtk_container_add (GTK_CONTAINER (box), hbox); 204 /*gtk_container_add (GTK_CONTAINER (box), hbox);*/
205 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
203 gtk_widget_show(hbox); 206 gtk_widget_show(hbox);
204 207
205 label = gtk_label_new_with_mnemonic(title); 208 label = gtk_label_new_with_mnemonic(title);
206 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); 209 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
207 gtk_widget_show(label); 210 gtk_widget_show(label);
1711 gtk_widget_show(ret); 1714 gtk_widget_show(ret);
1712 1715
1713 return ret; 1716 return ret;
1714 } 1717 }
1715 1718
1716 static gboolean
1717 protocol_pref_entry_cb(GtkWidget *entry, GdkEventFocus *event, gpointer data) {
1718 char *pref = data;
1719
1720 gaim_prefs_set_string(pref, gtk_entry_get_text(GTK_ENTRY(entry)));
1721
1722 return FALSE;
1723 }
1724
1725 static GtkWidget *
1726 protocol_pref_page(GaimPluginProtocolInfo *prpl_info) {
1727 GtkWidget *ret, *parent, *frame, *hbox, *label, *misc;
1728 GtkSizeGroup *sg;
1729 GList *pp = NULL;
1730
1731 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1732
1733 ret = gtk_vbox_new(FALSE, 18);
1734 gtk_container_set_border_width (GTK_CONTAINER (ret), 12);
1735 gtk_widget_show(ret);
1736
1737 parent = ret;
1738
1739 for(pp = prpl_info->protocol_prefs; pp != NULL; pp = pp->next) {
1740 struct proto_pref *pref = pp->data;
1741
1742 if(pref->key != NULL) {
1743 switch(gaim_prefs_get_type(pref->key)) {
1744 case GAIM_PREF_BOOLEAN:
1745 misc = gaim_gtk_prefs_checkbox(pref->label,
1746 pref->key,
1747 parent);
1748 break;
1749 case GAIM_PREF_INT:
1750 misc = gaim_gtk_prefs_labeled_spin_button(parent,
1751 pref->label,
1752 pref->key,
1753 pref->min,
1754 pref->max,
1755 sg);
1756 break;
1757 case GAIM_PREF_STRING:
1758 hbox = gtk_hbox_new(FALSE, 6);
1759 gtk_widget_show(hbox);
1760 gtk_box_pack_start(GTK_BOX(parent), hbox, FALSE, FALSE, 0);
1761
1762 label = gtk_label_new_with_mnemonic(pref->label);
1763 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
1764 gtk_size_group_add_widget(sg, label);
1765 gtk_widget_show(label);
1766 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1767
1768 misc = gtk_entry_new();
1769 gtk_entry_set_text(GTK_ENTRY(misc),
1770 gaim_prefs_get_string(pref->key));
1771 g_signal_connect(G_OBJECT(misc), "focus-out-event",
1772 G_CALLBACK(protocol_pref_entry_cb),
1773 (gpointer)pref->key);
1774 gtk_label_set_mnemonic_widget(GTK_LABEL(label), misc);
1775 gtk_widget_show(misc);
1776 gtk_box_pack_start(GTK_BOX(hbox), misc, FALSE, FALSE, 0);
1777
1778 break;
1779 case GAIM_PREF_NONE: /* XXX No use for this, if you want a
1780 frame, set key to NULL */
1781 case GAIM_PREF_STRING_LIST: /*XXX No one should need this */
1782 default:
1783 break;
1784 }
1785 } else {
1786 frame = gaim_gtk_make_frame(ret, pref->label);
1787 gtk_widget_show(frame);
1788
1789 parent = frame;
1790 }
1791 }
1792
1793 return ret;
1794 }
1795
1796 static GtkWidget *plugin_description=NULL, *plugin_details=NULL; 1719 static GtkWidget *plugin_description=NULL, *plugin_details=NULL;
1797 1720
1798 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model) 1721 static void prefs_plugin_sel (GtkTreeSelection *sel, GtkTreeModel *model)
1799 { 1722 {
1800 gchar *buf, *pname, *perr, *pdesc, *pauth, *pweb; 1723 gchar *buf, *pname, *perr, *pdesc, *pauth, *pweb;
1906 path2, TRUE); 1829 path2, TRUE);
1907 gtk_tree_path_free(path2); 1830 gtk_tree_path_free(path2);
1908 } 1831 }
1909 } 1832 }
1910 } 1833 }
1834
1835 if(GAIM_PLUGIN_HAS_PREF_FRAME(plug)) {
1836 GtkTreeIter iter;
1837 GtkWidget *pref_frame;
1838 GaimPluginUiInfo *prefs_info;
1839
1840 if(plug->info->type == GAIM_PLUGIN_PROTOCOL)
1841 iter = proto_iter;
1842 else
1843 iter = plugin_iter;
1844
1845 prefs_info = GAIM_PLUGIN_UI_INFO(plug);
1846 pref_frame = gaim_gtk_plugin_pref_create_frame(prefs_info->get_plugin_pref_frame(plug));
1847
1848 if(pref_frame != NULL) {
1849 prefs_info->iter = g_new0(GtkTreeIter, 1);
1850 prefs_notebook_add_page(_(plug->info->name), NULL,
1851 pref_frame, prefs_info->iter,
1852 &iter, notebook_page++);
1853
1854 if(gtk_tree_model_iter_n_children(GTK_TREE_MODEL(prefstree), &iter) == 1)
1855 {
1856 GtkTreePath *path2;
1857
1858 path2 = gtk_tree_model_get_path(GTK_TREE_MODEL(prefstree), &iter);
1859 gtk_tree_view_expand_row(GTK_TREE_VIEW(tree_v), path2, TRUE);
1860 gtk_tree_path_free(path2);
1861 }
1862 }
1863 }
1911 } 1864 }
1912 else { 1865 else {
1913 if (GAIM_IS_GTK_PLUGIN(plug)) { 1866 if (GAIM_IS_GTK_PLUGIN(plug)) {
1914 GaimGtkPluginUiInfo *ui_info; 1867 GaimGtkPluginUiInfo *ui_info;
1915 1868
1917 1870
1918 if (ui_info != NULL && ui_info->iter != NULL) { 1871 if (ui_info != NULL && ui_info->iter != NULL) {
1919 gtk_tree_store_remove(GTK_TREE_STORE(prefstree), ui_info->iter); 1872 gtk_tree_store_remove(GTK_TREE_STORE(prefstree), ui_info->iter);
1920 g_free(ui_info->iter); 1873 g_free(ui_info->iter);
1921 ui_info->iter = NULL; 1874 ui_info->iter = NULL;
1875 }
1876 } else if (GAIM_PLUGIN_HAS_PREF_FRAME(plug)) {
1877 GaimPluginUiInfo *prefs_info;
1878
1879 prefs_info = GAIM_PLUGIN_UI_INFO(plug);
1880
1881 if(prefs_info != NULL && prefs_info->iter != NULL) {
1882 gtk_tree_store_remove(GTK_TREE_STORE(prefstree), prefs_info->iter);
1883 g_free(prefs_info->iter);
1884 prefs_info->iter = NULL;
1922 } 1885 }
1923 } 1886 }
1924 1887
1925 gaim_plugin_unload(plug); 1888 gaim_plugin_unload(plug);
1926 } 1889 }
2538 prefs_notebook_add_page(_("Sounds"), NULL, sound_page(), &p, NULL, notebook_page++); 2501 prefs_notebook_add_page(_("Sounds"), NULL, sound_page(), &p, NULL, notebook_page++);
2539 prefs_notebook_add_page(_("Sound Events"), NULL, sound_events_page(), &c, &p, notebook_page++); 2502 prefs_notebook_add_page(_("Sound Events"), NULL, sound_events_page(), &c, &p, notebook_page++);
2540 prefs_notebook_add_page(_("Away / Idle"), NULL, away_page(), &p, NULL, notebook_page++); 2503 prefs_notebook_add_page(_("Away / Idle"), NULL, away_page(), &p, NULL, notebook_page++);
2541 prefs_notebook_add_page(_("Away Messages"), NULL, away_message_page(), &c, &p, notebook_page++); 2504 prefs_notebook_add_page(_("Away Messages"), NULL, away_message_page(), &c, &p, notebook_page++);
2542 2505
2543 prefs_notebook_add_page(_("Protocols"), NULL, protocol_page(), &p, NULL, notebook_page++);
2544 for (l = gaim_plugins_get_protocols(); l != NULL; l = l->next) {
2545 plug = l->data;
2546
2547 if (GAIM_IS_PROTOCOL_PLUGIN(plug)) {
2548 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plug);
2549
2550 if (prpl_info->protocol_prefs != NULL) {
2551 prefs_notebook_add_page(_(plug->info->name), NULL,
2552 protocol_pref_page(prpl_info), &c,
2553 &p, notebook_page++);
2554 }
2555 }
2556 }
2557
2558 if (gaim_plugins_enabled()) { 2506 if (gaim_plugins_enabled()) {
2507 prefs_notebook_add_page(_("Protocols"), NULL, protocol_page(), &proto_iter, NULL, notebook_page++);
2559 prefs_notebook_add_page(_("Plugins"), NULL, plugin_page(), &plugin_iter, NULL, notebook_page++); 2508 prefs_notebook_add_page(_("Plugins"), NULL, plugin_page(), &plugin_iter, NULL, notebook_page++);
2560 2509
2561 for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) { 2510 for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) {
2562 plug = l->data; 2511 plug = (GaimPlugin *)l->data;
2563 2512
2564 if (GAIM_IS_GTK_PLUGIN(plug)) { 2513 if (GAIM_IS_GTK_PLUGIN(plug)) {
2565 GtkWidget *config_frame; 2514 GtkWidget *config_frame;
2566 GaimGtkPluginUiInfo *ui_info; 2515 GaimGtkPluginUiInfo *ui_info;
2567 2516
2571 if (config_frame != NULL) { 2520 if (config_frame != NULL) {
2572 ui_info->iter = g_new0(GtkTreeIter, 1); 2521 ui_info->iter = g_new0(GtkTreeIter, 1);
2573 prefs_notebook_add_page(_(plug->info->name), NULL, 2522 prefs_notebook_add_page(_(plug->info->name), NULL,
2574 config_frame, ui_info->iter, 2523 config_frame, ui_info->iter,
2575 &plugin_iter, notebook_page++); 2524 &plugin_iter, notebook_page++);
2525 }
2526 }
2527
2528 if(GAIM_PLUGIN_HAS_PREF_FRAME(plug)) {
2529 GtkWidget *pref_frame;
2530 GaimPluginUiInfo *prefs_info;
2531
2532 prefs_info = GAIM_PLUGIN_UI_INFO(plug);
2533 pref_frame = gaim_gtk_plugin_pref_create_frame(prefs_info->get_plugin_pref_frame(plug));
2534
2535 if(pref_frame != NULL) {
2536 prefs_info->iter = g_new0(GtkTreeIter, 1);
2537 prefs_notebook_add_page(_(plug->info->name), NULL,
2538 pref_frame, prefs_info->iter,
2539 (plug->info->type == GAIM_PLUGIN_PROTOCOL) ? &proto_iter : &plugin_iter,
2540 notebook_page++);
2576 } 2541 }
2577 } 2542 }
2578 } 2543 }
2579 } 2544 }
2580 } 2545 }
2689 gtk_widget_show(notebook); 2654 gtk_widget_show(notebook);
2690 sep = gtk_hseparator_new(); 2655 sep = gtk_hseparator_new();
2691 gtk_widget_show(sep); 2656 gtk_widget_show(sep);
2692 gtk_box_pack_start (GTK_BOX (vbox), sep, FALSE, FALSE, 0); 2657 gtk_box_pack_start (GTK_BOX (vbox), sep, FALSE, FALSE, 0);
2693 2658
2694 /* The buttons^H to press! */ 2659 /* The buttons to press! */
2695 bbox = gtk_hbutton_box_new(); 2660 bbox = gtk_hbutton_box_new();
2696 gtk_box_set_spacing(GTK_BOX(bbox), 6); 2661 gtk_box_set_spacing(GTK_BOX(bbox), 6);
2697 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); 2662 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
2698 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); 2663 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
2699 gtk_widget_show (bbox); 2664 gtk_widget_show (bbox);