Merged pidgin/main into default
[pidgin-git.git] / libpurple / plugins / pluginpref_example.c
blobc8048976043f4057a77251cf9e5789374f5dc0ab
1 /*
2 * PluginPref Example Plugin
4 * Copyright (C) 2004, Gary Kramlich <amc_grim@users.sf.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02111-1301, USA.
22 /* When writing a third-party plugin, do not include libpurple's internal.h
23 * included below. This file is for internal libpurple use only. We're including
24 * it here for our own convenience. */
25 #include "internal.h"
27 /* This file defines PURPLE_PLUGINS and includes all the libpurple headers */
28 #include <purple.h>
30 static PurplePluginPrefFrame *
31 get_plugin_pref_frame(PurplePlugin *plugin) {
32 PurplePluginPrefFrame *frame;
33 PurplePluginPref *ppref;
35 frame = purple_plugin_pref_frame_new();
37 ppref = purple_plugin_pref_new_with_label("boolean");
38 purple_plugin_pref_frame_add(frame, ppref);
40 ppref = purple_plugin_pref_new_with_name_and_label(
41 "/plugins/core/pluginpref_example/bool",
42 "boolean pref");
43 purple_plugin_pref_frame_add(frame, ppref);
45 ppref = purple_plugin_pref_new_with_label("integer");
46 purple_plugin_pref_frame_add(frame, ppref);
48 ppref = purple_plugin_pref_new_with_name_and_label(
49 "/plugins/core/pluginpref_example/int",
50 "integer pref");
51 purple_plugin_pref_set_bounds(ppref, 0, 255);
52 purple_plugin_pref_frame_add(frame, ppref);
54 ppref = purple_plugin_pref_new_with_name_and_label(
55 "/plugins/core/pluginpref_example/int_choice",
56 "integer choice");
57 purple_plugin_pref_set_pref_type(ppref, PURPLE_PLUGIN_PREF_CHOICE);
58 purple_plugin_pref_add_choice(ppref, "One", GINT_TO_POINTER(1));
59 purple_plugin_pref_add_choice(ppref, "Two", GINT_TO_POINTER(2));
60 purple_plugin_pref_add_choice(ppref, "Four", GINT_TO_POINTER(4));
61 purple_plugin_pref_add_choice(ppref, "Eight", GINT_TO_POINTER(8));
62 purple_plugin_pref_add_choice(ppref, "Sixteen", GINT_TO_POINTER(16));
63 purple_plugin_pref_add_choice(ppref, "Thirty Two", GINT_TO_POINTER(32));
64 purple_plugin_pref_add_choice(ppref, "Sixty Four", GINT_TO_POINTER(64));
65 purple_plugin_pref_add_choice(ppref, "One Hundred Twenty Eight", GINT_TO_POINTER(128));
66 purple_plugin_pref_frame_add(frame, ppref);
68 ppref = purple_plugin_pref_new_with_label("string");
69 purple_plugin_pref_frame_add(frame, ppref);
71 ppref = purple_plugin_pref_new_with_name_and_label(
72 "/plugins/core/pluginpref_example/string",
73 "string pref");
74 purple_plugin_pref_frame_add(frame, ppref);
76 ppref = purple_plugin_pref_new_with_name_and_label(
77 "/plugins/core/pluginpref_example/masked_string",
78 "masked string");
79 purple_plugin_pref_set_masked(ppref, TRUE);
80 purple_plugin_pref_frame_add(frame, ppref);
82 ppref = purple_plugin_pref_new_with_name_and_label(
83 "/plugins/core/pluginpref_example/max_string",
84 "string pref\n(max length of 16)");
85 purple_plugin_pref_set_max_length(ppref, 16);
86 purple_plugin_pref_frame_add(frame, ppref);
88 ppref = purple_plugin_pref_new_with_name_and_label(
89 "/plugins/core/pluginpref_example/string_choice",
90 "string choice");
91 purple_plugin_pref_set_pref_type(ppref, PURPLE_PLUGIN_PREF_CHOICE);
92 purple_plugin_pref_add_choice(ppref, "red", "red");
93 purple_plugin_pref_add_choice(ppref, "orange", "orange");
94 purple_plugin_pref_add_choice(ppref, "yellow", "yellow");
95 purple_plugin_pref_add_choice(ppref, "green", "green");
96 purple_plugin_pref_add_choice(ppref, "blue", "blue");
97 purple_plugin_pref_add_choice(ppref, "purple", "purple");
98 purple_plugin_pref_frame_add(frame, ppref);
100 return frame;
103 static PurplePluginInfo *
104 plugin_query(GError **error)
106 const gchar * const authors[] = {
107 "Gary Kramlich <amc_grim@users.sf.net>",
108 NULL
111 return purple_plugin_info_new(
112 "id", "core-pluginpref_example",
113 "name", "Pluginpref Example",
114 "version", DISPLAY_VERSION,
115 "category", "Example",
116 "summary", "An example of how to use pluginprefs",
117 "description", "An example of how to use pluginprefs",
118 "authors", authors,
119 "website", PURPLE_WEBSITE,
120 "abi-version", PURPLE_ABI_VERSION,
121 "pref-frame-cb", get_plugin_pref_frame,
122 NULL
126 static gboolean
127 plugin_load(PurplePlugin *plugin, GError **error)
129 purple_prefs_add_none("/plugins/core/pluginpref_example");
130 purple_prefs_add_bool("/plugins/core/pluginpref_example/bool", TRUE);
131 purple_prefs_add_int("/plugins/core/pluginpref_example/int", 0);
132 purple_prefs_add_int("/plugins/core/pluginpref_example/int_choice", 1);
133 purple_prefs_add_string("/plugins/core/pluginpref_example/string",
134 "string");
135 purple_prefs_add_string("/plugins/core/pluginpref_example/max_string",
136 "max length string");
137 purple_prefs_add_string("/plugins/core/pluginpref_example/masked_string", "masked");
138 purple_prefs_add_string("/plugins/core/pluginpref_example/string_choice", "red");
140 return TRUE;
143 static gboolean
144 plugin_unload(PurplePlugin *plugin, GError **error)
146 return TRUE;
149 PURPLE_PLUGIN_INIT(ppexample, plugin_query, plugin_load, plugin_unload);