[gnome-notes] Add BjbNotebookRow



commit d10b3f799de54337d71bc2dd3170967e62d7fb3f
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Mon Jul 26 11:58:00 2021 +0530

    Add BjbNotebookRow

 data/bjb.gresource.xml             |   1 +
 data/resources/bjb-notebook-row.ui |  27 ++++++++
 src/bjb-notebook-row.c             | 123 +++++++++++++++++++++++++++++++++++++
 src/bjb-notebook-row.h             |  44 +++++++++++++
 src/meson.build                    |   1 +
 5 files changed, 196 insertions(+)
---
diff --git a/data/bjb.gresource.xml b/data/bjb.gresource.xml
index da8f9908..99cc9a8d 100644
--- a/data/bjb.gresource.xml
+++ b/data/bjb.gresource.xml
@@ -19,6 +19,7 @@
     <file alias="import-dialog.ui"       preprocess="xml-stripblanks">resources/import-dialog.ui</file>
     <file alias="list-view.ui"           preprocess="xml-stripblanks">resources/list-view.ui</file>
     <file alias="list-view-row.ui"       preprocess="xml-stripblanks">resources/list-view-row.ui</file>
+    <file alias="bjb-notebook-row.ui"    preprocess="xml-stripblanks">resources/bjb-notebook-row.ui</file>
     <file alias="organize-dialog.ui"     preprocess="xml-stripblanks">resources/organize-dialog.ui</file>
     <file alias="settings-dialog.ui"     preprocess="xml-stripblanks">resources/settings-dialog.ui</file>
   </gresource>
diff --git a/data/resources/bjb-notebook-row.ui b/data/resources/bjb-notebook-row.ui
new file mode 100644
index 00000000..4badbf33
--- /dev/null
+++ b/data/resources/bjb-notebook-row.ui
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="BjbNotebookRow" parent="GtkListBoxRow">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">1</property>
+        <property name="margin">12</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="tag_label">
+            <property name="visible">1</property>
+            <property name="halign">start</property>
+            <property name="hexpand">1</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="select_image">
+            <property name="visible">1</property>
+            <property name="halign">end</property>
+            <property name="icon-name">emblem-ok-symbolic</property>
+            <property name="opacity">0.0</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/bjb-notebook-row.c b/src/bjb-notebook-row.c
new file mode 100644
index 00000000..31a630da
--- /dev/null
+++ b/src/bjb-notebook-row.c
@@ -0,0 +1,123 @@
+/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
+/* bjb-notebook-row.c
+ *
+ * Copyright 2021 Mohammed Sadiq <sadiq sadiqpk org>
+ * Copyright 2021 Purism SPC
+ *
+ * bijiben 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.
+ *
+ * bijiben 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/>.
+ *
+ * Author(s):
+ *   Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "bjb-notebook-row"
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdbool.h>
+
+#include "bjb-notebook-row.h"
+#include "bjb-log.h"
+
+struct _BjbNotebookRow
+{
+  GtkListBoxRow   parent_instance;
+
+  BijiItem       *item;
+
+  GtkWidget      *select_image;
+  GtkWidget      *tag_label;
+
+  gboolean        selected;
+};
+
+G_DEFINE_TYPE (BjbNotebookRow, bjb_notebook_row, GTK_TYPE_LIST_BOX_ROW)
+
+
+static void
+bjb_notebook_row_finalize (GObject *object)
+{
+  BjbNotebookRow *self = (BjbNotebookRow *)object;
+
+  g_clear_object (&self->item);
+
+  G_OBJECT_CLASS (bjb_notebook_row_parent_class)->finalize (object);
+}
+
+static void
+bjb_notebook_row_class_init (BjbNotebookRowClass *klass)
+{
+  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = bjb_notebook_row_finalize;
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/Notes/"
+                                               "ui/bjb-notebook-row.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, BjbNotebookRow, select_image);
+  gtk_widget_class_bind_template_child (widget_class, BjbNotebookRow, tag_label);
+}
+
+static void
+bjb_notebook_row_init (BjbNotebookRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+bjb_notebook_row_new (BijiItem *notebook)
+{
+  BjbNotebookRow *self;
+
+  g_return_val_if_fail (BIJI_IS_NOTEBOOK (notebook), NULL);
+
+  self = g_object_new (BJB_TYPE_NOTEBOOK_ROW, NULL);
+  self->item = g_object_ref (notebook);
+
+  gtk_label_set_text (GTK_LABEL (self->tag_label),
+                      biji_item_get_title (notebook));
+
+  return GTK_WIDGET (self);
+}
+
+BijiItem *
+bjb_notebook_row_get_item (BjbNotebookRow *self)
+{
+  g_return_val_if_fail (BJB_IS_NOTEBOOK_ROW (self), NULL);
+
+  return self->item;
+}
+
+gboolean
+bjb_notebook_row_get_active (BjbNotebookRow *self)
+{
+  g_return_val_if_fail (BJB_IS_NOTEBOOK_ROW (self), false);
+
+  return gtk_widget_get_opacity (self->select_image) == 1.0;
+}
+
+void
+bjb_notebook_row_set_active (BjbNotebookRow *self,
+                             gboolean        is_active)
+{
+  g_return_if_fail (BJB_IS_NOTEBOOK_ROW (self));
+
+  gtk_widget_set_opacity (self->select_image, is_active ? 1.0 : 0.0);
+}
diff --git a/src/bjb-notebook-row.h b/src/bjb-notebook-row.h
new file mode 100644
index 00000000..553493f6
--- /dev/null
+++ b/src/bjb-notebook-row.h
@@ -0,0 +1,44 @@
+/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
+/* bjb-notebook-row.c
+ *
+ * Copyright 2021 Mohammed Sadiq <sadiq sadiqpk org>
+ * Copyright 2021 Purism SPC
+ *
+ * bijiben 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.
+ *
+ * bijiben 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/>.
+ *
+ * Author(s):
+ *   Mohammed Sadiq <sadiq sadiqpk org>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#include "libbiji.h"
+
+G_BEGIN_DECLS
+
+#define BJB_TYPE_NOTEBOOK_ROW (bjb_notebook_row_get_type ())
+
+G_DECLARE_FINAL_TYPE (BjbNotebookRow, bjb_notebook_row, BJB, NOTEBOOK_ROW, GtkListBoxRow)
+
+GtkWidget    *bjb_notebook_row_new        (BijiItem       *notebook);
+BijiItem     *bjb_notebook_row_get_item   (BjbNotebookRow *self);
+gboolean      bjb_notebook_row_get_active (BjbNotebookRow *self);
+void          bjb_notebook_row_set_active (BjbNotebookRow *self,
+                                           gboolean        is_active);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index c8694296..b5233dcf 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -19,6 +19,7 @@ sources = files(
   'bjb-main.c',
   'bjb-note-view.c',
   'bjb-organize-dialog.c',
+  'bjb-notebook-row.c',
   'bjb-search-toolbar.c',
   'bjb-settings.c',
   'bjb-settings-dialog.c',


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