/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2002 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
*
* 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
#include <stdio.h>
#include <string.h>
+#include "utils.h"
#include "addritem.h"
#include "mgutils.h"
+#include "codeconv.h"
/**
* Create new email address item.
* \param value Name.
*/
void addritem_person_set_first_name( ItemPerson *person, const gchar *value ) {
- person->firstName = mgu_replace_string( person->firstName, value );
+ if (!value || g_utf8_validate(value, -1, NULL))
+ person->firstName = mgu_replace_string( person->firstName, value );
+ else {
+ gchar *out = conv_codeset_strdup(value,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ if (out)
+ person->firstName = mgu_replace_string( person->firstName, out );
+ g_free(out);
+ }
}
/**
* \param value name.
*/
void addritem_person_set_last_name( ItemPerson *person, const gchar *value ) {
- person->lastName = mgu_replace_string( person->lastName, value );
+ if (!value || g_utf8_validate(value, -1, NULL))
+ person->lastName = mgu_replace_string( person->lastName, value );
+ else {
+ gchar *out = conv_codeset_strdup(value,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ if (out)
+ person->lastName = mgu_replace_string( person->lastName, out );
+ g_free(out);
+ }
}
/**
* \param value name.
*/
void addritem_person_set_nick_name( ItemPerson *person, const gchar *value ) {
- person->nickName = mgu_replace_string( person->nickName, value );
+ if (!value || g_utf8_validate(value, -1, NULL))
+ person->nickName = mgu_replace_string( person->nickName, value );
+ else {
+ gchar *out = conv_codeset_strdup(value,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ if (out)
+ person->nickName = mgu_replace_string( person->nickName, out );
+ g_free(out);
+ }
}
/**
* \param value name.
*/
void addritem_person_set_common_name( ItemPerson *person, const gchar *value ) {
- ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), value );
+ if (!value || g_utf8_validate(value, -1, NULL))
+ ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), value );
+ else {
+ gchar *out = conv_codeset_strdup(value,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ if (out)
+ ADDRITEM_NAME(person) = mgu_replace_string( ADDRITEM_NAME(person), out );
+ g_free(out);
+ }
}
/**
return NULL;
}
+/**
+ * Remove person object for specified group.
+ * \param group Group from which to remove address.
+ * \param email EMail to remove
+ * \return EMail object, or <i>NULL if email not found in group. Note that
+ * this object is referenced (linked) to a group and should *NOT*
+ * be freed. An E-Mail object object should only be freed after
+ * removing from a person.
+ */
+ItemPerson *addritem_folder_remove_person( ItemFolder *group, ItemPerson *person ) {
+ if( group && person ) {
+ GList *node = group->listPerson;
+ while( node ) {
+ if( node->data == person ) {
+ group->listPerson = g_list_remove( group->listPerson, person );
+ return person;
+ }
+ node = g_list_next( node );
+ }
+ }
+ return NULL;
+}
+
/**
* Remove email address of specified ID for specified group.
* \param group Group from which to remove address.
folder->listGroup = NULL;
folder->folderType = ADDRFOLDER_NONE;
folder->folderData = NULL;
+ folder->isHidden = FALSE;
return folder;
}
folder->remarks = mgu_replace_string( folder->remarks, value );
}
+/**
+ * Specify visibility of folder.
+ * \param folder Folder.
+ * \param value Set to <code>TRUE</code> to hide folder.
+ */
+void addritem_folder_set_hidden( ItemFolder *folder, const gboolean value ) {
+ folder->isHidden = value;
+}
+
/**
* Free address folder. Note: this does not free up the lists of children
* (folders, groups and person). This should be done prior to calling this
folder->listPerson = NULL;
folder->folderType = ADDRFOLDER_NONE;
folder->folderData = NULL;
+ folder->isHidden = FALSE;
g_free( folder );
}
fprintf( stream, "\tnam: '%s'\n", ADDRITEM_NAME(folder) );
fprintf( stream, "\trem: '%s'\n", folder->remarks );
fprintf( stream, "\ttyp: %d\n", folder->folderType );
+ fprintf( stream, "\thid: %s\n", folder->isHidden ? "hidden" : "visible" );
fprintf( stream, "\t---\n" );
parent = ( ItemFolder * ) ADDRITEM_PARENT(folder);
if( parent ) {