Mercurial > pidgin
comparison gtk/gtkstatusbox.c @ 14599:26e7d03d40c5
[gaim-migrate @ 17326]
Show a placeholder icon when there is no global buddy icon selected.
Someone more familiar with gtk might want to look over there...
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 20 Sep 2006 09:13:17 +0000 |
parents | 3ff55ec8203a |
children | 2c09131fffa5 |
comparison
equal
deleted
inserted
replaced
14598:e2798f3d3a45 | 14599:26e7d03d40c5 |
---|---|
73 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); | 73 static void gtk_gaim_status_box_regenerate(GtkGaimStatusBox *status_box); |
74 static void gtk_gaim_status_box_changed(GtkComboBox *box); | 74 static void gtk_gaim_status_box_changed(GtkComboBox *box); |
75 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); | 75 static void gtk_gaim_status_box_size_request (GtkWidget *widget, GtkRequisition *requisition); |
76 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | 76 static void gtk_gaim_status_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); |
77 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); | 77 static gboolean gtk_gaim_status_box_expose_event (GtkWidget *widget, GdkEventExpose *event); |
78 static void gtk_gaim_status_box_redisplay_buddy_icon(GtkGaimStatusBox *status_box); | |
78 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); | 79 static void gtk_gaim_status_box_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); |
79 | 80 |
80 static void do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift); | 81 static void do_colorshift (GdkPixbuf *dest, GdkPixbuf *src, int shift); |
81 static void icon_choose_cb(const char *filename, gpointer data); | 82 static void icon_choose_cb(const char *filename, gpointer data); |
82 | 83 |
306 } | 307 } |
307 else | 308 else |
308 { | 309 { |
309 gtk_gaim_status_box_set_buddy_icon(status_box, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); | 310 gtk_gaim_status_box_set_buddy_icon(status_box, gaim_prefs_get_string("/gaim/gtk/accounts/buddyicon")); |
310 } | 311 } |
311 status_box->icon = gtk_image_new_from_pixbuf(status_box->buddy_icon); | 312 status_box->icon = gtk_image_new(); |
312 status_box->icon_box = gtk_event_box_new(); | 313 status_box->icon_box = gtk_event_box_new(); |
313 | 314 |
314 status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); | 315 status_box->hand_cursor = gdk_cursor_new (GDK_HAND2); |
315 status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); | 316 status_box->arrow_cursor = gdk_cursor_new (GDK_LEFT_PTR); |
316 | 317 |
317 /* Set up DND */ | 318 /* Set up DND */ |
318 gtk_drag_dest_set(status_box->icon_box, | 319 gtk_drag_dest_set(status_box->icon_box, |
319 GTK_DEST_DEFAULT_MOTION | | 320 GTK_DEST_DEFAULT_MOTION | |
320 GTK_DEST_DEFAULT_DROP, | 321 GTK_DEST_DEFAULT_DROP, |
321 dnd_targets, | 322 dnd_targets, |
322 sizeof(dnd_targets) / sizeof(GtkTargetEntry), | 323 sizeof(dnd_targets) / sizeof(GtkTargetEntry), |
323 GDK_ACTION_COPY); | 324 GDK_ACTION_COPY); |
324 | 325 |
325 g_signal_connect(G_OBJECT(status_box->icon_box), "drag_data_received", G_CALLBACK(icon_box_dnd_cb), status_box); | 326 g_signal_connect(G_OBJECT(status_box->icon_box), "drag_data_received", G_CALLBACK(icon_box_dnd_cb), status_box); |
326 g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); | 327 g_signal_connect(G_OBJECT(status_box->icon_box), "enter-notify-event", G_CALLBACK(icon_box_enter_cb), status_box); |
327 g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); | 328 g_signal_connect(G_OBJECT(status_box->icon_box), "leave-notify-event", G_CALLBACK(icon_box_leave_cb), status_box); |
328 g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); | 329 g_signal_connect(G_OBJECT(status_box->icon_box), "button-press-event", G_CALLBACK(icon_box_press_cb), status_box); |
329 | 330 |
1122 } | 1123 } |
1123 } | 1124 } |
1124 } | 1125 } |
1125 } | 1126 } |
1126 gtk_gaim_status_box_set_buddy_icon(box, filename); | 1127 gtk_gaim_status_box_set_buddy_icon(box, filename); |
1128 if (box->account == NULL) | |
1129 gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); | |
1127 } | 1130 } |
1128 | 1131 |
1129 box->buddy_icon_sel = NULL; | 1132 box->buddy_icon_sel = NULL; |
1130 } | 1133 } |
1131 | 1134 |
1296 GtkAllocation *allocation) | 1299 GtkAllocation *allocation) |
1297 { | 1300 { |
1298 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); | 1301 GtkGaimStatusBox *status_box = GTK_GAIM_STATUS_BOX(widget); |
1299 GtkRequisition req = {0,0}; | 1302 GtkRequisition req = {0,0}; |
1300 GtkAllocation parent_alc, box_alc, icon_alc; | 1303 GtkAllocation parent_alc, box_alc, icon_alc; |
1301 GdkPixbuf *scaled; | |
1302 gint border_width = GTK_CONTAINER (widget)->border_width; | 1304 gint border_width = GTK_CONTAINER (widget)->border_width; |
1303 | 1305 |
1304 combo_box_size_request(widget, &req); | 1306 combo_box_size_request(widget, &req); |
1305 | 1307 |
1306 box_alc = *allocation; | 1308 box_alc = *allocation; |
1307 | 1309 |
1308 box_alc.width -= (border_width * 2); | 1310 box_alc.width -= (border_width * 2); |
1309 box_alc.height = MAX(1, ((allocation->height - req.height) - (border_width*2))); | 1311 box_alc.height = MAX(1, ((allocation->height - req.height) - (border_width*2))); |
1310 box_alc.x += border_width; | 1312 box_alc.x += border_width; |
1311 box_alc.y += req.height + border_width; | 1313 box_alc.y += req.height + border_width; |
1312 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); | 1314 gtk_widget_size_allocate((GTK_GAIM_STATUS_BOX(widget))->vbox, &box_alc); |
1329 parent_alc.x += icon_alc.width + border_width; | 1331 parent_alc.x += icon_alc.width + border_width; |
1330 } else { | 1332 } else { |
1331 icon_alc.x = allocation->width - (icon_alc.width + border_width); | 1333 icon_alc.x = allocation->width - (icon_alc.width + border_width); |
1332 } | 1334 } |
1333 icon_alc.y += border_width; | 1335 icon_alc.y += border_width; |
1334 | 1336 |
1335 if (status_box->icon_size != icon_alc.height) | 1337 if (status_box->icon_size != icon_alc.height) |
1336 { | 1338 { |
1337 if (status_box->buddy_icon_hover) | |
1338 g_object_unref(status_box->buddy_icon_hover); | |
1339 if ((status_box->buddy_icon_path != NULL) && | |
1340 (*status_box->buddy_icon_path != '\0')) | |
1341 { | |
1342 scaled = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, | |
1343 icon_alc.height, icon_alc.width, FALSE, NULL); | |
1344 if (scaled != NULL) | |
1345 { | |
1346 status_box->buddy_icon_hover = gdk_pixbuf_copy(scaled); | |
1347 do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); | |
1348 if (status_box->buddy_icon) | |
1349 g_object_unref(status_box->buddy_icon); | |
1350 status_box->buddy_icon = scaled; | |
1351 gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); | |
1352 } | |
1353 } | |
1354 status_box->icon_size = icon_alc.height; | 1339 status_box->icon_size = icon_alc.height; |
1340 gtk_gaim_status_box_redisplay_buddy_icon(status_box); | |
1355 } | 1341 } |
1356 gtk_widget_size_allocate(status_box->icon_box, &icon_alc); | 1342 gtk_widget_size_allocate(status_box->icon_box, &icon_alc); |
1357 } | 1343 } |
1358 | 1344 |
1359 combo_box_size_allocate(widget, &parent_alc); | 1345 combo_box_size_allocate(widget, &parent_alc); |
1495 return; | 1481 return; |
1496 status_box->connecting = connecting; | 1482 status_box->connecting = connecting; |
1497 gtk_gaim_status_box_refresh(status_box); | 1483 gtk_gaim_status_box_refresh(status_box); |
1498 } | 1484 } |
1499 | 1485 |
1486 static void | |
1487 gtk_gaim_status_box_redisplay_buddy_icon(GtkGaimStatusBox *status_box) | |
1488 { | |
1489 | |
1490 /* This is sometimes called before the box is shown, and we will not have a size */ | |
1491 if (status_box->icon_size <= 0) | |
1492 return; | |
1493 | |
1494 if (status_box->buddy_icon) | |
1495 g_object_unref(status_box->buddy_icon); | |
1496 if (status_box->buddy_icon_hover) | |
1497 g_object_unref(status_box->buddy_icon_hover); | |
1498 status_box->buddy_icon = NULL; | |
1499 status_box->buddy_icon_hover = NULL; | |
1500 | |
1501 if ((status_box->buddy_icon_path != NULL) && | |
1502 (*status_box->buddy_icon_path != '\0')) | |
1503 status_box->buddy_icon = gdk_pixbuf_new_from_file_at_scale(status_box->buddy_icon_path, | |
1504 status_box->icon_size, status_box->icon_size, FALSE, NULL); | |
1505 | |
1506 if (status_box->buddy_icon == NULL) | |
1507 { | |
1508 /* Show a placeholder icon */ | |
1509 gchar *filename; | |
1510 filename = g_build_filename(DATADIR, "pixmaps", | |
1511 "gaim", "insert-image.png", NULL); | |
1512 status_box->buddy_icon = gdk_pixbuf_new_from_file(filename, NULL); | |
1513 g_free(filename); | |
1514 } | |
1515 | |
1516 if (status_box->buddy_icon != NULL) { | |
1517 gtk_image_set_from_pixbuf(GTK_IMAGE(status_box->icon), status_box->buddy_icon); | |
1518 status_box->buddy_icon_hover = gdk_pixbuf_copy(status_box->buddy_icon); | |
1519 do_colorshift(status_box->buddy_icon_hover, status_box->buddy_icon_hover, 30); | |
1520 } | |
1521 } | |
1522 | |
1500 void | 1523 void |
1501 gtk_gaim_status_box_set_buddy_icon(GtkGaimStatusBox *box, const char *filename) | 1524 gtk_gaim_status_box_set_buddy_icon(GtkGaimStatusBox *status_box, const char *filename) |
1502 { | 1525 { |
1503 GdkPixbuf *scaled; | 1526 g_free(status_box->buddy_icon_path); |
1504 g_free(box->buddy_icon_path); | 1527 status_box->buddy_icon_path = g_strdup(filename); |
1505 box->buddy_icon_path = g_strdup(filename); | 1528 |
1506 | 1529 gtk_gaim_status_box_redisplay_buddy_icon(status_box); |
1507 if ((filename != NULL) && (*filename != '\0')) | |
1508 { | |
1509 if (box->buddy_icon != NULL) | |
1510 g_object_unref(box->buddy_icon); | |
1511 | |
1512 /* This will get called before the box is shown and will not have a size */ | |
1513 if (box->icon_size > 0) { | |
1514 scaled = gdk_pixbuf_new_from_file_at_scale(filename, | |
1515 box->icon_size, box->icon_size, FALSE, NULL); | |
1516 if (scaled != NULL) | |
1517 { | |
1518 box->buddy_icon_hover = gdk_pixbuf_copy(scaled); | |
1519 do_colorshift(box->buddy_icon_hover, box->buddy_icon_hover, 30); | |
1520 box->buddy_icon = scaled; | |
1521 gtk_image_set_from_pixbuf(GTK_IMAGE(box->icon), box->buddy_icon); | |
1522 } | |
1523 } | |
1524 } | |
1525 | |
1526 if (box->account == NULL) | |
1527 gaim_prefs_set_string("/gaim/gtk/accounts/buddyicon", filename); | |
1528 } | 1530 } |
1529 | 1531 |
1530 const char* | 1532 const char* |
1531 gtk_gaim_status_box_get_buddy_icon(GtkGaimStatusBox *box) | 1533 gtk_gaim_status_box_get_buddy_icon(GtkGaimStatusBox *box) |
1532 { | 1534 { |