[bijiben/wip/sadiq/rewrite: 1/6] Add window class



commit aae386e762373af53ee13b86948ad43f0c978f93
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Tue Feb 27 07:51:23 2018 +0530

    Add window class

 src/bjb-window.c |  202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/bjb-window.h |   34 +++++++++
 2 files changed, 236 insertions(+), 0 deletions(-)
---
diff --git a/src/bjb-window.c b/src/bjb-window.c
new file mode 100644
index 0000000..e5b43ba
--- /dev/null
+++ b/src/bjb-window.c
@@ -0,0 +1,202 @@
+/* bjb-window.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-window"
+
+#include "bjb-app.h"
+/* #include <libgd/gd.h> */
+#include "bjb-provider.h"
+#include "bjb-item.h"
+#include "bjb-note.h"
+#include "views/bjb-main-view.h"
+#include "bjb-trace.h"
+
+#include "bjb-window.h"
+
+
+struct _BjbWindow
+{
+  GtkApplicationWindow parent_instance;
+
+  GtkWidget *main_view;
+  GtkWidget *note_view;
+
+  GtkListStore *list_store;
+
+  GtkWidget *menu_button;
+
+  gint       width;
+  gint       height;
+  gint       pos_x;
+  gint       pos_y;
+  gboolean   is_maximized;
+};
+
+G_DEFINE_TYPE (BjbWindow, bjb_window, GTK_TYPE_APPLICATION_WINDOW)
+
+
+static void
+bjb_window_load_geometry (BjbWindow *self)
+{
+  GSettings *settings = bjb_application_get_default_settings ();
+
+  BJB_ENTRY;
+
+  g_assert (BJB_IS_WINDOW (self));
+
+  self->is_maximized = g_settings_get_boolean (settings, "window-maximized");
+  g_settings_get (settings, "window-size", "(ii)", &self->width, &self->height);
+  g_settings_get (settings, "window-position", "(ii)", &self->pos_x, &self->pos_y);
+
+  BJB_EXIT;
+}
+
+static void
+bjb_window_save_geometry (BjbWindow *self)
+{
+  GSettings *settings = bjb_application_get_default_settings ();
+
+  BJB_ENTRY;
+
+  g_assert (BJB_IS_WINDOW (self));
+
+  g_settings_set_boolean (settings, "window-maximized", self->is_maximized);
+  g_settings_set (settings, "window-size", "(ii)", self->width, self->height);
+  g_settings_set (settings, "window-position", "(ii)", self->pos_x, self->pos_y);
+
+  BJB_EXIT;
+}
+
+static gboolean
+bjb_window_configure_event (BjbWindow *self)
+{
+  g_assert (BJB_IS_WINDOW (self));
+
+  self->is_maximized = gtk_window_is_maximized (GTK_WINDOW (self));
+  if (!self->is_maximized)
+    {
+      gtk_window_get_size (GTK_WINDOW (self), &self->width, &self->height);
+      gtk_window_get_position (GTK_WINDOW (self), &self->pos_x, &self->pos_y);
+    }
+
+  return FALSE;
+}
+
+static void
+bjb_window_destroy (BjbWindow *self)
+{
+  g_assert (BJB_IS_WINDOW (self));
+
+  bjb_window_save_geometry (self);
+}
+
+static void
+bjb_window_provider_added_cb (BjbWindow      *self,
+                              BjbProvider    *provider,
+                              BjbApplication *application)
+{
+  GList *items;
+  GtkTreeIter iter;
+  gint scale;
+
+  g_assert (BJB_IS_WINDOW (self));
+  g_assert (BJB_IS_PROVIDER (provider));
+  g_assert (BJB_IS_APPLICATION (application));
+
+  scale = gtk_widget_get_scale_factor (GTK_WIDGET (self));
+
+  items = bjb_provider_get_notes (provider);
+
+  /* for (GList *item = items; item != NULL; item = item->next) */
+  /*   { */
+  /*     gtk_list_store_append (self->list_store, &iter); */
+  /*     /\* gtk_list_store_set (self->list_store, &iter, *\/ */
+  /*     /\*                     GD_MAIN_COLUMN_ID, bjb_item_get_uid (item->data), *\/ */
+  /*     /\*                     /\\* GD_MAIN_COLUMN_URI, uuid, *\\/ *\/ */
+  /*     /\*                     GD_MAIN_COLUMN_PRIMARY_TEXT, bjb_item_get_title (item->data), *\/ */
+  /*     /\*                     GD_MAIN_COLUMN_ICON, bjb_item_get_thumbnail (item->data, scale, TRUE), *\/ 
*/
+  /*     /\*                     /\\* GD_MAIN_COLUMN_SECONDARY_TEXT, NULL, *\\/ *\/ */
+  /*     /\*                     -1); *\/ */
+
+  /*   } */
+}
+
+static void
+bjb_window_constructed (GObject *object)
+{
+  BjbWindow *self = BJB_WINDOW (object);
+  GtkWindow *window = GTK_WINDOW (self);
+
+  bjb_window_load_geometry (self);
+  gtk_window_set_default_size (window, self->width, self->height);
+
+  if (self->is_maximized)
+    gtk_window_maximize (window);
+  else if (self->pos_x >= 0)
+    gtk_window_move (window, self->pos_x, self->pos_y);
+
+  G_OBJECT_CLASS (bjb_window_parent_class)->constructed (object);
+}
+
+static void
+bjb_window_class_init (BjbWindowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->constructed = bjb_window_constructed;
+
+  g_type_ensure (BJB_TYPE_MAIN_VIEW);
+
+  gtk_widget_class_set_template_from_resource (widget_class,
+                                               "/org/gnome/bijiben/"
+                                               "ui/bjb-window.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, BjbWindow, menu_button);
+  gtk_widget_class_bind_template_child (widget_class, BjbWindow, main_view);
+  gtk_widget_class_bind_template_child (widget_class, BjbWindow, list_store);
+
+  gtk_widget_class_bind_template_callback (widget_class, bjb_window_destroy);
+  gtk_widget_class_bind_template_callback (widget_class, bjb_window_configure_event);
+}
+
+static void
+bjb_window_init (BjbWindow *self)
+{
+  BjbApplication *application = BJB_APPLICATION (g_application_get_default ());
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+
+  g_signal_connect_object (application,
+                           "provider-added",
+                           G_CALLBACK (bjb_window_provider_added_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+BjbWindow *
+bjb_window_new (BjbApplication *application)
+{
+  g_assert (GTK_IS_APPLICATION (application));
+
+  return g_object_new (BJB_TYPE_WINDOW,
+                       "application", application,
+                       NULL);
+}
diff --git a/src/bjb-window.h b/src/bjb-window.h
new file mode 100644
index 0000000..2d73ea2
--- /dev/null
+++ b/src/bjb-window.h
@@ -0,0 +1,34 @@
+/* bjb-window.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>
+#include "bjb-app.h"
+
+G_BEGIN_DECLS
+
+#define BJB_TYPE_WINDOW (bjb_window_get_type ())
+
+G_DECLARE_FINAL_TYPE (BjbWindow, bjb_window, BJB, WINDOW, GtkApplicationWindow)
+
+BjbWindow *bjb_window_new (BjbApplication *application);
+
+G_END_DECLS


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