~tristan957/harvest-almanac

ref: 0f0fa7109d3fb40354c03f4ba0fcda63df8280e4 harvest-almanac/harvest-almanac/hal-time-tracker.c -rw-r--r-- 6.8 KiB
0f0fa710Tristan Partin harvest-glib: fix implicit fallthrough 1 year, 8 months ago
                                                                                
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "config.h"

#include <glib-object.h>
#include <gtk/gtk.h>

#include "hal-time-entry.h"
#include "hal-time-tracker.h"

struct _HalTimeTracker
{
	GtkBox parent_instance;
};

typedef struct HalTimeTrackerPrivate
{
	GtkButton *monday_button;
	GtkButton *tuesday_button;
	GtkButton *wednesday_button;
	GtkButton *thursday_button;
	GtkButton *friday_button;
	GtkButton *saturday_button;
	GtkButton *sunday_button;
	GtkLabel *monday_time;
	GtkLabel *tuesday_time;
	GtkLabel *wednesday_time;
	GtkLabel *thursday_time;
	GtkLabel *friday_time;
	GtkLabel *saturday_time;
	GtkLabel *sunday_time;
	GtkListBox *monday_time_entries;
	GtkListBox *tuesday_time_entries;
	GtkListBox *wednesday_time_entries;
	GtkListBox *thursday_time_entries;
	GtkListBox *friday_time_entries;
	GtkListBox *saturday_time_entries;
	GtkListBox *sunday_time_entries;
} HalTimeTrackerPrivate;

G_DEFINE_TYPE_WITH_PRIVATE(HalTimeTracker, hal_time_tracker, GTK_TYPE_BOX)

enum HalTimeTrackerProps
{
	PROP_0,
	PROP_CLIENT,
	PROP_USER,
	N_PROPS
};

G_GNUC_UNUSED static GParamSpec *obj_properties[N_PROPS];

static void
hal_time_tracker_clear_entries(HalTimeTracker *self)
{
	G_GNUC_UNUSED HalTimeTrackerPrivate *priv = hal_time_tracker_get_instance_private(self);
}

static void
on_monday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "monday");
}

static void
on_tuesday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "tuesday");
}

static void
on_wednesday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "wednesday");
}

static void
on_thursday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "thursday");
}

static void
on_friday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "friday");
}

static void
on_saturday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "saturday");
}

static void
on_sunday_button_clicked(G_GNUC_UNUSED GtkButton *widget, gpointer user_data)
{
	gtk_stack_set_visible_child_name(GTK_STACK(user_data), "sunday");
}

static void
hal_time_tracker_finalize(GObject *self)
{
	hal_time_tracker_clear_entries(HAL_TIME_TRACKER(self));

	G_OBJECT_CLASS(hal_time_tracker_parent_class)->finalize(self);
}

static void
hal_time_tracker_get_property(
	GObject *obj, guint prop_id, G_GNUC_UNUSED GValue *val, GParamSpec *pspec)
{
	switch (prop_id) {
	case PROP_CLIENT:
		break;
	case PROP_USER:
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
	}
}

static void
hal_time_tracker_set_property(
	GObject *obj, guint prop_id, G_GNUC_UNUSED const GValue *val, GParamSpec *pspec)
{
	switch (prop_id) {
	case PROP_CLIENT:
		break;
	case PROP_USER:
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec);
	}
}

static void
hal_time_tracker_class_init(HalTimeTrackerClass *klass)
{
	GObjectClass *obj_class	  = G_OBJECT_CLASS(klass);
	GtkWidgetClass *wid_class = GTK_WIDGET_CLASS(klass);

	obj_class->finalize		= hal_time_tracker_finalize;
	obj_class->get_property = hal_time_tracker_get_property;
	obj_class->set_property = hal_time_tracker_set_property;

	gtk_widget_class_set_template_from_resource(
		wid_class, "/io/partin/tristan/HarvestAlmanac/ui/hal-time-tracker.ui");
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, monday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, tuesday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, wednesday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, thursday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, friday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, saturday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, sunday_button);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, monday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, tuesday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, wednesday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, thursday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, friday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, saturday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, sunday_time);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, monday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, tuesday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, wednesday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, thursday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, friday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, saturday_time_entries);
	gtk_widget_class_bind_template_child_private(wid_class, HalTimeTracker, sunday_time_entries);
	gtk_widget_class_bind_template_callback(wid_class, on_monday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_tuesday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_wednesday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_thursday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_friday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_saturday_button_clicked);
	gtk_widget_class_bind_template_callback(wid_class, on_sunday_button_clicked);
}

static void
hal_time_tracker_init(HalTimeTracker *self)
{
	HalTimeTrackerPrivate *priv = hal_time_tracker_get_instance_private(self);

	gtk_widget_init_template(GTK_WIDGET(self));

	gtk_list_box_insert(priv->monday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->tuesday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->wednesday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->thursday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->friday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->saturday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
	gtk_list_box_insert(priv->sunday_time_entries, GTK_WIDGET(hal_time_entry_new()), -1);
}

HalTimeTracker *
hal_time_tracker_new()
{
	return g_object_new(HAL_TYPE_TIME_TRACKER, NULL);
}