[gnome-software/wip/hughsie/non-free: 2/6] trivial: Factor out some code for future use
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/non-free: 2/6] trivial: Factor out some code for future use
- Date: Mon, 29 Aug 2016 18:47:10 +0000 (UTC)
commit a99465783cb5abdad6af7553f54f6d236117881e
Author: Richard Hughes <richard hughsie com>
Date: Mon Aug 29 16:52:25 2016 +0100
trivial: Factor out some code for future use
src/gs-sources-dialog.c | 80 ++++++++++++++++++++++++++---------------------
1 files changed, 44 insertions(+), 36 deletions(-)
---
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index 0ed26d8..8c0dd24 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -51,25 +51,18 @@ struct _GsSourcesDialog
G_DEFINE_TYPE (GsSourcesDialog, gs_sources_dialog, GTK_TYPE_DIALOG)
-static void
-add_source (GtkListBox *listbox, GsApp *app)
+static gchar *
+get_source_installed_text (GsApp *app)
{
- GtkWidget *row;
GPtrArray *related;
guint cnt_addon = 0;
guint cnt_apps = 0;
guint i;
g_autofree gchar *addons_text = NULL;
g_autofree gchar *apps_text = NULL;
- g_autofree gchar *text = NULL;
-
- row = gs_sources_dialog_row_new ();
- gs_sources_dialog_row_set_name (GS_SOURCES_DIALOG_ROW (row),
- gs_app_get_name (app));
-
- related = gs_app_get_related (app);
/* split up the types */
+ related = gs_app_get_related (app);
for (i = 0; i < related->len; i++) {
GsApp *app_tmp = g_ptr_array_index (related, i);
switch (gs_app_get_kind (app_tmp)) {
@@ -88,44 +81,59 @@ add_source (GtkListBox *listbox, GsApp *app)
}
}
+ /* nothing! */
if (cnt_apps == 0 && cnt_addon == 0) {
/* TRANSLATORS: This string describes a software source that
has no software installed from it. */
- text = g_strdup (_("No applications or addons installed; other software might still be"));
- } else if (cnt_addon == 0) {
+ return g_strdup (_("No applications or addons installed; other software might still be"));
+ }
+ if (cnt_addon == 0) {
/* TRANSLATORS: This string is used to construct the 'X applications
installed' sentence, describing a software source. */
- text = g_strdup_printf (ngettext ("%u application installed",
+ return g_strdup_printf (ngettext ("%u application installed",
"%u applications installed",
cnt_apps), cnt_apps);
- } else if (cnt_apps == 0) {
+ }
+ if (cnt_apps == 0) {
/* TRANSLATORS: This string is used to construct the 'X add-ons
installed' sentence, describing a software source. */
- text = g_strdup_printf (ngettext ("%u add-on installed",
+ return g_strdup_printf (ngettext ("%u add-on installed",
"%u add-ons installed",
cnt_addon), cnt_addon);
- } else {
- /* TRANSLATORS: This string is used to construct the 'X applications
- and y add-ons installed' sentence, describing a software source.
- The correct form here depends on the number of applications. */
- apps_text = g_strdup_printf (ngettext ("%u application",
- "%u applications",
- cnt_apps), cnt_apps);
- /* TRANSLATORS: This string is used to construct the 'X applications
- and y add-ons installed' sentence, describing a software source.
- The correct form here depends on the number of add-ons. */
- addons_text = g_strdup_printf (ngettext ("%u add-on",
- "%u add-ons",
- cnt_addon), cnt_addon);
- /* TRANSLATORS: This string is used to construct the 'X applications
- and y add-ons installed' sentence, describing a software source.
- The correct form here depends on the total number of
- applications and add-ons. */
- text = g_strdup_printf (ngettext ("%s and %s installed",
- "%s and %s installed",
- cnt_apps + cnt_addon),
- apps_text, addons_text);
}
+
+ /* TRANSLATORS: This string is used to construct the 'X applications
+ and y add-ons installed' sentence, describing a software source.
+ The correct form here depends on the number of applications. */
+ apps_text = g_strdup_printf (ngettext ("%u application",
+ "%u applications",
+ cnt_apps), cnt_apps);
+ /* TRANSLATORS: This string is used to construct the 'X applications
+ and y add-ons installed' sentence, describing a software source.
+ The correct form here depends on the number of add-ons. */
+ addons_text = g_strdup_printf (ngettext ("%u add-on",
+ "%u add-ons",
+ cnt_addon), cnt_addon);
+ /* TRANSLATORS: This string is used to construct the 'X applications
+ and y add-ons installed' sentence, describing a software source.
+ The correct form here depends on the total number of
+ applications and add-ons. */
+ return g_strdup_printf (ngettext ("%s and %s installed",
+ "%s and %s installed",
+ cnt_apps + cnt_addon),
+ apps_text, addons_text);
+}
+
+static void
+add_source (GtkListBox *listbox, GsApp *app)
+{
+ GtkWidget *row;
+ g_autofree gchar *text = NULL;
+
+ row = gs_sources_dialog_row_new ();
+ gs_sources_dialog_row_set_name (GS_SOURCES_DIALOG_ROW (row),
+ gs_app_get_name (app));
+ text = get_source_installed_text (app);
gs_sources_dialog_row_set_description (GS_SOURCES_DIALOG_ROW (row),
text);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]