aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--addressbook/ChangeLog20
-rw-r--r--addressbook/gui/contact-editor/contact-editor.glade6
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c44
-rw-r--r--addressbook/gui/contact-list-editor/contact-list-editor.glade2
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-editor.c281
-rw-r--r--addressbook/gui/contact-list-editor/e-contact-list-editor.h5
-rw-r--r--addressbook/gui/widgets/eab-gui-util.c24
-rw-r--r--addressbook/gui/widgets/eab-gui-util.h3
8 files changed, 118 insertions, 267 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 8bc56d21ba..1a8868092e 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,3 +1,23 @@
+2004-01-30 Chris Toshok <toshok@ximian.com>
+
+ * gui/contact-editor/e-contact-editor.c: enable d&d drop photos.
+
+ * gui/contact-editor/contact-editor.glade: use
+ eab_create_image_chooser_widget for the d&d'able image.
+
+ * gui/contact-list-editor/e-contact-list-editor.c: abstract out
+ all the d&d image support (it's now in
+ widgets/misc/e-image-chooser.[ch]).
+
+ * gui/contact-list-editor/contact-list-editor.glade: use
+ eab_create_image_chooser_widget for the d&d'able image.
+
+ * gui/widgets/eab-gui-util.c (eab_create_image_chooser_widget):
+ new function.
+
+ * gui/widgets/eab-gui-util.h: add prototype for
+ eab_create_image_chooser_widget.
+
2004-01-29 Hans Petter Jansson <hpj@ximian.com>
* gui/widgets/eab-gui-util.c (source_selection_changed_cb): Implement.
diff --git a/addressbook/gui/contact-editor/contact-editor.glade b/addressbook/gui/contact-editor/contact-editor.glade
index 91e0658ef7..6b0d2fed31 100644
--- a/addressbook/gui/contact-editor/contact-editor.glade
+++ b/addressbook/gui/contact-editor/contact-editor.glade
@@ -1503,14 +1503,14 @@
</child>
<child>
- <widget class="Custom" id="custom1">
+ <widget class="Custom" id="image-chooser">
<property name="visible">True</property>
- <property name="creation_function">e_create_image_widget</property>
+ <property name="creation_function">eab_create_image_chooser_widget</property>
<property name="string1">malehead.png</property>
<property name="string2"></property>
<property name="int1">0</property>
<property name="int2">0</property>
- <property name="last_modification_time">Thu, 18 May 2000 12:19:47 GMT</property>
+ <property name="last_modification_time">Sat, 24 Jan 2004 19:28:18 GMT</property>
</widget>
<packing>
<property name="left_attach">0</property>
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index 5be1450ca7..0e60e5dea5 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -58,6 +58,7 @@
#include "addressbook/gui/widgets/eab-gui-util.h"
#include "e-util/e-gui-utils.h"
#include "widgets/misc/e-dateedit.h"
+#include "widgets/misc/e-image-chooser.h"
#include "widgets/misc/e-url-entry.h"
#include "widgets/misc/e-source-option-menu.h"
#include "shell/evolution-shell-component-utils.h"
@@ -1329,6 +1330,12 @@ set_entry_changed_signals(EContactEditor *editor)
g_signal_connect (widget, "changed",
G_CALLBACK (widget_changed), editor);
}
+
+ widget = glade_xml_get_widget (editor->gui, "image-chooser");
+ if (widget && E_IS_IMAGE_CHOOSER (widget)) {
+ g_signal_connect (widget, "changed",
+ G_CALLBACK (widget_changed), editor);
+ }
}
static void
@@ -3179,6 +3186,10 @@ set_editable (EContactEditor *editor)
entry = "text-address";
enable_widget (glade_xml_get_widget(editor->gui, entry),
editor->target_editable);
+
+ entry = "image-chooser";
+ enable_widget (glade_xml_get_widget(editor->gui, entry),
+ editor->target_editable);
}
static void
@@ -3190,6 +3201,7 @@ fill_in_info(EContactEditor *editor)
EContactName *name;
EContactDate *anniversary;
EContactDate *bday;
+ EContactPhoto *photo;
int i;
GtkWidget *widget;
gboolean wants_html;
@@ -3200,6 +3212,7 @@ fill_in_info(EContactEditor *editor)
"anniversary", &anniversary,
"birth_date", &bday,
"wants_html", &wants_html,
+ "photo", &photo,
NULL);
for (i = 0; i < sizeof(field_mapping) / sizeof(field_mapping[0]); i++) {
@@ -3253,8 +3266,15 @@ fill_in_info(EContactEditor *editor)
e_date_edit_set_time (dateedit, -1);
}
+ if (photo) {
+ widget = glade_xml_get_widget(editor->gui, "image-chooser");
+ if (widget && E_IS_IMAGE_CHOOSER(widget))
+ e_image_chooser_set_image_data (E_IMAGE_CHOOSER (widget), photo->data, photo->length);
+ }
+
e_contact_date_free (anniversary);
e_contact_date_free (bday);
+ e_contact_photo_free (photo);
set_fields(editor);
@@ -3346,6 +3366,27 @@ extract_info(EContactEditor *editor)
} else
e_contact_set (contact, E_CONTACT_BIRTH_DATE, NULL);
}
+
+ widget = glade_xml_get_widget (editor->gui, "image-chooser");
+ if (widget && E_IS_IMAGE_CHOOSER (widget)) {
+ char *image_data;
+ gsize image_data_len;
+
+ if (e_image_chooser_get_image_data (E_IMAGE_CHOOSER (widget),
+ &image_data,
+ &image_data_len)) {
+ EContactPhoto photo;
+
+ photo.data = image_data;
+ photo.length = image_data_len;
+
+ e_contact_set (contact, E_CONTACT_PHOTO, &photo);
+ g_free (image_data);
+ }
+ else {
+ e_contact_set (contact, E_CONTACT_PHOTO, NULL);
+ }
+ }
}
}
@@ -3454,6 +3495,9 @@ enable_widget (GtkWidget *widget, gboolean enabled)
else if (E_IS_DATE_EDIT (widget)) {
e_date_edit_set_editable (E_DATE_EDIT (widget), enabled);
}
+ else if (E_IS_IMAGE_CHOOSER (widget)) {
+ e_image_chooser_set_editable (E_IMAGE_CHOOSER (widget), enabled);
+ }
else
gtk_widget_set_sensitive (widget, enabled);
}
diff --git a/addressbook/gui/contact-list-editor/contact-list-editor.glade b/addressbook/gui/contact-list-editor/contact-list-editor.glade
index 002e697105..ebe7dcb1d0 100644
--- a/addressbook/gui/contact-list-editor/contact-list-editor.glade
+++ b/addressbook/gui/contact-list-editor/contact-list-editor.glade
@@ -80,7 +80,7 @@
<child>
<widget class="Custom" id="list-image">
<property name="visible">True</property>
- <property name="creation_function">e_create_image_widget</property>
+ <property name="creation_function">eab_create_image_chooser_widget</property>
<property name="string1">evolution-contacts-plain.png</property>
<property name="int1">0</property>
<property name="int2">0</property>
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.c b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
index 60ed1cf4f6..c8df169c70 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.c
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.c
@@ -33,6 +33,8 @@
#include <libgnomevfs/gnome-vfs-ops.h>
#include "shell/evolution-shell-component-utils.h"
+#include "widgets/misc/e-image-chooser.h"
+
#include "addressbook/gui/widgets/eab-gui-util.h"
#include "addressbook/util/eab-book-util.h"
@@ -65,6 +67,7 @@ static void fill_in_info(EContactListEditor *editor);
static void add_email_cb (GtkWidget *w, EContactListEditor *editor);
static void remove_entry_cb (GtkWidget *w, EContactListEditor *editor);
static void list_name_changed_cb (GtkWidget *w, EContactListEditor *editor);
+static void list_image_changed_cb (GtkWidget *w, EContactListEditor *editor);
static void visible_addrs_toggled_cb (GtkWidget *w, EContactListEditor *editor);
static gint app_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data);
@@ -77,17 +80,6 @@ static void table_drag_data_received_cb (ETable *table, int row, int col,
gint x, gint y,
GtkSelectionData *selection_data, guint info, guint time,
EContactListEditor *editor);
-static gboolean image_drag_motion_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y, guint time, EContactListEditor *editor);
-static gboolean image_drag_drop_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y, guint time, EContactListEditor *editor);
-static void image_drag_data_received_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y,
- GtkSelectionData *selection_data,
- guint info, guint time, EContactListEditor *editor);
static GtkObjectClass *parent_class = NULL;
@@ -95,21 +87,14 @@ static guint contact_list_editor_signals[LAST_SIGNAL];
enum DndTargetType {
DND_TARGET_TYPE_VCARD,
- DND_TARGET_TYPE_URI_LIST
};
#define VCARD_TYPE "text/x-vcard"
-#define URI_LIST_TYPE "text/uri-list"
static GtkTargetEntry list_drag_types[] = {
{ VCARD_TYPE, 0, DND_TARGET_TYPE_VCARD },
};
static const int num_list_drag_types = sizeof (list_drag_types) / sizeof (list_drag_types[0]);
-static GtkTargetEntry image_drag_types[] = {
- { URI_LIST_TYPE, 0, DND_TARGET_TYPE_URI_LIST },
-};
-static const int num_image_drag_types = sizeof (image_drag_types) / sizeof (image_drag_types[0]);
-
/* The arguments we take */
enum {
PROP_0,
@@ -232,9 +217,7 @@ e_contact_list_editor_init (EContactListEditor *editor)
GtkWidget *bonobo_win;
BonoboUIContainer *container;
char *icon_path;
- GdkPixbuf *pixbuf;
- editor->image_buf = NULL;
editor->contact = NULL;
editor->changed = FALSE;
editor->editable = TRUE;
@@ -258,16 +241,8 @@ e_contact_list_editor_init (EContactListEditor *editor)
editor->email_entry = glade_xml_get_widget (gui, "email-entry");
editor->list_name_entry = glade_xml_get_widget (gui, "list-name-entry");
editor->list_image = glade_xml_get_widget (gui, "list-image");
- if (GTK_IS_ALIGNMENT (editor->list_image)) {
- /* deal with the e_create_image_widget code, that wraps the image in an alignment */
- editor->list_image = GTK_BIN (editor->list_image)->child;
- }
editor->visible_addrs_checkbutton = glade_xml_get_widget (gui, "visible-addrs-checkbutton");
- pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (editor->list_image));
- editor->list_image_width = gdk_pixbuf_get_width (pixbuf);
- editor->list_image_height = gdk_pixbuf_get_height (pixbuf);
-
/* Construct the app */
bonobo_win = bonobo_window_new ("contact-list-editor", _("Contact List Editor"));
@@ -325,13 +300,8 @@ e_contact_list_editor_init (EContactListEditor *editor)
g_signal_connect (e_table_scrolled_get_table (E_TABLE_SCROLLED (editor->table)),
"table_drag_data_received", G_CALLBACK(table_drag_data_received_cb), editor);
- gtk_drag_dest_set (editor->list_image, 0, image_drag_types, num_image_drag_types, GDK_ACTION_COPY);
- g_signal_connect (editor->list_image,
- "drag_motion", G_CALLBACK (image_drag_motion_cb), editor);
g_signal_connect (editor->list_image,
- "drag_drop", G_CALLBACK (image_drag_drop_cb), editor);
- g_signal_connect (editor->list_image,
- "drag_data_received", G_CALLBACK (image_drag_data_received_cb), editor);
+ "changed", G_CALLBACK(list_image_changed_cb), editor);
command_state_changed (editor);
@@ -349,13 +319,6 @@ e_contact_list_editor_init (EContactListEditor *editor)
static void
e_contact_list_editor_dispose (GObject *object)
{
- EContactListEditor *cle = E_CONTACT_LIST_EDITOR (object);
-
- if (cle->image_buf) {
- g_free (cle->image_buf);
- cle->image_buf = NULL;
- }
-
if (G_OBJECT_CLASS (parent_class)->dispose)
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
}
@@ -810,6 +773,13 @@ list_name_changed_cb (GtkWidget *w, EContactListEditor *editor)
}
static void
+list_image_changed_cb (GtkWidget *w, EContactListEditor *editor)
+{
+ editor->changed = TRUE;
+ command_state_changed (editor);
+}
+
+static void
visible_addrs_toggled_cb (GtkWidget *w, EContactListEditor *editor)
{
editor->changed = TRUE;
@@ -943,219 +913,6 @@ table_drag_data_received_cb (ETable *table, int row, int col,
gtk_drag_finish (context, handled, FALSE, time);
}
-static gboolean
-set_image_from_data (EContactListEditor *editor,
- char *data, int length)
-{
- gboolean rv = FALSE;
- GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
- GdkPixbuf *pixbuf;
-
- gdk_pixbuf_loader_write (loader, data, length, NULL);
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
- if (pixbuf)
- gdk_pixbuf_ref (pixbuf);
- gdk_pixbuf_loader_close (loader, NULL);
- g_object_unref (loader);
-
- if (pixbuf) {
- GdkPixbuf *scaled;
- GdkPixbuf *composite;
-
- float scale;
- int new_height, new_width;
-
- new_height = gdk_pixbuf_get_height (pixbuf);
- new_width = gdk_pixbuf_get_width (pixbuf);
-
- printf ("new dimensions = (%d,%d)\n", new_width, new_height);
-
- if (editor->list_image_height < new_height
- || editor->list_image_width < new_width) {
- /* we need to scale down */
- printf ("we need to scale down\n");
- if (new_height > new_width)
- scale = (float)editor->list_image_height / new_height;
- else
- scale = (float)editor->list_image_width / new_width;
- }
- else {
- /* we need to scale up */
- printf ("we need to scale up\n");
- if (new_height > new_width)
- scale = (float)new_height / editor->list_image_height;
- else
- scale = (float)new_width / editor->list_image_width;
- }
-
- printf ("scale = %g\n", scale);
-
- new_width *= scale;
- new_height *= scale;
- new_width = MIN (new_width, editor->list_image_width);
- new_height = MIN (new_height, editor->list_image_height);
-
- printf ("new scaled dimensions = (%d,%d)\n", new_width, new_height);
-
- scaled = gdk_pixbuf_scale_simple (pixbuf,
- new_width, new_height,
- GDK_INTERP_BILINEAR);
-
- composite = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, gdk_pixbuf_get_bits_per_sample (pixbuf),
- editor->list_image_width, editor->list_image_height);
-
- gdk_pixbuf_fill (composite, 0x00000000);
-
- gdk_pixbuf_copy_area (scaled, 0, 0, new_width, new_height,
- composite,
- editor->list_image_width / 2 - new_width / 2,
- editor->list_image_height / 2 - new_height / 2);
-
- gtk_image_set_from_pixbuf (GTK_IMAGE (editor->list_image), composite);
- gdk_pixbuf_unref (pixbuf);
- gdk_pixbuf_unref (scaled);
- gdk_pixbuf_unref (composite);
-
- rv = TRUE;
- }
-
- return rv;
-}
-
-static gboolean
-image_drag_motion_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y, guint time, EContactListEditor *editor)
-{
- GList *p;
-
- for (p = context->targets; p != NULL; p = p->next) {
- char *possible_type;
-
- possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
- if (!strcmp (possible_type, URI_LIST_TYPE)) {
- g_free (possible_type);
- gdk_drag_status (context, GDK_ACTION_COPY, time);
- return TRUE;
- }
-
- g_free (possible_type);
- }
-
- return FALSE;
-}
-
-static gboolean
-image_drag_drop_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y, guint time, EContactListEditor *editor)
-{
- GList *p;
-
- if (context->targets == NULL)
- return FALSE;
-
-
- for (p = context->targets; p != NULL; p = p->next) {
- char *possible_type;
-
- possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
- if (!strcmp (possible_type, URI_LIST_TYPE)) {
- g_free (possible_type);
- gtk_drag_get_data (widget, context,
- GDK_POINTER_TO_ATOM (p->data),
- time);
- return TRUE;
- }
-
- g_free (possible_type);
- }
-
- return FALSE;
-}
-
-static void
-image_drag_data_received_cb (GtkWidget *widget,
- GdkDragContext *context,
- gint x, gint y,
- GtkSelectionData *selection_data,
- guint info, guint time, EContactListEditor *editor)
-{
- char *target_type;
- gboolean changed = FALSE;
- gboolean handled = FALSE;
-
- target_type = gdk_atom_name (selection_data->target);
-
- printf ("target_type == %s\n", target_type);
-
- if (!strcmp (target_type, URI_LIST_TYPE)) {
- GnomeVFSResult result;
- GnomeVFSHandle *handle;
- char *uri;
- char *nl = strstr (selection_data->data, "\r\n");
- char *buf = NULL;
- GnomeVFSFileInfo info;
-
- if (nl)
- uri = g_strndup (selection_data->data, nl - (char*)selection_data->data);
- else
- uri = g_strdup (selection_data->data);
-
- printf ("uri == %s\n", uri);
-
- result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
- if (result == GNOME_VFS_OK) {
- result = gnome_vfs_get_file_info_from_handle (handle, &info, GNOME_VFS_FILE_INFO_DEFAULT);
- if (result == GNOME_VFS_OK) {
- GnomeVFSFileSize num_left;
- GnomeVFSFileSize num_read;
- GnomeVFSFileSize total_read;
-
- printf ("file size = %d\n", (int)info.size);
- buf = g_malloc (info.size);
-
- num_left = info.size;
- total_read = 0;
-
- while ((result = gnome_vfs_read (handle, buf + total_read, num_left, &num_read)) == GNOME_VFS_OK) {
- num_left -= num_read;
- total_read += num_read;
- }
-
- printf ("read %d bytes\n", (int)total_read);
- if (set_image_from_data (editor, buf, total_read)) {
- changed = TRUE;
- handled = TRUE;
- g_free (editor->image_buf);
- editor->image_buf = buf;
- editor->image_buf_size = total_read;
- }
- else {
- /* XXX we should pop up a
- warning dialog here */
- g_free (buf);
- }
- }
-
- gnome_vfs_close (handle);
- }
- else {
- printf ("gnome_vfs_open failed (%s)\n", gnome_vfs_result_to_string (result));
- }
-
- g_free (uri);
-
- if (changed) {
- editor->changed = TRUE;
- command_state_changed (editor);
- }
- }
-
- gtk_drag_finish (context, handled, FALSE, time);
-}
-
static void
command_state_changed (EContactListEditor *editor)
{
@@ -1184,6 +941,8 @@ extract_info(EContactListEditor *editor)
if (contact) {
int i;
GList *email_list;
+ char *image_data;
+ gsize image_data_len;
char *string = gtk_editable_get_chars(GTK_EDITABLE (editor->list_name_entry), 0, -1);
if (string && *string) {
@@ -1211,13 +970,19 @@ extract_info(EContactListEditor *editor)
g_list_foreach (email_list, (GFunc) g_free, NULL);
g_list_free (email_list);
- if (editor->image_buf) {
+ if (e_image_chooser_get_image_data (E_IMAGE_CHOOSER (editor->list_image),
+ &image_data,
+ &image_data_len)) {
EContactPhoto photo;
- photo.data = editor->image_buf;
- photo.length = editor->image_buf_size;
+ photo.data = image_data;
+ photo.length = image_data_len;
e_contact_set (contact, E_CONTACT_LOGO, &photo);
+ g_free (image_data);
+ }
+ else {
+ e_contact_set (contact, E_CONTACT_LOGO, NULL);
}
}
}
@@ -1266,7 +1031,7 @@ fill_in_info(EContactListEditor *editor)
photo = e_contact_get (editor->contact, E_CONTACT_LOGO);
if (photo) {
- set_image_from_data (editor, photo->data, photo->length);
+ e_image_chooser_set_image_data (E_IMAGE_CHOOSER (editor->list_image), photo->data, photo->length);
e_contact_photo_free (photo);
}
}
diff --git a/addressbook/gui/contact-list-editor/e-contact-list-editor.h b/addressbook/gui/contact-list-editor/e-contact-list-editor.h
index 52e78a6a23..f9293116b6 100644
--- a/addressbook/gui/contact-list-editor/e-contact-list-editor.h
+++ b/addressbook/gui/contact-list-editor/e-contact-list-editor.h
@@ -64,11 +64,6 @@ struct _EContactListEditor
GtkWidget *list_image_button;
GtkWidget *visible_addrs_checkbutton;
GtkWidget *list_image;
- int list_image_width;
- int list_image_height;
-
- char *image_buf;
- int image_buf_size;
/* Whether we are editing a new contact or an existing one */
guint is_new_list : 1;
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index 038c1454fc..2459b5c483 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -30,6 +30,7 @@
#include "eab-gui-util.h"
#include "util/eab-book-util.h"
#include "util/eab-destination.h"
+#include "widgets/misc/e-image-chooser.h"
#include "widgets/misc/e-source-selector.h"
#include <gnome.h>
@@ -859,3 +860,26 @@ eab_send_contact (EContact *contact, EABDisposition disposition)
eab_send_contact_list (list, disposition);
g_list_free (list);
}
+
+GtkWidget *
+eab_create_image_chooser_widget(gchar *name,
+ gchar *string1, gchar *string2,
+ gint int1, gint int2)
+{
+ char *filename;
+ GtkWidget *w = NULL;
+ if (string1) {
+ if (*string1 == '/')
+ filename = g_strdup(string1);
+ else
+ filename = g_build_filename (EVOLUTION_IMAGESDIR, string1, NULL);
+
+ w = e_image_chooser_new ();
+ e_image_chooser_set_from_file (E_IMAGE_CHOOSER (w), filename);
+
+ gtk_widget_show_all (w);
+ g_free (filename);
+ }
+
+ return w;
+}
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 53700bed1f..5f96bc740c 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -65,6 +65,9 @@ void eab_send_contact (EContact *contact,
void eab_send_contact_list (GList *contacts,
EABDisposition disposition);
+GtkWidget *eab_create_image_chooser_widget (gchar *name, gchar *string1, gchar *string2, gint int1, gint int2);
+
+
ESource *eab_select_source (const gchar *title, const gchar *message,
const gchar *select_uid, GtkWindow *parent);