Skip to content
Snippets Groups Projects
Commit 4d342d6f authored by Tristan Matthews's avatar Tristan Matthews
Browse files

gnome: add years to timer and reuse for call history display

Refs #47119

Change-Id: I9a7f0e5f6633feec4e9322ad9f38a2c6039b012a
parent 74a97294
Branches
Tags
No related merge requests found
......@@ -41,6 +41,7 @@
#include "contacts/calltree.h"
#include "dbus.h"
#include <unistd.h>
#include <stdint.h>
gint get_state_callstruct(gconstpointer a, gconstpointer b)
{
......@@ -193,12 +194,40 @@ gchar* get_peer_info(const gchar* const number, const gchar* const name)
gchar* get_call_duration(callable_obj_t *obj)
{
long duration = difftime(obj->_time_stop, obj->_time_start);
char time_str[32];
format_duration(obj, obj->_time_stop, time_str, sizeof time_str);
if (duration < 0)
duration = 0;
return g_strdup_printf("<small>Duration:</small> %s", time_str);
}
return g_strdup_printf("<small>Duration:</small> %.2ld:%.2ld" , duration/60 , duration%60);
void
format_duration(callable_obj_t *obj, time_t end, char *timestr, size_t timestr_sz)
{
const gdouble diff = difftime(end, obj->_time_start);
guint32 seconds = CLAMP(diff, 0.0f, UINT32_MAX);
enum {HOURS_PER_DAY = 24, DAYS_PER_YEAR = 365, SECONDS_PER_HOUR = 3600,
SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY,
SECONDS_PER_YEAR = DAYS_PER_YEAR * SECONDS_PER_DAY};
const guint32 years = seconds / SECONDS_PER_YEAR;
const guint32 days = (seconds / SECONDS_PER_DAY) % DAYS_PER_YEAR;
const guint32 hours = (seconds / SECONDS_PER_HOUR) % HOURS_PER_DAY;
const guint32 minutes = (seconds / 60) % 60;
seconds %= 60;
if (years)
g_snprintf(timestr, timestr_sz, _("%uy %ud %02uh %02umn %02us"),
years, days, hours, minutes, seconds);
else if (days)
g_snprintf(timestr, timestr_sz, _("%ud %02uh %02umn %02us"),
days, hours, minutes, seconds);
else if (hours)
g_snprintf(timestr, timestr_sz, "%u:%02u:%02u",
hours, minutes, seconds);
else
g_snprintf(timestr, timestr_sz, "%02u:%02u",
minutes, seconds);
}
static
......
......@@ -197,6 +197,8 @@ gchar* get_call_duration(callable_obj_t *obj);
gchar* get_formatted_start_timestamp(time_t);
void format_duration(callable_obj_t *obj, time_t end, char *timestr, size_t timestr_sz);
gboolean call_was_outgoing(callable_obj_t * obj);
void restore_call(const gchar *id);
......
......@@ -1170,29 +1170,6 @@ void calltree_display(calltab_t *tab, SFLPhoneClient *client)
update_actions(client);
}
static void
format_duration(guint32 seconds, char *timestr, size_t timestr_sz)
{
enum {HOURS_PER_DAY = 24, SECONDS_PER_HOUR = 3600,
SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY};
const guint32 days = seconds / SECONDS_PER_DAY;
const guint32 hours = (seconds / SECONDS_PER_HOUR) % HOURS_PER_DAY;
const guint32 minutes = (seconds / 60) % 60;
seconds %= 60;
if (days)
g_snprintf(timestr, timestr_sz, _("%ud %02uh %02umn %02us"),
days, hours, minutes, seconds);
else
if (hours)
g_snprintf(timestr, timestr_sz, "%u:%02u:%02u",
hours, minutes, seconds);
else
g_snprintf(timestr, timestr_sz, "%02u:%02u",
minutes, seconds);
}
gboolean calltree_update_clock(G_GNUC_UNUSED gpointer data)
{
if (calllist_empty(current_calls_tab))
......@@ -1200,7 +1177,6 @@ gboolean calltree_update_clock(G_GNUC_UNUSED gpointer data)
char timestr[32];
const gchar *msg = "";
double duration;
callable_obj_t *call = calltab_get_selected_call(current_calls_tab);
if (call) {
......@@ -1213,9 +1189,7 @@ gboolean calltree_update_clock(G_GNUC_UNUSED gpointer data)
case CALL_STATE_BUSY:
break;
default:
duration = difftime(time(NULL), call->_time_start);
format_duration(CLAMP(duration, 0.0f, UINT32_MAX), timestr,
sizeof(timestr));
format_duration(call, time(NULL), timestr, sizeof(timestr));
msg = timestr;
break;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment