Sat, 12 Jul 2003 19:08:19 +0000
[gaim-migrate @ 6560]
This should fix some icon uploading looping.
Sean, the problem was that, when adding the md5 sum to ssi, the code was
checking if it existed by looking for an item named "0", but it was
actually adding an item named "1." So for accounts with no icon info yet,
Gaim would end up getting in a loop and spiraling into oblivion, only far
less dramatic.
| 3832 | 1 | /* gtkcellrendererprogress.c |
| 2 | * Copyright (C) 2002, Sean Egan <bj91704@binghamton.edu> | |
| 3 | * | |
| 4 | * This program is free software; you can redistribute it and/or modify | |
| 5 | * it under the terms of the GNU General Public License as published by | |
| 6 | * the Free Software Foundation; either version 2 of the License, or | |
| 7 | * (at your option) any later version. | |
| 8 | * | |
| 9 | * This program is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | * GNU General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU General Public License | |
| 15 | * along with this program; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | */ | |
| 19 | ||
| 20 | /* This is taken largely from GtkCellRenderer[Text|Pixbuf|Toggle] by | |
| 21 | * Jonathon Blandford <jrb@redhat.com> for RedHat, Inc. | |
| 22 | */ | |
| 23 | ||
| 24 | #include "gtkcellrendererprogress.h" | |
| 25 | ||
| 26 | static void gtk_cell_renderer_progress_get_property (GObject *object, | |
| 27 | guint param_id, | |
| 28 | GValue *value, | |
| 29 | GParamSpec *pspec); | |
| 30 | static void gtk_cell_renderer_progress_set_property (GObject *object, | |
| 31 | guint param_id, | |
| 32 | const GValue *value, | |
| 33 | GParamSpec *pspec); | |
| 34 | static void gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress); | |
| 35 | static void gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *class); | |
| 36 | static void gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell, | |
| 37 | GtkWidget *widget, | |
| 38 | GdkRectangle *cell_area, | |
| 39 | gint *x_offset, | |
| 40 | gint *y_offset, | |
| 41 | gint *width, | |
| 42 | gint *height); | |
| 43 | static void gtk_cell_renderer_progress_render (GtkCellRenderer *cell, | |
| 44 | GdkWindow *window, | |
| 45 | GtkWidget *widget, | |
| 46 | GdkRectangle *background_area, | |
| 47 | GdkRectangle *cell_area, | |
| 48 | GdkRectangle *expose_area, | |
| 49 | guint flags); | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
50 | #if 0 |
| 3832 | 51 | static gboolean gtk_cell_renderer_progress_activate (GtkCellRenderer *cell, |
| 52 | GdkEvent *event, | |
| 53 | GtkWidget *widget, | |
| 54 | const gchar *path, | |
| 55 | GdkRectangle *background_area, | |
| 56 | GdkRectangle *cell_area, | |
| 57 | guint flags); | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
58 | #endif |
| 3832 | 59 | static void gtk_cell_renderer_progress_finalize (GObject *gobject); |
| 60 | ||
| 61 | enum { | |
| 62 | LAST_SIGNAL | |
| 63 | }; | |
| 64 | ||
| 65 | enum { | |
| 66 | PROP_0, | |
| 67 | ||
| 68 | PROP_PERCENTAGE, | |
| 69 | PROP_TEXT, | |
| 70 | PROP_SHOW_TEXT | |
| 71 | }; | |
| 72 | ||
| 73 | static gpointer parent_class; | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
74 | /* static guint progress_cell_renderer_signals [LAST_SIGNAL]; */ |
| 3832 | 75 | |
| 76 | GType gtk_cell_renderer_progress_get_type (void) | |
| 77 | { | |
| 78 | static GType cell_progress_type = 0; | |
| 79 | ||
| 80 | if (!cell_progress_type) | |
| 81 | { | |
| 82 | static const GTypeInfo cell_progress_info = | |
| 83 | { | |
| 84 | sizeof (GtkCellRendererProgressClass), | |
| 85 | NULL, /* base_init */ | |
| 86 | NULL, /* base_finalize */ | |
| 87 | (GClassInitFunc) gtk_cell_renderer_progress_class_init, | |
| 88 | NULL, /* class_finalize */ | |
| 89 | NULL, /* class_data */ | |
| 90 | sizeof (GtkCellRendererProgress), | |
| 91 | 0, /* n_preallocs */ | |
| 92 | (GInstanceInitFunc) gtk_cell_renderer_progress_init, | |
| 93 | }; | |
| 94 | ||
| 95 | cell_progress_type = | |
| 96 | g_type_register_static (GTK_TYPE_CELL_RENDERER, "GtkCellRendererProgress", | |
| 97 | &cell_progress_info, 0); | |
| 98 | } | |
| 99 | ||
| 100 | return cell_progress_type; | |
| 101 | } | |
| 102 | ||
| 103 | ||
| 104 | static void gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress) | |
| 105 | { | |
| 106 | GTK_CELL_RENDERER(cellprogress)->mode = GTK_CELL_RENDERER_MODE_INERT; | |
| 107 | GTK_CELL_RENDERER(cellprogress)->xpad = 2; | |
| 108 | GTK_CELL_RENDERER(cellprogress)->ypad = 2; | |
| 109 | } | |
| 110 | ||
| 111 | static void gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *class) | |
| 112 | { | |
| 113 | GObjectClass *object_class = G_OBJECT_CLASS(class); | |
| 114 | GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class); | |
| 115 | ||
| 116 | parent_class = g_type_class_peek_parent (class); | |
| 117 | object_class->finalize = gtk_cell_renderer_progress_finalize; | |
| 118 | ||
| 119 | object_class->get_property = gtk_cell_renderer_progress_get_property; | |
| 120 | object_class->set_property = gtk_cell_renderer_progress_set_property; | |
| 121 | ||
| 122 | cell_class->get_size = gtk_cell_renderer_progress_get_size; | |
| 123 | cell_class->render = gtk_cell_renderer_progress_render; | |
| 124 | ||
| 125 | g_object_class_install_property (object_class, | |
| 126 | PROP_PERCENTAGE, | |
| 127 | g_param_spec_double ("percentage", | |
| 128 | "Percentage", | |
| 129 | "The fractional progress to display", | |
| 130 | 0, 1, 0, | |
| 131 | G_PARAM_READWRITE)); | |
| 132 | ||
| 133 | g_object_class_install_property (object_class, | |
| 134 | PROP_TEXT, | |
| 135 | g_param_spec_string ("text", | |
| 136 | "Text", | |
| 137 | "Text to overlay over progress bar", | |
| 138 | NULL, | |
| 139 | G_PARAM_READWRITE)); | |
| 140 | g_object_class_install_property(object_class, | |
| 141 | PROP_SHOW_TEXT, | |
| 142 | g_param_spec_string("text_set", | |
| 143 | "Text set", | |
| 144 | "Whether to overlay text on the progress bar", | |
| 145 | FALSE, | |
| 146 | G_PARAM_READABLE | G_PARAM_WRITABLE)); | |
| 147 | } | |
| 148 | ||
| 149 | ||
| 150 | ||
| 151 | static void gtk_cell_renderer_progress_finalize (GObject *object) | |
| 152 | { | |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
153 | /* |
| 3832 | 154 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS(object); |
|
4514
40e3588a280f
[gaim-migrate @ 4792]
Christian Hammond <chipx86@chipx86.com>
parents:
3832
diff
changeset
|
155 | */ |
| 3832 | 156 | |
| 157 | (* G_OBJECT_CLASS (parent_class)->finalize) (object); | |
| 158 | } | |
| 159 | ||
| 160 | static void gtk_cell_renderer_progress_get_property (GObject *object, | |
| 161 | guint param_id, | |
| 162 | GValue *value, | |
| 163 | GParamSpec *psec) | |
| 164 | { | |
| 165 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS(object); | |
| 166 | ||
| 167 | switch (param_id) | |
| 168 | { | |
| 169 | case PROP_PERCENTAGE: | |
| 170 | g_value_set_double(value, cellprogress->progress); | |
| 171 | break; | |
| 172 | case PROP_TEXT: | |
| 173 | g_value_set_string(value, cellprogress->text); | |
| 174 | break; | |
| 175 | case PROP_SHOW_TEXT: | |
| 176 | g_value_set_boolean(value, cellprogress->text_set); | |
| 177 | break; | |
| 178 | default: | |
| 179 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec); | |
| 180 | break; | |
| 181 | } | |
| 182 | } | |
| 183 | ||
| 184 | static void gtk_cell_renderer_progress_set_property (GObject *object, | |
| 185 | guint param_id, | |
| 186 | const GValue *value, | |
| 187 | GParamSpec *pspec) | |
| 188 | { | |
| 189 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object); | |
| 190 | ||
| 191 | switch (param_id) | |
| 192 | { | |
| 193 | case PROP_PERCENTAGE: | |
| 194 | cellprogress->progress = g_value_get_double(value); | |
| 195 | break; | |
| 196 | case PROP_TEXT: | |
| 197 | if (cellprogress->text) | |
| 198 | g_free(cellprogress->text); | |
| 199 | cellprogress->text = g_strdup(g_value_get_string(value)); | |
| 200 | g_object_notify(object, "text"); | |
| 201 | break; | |
| 202 | case PROP_SHOW_TEXT: | |
| 203 | cellprogress->text_set = g_value_get_boolean(value); | |
| 204 | break; | |
| 205 | default: | |
| 206 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); | |
| 207 | break; | |
| 208 | } | |
| 209 | } | |
| 210 | ||
| 211 | GtkCellRenderer *gtk_cell_renderer_progress_new(void) | |
| 212 | { | |
| 213 | return g_object_new(GTK_TYPE_CELL_RENDERER_PROGRESS, NULL); | |
| 214 | } | |
| 215 | ||
| 216 | static void gtk_cell_renderer_progress_get_size (GtkCellRenderer *cell, | |
| 217 | GtkWidget *widget, | |
| 218 | GdkRectangle *cell_area, | |
| 219 | gint *x_offset, | |
| 220 | gint *y_offset, | |
| 221 | gint *width, | |
| 222 | gint *height) | |
| 223 | { | |
| 224 | gint calc_width; | |
| 225 | gint calc_height; | |
| 226 | ||
| 227 | calc_width = (gint) cell->xpad * 2 + 50; | |
| 228 | calc_height = (gint) cell->ypad * 2 + 10; | |
| 229 | ||
| 230 | if (width) | |
| 231 | *width = calc_width; | |
| 232 | ||
| 233 | if (height) | |
| 234 | *height = calc_height; | |
| 235 | ||
| 236 | if (cell_area) | |
| 237 | { | |
| 238 | if (x_offset) | |
| 239 | { | |
| 240 | *x_offset = cell->xalign * (cell_area->width - calc_width); | |
| 241 | *x_offset = MAX (*x_offset, 0); | |
| 242 | } | |
| 243 | if (y_offset) | |
| 244 | { | |
| 245 | *y_offset = cell->yalign * (cell_area->height - calc_height); | |
| 246 | *y_offset = MAX (*y_offset, 0); | |
| 247 | } | |
| 248 | } | |
| 249 | } | |
| 250 | ||
| 251 | ||
| 252 | static void gtk_cell_renderer_progress_render (GtkCellRenderer *cell, | |
| 253 | GdkWindow *window, | |
| 254 | GtkWidget *widget, | |
| 255 | GdkRectangle *background_area, | |
| 256 | GdkRectangle *cell_area, | |
| 257 | GdkRectangle *expose_area, | |
| 258 | guint flags) | |
| 259 | { | |
| 260 | GtkCellRendererProgress *cellprogress = (GtkCellRendererProgress *) cell; | |
| 261 | ||
| 262 | gint width, height; | |
| 263 | gint x_offset, y_offset; | |
| 264 | GtkStateType state; | |
| 265 | ||
| 266 | gtk_cell_renderer_progress_get_size (cell, widget, cell_area, | |
| 267 | &x_offset, &y_offset, | |
| 268 | &width, &height); | |
| 269 | ||
| 270 | ||
| 271 | if (GTK_WIDGET_HAS_FOCUS (widget)) | |
| 272 | state = GTK_STATE_ACTIVE; | |
| 273 | else | |
| 274 | state = GTK_STATE_NORMAL; | |
| 275 | ||
| 276 | ||
| 277 | ||
| 278 | width -= cell->xpad*2; | |
| 279 | height -= cell->ypad*2; | |
| 280 | ||
| 281 | gtk_paint_box (widget->style, | |
| 282 | window, | |
| 283 | GTK_STATE_NORMAL, GTK_SHADOW_IN, | |
| 284 | NULL, widget, "trough", | |
| 285 | cell_area->x + x_offset + cell->xpad, | |
| 286 | cell_area->y + y_offset + cell->ypad, | |
| 287 | width - 1, height - 1); | |
| 288 | gtk_paint_box (widget->style, | |
| 289 | window, | |
| 290 | state, GTK_SHADOW_OUT, | |
| 291 | NULL, widget, "bar", | |
| 4559 | 292 | cell_area->x + x_offset + cell->xpad, |
| 293 | cell_area->y + y_offset + cell->ypad, | |
| 3832 | 294 | width * cellprogress->progress, |
| 4559 | 295 | height - 1); |
| 3832 | 296 | } |