aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-05-01 01:03:06 +0800
committerChris Lahey <clahey@src.gnome.org>2000-05-01 01:03:06 +0800
commitd87a10196cd82a391f9c2f937ee91dd9f06e5abe (patch)
tree0f39e8ecfe6495db3d32716ce5b20ffd50d9bca2 /addressbook
parentedf876f544a5f2010f117b0b609b557f9d2b1e04 (diff)
downloadgsoc2013-evolution-d87a10196cd82a391f9c2f937ee91dd9f06e5abe.tar.gz
gsoc2013-evolution-d87a10196cd82a391f9c2f937ee91dd9f06e5abe.tar.zst
gsoc2013-evolution-d87a10196cd82a391f9c2f937ee91dd9f06e5abe.zip
From addressbook/ChangeLog
2000-04-30 Christopher James Lahey <clahey@helixcode.com> * backend/ebook/e-card.c: Make file as not have the : after it if it's empty. If there's no name, or file_as, fill in these fields with defaults based on full_name or name respectively. * backend/ebook/load-pine-addressbook.c: New file to do import of pine .addressbook files. * backend/pas/pas-backend-file.c: Made empty fields act as the empty string for searches. * contact-editor/e-contact-editor.c, contact-editor/e-contact-editor.h: Made the File As field update properly as you edit the name and company fields. Added the pull down list of File As choices. Made sure that all fields will be set to NULL if they are deleted to the empty string. * gui/minicard/e-minicard.c: Use the File As field instead of the Full Name field for the header. Make identical compares on the File As field do a compare on the uid. From wombat/ChangeLog 2000-04-30 Christopher James Lahey <clahey@helixcode.com> * Makefile.am: Added ename libs to LDADD. svn path=/trunk/; revision=2696
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog22
-rw-r--r--addressbook/backend/ebook/e-card.c27
-rw-r--r--addressbook/backend/ebook/load-pine-addressbook.c147
-rw-r--r--addressbook/backend/pas/pas-backend-file.c3
-rw-r--r--addressbook/contact-editor/e-contact-editor.c240
-rw-r--r--addressbook/contact-editor/e-contact-editor.h1
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.c240
-rw-r--r--addressbook/gui/contact-editor/e-contact-editor.h1
-rw-r--r--addressbook/gui/minicard/e-minicard.c36
-rw-r--r--addressbook/gui/widgets/e-minicard.c36
10 files changed, 693 insertions, 60 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index a0e59a5574..57c10947a5 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,5 +1,27 @@
2000-04-30 Christopher James Lahey <clahey@helixcode.com>
+ * backend/ebook/e-card.c: Make file as not have the : after it if
+ it's empty. If there's no name, or file_as, fill in these fields
+ with defaults based on full_name or name respectively.
+
+ * backend/ebook/load-pine-addressbook.c: New file to do import of
+ pine .addressbook files.
+
+ * backend/pas/pas-backend-file.c: Made empty fields act as the
+ empty string for searches.
+
+ * contact-editor/e-contact-editor.c,
+ contact-editor/e-contact-editor.h: Made the File As field update
+ properly as you edit the name and company fields. Added the pull
+ down list of File As choices. Made sure that all fields will
+ be set to NULL if they are deleted to the empty string.
+
+ * gui/minicard/e-minicard.c: Use the File As field instead of the
+ Full Name field for the header. Make identical compares on the
+ File As field do a compare on the uid.
+
+2000-04-30 Christopher James Lahey <clahey@helixcode.com>
+
* contact-editor/e-contact-editor-fullname.c,
contact-editor/fullname.glade: Fixed a string mismatch.
diff --git a/addressbook/backend/ebook/e-card.c b/addressbook/backend/ebook/e-card.c
index 2f0f05b97f..2eeec38b73 100644
--- a/addressbook/backend/ebook/e-card.c
+++ b/addressbook/backend/ebook/e-card.c
@@ -227,13 +227,15 @@ char
vobj = newVObject (VCCardProp);
- if ( card->file_as )
+ if ( card->file_as && *card->file_as )
addPropValue(vobj, "X-EVOLUTION-FILE-AS", card->file_as);
+ else if (card->file_as)
+ addProp(vobj, "X-EVOLUTION-FILE_AS");
if ( card->fname )
addPropValue(vobj, VCFullNameProp, card->fname);
- if ( card->name ) {
+ if ( card->name && (card->name->prefix || card->name->given || card->name->additional || card->name->family || card->name->suffix) ) {
VObject *nameprop;
nameprop = addProp(vobj, VCNameProp);
if ( card->name->prefix )
@@ -705,6 +707,27 @@ parse(ECard *card, VObject *vobj)
while(moreIteration (&iterator)) {
parse_attribute(card, nextVObject(&iterator));
}
+ if (!card->name) {
+ if (card->fname) {
+ card->name = e_card_name_from_string(card->fname);
+ }
+ }
+ if (!card->file_as) {
+ if (card->name) {
+ ECardName *name = card->name;
+ char *strings[3], **stringptr;
+ char *string;
+ stringptr = strings;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ *stringptr = NULL;
+ string = g_strjoinv(", ", strings);
+ card->file_as = string;
+ } else
+ card->file_as = g_strdup("");
+ }
}
static void
diff --git a/addressbook/backend/ebook/load-pine-addressbook.c b/addressbook/backend/ebook/load-pine-addressbook.c
new file mode 100644
index 0000000000..8837a11a9a
--- /dev/null
+++ b/addressbook/backend/ebook/load-pine-addressbook.c
@@ -0,0 +1,147 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#include <config.h>
+#include <bonobo.h>
+#include <gnome.h>
+#include <stdio.h>
+
+#include <e-book.h>
+
+static CORBA_Environment ev;
+
+#ifdef USING_OAF
+
+#include <liboaf/liboaf.h>
+
+static void
+init_corba (int *argc, char **argv)
+{
+ gnome_init_with_popt_table("blah", "0.0", *argc, argv, NULL, 0, NULL);
+
+ oaf_init (*argc, argv);
+}
+
+#else
+
+#include <libgnorba/gnorba.h>
+
+static void
+init_corba (int *argc, char **argv)
+{
+ gnome_CORBA_init_with_popt_table (
+ "blah", "0.0",
+ argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev);
+}
+
+#endif
+
+static void
+init_bonobo (int argc, char **argv)
+{
+ if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE)
+ g_error (_("Could not initialize Bonobo"));
+}
+
+static void
+add_card_cb (EBook *book, EBookStatus status, const gchar *id, gpointer closure)
+{
+ ECard *card = E_CARD(closure);
+ char *vcard = e_card_get_vcard(card);
+ g_print ("Saved card: %s\n", vcard);
+ g_free(vcard);
+ gtk_object_unref(GTK_OBJECT(card));
+}
+
+static void
+book_open_cb (EBook *book, EBookStatus status, gpointer closure)
+{
+ FILE *fp = fopen (".addressbook", "r");
+ char line[1024];
+ while(fgets(line, 1024, fp)) {
+ int length = strlen(line);
+ char **strings;
+ ECardName *name;
+ ECard *card;
+ ECardList *list;
+ if (line[length - 1] == '\n')
+ line[--length] = 0;
+
+ card = e_card_new("");
+ strings = g_strsplit(line, "\t", 3);
+ name = e_card_name_from_string(strings[1]);
+ gtk_object_set(GTK_OBJECT(card),
+ "nickname", strings[0],
+ "full_name", strings[1],
+ "name", name,
+ NULL);
+ gtk_object_get(GTK_OBJECT(card),
+ "email", &list,
+ NULL);
+ e_card_list_append(list, strings[2]);
+ g_strfreev(strings);
+ e_book_add_card(book, card, add_card_cb, card);
+ }
+}
+
+static guint
+ebook_create (void)
+{
+ EBook *book;
+
+ book = e_book_new ();
+
+ if (!book) {
+ printf ("%s: %s(): Couldn't create EBook, bailing.\n",
+ __FILE__,
+ __FUNCTION__);
+ return FALSE;
+ }
+
+
+ if (! e_book_load_uri (book, "file:/tmp/test.db", book_open_cb, NULL)) {
+ printf ("error calling load_uri!\n");
+ }
+
+
+ return FALSE;
+}
+
+#if 0
+static char *
+read_file (char *name)
+{
+ int len;
+ char buff[65536];
+ char line[1024];
+ FILE *f;
+
+ f = fopen (name, "r");
+ if (f == NULL)
+ g_error ("Unable to open %s!\n", name);
+
+ len = 0;
+ while (fgets (line, sizeof (line), f) != NULL) {
+ strcpy (buff + len, line);
+ len += strlen (line);
+ }
+
+ fclose (f);
+
+ return g_strdup (buff);
+}
+#endif
+
+int
+main (int argc, char **argv)
+{
+
+ CORBA_exception_init (&ev);
+
+ init_corba (&argc, argv);
+ init_bonobo (argc, argv);
+
+ gtk_idle_add ((GtkFunction) ebook_create, NULL);
+
+ bonobo_main ();
+
+ return 0;
+}
diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c
index cbe75a5aba..20de42808c 100644
--- a/addressbook/backend/pas/pas-backend-file.c
+++ b/addressbook/backend/pas/pas-backend-file.c
@@ -287,6 +287,9 @@ entry_compare(PASBackendFileSearchContext *ctx, struct _ESExp *f,
if (prop && compare(prop, argv[1]->value.string)) {
truth = TRUE;
}
+ if ((!prop) && compare("", argv[1]->value.string)) {
+ truth = TRUE;
+ }
}
else if (info->prop_type == PROP_TYPE_LIST) {
/* the special searches that match any of the list elements */
diff --git a/addressbook/contact-editor/e-contact-editor.c b/addressbook/contact-editor/e-contact-editor.c
index 3d25e8a1a9..b4c20987f9 100644
--- a/addressbook/contact-editor/e-contact-editor.c
+++ b/addressbook/contact-editor/e-contact-editor.c
@@ -253,14 +253,149 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor)
editor->address[editor->address_choice]->data = string;
}
+/* This function tells you whether name_to_style will make sense. */
+static gboolean
+style_makes_sense(const ECardName *name, char *company, int style)
+{
+ switch (style) {
+ case 0: /* Fall Through */
+ case 1:
+ return TRUE;
+ case 2:
+ if (company && *company)
+ return TRUE;
+ else
+ return FALSE;
+ case 3: /* Fall Through */
+ case 4:
+ if (company && *company && ((name->given && *name->given) || (name->family && *name->family)))
+ return TRUE;
+ else
+ return FALSE;
+ default:
+ return FALSE;
+ }
+}
+
+static char *
+name_to_style(const ECardName *name, char *company, int style)
+{
+ char *string;
+ char *strings[4], **stringptr;
+ char *substring;
+ switch (style) {
+ case 0:
+ stringptr = strings;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ *stringptr = NULL;
+ string = g_strjoinv(", ", strings);
+ break;
+ case 1:
+ stringptr = strings;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ *stringptr = NULL;
+ string = g_strjoinv(" ", strings);
+ break;
+ case 2:
+ string = g_strdup(company);
+ break;
+ case 3: /* Fall Through */
+ case 4:
+ stringptr = strings;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ *stringptr = NULL;
+ substring = g_strjoinv(", ", strings);
+ if (!(company && *company))
+ company = "";
+ if (style == 3)
+ string = g_strdup_printf("%s (%s)", substring, company);
+ else
+ string = g_strdup_printf("%s (%s)", company, substring);
+ g_free(substring);
+ break;
+ default:
+ string = g_strdup("");
+ }
+ return string;
+}
+
+static int
+file_as_get_style (EContactEditor *editor)
+{
+ GtkEntry *file_as = GTK_ENTRY(glade_xml_get_widget(editor->gui, "entry-file-as"));
+ char *filestring = gtk_entry_get_text(file_as);
+ char *trystring;
+ ECardName *name = editor->name;
+ int i;
+ int style;
+
+ if (!name) return 0;
+
+ style = -1;
+ for (i = 0; i < 5; i++) {
+ trystring = name_to_style(name, editor->company, i);
+ if (!strcmp(trystring, filestring)) {
+ g_free(trystring);
+ return i;
+ }
+ g_free(trystring);
+ }
+ return -1;
+}
+
static void
-name_entry_changed (GtkWidget *widget, EContactEditor *editor)
+file_as_set_style(EContactEditor *editor, int style)
{
char *string;
+ int i;
+ GList *strings = NULL;
+ GtkCombo *combo = GTK_COMBO(glade_xml_get_widget(editor->gui, "combo-file-as"));
+ GtkEntry *file_as = GTK_ENTRY(glade_xml_get_widget(editor->gui, "entry-file-as"));
+
+ if (style == -1) {
+ string = g_strdup(gtk_entry_get_text(file_as));
+ strings = g_list_append(strings, string);
+ }
+
+ for (i = 0; i < 5; i++) {
+ if (style_makes_sense(editor->name, editor->company, i)) {
+ string = name_to_style(editor->name, editor->company, i);
+ strings = g_list_append(strings, string);
+ }
+ }
+
+ gtk_combo_set_popdown_strings(combo, strings);
+ g_list_foreach(strings, (GFunc) g_free, NULL);
+ g_list_free(strings);
+
+ if (style != -1) {
+ string = name_to_style(editor->name, editor->company, style);
+ gtk_entry_set_text(file_as, string);
+ g_free(string);
+ }
+}
+
+static void
+name_entry_changed (GtkWidget *widget, EContactEditor *editor)
+{
ECardName *name;
+ char *string;
GtkEntry *entry = GTK_ENTRY(widget);
+ int style = 0;
+
+ style = file_as_get_style(editor);
name = editor->name;
+
if (name)
e_card_name_free(name);
@@ -269,6 +404,23 @@ name_entry_changed (GtkWidget *widget, EContactEditor *editor)
name = e_card_name_from_string(string);
editor->name = name;
+
+ file_as_set_style(editor, style);
+}
+
+static void
+company_entry_changed (GtkWidget *widget, EContactEditor *editor)
+{
+ GtkEntry *entry = GTK_ENTRY(widget);
+ int style = 0;
+
+ style = file_as_get_style(editor);
+
+ g_free(editor->company);
+
+ editor->company = g_strdup(gtk_entry_get_text(entry));
+
+ file_as_set_style(editor, style);
}
static void
@@ -296,6 +448,9 @@ set_entry_changed_signals(EContactEditor *editor)
widget = glade_xml_get_widget(editor->gui, "entry-fullname");
gtk_signal_connect(GTK_OBJECT(widget), "changed",
name_entry_changed, editor);
+ widget = glade_xml_get_widget(editor->gui, "entry-company");
+ gtk_signal_connect(GTK_OBJECT(widget), "changed",
+ company_entry_changed, editor);
}
static void
@@ -358,6 +513,7 @@ e_contact_editor_init (EContactEditor *e_contact_editor)
e_contact_editor->phone_list = NULL;
e_contact_editor->address_list = NULL;
e_contact_editor->name = NULL;
+ e_contact_editor->company = g_strdup("");
for (i = 0; i < E_CONTACT_EDITOR_PHONE_ID_LAST; i++) {
e_contact_editor->phone[i] = NULL;
@@ -414,6 +570,8 @@ e_contact_editor_destroy (GtkObject *object) {
gtk_widget_unref(e_contact_editor->address_popup);
}
+ g_free (e_contact_editor->company);
+
gtk_object_unref(GTK_OBJECT(e_contact_editor->gui));
}
@@ -884,14 +1042,6 @@ fill_in_info(EContactEditor *editor)
if (fname)
gtk_editable_insert_text(editable, fname, strlen(fname), &position);
-
-
- position = 0;
- editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
- gtk_editable_delete_text(editable, 0, -1);
- if (file_as)
- gtk_editable_insert_text(editable, file_as, strlen(file_as), &position);
-
for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) {
int i;
phone = e_card_iterator_get(iterator);
@@ -1023,6 +1173,14 @@ fill_in_info(EContactEditor *editor)
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-birthday"));
gnome_date_edit_set_time(dateedit, time_val);
}
+
+ /* File as has to come after company and name or else it'll get messed up when setting them. */
+ position = 0;
+ editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
+ gtk_editable_delete_text(editable, 0, -1);
+ if (file_as)
+ gtk_editable_insert_text(editable, file_as, strlen(file_as), &position);
+
set_fields(editor);
}
}
@@ -1073,10 +1231,9 @@ extract_info(EContactEditor *editor)
position = 0;
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
file_as = gtk_editable_get_chars(editable, 0, -1);
- if (file_as && *file_as)
- gtk_object_set(GTK_OBJECT(card),
- "file_as", file_as,
- NULL);
+ gtk_object_set(GTK_OBJECT(card),
+ "file_as", file_as,
+ NULL);
g_free(file_as);
position = 0;
@@ -1086,8 +1243,17 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"full_name", fname,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "full_name", NULL,
+ NULL);
g_free(fname);
+ if (editor->name)
+ gtk_object_set(GTK_OBJECT(card),
+ "name", editor->name,
+ NULL);
+
for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); iterator_next ? e_card_iterator_next(iterator) : FALSE ) {
int i;
phone = e_card_iterator_get(iterator);
@@ -1182,6 +1348,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"url", url,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "url", NULL,
+ NULL);
g_free(url);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-company"));
@@ -1190,6 +1360,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"org", org,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "org", NULL,
+ NULL);
g_free(org);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-department"));
@@ -1198,6 +1372,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"org_unit", org_unit,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "org_unit", NULL,
+ NULL);
g_free(org_unit);
position = 0;
@@ -1207,6 +1385,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"office", office,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "office", NULL,
+ NULL);
g_free(office);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-jobtitle"));
@@ -1215,6 +1397,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"title", title,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "title", NULL,
+ NULL);
g_free(title);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-profession"));
@@ -1223,6 +1409,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"role", role,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "role", NULL,
+ NULL);
g_free(role);
position = 0;
@@ -1232,6 +1422,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"manager", manager,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "manager", NULL,
+ NULL);
g_free(manager);
position = 0;
@@ -1241,6 +1435,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"assistant", assistant,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "assistant", NULL,
+ NULL);
g_free(assistant);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-nickname"));
@@ -1249,6 +1447,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"nickname", nickname,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "nickname", NULL,
+ NULL);
g_free(nickname);
position = 0;
@@ -1258,6 +1460,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"spouse", spouse,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "spouse", NULL,
+ NULL);
g_free(spouse);
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-anniversary"));
@@ -1278,6 +1484,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"fburl", fburl,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "fburl", NULL,
+ NULL);
g_free(fburl);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-comments"));
@@ -1286,6 +1496,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"note", note,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "note", NULL,
+ NULL);
g_free(note);
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-birthday"));
diff --git a/addressbook/contact-editor/e-contact-editor.h b/addressbook/contact-editor/e-contact-editor.h
index fa31e73bde..a0bad6e1f9 100644
--- a/addressbook/contact-editor/e-contact-editor.h
+++ b/addressbook/contact-editor/e-contact-editor.h
@@ -115,6 +115,7 @@ struct _EContactEditor
ECardAddrLabel *address[E_CONTACT_EDITOR_ADDRESS_ID_LAST];
ECardName *name;
+ char *company;
EContactEditorEmailId email_choice;
EContactEditorPhoneId phone_choice[4];
diff --git a/addressbook/gui/contact-editor/e-contact-editor.c b/addressbook/gui/contact-editor/e-contact-editor.c
index 3d25e8a1a9..b4c20987f9 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.c
+++ b/addressbook/gui/contact-editor/e-contact-editor.c
@@ -253,14 +253,149 @@ address_text_changed (GtkWidget *widget, EContactEditor *editor)
editor->address[editor->address_choice]->data = string;
}
+/* This function tells you whether name_to_style will make sense. */
+static gboolean
+style_makes_sense(const ECardName *name, char *company, int style)
+{
+ switch (style) {
+ case 0: /* Fall Through */
+ case 1:
+ return TRUE;
+ case 2:
+ if (company && *company)
+ return TRUE;
+ else
+ return FALSE;
+ case 3: /* Fall Through */
+ case 4:
+ if (company && *company && ((name->given && *name->given) || (name->family && *name->family)))
+ return TRUE;
+ else
+ return FALSE;
+ default:
+ return FALSE;
+ }
+}
+
+static char *
+name_to_style(const ECardName *name, char *company, int style)
+{
+ char *string;
+ char *strings[4], **stringptr;
+ char *substring;
+ switch (style) {
+ case 0:
+ stringptr = strings;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ *stringptr = NULL;
+ string = g_strjoinv(", ", strings);
+ break;
+ case 1:
+ stringptr = strings;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ *stringptr = NULL;
+ string = g_strjoinv(" ", strings);
+ break;
+ case 2:
+ string = g_strdup(company);
+ break;
+ case 3: /* Fall Through */
+ case 4:
+ stringptr = strings;
+ if (name->family && *name->family)
+ *(stringptr++) = name->family;
+ if (name->given && *name->given)
+ *(stringptr++) = name->given;
+ *stringptr = NULL;
+ substring = g_strjoinv(", ", strings);
+ if (!(company && *company))
+ company = "";
+ if (style == 3)
+ string = g_strdup_printf("%s (%s)", substring, company);
+ else
+ string = g_strdup_printf("%s (%s)", company, substring);
+ g_free(substring);
+ break;
+ default:
+ string = g_strdup("");
+ }
+ return string;
+}
+
+static int
+file_as_get_style (EContactEditor *editor)
+{
+ GtkEntry *file_as = GTK_ENTRY(glade_xml_get_widget(editor->gui, "entry-file-as"));
+ char *filestring = gtk_entry_get_text(file_as);
+ char *trystring;
+ ECardName *name = editor->name;
+ int i;
+ int style;
+
+ if (!name) return 0;
+
+ style = -1;
+ for (i = 0; i < 5; i++) {
+ trystring = name_to_style(name, editor->company, i);
+ if (!strcmp(trystring, filestring)) {
+ g_free(trystring);
+ return i;
+ }
+ g_free(trystring);
+ }
+ return -1;
+}
+
static void
-name_entry_changed (GtkWidget *widget, EContactEditor *editor)
+file_as_set_style(EContactEditor *editor, int style)
{
char *string;
+ int i;
+ GList *strings = NULL;
+ GtkCombo *combo = GTK_COMBO(glade_xml_get_widget(editor->gui, "combo-file-as"));
+ GtkEntry *file_as = GTK_ENTRY(glade_xml_get_widget(editor->gui, "entry-file-as"));
+
+ if (style == -1) {
+ string = g_strdup(gtk_entry_get_text(file_as));
+ strings = g_list_append(strings, string);
+ }
+
+ for (i = 0; i < 5; i++) {
+ if (style_makes_sense(editor->name, editor->company, i)) {
+ string = name_to_style(editor->name, editor->company, i);
+ strings = g_list_append(strings, string);
+ }
+ }
+
+ gtk_combo_set_popdown_strings(combo, strings);
+ g_list_foreach(strings, (GFunc) g_free, NULL);
+ g_list_free(strings);
+
+ if (style != -1) {
+ string = name_to_style(editor->name, editor->company, style);
+ gtk_entry_set_text(file_as, string);
+ g_free(string);
+ }
+}
+
+static void
+name_entry_changed (GtkWidget *widget, EContactEditor *editor)
+{
ECardName *name;
+ char *string;
GtkEntry *entry = GTK_ENTRY(widget);
+ int style = 0;
+
+ style = file_as_get_style(editor);
name = editor->name;
+
if (name)
e_card_name_free(name);
@@ -269,6 +404,23 @@ name_entry_changed (GtkWidget *widget, EContactEditor *editor)
name = e_card_name_from_string(string);
editor->name = name;
+
+ file_as_set_style(editor, style);
+}
+
+static void
+company_entry_changed (GtkWidget *widget, EContactEditor *editor)
+{
+ GtkEntry *entry = GTK_ENTRY(widget);
+ int style = 0;
+
+ style = file_as_get_style(editor);
+
+ g_free(editor->company);
+
+ editor->company = g_strdup(gtk_entry_get_text(entry));
+
+ file_as_set_style(editor, style);
}
static void
@@ -296,6 +448,9 @@ set_entry_changed_signals(EContactEditor *editor)
widget = glade_xml_get_widget(editor->gui, "entry-fullname");
gtk_signal_connect(GTK_OBJECT(widget), "changed",
name_entry_changed, editor);
+ widget = glade_xml_get_widget(editor->gui, "entry-company");
+ gtk_signal_connect(GTK_OBJECT(widget), "changed",
+ company_entry_changed, editor);
}
static void
@@ -358,6 +513,7 @@ e_contact_editor_init (EContactEditor *e_contact_editor)
e_contact_editor->phone_list = NULL;
e_contact_editor->address_list = NULL;
e_contact_editor->name = NULL;
+ e_contact_editor->company = g_strdup("");
for (i = 0; i < E_CONTACT_EDITOR_PHONE_ID_LAST; i++) {
e_contact_editor->phone[i] = NULL;
@@ -414,6 +570,8 @@ e_contact_editor_destroy (GtkObject *object) {
gtk_widget_unref(e_contact_editor->address_popup);
}
+ g_free (e_contact_editor->company);
+
gtk_object_unref(GTK_OBJECT(e_contact_editor->gui));
}
@@ -884,14 +1042,6 @@ fill_in_info(EContactEditor *editor)
if (fname)
gtk_editable_insert_text(editable, fname, strlen(fname), &position);
-
-
- position = 0;
- editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
- gtk_editable_delete_text(editable, 0, -1);
- if (file_as)
- gtk_editable_insert_text(editable, file_as, strlen(file_as), &position);
-
for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); e_card_iterator_next(iterator)) {
int i;
phone = e_card_iterator_get(iterator);
@@ -1023,6 +1173,14 @@ fill_in_info(EContactEditor *editor)
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-birthday"));
gnome_date_edit_set_time(dateedit, time_val);
}
+
+ /* File as has to come after company and name or else it'll get messed up when setting them. */
+ position = 0;
+ editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
+ gtk_editable_delete_text(editable, 0, -1);
+ if (file_as)
+ gtk_editable_insert_text(editable, file_as, strlen(file_as), &position);
+
set_fields(editor);
}
}
@@ -1073,10 +1231,9 @@ extract_info(EContactEditor *editor)
position = 0;
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-file-as"));
file_as = gtk_editable_get_chars(editable, 0, -1);
- if (file_as && *file_as)
- gtk_object_set(GTK_OBJECT(card),
- "file_as", file_as,
- NULL);
+ gtk_object_set(GTK_OBJECT(card),
+ "file_as", file_as,
+ NULL);
g_free(file_as);
position = 0;
@@ -1086,8 +1243,17 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"full_name", fname,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "full_name", NULL,
+ NULL);
g_free(fname);
+ if (editor->name)
+ gtk_object_set(GTK_OBJECT(card),
+ "name", editor->name,
+ NULL);
+
for (iterator = e_card_list_get_iterator(phone_list); e_card_iterator_is_valid(iterator); iterator_next ? e_card_iterator_next(iterator) : FALSE ) {
int i;
phone = e_card_iterator_get(iterator);
@@ -1182,6 +1348,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"url", url,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "url", NULL,
+ NULL);
g_free(url);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-company"));
@@ -1190,6 +1360,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"org", org,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "org", NULL,
+ NULL);
g_free(org);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-department"));
@@ -1198,6 +1372,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"org_unit", org_unit,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "org_unit", NULL,
+ NULL);
g_free(org_unit);
position = 0;
@@ -1207,6 +1385,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"office", office,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "office", NULL,
+ NULL);
g_free(office);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-jobtitle"));
@@ -1215,6 +1397,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"title", title,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "title", NULL,
+ NULL);
g_free(title);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-profession"));
@@ -1223,6 +1409,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"role", role,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "role", NULL,
+ NULL);
g_free(role);
position = 0;
@@ -1232,6 +1422,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"manager", manager,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "manager", NULL,
+ NULL);
g_free(manager);
position = 0;
@@ -1241,6 +1435,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"assistant", assistant,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "assistant", NULL,
+ NULL);
g_free(assistant);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "entry-nickname"));
@@ -1249,6 +1447,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"nickname", nickname,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "nickname", NULL,
+ NULL);
g_free(nickname);
position = 0;
@@ -1258,6 +1460,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"spouse", spouse,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "spouse", NULL,
+ NULL);
g_free(spouse);
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-anniversary"));
@@ -1278,6 +1484,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"fburl", fburl,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "fburl", NULL,
+ NULL);
g_free(fburl);
editable = GTK_EDITABLE(glade_xml_get_widget(editor->gui, "text-comments"));
@@ -1286,6 +1496,10 @@ extract_info(EContactEditor *editor)
gtk_object_set(GTK_OBJECT(card),
"note", note,
NULL);
+ else
+ gtk_object_set(GTK_OBJECT(card),
+ "note", NULL,
+ NULL);
g_free(note);
dateedit = GNOME_DATE_EDIT(glade_xml_get_widget(editor->gui, "dateedit-birthday"));
diff --git a/addressbook/gui/contact-editor/e-contact-editor.h b/addressbook/gui/contact-editor/e-contact-editor.h
index fa31e73bde..a0bad6e1f9 100644
--- a/addressbook/gui/contact-editor/e-contact-editor.h
+++ b/addressbook/gui/contact-editor/e-contact-editor.h
@@ -115,6 +115,7 @@ struct _EContactEditor
ECardAddrLabel *address[E_CONTACT_EDITOR_ADDRESS_ID_LAST];
ECardName *name;
+ char *company;
EContactEditorEmailId email_choice;
EContactEditorPhoneId phone_choice[4];
diff --git a/addressbook/gui/minicard/e-minicard.c b/addressbook/gui/minicard/e-minicard.c
index 1b6138c87c..6ff1d94aeb 100644
--- a/addressbook/gui/minicard/e-minicard.c
+++ b/addressbook/gui/minicard/e-minicard.c
@@ -449,6 +449,7 @@ remodel( EMinicard *e_minicard )
{
if (e_minicard->card) {
char *fname;
+ char *file_as;
char *url;
char *org;
char *title;
@@ -469,6 +470,7 @@ remodel( EMinicard *e_minicard )
gtk_object_get(GTK_OBJECT(e_minicard->card),
"full_name", &fname,
+ "file_as", &file_as,
"address", &address_list,
"phone", &phone_list,
"email", &email_list,
@@ -478,17 +480,19 @@ remodel( EMinicard *e_minicard )
"role", &role,
NULL);
- if (fname) {
- add_field(e_minicard, "Name:", fname);
- if (e_minicard->header_text)
- gnome_canvas_item_set(e_minicard->header_text,
- "text", fname,
+ if (e_minicard->header_text) {
+ if (file_as)
+ gnome_canvas_item_set(e_minicard->header_text,
+ "text", file_as,
NULL);
- } else
- if (e_minicard->header_text)
+ else
gnome_canvas_item_set(e_minicard->header_text,
"text", "",
NULL);
+ }
+
+ if (fname)
+ add_field(e_minicard, "Name:", fname);
if (org)
add_field(e_minicard, "Company:", org);
@@ -592,7 +596,7 @@ e_minicard_get_card_id (EMinicard *minicard)
if (minicard->card) {
return e_card_get_id(minicard->card);
} else {
- return NULL;
+ return "";
}
}
@@ -605,20 +609,20 @@ e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2)
g_return_val_if_fail(E_IS_MINICARD(minicard2), 0);
if (minicard1->card && minicard2->card) {
- char *fname1, *fname2;
+ char *file_as1, *file_as2;
gtk_object_get(GTK_OBJECT(minicard1->card),
- "full_name", &fname1,
+ "file_as", &file_as1,
NULL);
gtk_object_get(GTK_OBJECT(minicard2->card),
- "full_name", &fname2,
+ "file_as", &file_as2,
NULL);
- if (fname1 && fname2)
- return strcmp(fname1, fname2);
- if (fname1)
+ if (file_as1 && file_as2)
+ return strcmp(file_as1, file_as2);
+ if (file_as1)
return -1;
- if (fname2)
+ if (file_as2)
return 1;
- return 0;
+ return strcmp(e_minicard_get_card_id(minicard1), e_minicard_get_card_id(minicard2));
} else {
return 0;
}
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index 1b6138c87c..6ff1d94aeb 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -449,6 +449,7 @@ remodel( EMinicard *e_minicard )
{
if (e_minicard->card) {
char *fname;
+ char *file_as;
char *url;
char *org;
char *title;
@@ -469,6 +470,7 @@ remodel( EMinicard *e_minicard )
gtk_object_get(GTK_OBJECT(e_minicard->card),
"full_name", &fname,
+ "file_as", &file_as,
"address", &address_list,
"phone", &phone_list,
"email", &email_list,
@@ -478,17 +480,19 @@ remodel( EMinicard *e_minicard )
"role", &role,
NULL);
- if (fname) {
- add_field(e_minicard, "Name:", fname);
- if (e_minicard->header_text)
- gnome_canvas_item_set(e_minicard->header_text,
- "text", fname,
+ if (e_minicard->header_text) {
+ if (file_as)
+ gnome_canvas_item_set(e_minicard->header_text,
+ "text", file_as,
NULL);
- } else
- if (e_minicard->header_text)
+ else
gnome_canvas_item_set(e_minicard->header_text,
"text", "",
NULL);
+ }
+
+ if (fname)
+ add_field(e_minicard, "Name:", fname);
if (org)
add_field(e_minicard, "Company:", org);
@@ -592,7 +596,7 @@ e_minicard_get_card_id (EMinicard *minicard)
if (minicard->card) {
return e_card_get_id(minicard->card);
} else {
- return NULL;
+ return "";
}
}
@@ -605,20 +609,20 @@ e_minicard_compare (EMinicard *minicard1, EMinicard *minicard2)
g_return_val_if_fail(E_IS_MINICARD(minicard2), 0);
if (minicard1->card && minicard2->card) {
- char *fname1, *fname2;
+ char *file_as1, *file_as2;
gtk_object_get(GTK_OBJECT(minicard1->card),
- "full_name", &fname1,
+ "file_as", &file_as1,
NULL);
gtk_object_get(GTK_OBJECT(minicard2->card),
- "full_name", &fname2,
+ "file_as", &file_as2,
NULL);
- if (fname1 && fname2)
- return strcmp(fname1, fname2);
- if (fname1)
+ if (file_as1 && file_as2)
+ return strcmp(file_as1, file_as2);
+ if (file_as1)
return -1;
- if (fname2)
+ if (file_as2)
return 1;
- return 0;
+ return strcmp(e_minicard_get_card_id(minicard1), e_minicard_get_card_id(minicard2));
} else {
return 0;
}