[gnome-control-center/wip/privacy-swarm: 1/12] power: Move helper function to panels/common
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/privacy-swarm: 1/12] power: Move helper function to panels/common
- Date: Wed, 6 Nov 2019 13:55:10 +0000 (UTC)
commit 01d0cf042c929e80bd12c0b50350baea09bf0eea
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Nov 6 10:15:51 2019 -0300
power: Move helper function to panels/common
It will be used by the Lock Screen panel in the future.
panels/common/cc-util.c | 43 +++++++++++++++++++++++++++++++++++++++++++
panels/common/cc-util.h | 1 +
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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]