From fed8f0f410d7f5132dec92e16a78cf46bfef7bfd Mon Sep 17 00:00:00 2001 From: Kaian Date: Wed, 14 Dec 2016 15:21:49 +0100 Subject: [PATCH] cl: Add new setting to select default sorting options #161 --- src/setting.c | 2 ++ src/setting.h | 2 ++ src/sip.c | 12 +++++++++--- src/sip_attr.c | 2 +- src/sip_attr.h | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/setting.c b/src/setting.c index 57afc51..a108b1a 100644 --- a/src/setting.c +++ b/src/setting.c @@ -57,6 +57,8 @@ setting_t settings[SETTING_COUNT] = { { SETTING_CL_SCROLLSTEP, "cl.scrollstep", SETTING_FMT_NUMBER, "4", NULL }, { SETTING_CL_COLORATTR, "cl.colorattr", SETTING_FMT_ENUM, SETTING_ON, SETTING_ENUM_ONOFF }, { SETTING_CL_AUTOSCROLL, "cl.autoscroll", SETTING_FMT_ENUM, SETTING_OFF, SETTING_ENUM_ONOFF }, + { SETTING_CL_SORTFIELD, "cl.sortfield", SETTING_FMT_STRING, "index", NULL }, + { SETTING_CL_SORTORDER, "cl.sortorder", SETTING_FMT_STRING, "asc", NULL }, { SETTING_CF_FORCERAW, "cf.forceraw", SETTING_FMT_ENUM, SETTING_ON, SETTING_ENUM_ONOFF }, { SETTING_CF_RAWMINWIDTH, "cf.rawminwidth", SETTING_FMT_NUMBER, "40", NULL }, { SETTING_CF_RAWFIXEDWIDTH, "cf.rawfixedwidth", SETTING_FMT_NUMBER, "", NULL }, diff --git a/src/setting.h b/src/setting.h index 4603b1b..cadbfeb 100644 --- a/src/setting.h +++ b/src/setting.h @@ -87,6 +87,8 @@ enum setting_id { SETTING_CL_SCROLLSTEP, SETTING_CL_COLORATTR, SETTING_CL_AUTOSCROLL, + SETTING_CL_SORTFIELD, + SETTING_CL_SORTORDER, SETTING_CF_FORCERAW, SETTING_CF_RAWMINWIDTH, SETTING_CF_RAWFIXEDWIDTH, diff --git a/src/sip.c b/src/sip.c index cefe8ee..af299f8 100644 --- a/src/sip.c +++ b/src/sip.c @@ -156,9 +156,15 @@ sip_init(int limit, int only_calls, int no_incomplete) // Create hash table for callid search calls.callids = htable_create(calls.limit); - // By default sort by call index ascending - calls.sort.by = SIP_ATTR_CALLINDEX; - calls.sort.asc = true; + // Set default sorting field + if (sip_attr_from_name(setting_get_value(SETTING_CL_SORTFIELD)) >= 0) { + calls.sort.by = sip_attr_from_name(setting_get_value(SETTING_CL_SORTFIELD)); + calls.sort.asc = (!strcmp(setting_get_value(SETTING_CL_SORTORDER), "asc")); + } else { + // Fallback to default sorting field + calls.sort.by = SIP_ATTR_CALLINDEX; + calls.sort.asc = true; + } // Initialize payload parsing regexp match_flags = REG_EXTENDED | REG_ICASE | REG_NEWLINE; diff --git a/src/sip_attr.c b/src/sip_attr.c index a8e0f5b..827e14c 100644 --- a/src/sip_attr.c +++ b/src/sip_attr.c @@ -105,7 +105,7 @@ sip_attr_get_width(enum sip_attr_id id) return 0; } -enum sip_attr_id +int sip_attr_from_name(const char *name) { int i; diff --git a/src/sip_attr.h b/src/sip_attr.h index 0042ce2..ee99534 100644 --- a/src/sip_attr.h +++ b/src/sip_attr.h @@ -187,7 +187,7 @@ sip_attr_get_width(enum sip_attr_id id); * @param name Attribut name * @return Attribute id or -1 if not found */ -enum sip_attr_id +int sip_attr_from_name(const char *name); /**