1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into openpgp

This commit is contained in:
James Booth 2015-05-07 00:26:45 +01:00
commit 8c347de298
5 changed files with 37 additions and 22 deletions

View File

@ -45,7 +45,9 @@
struct p_contact_t { struct p_contact_t {
char *barejid; char *barejid;
gchar *barejid_collate_key;
char *name; char *name;
gchar *name_collate_key;
GSList *groups; GSList *groups;
char *subscription; char *subscription;
char *offline_message; char *offline_message;
@ -62,11 +64,14 @@ p_contact_new(const char * const barejid, const char * const name,
{ {
PContact contact = malloc(sizeof(struct p_contact_t)); PContact contact = malloc(sizeof(struct p_contact_t));
contact->barejid = strdup(barejid); contact->barejid = strdup(barejid);
contact->barejid_collate_key = g_utf8_collate_key(contact->barejid, -1);
if (name) { if (name) {
contact->name = strdup(name); contact->name = strdup(name);
contact->name_collate_key = g_utf8_collate_key(contact->name, -1);
} else { } else {
contact->name = NULL; contact->name = NULL;
contact->name_collate_key = NULL;
} }
contact->groups = groups; contact->groups = groups;
@ -96,8 +101,10 @@ void
p_contact_set_name(const PContact contact, const char * const name) p_contact_set_name(const PContact contact, const char * const name)
{ {
FREE_SET_NULL(contact->name); FREE_SET_NULL(contact->name);
FREE_SET_NULL(contact->name_collate_key);
if (name) { if (name) {
contact->name = strdup(name); contact->name = strdup(name);
contact->name_collate_key = g_utf8_collate_key(contact->name, -1);
} }
} }
@ -146,7 +153,9 @@ p_contact_free(PContact contact)
{ {
if (contact) { if (contact) {
free(contact->barejid); free(contact->barejid);
free(contact->barejid_collate_key);
free(contact->name); free(contact->name);
free(contact->name_collate_key);
free(contact->subscription); free(contact->subscription);
free(contact->offline_message); free(contact->offline_message);
@ -170,12 +179,24 @@ p_contact_barejid(const PContact contact)
return contact->barejid; return contact->barejid;
} }
const char *
p_contact_barejid_collate_key(const PContact contact)
{
return contact->barejid_collate_key;
}
const char * const char *
p_contact_name(const PContact contact) p_contact_name(const PContact contact)
{ {
return contact->name; return contact->name;
} }
const char *
p_contact_name_collate_key(const PContact contact)
{
return contact->name_collate_key;
}
const char * const char *
p_contact_name_or_jid(const PContact contact) p_contact_name_or_jid(const PContact contact)
{ {

View File

@ -47,7 +47,9 @@ void p_contact_add_resource(PContact contact, Resource *resource);
gboolean p_contact_remove_resource(PContact contact, const char * const resource); gboolean p_contact_remove_resource(PContact contact, const char * const resource);
void p_contact_free(PContact contact); void p_contact_free(PContact contact);
const char* p_contact_barejid(PContact contact); const char* p_contact_barejid(PContact contact);
const char* p_contact_barejid_collate_key(PContact contact);
const char* p_contact_name(PContact contact); const char* p_contact_name(PContact contact);
const char* p_contact_name_collate_key(PContact contact);
const char* p_contact_name_or_jid(const PContact contact); const char* p_contact_name_or_jid(const PContact contact);
const char* p_contact_presence(PContact contact); const char* p_contact_presence(PContact contact);
const char* p_contact_status(PContact contact); const char* p_contact_status(PContact contact);

View File

@ -832,16 +832,10 @@ _free_room(ChatRoom *room)
static static
gint _compare_occupants(Occupant *a, Occupant *b) gint _compare_occupants(Occupant *a, Occupant *b)
{ {
const char * utf8_str_a = a->nick; const char * utf8_str_a = a->nick_collate_key;
const char * utf8_str_b = b->nick; const char * utf8_str_b = b->nick_collate_key;
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); gint result = g_strcmp0(utf8_str_a, utf8_str_b);
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
gint result = g_strcmp0(key_a, key_b);
g_free(key_a);
g_free(key_b);
return result; return result;
} }
@ -947,8 +941,10 @@ _muc_occupant_new(const char *const nick, const char * const jid, muc_role_t rol
if (nick) { if (nick) {
occupant->nick = strdup(nick); occupant->nick = strdup(nick);
occupant->nick_collate_key = g_utf8_collate_key(occupant->nick, -1);
} else { } else {
occupant->nick = NULL; occupant->nick = NULL;
occupant->nick_collate_key = NULL;
} }
if (jid) { if (jid) {
@ -976,6 +972,7 @@ _occupant_free(Occupant *occupant)
{ {
if (occupant) { if (occupant) {
free(occupant->nick); free(occupant->nick);
free(occupant->nick_collate_key);
free(occupant->jid); free(occupant->jid);
free(occupant->status); free(occupant->status);
free(occupant); free(occupant);

View File

@ -64,6 +64,7 @@ typedef enum {
typedef struct _muc_occupant_t { typedef struct _muc_occupant_t {
char *nick; char *nick;
gchar *nick_collate_key;
char *jid; char *jid;
muc_role_t role; muc_role_t role;
muc_affiliation_t affiliation; muc_affiliation_t affiliation;

View File

@ -507,24 +507,18 @@ gint _compare_contacts(PContact a, PContact b)
const char * utf8_str_a = NULL; const char * utf8_str_a = NULL;
const char * utf8_str_b = NULL; const char * utf8_str_b = NULL;
if (p_contact_name(a)) { if (p_contact_name_collate_key(a)) {
utf8_str_a = p_contact_name(a); utf8_str_a = p_contact_name_collate_key(a);
} else { } else {
utf8_str_a = p_contact_barejid(a); utf8_str_a = p_contact_barejid_collate_key(a);
} }
if (p_contact_name(b)) { if (p_contact_name_collate_key(b)) {
utf8_str_b = p_contact_name(b); utf8_str_b = p_contact_name_collate_key(b);
} else { } else {
utf8_str_b = p_contact_barejid(b); utf8_str_b = p_contact_barejid_collate_key(b);
} }
gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); gint result = g_strcmp0(utf8_str_a, utf8_str_b);
gchar *key_b = g_utf8_collate_key(utf8_str_b, -1);
gint result = g_strcmp0(key_a, key_b);
g_free(key_a);
g_free(key_b);
return result; return result;
} }