Sat, 19 May 2007 21:38:47 +0000
merge of '1442df274a24edc9a31194327bd00dfbcf478720'
and 'ce02548a6b6a545d97fb3f371506bcf1b5cc5131'
| 15231 | 1 | /* |
| 2 | * Markerline - Draw a line to indicate new messages in a conversation. | |
| 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-markerline" | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
23 | #define PLUGIN_NAME N_("Markerline") |
| 15231 | 24 | #define PLUGIN_STATIC_NAME "Markerline" |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
25 | #define PLUGIN_SUMMARY N_("Draw a line to indicate new messages in a conversation.") |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
26 | #define PLUGIN_DESCRIPTION N_("Draw a line to indicate new messages in a conversation.") |
| 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 | ||
| 15884 | 34 | /* Purple headers */ |
| 15231 | 35 | #include <gtkconv.h> |
| 36 | #include <gtkimhtml.h> | |
| 37 | #include <gtkplugin.h> | |
| 38 | #include <version.h> | |
| 39 | ||
| 40 | #define PREF_PREFIX "/plugins/gtk/" PLUGIN_ID | |
| 41 | #define PREF_IMS PREF_PREFIX "/ims" | |
| 42 | #define PREF_CHATS PREF_PREFIX "/chats" | |
| 43 | ||
| 44 | static int | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
45 | imhtml_expose_cb(GtkWidget *widget, GdkEventExpose *event, PidginConversation *gtkconv) |
| 15231 | 46 | { |
| 47 | int y, last_y, offset; | |
| 48 | GdkRectangle visible_rect; | |
| 49 | GtkTextIter iter; | |
| 50 | GdkRectangle buf; | |
| 51 | int pad; | |
| 15884 | 52 | PurpleConversation *conv = gtkconv->active_conv; |
| 53 | PurpleConversationType type = purple_conversation_get_type(conv); | |
| 15231 | 54 | |
| 15884 | 55 | if ((type == PURPLE_CONV_TYPE_CHAT && !purple_prefs_get_bool(PREF_CHATS)) || |
| 56 | (type == PURPLE_CONV_TYPE_IM && !purple_prefs_get_bool(PREF_IMS))) | |
| 15231 | 57 | return FALSE; |
| 58 | ||
| 59 | gtk_text_view_get_visible_rect(GTK_TEXT_VIEW(widget), &visible_rect); | |
| 60 | ||
| 61 | offset = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "markerline")); | |
| 62 | if (offset) | |
| 63 | { | |
| 64 | gtk_text_buffer_get_iter_at_offset(gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)), | |
| 65 | &iter, offset); | |
| 66 | ||
| 67 | gtk_text_view_get_iter_location(GTK_TEXT_VIEW(widget), &iter, &buf); | |
| 68 | last_y = buf.y + buf.height; | |
| 69 | pad = (gtk_text_view_get_pixels_below_lines(GTK_TEXT_VIEW(widget)) + | |
| 70 | gtk_text_view_get_pixels_above_lines(GTK_TEXT_VIEW(widget))) / 2; | |
| 71 | last_y += pad; | |
| 72 | } | |
| 73 | else | |
| 74 | last_y = 0; | |
| 75 | ||
| 76 | gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT, | |
| 77 | 0, last_y, 0, &y); | |
| 78 | ||
| 79 | if (y >= event->area.y) | |
| 80 | { | |
| 81 | GdkColor red = {0, 0xffff, 0, 0}; | |
| 82 | GdkGC *gc = gdk_gc_new(GDK_DRAWABLE(event->window)); | |
| 83 | ||
| 84 | gdk_gc_set_rgb_fg_color(gc, &red); | |
| 85 | gdk_draw_line(event->window, gc, | |
| 86 | 0, y, visible_rect.width, y); | |
| 87 | gdk_gc_unref(gc); | |
| 88 | } | |
| 89 | return FALSE; | |
| 90 | } | |
| 91 | ||
| 92 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
93 | update_marker_for_gtkconv(PidginConversation *gtkconv) |
| 15231 | 94 | { |
| 95 | GtkTextIter iter; | |
| 96 | GtkTextBuffer *buffer; | |
| 97 | g_return_if_fail(gtkconv != NULL); | |
| 98 | ||
| 99 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)); | |
| 100 | ||
| 101 | if (!gtk_text_buffer_get_char_count(buffer)) | |
| 102 | return; | |
| 103 | ||
| 104 | gtk_text_buffer_get_end_iter(buffer, &iter); | |
| 105 | ||
| 106 | g_object_set_data(G_OBJECT(gtkconv->imhtml), "markerline", | |
| 107 | GINT_TO_POINTER(gtk_text_iter_get_offset(&iter))); | |
| 108 | gtk_widget_queue_draw(gtkconv->imhtml); | |
| 109 | } | |
| 110 | ||
| 111 | static gboolean | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
112 | focus_removed(GtkWidget *widget, GdkEventVisibility *event, PidginWindow *win) |
| 15231 | 113 | { |
| 15884 | 114 | PurpleConversation *conv; |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
115 | PidginConversation *gtkconv; |
| 15231 | 116 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
117 | conv = pidgin_conv_window_get_active_conversation(win); |
| 15231 | 118 | g_return_val_if_fail(conv != NULL, FALSE); |
| 119 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
120 | gtkconv = PIDGIN_CONVERSATION(conv); |
| 15231 | 121 | update_marker_for_gtkconv(gtkconv); |
| 122 | ||
| 123 | return FALSE; | |
| 124 | } | |
| 125 | ||
| 126 | #if 0 | |
| 127 | static gboolean | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
128 | window_resized(GtkWidget *w, GdkEventConfigure *event, PidginWindow *win) |
| 15231 | 129 | { |
| 130 | GList *list; | |
| 131 | ||
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
132 | list = pidgin_conv_window_get_gtkconvs(win); |
| 15231 | 133 | |
| 134 | for (; list; list = list->next) | |
| 135 | update_marker_for_gtkconv(list->data); | |
| 136 | ||
| 137 | return FALSE; | |
| 138 | } | |
| 139 | ||
| 140 | static gboolean | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
141 | imhtml_resize_cb(GtkWidget *w, GtkAllocation *allocation, PidginConversation *gtkconv) |
| 15231 | 142 | { |
| 143 | gtk_widget_queue_draw(w); | |
| 144 | return FALSE; | |
| 145 | } | |
| 146 | #endif | |
| 147 | ||
| 148 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
149 | page_switched(GtkWidget *widget, GtkWidget *page, gint num, PidginWindow *win) |
| 15231 | 150 | { |
| 151 | focus_removed(NULL, NULL, win); | |
| 152 | } | |
| 153 | ||
| 154 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
155 | detach_from_gtkconv(PidginConversation *gtkconv, gpointer null) |
| 15231 | 156 | { |
| 157 | g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->imhtml), imhtml_expose_cb, gtkconv); | |
| 158 | } | |
| 159 | ||
| 160 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
161 | detach_from_pidgin_window(PidginWindow *win, gpointer null) |
| 15231 | 162 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
163 | g_list_foreach(pidgin_conv_window_get_gtkconvs(win), (GFunc)detach_from_gtkconv, NULL); |
| 15231 | 164 | g_signal_handlers_disconnect_by_func(G_OBJECT(win->notebook), page_switched, win); |
| 165 | g_signal_handlers_disconnect_by_func(G_OBJECT(win->window), focus_removed, win); | |
| 166 | ||
| 167 | gtk_widget_queue_draw(win->window); | |
| 168 | } | |
| 169 | ||
| 170 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
171 | attach_to_gtkconv(PidginConversation *gtkconv, gpointer null) |
| 15231 | 172 | { |
| 173 | detach_from_gtkconv(gtkconv, NULL); | |
| 174 | g_signal_connect(G_OBJECT(gtkconv->imhtml), "expose_event", | |
| 175 | G_CALLBACK(imhtml_expose_cb), gtkconv); | |
| 176 | } | |
| 177 | ||
| 178 | static void | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
179 | attach_to_pidgin_window(PidginWindow *win, gpointer null) |
| 15231 | 180 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
181 | g_list_foreach(pidgin_conv_window_get_gtkconvs(win), (GFunc)attach_to_gtkconv, NULL); |
| 15231 | 182 | |
| 183 | g_signal_connect(G_OBJECT(win->window), "focus_out_event", | |
| 184 | G_CALLBACK(focus_removed), win); | |
| 185 | ||
| 186 | g_signal_connect(G_OBJECT(win->notebook), "switch_page", | |
| 187 | G_CALLBACK(page_switched), win); | |
| 188 | ||
| 189 | gtk_widget_queue_draw(win->window); | |
| 190 | } | |
| 191 | ||
| 192 | static void | |
| 193 | detach_from_all_windows() | |
| 194 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
195 | g_list_foreach(pidgin_conv_windows_get_list(), (GFunc)detach_from_pidgin_window, NULL); |
| 15231 | 196 | } |
| 197 | ||
| 198 | static void | |
| 199 | attach_to_all_windows() | |
| 200 | { | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
201 | g_list_foreach(pidgin_conv_windows_get_list(), (GFunc)attach_to_pidgin_window, NULL); |
| 15231 | 202 | } |
| 203 | ||
| 204 | static void | |
| 15884 | 205 | conv_created(PurpleConversation *conv, gpointer null) |
| 15231 | 206 | { |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
207 | PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
208 | PidginWindow *win; |
| 15231 | 209 | |
| 210 | if (!gtkconv) | |
| 211 | return; | |
| 212 | ||
| 15563 | 213 | win = pidgin_conv_get_window(gtkconv); |
| 15231 | 214 | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
215 | detach_from_pidgin_window(win, NULL); |
|
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
216 | attach_to_pidgin_window(win, NULL); |
| 15231 | 217 | } |
| 218 | ||
| 219 | static gboolean | |
| 15884 | 220 | plugin_load(PurplePlugin *plugin) |
| 15231 | 221 | { |
| 222 | attach_to_all_windows(); | |
| 223 | ||
| 15884 | 224 | purple_signal_connect(purple_conversations_get_handle(), "conversation-created", |
| 225 | plugin, PURPLE_CALLBACK(conv_created), NULL); | |
| 15231 | 226 | |
| 227 | return TRUE; | |
| 228 | } | |
| 229 | ||
| 230 | static gboolean | |
| 15884 | 231 | plugin_unload(PurplePlugin *plugin) |
| 15231 | 232 | { |
| 233 | detach_from_all_windows(); | |
| 234 | ||
| 235 | return TRUE; | |
| 236 | } | |
| 237 | ||
| 15884 | 238 | static PurplePluginPrefFrame * |
| 239 | get_plugin_pref_frame(PurplePlugin *plugin) | |
| 15231 | 240 | { |
| 15884 | 241 | PurplePluginPrefFrame *frame; |
| 242 | PurplePluginPref *pref; | |
| 15231 | 243 | |
| 15884 | 244 | frame = purple_plugin_pref_frame_new(); |
| 15231 | 245 | |
| 15884 | 246 | pref = purple_plugin_pref_new_with_label(_("Draw Markerline in ")); |
| 247 | purple_plugin_pref_frame_add(frame, pref); | |
| 15231 | 248 | |
| 15884 | 249 | pref = purple_plugin_pref_new_with_name_and_label(PREF_IMS, |
| 15231 | 250 | _("_IM windows")); |
| 15884 | 251 | purple_plugin_pref_frame_add(frame, pref); |
| 15231 | 252 | |
| 15884 | 253 | pref = purple_plugin_pref_new_with_name_and_label(PREF_CHATS, |
| 15231 | 254 | _("C_hat windows")); |
| 15884 | 255 | purple_plugin_pref_frame_add(frame, pref); |
| 15231 | 256 | |
| 257 | return frame; | |
| 258 | } | |
| 259 | ||
| 15884 | 260 | static PurplePluginUiInfo prefs_info = { |
| 15231 | 261 | get_plugin_pref_frame, |
| 262 | 0, | |
| 263 | NULL, | |
|
16749
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
264 | |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
265 | /* padding */ |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
266 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
267 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
268 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
269 | NULL |
| 15231 | 270 | }; |
| 271 | ||
| 15884 | 272 | static PurplePluginInfo info = { |
| 273 | PURPLE_PLUGIN_MAGIC, /* Magic */ | |
| 274 | PURPLE_MAJOR_VERSION, /* Purple Major Version */ | |
| 275 | PURPLE_MINOR_VERSION, /* Purple Minor Version */ | |
| 276 | PURPLE_PLUGIN_STANDARD, /* plugin type */ | |
|
15562
8c8249fe5e3c
gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents:
15435
diff
changeset
|
277 | PIDGIN_PLUGIN_TYPE, /* ui requirement */ |
| 15231 | 278 | 0, /* flags */ |
| 279 | NULL, /* dependencies */ | |
| 15884 | 280 | PURPLE_PRIORITY_DEFAULT, /* priority */ |
| 15231 | 281 | |
| 282 | PLUGIN_ID, /* plugin id */ | |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
283 | PLUGIN_NAME, /* name */ |
| 15231 | 284 | VERSION, /* version */ |
|
15418
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
285 | PLUGIN_SUMMARY, /* summary */ |
|
bf287f742a5a
[gaim-migrate @ 18149]
Luke Schierer <lschiere@pidgin.im>
parents:
15231
diff
changeset
|
286 | PLUGIN_DESCRIPTION, /* description */ |
| 15231 | 287 | PLUGIN_AUTHOR, /* author */ |
| 15884 | 288 | PURPLE_WEBSITE, /* website */ |
| 15231 | 289 | |
| 290 | plugin_load, /* load */ | |
| 291 | plugin_unload, /* unload */ | |
| 292 | NULL, /* destroy */ | |
| 293 | ||
| 294 | NULL, /* ui_info */ | |
| 295 | NULL, /* extra_info */ | |
| 296 | &prefs_info, /* prefs_info */ | |
|
16749
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
297 | NULL, /* actions */ |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
298 | |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
299 | /* padding */ |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
300 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
301 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
302 | NULL, |
|
14a3fdc0aed7
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>
parents:
15884
diff
changeset
|
303 | NULL |
| 15231 | 304 | }; |
| 305 | ||
| 306 | static void | |
| 15884 | 307 | init_plugin(PurplePlugin *plugin) |
| 15231 | 308 | { |
| 15884 | 309 | purple_prefs_add_none(PREF_PREFIX); |
| 310 | purple_prefs_add_bool(PREF_IMS, FALSE); | |
| 311 | purple_prefs_add_bool(PREF_CHATS, TRUE); | |
| 15231 | 312 | } |
| 313 | ||
| 15884 | 314 | PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info) |