[balsa/wip/gtk4: 263/351] rfc 2445: Declare types final
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/wip/gtk4: 263/351] rfc 2445: Declare types final
- Date: Wed, 23 May 2018 21:39:04 +0000 (UTC)
commit b734995ac226df3d1dd9314a420d4c47ea3186c6
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Thu Mar 29 22:44:41 2018 -0400
rfc 2445: Declare types final
Use G_DECLARE_FINAL_TYPE for LibBalsaVCal and LibBalsaVEvent, make them
private, and provide a complete set of getters.
libbalsa/rfc2445.c | 152 +++++++++++++++++++++++--------------
libbalsa/rfc2445.h | 78 ++++++-------------
src/balsa-mime-widget-vcalendar.c | 28 ++++---
src/balsa-print-object-text.c | 27 ++++---
4 files changed, 151 insertions(+), 134 deletions(-)
---
diff --git a/libbalsa/rfc2445.c b/libbalsa/rfc2445.c
index 61f99c0..111e48d 100644
--- a/libbalsa/rfc2445.c
+++ b/libbalsa/rfc2445.c
@@ -42,10 +42,6 @@ typedef enum {
} LibBalsaVCalRole;
-static GObjectClass *libbalsa_vcal_parent_class = NULL;
-static GObjectClass *libbalsa_vevent_parent_class = NULL;
-
-
/* LibBalsaAddress extra object data */
#define RFC2445_ROLE "RFC2445:Role"
#define RFC2445_PARTSTAT "RFC2445:PartStat"
@@ -97,40 +93,28 @@ static struct {
/* --- VCal GObject stuff --- */
-GType
-libbalsa_vcal_get_type(void)
-{
- static GType libbalsa_vcal_type = 0;
-
- if (!libbalsa_vcal_type) {
- static const GTypeInfo libbalsa_vcal_type_info = {
- sizeof(LibBalsaVCalClass), /* class_size */
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) libbalsa_vcal_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(LibBalsaVCal), /* instance_size */
- 0, /* n_preallocs */
- (GInstanceInitFunc) libbalsa_vcal_init, /* instance_init */
- /* no value_table */
- };
-
- libbalsa_vcal_type =
- g_type_register_static(G_TYPE_OBJECT, "LibBalsaVCal",
- &libbalsa_vcal_type_info, 0);
- }
- return libbalsa_vcal_type;
-}
+struct _LibBalsaVCal {
+ GObject parent;
+ /* method */
+ LibBalsaVCalMethod method;
+
+ /* linked list of VEVENT entries */
+ GList *vevent;
+};
+
+struct _LibBalsaVCalClass {
+ GObjectClass parent;
+};
+
+G_DEFINE_TYPE(LibBalsaVCal, libbalsa_vcal, G_TYPE_OBJECT)
static void
libbalsa_vcal_class_init(LibBalsaVCalClass * klass)
{
GObjectClass *gobject_klass = G_OBJECT_CLASS(klass);
- libbalsa_vcal_parent_class = g_type_class_peek(G_TYPE_OBJECT);
gobject_klass->finalize = (GObjectFinalizeFunc) libbalsa_vcal_finalize;
}
@@ -150,7 +134,7 @@ libbalsa_vcal_finalize(LibBalsaVCal * self)
g_list_free_full(self->vevent, g_object_unref);
- libbalsa_vcal_parent_class->finalize(G_OBJECT(self));
+ G_OBJECT_CLASS(libbalsa_vcal_parent_class)->finalize(G_OBJECT(self));
}
@@ -162,32 +146,27 @@ libbalsa_vcal_new(void)
/* --- VEvent GObject stuff --- */
-GType
-libbalsa_vevent_get_type(void)
-{
- static GType libbalsa_vevent_type = 0;
-
- if (!libbalsa_vevent_type) {
- static const GTypeInfo libbalsa_vevent_type_info = {
- sizeof(LibBalsaVEventClass), /* class_size */
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) libbalsa_vevent_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(LibBalsaVEvent), /* instance_size */
- 0, /* n_preallocs */
- (GInstanceInitFunc) libbalsa_vevent_init, /* instance_init */
- /* no value_table */
- };
-
- libbalsa_vevent_type =
- g_type_register_static(G_TYPE_OBJECT, "LibBalsaVEvent",
- &libbalsa_vevent_type_info, 0);
- }
- return libbalsa_vevent_type;
-}
+struct _LibBalsaVEvent {
+ GObject parent;
+
+ LibBalsaAddress *organizer;
+ GList *attendee;
+ time_t stamp;
+ time_t start;
+ time_t end;
+ gchar *uid;
+ gchar *summary;
+ gchar *location;
+ gchar *description;
+};
+
+
+struct _LibBalsaVEventClass {
+ GObjectClass parent;
+};
+
+G_DEFINE_TYPE(LibBalsaVEvent, libbalsa_vevent, G_TYPE_OBJECT)
static void
@@ -195,7 +174,6 @@ libbalsa_vevent_class_init(LibBalsaVEventClass * klass)
{
GObjectClass *gobject_klass = G_OBJECT_CLASS(klass);
- libbalsa_vevent_parent_class = g_type_class_peek(G_TYPE_OBJECT);
gobject_klass->finalize =
(GObjectFinalizeFunc) libbalsa_vevent_finalize;
}
@@ -222,7 +200,7 @@ libbalsa_vevent_finalize(LibBalsaVEvent * self)
g_free(self->location);
g_free(self->description);
- libbalsa_vevent_parent_class->finalize(G_OBJECT(self));
+ G_OBJECT_CLASS(libbalsa_vevent_parent_class)->finalize(G_OBJECT(self));
}
@@ -786,3 +764,61 @@ vcal_str_to_part_stat(const gchar * pstat)
&& g_ascii_strcasecmp(pstat, pstat_list[n].pstat_id); n++);
return pstat_list[n].pstat;
}
+
+/*
+ * Getters
+ */
+
+LibBalsaVCalMethod
+libbalsa_vcal_get_method(LibBalsaVCal *vcal)
+{
+ return vcal->method;
+}
+
+GList *
+libbalsa_vcal_get_vevent(LibBalsaVCal *vcal)
+{
+ return vcal->vevent;
+}
+
+const gchar *
+libbalsa_vevent_get_summary(LibBalsaVEvent *vevent)
+{
+ return vevent->summary;
+}
+
+LibBalsaAddress *
+libbalsa_vevent_get_organizer(LibBalsaVEvent *vevent)
+{
+ return vevent->organizer;
+}
+
+time_t
+libbalsa_vevent_get_start(LibBalsaVEvent *vevent)
+{
+ return vevent->start;
+}
+
+time_t
+libbalsa_vevent_get_end(LibBalsaVEvent *vevent)
+{
+ return vevent->end;
+}
+
+const gchar *
+libbalsa_vevent_get_location(LibBalsaVEvent *vevent)
+{
+ return vevent->location;
+}
+
+GList *
+libbalsa_vevent_get_attendee(LibBalsaVEvent *vevent)
+{
+ return vevent->attendee;
+}
+
+const gchar *
+libbalsa_vevent_get_description(LibBalsaVEvent *vevent)
+{
+ return vevent->description;
+}
diff --git a/libbalsa/rfc2445.h b/libbalsa/rfc2445.h
index 710c66b..318a84a 100644
--- a/libbalsa/rfc2445.h
+++ b/libbalsa/rfc2445.h
@@ -31,28 +31,24 @@
G_BEGIN_DECLS
/* a VCalendar object description as GObject */
-#define LIBBALSA_TYPE_VCAL (libbalsa_vcal_get_type())
-#define LIBBALSA_VCAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), LIBBALSA_TYPE_VCAL, LibBalsaVCal))
-#define LIBBALSA_VCAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), LIBBALSA_TYPE_VCAL,
LibBalsaVCalClass))
-#define LIBBALSA_IS_VCAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LIBBALSA_TYPE_VCAL))
-#define LIBBALSA_IS_VCAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), LIBBALSA_TYPE_VCAL))
-#define LIBBALSA_VCAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LIBBALSA_TYPE_VCAL,
LibBalsaVCalClass))
-typedef struct _LibBalsaVCal LibBalsaVCal;
-typedef struct _LibBalsaVCalClass LibBalsaVCalClass;
+#define LIBBALSA_TYPE_VCAL libbalsa_vcal_get_type()
+G_DECLARE_FINAL_TYPE(LibBalsaVCal,
+ libbalsa_vcal,
+ LIBBALSA,
+ VCAL,
+ GObject)
/* a VEvent object description as GObject */
-#define LIBBALSA_TYPE_VEVENT (libbalsa_vevent_get_type())
-#define LIBBALSA_VEVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), LIBBALSA_TYPE_VEVENT,
LibBalsaVEvent))
-#define LIBBALSA_VEVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), LIBBALSA_TYPE_VEVENT,
LibBalsaVEventClass))
-#define LIBBALSA_IS_VEVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), LIBBALSA_TYPE_VEVENT))
-#define LIBBALSA_IS_VEVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), LIBBALSA_TYPE_VEVENT))
-#define LIBBALSA_VEVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), LIBBALSA_TYPE_VEVENT,
LibBalsaVEventClass))
-typedef struct _LibBalsaVEvent LibBalsaVEvent;
-typedef struct _LibBalsaVEventClass LibBalsaVEventClass;
+#define LIBBALSA_TYPE_VEVENT libbalsa_vevent_get_type()
+G_DECLARE_FINAL_TYPE(LibBalsaVEvent,
+ libbalsa_vevent,
+ LIBBALSA,
+ VEVENT,
+ GObject)
/* methods as defined by RFC 2446 */
typedef enum {
@@ -77,47 +73,10 @@ typedef enum {
} LibBalsaVCalPartStat;
-struct _LibBalsaVCal {
- GObject parent;
- /* method */
- LibBalsaVCalMethod method;
-
- /* linked list of VEVENT entries */
- GList *vevent;
-};
-
-
-struct _LibBalsaVEvent {
- GObject parent;
-
- LibBalsaAddress *organizer;
- GList *attendee;
- time_t stamp;
- time_t start;
- time_t end;
- gchar *uid;
- gchar *summary;
- gchar *location;
- gchar *description;
-};
-
-
-struct _LibBalsaVCalClass {
- GObjectClass parent;
-};
-
-
-struct _LibBalsaVEventClass {
- GObjectClass parent;
-};
-
-
-GType libbalsa_vcal_get_type(void);
LibBalsaVCal *libbalsa_vcal_new(void);
LibBalsaVCal *libbalsa_vcal_new_from_body(LibBalsaMessageBody * body);
-GType libbalsa_vevent_get_type(void);
LibBalsaVEvent *libbalsa_vevent_new(void);
gchar *libbalsa_vevent_reply(const LibBalsaVEvent * event,
const gchar * sender,
@@ -128,6 +87,19 @@ gboolean libbalsa_vcal_attendee_rsvp(LibBalsaAddress * person);
const gchar *libbalsa_vcal_method_to_str(LibBalsaVCalMethod method);
const gchar *libbalsa_vcal_part_stat_to_str(LibBalsaVCalPartStat pstat);
+/*
+ * Getters
+ */
+LibBalsaVCalMethod libbalsa_vcal_get_method(LibBalsaVCal *vcal);
+GList *libbalsa_vcal_get_vevent(LibBalsaVCal *vcal);
+const gchar * libbalsa_vevent_get_summary(LibBalsaVEvent *vevent);
+LibBalsaAddress * libbalsa_vevent_get_organizer(LibBalsaVEvent *vevent);
+time_t libbalsa_vevent_get_start(LibBalsaVEvent *vevent);
+time_t libbalsa_vevent_get_end(LibBalsaVEvent *vevent);
+const gchar * libbalsa_vevent_get_location(LibBalsaVEvent *vevent);
+GList * libbalsa_vevent_get_attendee(LibBalsaVEvent *vevent);
+const gchar * libbalsa_vevent_get_description(LibBalsaVEvent *vevent);
+
G_END_DECLS
#endif /* __RFC2445_H__ */
diff --git a/src/balsa-mime-widget-vcalendar.c b/src/balsa-mime-widget-vcalendar.c
index c61c2c7..eddbd5f 100644
--- a/src/balsa-mime-widget-vcalendar.c
+++ b/src/balsa-mime-widget-vcalendar.c
@@ -43,6 +43,7 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
const gchar * content_type, gpointer data)
{
LibBalsaVCal *vcal_obj;
+ LibBalsaVCalMethod method;
BalsaMimeWidget *mw;
GtkWidget *widget;
GtkWidget *label;
@@ -64,8 +65,9 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
balsa_mime_widget_set_widget(mw, widget);
+ method = libbalsa_vcal_get_method(vcal_obj);
text = g_strdup_printf(_("This is an iTIP calendar ā%sā message."),
- libbalsa_vcal_method_to_str(vcal_obj->method));
+ libbalsa_vcal_method_to_str(method));
label = gtk_label_new(text);
g_free(text);
gtk_widget_set_halign(label, GTK_ALIGN_START);
@@ -73,7 +75,7 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
gtk_box_pack_start(GTK_BOX(widget), label);
/* a reply may be created only for unread requests */
- if ((vcal_obj->method == ITIP_REQUEST) &&
+ if ((method == ITIP_REQUEST) &&
LIBBALSA_MESSAGE_IS_UNREAD(lbm)) {
LibBalsaMessageHeaders *headers;
@@ -89,7 +91,7 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
}
/* add events */
- for (l = vcal_obj->vevent; l != NULL; l = l->next) {
+ for (l = libbalsa_vcal_get_vevent(vcal_obj); l != NULL; l = l->next) {
GtkWidget *event =
balsa_vevent_widget((LibBalsaVEvent *) l->data, may_reply,
sender);
@@ -169,16 +171,16 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
grid = GTK_GRID(gtk_grid_new());
gtk_grid_set_row_spacing(grid, 6);
gtk_grid_set_column_spacing(grid, 12);
- GRID_ATTACH(grid, event->summary, _("Summary:"));
- GRID_ATTACH_ADDRESS(grid, event->organizer, _("Organizer:"));
- GRID_ATTACH_DATE(grid, event->start, _("Start:"));
- GRID_ATTACH_DATE(grid, event->end, _("End:"));
- GRID_ATTACH(grid, event->location, _("Location:"));
- if (event->attendee) {
+ GRID_ATTACH(grid, libbalsa_vevent_get_summary(event), _("Summary:"));
+ GRID_ATTACH_ADDRESS(grid, libbalsa_vevent_get_organizer(event), _("Organizer:"));
+ GRID_ATTACH_DATE(grid, libbalsa_vevent_get_start(event), _("Start:"));
+ GRID_ATTACH_DATE(grid, libbalsa_vevent_get_end(event), _("End:"));
+ GRID_ATTACH(grid, libbalsa_vevent_get_location(event), _("Location:"));
+ if (libbalsa_vevent_get_attendee(event)) {
GList *att;
GString *all_atts = NULL;
- for (att = event->attendee; att; att = att->next) {
+ for (att = libbalsa_vevent_get_attendee(event); att; att = att->next) {
LibBalsaAddress *lba = LIBBALSA_ADDRESS(att->data);
gchar *this_att = libbalsa_vcal_attendee_to_str(lba);
@@ -206,10 +208,10 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
}
GRID_ATTACH(grid, all_atts->str,
ngettext("Attendee:", "Attendees:",
- g_list_length(event->attendee)));
+ g_list_length(libbalsa_vevent_get_attendee(event))));
g_string_free(all_atts, TRUE);
}
- GRID_ATTACH_TEXT(grid, event->description, _("Description:"));
+ GRID_ATTACH_TEXT(grid, libbalsa_vevent_get_description(event), _("Description:"));
if (sender && vevent_ident) {
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
@@ -303,7 +305,7 @@ vevent_reply(GObject * button, GtkWidget * box)
/* create the message subject */
dummy = g_strdup_printf("%s: %s",
- event->summary ? event->summary : _("iTIP Calendar Request"),
+ libbalsa_vevent_get_summary(event) ? libbalsa_vevent_get_summary(event) : _("iTIP
Calendar Request"),
libbalsa_vcal_part_stat_to_str(pstat));
libbalsa_message_set_subject(message, dummy);
g_free(dummy);
diff --git a/src/balsa-print-object-text.c b/src/balsa-print-object-text.c
index 06b8f3e..645ed2f 100644
--- a/src/balsa-print-object-text.c
+++ b/src/balsa-print-object-text.c
@@ -634,23 +634,28 @@ balsa_print_object_text_calendar(GList * list,
/* add fields from the events*/
desc_buf = g_string_new("");
pod->p_label_width = 0;
- for (this_ev = vcal_obj->vevent; this_ev != NULL; this_ev = this_ev->next) {
+ for (this_ev = libbalsa_vcal_get_vevent(vcal_obj);
+ this_ev != NULL; this_ev = this_ev->next) {
LibBalsaVEvent * event = (LibBalsaVEvent *) this_ev->data;
+ const gchar *description;
+ GList *attendee;
if (desc_buf->len > 0)
g_string_append_c(desc_buf, '\n');
ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
- event->summary, _("Summary"));
+ libbalsa_vevent_get_summary(event), _("Summary"));
ADD_VCAL_ADDRESS(desc_buf, pod->p_label_width, test_layout,
- event->organizer, _("Organizer"));
+ libbalsa_vevent_get_organizer(event), _("Organizer"));
ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
- event->start, _("Start"));
+ libbalsa_vevent_get_start(event), _("Start"));
ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
- event->end, _("End"));
+ libbalsa_vevent_get_end(event), _("End"));
ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
- event->location, _("Location"));
- if (event->attendee) {
- GList * att = event->attendee;
+ libbalsa_vevent_get_location(event), _("Location"));
+
+ attendee = libbalsa_vevent_get_attendee(event);
+ if (attendee != NULL) {
+ GList * att = attendee;
gchar * this_att;
this_att =
@@ -666,8 +671,10 @@ balsa_print_object_text_calendar(GList * list,
g_free(this_att);
}
}
- if (event->description) {
- gchar ** desc_lines = g_strsplit(event->description, "\n", -1);
+
+ description = libbalsa_vevent_get_description(event);
+ if (description != NULL) {
+ gchar ** desc_lines = g_strsplit(description, "\n", -1);
gint i;
ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]