mark PurpleImageClass as private
[pidgin-git.git] / pidgin / plugins / contact_priority.c
blobde2aa6878fc5ec665a9b7fe88586162ebbd7e70e
1 /*
2 * Contact priority settings plugin.
4 * Copyright (C) 2003 Etan Reisner, <deryni9@users.sourceforge.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,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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 02111-1301, USA.
21 #include "internal.h"
22 #include "pidgin.h"
23 #include "gtk3compat.h"
24 #include "gtkplugin.h"
25 #include "gtkutils.h"
26 #include "prefs.h"
27 #include "version.h"
29 #include "pidginaccountchooser.h"
31 #define CONTACT_PRIORITY_PLUGIN_ID "gtk-contact-priority"
33 static void
34 select_account(GtkWidget *chooser, gpointer data)
36 PurpleAccount *account = pidgin_account_chooser_get_selected(chooser);
37 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data),
38 (gdouble)purple_account_get_int(account, "score", 0));
41 static void
42 account_update(GtkWidget *widget, GtkWidget *chooser)
44 PurpleAccount *account = NULL;
46 account = pidgin_account_chooser_get_selected(chooser);
47 purple_account_set_int(account, "score", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
50 static void
51 pref_update(GtkWidget *widget, char *pref)
53 if (purple_prefs_get_pref_type(pref) == PURPLE_PREF_INT)
54 purple_prefs_set_int(pref, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
55 if (purple_prefs_get_pref_type(pref) == PURPLE_PREF_BOOLEAN)
56 purple_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
59 static struct PurpleContactPriorityStatuses
61 const char *id;
62 const char *description;
63 } const statuses[] =
65 { "idle", N_("Buddy is idle") },
66 { "away", N_("Buddy is away") },
67 { "extended_away", N_("Buddy is \"extended\" away") },
68 #if 0
69 /* Not used yet. */
70 { "mobile", N_("Buddy is mobile") },
71 #endif
72 { "offline", N_("Buddy is offline") },
73 { NULL, NULL }
76 static GtkWidget *
77 get_config_frame(PurplePlugin *plugin)
79 GtkWidget *ret = NULL, *hbox = NULL, *frame = NULL, *vbox = NULL;
80 GtkWidget *label = NULL, *spin = NULL, *check = NULL;
81 GtkWidget *chooser = NULL;
82 GtkAdjustment *adj = NULL;
83 GtkSizeGroup *sg = NULL;
84 PurpleAccount *account = NULL;
85 int i;
87 gboolean last_match = purple_prefs_get_bool("/purple/contact/last_match");
89 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
91 ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18);
92 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
94 frame = pidgin_make_frame(ret, _("Point values to use when..."));
96 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
97 gtk_container_add(GTK_CONTAINER(frame), vbox);
99 /* Status Spinboxes */
100 for (i = 0 ; statuses[i].id != NULL && statuses[i].description != NULL ; i++)
102 char *pref = g_strconcat("/purple/status/scores/", statuses[i].id, NULL);
104 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
105 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
107 label = gtk_label_new_with_mnemonic(_(statuses[i].description));
108 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
109 gtk_size_group_add_widget(sg, label);
110 gtk_label_set_xalign(GTK_LABEL(label), 0);
111 gtk_label_set_yalign(GTK_LABEL(label), 0);
113 adj = GTK_ADJUSTMENT(gtk_adjustment_new(purple_prefs_get_int(pref),
114 -500, 500, 1, 1, 1));
115 spin = gtk_spin_button_new(adj, 1, 0);
116 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), pref);
117 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
119 g_free(pref);
122 /* Explanation */
123 label = gtk_label_new(NULL);
124 gtk_label_set_markup(GTK_LABEL(label), _("The buddy with the <i>largest score</i> is the buddy who will have priority in the contact.\n"));
125 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
127 /* Last match */
128 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
129 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
131 check = gtk_check_button_new_with_label(_("Use last buddy when scores are equal"));
132 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), last_match);
133 g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(pref_update), "/purple/contact/last_match");
134 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
136 frame = pidgin_make_frame(ret, _("Point values to use for account..."));
138 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
139 gtk_container_add(GTK_CONTAINER(frame), vbox);
141 /* Account */
142 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
143 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
145 /* make this here so I can use it in the option menu callback, we'll
146 * actually set it up later */
147 adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -500, 500, 1, 1, 1));
148 spin = gtk_spin_button_new(adj, 1, 0);
150 chooser = pidgin_account_chooser_new(NULL, TRUE);
151 gtk_box_pack_start(GTK_BOX(hbox), chooser, FALSE, FALSE, 0);
152 g_signal_connect(chooser, "changed", G_CALLBACK(select_account), spin);
154 /* this is where we set up the spin button we made above */
155 account = pidgin_account_chooser_get_selected(chooser);
156 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
157 (gdouble)purple_account_get_int(account, "score", 0));
158 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj));
159 g_signal_connect(G_OBJECT(spin), "value-changed",
160 G_CALLBACK(account_update), chooser);
161 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
163 gtk_widget_show_all(ret);
164 g_object_unref(sg);
166 return ret;
169 static PidginPluginInfo *
170 plugin_query(GError **error)
172 const gchar * const authors[] = {
173 "Etan Reisner <deryni@eden.rutgers.edu>",
174 NULL
177 return pidgin_plugin_info_new(
178 "id", CONTACT_PRIORITY_PLUGIN_ID,
179 "name", N_("Contact Priority"),
180 "version", DISPLAY_VERSION,
181 "category", N_("Utility"),
182 "summary", N_("Allows for controlling the values associated with different buddy states."),
183 "description", N_("Allows for changing the point values of idle/away/offline states for buddies in contact priority computations."),
184 "authors", authors,
185 "website", PURPLE_WEBSITE,
186 "abi-version", PURPLE_ABI_VERSION,
187 "gtk-config-frame-cb", get_config_frame,
188 NULL
192 static gboolean
193 plugin_load(PurplePlugin *plugin, GError **error)
195 return TRUE;
198 static gboolean
199 plugin_unload(PurplePlugin *plugin, GError **error)
201 return TRUE;
204 PURPLE_PLUGIN_INIT(contactpriority, plugin_query, plugin_load, plugin_unload);