Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / pidgin / plugins / contact_priority.c
blob75edbd0100bea5161177e48830e3a6de9fca5381
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 #define CONTACT_PRIORITY_PLUGIN_ID "gtk-contact-priority"
31 static void
32 select_account(GtkWidget *widget, PurpleAccount *account, gpointer data)
34 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data),
35 (gdouble)purple_account_get_int(account, "score", 0));
38 static void
39 account_update(GtkWidget *widget, GtkWidget *optmenu)
41 PurpleAccount *account = NULL;
43 account = pidgin_account_option_menu_get_selected(optmenu);
44 purple_account_set_int(account, "score", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
47 static void
48 pref_update(GtkWidget *widget, char *pref)
50 if (purple_prefs_get_pref_type(pref) == PURPLE_PREF_INT)
51 purple_prefs_set_int(pref, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
52 if (purple_prefs_get_pref_type(pref) == PURPLE_PREF_BOOLEAN)
53 purple_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
56 static struct PurpleContactPriorityStatuses
58 const char *id;
59 const char *description;
60 } const statuses[] =
62 { "idle", N_("Buddy is idle") },
63 { "away", N_("Buddy is away") },
64 { "extended_away", N_("Buddy is \"extended\" away") },
65 #if 0
66 /* Not used yet. */
67 { "mobile", N_("Buddy is mobile") },
68 #endif
69 { "offline", N_("Buddy is offline") },
70 { NULL, NULL }
73 static GtkWidget *
74 get_config_frame(PurplePlugin *plugin)
76 GtkWidget *ret = NULL, *hbox = NULL, *frame = NULL, *vbox = NULL;
77 GtkWidget *label = NULL, *spin = NULL, *check = NULL;
78 GtkWidget *optmenu = NULL;
79 GtkAdjustment *adj = NULL;
80 GtkSizeGroup *sg = NULL;
81 PurpleAccount *account = NULL;
82 int i;
84 gboolean last_match = purple_prefs_get_bool("/purple/contact/last_match");
86 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
88 ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 18);
89 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
91 frame = pidgin_make_frame(ret, _("Point values to use when..."));
93 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
94 gtk_container_add(GTK_CONTAINER(frame), vbox);
96 /* Status Spinboxes */
97 for (i = 0 ; statuses[i].id != NULL && statuses[i].description != NULL ; i++)
99 char *pref = g_strconcat("/purple/status/scores/", statuses[i].id, NULL);
101 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
102 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
104 label = gtk_label_new_with_mnemonic(_(statuses[i].description));
105 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
106 gtk_size_group_add_widget(sg, label);
107 gtk_label_set_xalign(GTK_LABEL(label), 0);
108 gtk_label_set_yalign(GTK_LABEL(label), 0);
110 adj = GTK_ADJUSTMENT(gtk_adjustment_new(purple_prefs_get_int(pref),
111 -500, 500, 1, 1, 1));
112 spin = gtk_spin_button_new(adj, 1, 0);
113 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), pref);
114 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
116 g_free(pref);
119 /* Explanation */
120 label = gtk_label_new(NULL);
121 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"));
122 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
124 /* Last match */
125 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
126 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
128 check = gtk_check_button_new_with_label(_("Use last buddy when scores are equal"));
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), last_match);
130 g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(pref_update), "/purple/contact/last_match");
131 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
133 frame = pidgin_make_frame(ret, _("Point values to use for account..."));
135 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
136 gtk_container_add(GTK_CONTAINER(frame), vbox);
138 /* Account */
139 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
140 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
142 /* make this here so I can use it in the option menu callback, we'll
143 * actually set it up later */
144 adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -500, 500, 1, 1, 1));
145 spin = gtk_spin_button_new(adj, 1, 0);
147 optmenu = pidgin_account_option_menu_new(NULL, TRUE,
148 G_CALLBACK(select_account),
149 NULL, spin);
150 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
152 /* this is where we set up the spin button we made above */
153 account = pidgin_account_option_menu_get_selected(optmenu);
154 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
155 (gdouble)purple_account_get_int(account, "score", 0));
156 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj));
157 g_signal_connect(G_OBJECT(spin), "value-changed",
158 G_CALLBACK(account_update), optmenu);
159 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
161 gtk_widget_show_all(ret);
162 g_object_unref(sg);
164 return ret;
167 static PidginPluginInfo *
168 plugin_query(GError **error)
170 const gchar * const authors[] = {
171 "Etan Reisner <deryni@eden.rutgers.edu>",
172 NULL
175 return pidgin_plugin_info_new(
176 "id", CONTACT_PRIORITY_PLUGIN_ID,
177 "name", N_("Contact Priority"),
178 "version", DISPLAY_VERSION,
179 "category", N_("Utility"),
180 "summary", N_("Allows for controlling the values associated with different buddy states."),
181 "description", N_("Allows for changing the point values of idle/away/offline states for buddies in contact priority computations."),
182 "authors", authors,
183 "website", PURPLE_WEBSITE,
184 "abi-version", PURPLE_ABI_VERSION,
185 "gtk-config-frame-cb", get_config_frame,
186 NULL
190 static gboolean
191 plugin_load(PurplePlugin *plugin, GError **error)
193 return TRUE;
196 static gboolean
197 plugin_unload(PurplePlugin *plugin, GError **error)
199 return TRUE;
202 PURPLE_PLUGIN_INIT(contactpriority, plugin_query, plugin_load, plugin_unload);