[bijiben/wip/sadiq/rewrite: 6/7] Add grid view class
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben/wip/sadiq/rewrite: 6/7] Add grid view class
- Date: Tue, 13 Mar 2018 13:19:04 +0000 (UTC)
commit 8b90c6a51416910fb353bde51c37783971fbc79e
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Sat Mar 10 16:59:12 2018 +0530
Add grid view class
src/views/bjb-grid-view.c | 177 +++++++++++++++++++++++++++++++++++++++++++++
src/views/bjb-grid-view.h | 34 +++++++++
2 files changed, 211 insertions(+), 0 deletions(-)
---
diff --git a/src/views/bjb-grid-view.c b/src/views/bjb-grid-view.c
new file mode 100644
index 0000000..de452c5
--- /dev/null
+++ b/src/views/bjb-grid-view.c
@@ -0,0 +1,177 @@
+/* bjb-grid-view.c
+ *
+ * Copyright 2018 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "bjb-grid-view"
+
+#include "config.h"
+
+#include "bjb-item.h"
+#include "bjb-grid-view-item.h"
+#include "bjb-trace.h"
+
+#include "bjb-grid-view.h"
+
+/**
+ * SECTION: bjb-grid-view
+ * @title: BjbGridView
+ * @short_description: Container whose child are shown as Grid
+ * @include: "bjb-grid-view.h"
+ */
+
+/*
+ * TODO: Create bjb-view interface common to list-view too
+ * Do we actually need this?
+ */
+struct _BjbGridView
+{
+ GtkFlowBox parent_instance;
+};
+
+G_DEFINE_TYPE (BjbGridView, bjb_grid_view, GTK_TYPE_FLOW_BOX)
+
+enum {
+ PROP_0,
+
+ N_PROPS
+};
+
+enum {
+
+ N_SIGNALS
+};
+
+static GParamSpec *properties[N_PROPS];
+static guint signals[N_SIGNALS];
+
+static void
+bjb_grid_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BjbGridView *self = (BjbGridView *)object;
+
+ switch (prop_id)
+ {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_grid_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbGridView *self = (BjbGridView *)object;
+
+ switch (prop_id)
+ {
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_grid_view_dispose (GObject *object)
+{
+ BjbGridView *self = (BjbGridView *)object;
+
+ BJB_ENTRY;
+
+
+
+ G_OBJECT_CLASS (bjb_grid_view_parent_class)->dispose (object);
+
+ BJB_EXIT;
+}
+
+static void
+bjb_grid_view_finalize (GObject *object)
+{
+ BjbGridView *self = (BjbGridView *)object;
+
+ BJB_ENTRY;
+
+
+
+ G_OBJECT_CLASS (bjb_grid_view_parent_class)->finalize (object);
+
+ BJB_EXIT;
+}
+
+static void
+bjb_grid_view_class_init (BjbGridViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = bjb_grid_view_get_property;
+ object_class->set_property = bjb_grid_view_set_property;
+ object_class->dispose = bjb_grid_view_dispose;
+ object_class->finalize = bjb_grid_view_finalize;
+
+ /* g_object_class_install_properties (object_class, N_PROPS, properties); */
+}
+
+static void
+bjb_grid_view_init (BjbGridView *self)
+{
+ BJB_ENTRY;
+
+
+
+ BJB_EXIT;
+}
+
+static GtkWidget *
+bjb_grid_view_create_item (gpointer data,
+ gpointer user_data)
+{
+ BjbItem *item = data;
+
+ return bjb_grid_view_item_new (bjb_item_get_thumbnail (item, 1, TRUE),
+ bjb_item_get_title (item));
+}
+
+BjbGridView *
+bjb_grid_view_new (void)
+{
+ return g_object_new (BJB_TYPE_GRID_VIEW,
+ "row-spacing", 9,
+ "column-spacing", 9,
+ "margin", 6,
+ NULL);
+}
+
+void
+bjb_grid_view_set_model (BjbGridView *self,
+ GListModel *model)
+{
+ g_return_if_fail (BJB_IS_GRID_VIEW (self));
+ g_return_if_fail (G_IS_LIST_MODEL (model));
+
+ gtk_flow_box_bind_model (GTK_FLOW_BOX (self),
+ model,
+ bjb_grid_view_create_item,
+ NULL, NULL);
+}
diff --git a/src/views/bjb-grid-view.h b/src/views/bjb-grid-view.h
new file mode 100644
index 0000000..87f0535
--- /dev/null
+++ b/src/views/bjb-grid-view.h
@@ -0,0 +1,34 @@
+/* bjb-grid-view.h
+ *
+ * Copyright 2018 Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BJB_TYPE_GRID_VIEW (bjb_grid_view_get_type ())
+
+G_DECLARE_FINAL_TYPE (BjbGridView, bjb_grid_view, BJB, GRID_VIEW, GtkFlowBox)
+
+BjbGridView *bjb_grid_view_new (void);
+void bjb_grid_view_set_model (BjbGridView *self,
+ GListModel *model);
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]