[gnome-calendar] calendar-management-page: Introduce new interface



commit 831bbbdba8da23675ecf0b7d6d377265e37243dc
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Jun 1 21:04:38 2019 -0300

    calendar-management-page: Introduce new interface
    
    This will be used by the pages of the calendar management dialog
    to let it know they are actual pages, to offer an activation
    mechanism, and to communicate with the dialog when they want to
    switch to another page.

 .../gcal-calendar-management-page.c                | 108 +++++++++++++++++++++
 .../gcal-calendar-management-page.h                |  62 ++++++++++++
 src/meson.build                                    |   1 +
 3 files changed, 171 insertions(+)
---
diff --git a/src/gui/calendar-management/gcal-calendar-management-page.c 
b/src/gui/calendar-management/gcal-calendar-management-page.c
new file mode 100644
index 00000000..344d014c
--- /dev/null
+++ b/src/gui/calendar-management/gcal-calendar-management-page.c
@@ -0,0 +1,108 @@
+/* gcal-calendar-management-page.c
+ *
+ * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 "GcalCalendarManagementPage"
+
+#include "gcal-calendar-management-page.h"
+#include "gcal-context.h"
+
+G_DEFINE_INTERFACE (GcalCalendarManagementPage, gcal_calendar_management_page, G_TYPE_OBJECT)
+
+enum
+{
+  SWITCH_PAGE,
+  N_SIGNALS,
+};
+
+static guint signals[N_SIGNALS] = { 0, };
+
+static void
+gcal_calendar_management_page_default_init (GcalCalendarManagementPageInterface *iface)
+{
+  g_object_interface_install_property (iface,
+                                       g_param_spec_object ("context",
+                                                            "Context",
+                                                            "Context",
+                                                            GCAL_TYPE_CONTEXT,
+                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+  signals[SWITCH_PAGE] = g_signal_new ("switch-page",
+                                       GCAL_TYPE_CALENDAR_MANAGEMENT_PAGE,
+                                       G_SIGNAL_RUN_LAST,
+                                       G_STRUCT_OFFSET (GcalCalendarManagementPageInterface, switch_page),
+                                       NULL, NULL, NULL,
+                                       G_TYPE_NONE,
+                                       2,
+                                       G_TYPE_STRING,
+                                       G_TYPE_POINTER);
+}
+
+const gchar*
+gcal_calendar_management_page_get_name (GcalCalendarManagementPage *self)
+{
+  g_return_val_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_PAGE (self), NULL);
+  g_return_val_if_fail (GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->get_name, NULL);
+
+  return GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->get_name (self);
+}
+
+const gchar*
+gcal_calendar_management_page_get_title (GcalCalendarManagementPage *self)
+{
+  g_return_val_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_PAGE (self), NULL);
+  g_return_val_if_fail (GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->get_title, NULL);
+
+  return GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->get_title (self);
+}
+
+void
+gcal_calendar_management_page_activate (GcalCalendarManagementPage *self,
+                                        gpointer                    page_data)
+{
+  g_return_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_PAGE (self));
+
+  if (GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->activate)
+    {
+      g_debug ("Activating %s", G_OBJECT_TYPE_NAME (self));
+      GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->activate (self, page_data);
+    }
+}
+
+void
+gcal_calendar_management_page_deactivate (GcalCalendarManagementPage *self)
+{
+  g_return_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_PAGE (self));
+
+  if (GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->deactivate)
+    {
+      g_debug ("Deactivating %s", G_OBJECT_TYPE_NAME (self));
+      GCAL_CALENDAR_MANAGEMENT_PAGE_GET_IFACE (self)->deactivate (self);
+    }
+}
+
+void
+gcal_calendar_management_page_switch_page (GcalCalendarManagementPage *self,
+                                           const gchar                *page_name,
+                                           gpointer                    page_data)
+{
+  g_return_if_fail (GCAL_IS_CALENDAR_MANAGEMENT_PAGE (self));
+
+  g_signal_emit (self, signals[SWITCH_PAGE], 0, page_name, page_data);
+}
diff --git a/src/gui/calendar-management/gcal-calendar-management-page.h 
b/src/gui/calendar-management/gcal-calendar-management-page.h
new file mode 100644
index 00000000..de2edeec
--- /dev/null
+++ b/src/gui/calendar-management/gcal-calendar-management-page.h
@@ -0,0 +1,62 @@
+/* gcal-calendar-management-page.h
+ *
+ * Copyright 2019 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * 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 GCAL_TYPE_CALENDAR_MANAGEMENT_PAGE (gcal_calendar_management_page_get_type ())
+
+G_DECLARE_INTERFACE (GcalCalendarManagementPage, gcal_calendar_management_page, GCAL, 
CALENDAR_MANAGEMENT_PAGE, GtkWidget)
+
+struct _GcalCalendarManagementPageInterface
+{
+  GTypeInterface parent;
+
+  const gchar*       (*get_name)                                 (GcalCalendarManagementPage *self);
+
+  const gchar*       (*get_title)                                (GcalCalendarManagementPage *self);
+
+  void               (*activate)                                 (GcalCalendarManagementPage *self,
+                                                                  gpointer                    page_data);
+
+  void               (*deactivate)                               (GcalCalendarManagementPage *self);
+
+  void               (*switch_page)                              (GcalCalendarManagementPage *self,
+                                                                  const gchar                *page_name,
+                                                                  gpointer                    page_data);
+};
+
+const gchar*         gcal_calendar_management_page_get_name      (GcalCalendarManagementPage *self);
+
+const gchar*         gcal_calendar_management_page_get_title     (GcalCalendarManagementPage *self);
+
+void                 gcal_calendar_management_page_activate      (GcalCalendarManagementPage *self,
+                                                                  gpointer                    page_data);
+
+void                 gcal_calendar_management_page_deactivate    (GcalCalendarManagementPage *self);
+
+void                 gcal_calendar_management_page_switch_page   (GcalCalendarManagementPage *self,
+                                                                  const gchar                *page_name,
+                                                                  gpointer                    page_data);
+
+G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 5333bcbc..44211790 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -103,6 +103,7 @@ sources = files(
   'core/gcal-timer.c',
   'core/gcal-time-zone-monitor.c',
   'gui/calendar-management/gcal-calendar-management-dialog.c',
+  'gui/calendar-management/gcal-calendar-management-page.c',
   'gui/gcal-application.c',
   'gui/gcal-calendar-popover.c',
   'gui/gcal-date-chooser.c',


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