1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-27 02:43:25 +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 "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];

View File

@ -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

View File

@ -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);
int name_compare(const void *nick1, const void *nick2);