#include <gtk/gtkentry.h>
#include <gtk/gtktable.h>
+#include "alertpanel.h"
#include "mgutils.h"
#include "addressbook.h"
#include "addressitem.h"
static void addressbook_edit_person_unset_picture (void *obj, guint action, void *data)
{
- personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
- gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+ GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+ gdk_pixbuf_fill(pixbuf, 0xffffff00);
personeditdlg.picture_set = FALSE;
- gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
+ gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), pixbuf);
+ g_object_unref(pixbuf);
}
static GtkItemFactoryEntry editaddr_popup_entries[] =
if (event->button == 1) {
if ( (filename = filesel_select_file_open(_("Choose a picture"), NULL)) ) {
- personeditdlg.pixbuf = gdk_pixbuf_new_from_file(filename, &error);
- personeditdlg.picture_set = TRUE;
- g_free(filename);
- width = gdk_pixbuf_get_width(personeditdlg.pixbuf);
- height = gdk_pixbuf_get_height(personeditdlg.pixbuf);
+ GdkPixbuf *pixbuf = NULL;
+ gdk_pixbuf_get_file_info(filename, &width, &height);
if ( width > 128 || height > 128 ) {
if (width > height) {
scalewidth = (width * 128) / height;
scaleheight = 128;
}
- personeditdlg.pixbuf = gdk_pixbuf_scale_simple(personeditdlg.pixbuf, scalewidth, scaleheight, GDK_INTERP_BILINEAR);
+ pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
+ scalewidth, scaleheight, TRUE, &error);
+ } else {
+ pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+ }
+ if (error) {
+ alertpanel_error(_("Failed to import image: \n%s"),
+ error->message);
+ g_error_free(error);
+ error = NULL;
}
- gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
+ personeditdlg.picture_set = TRUE;
+ g_free(filename);
+ gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), pixbuf);
+ g_object_unref(pixbuf);
}
} else {
gtk_menu_popup(GTK_MENU(personeditdlg.editaddr_popupmenu),
const gchar *locale;
gint top = 0;
gint n_entries;
-
+ GdkPixbuf *pixbuf;
vbox = gtk_vbox_new( FALSE, 20 );
hbox = gtk_hbox_new( FALSE, 8 );
frame_picture = gtk_frame_new("Photo");
/* Room for a photo */
- personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
- gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+ gdk_pixbuf_fill(pixbuf, 0xffffff00);
personeditdlg.picture_set = FALSE;
- personeditdlg.image = gtk_image_new_from_pixbuf(personeditdlg.pixbuf);
-
+ personeditdlg.image = gtk_image_new_from_pixbuf(pixbuf);
+ g_object_unref(pixbuf);
+
gtk_container_add(GTK_CONTAINER(ebox_picture), personeditdlg.image);
gtk_container_add(GTK_CONTAINER(frame_picture), ebox_picture);
gtk_container_add(GTK_CONTAINER( personeditdlg.notebook ), hbox );
{
GList *listEMail = NULL;
GList *listAttrib = NULL;
- GError *error;
+ GError *error = NULL;
gchar *cn = NULL;
listEMail = edit_person_build_email_list();
gchar *name;
addritem_person_set_common_name( current_person, cn );
if (personeditdlg.picture_set) {
+ GdkPixbuf * pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(personeditdlg.image));
name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- ADDRITEM_ID(current_person), NULL );
- gdk_pixbuf_save(personeditdlg.pixbuf, name, "png", &error, NULL);
+ ADDRITEM_ID(current_person), ".png", NULL );
+ gdk_pixbuf_save(pixbuf, name, "png", &error, NULL);
+ if (error) {
+ alertpanel_error(_("Failed to save image: \n%s"),
+ error->message);
+ g_error_free(error);
+ }
addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
g_free( name );
} else {
name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- ADDRITEM_ID(current_person), NULL );
+ ADDRITEM_ID(current_person), ".png", NULL );
g_unlink(name);
g_free(name);
}
gboolean get_focus) {
static gboolean cancelled;
GError *error = NULL;
-
+ GdkPixbuf *pixbuf;
/* set transient data */
current_abf = abf;
current_person = person;
current_parent_folder = parent_folder;
edit_person_close_post_update_cb = post_update_cb;
personeditdlg.ldap = (abf && abf->type == ADBOOKTYPE_LDAP)? TRUE : FALSE;
- if( !personeditdlg.container )
- addressbook_edit_person_create(parent_container, &cancelled);
+
+ if( personeditdlg.container ) {
+ gtk_widget_destroy(personeditdlg.container);
+ personeditdlg.container = NULL;
+ }
+ addressbook_edit_person_create(parent_container, &cancelled);
/* typically, get focus when dialog mode is enabled, or when editing a new address */
if( get_focus ) {
if( current_person->picture ) {
gchar *filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S,
- current_person->picture, NULL );
+ current_person->picture, ".png", NULL );
if (is_file_exist(filename)) {
- personeditdlg.pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+ pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+ if (error) {
+ debug_print("Failed to import image: \n%s",
+ error->message);
+ g_error_free(error);
+ goto no_img;
+ }
personeditdlg.picture_set = TRUE;
} else {
- personeditdlg.picture_set = FALSE;
- personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
- gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+ goto no_img;
}
g_free(filename);
} else {
+no_img:
personeditdlg.picture_set = FALSE;
- personeditdlg.pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
- gdk_pixbuf_fill(personeditdlg.pixbuf, 0xffffff00);
+ pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 48, 48);
+ gdk_pixbuf_fill(pixbuf, 0xffffff00);
}
- gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), personeditdlg.pixbuf);
+ gtk_image_set_from_pixbuf(GTK_IMAGE(personeditdlg.image), pixbuf);
+ g_object_unref(pixbuf);
+ pixbuf = NULL;
if( current_person->firstName )
gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), current_person->firstName );