[bijiben/wip/sadiq/rewrite: 17/19] Add main-view class
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben/wip/sadiq/rewrite: 17/19] Add main-view class
- Date: Mon, 12 Mar 2018 10:55:18 +0000 (UTC)
commit 4ed148e4857eb5d969db93c6586b80962df23181
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Sat Mar 10 12:42:56 2018 +0530
Add main-view class
src/resources/bijiben.gresource.xml | 1 +
src/resources/ui/bjb-main-view.ui | 28 ++++
src/views/bjb-main-view.c | 300 +++++++++++++++++++++++++++++++++++
src/views/bjb-main-view.h | 46 ++++++
4 files changed, 375 insertions(+), 0 deletions(-)
---
diff --git a/src/resources/bijiben.gresource.xml b/src/resources/bijiben.gresource.xml
index 475904f..c4903d1 100644
--- a/src/resources/bijiben.gresource.xml
+++ b/src/resources/bijiben.gresource.xml
@@ -3,6 +3,7 @@
<gresource prefix="/org/gnome/bijiben">
<file preprocess="xml-stripblanks">gtk/menus.ui</file>
<file preprocess="xml-stripblanks">ui/bjb-window.ui</file>
+ <file preprocess="xml-stripblanks">ui/bjb-main-view.ui</file>
<file>css/style.css</file>
</gresource>
</gresources>
diff --git a/src/resources/ui/bjb-main-view.ui b/src/resources/ui/bjb-main-view.ui
new file mode 100644
index 0000000..9a48433
--- /dev/null
+++ b/src/resources/ui/bjb-main-view.ui
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk 3.14 -->
+ <template class="BjbMainView" parent="GtkStack">
+ <property name="visible">1</property>
+
+ <!-- <child>
+ <object class="BjbListView" id="list_view">
+ <property name="selection-mode" bind-source="BjbMainView" bind-property="selection-mode"/>
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="name">list</property>
+ </packing>
+ </child>
+ -->
+ <child>
+ <object class="BjbGridView" id="grid_view">
+ <!-- <property name="selection-mode" bind-source="BjbMainView" bind-property="selection-mode"/> -->
+ <property name="visible">1</property>
+ </object>
+ <packing>
+ <property name="name">grid</property>
+ </packing>
+ </child>
+
+ </template>
+</interface>
diff --git a/src/views/bjb-main-view.c b/src/views/bjb-main-view.c
new file mode 100644
index 0000000..c528a5c
--- /dev/null
+++ b/src/views/bjb-main-view.c
@@ -0,0 +1,300 @@
+/* bjb-main-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-main-view"
+
+#include "config.h"
+
+#include "bjb-grid-view.h"
+#include "bjb-trace.h"
+
+#include "bjb-main-view.h"
+
+/**
+ * SECTION: bjb-main-view
+ * @title: BjbMainView
+ * @short_description:
+ * @include: "bjb-main-view.h"
+ */
+
+struct _BjbMainView
+{
+ GtkStack parent_instance;
+
+ GListModel *model;
+
+ GtkWidget *grid_view;
+ GtkWidget *list_view;
+
+ BjbViewType current_view;
+ gboolean selection_mode;
+};
+
+G_DEFINE_TYPE (BjbMainView, bjb_main_view, GTK_TYPE_STACK)
+
+enum {
+ PROP_0,
+ PROP_SELECTION_MODE,
+ PROP_MODEL,
+ N_PROPS
+};
+
+enum {
+ ITEM_ACTIVATED,
+ N_SIGNALS
+};
+
+static GParamSpec *properties[N_PROPS];
+static guint signals[N_SIGNALS];
+
+static void
+bjb_main_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BjbMainView *self = (BjbMainView *)object;
+
+ switch (prop_id)
+ {
+ case PROP_SELECTION_MODE:
+ g_value_set_boolean (value, self->selection_mode);
+ break;
+
+ case PROP_MODEL:
+ g_value_set_object (value, self->model);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_main_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbMainView *self = (BjbMainView *)object;
+
+ switch (prop_id)
+ {
+ case PROP_SELECTION_MODE:
+ bjb_main_view_set_selection_mode (self, g_value_get_boolean (value));
+ break;
+
+ case PROP_MODEL:
+ bjb_main_view_set_model (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+bjb_main_view_dispose (GObject *object)
+{
+ BjbMainView *self = (BjbMainView *)object;
+
+ BJB_ENTRY;
+
+
+
+ G_OBJECT_CLASS (bjb_main_view_parent_class)->dispose (object);
+
+ BJB_EXIT;
+}
+
+static void
+bjb_main_view_finalize (GObject *object)
+{
+ BjbMainView *self = (BjbMainView *)object;
+
+ BJB_ENTRY;
+
+
+
+ G_OBJECT_CLASS (bjb_main_view_parent_class)->finalize (object);
+
+ BJB_EXIT;
+}
+
+static void
+bjb_main_view_class_init (BjbMainViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = bjb_main_view_get_property;
+ object_class->set_property = bjb_main_view_set_property;
+ object_class->dispose = bjb_main_view_dispose;
+ object_class->finalize = bjb_main_view_finalize;
+
+ properties[PROP_SELECTION_MODE] =
+ g_param_spec_boolean ("selection-mode",
+ "Selection Mode",
+ "If mode is selection mode or not",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model",
+ "Model",
+ "The GListModel for the view",
+ G_TYPE_LIST_MODEL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/bijiben/"
+ "ui/bjb-main-view.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, BjbMainView, grid_view);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+bjb_main_view_init (BjbMainView *self)
+{
+ BJB_ENTRY;
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ BJB_EXIT;
+}
+
+static void
+bjb_main_view_set_child_selection_mode (BjbMainView *self,
+ GtkSelectionMode selection_mode)
+{
+ gtk_flow_box_set_selection_mode (GTK_FLOW_BOX (self->grid_view),
+ selection_mode);
+ gtk_list_box_set_selection_mode (GTK_LIST_BOX (self->list_view),
+ selection_mode);
+}
+
+static void
+bjb_main_view_set_view_widget (BjbMainView *self,
+ GtkWidget *widget)
+{
+ gtk_stack_set_visible_child (GTK_STACK (self), widget);
+}
+
+BjbMainView *
+bjb_main_view_new (void)
+{
+ return g_object_new (BJB_TYPE_MAIN_VIEW,
+ NULL);
+}
+
+/**
+ * bjb_main_view_get_selection_mode:
+ * @self: A #BjbMainView
+ *
+ * Get if selection mode is active
+ *
+ * Returns: %TRUE if selection mode is active. %FALSE otherwise
+ */
+gboolean
+bjb_main_view_get_selection_mode (BjbMainView *self)
+{
+ g_return_val_if_fail (BJB_IS_MAIN_VIEW (self), FALSE);
+
+ return self->selection_mode;
+}
+
+/**
+ * bjb_main_view_set_selection_mode:
+ * @self: A #BjbMainView
+ * @selection_mode: a gboolean to set mode
+ *
+ * Set selection mode
+ */
+void
+bjb_main_view_set_selection_mode (BjbMainView *self,
+ gboolean selection_mode)
+{
+ BJB_ENTRY;
+
+ g_return_if_fail (BJB_IS_MAIN_VIEW (self));
+
+ if (self->selection_mode == selection_mode)
+ return;
+
+ self->selection_mode = selection_mode;
+
+ if (selection_mode)
+ bjb_main_view_set_child_selection_mode (self, GTK_SELECTION_MULTIPLE);
+ else
+ bjb_main_view_set_child_selection_mode (self, GTK_SELECTION_NONE);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTION_MODE]);
+
+ BJB_EXIT;
+}
+
+/**
+ * bjb_main_view_set_model:
+ * @self: A #BjbMainView
+ * @model: a #GListModel
+ *
+ * The data model to be used for the view
+ */
+void
+bjb_main_view_set_model (BjbMainView *self,
+ GListModel *model)
+{
+ g_return_if_fail (BJB_IS_MAIN_VIEW (self));
+
+ if (g_set_object (&self->model, model))
+ {
+ bjb_grid_view_set_model (BJB_GRID_VIEW (self->grid_view), model);
+ /* bjb_list_view_set_model (self->list_view, model); */
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]);
+ }
+}
+
+/**
+ * bjb_main_view_set_view:
+ * @self: A #BjbMainView
+ * @view_type: a #BjbViewType
+ *
+ * Set Current view type.
+ */
+void
+bjb_main_view_set_view (BjbMainView *self,
+ BjbViewType view_type)
+{
+ GtkStack *stack;
+
+ g_return_if_fail (BJB_IS_MAIN_VIEW (self));
+
+ if (self->current_view == view_type)
+ return;
+
+ self->current_view = view_type;
+
+ if (view_type == BJB_VIEW_TYPE_GRID)
+ bjb_main_view_set_view_widget (self, self->grid_view);
+ else
+ bjb_main_view_set_view_widget (self, self->list_view);
+}
diff --git a/src/views/bjb-main-view.h b/src/views/bjb-main-view.h
new file mode 100644
index 0000000..7b39f82
--- /dev/null
+++ b/src/views/bjb-main-view.h
@@ -0,0 +1,46 @@
+/* bjb-main-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_MAIN_VIEW (bjb_main_view_get_type ())
+
+typedef enum
+{
+ BJB_VIEW_TYPE_GRID,
+ BJB_VIEW_TYPE_LIST
+} BjbViewType;
+
+G_DECLARE_FINAL_TYPE (BjbMainView, bjb_main_view, BJB, MAIN_VIEW, GtkStack)
+
+BjbMainView *bjb_main_view_new (void);
+gboolean bjb_main_view_get_selection_mode (BjbMainView *self);
+void bjb_main_view_set_selection_mode (BjbMainView *self,
+ gboolean selection_mode);
+void bjb_main_view_set_model (BjbMainView *self,
+ GListModel *model);
+void bjb_main_view_set_view (BjbMainView *self,
+ BjbViewType view_type);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]