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

Added roster rooms order preference

This commit is contained in:
James Booth 2016-01-09 22:21:09 +00:00
parent cd2458c019
commit de90243401
7 changed files with 74 additions and 1 deletions

View File

@ -281,6 +281,7 @@ static struct cmd_t command_defs[] =
"/roster hide [offline|resource|presence|status|empty|count|priority|rooms]", "/roster hide [offline|resource|presence|status|empty|count|priority|rooms]",
"/roster by group|presence|none", "/roster by group|presence|none",
"/roster order name|presence", "/roster order name|presence",
"/roster room order name|unread",
"/roster header char <char>|none", "/roster header char <char>|none",
"/roster presence indent <indent>", "/roster presence indent <indent>",
"/roster contact char <char>|none", "/roster contact char <char>|none",
@ -323,6 +324,8 @@ static struct cmd_t command_defs[] =
{ "by none", "No grouping in the roster panel." }, { "by none", "No grouping in the roster panel." },
{ "order name", "Order roster items by name only." }, { "order name", "Order roster items by name only." },
{ "order presence", "Order roster items by presence, and then by name." }, { "order presence", "Order roster items by presence, and then by name." },
{ "room order name", "Order roster rooms by name." },
{ "room order unread", "Order roster rooms by unread messages, and then by name." },
{ "header char <char>", "Prefix roster headers with specified character." }, { "header char <char>", "Prefix roster headers with specified character." },
{ "header char none", "Remove roster header character prefix." }, { "header char none", "Remove roster header character prefix." },
{ "contact char <char>", "Prefix roster contacts with specified character." }, { "contact char <char>", "Prefix roster contacts with specified character." },
@ -1895,6 +1898,8 @@ static Autocomplete roster_resource_ac;
static Autocomplete roster_presence_ac; static Autocomplete roster_presence_ac;
static Autocomplete roster_char_ac; static Autocomplete roster_char_ac;
static Autocomplete roster_remove_all_ac; static Autocomplete roster_remove_all_ac;
static Autocomplete roster_room_ac;
static Autocomplete roster_room_order_ac;
static Autocomplete group_ac; static Autocomplete group_ac;
static Autocomplete bookmark_ac; static Autocomplete bookmark_ac;
static Autocomplete bookmark_property_ac; static Autocomplete bookmark_property_ac;
@ -2155,6 +2160,7 @@ cmd_init(void)
autocomplete_add(roster_ac, "hide"); autocomplete_add(roster_ac, "hide");
autocomplete_add(roster_ac, "by"); autocomplete_add(roster_ac, "by");
autocomplete_add(roster_ac, "order"); autocomplete_add(roster_ac, "order");
autocomplete_add(roster_ac, "room");
autocomplete_add(roster_ac, "size"); autocomplete_add(roster_ac, "size");
autocomplete_add(roster_ac, "wrap"); autocomplete_add(roster_ac, "wrap");
autocomplete_add(roster_ac, "header"); autocomplete_add(roster_ac, "header");
@ -2199,6 +2205,13 @@ cmd_init(void)
autocomplete_add(roster_order_ac, "name"); autocomplete_add(roster_order_ac, "name");
autocomplete_add(roster_order_ac, "presence"); autocomplete_add(roster_order_ac, "presence");
roster_room_ac = autocomplete_new();
autocomplete_add(roster_room_ac, "order");
roster_room_order_ac = autocomplete_new();
autocomplete_add(roster_room_order_ac, "name");
autocomplete_add(roster_room_order_ac, "unread");
roster_remove_all_ac = autocomplete_new(); roster_remove_all_ac = autocomplete_new();
autocomplete_add(roster_remove_all_ac, "contacts"); autocomplete_add(roster_remove_all_ac, "contacts");
@ -2472,6 +2485,8 @@ cmd_uninit(void)
autocomplete_free(roster_show_ac); autocomplete_free(roster_show_ac);
autocomplete_free(roster_by_ac); autocomplete_free(roster_by_ac);
autocomplete_free(roster_order_ac); autocomplete_free(roster_order_ac);
autocomplete_free(roster_room_ac);
autocomplete_free(roster_room_order_ac);
autocomplete_free(roster_remove_all_ac); autocomplete_free(roster_remove_all_ac);
autocomplete_free(group_ac); autocomplete_free(group_ac);
autocomplete_free(bookmark_ac); autocomplete_free(bookmark_ac);
@ -2681,6 +2696,8 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(roster_show_ac); autocomplete_reset(roster_show_ac);
autocomplete_reset(roster_by_ac); autocomplete_reset(roster_by_ac);
autocomplete_reset(roster_order_ac); autocomplete_reset(roster_order_ac);
autocomplete_reset(roster_room_ac);
autocomplete_reset(roster_room_order_ac);
autocomplete_reset(roster_remove_all_ac); autocomplete_reset(roster_remove_all_ac);
autocomplete_reset(group_ac); autocomplete_reset(group_ac);
autocomplete_reset(titlebar_ac); autocomplete_reset(titlebar_ac);
@ -3087,6 +3104,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster room order", roster_room_order_ac, TRUE);
if (result) {
return result;
}
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status == JABBER_CONNECTED) { if (conn_status == JABBER_CONNECTED) {
@ -3124,6 +3145,10 @@ _roster_autocomplete(ProfWin *window, const char *const input)
if (result) { if (result) {
return result; return result;
} }
result = autocomplete_param_with_ac(input, "/roster room", roster_room_ac, TRUE);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/roster wrap", prefs_autocomplete_boolean_choice); result = autocomplete_param_with_func(input, "/roster wrap", prefs_autocomplete_boolean_choice);
if (result) { if (result) {
return result; return result;

View File

@ -2184,6 +2184,31 @@ cmd_roster(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
} else if (g_strcmp0(args[0], "room") == 0) {
if (g_strcmp0(args[1], "order") == 0) {
if (g_strcmp0(args[2], "name") == 0) {
cons_show("Ordering roster rooms by name");
prefs_set_string(PREF_ROSTER_ROOMS_ORDER, "name");
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else if (g_strcmp0(args[2], "unread") == 0) {
cons_show("Ordering roster rooms by unread messages");
prefs_set_string(PREF_ROSTER_ROOMS_ORDER, "unread");
if (conn_status == JABBER_CONNECTED) {
rosterwin_roster();
}
return TRUE;
} else {
cons_bad_cmd_usage(command);
return TRUE;
}
} else {
cons_bad_cmd_usage(command);
return TRUE;
}
// add contact // add contact
} else if (strcmp(args[0], "add") == 0) { } else if (strcmp(args[0], "add") == 0) {
if (conn_status != JABBER_CONNECTED) { if (conn_status != JABBER_CONNECTED) {

View File

@ -1047,6 +1047,7 @@ _get_group(preference_t pref)
case PREF_ROSTER_WRAP: case PREF_ROSTER_WRAP:
case PREF_ROSTER_RESOURCE_JOIN: case PREF_ROSTER_RESOURCE_JOIN:
case PREF_ROSTER_ROOMS: case PREF_ROSTER_ROOMS:
case PREF_ROSTER_ROOMS_ORDER:
case PREF_RESOURCE_TITLE: case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
case PREF_ENC_WARN: case PREF_ENC_WARN:
@ -1243,6 +1244,8 @@ _get_key(preference_t pref)
return "roster.resource.join"; return "roster.resource.join";
case PREF_ROSTER_ROOMS: case PREF_ROSTER_ROOMS:
return "roster.rooms"; return "roster.rooms";
case PREF_ROSTER_ROOMS_ORDER:
return "roster.rooms.order";
case PREF_RESOURCE_TITLE: case PREF_RESOURCE_TITLE:
return "resource.title"; return "resource.title";
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
@ -1330,6 +1333,8 @@ _get_default_string(preference_t pref)
return "presence"; return "presence";
case PREF_ROSTER_ORDER: case PREF_ROSTER_ORDER:
return "presence"; return "presence";
case PREF_ROSTER_ROOMS_ORDER:
return "name";
case PREF_TIME_CONSOLE: case PREF_TIME_CONSOLE:
return "%H:%M:%S"; return "%H:%M:%S";
case PREF_TIME_CHAT: case PREF_TIME_CHAT:

View File

@ -74,6 +74,7 @@ typedef enum {
PREF_ROSTER_WRAP, PREF_ROSTER_WRAP,
PREF_ROSTER_RESOURCE_JOIN, PREF_ROSTER_RESOURCE_JOIN,
PREF_ROSTER_ROOMS, PREF_ROSTER_ROOMS,
PREF_ROSTER_ROOMS_ORDER,
PREF_MUC_PRIVILEGES, PREF_MUC_PRIVILEGES,
PREF_PRESENCE, PREF_PRESENCE,
PREF_WRAP, PREF_WRAP,

View File

@ -476,6 +476,7 @@ _load_preferences(void)
_set_boolean_preference("roster.count", PREF_ROSTER_COUNT); _set_boolean_preference("roster.count", PREF_ROSTER_COUNT);
_set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY); _set_boolean_preference("roster.priority", PREF_ROSTER_PRIORITY);
_set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS); _set_boolean_preference("roster.rooms", PREF_ROSTER_ROOMS);
_set_string_preference("roster.rooms.order", PREF_ROSTER_ROOMS_ORDER);
if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) { if (g_key_file_has_key(theme, "ui", "roster.size", NULL)) {
gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL); gint roster_size = g_key_file_get_integer(theme, "ui", "roster.size", NULL);
prefs_set_roster_size(roster_size); prefs_set_roster_size(roster_size);

View File

@ -1337,6 +1337,10 @@ cons_roster_setting(void)
cons_show("Roster order (/roster) : %s", order); cons_show("Roster order (/roster) : %s", order);
prefs_free_string(order); prefs_free_string(order);
char *rooms_order = prefs_get_string(PREF_ROSTER_ROOMS_ORDER);
cons_show("Roster rooms order (/roster) : %s", rooms_order);
prefs_free_string(rooms_order);
int size = prefs_get_roster_size(); int size = prefs_get_roster_size();
cons_show("Roster size (/roster) : %d", size); cons_show("Roster size (/roster) : %d", size);

View File

@ -411,6 +411,12 @@ _rosterwin_room(ProfLayoutSplit *layout, ProfMucWin *mucwin)
} }
} }
static int
_compare_rooms_name(ProfMucWin *a, ProfMucWin *b)
{
return g_strcmp0(a->roomjid, b->roomjid);
}
static int static int
_compare_rooms_unread(ProfMucWin *a, ProfMucWin *b) _compare_rooms_unread(ProfMucWin *a, ProfMucWin *b)
{ {
@ -432,7 +438,13 @@ _rosterwin_rooms(ProfLayoutSplit *layout, gboolean newline)
while (curr_room) { while (curr_room) {
ProfMucWin *mucwin = wins_get_muc(curr_room->data); ProfMucWin *mucwin = wins_get_muc(curr_room->data);
if (mucwin) { if (mucwin) {
char *order = prefs_get_string(PREF_ROSTER_ROOMS_ORDER);
if (g_strcmp0(order, "unread") == 0) {
rooms_sorted = g_list_insert_sorted(rooms_sorted, mucwin, (GCompareFunc)_compare_rooms_unread); rooms_sorted = g_list_insert_sorted(rooms_sorted, mucwin, (GCompareFunc)_compare_rooms_unread);
} else {
rooms_sorted = g_list_insert_sorted(rooms_sorted, mucwin, (GCompareFunc)_compare_rooms_name);
}
prefs_free_string(order);
} }
curr_room = g_list_next(curr_room); curr_room = g_list_next(curr_room);
} }