Mercurial > pidgin.yaz
comparison pidgin/plugins/contact_priority.c @ 15374:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | d75099d2567e |
comparison
equal
deleted
inserted
replaced
15373:f79e0f4df793 | 15374:5fe8042783c1 |
---|---|
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 "internal.h" | |
22 #include "gtkgaim.h" | |
23 #include "gtkplugin.h" | |
24 #include "gtkutils.h" | |
25 #include "prefs.h" | |
26 #include "version.h" | |
27 | |
28 #define CONTACT_PRIORITY_PLUGIN_ID "gtk-contact-priority" | |
29 | |
30 static void | |
31 select_account(GtkWidget *widget, GaimAccount *account, gpointer data) | |
32 { | |
33 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data), | |
34 (gdouble)gaim_account_get_int(account, "score", 0)); | |
35 } | |
36 | |
37 static void | |
38 account_update(GtkWidget *widget, GtkOptionMenu *optmenu) | |
39 { | |
40 GaimAccount *account = NULL; | |
41 | |
42 account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(optmenu)))), "account"); | |
43 gaim_account_set_int(account, "score", gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget))); | |
44 } | |
45 | |
46 static void | |
47 pref_update(GtkWidget *widget, char *pref) | |
48 { | |
49 if (gaim_prefs_get_type(pref) == GAIM_PREF_INT) | |
50 gaim_prefs_set_int(pref, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget))); | |
51 if (gaim_prefs_get_type(pref) == GAIM_PREF_BOOLEAN) | |
52 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))); | |
53 } | |
54 | |
55 static struct GaimContactPriorityStatuses | |
56 { | |
57 const char *id; | |
58 const char *description; | |
59 } const statuses[] = | |
60 { | |
61 { "idle", N_("Buddy is idle") }, | |
62 { "away", N_("Buddy is away") }, | |
63 { "extended_away", N_("Buddy is \"extended\" away") }, | |
64 #if 0 | |
65 /* Not used yet. */ | |
66 { "mobile", N_("Buddy is mobile") }, | |
67 #endif | |
68 { "offline", N_("Buddy is offline") }, | |
69 { NULL, NULL } | |
70 }; | |
71 | |
72 static GtkWidget * | |
73 get_config_frame(GaimPlugin *plugin) | |
74 { | |
75 GtkWidget *ret = NULL, *hbox = NULL, *frame = NULL, *vbox = NULL; | |
76 GtkWidget *label = NULL, *spin = NULL, *check = NULL; | |
77 GtkWidget *optmenu = NULL; | |
78 GtkObject *adj = NULL; | |
79 GtkSizeGroup *sg = NULL; | |
80 GaimAccount *account = NULL; | |
81 int i; | |
82 | |
83 gboolean last_match = gaim_prefs_get_bool("/core/contact/last_match"); | |
84 | |
85 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
86 | |
87 ret = gtk_vbox_new(FALSE, 18); | |
88 gtk_container_set_border_width(GTK_CONTAINER(ret), 12); | |
89 | |
90 frame = gaim_gtk_make_frame(ret, _("Point values to use when...")); | |
91 | |
92 vbox = gtk_vbox_new(FALSE, 5); | |
93 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
94 | |
95 /* Status Spinboxes */ | |
96 for (i = 0 ; statuses[i].id != NULL && statuses[i].description != NULL ; i++) | |
97 { | |
98 char *pref = g_strconcat("/core/status/scores/", statuses[i].id, NULL); | |
99 | |
100 hbox = gtk_hbox_new(FALSE, 5); | |
101 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
102 | |
103 label = gtk_label_new_with_mnemonic(_(statuses[i].description)); | |
104 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
105 gtk_size_group_add_widget(sg, label); | |
106 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
107 | |
108 adj = gtk_adjustment_new(gaim_prefs_get_int(pref), -500, 500, 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), pref); | |
111 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0); | |
112 | |
113 g_free(pref); | |
114 } | |
115 | |
116 /* Explanation */ | |
117 label = gtk_label_new(NULL); | |
118 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")); | |
119 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); | |
120 | |
121 /* Last match */ | |
122 hbox = gtk_hbox_new(FALSE, 5); | |
123 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
124 | |
125 check = gtk_check_button_new_with_label(_("Use last buddy when scores are equal")); | |
126 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), last_match); | |
127 g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(pref_update), "/core/contact/last_match"); | |
128 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0); | |
129 | |
130 frame = gaim_gtk_make_frame(ret, _("Point values to use for account...")); | |
131 | |
132 vbox = gtk_vbox_new(FALSE, 5); | |
133 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
134 | |
135 /* Account */ | |
136 hbox = gtk_hbox_new(FALSE, 5); | |
137 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
138 | |
139 /* make this here so I can use it in the option menu callback, we'll | |
140 * actually set it up later */ | |
141 adj = gtk_adjustment_new(0, -500, 500, 1, 1, 1); | |
142 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0); | |
143 | |
144 optmenu = gaim_gtk_account_option_menu_new(NULL, TRUE, | |
145 G_CALLBACK(select_account), | |
146 NULL, spin); | |
147 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0); | |
148 | |
149 /* this is where we set up the spin button we made above */ | |
150 account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))))), | |
151 "account"); | |
152 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | |
153 (gdouble)gaim_account_get_int(account, "score", 0)); | |
154 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj)); | |
155 g_signal_connect(G_OBJECT(spin), "value-changed", | |
156 G_CALLBACK(account_update), optmenu); | |
157 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0); | |
158 | |
159 gtk_widget_show_all(ret); | |
160 | |
161 return ret; | |
162 } | |
163 | |
164 static GaimGtkPluginUiInfo ui_info = | |
165 { | |
166 get_config_frame, | |
167 0 /* page_num (Reserved) */ | |
168 }; | |
169 | |
170 static GaimPluginInfo info = | |
171 { | |
172 GAIM_PLUGIN_MAGIC, | |
173 GAIM_MAJOR_VERSION, | |
174 GAIM_MINOR_VERSION, | |
175 GAIM_PLUGIN_STANDARD, /**< type */ | |
176 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
177 0, /**< flags */ | |
178 NULL, /**< dependencies */ | |
179 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
180 | |
181 CONTACT_PRIORITY_PLUGIN_ID, /**< id */ | |
182 N_("Contact Priority"), /**< name */ | |
183 VERSION, /**< version */ | |
184 /**< summary */ | |
185 N_("Allows for controlling the values associated with different buddy states."), | |
186 /**< description */ | |
187 N_("Allows for changing the point values of idle/away/offline states for buddies in contact priority computations."), | |
188 "Etan Reisner <deryni@eden.rutgers.edu>", /**< author */ | |
189 GAIM_WEBSITE, /**< homepage */ | |
190 | |
191 NULL, /**< load */ | |
192 NULL, /**< unload */ | |
193 NULL, /**< destroy */ | |
194 &ui_info, /**< ui_info */ | |
195 NULL, /**< extra_info */ | |
196 NULL, /**< prefs_info */ | |
197 NULL /**< actions */ | |
198 }; | |
199 | |
200 static void | |
201 init_plugin(GaimPlugin *plugin) | |
202 { | |
203 } | |
204 | |
205 GAIM_INIT_PLUGIN(contactpriority, init_plugin, info) |