summaryrefslogtreecommitdiff
path: root/src/plugins/task-lists-workspace/gtd-sidebar-panel-row.c
blob: a379f24da679fe3b4ca2a618671072e4888b348b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* gtd-sidebar-panel-row.c
 *
 * Copyright 2018-2020 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
 */

#include "gtd-panel.h"
#include "gtd-sidebar-panel-row.h"

struct _GtdSidebarPanelRow
{
  GtkListBoxRow       parent;

  GtkWidget          *panel_icon;
  GtkWidget          *subtitle_label;
  GtkWidget          *title_label;

  GtdPanel           *panel;
};

G_DEFINE_TYPE (GtdSidebarPanelRow, gtd_sidebar_panel_row, GTK_TYPE_LIST_BOX_ROW)

enum
{
  PROP_0,
  PROP_PANEL,
  N_PROPS
};

static GParamSpec *properties [N_PROPS];


/*
 * Auxiliary methods
 */

static void
set_panel (GtdSidebarPanelRow *self,
           GtdPanel           *panel)
{
  g_assert (panel != NULL);
  g_assert (self->panel == NULL);

  self->panel = g_object_ref (panel);

  /* Bind panel properties to the row widgets */
  g_object_bind_property (self->panel,
                          "icon",
                          self->panel_icon,
                          "gicon",
                          G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

  g_object_bind_property (self->panel,
                          "title",
                          self->title_label,
                          "label",
                          G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

  g_object_bind_property (self->panel,
                          "subtitle",
                          self->subtitle_label,
                          "label",
                          G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);

  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PANEL]);
}


/*
 * GObject overrides
 */

static void
gtd_sidebar_panel_row_finalize (GObject *object)
{
  GtdSidebarPanelRow *self = (GtdSidebarPanelRow *)object;

  g_clear_object (&self->panel);

  G_OBJECT_CLASS (gtd_sidebar_panel_row_parent_class)->finalize (object);
}

static void
gtd_sidebar_panel_row_get_property (GObject    *object,
                                    guint       prop_id,
                                    GValue     *value,
                                    GParamSpec *pspec)
{
  GtdSidebarPanelRow *self = GTD_SIDEBAR_PANEL_ROW (object);

  switch (prop_id)
    {
    case PROP_PANEL:
      g_value_set_object (value, self->panel);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
gtd_sidebar_panel_row_set_property (GObject      *object,
                                    guint         prop_id,
                                    const GValue *value,
                                    GParamSpec   *pspec)
{
  GtdSidebarPanelRow *self = GTD_SIDEBAR_PANEL_ROW (object);

  switch (prop_id)
    {
    case PROP_PANEL:
      set_panel (self, g_value_get_object (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
gtd_sidebar_panel_row_class_init (GtdSidebarPanelRowClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  object_class->finalize = gtd_sidebar_panel_row_finalize;
  object_class->get_property = gtd_sidebar_panel_row_get_property;
  object_class->set_property = gtd_sidebar_panel_row_set_property;

  properties[PROP_PANEL] = g_param_spec_object ("panel",
                                                "Panel",
                                                "The panel this row represents",
                                                GTD_TYPE_PANEL,
                                                G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);

  g_object_class_install_properties (object_class, N_PROPS, properties);

  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/todo/plugins/task-lists-workspace/gtd-sidebar-panel-row.ui");

  gtk_widget_class_bind_template_child (widget_class, GtdSidebarPanelRow, panel_icon);
  gtk_widget_class_bind_template_child (widget_class, GtdSidebarPanelRow, subtitle_label);
  gtk_widget_class_bind_template_child (widget_class, GtdSidebarPanelRow, title_label);
}

static void
gtd_sidebar_panel_row_init (GtdSidebarPanelRow *self)
{
  gtk_widget_init_template (GTK_WIDGET (self));
}

GtkWidget*
gtd_sidebar_panel_row_new (GtdPanel *panel)
{
  return g_object_new (GTD_TYPE_SIDEBAR_PANEL_ROW,
                       "panel", panel,
                       NULL);
}

GtdPanel*
gtd_sidebar_panel_row_get_panel (GtdSidebarPanelRow *self)
{
  g_return_val_if_fail (GTD_IS_SIDEBAR_PANEL_ROW (self), NULL);

  return self->panel;
}