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.
23 #include "gtk3compat.h"
24 #include "gtkplugin.h"
29 #define CONTACT_PRIORITY_PLUGIN_ID "gtk-contact-priority"
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));
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
)));
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
59 const char *description
;
62 { "idle", N_("Buddy is idle") },
63 { "away", N_("Buddy is away") },
64 { "extended_away", N_("Buddy is \"extended\" away") },
67 { "mobile", N_("Buddy is mobile") },
69 { "offline", N_("Buddy is offline") },
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
;
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);
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);
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
);
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
),
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
);
167 static PidginPluginInfo
*
168 plugin_query(GError
**error
)
170 const gchar
* const authors
[] = {
171 "Etan Reisner <deryni@eden.rutgers.edu>",
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."),
183 "website", PURPLE_WEBSITE
,
184 "abi-version", PURPLE_ABI_VERSION
,
185 "gtk-config-frame-cb", get_config_frame
,
191 plugin_load(PurplePlugin
*plugin
, GError
**error
)
197 plugin_unload(PurplePlugin
*plugin
, GError
**error
)
202 PURPLE_PLUGIN_INIT(contactpriority
, plugin_query
, plugin_load
, plugin_unload
);