Fri, 26 Jan 2007 03:53:15 +0000
Fix convcolors to not unlinkify the links.
| 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); | |
|
15481
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
127 | /* Restore the links */ |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
128 | t = *displaying; |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
129 | *displaying = gaim_markup_linkify(t); |
|
6e9da7b5bd5c
Fix convcolors to not unlinkify the links.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15435
diff
changeset
|
130 | g_free(t); |
| 15231 | 131 | } |
| 132 | ||
| 133 | if (color && *color) | |
| 134 | { | |
| 135 | t = *displaying; | |
| 136 | *displaying = g_strdup_printf("<FONT COLOR=\"%s\">%s</FONT>", color, t); | |
| 137 | g_free(t); | |
| 138 | } | |
| 139 | ||
| 140 | t = *displaying; | |
| 141 | *displaying = g_strdup_printf("%s%s%s%s%s%s%s", | |
| 142 | bold ? "<B>" : "</B>", | |
| 143 | italic ? "<I>" : "</I>", | |
| 144 | underline ? "<U>" : "</U>", | |
| 145 | t, | |
| 146 | bold ? "</B>" : "<B>", | |
| 147 | italic ? "</I>" : "<I>", | |
| 148 | underline ? "</U>" : "<U>" | |
| 149 | ); | |
| 150 | g_free(t); | |
| 151 | ||
| 152 | return FALSE; | |
| 153 | } | |
| 154 | ||
| 155 | static gboolean | |
| 156 | plugin_load(GaimPlugin *plugin) | |
| 157 | { | |
| 158 | gaim_signal_connect(gaim_gtk_conversations_get_handle(), | |
| 159 | "displaying-im-msg", plugin, | |
| 160 | GAIM_CALLBACK(displaying_msg), NULL); | |
| 161 | gaim_signal_connect(gaim_gtk_conversations_get_handle(), | |
| 162 | "displaying-chat-msg", plugin, | |
| 163 | GAIM_CALLBACK(displaying_msg), NULL); | |
| 164 | return TRUE; | |
| 165 | } | |
| 166 | ||
| 167 | static gboolean | |
| 168 | plugin_unload(GaimPlugin *plugin) | |
| 169 | { | |
| 170 | return TRUE; | |
| 171 | } | |
| 172 | ||
| 173 | /* Ripped from GaimRC */ | |
| 174 | static void | |
| 175 | color_response(GtkDialog *color_dialog, gint response, const char *data) | |
| 176 | { | |
| 177 | if (response == GTK_RESPONSE_OK) | |
| 178 | { | |
| 179 | GtkWidget *colorsel = GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel; | |
| 180 | GdkColor color; | |
| 181 | char colorstr[8]; | |
| 182 | char tmp[128]; | |
| 183 | ||
| 184 | gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), &color); | |
| 185 | ||
| 186 | g_snprintf(colorstr, sizeof(colorstr), "#%02X%02X%02X", | |
| 187 | color.red/256, color.green/256, color.blue/256); | |
| 188 | ||
| 189 | g_snprintf(tmp, sizeof(tmp), "%s/color", data); | |
| 190 | ||
| 191 | gaim_prefs_set_string(tmp, colorstr); | |
| 192 | } | |
| 193 | ||
| 194 | gtk_widget_destroy(GTK_WIDGET(color_dialog)); | |
| 195 | } | |
| 196 | ||
| 197 | static void | |
| 198 | set_color(GtkWidget *widget, const char *data) | |
| 199 | { | |
| 200 | GtkWidget *color_dialog = NULL; | |
| 201 | GdkColor color; | |
| 202 | char title[128]; | |
| 203 | char tmp[128]; | |
| 204 | ||
| 205 | g_snprintf(title, sizeof(title), _("Select Color for %s"), _(data)); | |
| 206 | color_dialog = gtk_color_selection_dialog_new(title); | |
| 207 | g_signal_connect(G_OBJECT(color_dialog), "response", | |
| 208 | G_CALLBACK(color_response), (gpointer)data); | |
| 209 | ||
| 210 | g_snprintf(tmp, sizeof(tmp), "%s/color", data); | |
| 211 | if (gdk_color_parse(gaim_prefs_get_string(tmp), &color)) | |
| 212 | { | |
| 213 | gtk_color_selection_set_current_color( | |
| 214 | GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color); | |
| 215 | } | |
| 216 | ||
| 217 | gtk_window_present(GTK_WINDOW(color_dialog)); | |
| 218 | } | |
| 219 | ||
| 220 | static void | |
| 221 | toggle_something(const char *prefix, int format) | |
| 222 | { | |
| 223 | int f; | |
| 224 | char tmp[128]; | |
| 225 | ||
| 226 | g_snprintf(tmp, sizeof(tmp), "%s/format", prefix); | |
| 227 | f = gaim_prefs_get_int(tmp); | |
| 228 | f ^= format; | |
| 229 | gaim_prefs_set_int(tmp, f); | |
| 230 | } | |
| 231 | ||
| 232 | static void | |
| 233 | toggle_bold(GtkWidget *widget, gpointer data) | |
| 234 | { | |
| 235 | toggle_something(data, FONT_BOLD); | |
| 236 | } | |
| 237 | ||
| 238 | static void | |
| 239 | toggle_italic(GtkWidget *widget, gpointer data) | |
| 240 | { | |
| 241 | toggle_something(data, FONT_ITALIC); | |
| 242 | } | |
| 243 | ||
| 244 | static void | |
| 245 | toggle_underline(GtkWidget *widget, gpointer data) | |
| 246 | { | |
| 247 | toggle_something(data, FONT_UNDERLINE); | |
| 248 | } | |
| 249 | ||
| 250 | static GtkWidget * | |
| 251 | get_config_frame(GaimPlugin *plugin) | |
| 252 | { | |
| 253 | GtkWidget *ret; | |
| 254 | GtkWidget *frame; | |
| 255 | int i; | |
| 256 | ||
| 257 | ret = gtk_vbox_new(FALSE, GAIM_HIG_CAT_SPACE); | |
| 258 | gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER); | |
| 259 | ||
| 260 | for (i = 0; formats[i].prefix; i++) | |
| 261 | { | |
| 262 | char tmp[128]; | |
| 263 | int f; | |
| 264 | GtkWidget *vbox, *hbox, *button; | |
| 265 | ||
| 266 | g_snprintf(tmp, sizeof(tmp), "%s/format", formats[i].prefix); | |
| 267 | f = gaim_prefs_get_int(tmp); | |
| 268 | ||
| 269 | frame = gaim_gtk_make_frame(ret, _(formats[i].text)); | |
| 270 | vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
| 271 | gtk_box_pack_start(GTK_BOX(frame), vbox, FALSE, FALSE, 0); | |
| 272 | ||
| 273 | hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); | |
| 274 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
| 275 | ||
| 276 | button = gaim_pixbuf_button_from_stock(" Color", GTK_STOCK_SELECT_COLOR, | |
| 277 | GAIM_BUTTON_HORIZONTAL); | |
| 278 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 279 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_color), | |
| 280 | formats[i].prefix); | |
| 281 | ||
| 282 | button = gtk_check_button_new_with_label(_("Bold")); | |
| 283 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 284 | if (f & FONT_BOLD) | |
| 285 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 286 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toggle_bold), | |
| 287 | formats[i].prefix); | |
| 288 | ||
| 289 | button = gtk_check_button_new_with_label(_("Italic")); | |
| 290 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 291 | if (f & FONT_ITALIC) | |
| 292 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 293 | g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(toggle_italic), | |
| 294 | formats[i].prefix); | |
| 295 | ||
| 296 | button = gtk_check_button_new_with_label(_("Underline")); | |
| 297 | gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); | |
| 298 | if (f & FONT_UNDERLINE) | |
| 299 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
| 300 | g_signal_connect(G_OBJECT(button), "clicked", | |
| 301 | G_CALLBACK(toggle_underline), formats[i].prefix); | |
| 302 | } | |
| 303 | ||
| 304 | frame = gaim_gtk_make_frame(ret, _("General")); | |
| 305 | gaim_gtk_prefs_checkbox(_("Ignore incoming format"), PREF_IGNORE, frame); | |
| 306 | gaim_gtk_prefs_checkbox(_("Apply in Chats"), PREF_CHATS, frame); | |
| 307 | gaim_gtk_prefs_checkbox(_("Apply in IMs"), PREF_IMS, frame); | |
| 308 | ||
| 309 | gtk_widget_show_all(ret); | |
| 310 | return ret; | |
| 311 | } | |
| 312 | ||
| 313 | static GaimGtkPluginUiInfo ui_info = | |
| 314 | { | |
| 315 | get_config_frame, | |
| 316 | 0, | |
| 317 | }; | |
| 318 | ||
| 319 | static GaimPluginInfo info = | |
| 320 | { | |
| 321 | GAIM_PLUGIN_MAGIC, /* Magic */ | |
| 322 | GAIM_MAJOR_VERSION, /* Gaim Major Version */ | |
| 323 | GAIM_MINOR_VERSION, /* Gaim Minor Version */ | |
| 324 | GAIM_PLUGIN_STANDARD, /* plugin type */ | |
| 325 | GAIM_GTK_PLUGIN_TYPE, /* ui requirement */ | |
| 326 | 0, /* flags */ | |
| 327 | NULL, /* dependencies */ | |
| 328 | GAIM_PRIORITY_DEFAULT, /* priority */ | |
| 329 | ||
| 330 | PLUGIN_ID, /* plugin id */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
331 | PLUGIN_NAME, /* name */ |
| 15231 | 332 | VERSION, /* version */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
333 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
334 | PLUGIN_DESCRIPTION, /* description */ |
| 15231 | 335 | PLUGIN_AUTHOR, /* author */ |
| 336 | GAIM_WEBSITE, /* website */ | |
| 337 | ||
| 338 | plugin_load, /* load */ | |
| 339 | plugin_unload, /* unload */ | |
| 340 | NULL, /* destroy */ | |
| 341 | ||
| 342 | &ui_info, /* ui_info */ | |
| 343 | NULL, /* extra_info */ | |
| 344 | NULL, /* prefs_info */ | |
| 345 | NULL /* actions */ | |
| 346 | }; | |
| 347 | ||
| 348 | static void | |
| 349 | init_plugin(GaimPlugin *plugin) | |
| 350 | { | |
| 351 | gaim_prefs_add_none(PREF_PREFIX); | |
| 352 | ||
| 353 | gaim_prefs_add_bool(PREF_IGNORE, TRUE); | |
| 354 | gaim_prefs_add_bool(PREF_CHATS, TRUE); | |
| 355 | gaim_prefs_add_bool(PREF_IMS, TRUE); | |
| 356 | ||
| 357 | gaim_prefs_add_none(PREF_SEND); | |
| 358 | gaim_prefs_add_none(PREF_RECV); | |
| 359 | gaim_prefs_add_none(PREF_SYSTEM); | |
| 360 | gaim_prefs_add_none(PREF_ERROR); | |
| 361 | gaim_prefs_add_none(PREF_NICK); | |
| 362 | ||
| 363 | gaim_prefs_add_string(PREF_SEND_C, "#909090"); | |
| 364 | gaim_prefs_add_string(PREF_RECV_C, "#000000"); | |
| 365 | gaim_prefs_add_string(PREF_SYSTEM_C, "#50a050"); | |
| 366 | gaim_prefs_add_string(PREF_ERROR_C, "#ff0000"); | |
| 367 | gaim_prefs_add_string(PREF_NICK_C, "#0000dd"); | |
| 368 | ||
| 369 | gaim_prefs_add_int(PREF_SEND_F, 0); | |
| 370 | gaim_prefs_add_int(PREF_RECV_F, 0); | |
| 371 | gaim_prefs_add_int(PREF_SYSTEM_F, FONT_ITALIC); | |
| 372 | gaim_prefs_add_int(PREF_ERROR_F, FONT_BOLD | FONT_UNDERLINE); | |
| 373 | gaim_prefs_add_int(PREF_NICK_F, FONT_BOLD); | |
| 374 | } | |
| 375 | ||
| 376 | GAIM_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |