aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-07 00:26:45 +0100
committerJames Booth <boothj5@gmail.com>2015-05-07 00:26:45 +0100
commit8c347de298609b647cb1243e13125affa96491f3 (patch)
treed1a238b9094372df01b699ae46c103c72405a1bc /src
parent6840f3b599ad278a9de869fc385a96a1f1a61943 (diff)
parent6fd9b179a08126deb20d6efedac3089e9bf432cb (diff)
downloadprofani-tty-8c347de298609b647cb1243e13125affa96491f3.tar.gz
Merge branch 'master' into openpgp
Diffstat (limited to 'src')
-rw-r--r--src/contact.c21
-rw-r--r--src/contact.h2
-rw-r--r--src/muc.c15
-rw-r--r--src/muc.h1
-rw-r--r--src/roster_list.c20
5 files changed, 37 insertions, 22 deletions
diff --git a/src/contact.c b/src/contact.c
index 993ede7c..713af955 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -45,7 +45,9 @@
struct p_contact_t {
char *barejid;
+ gchar *barejid_collate_key;
char *name;
+ gchar *name_collate_key;
GSList *groups;
char *subscription;
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));
contact->barejid = strdup(barejid);
+ contact->barejid_collate_key = g_utf8_collate_key(contact->barejid, -1);
if (name) {
contact->name = strdup(name);
+ contact->name_collate_key = g_utf8_collate_key(contact->name, -1);
} else {
contact->name = NULL;
+ contact->name_collate_key = NULL;
}
contact->groups = groups;
@@ -96,8 +101,10 @@ void
p_contact_set_name(const PContact contact, const char * const name)
{
FREE_SET_NULL(contact->name);
+ FREE_SET_NULL(contact->name_collate_key);
if (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) {
free(contact->barejid);
+ free(contact->barejid_collate_key);
free(contact->name);
+ free(contact->name_collate_key);
free(contact->subscription);
free(contact->offline_message);
@@ -171,12 +180,24 @@ p_contact_barejid(const PContact contact)
}
const char *
+p_contact_barejid_collate_key(const PContact contact)
+{
+ return contact->barejid_collate_key;
+}
+
+const char *
p_contact_name(const PContact contact)
{
return contact->name;
}
const char *
+p_contact_name_collate_key(const PContact contact)
+{
+ return contact->name_collate_key;
+}
+
+const char *
p_contact_name_or_jid(const PContact contact)
{
if (contact->name) {
diff --git a/src/contact.h b/src/contact.h
index a08aef43..343b230f 100644
--- a/src/contact.h
+++ b/src/contact.h
@@ -47,7 +47,9 @@ void p_contact_add_resource(PContact contact, Resource *resource);
gboolean p_contact_remove_resource(PContact contact, const char * const resource);
void p_contact_free(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_collate_key(PContact contact);
const char* p_contact_name_or_jid(const PContact contact);
const char* p_contact_presence(PContact contact);
const char* p_contact_status(PContact contact);
diff --git a/src/muc.c b/src/muc.c
index 6fd09de3..d283b55e 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -832,16 +832,10 @@ _free_room(ChatRoom *room)
static
gint _compare_occupants(Occupant *a, Occupant *b)
{
- const char * utf8_str_a = a->nick;
- const char * utf8_str_b = b->nick;
+ const char * utf8_str_a = a->nick_collate_key;
+ const char * utf8_str_b = b->nick_collate_key;
- gchar *key_a = g_utf8_collate_key(utf8_str_a, -1);
- 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);
+ gint result = g_strcmp0(utf8_str_a, utf8_str_b);
return result;
}
@@ -947,8 +941,10 @@ _muc_occupant_new(const char *const nick, const char * const jid, muc_role_t rol
if (nick) {
occupant->nick = strdup(nick);
+ occupant->nick_collate_key = g_utf8_collate_key(occupant->nick, -1);
} else {
occupant->nick = NULL;
+ occupant->nick_collate_key = NULL;
}
if (jid) {
@@ -976,6 +972,7 @@ _occupant_free(Occupant *occupant)
{
if (occupant) {
free(occupant->nick);
+ free(occupant->nick_collate_key);
free(occupant->jid);
free(occupant->status);
free(occupant);
diff --git a/src/muc.h b/src/muc.h
index cdaa10bd..ad96f3d9 100644
--- a/src/muc.h
+++ b/src/muc.h
@@ -64,6 +64,7 @@ typedef enum {
typedef struct _muc_occupant_t {
char *nick;
+ gchar *nick_collate_key;
char *jid;
muc_role_t role;
muc_affiliation_t affiliation;
diff --git a/src/roster_list.c b/src/roster_list.c
index d5e1c4a0..2d9df860 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -507,24 +507,18 @@ gint _compare_contacts(PContact a, PContact b)
const char * utf8_str_a = NULL;
const char * utf8_str_b = NULL;
- if (p_contact_name(a)) {
- utf8_str_a = p_contact_name(a);
+ if (p_contact_name_collate_key(a)) {
+ utf8_str_a = p_contact_name_collate_key(a);
} else {
- utf8_str_a = p_contact_barejid(a);
+ utf8_str_a = p_contact_barejid_collate_key(a);
}
- if (p_contact_name(b)) {
- utf8_str_b = p_contact_name(b);
+ if (p_contact_name_collate_key(b)) {
+ utf8_str_b = p_contact_name_collate_key(b);
} 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);
- 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);
+ gint result = g_strcmp0(utf8_str_a, utf8_str_b);
return result;
}