7421
+ ��膩��� 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
9821
+ ��膩��� 21 #include "internal.h"
+ ��膩��� 22 #include "gtkgaim.h"
7421
+ ��膩��� 23 #include "gtkplugin.h"
+ ��膩��� 24 #include "gtkutils.h"
+ ��膩��� 25 #include "prefs.h"
9954
+ ��膩��� 26 #include "version.h"
7421
+ ��膩��� 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, gpointer data)
+ ��膩��� 48 {
+ ��膩��� 49 gchar pref[256];
+ ��膩��� 50
+ ��膩��� 51 g_snprintf(pref, sizeof(pref), "/core/contact/%s", (gchar *)data);
+ ��膩��� 52
+ ��膩��� 53 if (gaim_prefs_get_type(pref) == GAIM_PREF_INT)
+ ��膩��� 54 gaim_prefs_set_int(pref, gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)));
+ ��膩��� 55 if (gaim_prefs_get_type(pref) == GAIM_PREF_BOOLEAN)
+ ��膩��� 56 gaim_prefs_set_bool(pref, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)));
+ ��膩��� 57 }
+ ��膩��� 58
+ ��膩��� 59 static GtkWidget *
+ ��膩��� 60 get_config_frame(GaimPlugin *plugin)
+ ��膩��� 61 {
+ ��膩��� 62 GtkWidget *ret = NULL, *hbox = NULL, *frame = NULL, *vbox = NULL;
+ ��膩��� 63 GtkWidget *label = NULL, *spin = NULL, *check = NULL;
+ ��膩��� 64 GtkWidget *optmenu = NULL;
+ ��膩��� 65 GtkObject *adj = NULL;
+ ��膩��� 66 GtkSizeGroup *sg = NULL;
+ ��膩��� 67 GaimAccount *account = NULL;
+ ��膩��� 68 /*
+ ��膩��� 69 GList *accounts = NULL;
+ ��膩��� 70 */
+ ��膩��� 71 int offline = gaim_prefs_get_int("/core/contact/offline_score");
+ ��膩��� 72 int away = gaim_prefs_get_int("/core/contact/away_score");
+ ��膩��� 73 int idle = gaim_prefs_get_int("/core/contact/idle_score");
+ ��膩��� 74 /*
+ ��膩��� 75 int score;
+ ��膩��� 76 */
+ ��膩��� 77 gboolean last_match = gaim_prefs_get_bool("/core/contact/last_match");
+ ��膩��� 78
+ ��膩��� 79 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+ ��膩��� 80
+ ��膩��� 81 ret = gtk_vbox_new(FALSE, 18);
+ ��膩��� 82 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
+ ��膩��� 83
+ ��膩��� 84 frame = gaim_gtk_make_frame(ret, _("Point values to use when..."));
+ ��膩��� 85
+ ��膩��� 86 vbox = gtk_vbox_new(FALSE, 5);
+ ��膩��� 87 gtk_container_add(GTK_CONTAINER(frame), vbox);
+ ��膩��� 88
+ ��膩��� 89 /* Offline */
+ ��膩��� 90 hbox = gtk_hbox_new(FALSE, 5);
+ ��膩��� 91 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ ��膩��� 92
+ ��膩��� 93 label = gtk_label_new_with_mnemonic(_("Buddy is offline:"));
+ ��膩��� 94 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ ��膩��� 95 gtk_size_group_add_widget(sg, label);
7439
+ ��膩��� 96 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
7421
+ ��膩��� 97
+ ��膩��� 98 adj = gtk_adjustment_new(offline, -20, 20, 1, 1, 1);
+ ��膩��� 99 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
+ ��膩��� 100 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "offline_score");
+ ��膩��� 101 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
+ ��膩��� 102
+ ��膩��� 103 /* Away */
+ ��膩��� 104 hbox = gtk_hbox_new(FALSE, 5);
+ ��膩��� 105 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ ��膩��� 106
+ ��膩��� 107 label = gtk_label_new_with_mnemonic(_("Buddy is away:"));
+ ��膩��� 108 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ ��膩��� 109 gtk_size_group_add_widget(sg, label);
7439
+ ��膩��� 110 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
7421
+ ��膩��� 111
+ ��膩��� 112 adj = gtk_adjustment_new(away, -20, 20, 1, 1, 1);
+ ��膩��� 113 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
+ ��膩��� 114 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "away_score");
+ ��膩��� 115 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
+ ��膩��� 116
+ ��膩��� 117 /* Idle */
+ ��膩��� 118 hbox = gtk_hbox_new(FALSE, 5);
+ ��膩��� 119 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ ��膩��� 120
+ ��膩��� 121 label = gtk_label_new_with_mnemonic(_("Buddy is idle:"));
+ ��膩��� 122 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+ ��膩��� 123 gtk_size_group_add_widget(sg, label);
7439
+ ��膩��� 124 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
7421
+ ��膩��� 125
+ ��膩��� 126 adj = gtk_adjustment_new(idle, -20, 20, 1, 1, 1);
+ ��膩��� 127 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
+ ��膩��� 128 g_signal_connect(G_OBJECT(spin), "value-changed", G_CALLBACK(pref_update), "idle_score");
+ ��膩��� 129 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
+ ��膩��� 130
+ ��膩��� 131 /* Last match */
+ ��膩��� 132 hbox = gtk_hbox_new(FALSE, 5);
+ ��膩��� 133 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ ��膩��� 134
+ ��膩��� 135 check = gtk_check_button_new_with_label(_("Use last matching buddy"));
+ ��膩��� 136 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), last_match);
+ ��膩��� 137 g_signal_connect(G_OBJECT(check), "toggled", G_CALLBACK(pref_update), "last_match");
+ ��膩��� 138 gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
+ ��膩��� 139
+ ��膩��� 140 /* Explanation */
10729
+ ��膩��� 141 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) will use what used to be\nthe built-in order: active, idle, away, away + idle, offline."));
7421
+ ��膩��� 142 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ ��膩��� 143
10729
+ ��膩��� 144 frame = gaim_gtk_make_frame(ret, _("Point values to use for account..."));
7421
+ ��膩��� 145
+ ��膩��� 146 vbox = gtk_vbox_new(FALSE, 5);
+ ��膩��� 147 gtk_container_add(GTK_CONTAINER(frame), vbox);
+ ��膩��� 148
+ ��膩��� 149 /* Account */
+ ��膩��� 150 hbox = gtk_hbox_new(FALSE, 5);
+ ��膩��� 151 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ ��膩��� 152
+ ��膩��� 153 /* make this here so I can use it in the option menu callback, we'll
+ ��膩��� 154 * actually set it up later */
+ ��膩��� 155 adj = gtk_adjustment_new(0, -20, 20, 1, 1, 1);
+ ��膩��� 156 spin = gtk_spin_button_new((GtkAdjustment *)adj, 1, 0);
+ ��膩��� 157
+ ��膩��� 158 optmenu = gaim_gtk_account_option_menu_new(NULL, TRUE,
+ ��膩��� 159 G_CALLBACK(select_account),
+ ��膩��� 160 NULL, spin);
+ ��膩��� 161 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
+ ��膩��� 162
+ ��膩��� 163 /* this is where we set up the spin button we made above */
+ ��膩��� 164 account = g_object_get_data(G_OBJECT(gtk_menu_get_active(GTK_MENU(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu))))),
+ ��膩��� 165 "account");
+ ��膩��� 166 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),
+ ��膩��� 167 (gdouble)gaim_account_get_int(account, "score", 0));
+ ��膩��� 168 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(spin), GTK_ADJUSTMENT(adj));
+ ��膩��� 169 g_signal_connect(G_OBJECT(spin), "value-changed",
+ ��膩��� 170 G_CALLBACK(account_update), optmenu);
+ ��膩��� 171 gtk_box_pack_start(GTK_BOX(hbox), spin, FALSE, FALSE, 0);
+ ��膩��� 172
+ ��膩��� 173 gtk_widget_show_all(ret);
+ ��膩��� 174
+ ��膩��� 175 return ret;
+ ��膩��� 176 }
+ ��膩��� 177
+ ��膩��� 178 static GaimGtkPluginUiInfo ui_info =
+ ��膩��� 179 {
+ ��膩��� 180 get_config_frame
+ ��膩��� 181 };
+ ��膩��� 182
+ ��膩��� 183 static GaimPluginInfo info =
+ ��膩��� 184 {
9954
+ ��膩��� 185 GAIM_PLUGIN_MAGIC,
+ ��膩��� 186 GAIM_MAJOR_VERSION,
+ ��膩��� 187 GAIM_MINOR_VERSION,
7421
+ ��膩��� 188 GAIM_PLUGIN_STANDARD, /**< type */
+ ��膩��� 189 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
+ ��膩��� 190 0, /**< flags */
+ ��膩��� 191 NULL, /**< dependencies */
+ ��膩��� 192 GAIM_PRIORITY_DEFAULT, /**< priority */
+ ��膩��� 193
+ ��膩��� 194 CONTACT_PRIORITY_PLUGIN_ID, /**< id */
+ ��膩��� 195 N_("Contact Priority"), /**< name */
+ ��膩��� 196 VERSION, /**< version */
+ ��膩��� 197 /**< summary */
+ ��膩��� 198 N_("Allows for controlling the values associated with different buddy states."),
+ ��膩��� 199 /**< description */
+ ��膩��� 200 N_("Allows for changing the point values of idle/away/offline states for buddies in contact priority computations."),
+ ��膩��� 201 "Etan Reisner <deryni@eden.rutgers.edu>", /**< author */
+ ��膩��� 202 GAIM_WEBSITE, /**< homepage */
+ ��膩��� 203
+ ��膩��� 204 NULL, /**< load */
+ ��膩��� 205 NULL, /**< unload */
+ ��膩��� 206 NULL, /**< destroy */
+ ��膩��� 207 &ui_info, /**< ui_info */
+ ��膩��� 208 NULL /**< extra_info */
+ ��膩��� 209 };
+ ��膩��� 210
+ ��膩��� 211 static void
+ ��膩��� 212 init_plugin(GaimPlugin *plugin)
+ ��膩��� 213 {
+ ��膩��� 214 }
+ ��膩��� 215
+ ��膩��� 216 GAIM_INIT_PLUGIN(contactpriority, init_plugin, info)