diff options
author | Georges Basile Stavracas Neto <georges.stavracas@gmail.com> | 2019-11-06 10:15:51 -0300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2019-11-07 14:19:23 +1300 |
commit | 255a1ab948208bf1540ec2657bd6b1175f2bc518 (patch) | |
tree | edc4448f99efa04d1d01611f66eb220982076b6e | |
parent | af76f51976ed9eef3d5cbe71c19ccbc9c61e9ddf (diff) | |
download | gnome-control-center-255a1ab948208bf1540ec2657bd6b1175f2bc518.tar.gz |
power: Move helper function to panels/common
It will be used by the Lock Screen panel in the future.
-rw-r--r-- | panels/common/cc-util.c | 43 | ||||
-rw-r--r-- | panels/common/cc-util.h | 1 | ||||
-rw-r--r-- | panels/power/cc-power-panel.c | 43 |
3 files changed, 46 insertions, 41 deletions
diff --git a/panels/common/cc-util.c b/panels/common/cc-util.c index d64125362..d37846a28 100644 --- a/panels/common/cc-util.c +++ b/panels/common/cc-util.c @@ -144,3 +144,46 @@ cc_util_get_smart_date (GDateTime *date) } } } + +/* Copied from src/properties/bacon-video-widget-properties.c + * in totem */ +char * +cc_util_time_to_string_text (gint64 msecs) +{ + g_autofree gchar *hours = NULL; + g_autofree gchar *mins = NULL; + g_autofree gchar *secs = NULL; + gint sec, min, hour, _time; + + _time = (int) (msecs / 1000); + sec = _time % 60; + _time = _time - sec; + min = (_time % (60*60)) / 60; + _time = _time - (min * 60); + hour = _time / (60*60); + + hours = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d hour", "%d hours", hour), hour); + mins = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d minute", "%d minutes", min), min); + secs = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d second", "%d seconds", sec), sec); + + if (hour > 0) + { + /* 5 hours 2 minutes 12 seconds */ + return g_strdup_printf (C_("time", "%s %s %s"), hours, mins, secs); + } + else if (min > 0) + { + /* 2 minutes 12 seconds */ + return g_strdup_printf (C_("time", "%s %s"), mins, secs); + } + else if (sec > 0) + { + /* 10 seconds */ + return g_strdup (secs); + } + else + { + /* 0 seconds */ + return g_strdup (_("0 seconds")); + } +} diff --git a/panels/common/cc-util.h b/panels/common/cc-util.h index 538d3582a..131c2afb7 100644 --- a/panels/common/cc-util.h +++ b/panels/common/cc-util.h @@ -24,3 +24,4 @@ char * cc_util_normalize_casefold_and_unaccent (const char *str); char * cc_util_get_smart_date (GDateTime *date); +char * cc_util_time_to_string_text (gint64 msecs); diff --git a/panels/power/cc-power-panel.c b/panels/power/cc-power-panel.c index f65a80730..98b19d0db 100644 --- a/panels/power/cc-power-panel.c +++ b/panels/power/cc-power-panel.c @@ -33,6 +33,7 @@ #include "list-box-helper.h" #include "cc-power-panel.h" #include "cc-power-resources.h" +#include "cc-util.h" /* Uncomment this to test the behaviour of the panel in * battery-less situations: @@ -1254,46 +1255,6 @@ combo_time_changed_cb (GtkWidget *widget, CcPowerPanel *self) g_settings_set_int (self->gsd_settings, key, value); } -/* Copied from src/properties/bacon-video-widget-properties.c - * in totem */ -static char * -time_to_string_text (gint64 msecs) -{ - int sec, min, hour, _time; - g_autofree gchar *hours = NULL; - g_autofree gchar *mins = NULL; - g_autofree gchar *secs = NULL; - - _time = (int) (msecs / 1000); - sec = _time % 60; - _time = _time - sec; - min = (_time % (60*60)) / 60; - _time = _time - (min * 60); - hour = _time / (60*60); - - hours = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d hour", "%d hours", hour), hour); - - mins = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d minute", - "%d minutes", min), min); - - secs = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%d second", - "%d seconds", sec), sec); - - if (hour > 0) { - /* 5 hours 2 minutes 12 seconds */ - return g_strdup_printf (C_("time", "%s %s %s"), hours, mins, secs); - } else if (min > 0) { - /* 2 minutes 12 seconds */ - return g_strdup_printf (C_("time", "%s %s"), mins, secs); - } else if (sec > 0) { - /* 10 seconds */ - return g_strdup (secs); - } else { - /* 0 seconds */ - return g_strdup (_("0 seconds")); - } -} - static void set_value_for_combo (GtkComboBox *combo_box, gint value) { @@ -1335,7 +1296,7 @@ set_value_for_combo (GtkComboBox *combo_box, gint value) /* The value is not listed, so add it at the best point (or the end). */ gtk_list_store_insert_before (GTK_LIST_STORE (model), &new, insert); - text = time_to_string_text (value * 1000); + text = cc_util_time_to_string_text (value * 1000); gtk_list_store_set (GTK_LIST_STORE (model), &new, ACTION_MODEL_TEXT, text, ACTION_MODEL_VALUE, value, |