Replace strcmp() with purple_strequal()
[pidgin-git.git] / pidgin / plugins / extplacement.c
blob494e0849d26ef6f75887b99e4b9e107231809f02
1 /*
2 * Extra conversation placement options for Purple
4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA.
23 #include "internal.h"
24 #include "pidgin.h"
25 #include "conversation.h"
26 #include "version.h"
27 #include "gtkplugin.h"
28 #include "gtkconv.h"
29 #include "gtkconvwin.h"
31 static void
32 conv_placement_by_number(PidginConversation *conv)
34 PidginWindow *win = NULL;
35 GList *wins = NULL;
37 if (purple_prefs_get_bool("/plugins/gtk/extplacement/placement_number_separate"))
38 win = pidgin_conv_window_last_with_type(purple_conversation_get_type(conv->active_conv));
39 else if ((wins = pidgin_conv_windows_get_list()) != NULL)
40 win = g_list_last(wins)->data;
42 if (win == NULL) {
43 win = pidgin_conv_window_new();
45 pidgin_conv_window_add_gtkconv(win, conv);
46 pidgin_conv_window_show(win);
47 } else {
48 int max_count = purple_prefs_get_int("/plugins/gtk/extplacement/placement_number");
49 int count = pidgin_conv_window_get_gtkconv_count(win);
51 if (count < max_count)
52 pidgin_conv_window_add_gtkconv(win, conv);
53 else {
54 GList *l = NULL;
56 for (l = pidgin_conv_windows_get_list(); l != NULL; l = l->next) {
57 win = l->data;
59 if (purple_prefs_get_bool("/plugins/gtk/extplacement/placement_number_separate") &&
60 purple_conversation_get_type(pidgin_conv_window_get_active_conversation(win)) != purple_conversation_get_type(conv->active_conv))
61 continue;
63 count = pidgin_conv_window_get_gtkconv_count(win);
64 if (count < max_count) {
65 pidgin_conv_window_add_gtkconv(win, conv);
66 return;
69 win = pidgin_conv_window_new();
71 pidgin_conv_window_add_gtkconv(win, conv);
72 pidgin_conv_window_show(win);
77 static gboolean
78 plugin_load(PurplePlugin *plugin)
80 pidgin_conv_placement_add_fnc("number", _("By conversation count"),
81 &conv_placement_by_number);
82 purple_prefs_trigger_callback(PIDGIN_PREFS_ROOT "/conversations/placement");
83 return TRUE;
86 static gboolean
87 plugin_unload(PurplePlugin *plugin)
89 pidgin_conv_placement_remove_fnc("number");
90 purple_prefs_trigger_callback(PIDGIN_PREFS_ROOT "/conversations/placement");
91 return TRUE;
94 static PurplePluginPrefFrame *
95 get_plugin_pref_frame(PurplePlugin *plugin) {
96 PurplePluginPrefFrame *frame;
97 PurplePluginPref *ppref;
99 frame = purple_plugin_pref_frame_new();
101 ppref = purple_plugin_pref_new_with_label(_("Conversation Placement"));
102 purple_plugin_pref_frame_add(frame, ppref);
104 /* Translators: "New conversations" should match the text in the preferences dialog and "By conversation count" should be the same text used above */
105 ppref = purple_plugin_pref_new_with_label(_("Note: The preference for \"New conversations\" must be set to \"By conversation count\"."));
106 purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_INFO);
107 purple_plugin_pref_frame_add(frame, ppref);
109 ppref = purple_plugin_pref_new_with_name_and_label(
110 "/plugins/gtk/extplacement/placement_number",
111 _("Number of conversations per window"));
112 purple_plugin_pref_set_bounds(ppref, 1, 50);
113 purple_plugin_pref_frame_add(frame, ppref);
115 ppref = purple_plugin_pref_new_with_name_and_label(
116 "/plugins/gtk/extplacement/placement_number_separate",
117 _("Separate IM and Chat windows when placing by number"));
118 purple_plugin_pref_frame_add(frame, ppref);
120 return frame;
123 static PurplePluginUiInfo prefs_info = {
124 get_plugin_pref_frame,
125 0, /* page_num (Reserved) */
126 NULL, /* frame (Reserved) */
128 /* padding */
129 NULL,
130 NULL,
131 NULL,
132 NULL
135 static PurplePluginInfo info =
137 PURPLE_PLUGIN_MAGIC,
138 PURPLE_MAJOR_VERSION,
139 PURPLE_MINOR_VERSION,
140 PURPLE_PLUGIN_STANDARD, /**< type */
141 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
142 0, /**< flags */
143 NULL, /**< dependencies */
144 PURPLE_PRIORITY_DEFAULT, /**< priority */
145 "gtk-extplacement", /**< id */
146 N_("ExtPlacement"), /**< name */
147 DISPLAY_VERSION, /**< version */
148 N_("Extra conversation placement options."), /**< summary */
149 /** description */
150 N_("Restrict the number of conversations per windows,"
151 " optionally separating IMs and Chats"),
152 "Stu Tomlinson <stu@nosnilmot.com>", /**< author */
153 PURPLE_WEBSITE, /**< homepage */
154 plugin_load, /**< load */
155 plugin_unload, /**< unload */
156 NULL, /**< destroy */
157 NULL, /**< ui_info */
158 NULL, /**< extra_info */
159 &prefs_info, /**< prefs_info */
160 NULL, /**< actions */
162 /* padding */
163 NULL,
164 NULL,
165 NULL,
166 NULL
169 static void
170 init_plugin(PurplePlugin *plugin)
172 purple_prefs_add_none("/plugins/gtk/extplacement");
173 purple_prefs_add_int("/plugins/gtk/extplacement/placement_number", 4);
174 purple_prefs_add_bool("/plugins/gtk/extplacement/placement_number_separate", FALSE);
177 PURPLE_INIT_PLUGIN(extplacement, init_plugin, info)