diff --git a/src/friendlist.c b/src/friendlist.c index 486cb77..483cf7d 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -14,6 +14,7 @@ #include "chat.h" #include "friendlist.h" +#include "misc_tools.h" extern char *DATA_FILE; extern ToxWindow *prompt; @@ -22,7 +23,12 @@ static int max_friends_index = 0; /* marks the index of the last friend in fr static int num_friends = 0; static int num_selected = 0; -static int friendlist_index[MAX_FRIENDS_NUM]; +static int friendlist_index[MAX_FRIENDS_NUM] = {0}; + +int index_name_cmp(const void *n1, const void *n2) +{ + return name_compare(friends[*(int *) n1].name, friends[*(int *) n2].name); +} /* sorts friendlist_index by connection status */ void sort_friendlist_index(void) @@ -44,6 +50,10 @@ void sort_friendlist_index(void) off_friends[off_cnt++] = friends[i].num; } + /* Sort both groups alphabetically*/ + qsort(on_friends, on_cnt, sizeof(int), index_name_cmp); + qsort(off_friends, off_cnt, sizeof(int), index_name_cmp); + /* update friendlist_index, putting online friends before offline friends */ for (i = 0; i < on_cnt; ++i) friendlist_index[i] = on_friends[i]; diff --git a/src/groupchat.h b/src/groupchat.h index a8b4f48..4778112 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -2,7 +2,6 @@ * Toxic -- Tox Curses Client */ -/* The sidebar will take up y/n of the window width where x is the full width of the window */ #define SIDEBAR_WIDTH 16 #define CHATBOX_HEIGHT 4 diff --git a/src/misc_tools.h b/src/misc_tools.h index ccda726..79c660d 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -29,4 +29,4 @@ bool timed_out(uint64_t timestamp, uint64_t timeout, uint64_t curtime); void alert_window(ToxWindow *self); /* case-insensitive string compare function for use with qsort - same return logic as strcmp */ -int name_compare(const void *nick1, const void *nick2); \ No newline at end of file +int name_compare(const void *nick1, const void *nick2);