2004-11-03 20:29:08 +00:00
|
|
|
/* gnome-about-me.c
|
|
|
|
* Copyright (C) 2002 Diego Gonzalez
|
|
|
|
*
|
|
|
|
* Written by: Diego Gonzalez <diego@pemas.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-04-30 17:14:47 +00:00
|
|
|
#include <glib/gstdio.h>
|
2004-11-03 20:29:08 +00:00
|
|
|
#include <gnome.h>
|
|
|
|
#include <pwd.h>
|
2005-11-22 04:46:43 +00:00
|
|
|
#include <libgnomevfs/gnome-vfs.h>
|
|
|
|
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
|
|
|
#include <libgnomevfs/gnome-vfs-mime-utils.h>
|
|
|
|
#include <libgnomeui/gnome-thumbnail.h>
|
2004-11-03 20:29:08 +00:00
|
|
|
#include <gconf/gconf-client.h>
|
|
|
|
#include <glade/glade.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libebook/e-book.h>
|
|
|
|
|
|
|
|
#include "e-image-chooser.h"
|
|
|
|
#include "gnome-about-me-password.h"
|
|
|
|
|
|
|
|
#include "capplet-util.h"
|
|
|
|
|
2005-07-13 20:28:10 +00:00
|
|
|
#define MAX_HEIGHT 150
|
|
|
|
#define MAX_WIDTH 150
|
2005-07-13 20:16:13 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
typedef struct {
|
2005-06-23 11:27:21 +00:00
|
|
|
EContact *contact;
|
|
|
|
EBook *book;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
GladeXML *dialog;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
GtkIconTheme *theme;
|
2005-11-22 04:46:43 +00:00
|
|
|
GnomeThumbnailFactory *thumbs;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
EContactAddress *addr1;
|
|
|
|
EContactAddress *addr2;
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
gboolean have_image;
|
|
|
|
gboolean image_changed;
|
|
|
|
gboolean create_self;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
gchar *person;
|
|
|
|
gchar *login;
|
|
|
|
gchar *username;
|
2005-06-15 00:25:55 +00:00
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
guint commit_timeout_id;
|
2004-11-03 20:29:08 +00:00
|
|
|
} GnomeAboutMe;
|
|
|
|
|
2007-02-07 21:41:41 +00:00
|
|
|
static GnomeAboutMe *me = NULL;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
struct WidToCid{
|
|
|
|
gchar *wid;
|
|
|
|
guint cid;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ADDRESS_STREET = 1,
|
|
|
|
ADDRESS_POBOX,
|
|
|
|
ADDRESS_LOCALITY,
|
|
|
|
ADDRESS_CODE,
|
|
|
|
ADDRESS_REGION,
|
|
|
|
ADDRESS_COUNTRY
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ADDRESS_HOME 21
|
|
|
|
#define ADDRESS_WORK 27
|
|
|
|
|
|
|
|
struct WidToCid ids[] = {
|
|
|
|
|
|
|
|
{ "email-work-e", E_CONTACT_EMAIL_1 }, /* 00 */
|
|
|
|
{ "email-home-e", E_CONTACT_EMAIL_2 }, /* 01 */
|
|
|
|
|
|
|
|
{ "phone-home-e", E_CONTACT_PHONE_HOME }, /* 02 */
|
|
|
|
{ "phone-mobile-e", E_CONTACT_PHONE_MOBILE }, /* 03 */
|
|
|
|
{ "phone-work-e", E_CONTACT_PHONE_BUSINESS }, /* 04 */
|
|
|
|
{ "phone-work-fax-e", E_CONTACT_PHONE_BUSINESS_FAX }, /* 05 */
|
|
|
|
|
|
|
|
{ "im-jabber-e", E_CONTACT_IM_JABBER_HOME_1 }, /* 06 */
|
|
|
|
{ "im-msn-e", E_CONTACT_IM_MSN_HOME_1 }, /* 07 */
|
|
|
|
{ "im-icq-e", E_CONTACT_IM_ICQ_HOME_1 }, /* 08 */
|
|
|
|
{ "im-yahoo-e", E_CONTACT_IM_YAHOO_HOME_1 }, /* 09 */
|
|
|
|
{ "im-aim-e", E_CONTACT_IM_AIM_HOME_1 }, /* 10 */
|
|
|
|
{ "im-groupwise-e", E_CONTACT_IM_GROUPWISE_HOME_1 }, /* 11 */
|
|
|
|
|
|
|
|
{ "web-homepage-e", E_CONTACT_HOMEPAGE_URL }, /* 12 */
|
|
|
|
{ "web-calendar-e", E_CONTACT_CALENDAR_URI }, /* 13 */
|
|
|
|
{ "web-weblog-e", E_CONTACT_BLOG_URL }, /* 14 */
|
|
|
|
|
|
|
|
{ "job-profession-e", E_CONTACT_ROLE }, /* 15 */
|
|
|
|
{ "job-title-e", E_CONTACT_TITLE }, /* 16 */
|
|
|
|
{ "job-dept-e", E_CONTACT_ORG_UNIT }, /* 17 */
|
|
|
|
{ "job-assistant-e", E_CONTACT_ASSISTANT }, /* 18 */
|
|
|
|
{ "job-company-e", E_CONTACT_ORG }, /* 19 */
|
|
|
|
{ "job-manager-e", E_CONTACT_MANAGER }, /* 20 */
|
|
|
|
|
|
|
|
{ "addr-street-1", ADDRESS_STREET }, /* 21 */
|
|
|
|
{ "addr-po-1", ADDRESS_POBOX }, /* 22 */
|
|
|
|
{ "addr-locality-1", ADDRESS_LOCALITY }, /* 23 */
|
|
|
|
{ "addr-code-1", ADDRESS_CODE }, /* 24 */
|
|
|
|
{ "addr-region-1", ADDRESS_REGION }, /* 25 */
|
|
|
|
{ "addr-country-1", ADDRESS_COUNTRY }, /* 26 */
|
|
|
|
|
|
|
|
{ "addr-street-2", ADDRESS_STREET }, /* 27 */
|
|
|
|
{ "addr-po-2", ADDRESS_POBOX }, /* 28 */
|
|
|
|
{ "addr-locality-2", ADDRESS_LOCALITY }, /* 29 */
|
|
|
|
{ "addr-code-2", ADDRESS_CODE }, /* 30 */
|
|
|
|
{ "addr-region-2", ADDRESS_REGION }, /* 31 */
|
|
|
|
{ "addr-country-2", ADDRESS_COUNTRY }, /* 32 */
|
|
|
|
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void about_me_set_address_field (EContactAddress *, guint, gchar *);
|
|
|
|
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
/*** Utility functions ***/
|
|
|
|
static void
|
2005-07-05 10:34:49 +00:00
|
|
|
about_me_error (GtkWindow *parent, gchar *str)
|
2005-06-23 11:27:21 +00:00
|
|
|
{
|
2005-07-05 10:34:49 +00:00
|
|
|
GtkWidget *dialog;
|
2005-06-23 11:27:21 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
dialog = gtk_message_dialog_new (parent,
|
|
|
|
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_OK, str);
|
2005-06-23 11:27:21 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
2005-06-23 11:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
/********************/
|
2007-02-07 21:41:41 +00:00
|
|
|
static void
|
|
|
|
about_me_destroy (GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
e_contact_address_free (me->addr1);
|
|
|
|
e_contact_address_free (me->addr2);
|
|
|
|
|
|
|
|
if (me->contact)
|
|
|
|
g_object_unref (me->contact);
|
|
|
|
if (me->book)
|
|
|
|
g_object_unref (me->book);
|
|
|
|
if (me->dialog)
|
|
|
|
g_object_unref (me->dialog);
|
|
|
|
|
|
|
|
g_free (me->person);
|
|
|
|
g_free (me->login);
|
|
|
|
g_free (me->username);
|
|
|
|
g_free (me);
|
|
|
|
}
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
static void
|
|
|
|
about_me_commit (GnomeAboutMe *me)
|
|
|
|
{
|
2005-06-23 11:27:21 +00:00
|
|
|
EContactName *name;
|
2005-07-13 10:46:56 +00:00
|
|
|
GError *error;
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
char *strings[4], **stringptr;
|
2005-07-13 10:46:56 +00:00
|
|
|
char *fileas;
|
2005-06-23 11:27:21 +00:00
|
|
|
|
2005-07-13 10:46:56 +00:00
|
|
|
name = NULL;
|
|
|
|
error = NULL;
|
2005-06-23 11:27:21 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
if (me->create_self) {
|
2005-06-23 11:27:21 +00:00
|
|
|
if (me->username == NULL)
|
|
|
|
fileas = g_strdup ("Myself");
|
|
|
|
else {
|
|
|
|
name = e_contact_name_from_string (me->username);
|
|
|
|
|
|
|
|
stringptr = strings;
|
|
|
|
if (name->family && *name->family)
|
|
|
|
*(stringptr++) = name->family;
|
|
|
|
if (name->given && *name->given)
|
|
|
|
*(stringptr++) = name->given;
|
|
|
|
*stringptr = NULL;
|
|
|
|
fileas = g_strjoinv (", ", strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
e_contact_set (me->contact, E_CONTACT_FILE_AS, fileas);
|
2004-11-03 20:29:08 +00:00
|
|
|
e_contact_set (me->contact, E_CONTACT_NICKNAME, "nickname");
|
2005-06-23 11:27:21 +00:00
|
|
|
e_contact_set (me->contact, E_CONTACT_FULL_NAME, me->username);
|
|
|
|
|
|
|
|
e_contact_name_free (name);
|
|
|
|
g_free (fileas);
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (me->create_self) {
|
|
|
|
e_book_add_contact (me->book, me->contact, &error);
|
|
|
|
e_book_set_self (me->book, me->contact, &error);
|
|
|
|
} else {
|
|
|
|
if (e_book_commit_contact (me->book, me->contact, &error) == FALSE)
|
2005-07-05 10:34:49 +00:00
|
|
|
g_print ("There was an undetermined error\n");
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
me->create_self = FALSE;
|
|
|
|
}
|
|
|
|
|
2005-06-15 00:25:55 +00:00
|
|
|
static gboolean
|
|
|
|
about_me_commit_from_timeout (GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
about_me_commit (me);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
static gboolean
|
|
|
|
about_me_focus_out (GtkWidget *widget, GdkEventFocus *event, GnomeAboutMe *me)
|
|
|
|
{
|
2005-04-04 19:11:09 +00:00
|
|
|
gchar *str = NULL;
|
2004-11-03 20:29:08 +00:00
|
|
|
const gchar *wid;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
wid = glade_get_widget_name (widget);
|
2006-01-21 16:59:38 +00:00
|
|
|
|
|
|
|
if (wid == NULL)
|
|
|
|
return FALSE;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
for (i = 0; ids[i].wid != NULL; i++)
|
|
|
|
if (g_ascii_strcasecmp (ids[i].wid, wid) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ids[i].cid == 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GTK_IS_ENTRY (widget)) {
|
|
|
|
str = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
|
|
|
|
} else if (GTK_IS_TEXT_VIEW (widget)) {
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter iter_start;
|
|
|
|
GtkTextIter iter_end;
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &iter_start);
|
|
|
|
iter_end = iter_start;
|
|
|
|
gtk_text_iter_forward_to_end (&iter_end);
|
|
|
|
str = gtk_text_iter_get_text (&iter_start, &iter_end);
|
2005-07-16 21:09:01 +00:00
|
|
|
} else {
|
2007-02-11 11:15:46 +00:00
|
|
|
str = g_strdup ("");
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
/* FIXME: i'm getting an empty address field in evolution */
|
2004-11-03 20:29:08 +00:00
|
|
|
if (i >= ADDRESS_HOME && i < ADDRESS_WORK) {
|
|
|
|
about_me_set_address_field (me->addr1, ids[i].cid, str);
|
|
|
|
e_contact_set (me->contact, E_CONTACT_ADDRESS_HOME, me->addr1);
|
|
|
|
} else if (i >= ADDRESS_WORK) {
|
|
|
|
about_me_set_address_field (me->addr2, ids[i].cid, str);
|
|
|
|
e_contact_set (me->contact, E_CONTACT_ADDRESS_WORK, me->addr2);
|
|
|
|
} else {
|
|
|
|
e_contact_set (me->contact, ids[i].cid, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
2005-06-15 00:25:55 +00:00
|
|
|
if (me->commit_timeout_id) {
|
|
|
|
g_source_remove (me->commit_timeout_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
me->commit_timeout_id = g_timeout_add (600, (GSourceFunc) about_me_commit_from_timeout, me);
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
get_user_login (void)
|
|
|
|
{
|
|
|
|
char buf[LINE_MAX * 4];
|
|
|
|
struct passwd pwd, *err;
|
|
|
|
|
|
|
|
int i;
|
2005-11-25 20:18:23 +00:00
|
|
|
#if __sun
|
|
|
|
i = getpwuid_r (getuid (), &pwd, buf, sizeof (buf));
|
|
|
|
return (i != 0) ? g_strdup (pwd.pw_name) : NULL;
|
|
|
|
#else
|
|
|
|
i = getpwuid_r (getuid (), &pwd, buf, sizeof (buf), &err);
|
|
|
|
return ((i == 0) && (err == &pwd)) ? g_strdup (pwd.pw_name) : NULL;
|
|
|
|
#endif
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
about_me_get_address_field (EContactAddress *addr, guint cid)
|
|
|
|
{
|
2005-07-16 21:09:01 +00:00
|
|
|
gchar *str;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-16 21:09:01 +00:00
|
|
|
if (addr == NULL) {
|
2005-04-04 19:11:09 +00:00
|
|
|
return NULL;
|
2005-07-16 21:09:01 +00:00
|
|
|
}
|
2005-04-04 19:11:09 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
switch (cid) {
|
|
|
|
case ADDRESS_STREET:
|
|
|
|
str = addr->street;
|
|
|
|
break;
|
|
|
|
case ADDRESS_POBOX:
|
|
|
|
str = addr->po;
|
|
|
|
break;
|
|
|
|
case ADDRESS_LOCALITY:
|
|
|
|
str = addr->locality;
|
|
|
|
break;
|
|
|
|
case ADDRESS_CODE:
|
|
|
|
str = addr->code;
|
|
|
|
break;
|
|
|
|
case ADDRESS_REGION:
|
|
|
|
str = addr->region;
|
|
|
|
break;
|
|
|
|
case ADDRESS_COUNTRY:
|
|
|
|
str = addr->country;
|
|
|
|
break;
|
2005-07-16 21:09:01 +00:00
|
|
|
default:
|
|
|
|
str = NULL;
|
|
|
|
break;
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_set_address_field (EContactAddress *addr, guint cid, gchar *str)
|
|
|
|
{
|
|
|
|
switch (cid) {
|
|
|
|
case ADDRESS_STREET:
|
|
|
|
if (addr->street)
|
|
|
|
g_free (addr->street);
|
|
|
|
addr->street = g_strdup (str);
|
|
|
|
break;
|
|
|
|
case ADDRESS_POBOX:
|
|
|
|
if (addr->po)
|
|
|
|
g_free (addr->po);
|
|
|
|
addr->po = g_strdup (str);
|
|
|
|
break;
|
|
|
|
case ADDRESS_LOCALITY:
|
|
|
|
if (addr->locality)
|
|
|
|
g_free (addr->locality);
|
|
|
|
addr->locality = g_strdup (str);
|
|
|
|
break;
|
|
|
|
case ADDRESS_CODE:
|
|
|
|
if (addr->code)
|
|
|
|
g_free (addr->code);
|
|
|
|
addr->code = g_strdup (str);
|
|
|
|
break;
|
|
|
|
case ADDRESS_REGION:
|
|
|
|
if (addr->region)
|
|
|
|
g_free (addr->region);
|
|
|
|
addr->region = g_strdup (str);
|
|
|
|
break;
|
|
|
|
case ADDRESS_COUNTRY:
|
|
|
|
if (addr->country)
|
|
|
|
g_free (addr->country);
|
|
|
|
addr->country = g_strdup (str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-06-23 11:27:21 +00:00
|
|
|
* about_me_load_string_field:
|
2004-11-03 20:29:08 +00:00
|
|
|
*
|
|
|
|
* wid: glade widget name
|
|
|
|
* cid: id of the field (EDS id)
|
|
|
|
* aid: position in the array WidToCid
|
|
|
|
**/
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_load_string_field (GnomeAboutMe *me, const gchar *wid, guint cid, guint aid)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GladeXML *dialog;
|
2007-02-07 20:46:34 +00:00
|
|
|
const gchar *str;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
dialog = me->dialog;
|
|
|
|
|
|
|
|
widget = WID (wid);
|
|
|
|
|
2005-04-04 19:11:09 +00:00
|
|
|
if (me->create_self == TRUE) {
|
|
|
|
g_signal_connect (widget, "focus-out-event", G_CALLBACK (about_me_focus_out), me);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
if (aid >= ADDRESS_HOME && aid < ADDRESS_WORK) {
|
|
|
|
str = about_me_get_address_field (me->addr1, cid);
|
|
|
|
} else if (aid >= ADDRESS_WORK) {
|
|
|
|
str = about_me_get_address_field (me->addr2, cid);
|
|
|
|
} else {
|
|
|
|
str = e_contact_get_const (me->contact, cid);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = str ? str : "";
|
|
|
|
|
|
|
|
if (GTK_IS_ENTRY (widget)) {
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), str);
|
|
|
|
} else if (GTK_IS_TEXT_VIEW (widget)) {
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
|
|
|
|
gtk_text_buffer_set_text (buffer, str, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (widget, "focus-out-event", G_CALLBACK (about_me_focus_out), me);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_load_photo (GnomeAboutMe *me, EContact *contact)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GladeXML *dialog;
|
|
|
|
EContactPhoto *photo;
|
|
|
|
|
|
|
|
dialog = me->dialog;
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
widget = WID ("image-chooser");
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (widget), me->person);
|
|
|
|
|
|
|
|
photo = e_contact_get (contact, E_CONTACT_PHOTO);
|
|
|
|
|
2006-08-06 22:45:09 +00:00
|
|
|
if (photo && photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
|
2004-11-03 20:29:08 +00:00
|
|
|
me->have_image = TRUE;
|
2006-08-06 22:45:09 +00:00
|
|
|
e_image_chooser_set_image_data (E_IMAGE_CHOOSER (widget), photo->data.inlined.data, photo->data.inlined.length);
|
2004-11-03 20:29:08 +00:00
|
|
|
e_contact_photo_free (photo);
|
|
|
|
} else {
|
|
|
|
me->have_image = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_update_photo (GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GladeXML *dialog;
|
|
|
|
EContactPhoto *photo;
|
|
|
|
gchar *file;
|
2007-04-30 17:14:47 +00:00
|
|
|
GError *error;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2007-01-08 19:48:13 +00:00
|
|
|
guchar *data;
|
2005-07-13 10:46:56 +00:00
|
|
|
gsize length;
|
2005-07-05 15:29:33 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
dialog = me->dialog;
|
|
|
|
|
2005-07-05 15:29:33 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
if (me->image_changed && me->have_image) {
|
2005-07-05 15:29:33 +00:00
|
|
|
GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();
|
|
|
|
GdkPixbuf *pixbuf, *scaled;
|
|
|
|
int height, width;
|
|
|
|
gboolean do_scale = FALSE;
|
|
|
|
float scale;
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
widget = WID ("image-chooser");
|
2007-01-08 19:48:13 +00:00
|
|
|
e_image_chooser_get_image_data (E_IMAGE_CHOOSER (widget), (char **) &data, &length);
|
2005-07-05 15:29:33 +00:00
|
|
|
|
|
|
|
/* Before updating the image in EDS scale it to a reasonable size
|
|
|
|
so that the user doesn't get an application that does not respond
|
|
|
|
or that takes 100% CPU */
|
2007-01-08 19:48:13 +00:00
|
|
|
gdk_pixbuf_loader_write (loader, data, length, NULL);
|
2007-01-06 21:28:35 +00:00
|
|
|
gdk_pixbuf_loader_close (loader, NULL);
|
2005-07-05 15:29:33 +00:00
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
|
|
|
|
|
|
|
if (pixbuf)
|
2007-01-06 21:28:35 +00:00
|
|
|
g_object_ref (pixbuf);
|
2005-07-05 15:29:33 +00:00
|
|
|
|
|
|
|
g_object_unref (loader);
|
|
|
|
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
|
2005-07-13 20:16:13 +00:00
|
|
|
if (height >= width && height > MAX_HEIGHT) {
|
|
|
|
scale = (float)MAX_HEIGHT/height;
|
2005-07-05 15:29:33 +00:00
|
|
|
do_scale = TRUE;
|
2005-07-13 20:16:13 +00:00
|
|
|
} else if (width > height && width > MAX_WIDTH) {
|
|
|
|
scale = (float)MAX_WIDTH/width;
|
2005-07-05 15:29:33 +00:00
|
|
|
do_scale = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_scale) {
|
|
|
|
char *scaled_data = NULL;
|
2005-07-13 10:46:56 +00:00
|
|
|
gsize scaled_length;
|
2005-07-05 15:29:33 +00:00
|
|
|
|
|
|
|
scaled = gdk_pixbuf_scale_simple (pixbuf, width*scale, height*scale, GDK_INTERP_BILINEAR);
|
2005-07-13 20:16:13 +00:00
|
|
|
gdk_pixbuf_save_to_buffer (scaled, &scaled_data, &scaled_length, "png", NULL,
|
|
|
|
"compression", "9", NULL);
|
2005-07-05 15:29:33 +00:00
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
data = scaled_data;
|
|
|
|
length = scaled_length;
|
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
photo = g_new0 (EContactPhoto, 1);
|
2006-08-06 22:45:09 +00:00
|
|
|
photo->type = E_CONTACT_PHOTO_TYPE_INLINED;
|
|
|
|
photo->data.inlined.data = data;
|
|
|
|
photo->data.inlined.length = length;
|
2004-11-03 20:29:08 +00:00
|
|
|
e_contact_set (me->contact, E_CONTACT_PHOTO, photo);
|
|
|
|
|
|
|
|
/* Save the image for GDM */
|
2005-07-05 15:29:33 +00:00
|
|
|
/* FIXME: I would have to read the default used by the gdmgreeter program */
|
2007-04-30 17:14:47 +00:00
|
|
|
error = NULL;
|
|
|
|
file = g_build_filename (g_get_home_dir (), ".face", NULL);
|
|
|
|
if (g_file_set_contents (file,
|
|
|
|
photo->data.inlined.data,
|
|
|
|
photo->data.inlined.length,
|
|
|
|
&error) != FALSE) {
|
|
|
|
g_chmod (file, 0644);
|
|
|
|
} else {
|
|
|
|
g_warning ("Could not create %s: %s", file, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2007-04-30 17:14:47 +00:00
|
|
|
g_free (file);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
e_contact_photo_free (photo);
|
|
|
|
|
|
|
|
} else if (me->image_changed && !me->have_image) {
|
|
|
|
/* Update the image in the card */
|
|
|
|
e_contact_set (me->contact, E_CONTACT_PHOTO, NULL);
|
|
|
|
|
|
|
|
/* Update GDM configuration */
|
|
|
|
gnome_config_set_string ("/gdmphotosetup/last/picture", "");
|
|
|
|
gnome_config_set_string ("/gdm/face/picture", "");
|
|
|
|
gnome_config_sync ();
|
|
|
|
}
|
|
|
|
|
|
|
|
about_me_commit (me);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_load_info (GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2005-04-04 19:11:09 +00:00
|
|
|
if (me->create_self == FALSE) {
|
|
|
|
me->addr1 = e_contact_get (me->contact, E_CONTACT_ADDRESS_HOME);
|
|
|
|
if (me->addr1 == NULL)
|
|
|
|
me->addr1 = g_new0 (EContactAddress, 1);
|
|
|
|
me->addr2 = e_contact_get (me->contact, E_CONTACT_ADDRESS_WORK);
|
|
|
|
if (me->addr2 == NULL)
|
|
|
|
me->addr2 = g_new0 (EContactAddress, 1);
|
2005-06-23 11:27:21 +00:00
|
|
|
} else {
|
|
|
|
me->addr1 = g_new0 (EContactAddress, 1);
|
|
|
|
me->addr2 = g_new0 (EContactAddress, 1);
|
2005-04-04 19:11:09 +00:00
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
for (i = 0; ids[i].wid != NULL; i++) {
|
|
|
|
about_me_load_string_field (me, ids[i].wid, ids[i].cid, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2005-07-05 15:29:33 +00:00
|
|
|
eab_create_image_chooser_widget (gchar *name,
|
|
|
|
gchar *string1, gchar *string2,
|
|
|
|
gint int1, gint int2)
|
2004-11-03 20:29:08 +00:00
|
|
|
{
|
|
|
|
GtkWidget *w = NULL;
|
|
|
|
|
|
|
|
w = e_image_chooser_new ();
|
|
|
|
gtk_widget_show_all (w);
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-11-22 04:46:43 +00:00
|
|
|
static void
|
|
|
|
about_me_update_preview (GtkFileChooser *chooser,
|
|
|
|
GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
uri = gtk_file_chooser_get_preview_uri (chooser);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
GtkWidget *image;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gchar *mime_type;
|
|
|
|
|
|
|
|
if (!me->thumbs)
|
|
|
|
me->thumbs = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL);
|
|
|
|
|
|
|
|
|
|
|
|
mime_type = gnome_vfs_get_mime_type (uri);
|
|
|
|
pixbuf = gnome_thumbnail_factory_generate_thumbnail (me->thumbs,
|
|
|
|
uri,
|
|
|
|
mime_type);
|
|
|
|
image = gtk_file_chooser_get_preview_widget (chooser);
|
|
|
|
|
|
|
|
if(pixbuf != NULL) {
|
|
|
|
gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
} else {
|
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (image),
|
|
|
|
"gtk-dialog-question",
|
|
|
|
GTK_ICON_SIZE_DIALOG);
|
|
|
|
}
|
|
|
|
g_free (mime_type);
|
|
|
|
}
|
|
|
|
gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
|
|
|
|
}
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
static void
|
2005-07-05 10:34:49 +00:00
|
|
|
about_me_image_clicked_cb (GtkWidget *button, GnomeAboutMe *me)
|
2004-11-03 20:29:08 +00:00
|
|
|
{
|
2005-07-05 10:34:49 +00:00
|
|
|
GtkWidget *chooser_dialog;
|
|
|
|
gint response;
|
|
|
|
GtkWidget *image_chooser;
|
2004-11-03 20:29:08 +00:00
|
|
|
GladeXML *dialog;
|
2005-11-22 04:46:43 +00:00
|
|
|
GtkWidget *image;
|
2007-02-25 10:07:28 +00:00
|
|
|
const gchar *chooser_dir = DATADIR"/pixmaps/faces";
|
|
|
|
gchar *pics_dir;
|
2007-04-08 12:33:50 +00:00
|
|
|
GtkFileFilter *filter;
|
2007-02-25 10:07:28 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
dialog = me->dialog;
|
2005-07-05 10:34:49 +00:00
|
|
|
image_chooser = WID ("image-chooser");
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
chooser_dialog = gtk_file_chooser_dialog_new (_("Select Image"), GTK_WINDOW (WID ("about-me-dialog")),
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2005-07-16 21:42:40 +00:00
|
|
|
_("No Image"), GTK_RESPONSE_NO,
|
2005-07-05 10:34:49 +00:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (chooser_dialog), TRUE);
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (chooser_dialog), GTK_RESPONSE_ACCEPT);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2007-02-25 10:07:28 +00:00
|
|
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser_dialog), chooser_dir, NULL);
|
|
|
|
pics_dir = g_build_filename (g_get_home_dir (), "Pictures");
|
|
|
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (chooser_dialog), pics_dir, NULL);
|
|
|
|
g_free (pics_dir);
|
|
|
|
|
|
|
|
if (!g_file_test (chooser_dir, G_FILE_TEST_IS_DIR))
|
|
|
|
chooser_dir = g_get_home_dir ();
|
|
|
|
|
|
|
|
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser_dialog), chooser_dir);
|
2005-11-22 04:46:43 +00:00
|
|
|
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (chooser_dialog),
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
image = gtk_image_new ();
|
|
|
|
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser_dialog),
|
|
|
|
image);
|
|
|
|
gtk_widget_set_size_request (image, 128, -1);
|
|
|
|
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
|
|
|
g_signal_connect (chooser_dialog, "update-preview",
|
|
|
|
G_CALLBACK (about_me_update_preview), me);
|
|
|
|
|
2007-04-08 12:33:50 +00:00
|
|
|
filter = gtk_file_filter_new ();
|
|
|
|
gtk_file_filter_set_name (filter, _("Images"));
|
|
|
|
gtk_file_filter_add_pixbuf_formats (filter);
|
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser_dialog), filter);
|
|
|
|
filter = gtk_file_filter_new ();
|
|
|
|
gtk_file_filter_set_name (filter, _("All Files"));
|
|
|
|
gtk_file_filter_add_pattern(filter, "*");
|
|
|
|
|
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser_dialog), filter);
|
|
|
|
|
2007-02-25 10:07:28 +00:00
|
|
|
response = gtk_dialog_run (GTK_DIALOG (chooser_dialog));
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
if (response == GTK_RESPONSE_ACCEPT) {
|
|
|
|
gchar* filename;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser_dialog));
|
|
|
|
me->have_image = TRUE;
|
|
|
|
me->image_changed = TRUE;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (image_chooser), filename);
|
|
|
|
g_free (filename);
|
|
|
|
about_me_update_photo (me);
|
|
|
|
} else if (response == GTK_RESPONSE_NO) {
|
|
|
|
me->have_image = FALSE;
|
|
|
|
me->image_changed = TRUE;
|
|
|
|
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (image_chooser), me->person);
|
|
|
|
about_me_update_photo (me);
|
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
gtk_widget_destroy (chooser_dialog);
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-13 20:16:13 +00:00
|
|
|
static void
|
|
|
|
about_me_image_changed_cb (GtkWidget *widget, GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
me->have_image = TRUE;
|
|
|
|
me->image_changed = TRUE;
|
|
|
|
about_me_update_photo (me);
|
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
/* About Me Dialog Callbacks */
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_icon_theme_changed (GtkWindow *window,
|
|
|
|
GtkIconTheme *theme)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkIconInfo *icon;
|
|
|
|
GladeXML *dialog;
|
|
|
|
|
|
|
|
icon = gtk_icon_theme_lookup_icon (me->theme, "stock_person", 80, 0);
|
|
|
|
if (icon == NULL) {
|
|
|
|
g_print ("Icon not found\n");
|
|
|
|
}
|
|
|
|
g_free (me->person);
|
|
|
|
me->person = g_strdup (gtk_icon_info_get_filename (icon));
|
|
|
|
|
|
|
|
gtk_icon_info_free (icon);
|
|
|
|
|
|
|
|
if (me->have_image) {
|
|
|
|
dialog = me->dialog;
|
|
|
|
|
|
|
|
widget = WID ("image-chooser");
|
|
|
|
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (widget), me->person);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
about_me_button_clicked_cb (GtkDialog *dialog, gint response_id, GnomeAboutMe *me)
|
|
|
|
{
|
|
|
|
if (response_id == GTK_RESPONSE_HELP)
|
|
|
|
g_print ("Help goes here");
|
|
|
|
else {
|
2005-07-13 10:46:56 +00:00
|
|
|
if (me->commit_timeout_id) {
|
|
|
|
g_source_remove (me->commit_timeout_id);
|
|
|
|
about_me_commit (me);
|
|
|
|
}
|
|
|
|
|
2007-02-07 21:41:41 +00:00
|
|
|
about_me_destroy (me);
|
2004-11-03 20:29:08 +00:00
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-06-15 00:25:55 +00:00
|
|
|
about_me_passwd_clicked_cb (GtkWidget *button, GnomeAboutMe *me)
|
2004-11-03 20:29:08 +00:00
|
|
|
{
|
2005-06-15 00:25:55 +00:00
|
|
|
GladeXML *dialog;
|
|
|
|
|
|
|
|
dialog = me->dialog;
|
2005-07-05 10:34:49 +00:00
|
|
|
gnome_about_me_password (GTK_WINDOW (WID ("about-me-dialog")));
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
2005-08-06 17:22:29 +00:00
|
|
|
static gint
|
2004-11-03 20:29:08 +00:00
|
|
|
about_me_setup_dialog (void)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
2005-07-05 10:34:49 +00:00
|
|
|
GtkWidget *main_dialog;
|
2004-11-03 20:29:08 +00:00
|
|
|
GtkIconInfo *icon;
|
|
|
|
GladeXML *dialog;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
struct passwd *pwent;
|
|
|
|
gchar *str;
|
2007-02-07 20:46:34 +00:00
|
|
|
gchar **tok;
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
me = g_new0 (GnomeAboutMe, 1);
|
|
|
|
|
2007-02-02 18:12:40 +00:00
|
|
|
dialog = glade_xml_new (GNOMECC_GLADE_DIR "/gnome-about-me.glade",
|
2004-11-03 20:29:08 +00:00
|
|
|
"about-me-dialog", NULL);
|
|
|
|
|
2005-07-16 21:09:01 +00:00
|
|
|
if (dialog == NULL) {
|
2007-02-07 21:41:41 +00:00
|
|
|
about_me_destroy (me);
|
|
|
|
return -1;
|
2005-07-16 21:09:01 +00:00
|
|
|
}
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
me->dialog = dialog;
|
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
/* Connect the close button signal */
|
|
|
|
main_dialog = WID ("about-me-dialog");
|
|
|
|
g_signal_connect (G_OBJECT (main_dialog), "response",
|
|
|
|
G_CALLBACK (about_me_button_clicked_cb), me);
|
|
|
|
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (main_dialog), FALSE);
|
|
|
|
capplet_set_icon (main_dialog, "user-info");
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
/* Setup theme details */
|
2005-07-05 10:34:49 +00:00
|
|
|
me->screen = gtk_window_get_screen (GTK_WINDOW (main_dialog));
|
2004-11-03 20:29:08 +00:00
|
|
|
me->theme = gtk_icon_theme_get_for_screen (me->screen);
|
|
|
|
|
|
|
|
icon = gtk_icon_theme_lookup_icon (me->theme, "stock_person", 80, 0);
|
|
|
|
|
|
|
|
me->person = g_strdup (gtk_icon_info_get_filename (icon));
|
|
|
|
|
|
|
|
gtk_icon_info_free (icon);
|
|
|
|
|
|
|
|
g_signal_connect_object (me->theme, "changed",
|
|
|
|
G_CALLBACK (about_me_icon_theme_changed),
|
2005-07-05 10:34:49 +00:00
|
|
|
main_dialog,
|
2004-11-03 20:29:08 +00:00
|
|
|
G_CONNECT_SWAPPED);
|
|
|
|
|
|
|
|
/* Get the self contact */
|
|
|
|
if (!e_book_get_self (&me->contact, &me->book, &error)) {
|
2005-08-06 17:22:29 +00:00
|
|
|
if (error->code == E_BOOK_ERROR_PROTOCOL_NOT_SUPPORTED) {
|
|
|
|
about_me_error (NULL, _("There was an error while trying to get the addressbook information\n" \
|
|
|
|
"Evolution Data Server can't handle the protocol"));
|
2007-04-21 19:03:59 +00:00
|
|
|
g_clear_error (&error);
|
2007-02-07 21:41:41 +00:00
|
|
|
about_me_destroy (me);
|
2005-08-06 17:22:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-04-21 19:03:59 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
me->create_self = TRUE;
|
|
|
|
me->contact = e_contact_new ();
|
|
|
|
|
|
|
|
if (me->book == NULL) {
|
|
|
|
me->book = e_book_new_system_addressbook (&error);
|
2005-07-16 21:09:01 +00:00
|
|
|
if (me->book == NULL || error != NULL) {
|
|
|
|
g_error ("%s\n", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2005-04-04 19:11:09 +00:00
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
if (e_book_open (me->book, FALSE, NULL) == FALSE) {
|
2005-07-05 10:34:49 +00:00
|
|
|
about_me_error (GTK_WINDOW (main_dialog),
|
2005-06-23 11:27:21 +00:00
|
|
|
_("Unable to open address book"));
|
2005-07-16 21:09:01 +00:00
|
|
|
g_clear_error (&error);
|
2005-06-23 11:27:21 +00:00
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************/
|
2007-02-07 21:41:41 +00:00
|
|
|
me->login = get_user_login ();
|
2004-11-03 20:29:08 +00:00
|
|
|
setpwent ();
|
2007-02-07 21:41:41 +00:00
|
|
|
pwent = getpwnam (me->login);
|
2004-11-03 20:29:08 +00:00
|
|
|
if (pwent == NULL) {
|
2005-07-05 10:34:49 +00:00
|
|
|
about_me_error (GTK_WINDOW (WID ("about-me-dialog")),
|
2005-06-23 11:27:21 +00:00
|
|
|
_("Unknown login ID, the user database might be corrupted"));
|
2007-02-07 21:41:41 +00:00
|
|
|
about_me_destroy (me);
|
2005-08-06 17:22:29 +00:00
|
|
|
return -1;
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
tok = g_strsplit (pwent->pw_gecos, ",", 0);
|
|
|
|
|
|
|
|
/************************************************/
|
|
|
|
|
2005-06-23 11:27:21 +00:00
|
|
|
if (tok[0] == NULL || strlen (tok[0]) == 0)
|
|
|
|
me->username = NULL;
|
|
|
|
else
|
|
|
|
me->username = g_strdup (tok[0]);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
/* Contact Tab */
|
|
|
|
about_me_load_photo (me, me->contact);
|
|
|
|
|
|
|
|
widget = WID ("fullname");
|
2005-06-15 00:25:55 +00:00
|
|
|
if (tok[0] == NULL || strlen (tok[0]) == 0) {
|
2007-02-07 21:41:41 +00:00
|
|
|
str = g_strdup_printf ("<b><span size=\"xx-large\">%s</span></b>", me->login);
|
2004-11-03 20:29:08 +00:00
|
|
|
} else {
|
|
|
|
str = g_strdup_printf ("<b><span size=\"xx-large\">%s</span></b>", tok[0]);
|
|
|
|
}
|
2005-06-15 00:25:55 +00:00
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (widget), str);
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
widget = WID ("login");
|
2007-02-07 21:41:41 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (widget), me->login);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-06-15 00:25:55 +00:00
|
|
|
if (tok[0] == NULL || strlen (tok[0]) == 0) {
|
2007-02-07 21:41:41 +00:00
|
|
|
str = g_strdup_printf (_("About %s"), me->login);
|
2005-06-15 00:25:55 +00:00
|
|
|
} else {
|
2005-07-13 20:16:13 +00:00
|
|
|
str = g_strdup_printf (_("About %s"), tok[0]);
|
2005-06-15 00:25:55 +00:00
|
|
|
}
|
2005-07-05 10:34:49 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (main_dialog), str);
|
2004-11-03 20:29:08 +00:00
|
|
|
g_free (str);
|
2007-02-07 21:41:41 +00:00
|
|
|
g_strfreev (tok);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2005-07-13 20:16:13 +00:00
|
|
|
widget = WID ("password");
|
2004-11-03 20:29:08 +00:00
|
|
|
g_signal_connect (G_OBJECT (widget), "clicked",
|
2005-06-15 00:25:55 +00:00
|
|
|
G_CALLBACK (about_me_passwd_clicked_cb), me);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
|
|
|
widget = WID ("button-image");
|
|
|
|
g_signal_connect (G_OBJECT (widget), "clicked",
|
|
|
|
G_CALLBACK (about_me_image_clicked_cb), me);
|
|
|
|
|
2005-07-13 20:16:13 +00:00
|
|
|
widget = WID ("image-chooser");
|
|
|
|
g_signal_connect (G_OBJECT (widget), "changed",
|
|
|
|
G_CALLBACK (about_me_image_changed_cb), me);
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
about_me_load_info (me);
|
|
|
|
|
2005-07-05 10:34:49 +00:00
|
|
|
gtk_widget_show_all (main_dialog);
|
2005-08-06 17:22:29 +00:00
|
|
|
|
|
|
|
return 0;
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
2007-02-07 21:41:41 +00:00
|
|
|
GnomeProgram *program;
|
|
|
|
int rc = 0;
|
|
|
|
|
2004-11-03 20:29:08 +00:00
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
|
2007-02-07 21:41:41 +00:00
|
|
|
program = gnome_program_init ("gnome-about-me", VERSION,
|
|
|
|
LIBGNOMEUI_MODULE, argc, argv,
|
|
|
|
GNOME_PARAM_APP_DATADIR, GNOMECC_DATA_DIR,
|
|
|
|
NULL);
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2007-02-07 21:41:41 +00:00
|
|
|
rc = about_me_setup_dialog ();
|
|
|
|
|
|
|
|
if (rc != -1) {
|
2005-08-06 17:22:29 +00:00
|
|
|
gtk_main ();
|
|
|
|
}
|
2004-11-03 20:29:08 +00:00
|
|
|
|
2007-02-07 21:41:41 +00:00
|
|
|
g_object_unref (program);
|
|
|
|
|
|
|
|
return rc;
|
2004-11-03 20:29:08 +00:00
|
|
|
}
|