comparison plugins/contact_priority.c @ 7421:1a52d75489ad

[gaim-migrate @ 8023] forgot this committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 04 Nov 2003 00:17:45 +0000
parents
children 3a51b301a805
comparison
equal deleted inserted replaced
7420:53c86d59f20b 7421:1a52d75489ad
1 /*
2 * Contact priority settings plugin.
3 *
4 * Copyright (C) 2003 Etan Reisner, <deryni9@users.sourceforge.net>.
5 *
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.
10 *
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.
15 *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 #include "gtkinternal.h"
22 #include "gtkplugin.h"
23 #include "gtkutils.h"
24 #include "prefs.h"
25
26 #define CONTACT_PRIORITY_PLUGIN_ID "gtk-contact-priority"
27
28 static void
29 select_account(GtkWidget *widget, GaimAccount *account, gpointer data)
30 {
31 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data),
32 (gdouble)gaim_account_get_int(account, "score", 0));
33 }
34
35 static void
36 account_update(GtkWidget *widget, GtkOptionMenu *optmenu)
37 {
38 GaimAccount *account = NULL;
39
40 account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)))), "account");
41 gaim_account_set_int(account, "score", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
42 }
43
44 static void
45 pref_update(GtkWidget *widget, gpointer data)
46 {
47 gchar pref[256];
48
49 g_snprintf(pref, sizeof(pref), "/core/contact/%s", (gchar *)data);
50
51 if (gaim_prefs_get_type(pref) == GAIM_PREF_INT)
52 gaim_prefs_set_int(pref, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
53 if (gaim_prefs_get_type(pref) == GAIM_PREF_BOOLEAN)
54 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
55 }
56
57 static GtkWidget *
58 get_config_frame(GaimPlugin *plugin)
59 {
60 GtkWidget *ret = NULL, *hbox = NULL, *frame = NULL, *vbox = NULL;
61 GtkWidget *label = NULL, *spin = NULL, *check = NULL;
62 GtkWidget *optmenu = NULL;
63 GtkObject *adj = NULL;
64 GtkSizeGroup *sg = NULL;
65 GaimAccount *account = NULL;
66 /*
67 GList *accounts = NULL;
68 */
69 int offline = gaim_prefs_get_int("/core/contact/offline_score");
70 int away = gaim_prefs_get_int("/core/contact/away_score");
71 int idle = gaim_prefs_get_int("/core/contact/idle_score");
72 /*
73 int score;
74 */
75 gboolean last_match = gaim_prefs_get_bool("/core/contact/last_match");
76
77 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
78
79 ret = gtk_vbox_new(FALSE, 18);
80 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
81
82 frame = gaim_gtk_make_frame(ret, _("Point values to use when..."));
83
84 vbox = gtk_vbox_new(FALSE, 5);
85 gtk_container_add(GTK_CONTAINER(frame), vbox);
86
87 /* Offline */
88 hbox = gtk_hbox_new(FALSE, 5);
89 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
90
91 label = gtk_label_new_with_mnemonic(_("Buddy is offline:"));
92 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
93 gtk_size_group_add_widget(sg, label);
94
95 adj = gtk_adjustment_new(offline, -20, 20, 1, 1, 1);
96 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
97 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "offline_score");
98 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
99
100 /* Away */
101 hbox = gtk_hbox_new(FALSE, 5);
102 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
103
104 label = gtk_label_new_with_mnemonic(_("Buddy is away:"));
105 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
106 gtk_size_group_add_widget(sg, label);
107
108 adj = gtk_adjustment_new(away, -20, 20, 1, 1, 1);
109 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
110 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "away_score");
111 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
112
113 /* Idle */
114 hbox = gtk_hbox_new(FALSE, 5);
115 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
116
117 label = gtk_label_new_with_mnemonic(_("Buddy is idle:"));
118 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
119 gtk_size_group_add_widget(sg, label);
120
121 adj = gtk_adjustment_new(idle, -20, 20, 1, 1, 1);
122 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
123 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "idle_score");
124 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
125
126 /* Last match */
127 hbox = gtk_hbox_new(FALSE, 5);
128 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
129
130 check = gtk_check_button_new_with_label(_("Use last matching buddy"));
131 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), last_match);
132 g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(pref_update), "last_match");
133 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
134
135 /* Explanation */
136 label = gtk_label_new(_("The buddy with the lowest score is the buddy who will have priority in the contact.\nThe default values (offline = 4,away = 2, and idle = 1)\nwill use what used to be the built-in order active->idle->away->away+idle->offline."));
137 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
138
139 frame = gaim_gtk_make_frame(ret, _("Point values to use for Account..."));
140
141 vbox = gtk_vbox_new(FALSE, 5);
142 gtk_container_add(GTK_CONTAINER(frame), vbox);
143
144 /* Account */
145 hbox = gtk_hbox_new(FALSE, 5);
146 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
147
148 /* make this here so I can use it in the option menu callback, we'll
149 * actually set it up later */
150 adj = gtk_adjustment_new(0, -20, 20, 1, 1, 1);
151 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
152
153 optmenu = gaim_gtk_account_option_menu_new(NULL, TRUE,
154 G_CALLBACK(select_account),
155 NULL, spin);
156 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
157
158 /* this is where we set up the spin button we made above */
159 account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))))),
160 "account");
161 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
162 (gdouble)gaim_account_get_int(account, "score", 0));
163 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj));
164 g_signal_connect(G_OBJECT(spin), "value-changed",
165 G_CALLBACK(account_update), optmenu);
166 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
167
168 gtk_widget_show_all(ret);
169
170 return ret;
171 }
172
173 static GaimGtkPluginUiInfo ui_info =
174 {
175 get_config_frame
176 };
177
178 static GaimPluginInfo info =
179 {
180 2, /**< api_version */
181 GAIM_PLUGIN_STANDARD, /**< type */
182 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
183 0, /**< flags */
184 NULL, /**< dependencies */
185 GAIM_PRIORITY_DEFAULT, /**< priority */
186
187 CONTACT_PRIORITY_PLUGIN_ID, /**< id */
188 N_("Contact Priority"), /**< name */
189 VERSION, /**< version */
190 /**< summary */
191 N_("Allows for controlling the values associated with different buddy states."),
192 /**< description */
193 N_("Allows for changing the point values of idle/away/offline states for buddies in contact priority computations."),
194 "Etan Reisner <deryni@eden.rutgers.edu>", /**< author */
195 GAIM_WEBSITE, /**< homepage */
196
197 NULL, /**< load */
198 NULL, /**< unload */
199 NULL, /**< destroy */
200 &ui_info, /**< ui_info */
201 NULL /**< extra_info */
202 };
203
204 static void
205 init_plugin(GaimPlugin *plugin)
206 {
207 }
208
209 GAIM_INIT_PLUGIN(contactpriority, init_plugin, info)