[gnome-software] sources dialog: Break out the row widget in a separate class



commit 9850182a1f1269f913cccfc27b085f44983c32ee
Author: Kalev Lember <klember redhat com>
Date:   Mon Aug 31 14:40:21 2015 +0200

    sources dialog: Break out the row widget in a separate class
    
    The new class makes use of G_DECLARE_FINAL_TYPE, so this bumps glib
    dependency to 2.44.0 as well.

 configure.ac                     |    2 +-
 src/Makefile.am                  |    3 ++
 src/gnome-software.gresource.xml |    1 +
 src/gs-sources-dialog-row.c      |   73 ++++++++++++++++++++++++++++++++++++++
 src/gs-sources-dialog-row.h      |   43 ++++++++++++++++++++++
 src/gs-sources-dialog-row.ui     |   39 ++++++++++++++++++++
 src/gs-sources-dialog.c          |   39 +++++++-------------
 7 files changed, 174 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 79d6e50..76e5b3e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,7 +52,7 @@ GETTEXT_PACKAGE=AC_PACKAGE_NAME
 AC_SUBST(GETTEXT_PACKAGE)
 AC_DEFINE(GETTEXT_PACKAGE, "AC_PACKAGE_NAME", [gnome-software])
 
-AM_PATH_GLIB_2_0(2.39.1, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
+AM_PATH_GLIB_2_0(2.44.0, :, AC_MSG_ERROR([GLib is required]), gobject gmodule gio)
 AM_GLIB_GNU_GETTEXT
 GLIB_GSETTINGS
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 330cf73..98bdb3d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,6 +45,7 @@ UI_FILES =                                            \
        gs-shell-search.ui                              \
        gs-shell-updates.ui                             \
        gs-sources-dialog.ui                            \
+       gs-sources-dialog-row.ui                        \
        gs-star-widget.ui                               \
        gs-update-dialog.ui                             \
        screenshot-image.ui                             \
@@ -165,6 +166,8 @@ gnome_software_SOURCES =                            \
        gs-shell-search.h                               \
        gs-sources-dialog.c                             \
        gs-sources-dialog.h                             \
+       gs-sources-dialog-row.c                         \
+       gs-sources-dialog-row.h                         \
        gs-update-dialog.c                              \
        gs-update-dialog.h                              \
        gs-update-list.c                                \
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 697abf5..dbeb2af 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -21,6 +21,7 @@
   <file preprocess="xml-stripblanks">gs-shell-search.ui</file>
   <file preprocess="xml-stripblanks">gs-shell-updates.ui</file>
   <file preprocess="xml-stripblanks">gs-sources-dialog.ui</file>
+  <file preprocess="xml-stripblanks">gs-sources-dialog-row.ui</file>
   <file preprocess="xml-stripblanks">gs-star-widget.ui</file>
   <file preprocess="xml-stripblanks">gs-update-dialog.ui</file>
   <file preprocess="xml-stripblanks">org.freedesktop.PackageKit.xml</file>
diff --git a/src/gs-sources-dialog-row.c b/src/gs-sources-dialog-row.c
new file mode 100644
index 0000000..29b88d4
--- /dev/null
+++ b/src/gs-sources-dialog-row.c
@@ -0,0 +1,73 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Kalev Lember <klember redhat com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include "gs-sources-dialog-row.h"
+
+struct _GsSourcesDialogRow
+{
+       GtkListBoxRow    parent_instance;
+
+       GtkWidget       *name_label;
+       GtkWidget       *description_label;
+};
+
+G_DEFINE_TYPE (GsSourcesDialogRow, gs_sources_dialog_row, GTK_TYPE_LIST_BOX_ROW)
+
+void
+gs_sources_dialog_row_set_name (GsSourcesDialogRow *row,
+                                const gchar        *name)
+{
+       gtk_label_set_text (GTK_LABEL (row->name_label), name);
+}
+
+void
+gs_sources_dialog_row_set_description (GsSourcesDialogRow *row,
+                                       const gchar        *description)
+{
+       gtk_label_set_text (GTK_LABEL (row->description_label), description);
+}
+
+static void
+gs_sources_dialog_row_init (GsSourcesDialogRow *row)
+{
+       gtk_widget_init_template (GTK_WIDGET (row));
+}
+
+static void
+gs_sources_dialog_row_class_init (GsSourcesDialogRowClass *klass)
+{
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-sources-dialog-row.ui");
+
+       gtk_widget_class_bind_template_child (widget_class, GsSourcesDialogRow, name_label);
+       gtk_widget_class_bind_template_child (widget_class, GsSourcesDialogRow, description_label);
+}
+
+GtkWidget *
+gs_sources_dialog_row_new (void)
+{
+       return g_object_new (GS_TYPE_SOURCES_DIALOG_ROW, NULL);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-sources-dialog-row.h b/src/gs-sources-dialog-row.h
new file mode 100644
index 0000000..0d0f00c
--- /dev/null
+++ b/src/gs-sources-dialog-row.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2015 Kalev Lember <klember redhat com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GS_SOURCES_DIALOG_ROW_H
+#define GS_SOURCES_DIALOG_ROW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_SOURCES_DIALOG_ROW (gs_sources_dialog_row_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsSourcesDialogRow, gs_sources_dialog_row, GS, SOURCES_DIALOG_ROW, GtkListBoxRow)
+
+GtkWidget      *gs_sources_dialog_row_new              (void);
+void            gs_sources_dialog_row_set_name         (GsSourcesDialogRow     *row,
+                                                        const gchar            *name);
+void            gs_sources_dialog_row_set_description  (GsSourcesDialogRow     *row,
+                                                        const gchar            *description);
+
+G_END_DECLS
+
+#endif /* GS_SOURCES_DIALOG_ROW_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-sources-dialog-row.ui b/src/gs-sources-dialog-row.ui
new file mode 100644
index 0000000..e904989
--- /dev/null
+++ b/src/gs-sources-dialog-row.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GsSourcesDialogRow" parent="GtkListBoxRow">
+    <child>
+      <object class="GtkBox" id="vbox">
+        <property name="visible">True</property>
+        <property name="margin-top">12</property>
+        <property name="margin-bottom">12</property>
+        <property name="margin-start">12</property>
+        <property name="margin-end">12</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="name_label">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="description_label">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index 1585c24..4fa8ade 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -27,6 +27,7 @@
 
 #include "gs-cleanup.h"
 #include "gs-sources-dialog.h"
+#include "gs-sources-dialog-row.h"
 #include "gs-utils.h"
 
 struct _GsSourcesDialogPrivate
@@ -51,9 +52,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GsSourcesDialog, gs_sources_dialog, GTK_TYPE_DIALOG)
 static void
 add_source (GtkListBox *listbox, GsApp *app)
 {
-       GtkWidget *widget;
-       GtkWidget *box;
-       GtkStyleContext *context;
+       GtkWidget *row;
        GPtrArray *related;
        guint cnt_addon = 0;
        guint cnt_apps = 0;
@@ -62,15 +61,10 @@ add_source (GtkListBox *listbox, GsApp *app)
        _cleanup_free_ gchar *apps_text = NULL;
        _cleanup_free_ gchar *text = NULL;
 
-       box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-       gtk_widget_set_margin_top (box, 12);
-       gtk_widget_set_margin_start (box, 12);
-       gtk_widget_set_margin_bottom (box, 12);
-       gtk_widget_set_margin_end (box, 12);
+       row = gs_sources_dialog_row_new ();
+       gs_sources_dialog_row_set_name (GS_SOURCES_DIALOG_ROW (row),
+                                       gs_app_get_name (app));
 
-       widget = gtk_label_new (gs_app_get_name (app));
-       gtk_widget_set_halign (widget, GTK_ALIGN_START);
-       gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
        related = gs_app_get_related (app);
 
        /* split up the types */
@@ -130,23 +124,20 @@ add_source (GtkListBox *listbox, GsApp *app)
                                                  cnt_apps + cnt_addon),
                                                  apps_text, addons_text);
        }
-       widget = gtk_label_new (text);
-       gtk_widget_set_halign (widget, GTK_ALIGN_START);
-       gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 0);
+       gs_sources_dialog_row_set_description (GS_SOURCES_DIALOG_ROW (row),
+                                              text);
 
-       context = gtk_widget_get_style_context (widget);
-       gtk_style_context_add_class (context, "dim-label");
-       g_object_set_data_full (G_OBJECT (box), "GsShell::app",
+       g_object_set_data_full (G_OBJECT (row), "GsShell::app",
                                g_object_ref (app),
                                (GDestroyNotify) g_object_unref);
 
-       g_object_set_data_full (G_OBJECT (box),
+       g_object_set_data_full (G_OBJECT (row),
                                "sort",
                                g_utf8_casefold (gs_app_get_name (app), -1),
                                g_free);
 
-       gtk_list_box_prepend (listbox, box);
-       gtk_widget_show_all (box);
+       gtk_list_box_prepend (listbox, row);
+       gtk_widget_show (row);
 }
 
 static void
@@ -232,10 +223,8 @@ list_sort_func (GtkListBoxRow *a,
                GtkListBoxRow *b,
                gpointer user_data)
 {
-       GObject *o1 = G_OBJECT (gtk_bin_get_child (GTK_BIN (a)));
-       GObject *o2 = G_OBJECT (gtk_bin_get_child (GTK_BIN (b)));
-       const gchar *key1 = g_object_get_data (o1, "sort");
-       const gchar *key2 = g_object_get_data (o2, "sort");
+       const gchar *key1 = g_object_get_data (G_OBJECT (a), "sort");
+       const gchar *key2 = g_object_get_data (G_OBJECT (b), "sort");
        return g_strcmp0 (key1, key2);
 }
 
@@ -285,7 +274,7 @@ list_row_activated_cb (GtkListBox *list_box,
        gtk_widget_show (priv->button_back);
 
        gs_container_remove_all (GTK_CONTAINER (priv->listbox_apps));
-       app = GS_APP (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), 
+       app = GS_APP (g_object_get_data (G_OBJECT (row),
                                         "GsShell::app"));
        related = gs_app_get_related (app);
        for (i = 0; i < related->len; i++) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]