1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 13:43:27 +01:00

sort friendlist alphabetically

This commit is contained in:
Jfreegman 2013-11-24 17:12:24 -05:00
parent d47429ecb7
commit e625bffbb4
3 changed files with 12 additions and 3 deletions

View File

@ -14,6 +14,7 @@
#include "chat.h" #include "chat.h"
#include "friendlist.h" #include "friendlist.h"
#include "misc_tools.h"
extern char *DATA_FILE; extern char *DATA_FILE;
extern ToxWindow *prompt; 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_friends = 0;
static int num_selected = 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 */ /* sorts friendlist_index by connection status */
void sort_friendlist_index(void) void sort_friendlist_index(void)
@ -44,6 +50,10 @@ void sort_friendlist_index(void)
off_friends[off_cnt++] = friends[i].num; 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 */ /* update friendlist_index, putting online friends before offline friends */
for (i = 0; i < on_cnt; ++i) for (i = 0; i < on_cnt; ++i)
friendlist_index[i] = on_friends[i]; friendlist_index[i] = on_friends[i];

View File

@ -2,7 +2,6 @@
* Toxic -- Tox Curses Client * 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 SIDEBAR_WIDTH 16
#define CHATBOX_HEIGHT 4 #define CHATBOX_HEIGHT 4