Mercurial > pidgin
view plugins/docklet/docklet-x11.c @ 10787:c932d96a7c69
[gaim-migrate @ 12428]
" Autocorrect in gaim... um... sucks. The problem is
that the correction only happens AFTER you send a
message. This means that you don't actually know what
message you are sending until it is sent. Horrible.
My new patch works AS YOU TYPE with the following rules:
* You must be typing, not pasting in text. If you
paste in the and there is a rule to correct the to the,
it won't be corrected. This is because it would be
impossible to go back and check all the text.
* Check whole words ONLY. Partial words don't count.
* If the dictionary word has capital letters in it,
match only words with that capitalization. (FPT -> FTP
doesn't match ftp.)
* If the dictionary word doesn't have capital letters,
preserve the capitalization the user used. (The code
assumes three possible capitalization schemes:
ALLCAPS, lowercase, and Proper.) Unless the solution
has capital letters. In that case, force the
capitalization used in the solution.
* A word may have quote characters in it and still be a
word.
* If the user immediately hits the backspace key after
a correction, undo the correction." --xkan
" This patch is based off xkahn's work available at:
http://sf.net/support/tracker.php?aid=300235
Most of the changes are his. I just changed his formatting to
match the rest of Gaim more closely. Also, I made a couple
coding style changes.
The two biggest changes I made were:
1) I added some hash stuff to load_config. This removes
duplicates.
2) I imported my list of text replacement strings as the
default list in addition to xkahn's list. My list consisted
primarily of the autocorrect entries from my copy of
OpenOffice.org Writer. There were a few things I've added
by hand. (For those familiar with my comments in #gaim,
this list does NOT include anything like a pwn -> own
replacement. If people want to talk like that, I'm not going to
stop them. This list should be useful to anyone.)
I also fixed a memory leak in load_config. A GtkListStore
stores its own copy of strings, so there is no need to
g_strdup them when appending to the GtkListStore.
When I get a chance, I need to make it give an error if you
try to set a duplicate "You type" word in the preferences.
Otherwise, this patch should take care of everything.
I would recommend considering this patch over xkahn's
because it's a direct superset of his patches. However, I
want to be very clear that most of the changes in this patch
are his and he deserves the credit for them. " --rlaager
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 07 Apr 2005 14:35:25 +0000 |
parents | acf54edfde3d |
children | 0c90ef51ad66 |
line wrap: on
line source
/* * System tray icon (aka docklet) plugin for Gaim * * Copyright (C) 2002-3 Robert McQueen <robot101@debian.org> * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com> * Inspired by a similar plugin by: * John (J5) Palmieri <johnp@martianrock.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #include "internal.h" #include "gtkgaim.h" #include "debug.h" #include "gtkstock.h" #include "gaim.h" #include "gtkdialogs.h" #include "eggtrayicon.h" #include "docklet.h" #define EMBED_TIMEOUT 3000 /* globals */ static EggTrayIcon *docklet = NULL; static GtkWidget *image = NULL; static GdkPixbuf *blank_icon = NULL; static int embed_timeout = 0; /* protos */ static void docklet_x11_create(); static gboolean docklet_x11_create_cb() { docklet_x11_create(); return FALSE; /* for when we're called by the glib idle handler */ } static void docklet_x11_embedded_cb(GtkWidget *widget, void *data) { gaim_debug(GAIM_DEBUG_INFO, "tray icon", "embedded\n"); g_source_remove(embed_timeout); embed_timeout = 0; } static void docklet_x11_destroyed_cb(GtkWidget *widget, void *data) { gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); docklet_remove(TRUE); g_object_unref(G_OBJECT(docklet)); docklet = NULL; g_idle_add(docklet_x11_create_cb, &handle); } static void docklet_x11_clicked_cb(GtkWidget *button, GdkEventButton *event, void *data) { if (event->type != GDK_BUTTON_PRESS) return; docklet_clicked(event->button); } static void docklet_x11_update_icon(enum docklet_status icon) { const gchar *icon_name = NULL; g_return_if_fail(image != NULL); switch (icon) { case offline: icon_name = GAIM_STOCK_ICON_OFFLINE; break; case offline_connecting: case online_connecting: icon_name = GAIM_STOCK_ICON_CONNECT; break; case online: icon_name = GAIM_STOCK_ICON_ONLINE; break; case online_pending: icon_name = GAIM_STOCK_ICON_ONLINE_MSG; break; case away: icon_name = GAIM_STOCK_ICON_AWAY; break; case away_pending: icon_name = GAIM_STOCK_ICON_AWAY_MSG; break; } gtk_image_set_from_stock(GTK_IMAGE(image), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR); #if 0 GdkPixbuf *p; GdkBitmap *mask = NULL; p = gtk_widget_render_icon(GTK_WIDGET(image), icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); if (p && (gdk_pixbuf_get_colorspace(p) == GDK_COLORSPACE_RGB) && (gdk_pixbuf_get_bits_per_sample(p) == 8) && (gdk_pixbuf_get_has_alpha(p)) && (gdk_pixbuf_get_n_channels(p) == 4)) { int len = gdk_pixbuf_get_width(p) * gdk_pixbuf_get_height(p); guchar *data = gdk_pixbuf_get_pixels(p); guchar *bitmap = g_malloc((len / 8) + 1); int i; for (i = 0; i < len; i++) if (data[i*4 + 3] > 55) bitmap[i/8] |= 1 << i % 8; else bitmap[i/8] &= ~(1 << i % 8); mask = gdk_bitmap_create_from_data(GDK_DRAWABLE(GTK_WIDGET(image)->window), bitmap, gdk_pixbuf_get_width(p), gdk_pixbuf_get_height(p)); g_free(bitmap); } if (mask) gdk_window_shape_combine_mask(image->window, mask, 0, 0); g_object_unref(G_OBJECT(p)); #endif } static void docklet_x11_blank_icon() { if (!blank_icon) { gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_LARGE_TOOLBAR, &width, &height); blank_icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); gdk_pixbuf_fill(blank_icon, 0); } gtk_image_set_from_pixbuf(GTK_IMAGE(image), blank_icon); } #if GTK_CHECK_VERSION(2,2,0) static void docklet_x11_position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data) { GtkWidget *widget = GTK_WIDGET(docklet); GtkRequisition req; gint menu_xpos, menu_ypos; gtk_widget_size_request(GTK_WIDGET(menu), &req); gdk_window_get_origin(widget->window, &menu_xpos, &menu_ypos); menu_xpos += widget->allocation.x; menu_ypos += widget->allocation.y; if (menu_ypos > gdk_screen_get_height(gtk_widget_get_screen(widget)) / 2) menu_ypos -= req.height; else menu_ypos += widget->allocation.height; *x = menu_xpos; *y = menu_ypos; *push_in = TRUE; } #endif static void docklet_x11_destroy() { g_return_if_fail(docklet != NULL); docklet_remove(GTK_WIDGET_VISIBLE(docklet)); g_signal_handlers_disconnect_by_func(G_OBJECT(docklet), G_CALLBACK(docklet_x11_destroyed_cb), NULL); gtk_widget_destroy(GTK_WIDGET(docklet)); g_object_unref(G_OBJECT(docklet)); docklet = NULL; if (blank_icon) g_object_unref(G_OBJECT(blank_icon)); blank_icon = NULL; image = NULL; gaim_debug(GAIM_DEBUG_INFO, "tray icon", "destroyed\n"); } static gboolean docklet_x11_embed_timeout_cb() { docklet_unload(); return FALSE; } static void docklet_x11_create() { GtkWidget *box; if (docklet) { /* if this is being called when a tray icon exists, it's because something messed up. try destroying it before we proceed, although docklet_refcount may be all hosed. hopefully won't happen. */ gaim_debug(GAIM_DEBUG_WARNING, "tray icon", "trying to create icon but it already exists?\n"); docklet_x11_destroy(); } docklet = egg_tray_icon_new("Gaim"); box = gtk_event_box_new(); image = gtk_image_new(); g_signal_connect(G_OBJECT(docklet), "embedded", G_CALLBACK(docklet_x11_embedded_cb), NULL); g_signal_connect(G_OBJECT(docklet), "destroy", G_CALLBACK(docklet_x11_destroyed_cb), NULL); g_signal_connect(G_OBJECT(box), "button-press-event", G_CALLBACK(docklet_x11_clicked_cb), NULL); gtk_container_add(GTK_CONTAINER(box), image); gtk_container_add(GTK_CONTAINER(docklet), box); if(!gtk_check_version(2,4,0)) g_object_set(G_OBJECT(box), "visible-window", FALSE, NULL); gtk_widget_show_all(GTK_WIDGET(docklet)); /* ref the docklet before we bandy it about the place */ g_object_ref(G_OBJECT(docklet)); docklet_embedded(); embed_timeout = g_timeout_add(EMBED_TIMEOUT, docklet_x11_embed_timeout_cb, NULL); gaim_debug(GAIM_DEBUG_INFO, "tray icon", "created\n"); } static struct docklet_ui_ops ui_ops = { docklet_x11_create, docklet_x11_destroy, docklet_x11_update_icon, docklet_x11_blank_icon, #if GTK_CHECK_VERSION(2,2,0) docklet_x11_position_menu #else NULL #endif }; void docklet_ui_init() { docklet_set_ui_ops(&ui_ops); }