Sat, 03 Feb 2007 08:45:32 +0000
gtkutils changes
| 15231 | 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" | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
23 | #define PLUGIN_NAME N_("Conversation Colors") |
| 15231 | 24 | #define PLUGIN_STATIC_NAME "Conversation Colors" |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
25 | #define PLUGIN_SUMMARY N_("Customize colors in the conversation window") |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
26 | #define PLUGIN_DESCRIPTION N_("Customize colors in the conversation window") |
| 15231 | 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 | ||
| 34 | /* Gaim headers */ | |
| 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 | { | |
| 77 | GaimMessageFlags flag; | |
| 78 | char *prefix; | |
| 79 | const char *text; | |
| 80 | } formats[] = | |
| 81 | { | |
| 82 | {GAIM_MESSAGE_ERROR, PREF_ERROR, N_("Error Messages")}, | |
| 83 | {GAIM_MESSAGE_NICK, PREF_NICK, N_("Highlighted Messages")}, | |
| 84 | {GAIM_MESSAGE_SYSTEM, PREF_SYSTEM, N_("System Messages")}, | |
| 85 | {GAIM_MESSAGE_SEND, PREF_SEND, N_("Sent Messages")}, | |
| 86 | {GAIM_MESSAGE_RECV, PREF_RECV, N_("Received Messages")}, | |
| 87 | {0, NULL, NULL} | |
| 88 | }; | |
| 89 | ||
| 90 | static gboolean | |
| 91 | displaying_msg(GaimAccount *account, const char *who, char **displaying, | |
| 92 | GaimConversation *conv, GaimMessageFlags flags) | |
| 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 | ||
| 107 | if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM && | |
| 108 | !gaim_prefs_get_bool(PREF_IMS)) || | |
| 109 | (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
| 110 | !gaim_prefs_get_bool(PREF_CHATS))) | |
| 111 | return FALSE; | |
| 112 | ||
| 113 | g_snprintf(tmp, sizeof(tmp), "%s/color", formats[i].prefix); | |
| 114 | color = gaim_prefs_get_string(tmp); | |
| 115 | ||
| 116 | g_snprintf(tmp, sizeof(tmp), "%s/format", formats[i].prefix); | |
| 117 | f = gaim_prefs_get_int(tmp); | |
| 118 | bold = (f & FONT_BOLD); | |
| 119 | italic = (f & FONT_ITALIC); | |
| 120 | underline = (f & FONT_UNDERLINE); | |
| 121 | ||
| 122 | if (gaim_prefs_get_bool(PREF_IGNORE)) | |
| 123 | { | |
| 124 | t = *displaying; | |
| 125 | *displaying = gaim_markup_strip_html(t); | |
| 126 | g_free(t); | |
|
15488
d3de0d1f569d
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15481
diff
changeset
|
127 | |
|
d3de0d1f569d
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15481
diff
changeset
|
128 | t = *displaying; |
|
d3de0d1f569d
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15481
diff
changeset
|
129 | *displaying = g_markup_escape_text(t, -1); |
|
d3de0d1f569d
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15481
diff
changeset
|
130 | g_free(t); |
|
d3de0d1f569d
Fix bug #1645435. Thanks to Dennis Ristuccia (more commonly known as EvilDennisR) for helping me find the bug.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15481
diff
changeset
|
131 | |
|
15481
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
132 | /* Restore the links */ |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
133 | t = *displaying; |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
134 | *displaying = gaim_markup_linkify(t); |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
135 | g_free(t); |
| 15231 | 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 | |
| 161 | plugin_load(GaimPlugin *plugin) | |
| 162 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
163 | gaim_signal_connect(pidgin_conversations_get_handle(), |
| 15231 | 164 | "displaying-im-msg", plugin, |
| 165 | GAIM_CALLBACK(displaying_msg), NULL); | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
166 | gaim_signal_connect(pidgin_conversations_get_handle(), |
| 15231 | 167 | "displaying-chat-msg", plugin, |
| 168 | GAIM_CALLBACK(displaying_msg), NULL); | |
| 169 | return TRUE; | |
| 170 | } | |
| 171 | ||
| 172 | static gboolean | |
| 173 | plugin_unload(GaimPlugin *plugin) | |
| 174 | { | |
| 175 | return TRUE; | |
| 176 | } | |
| 177 | ||
| 178 | /* Ripped from GaimRC */ | |
| 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 | ||
| 196 | gaim_prefs_set_string(tmp, colorstr); | |
| 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); | |
| 216 | if (gdk_color_parse(gaim_prefs_get_string(tmp), &color)) | |
| 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); | |
| 232 | f = gaim_prefs_get_int(tmp); | |
| 233 | f ^= format; | |
| 234 | gaim_prefs_set_int(tmp, f); | |
| 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 * | |
| 256 | get_config_frame(GaimPlugin *plugin) | |
| 257 | { | |
| 258 | GtkWidget *ret; | |
| 259 | GtkWidget *frame; | |
| 260 | int i; | |
| 261 | ||
| 262 | ret = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); | |
| 263 | gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER); | |
| 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); | |
| 272 | f = gaim_prefs_get_int(tmp); | |
| 273 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
274 | frame = pidgin_make_frame(ret, _(formats[i].text)); |
| 15231 | 275 | vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
| 276 | gtk_box_pack_start(GTK_BOX(frame), vbox, FALSE, FALSE, 0); | |
| 277 | ||
| 278 | hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
| 279 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 280 | ||
| 15568 | 281 | button = pidgin_pixbuf_button_from_stock(" Color", GTK_STOCK_SELECT_COLOR, |
| 282 | PIDGIN_BUTTON_HORIZONTAL); | |
| 15231 | 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 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
309 | frame = pidgin_make_frame(ret, _("General")); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
310 | pidgin_prefs_checkbox(_("Ignore incoming format"), PREF_IGNORE, frame); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
311 | pidgin_prefs_checkbox(_("Apply in Chats"), PREF_CHATS, frame); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
312 | pidgin_prefs_checkbox(_("Apply in IMs"), PREF_IMS, frame); |
| 15231 | 313 | |
| 314 | gtk_widget_show_all(ret); | |
| 315 | return ret; | |
| 316 | } | |
| 317 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
318 | static PidginPluginUiInfo ui_info = |
| 15231 | 319 | { |
| 320 | get_config_frame, | |
| 321 | 0, | |
| 322 | }; | |
| 323 | ||
| 324 | static GaimPluginInfo info = | |
| 325 | { | |
| 326 | GAIM_PLUGIN_MAGIC, /* Magic */ | |
| 327 | GAIM_MAJOR_VERSION, /* Gaim Major Version */ | |
| 328 | GAIM_MINOR_VERSION, /* Gaim Minor Version */ | |
| 329 | GAIM_PLUGIN_STANDARD, /* plugin type */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15488
diff
changeset
|
330 | PIDGIN_PLUGIN_TYPE, /* ui requirement */ |
| 15231 | 331 | 0, /* flags */ |
| 332 | NULL, /* dependencies */ | |
| 333 | GAIM_PRIORITY_DEFAULT, /* priority */ | |
| 334 | ||
| 335 | PLUGIN_ID, /* plugin id */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
336 | PLUGIN_NAME, /* name */ |
| 15231 | 337 | VERSION, /* version */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
338 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
339 | PLUGIN_DESCRIPTION, /* description */ |
| 15231 | 340 | PLUGIN_AUTHOR, /* author */ |
| 341 | GAIM_WEBSITE, /* website */ | |
| 342 | ||
| 343 | plugin_load, /* load */ | |
| 344 | plugin_unload, /* unload */ | |
| 345 | NULL, /* destroy */ | |
| 346 | ||
| 347 | &ui_info, /* ui_info */ | |
| 348 | NULL, /* extra_info */ | |
| 349 | NULL, /* prefs_info */ | |
| 350 | NULL /* actions */ | |
| 351 | }; | |
| 352 | ||
| 353 | static void | |
| 354 | init_plugin(GaimPlugin *plugin) | |
| 355 | { | |
| 356 | gaim_prefs_add_none(PREF_PREFIX); | |
| 357 | ||
| 358 | gaim_prefs_add_bool(PREF_IGNORE, TRUE); | |
| 359 | gaim_prefs_add_bool(PREF_CHATS, TRUE); | |
| 360 | gaim_prefs_add_bool(PREF_IMS, TRUE); | |
| 361 | ||
| 362 | gaim_prefs_add_none(PREF_SEND); | |
| 363 | gaim_prefs_add_none(PREF_RECV); | |
| 364 | gaim_prefs_add_none(PREF_SYSTEM); | |
| 365 | gaim_prefs_add_none(PREF_ERROR); | |
| 366 | gaim_prefs_add_none(PREF_NICK); | |
| 367 | ||
| 368 | gaim_prefs_add_string(PREF_SEND_C, "#909090"); | |
| 369 | gaim_prefs_add_string(PREF_RECV_C, "#000000"); | |
| 370 | gaim_prefs_add_string(PREF_SYSTEM_C, "#50a050"); | |
| 371 | gaim_prefs_add_string(PREF_ERROR_C, "#ff0000"); | |
| 372 | gaim_prefs_add_string(PREF_NICK_C, "#0000dd"); | |
| 373 | ||
| 374 | gaim_prefs_add_int(PREF_SEND_F, 0); | |
| 375 | gaim_prefs_add_int(PREF_RECV_F, 0); | |
| 376 | gaim_prefs_add_int(PREF_SYSTEM_F, FONT_ITALIC); | |
| 377 | gaim_prefs_add_int(PREF_ERROR_F, FONT_BOLD | FONT_UNDERLINE); | |
| 378 | gaim_prefs_add_int(PREF_NICK_F, FONT_BOLD); | |
| 379 | } | |
| 380 | ||
| 381 | GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |