aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/backend
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@helixcode.com>2000-05-10 00:41:58 +0800
committerChris Lahey <clahey@src.gnome.org>2000-05-10 00:41:58 +0800
commit85faea789a7101eccd334b3b8734b9cb697a2d38 (patch)
tree5b35fb802fb14391b940180602566a03e94f4b11 /addressbook/backend
parent63687b2a3082e0e8731d6a91ba12aba860194542 (diff)
downloadgsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar.gz
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar.bz2
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar.lz
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar.xz
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.tar.zst
gsoc2013-evolution-85faea789a7101eccd334b3b8734b9cb697a2d38.zip
Make File As change if name or company are changed pretty much anywhere.
2000-05-09 Christopher James Lahey <clahey@helixcode.com> * backend/ebook/e-card-simple.c: Make File As change if name or company are changed pretty much anywhere. * gui/minicard/e-minicard.c: Turned off having minicard editing effect anything since it's so crashy. svn path=/trunk/; revision=2947
Diffstat (limited to 'addressbook/backend')
-rw-r--r--addressbook/backend/ebook/e-card-simple.c187
1 files changed, 161 insertions, 26 deletions
diff --git a/addressbook/backend/ebook/e-card-simple.c b/addressbook/backend/ebook/e-card-simple.c
index 58c44eb22f..6aac12742c 100644
--- a/addressbook/backend/ebook/e-card-simple.c
+++ b/addressbook/backend/ebook/e-card-simple.c
@@ -900,6 +900,128 @@ char *e_card_simple_get (ECardSimple *simple,
}
}
+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 (ECardSimple *simple)
+{
+ char *filestring = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FILE_AS);
+ char *trystring;
+ char *full_name = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FULL_NAME);
+ char *company = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_ORG);
+ ECardName *name = NULL;
+ int i;
+ int style;
+ style = 0;
+ if (!full_name)
+ full_name = g_strdup("");
+ if (!company)
+ company = g_strdup("");
+ if (filestring) {
+
+ name = e_card_name_from_string(full_name);
+
+ if (!name) {
+ goto end;
+ }
+
+ style = -1;
+
+ for (i = 0; i < 5; i++) {
+ trystring = name_to_style(name, company, i);
+ if (!strcmp(trystring, filestring)) {
+ g_free(trystring);
+ style = i;
+ goto end;
+ }
+ g_free(trystring);
+ }
+ }
+ end:
+
+ g_free(filestring);
+ g_free(full_name);
+ g_free(company);
+ if (name)
+ e_card_name_free(name);
+
+ return style;
+}
+
+static void
+file_as_set_style(ECardSimple *simple, int style)
+{
+ if (style != -1) {
+ char *string;
+ char *full_name = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_FULL_NAME);
+ char *company = e_card_simple_get(simple, E_CARD_SIMPLE_FIELD_ORG);
+ ECardName *name;
+
+ if (!full_name)
+ full_name = g_strdup("");
+ if (!company)
+ company = g_strdup("");
+ name = e_card_name_from_string(full_name);
+ if (name) {
+ string = name_to_style(name, company, style);
+ e_card_simple_set(simple, E_CARD_SIMPLE_FIELD_FILE_AS, string);
+ g_free(string);
+ }
+ g_free(full_name);
+ g_free(company);
+ e_card_name_free(name);
+ }
+}
+
void e_card_simple_set (ECardSimple *simple,
ECardSimpleField field,
const char *data)
@@ -907,36 +1029,49 @@ void e_card_simple_set (ECardSimple *simple,
ECardSimpleInternalType type = field_data[field].type;
ECardAddrLabel *address;
ECardPhone *phone;
- switch(type) {
- case E_CARD_SIMPLE_INTERNAL_TYPE_STRING:
+ int style;
+ switch (field) {
+ case E_CARD_SIMPLE_FIELD_FULL_NAME:
+ case E_CARD_SIMPLE_FIELD_ORG:
+ style = file_as_get_style(simple);
gtk_object_set(GTK_OBJECT(simple->card),
field_data[field].ecard_field, data,
NULL);
+ file_as_set_style(simple, style);
break;
- case E_CARD_SIMPLE_INTERNAL_TYPE_DATE:
- break; /* FIXME!!!! */
- case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS:
- address = e_card_address_label_new();
- address->data = (char *) data;
- e_card_simple_set_address(simple,
- field_data[field].list_type_index,
- address);
- address->data = NULL;
- e_card_address_label_free(address);
- break;
- case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE:
- phone = e_card_phone_new();
- phone->number = (char *) data;
- e_card_simple_set_phone(simple,
- field_data[field].list_type_index,
- phone);
- phone->number = NULL;
- e_card_phone_free(phone);
- break;
- case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL:
- e_card_simple_set_email(simple,
- field_data[field].list_type_index,
- data);
+ default:
+ switch(type) {
+ case E_CARD_SIMPLE_INTERNAL_TYPE_STRING:
+ gtk_object_set(GTK_OBJECT(simple->card),
+ field_data[field].ecard_field, data,
+ NULL);
+ break;
+ case E_CARD_SIMPLE_INTERNAL_TYPE_DATE:
+ break; /* FIXME!!!! */
+ case E_CARD_SIMPLE_INTERNAL_TYPE_ADDRESS:
+ address = e_card_address_label_new();
+ address->data = (char *) data;
+ e_card_simple_set_address(simple,
+ field_data[field].list_type_index,
+ address);
+ address->data = NULL;
+ e_card_address_label_free(address);
+ break;
+ case E_CARD_SIMPLE_INTERNAL_TYPE_PHONE:
+ phone = e_card_phone_new();
+ phone->number = (char *) data;
+ e_card_simple_set_phone(simple,
+ field_data[field].list_type_index,
+ phone);
+ phone->number = NULL;
+ e_card_phone_free(phone);
+ break;
+ case E_CARD_SIMPLE_INTERNAL_TYPE_EMAIL:
+ e_card_simple_set_email(simple,
+ field_data[field].list_type_index,
+ data);
+ break;
+ }
break;
}
}