Mercurial > pidgin
annotate src/dnd-hints.c @ 9584:fe35f55ee984
[gaim-migrate @ 10427]
" When joining a jabber conference many jabber servers
send a recap of the last 20 or so messages. If you
have sounds enabled, this will result in either 20
sounds in row, or worse if mixing is available, a
horrible mix of 20 overlapping sounds. These recap
messages can be identifed be the presence of the
"jabber:x:delay". This patch identifies delayed
messages, passes that information through flags from
the prpl to the core, and then on to the gui. Detailed
changes:
Add GAIM_MESSAGE_DELAYED to GaimMessageFlags to
indicate a delayed message.
Change gtkconv.c to not play sounds when either
GAIM_MESSAGE_DELAYED or GAIM_MESSAGE_SYSTEM are set.
Add GaimConvChatFlags, parallel to GaimConvImFlags, to
pass flags from protocols to core. Currently contains
two flags:
GAIM_CONV_CHAT_WHISPER
GAIM_CONV_CHAT_DELAYED
Change fourth arg of serv_got_chat_in() from "int
whisper" to "GaimConvChatFlags chatflags".
Change jabber prpl to set delayed flag when the
"jabber:x:delay" element is present. Change toc
protocol since it uses the whisper flag." --Nathan Fredrickson
Date: 2004-07-24 00:49
Sender: marv_sfAccepting Donations
Logged In: YES
user_id=790708
I'm not sure I like naming the flags "DELAYED". I mean
that's okay inside jabber since that's what the jabber
protocol refers to it as, but for the the GAIM_*_DELAYED
flags, I think they should be named something else.
I thought about NOSOUND, but I decided that was wrong,
because the flag should say what kind of message it is, not
what to do with it, that's up to the UI to decide.
What's up with not playing sounds on GAIM_MESSAGE_SYSTEM?
This sounds unrelated to this. Are there times when we want
to play sounds on system messages?
Date: 2004-07-24 09:13
Sender: noif
Logged In: YES
user_id=365548
I purposely did not use a name that implied what the UI
should do with the flag. The only characteristic that makes
these messages unique is that they've been stored in the
server for some period of time and are not current. I'm
open to a better flag name than "DELAYED"... I thought about
"RECAP", but that seemed less generalized than "DELAYED".
As for not playing sounds on GAIM_MESSAGE_SYSTEM, that can
be removed if it's controversial. I think I slipped that
in since the setting of the topic was still playing a sound
every time you joined a jabber conference.
I think we can change the flag name ourselves if something else is better.
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sat, 24 Jul 2004 15:18:32 +0000 |
| parents | fa6395637e2c |
| children | 03be9d653123 |
| rev | line source |
|---|---|
| 4359 | 1 /* |
| 8046 | 2 * Gaim is the legal property of its developers, whose names are too numerous |
| 3 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 4 * source distribution. | |
| 4359 | 5 * |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2, or(at your option) | |
| 9 * any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 19 */ | |
| 20 | |
| 21 #include "dnd-hints.h" | |
| 22 | |
| 23 #include <gtk/gtk.h> | |
| 24 #include <gdk/gdk.h> | |
| 25 #include <gdk-pixbuf/gdk-pixbuf.h> | |
| 26 | |
|
4363
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
27 #ifdef _WIN32 |
|
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
28 #include "win32dep.h" |
|
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
29 #endif |
|
65d98b565fbe
[gaim-migrate @ 4629]
Christian Hammond <chipx86@chipx86.com>
parents:
4359
diff
changeset
|
30 |
| 4359 | 31 typedef struct |
| 32 { | |
| 33 GtkWidget *widget; | |
| 34 gchar *filename; | |
| 35 gint ox; | |
| 36 gint oy; | |
| 37 | |
| 38 } HintWindowInfo; | |
| 39 | |
| 40 /** | |
| 41 * Info about each hint widget. See DndHintWindowId enum. | |
| 42 */ | |
| 43 HintWindowInfo hint_windows[] = { | |
| 44 { NULL, "tb_drag_arrow_up.xpm", -13/2, 0 }, | |
| 45 { NULL, "tb_drag_arrow_down.xpm", -13/2, -16 }, | |
| 46 { NULL, "tb_drag_arrow_left.xpm", 0, -13/2 }, | |
| 47 { NULL, "tb_drag_arrow_right.xpm", -16, -13/2 }, | |
| 48 { NULL, NULL, 0, 0 } | |
| 49 }; | |
| 50 | |
| 51 static GtkWidget * | |
| 52 dnd_hints_init_window(const gchar *fname) | |
| 53 { | |
| 54 GdkPixbuf *pixbuf; | |
| 55 GdkPixmap *pixmap; | |
| 56 GdkBitmap *bitmap; | |
| 57 GtkWidget *pix; | |
| 58 GtkWidget *win; | |
| 59 | |
| 60 pixbuf = gdk_pixbuf_new_from_file(fname, NULL); | |
| 61 g_return_val_if_fail(pixbuf, NULL); | |
| 62 | |
| 63 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128); | |
| 4793 | 64 g_object_unref(G_OBJECT(pixbuf)); |
| 4359 | 65 |
| 4793 | 66 gtk_widget_push_colormap(gdk_rgb_get_colormap()); |
| 4359 | 67 win = gtk_window_new(GTK_WINDOW_POPUP); |
| 4635 | 68 pix = gtk_image_new_from_pixmap(pixmap, bitmap); |
| 4359 | 69 gtk_widget_realize(win); |
| 70 gtk_container_add(GTK_CONTAINER(win), pix); | |
| 71 gtk_widget_shape_combine_mask(win, bitmap, 0, 0); | |
| 72 gtk_widget_pop_colormap(); | |
| 73 | |
| 4793 | 74 g_object_unref(G_OBJECT(pixmap)); |
| 75 g_object_unref(G_OBJECT(bitmap)); | |
| 4359 | 76 |
| 77 gtk_widget_show_all(pix); | |
| 78 | |
| 79 return win; | |
| 80 } | |
| 81 | |
| 82 static void | |
| 83 get_widget_coords(GtkWidget *w, gint *x1, gint *y1, gint *x2, gint *y2) | |
| 84 { | |
| 85 gint ox, oy, width, height; | |
| 86 | |
| 87 if (w->parent && w->parent->window == w->window) | |
| 88 { | |
| 89 get_widget_coords(w->parent, &ox, &oy, NULL, NULL); | |
| 90 ox += w->allocation.x; | |
| 91 oy += w->allocation.y; | |
| 92 height = w->allocation.height; | |
| 93 width = w->allocation.width; | |
| 94 } | |
| 95 else | |
| 96 { | |
| 97 gdk_window_get_origin(w->window, &ox, &oy); | |
| 4793 | 98 gdk_drawable_get_size(w->window, &width, &height); |
| 4359 | 99 } |
| 100 | |
| 101 if (x1) *x1 = ox; | |
| 102 if (y1) *y1 = oy; | |
| 103 if (x2) *x2 = ox + width; | |
| 104 if (y2) *y2 = oy + height; | |
| 105 } | |
| 106 | |
| 107 static void | |
| 108 dnd_hints_init(void) | |
| 109 { | |
| 110 static gboolean done = FALSE; | |
| 111 gint i; | |
| 112 | |
| 113 if (done) | |
| 114 return; | |
| 115 | |
| 116 done = TRUE; | |
| 117 | |
| 118 for (i = 0; hint_windows[i].filename != NULL; i++) { | |
| 119 gchar *fname; | |
| 120 | |
| 121 fname = g_build_filename(DATADIR, "pixmaps", "gaim", | |
| 122 hint_windows[i].filename, NULL); | |
| 123 | |
| 124 hint_windows[i].widget = dnd_hints_init_window(fname); | |
| 125 | |
| 126 g_free(fname); | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 void | |
| 131 dnd_hints_hide_all(void) | |
| 132 { | |
| 133 gint i; | |
| 134 | |
| 135 for (i = 0; hint_windows[i].filename != NULL; i++) | |
| 136 dnd_hints_hide(i); | |
| 137 } | |
| 138 | |
| 139 void | |
| 140 dnd_hints_hide(DndHintWindowId i) | |
| 141 { | |
| 142 GtkWidget *w = hint_windows[i].widget; | |
| 143 | |
| 144 if (w && GTK_IS_WIDGET(w)) | |
| 145 gtk_widget_hide(w); | |
| 146 } | |
| 147 | |
| 148 void | |
| 149 dnd_hints_show(DndHintWindowId id, gint x, gint y) | |
| 150 { | |
| 151 GtkWidget *w; | |
| 152 | |
| 153 dnd_hints_init(); | |
| 154 | |
| 155 w = hint_windows[id].widget; | |
| 156 | |
| 157 if (w && GTK_IS_WIDGET(w)) | |
| 158 { | |
| 4635 | 159 gtk_window_move(GTK_WINDOW(w), hint_windows[id].ox + x, |
| 4359 | 160 hint_windows[id].oy + y); |
| 161 gtk_widget_show(w); | |
| 162 } | |
| 163 } | |
| 164 | |
| 165 void | |
| 166 dnd_hints_show_relative(DndHintWindowId id, GtkWidget *widget, | |
| 167 DndHintPosition horiz, DndHintPosition vert) | |
| 168 { | |
| 169 gint x1, x2, y1, y2; | |
| 170 gint x = 0, y = 0; | |
| 171 | |
| 172 get_widget_coords(widget, &x1, &y1, &x2, &y2); | |
| 173 | |
| 174 switch (horiz) | |
| 175 { | |
| 176 case HINT_POSITION_RIGHT: x = x2; break; | |
| 177 case HINT_POSITION_LEFT: x = x1; break; | |
| 178 case HINT_POSITION_CENTER: x = (x1 + x2) / 2; break; | |
| 179 default: | |
| 180 /* should not happen */ | |
| 181 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 182 break; | |
| 183 } | |
| 184 | |
| 185 switch (vert) | |
| 186 { | |
| 187 case HINT_POSITION_TOP: y = y1; break; | |
| 188 case HINT_POSITION_BOTTOM: y = y2; break; | |
| 189 case HINT_POSITION_CENTER: y = (y1 + y2) / 2; break; | |
| 190 default: | |
| 191 /* should not happen */ | |
| 192 g_warning("Invalid parameter to dnd_hints_show_relative"); | |
| 193 break; | |
| 194 } | |
| 195 | |
| 196 dnd_hints_show(id, x, y); | |
| 197 } | |
| 198 |
