15374
|
1 /*
|
|
2 * Conversation Colors
|
|
3 * Copyright (C) 2006
|
|
4 *
|
|
5 * This program is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU General Public License as
|
|
7 * published by the Free Software Foundation; either version 2 of the
|
|
8 * License, or (at your option) any later version.
|
|
9 *
|
|
10 * This program is distributed in the hope that it will be useful, but
|
|
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License
|
|
16 * along with this program; if not, write to the Free Software
|
|
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
18 * 02111-1307, USA.
|
|
19 */
|
|
20 #include "internal.h"
|
|
21
|
|
22 #define PLUGIN_ID "gtk-plugin_pack-convcolors"
|
|
23 #define PLUGIN_NAME N_("Conversation Colors")
|
|
24 #define PLUGIN_STATIC_NAME "Conversation Colors"
|
|
25 #define PLUGIN_SUMMARY N_("Customize colors in the conversation window")
|
|
26 #define PLUGIN_DESCRIPTION N_("Customize colors in the conversation window")
|
|
27 #define PLUGIN_AUTHOR "Sadrul H Chowdhury <sadrul@users.sourceforge.net>"
|
|
28
|
|
29 /* System headers */
|
|
30 #include <gdk/gdk.h>
|
|
31 #include <glib.h>
|
|
32 #include <gtk/gtk.h>
|
|
33
|
15823
|
34 /* Purple headers */
|
15374
|
35 #include <gtkplugin.h>
|
|
36 #include <version.h>
|
|
37
|
|
38 #include <conversation.h>
|
|
39 #include <gtkconv.h>
|
|
40 #include <gtkprefs.h>
|
|
41 #include <gtkutils.h>
|
|
42
|
|
43 #define PREF_PREFIX "/plugins/gtk/" PLUGIN_ID
|
|
44 #define PREF_IGNORE PREF_PREFIX "/ignore_incoming"
|
|
45 #define PREF_CHATS PREF_PREFIX "/chats"
|
|
46 #define PREF_IMS PREF_PREFIX "/ims"
|
|
47
|
|
48 #define PREF_SEND PREF_PREFIX "/send"
|
|
49 #define PREF_SEND_C PREF_SEND "/color"
|
|
50 #define PREF_SEND_F PREF_SEND "/format"
|
|
51
|
|
52 #define PREF_RECV PREF_PREFIX "/recv"
|
|
53 #define PREF_RECV_C PREF_RECV "/color"
|
|
54 #define PREF_RECV_F PREF_RECV "/format"
|
|
55
|
|
56 #define PREF_SYSTEM PREF_PREFIX "/system"
|
|
57 #define PREF_SYSTEM_C PREF_SYSTEM "/color"
|
|
58 #define PREF_SYSTEM_F PREF_SYSTEM "/format"
|
|
59
|
|
60 #define PREF_ERROR PREF_PREFIX "/error"
|
|
61 #define PREF_ERROR_C PREF_ERROR "/color"
|
|
62 #define PREF_ERROR_F PREF_ERROR "/format"
|
|
63
|
|
64 #define PREF_NICK PREF_PREFIX "/nick"
|
|
65 #define PREF_NICK_C PREF_NICK "/color"
|
|
66 #define PREF_NICK_F PREF_NICK "/format"
|
|
67
|
|
68 enum
|
|
69 {
|
|
70 FONT_BOLD = 1 << 0,
|
|
71 FONT_ITALIC = 1 << 1,
|
|
72 FONT_UNDERLINE = 1 << 2
|
|
73 };
|
|
74
|
|
75 struct
|
|
76 {
|
15823
|
77 PurpleMessageFlags flag;
|
15374
|
78 char *prefix;
|
|
79 const char *text;
|
|
80 } formats[] =
|
|
81 {
|
15823
|
82 {PURPLE_MESSAGE_ERROR, PREF_ERROR, N_("Error Messages")},
|
|
83 {PURPLE_MESSAGE_NICK, PREF_NICK, N_("Highlighted Messages")},
|
|
84 {PURPLE_MESSAGE_SYSTEM, PREF_SYSTEM, N_("System Messages")},
|
|
85 {PURPLE_MESSAGE_SEND, PREF_SEND, N_("Sent Messages")},
|
|
86 {PURPLE_MESSAGE_RECV, PREF_RECV, N_("Received Messages")},
|
15374
|
87 {0, NULL, NULL}
|
|
88 };
|
|
89
|
|
90 static gboolean
|
15823
|
91 displaying_msg(PurpleAccount *account, const char *who, char **displaying,
|
|
92 PurpleConversation *conv, PurpleMessageFlags flags)
|
15374
|
93 {
|
|
94 int i;
|
|
95 char tmp[128], *t;
|
|
96 gboolean bold, italic, underline;
|
|
97 int f;
|
|
98 const char *color;
|
|
99
|
|
100 for (i = 0; formats[i].prefix; i++)
|
|
101 if (flags & formats[i].flag)
|
|
102 break;
|
|
103
|
|
104 if (!formats[i].prefix)
|
|
105 return FALSE;
|
|
106
|
15823
|
107 if ((purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM &&
|
|
108 !purple_prefs_get_bool(PREF_IMS)) ||
|
|
109 (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT &&
|
|
110 !purple_prefs_get_bool(PREF_CHATS)))
|
15374
|
111 return FALSE;
|
|
112
|
|
113 g_snprintf(tmp, sizeof(tmp), "%s/color", formats[i].prefix);
|
15823
|
114 color = purple_prefs_get_string(tmp);
|
15374
|
115
|
|
116 g_snprintf(tmp, sizeof(tmp), "%s/format", formats[i].prefix);
|
15823
|
117 f = purple_prefs_get_int(tmp);
|
15374
|
118 bold = (f & FONT_BOLD);
|
|
119 italic = (f & FONT_ITALIC);
|
|
120 underline = (f & FONT_UNDERLINE);
|
|
121
|
15823
|
122 if (purple_prefs_get_bool(PREF_IGNORE))
|
15374
|
123 {
|
|
124 t = *displaying;
|
15823
|
125 *displaying = purple_markup_strip_html(t);
|
15374
|
126 g_free(t);
|
15428
ce0cd7474b64
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
127
|
ce0cd7474b64
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
128 t = *displaying;
|
ce0cd7474b64
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
129 *displaying = g_markup_escape_text(t, -1);
|
ce0cd7474b64
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
130 g_free(t);
|
ce0cd7474b64
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
131
|
15420
|
132 /* Restore the links */
|
|
133 t = *displaying;
|
15823
|
134 *displaying = purple_markup_linkify(t);
|
15420
|
135 g_free(t);
|
15374
|
136 }
|
|
137
|
|
138 if (color && *color)
|
|
139 {
|
|
140 t = *displaying;
|
|
141 *displaying = g_strdup_printf("<FONT COLOR=\"%s\">%s</FONT>", color, t);
|
|
142 g_free(t);
|
|
143 }
|
|
144
|
|
145 t = *displaying;
|
|
146 *displaying = g_strdup_printf("%s%s%s%s%s%s%s",
|
|
147 bold ? "<B>" : "</B>",
|
|
148 italic ? "<I>" : "</I>",
|
|
149 underline ? "<U>" : "</U>",
|
|
150 t,
|
|
151 bold ? "</B>" : "<B>",
|
|
152 italic ? "</I>" : "<I>",
|
|
153 underline ? "</U>" : "<U>"
|
|
154 );
|
|
155 g_free(t);
|
|
156
|
|
157 return FALSE;
|
|
158 }
|
|
159
|
|
160 static gboolean
|
15823
|
161 plugin_load(PurplePlugin *plugin)
|
15374
|
162 {
|
15823
|
163 purple_signal_connect(pidgin_conversations_get_handle(),
|
15374
|
164 "displaying-im-msg", plugin,
|
15823
|
165 PURPLE_CALLBACK(displaying_msg), NULL);
|
|
166 purple_signal_connect(pidgin_conversations_get_handle(),
|
15374
|
167 "displaying-chat-msg", plugin,
|
15823
|
168 PURPLE_CALLBACK(displaying_msg), NULL);
|
15374
|
169 return TRUE;
|
|
170 }
|
|
171
|
|
172 static gboolean
|
15823
|
173 plugin_unload(PurplePlugin *plugin)
|
15374
|
174 {
|
|
175 return TRUE;
|
|
176 }
|
|
177
|
15823
|
178 /* Ripped from PurpleRC */
|
15374
|
179 static void
|
|
180 color_response(GtkDialog *color_dialog, gint response, const char *data)
|
|
181 {
|
|
182 if (response == GTK_RESPONSE_OK)
|
|
183 {
|
|
184 GtkWidget *colorsel = GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel;
|
|
185 GdkColor color;
|
|
186 char colorstr[8];
|
|
187 char tmp[128];
|
|
188
|
|
189 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), &color);
|
|
190
|
|
191 g_snprintf(colorstr, sizeof(colorstr), "#%02X%02X%02X",
|
|
192 color.red/256, color.green/256, color.blue/256);
|
|
193
|
|
194 g_snprintf(tmp, sizeof(tmp), "%s/color", data);
|
|
195
|
15823
|
196 purple_prefs_set_string(tmp, colorstr);
|
15374
|
197 }
|
|
198
|
|
199 gtk_widget_destroy(GTK_WIDGET(color_dialog));
|
|
200 }
|
|
201
|
|
202 static void
|
|
203 set_color(GtkWidget *widget, const char *data)
|
|
204 {
|
|
205 GtkWidget *color_dialog = NULL;
|
|
206 GdkColor color;
|
|
207 char title[128];
|
|
208 char tmp[128];
|
|
209
|
|
210 g_snprintf(title, sizeof(title), _("Select Color for %s"), _(data));
|
|
211 color_dialog = gtk_color_selection_dialog_new(title);
|
|
212 g_signal_connect(G_OBJECT(color_dialog), "response",
|
|
213 G_CALLBACK(color_response), (gpointer)data);
|
|
214
|
|
215 g_snprintf(tmp, sizeof(tmp), "%s/color", data);
|
15823
|
216 if (gdk_color_parse(purple_prefs_get_string(tmp), &color))
|
15374
|
217 {
|
|
218 gtk_color_selection_set_current_color(
|
|
219 GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color);
|
|
220 }
|
|
221
|
|
222 gtk_window_present(GTK_WINDOW(color_dialog));
|
|
223 }
|
|
224
|
|
225 static void
|
|
226 toggle_something(const char *prefix, int format)
|
|
227 {
|
|
228 int f;
|
|
229 char tmp[128];
|
|
230
|
|
231 g_snprintf(tmp, sizeof(tmp), "%s/format", prefix);
|
15823
|
232 f = purple_prefs_get_int(tmp);
|
15374
|
233 f ^= format;
|
15823
|
234 purple_prefs_set_int(tmp, f);
|
15374
|
235 }
|
|
236
|
|
237 static void
|
|
238 toggle_bold(GtkWidget *widget, gpointer data)
|
|
239 {
|
|
240 toggle_something(data, FONT_BOLD);
|
|
241 }
|
|
242
|
|
243 static void
|
|
244 toggle_italic(GtkWidget *widget, gpointer data)
|
|
245 {
|
|
246 toggle_something(data, FONT_ITALIC);
|
|
247 }
|
|
248
|
|
249 static void
|
|
250 toggle_underline(GtkWidget *widget, gpointer data)
|
|
251 {
|
|
252 toggle_something(data, FONT_UNDERLINE);
|
|
253 }
|
|
254
|
|
255 static GtkWidget *
|
15823
|
256 get_config_frame(PurplePlugin *plugin)
|
15374
|
257 {
|
|
258 GtkWidget *ret;
|
|
259 GtkWidget *frame;
|
|
260 int i;
|
|
261
|
15821
|
262 ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE);
|
|
263 gtk_container_set_border_width(GTK_CONTAINER(ret), PIDGIN_HIG_BORDER);
|
15374
|
264
|
|
265 for (i = 0; formats[i].prefix; i++)
|
|
266 {
|
|
267 char tmp[128];
|
|
268 int f;
|
|
269 GtkWidget *vbox, *hbox, *button;
|
|
270
|
|
271 g_snprintf(tmp, sizeof(tmp), "%s/format", formats[i].prefix);
|
15823
|
272 f = purple_prefs_get_int(tmp);
|
15374
|
273
|
15501
|
274 frame = pidgin_make_frame(ret, _(formats[i].text));
|
15821
|
275 vbox = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
|
15374
|
276 gtk_box_pack_start(GTK_BOX(frame), vbox, FALSE, FALSE, 0);
|
|
277
|
15821
|
278 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
|
15374
|
279 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
280
|
15507
|
281 button = pidgin_pixbuf_button_from_stock(" Color", GTK_STOCK_SELECT_COLOR,
|
|
282 PIDGIN_BUTTON_HORIZONTAL);
|
15374
|
283 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
284 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_color),
|
|
285 formats[i].prefix);
|
|
286
|
|
287 button = gtk_check_button_new_with_label(_("Bold"));
|
|
288 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
289 if (f & FONT_BOLD)
|
|
290 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
|
291 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toggle_bold),
|
|
292 formats[i].prefix);
|
|
293
|
|
294 button = gtk_check_button_new_with_label(_("Italic"));
|
|
295 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
296 if (f & FONT_ITALIC)
|
|
297 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
|
298 g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toggle_italic),
|
|
299 formats[i].prefix);
|
|
300
|
|
301 button = gtk_check_button_new_with_label(_("Underline"));
|
|
302 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
|
|
303 if (f & FONT_UNDERLINE)
|
|
304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
|
305 g_signal_connect(G_OBJECT(button), "clicked",
|
|
306 G_CALLBACK(toggle_underline), formats[i].prefix);
|
|
307 }
|
|
308
|
15501
|
309 frame = pidgin_make_frame(ret, _("General"));
|
|
310 pidgin_prefs_checkbox(_("Ignore incoming format"), PREF_IGNORE, frame);
|
|
311 pidgin_prefs_checkbox(_("Apply in Chats"), PREF_CHATS, frame);
|
|
312 pidgin_prefs_checkbox(_("Apply in IMs"), PREF_IMS, frame);
|
15374
|
313
|
|
314 gtk_widget_show_all(ret);
|
|
315 return ret;
|
|
316 }
|
|
317
|
15501
|
318 static PidginPluginUiInfo ui_info =
|
15374
|
319 {
|
|
320 get_config_frame,
|
|
321 0,
|
16678
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
322
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
323 /* padding */
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
324 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
325 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
326 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
327 NULL
|
15374
|
328 };
|
|
329
|
15823
|
330 static PurplePluginInfo info =
|
15374
|
331 {
|
15823
|
332 PURPLE_PLUGIN_MAGIC, /* Magic */
|
|
333 PURPLE_MAJOR_VERSION, /* Purple Major Version */
|
|
334 PURPLE_MINOR_VERSION, /* Purple Minor Version */
|
|
335 PURPLE_PLUGIN_STANDARD, /* plugin type */
|
15501
|
336 PIDGIN_PLUGIN_TYPE, /* ui requirement */
|
15374
|
337 0, /* flags */
|
|
338 NULL, /* dependencies */
|
15823
|
339 PURPLE_PRIORITY_DEFAULT, /* priority */
|
15374
|
340
|
|
341 PLUGIN_ID, /* plugin id */
|
|
342 PLUGIN_NAME, /* name */
|
|
343 VERSION, /* version */
|
|
344 PLUGIN_SUMMARY, /* summary */
|
|
345 PLUGIN_DESCRIPTION, /* description */
|
|
346 PLUGIN_AUTHOR, /* author */
|
15823
|
347 PURPLE_WEBSITE, /* website */
|
15374
|
348
|
|
349 plugin_load, /* load */
|
|
350 plugin_unload, /* unload */
|
|
351 NULL, /* destroy */
|
|
352
|
|
353 &ui_info, /* ui_info */
|
|
354 NULL, /* extra_info */
|
|
355 NULL, /* prefs_info */
|
16678
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
356 NULL, /* actions */
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
357
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
358 /* padding */
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
359 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
360 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
361 NULL,
|
3d41d0d7fb9b
Default plugins are done, for the release i'm not that concerned about plugins that do _NOT_ compile by default
Gary Kramlich <grim@reaperworld.com>
diff
changeset
|
362 NULL
|
15374
|
363 };
|
|
364
|
|
365 static void
|
15823
|
366 init_plugin(PurplePlugin *plugin)
|
15374
|
367 {
|
15823
|
368 purple_prefs_add_none(PREF_PREFIX);
|
15374
|
369
|
15823
|
370 purple_prefs_add_bool(PREF_IGNORE, TRUE);
|
|
371 purple_prefs_add_bool(PREF_CHATS, TRUE);
|
|
372 purple_prefs_add_bool(PREF_IMS, TRUE);
|
15374
|
373
|
15823
|
374 purple_prefs_add_none(PREF_SEND);
|
|
375 purple_prefs_add_none(PREF_RECV);
|
|
376 purple_prefs_add_none(PREF_SYSTEM);
|
|
377 purple_prefs_add_none(PREF_ERROR);
|
|
378 purple_prefs_add_none(PREF_NICK);
|
15374
|
379
|
15823
|
380 purple_prefs_add_string(PREF_SEND_C, "#909090");
|
|
381 purple_prefs_add_string(PREF_RECV_C, "#000000");
|
|
382 purple_prefs_add_string(PREF_SYSTEM_C, "#50a050");
|
|
383 purple_prefs_add_string(PREF_ERROR_C, "#ff0000");
|
|
384 purple_prefs_add_string(PREF_NICK_C, "#0000dd");
|
15374
|
385
|
15823
|
386 purple_prefs_add_int(PREF_SEND_F, 0);
|
|
387 purple_prefs_add_int(PREF_RECV_F, 0);
|
|
388 purple_prefs_add_int(PREF_SYSTEM_F, FONT_ITALIC);
|
|
389 purple_prefs_add_int(PREF_ERROR_F, FONT_BOLD | FONT_UNDERLINE);
|
|
390 purple_prefs_add_int(PREF_NICK_F, FONT_BOLD);
|
15374
|
391 }
|
|
392
|
15823
|
393 PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
|