From 6f1eb7ca9db40de0b2ce5bb016c5f9ecb551ada1 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 30 Dec 2015 14:36:27 -0200 Subject: [PATCH] edit-dialog: turn into a final class This commit updates GcalEditDialog's code for it to be a final class. As such, we don't need the GcalEditDialogPrivate type - we can simply move our data to the GcalEditDialog struct. --- src/gcal-edit-dialog.c | 484 +++++++++++++++++++---------------------- src/gcal-edit-dialog.h | 22 +- 2 files changed, 227 insertions(+), 279 deletions(-) diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c index f5217023..435b02d7 100644 --- a/src/gcal-edit-dialog.c +++ b/src/gcal-edit-dialog.c @@ -25,8 +25,10 @@ #include #include -typedef struct +struct _GcalEditDialog { + GtkDialog parent; + gchar *source_uid; gchar *event_uid; gchar *event_rid; @@ -68,7 +70,7 @@ typedef struct gboolean format_24h; gboolean event_is_new; gboolean setting_event; -} GcalEditDialogPrivate; +}; static void fill_sources_menu (GcalEditDialog *dialog); @@ -108,22 +110,19 @@ static void gcal_edit_dialog_action_button_clicked (GtkWidget *wi static void gcal_edit_dialog_all_day_changed (GtkWidget *widget, gpointer user_data); -G_DEFINE_TYPE_WITH_PRIVATE (GcalEditDialog, gcal_edit_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (GcalEditDialog, gcal_edit_dialog, GTK_TYPE_DIALOG) static void fill_sources_menu (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; GList *list; GList *aux; - priv = gcal_edit_dialog_get_instance_private (dialog); - - if (priv->manager == NULL) + if (dialog->manager == NULL) return; - list = gcal_manager_get_sources (priv->manager); - priv->sources_menu = g_menu_new (); + list = gcal_manager_get_sources (dialog->manager); + dialog->sources_menu = g_menu_new (); for (aux = list; aux != NULL; aux = aux->next) { @@ -143,7 +142,7 @@ fill_sources_menu (GcalEditDialog *dialog) g_menu_item_set_icon (item, G_ICON (pix)); /* set insensitive for read-only calendars */ - if (!gcal_manager_is_client_writable (priv->manager, source)) + if (!gcal_manager_is_client_writable (dialog->manager, source)) { g_menu_item_set_action_and_target_value (item, "select_calendar", NULL); } @@ -153,16 +152,16 @@ fill_sources_menu (GcalEditDialog *dialog) g_variant_new_string (e_source_get_uid (source))); } - g_menu_append_item (priv->sources_menu, item); + g_menu_append_item (dialog->sources_menu, item); g_object_unref (pix); g_object_unref (item); } - gtk_popover_bind_model (GTK_POPOVER (priv->sources_popover), G_MENU_MODEL (priv->sources_menu), "edit"); + gtk_popover_bind_model (GTK_POPOVER (dialog->sources_popover), G_MENU_MODEL (dialog->sources_menu), "edit"); /* HACK: show the popover menu icons */ - fix_popover_menu_icons (GTK_POPOVER (priv->sources_popover)); + fix_popover_menu_icons (GTK_POPOVER (dialog->sources_popover)); g_list_free (list); } @@ -172,13 +171,13 @@ on_calendar_selected (GtkWidget *menu_item, GVariant *value, gpointer user_data) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; GList *list; GList *aux; gchar *uid; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); - list = gcal_manager_get_sources (priv->manager); + dialog = GCAL_EDIT_DIALOG (user_data); + list = gcal_manager_get_sources (dialog->manager); /* retrieve selected calendar uid */ g_variant_get (value, "s", &uid); @@ -198,13 +197,13 @@ on_calendar_selected (GtkWidget *menu_item, get_color_name_from_source (source, &color); pix = gcal_get_pixbuf_from_color (&color, 16); - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->source_image), pix); + gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->source_image), pix); g_object_unref (pix); - if (priv->source != NULL) - g_set_object (&(priv->source), source); - gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->titlebar), - e_source_get_display_name (priv->source)); + if (dialog->source != NULL) + g_set_object (&(dialog->source), source); + gtk_header_bar_set_subtitle (GTK_HEADER_BAR (dialog->titlebar), + e_source_get_display_name (dialog->source)); break; } } @@ -217,15 +216,15 @@ static void update_date (GtkEntry *entry, gpointer user_data) { - GcalEditDialogPrivate *priv; ECalComponentDateTime dtstart; ECalComponentDateTime dtend; + GcalEditDialog *dialog; icaltimetype *start_date; icaltimetype *end_date; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); - if (priv->setting_event) + if (dialog->setting_event) return; start_date = gcal_edit_dialog_get_start_date (GCAL_EDIT_DIALOG (user_data)); @@ -235,13 +234,13 @@ update_date (GtkEntry *entry, if (icaltime_compare (*start_date, *end_date) != -1) { /* change the non-editing entry */ - if (GTK_WIDGET (entry) == priv->start_date_selector) + if (GTK_WIDGET (entry) == dialog->start_date_selector) { end_date->day = start_date->day; end_date->month = start_date->month; end_date->year = start_date->year; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_day_check))) + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check))) { end_date->day += 1; *end_date = icaltime_normalize (*end_date); @@ -253,7 +252,7 @@ update_date (GtkEntry *entry, start_date->month = end_date->month; start_date->year = end_date->year; - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_day_check))) + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check))) { start_date->day -= 1; *start_date = icaltime_normalize (*start_date); @@ -261,33 +260,33 @@ update_date (GtkEntry *entry, } /* update the entries with the new sane values */ - g_signal_handlers_block_by_func (priv->start_date_selector, + g_signal_handlers_block_by_func (dialog->start_date_selector, update_date, user_data); - g_signal_handlers_block_by_func (priv->end_date_selector, + g_signal_handlers_block_by_func (dialog->end_date_selector, update_date, user_data); - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->start_date_selector), start_date->day, start_date->month, start_date->year); - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), end_date->day, end_date->month, end_date->year); - g_signal_handlers_unblock_by_func (priv->start_date_selector, + g_signal_handlers_unblock_by_func (dialog->start_date_selector, update_date, user_data); - g_signal_handlers_unblock_by_func (priv->end_date_selector, + g_signal_handlers_unblock_by_func (dialog->end_date_selector, update_date, user_data); } /* update component */ - e_cal_component_get_dtstart (priv->component, &dtstart); - e_cal_component_get_dtend (priv->component, &dtend); + e_cal_component_get_dtstart (dialog->component, &dtstart); + e_cal_component_get_dtend (dialog->component, &dtend); *(dtstart.value) = *start_date; if (dtstart.tzid != NULL) @@ -303,9 +302,9 @@ update_date (GtkEntry *entry, *(dtend.value) = icaltime_convert_to_zone (*end_date, zone); } - e_cal_component_set_dtstart (priv->component, &dtstart); - e_cal_component_set_dtend (priv->component, &dtend); - e_cal_component_commit_sequence (priv->component); + e_cal_component_set_dtstart (dialog->component, &dtstart); + e_cal_component_set_dtend (dialog->component, &dtend); + e_cal_component_commit_sequence (dialog->component); g_free (start_date); g_free (end_date); @@ -319,24 +318,24 @@ update_location (GtkEntry *entry, GParamSpec *pspec, gpointer user_data) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); - e_cal_component_set_location (priv->component, gtk_entry_get_text (entry)); - e_cal_component_commit_sequence (priv->component); + e_cal_component_set_location (dialog->component, gtk_entry_get_text (entry)); + e_cal_component_commit_sequence (dialog->component); } static void update_notes (GtkTextBuffer *buffer, gpointer user_data) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; GSList note; ECalComponentText text; gchar *note_text; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); g_object_get (G_OBJECT (buffer), "text", ¬e_text, @@ -347,8 +346,8 @@ update_notes (GtkTextBuffer *buffer, note.data = &text; note.next = NULL; - e_cal_component_set_description_list (priv->component, ¬e); - e_cal_component_commit_sequence (priv->component); + e_cal_component_set_description_list (dialog->component, ¬e); + e_cal_component_commit_sequence (dialog->component); g_free (note_text); } @@ -358,32 +357,32 @@ update_summary (GtkEntry *entry, GParamSpec *pspec, gpointer user_data) { - GcalEditDialogPrivate *priv; ECalComponentText summary; + GcalEditDialog *dialog; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); summary.value = gtk_entry_get_text (entry); summary.altrep = NULL; - e_cal_component_set_summary (priv->component, &summary); - e_cal_component_commit_sequence (priv->component); + e_cal_component_set_summary (dialog->component, &summary); + e_cal_component_commit_sequence (dialog->component); } static void update_time (GtkEntry *entry, gpointer user_data) { - GcalEditDialogPrivate *priv; ECalComponentDateTime dtstart; ECalComponentDateTime dtend; + GcalEditDialog *dialog; icaltimetype *start_date; icaltimetype *end_date; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); - if (priv->setting_event) + if (dialog->setting_event) return; start_date = gcal_edit_dialog_get_start_date (GCAL_EDIT_DIALOG (user_data)); @@ -393,7 +392,7 @@ update_time (GtkEntry *entry, if (icaltime_compare (*start_date, *end_date) > -1) { /* change the non-editing entry */ - if (GTK_WIDGET (entry) == priv->start_time_selector) + if (GTK_WIDGET (entry) == dialog->start_time_selector) { end_date->hour = start_date->hour + 1; end_date->minute = start_date->minute; @@ -407,33 +406,33 @@ update_time (GtkEntry *entry, } /* update the entries with the new sane values */ - g_signal_handlers_block_by_func (priv->start_time_selector, + g_signal_handlers_block_by_func (dialog->start_time_selector, update_time, user_data); - g_signal_handlers_block_by_func (priv->end_time_selector, + g_signal_handlers_block_by_func (dialog->end_time_selector, update_time, user_data); /* updates date as well, since hours can change the current date */ - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), start_date->hour, start_date->minute); - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->start_date_selector), start_date->day, start_date->month, start_date->year); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), end_date->hour, end_date->minute); - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), end_date->day, end_date->month, end_date->year); - g_signal_handlers_unblock_by_func (priv->start_time_selector, + g_signal_handlers_unblock_by_func (dialog->start_time_selector, update_time, user_data); - g_signal_handlers_unblock_by_func (priv->end_time_selector, + g_signal_handlers_unblock_by_func (dialog->end_time_selector, update_time, user_data); } @@ -443,8 +442,8 @@ update_time (GtkEntry *entry, icaltime_as_ical_string (*end_date)); /* update component */ - e_cal_component_get_dtstart (priv->component, &dtstart); - e_cal_component_get_dtend (priv->component, &dtend); + e_cal_component_get_dtstart (dialog->component, &dtstart); + e_cal_component_get_dtend (dialog->component, &dtend); *(dtstart.value) = *start_date; if (dtstart.tzid != NULL) @@ -460,9 +459,9 @@ update_time (GtkEntry *entry, *(dtend.value) = icaltime_convert_to_zone (*end_date, zone); } - e_cal_component_set_dtstart (priv->component, &dtstart); - e_cal_component_set_dtend (priv->component, &dtend); - e_cal_component_commit_sequence (priv->component); + e_cal_component_set_dtstart (dialog->component, &dtstart); + e_cal_component_set_dtend (dialog->component, &dtend); + e_cal_component_commit_sequence (dialog->component); g_free (start_date); g_free (end_date); @@ -484,24 +483,24 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/edit-dialog.ui"); /* Buttons */ - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, done_button); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, cancel_button); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, delete_button); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, sources_button); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, done_button); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, cancel_button); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, delete_button); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, sources_button); /* Entries */ - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, summary_entry); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, start_time_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, start_date_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, end_time_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, end_date_selector); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, location_entry); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, summary_entry); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, start_time_selector); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, start_date_selector); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, end_time_selector); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, end_date_selector); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, location_entry); /* Other */ - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, notes_text); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, all_day_check); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, titlebar); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, lock); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, source_image); - gtk_widget_class_bind_template_child_private (widget_class, GcalEditDialog, sources_popover); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, notes_text); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, all_day_check); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, titlebar); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, lock); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, source_image); + gtk_widget_class_bind_template_child (widget_class, GcalEditDialog, sources_popover); /* callbacks */ gtk_widget_class_bind_template_callback (widget_class, gcal_edit_dialog_action_button_clicked); @@ -515,20 +514,17 @@ gcal_edit_dialog_class_init (GcalEditDialogClass *klass) static void gcal_edit_dialog_init (GcalEditDialog *self) { - GcalEditDialogPrivate *priv; + self->writable = TRUE; - priv = gcal_edit_dialog_get_instance_private (self); - - priv->writable = TRUE; gtk_widget_init_template (GTK_WIDGET (self)); } static void gcal_edit_dialog_constructed (GObject* object) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (object)); + dialog = GCAL_EDIT_DIALOG (object); /* chaining up */ G_OBJECT_CLASS (gcal_edit_dialog_parent_class)->constructed (object); @@ -536,52 +532,52 @@ gcal_edit_dialog_constructed (GObject* object) gtk_window_set_title (GTK_WINDOW (object), ""); /* titlebar */ - gtk_window_set_titlebar (GTK_WINDOW (object), priv->titlebar); + gtk_window_set_titlebar (GTK_WINDOW (object), dialog->titlebar); /* actions */ - priv->action_group = g_simple_action_group_new (); + dialog->action_group = g_simple_action_group_new (); gtk_widget_insert_action_group (GTK_WIDGET (object), "edit", - G_ACTION_GROUP (priv->action_group)); + G_ACTION_GROUP (dialog->action_group)); - priv->action = g_simple_action_new ("select_calendar", G_VARIANT_TYPE_STRING); - g_signal_connect (priv->action, + dialog->action = g_simple_action_new ("select_calendar", G_VARIANT_TYPE_STRING); + g_signal_connect (dialog->action, "activate", G_CALLBACK (on_calendar_selected), object); - g_action_map_add_action (G_ACTION_MAP (priv->action_group), G_ACTION (priv->action)); + g_action_map_add_action (G_ACTION_MAP (dialog->action_group), G_ACTION (dialog->action)); /* bind title & symmary */ - g_object_bind_property (priv->summary_entry, + g_object_bind_property (dialog->summary_entry, "text", - priv->titlebar, + dialog->titlebar, "title", G_BINDING_DEFAULT); /* bind all-day check button & time entries */ - g_object_bind_property (priv->all_day_check, + g_object_bind_property (dialog->all_day_check, "active", - priv->start_time_selector, + dialog->start_time_selector, "sensitive", G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN); - g_object_bind_property (priv->all_day_check, + g_object_bind_property (dialog->all_day_check, "active", - priv->end_time_selector, + dialog->end_time_selector, "sensitive", G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN); /* action area, buttons */ - g_object_set_data (G_OBJECT (priv->cancel_button), + g_object_set_data (G_OBJECT (dialog->cancel_button), "response", GINT_TO_POINTER (GTK_RESPONSE_CANCEL)); - g_object_set_data (G_OBJECT (priv->delete_button), + g_object_set_data (G_OBJECT (dialog->delete_button), "response", GINT_TO_POINTER (GCAL_RESPONSE_DELETE_EVENT)); - g_object_set_data (G_OBJECT (priv->done_button), + g_object_set_data (G_OBJECT (dialog->done_button), "response", GINT_TO_POINTER (GCAL_RESPONSE_SAVE_EVENT)); - g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->notes_text)), "changed", G_CALLBACK (update_notes), + g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->notes_text)), "changed", G_CALLBACK (update_notes), object); } @@ -589,27 +585,27 @@ gcal_edit_dialog_constructed (GObject* object) static void gcal_edit_dialog_finalize (GObject *object) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (object)); + dialog = GCAL_EDIT_DIALOG (object); - if (priv->source_uid != NULL) - g_free (priv->source_uid); + if (dialog->source_uid != NULL) + g_free (dialog->source_uid); - if (priv->event_uid != NULL) - g_free (priv->event_uid); + if (dialog->event_uid != NULL) + g_free (dialog->event_uid); - if (priv->source != NULL) - g_object_unref (priv->source); + if (dialog->source != NULL) + g_object_unref (dialog->source); - if (priv->component != NULL) - g_object_unref (priv->component); + if (dialog->component != NULL) + g_object_unref (dialog->component); - if (priv->action_group != NULL) - g_object_unref (priv->action_group); + if (dialog->action_group != NULL) + g_object_unref (dialog->action_group); - if (priv->action != NULL) - g_object_unref (priv->action); + if (dialog->action != NULL) + g_object_unref (dialog->action); G_OBJECT_CLASS (gcal_edit_dialog_parent_class)->finalize (object); } @@ -618,88 +614,80 @@ static void gcal_edit_dialog_set_writable (GcalEditDialog *dialog, gboolean writable) { - GcalEditDialogPrivate *priv; - - priv = gcal_edit_dialog_get_instance_private (dialog); - - priv->writable = writable; + dialog->writable = writable; if (! writable) { - gtk_widget_show (priv->lock); + gtk_widget_show (dialog->lock); } else { - gtk_widget_hide (priv->lock); + gtk_widget_hide (dialog->lock); } - gtk_editable_set_editable (GTK_EDITABLE (priv->summary_entry), writable); - gtk_editable_set_editable (GTK_EDITABLE (priv->location_entry), writable); + gtk_editable_set_editable (GTK_EDITABLE (dialog->summary_entry), writable); + gtk_editable_set_editable (GTK_EDITABLE (dialog->location_entry), writable); - gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->notes_text), writable); + gtk_text_view_set_editable (GTK_TEXT_VIEW (dialog->notes_text), writable); - gtk_widget_set_sensitive (priv->all_day_check, writable); - gtk_widget_set_sensitive (priv->end_date_selector, writable); - gtk_widget_set_sensitive (priv->start_date_selector, writable); + gtk_widget_set_sensitive (dialog->all_day_check, writable); + gtk_widget_set_sensitive (dialog->end_date_selector, writable); + gtk_widget_set_sensitive (dialog->start_date_selector, writable); - if (!writable || (writable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_day_check)))) + if (!writable || (writable && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check)))) { - gtk_widget_set_sensitive (priv->start_time_selector, FALSE); - gtk_widget_set_sensitive (priv->end_time_selector, FALSE); + gtk_widget_set_sensitive (dialog->start_time_selector, FALSE); + gtk_widget_set_sensitive (dialog->end_time_selector, FALSE); } else { - gtk_widget_set_sensitive (priv->start_time_selector, TRUE); - gtk_widget_set_sensitive (priv->end_time_selector, TRUE); + gtk_widget_set_sensitive (dialog->start_time_selector, TRUE); + gtk_widget_set_sensitive (dialog->end_time_selector, TRUE); } - gtk_button_set_label (GTK_BUTTON (priv->done_button), + gtk_button_set_label (GTK_BUTTON (dialog->done_button), writable ? _("Save") : _("Done")); /* add delete_button here */ - gtk_widget_set_sensitive (priv->delete_button, writable); + gtk_widget_set_sensitive (dialog->delete_button, writable); } static void gcal_edit_dialog_clear_data (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; - - priv = gcal_edit_dialog_get_instance_private (dialog); - /* summary */ - g_signal_handlers_block_by_func (priv->summary_entry, + g_signal_handlers_block_by_func (dialog->summary_entry, update_summary, dialog); - gtk_entry_set_text (GTK_ENTRY (priv->summary_entry), ""); - g_signal_handlers_unblock_by_func (priv->summary_entry, + gtk_entry_set_text (GTK_ENTRY (dialog->summary_entry), ""); + g_signal_handlers_unblock_by_func (dialog->summary_entry, update_summary, dialog); /* date and time */ - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), 0, 0, 0); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), 0, 0); - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), 0, 0, 0); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), 0, 0); + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->start_date_selector), 0, 0, 0); + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), 0, 0); + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), 0, 0, 0); + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), 0, 0); /* location */ - g_signal_handlers_block_by_func (priv->location_entry, + g_signal_handlers_block_by_func (dialog->location_entry, update_location, dialog); - gtk_entry_set_text (GTK_ENTRY (priv->location_entry), ""); - g_signal_handlers_unblock_by_func (priv->location_entry, + gtk_entry_set_text (GTK_ENTRY (dialog->location_entry), ""); + g_signal_handlers_unblock_by_func (dialog->location_entry, update_location, dialog); /* notes */ - g_signal_handlers_block_by_func (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->notes_text)), + g_signal_handlers_block_by_func (gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->notes_text)), update_notes, dialog); gtk_text_buffer_set_text ( - gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->notes_text)), + gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->notes_text)), "", -1); - g_signal_handlers_unblock_by_func (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->notes_text)), + g_signal_handlers_unblock_by_func (gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->notes_text)), update_notes, dialog); } @@ -708,15 +696,16 @@ static void gcal_edit_dialog_action_button_clicked (GtkWidget *widget, gpointer user_data) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; gint response; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); + response = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "response")); if (response == GCAL_RESPONSE_SAVE_EVENT && - priv->event_is_new) + dialog->event_is_new) { response = GCAL_RESPONSE_CREATE_EVENT; } @@ -728,14 +717,14 @@ static void gcal_edit_dialog_all_day_changed (GtkWidget *widget, gpointer user_data) { - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (user_data)); + dialog = GCAL_EDIT_DIALOG (user_data); - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->all_day_check))) + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check))) { - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), 0, 0); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), 0, 0); + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), 0, 0); + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), 0, 0); } } @@ -743,40 +732,35 @@ gcal_edit_dialog_all_day_changed (GtkWidget *widget, GtkWidget* gcal_edit_dialog_new (gboolean format_24h) { - GtkWidget *dialog; - GcalEditDialogPrivate *priv; + GcalEditDialog *dialog; dialog = g_object_new (GCAL_TYPE_EDIT_DIALOG, NULL); - priv = gcal_edit_dialog_get_instance_private (GCAL_EDIT_DIALOG (dialog)); - priv->format_24h = format_24h; + dialog->format_24h = format_24h; - gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (priv->start_time_selector), format_24h); - gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (priv->end_time_selector), format_24h); + gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->start_time_selector), format_24h); + gcal_time_selector_set_time_format (GCAL_TIME_SELECTOR (dialog->end_time_selector), format_24h); - return dialog; + return GTK_WIDGET (dialog); } void gcal_edit_dialog_set_event_is_new (GcalEditDialog *dialog, gboolean event_is_new) { - GcalEditDialogPrivate *priv; + dialog->event_is_new = event_is_new; - priv = gcal_edit_dialog_get_instance_private (dialog); - priv->event_is_new = event_is_new; - gtk_widget_set_visible (GTK_WIDGET (priv->delete_button), !event_is_new); + gtk_widget_set_visible (GTK_WIDGET (dialog->delete_button), !event_is_new); /* FIXME: implement moving events to other sources */ - gtk_widget_set_sensitive (GTK_WIDGET (priv->sources_button), event_is_new); - gtk_button_set_relief (GTK_BUTTON (priv->sources_button), event_is_new ? GTK_RELIEF_NORMAL : GTK_RELIEF_NONE); + gtk_widget_set_sensitive (GTK_WIDGET (dialog->sources_button), event_is_new); + gtk_button_set_relief (GTK_BUTTON (dialog->sources_button), event_is_new ? GTK_RELIEF_NORMAL : GTK_RELIEF_NONE); } void gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, GcalEventData *data) { - GcalEditDialogPrivate *priv; GdkRGBA color; GdkPixbuf *pix; @@ -790,34 +774,33 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, ECalComponentDateTime dtstart; ECalComponentDateTime dtend; - priv = gcal_edit_dialog_get_instance_private (dialog); all_day = FALSE; - priv->setting_event = TRUE; + dialog->setting_event = TRUE; - if (priv->source != NULL) - g_clear_object (&(priv->source)); - priv->source = g_object_ref (data->source); + if (dialog->source != NULL) + g_clear_object (&(dialog->source)); + dialog->source = g_object_ref (data->source); - if (priv->component != NULL) - g_object_unref (priv->component); - priv->component = e_cal_component_clone (data->event_component); + if (dialog->component != NULL) + g_object_unref (dialog->component); + dialog->component = e_cal_component_clone (data->event_component); - if (priv->source_uid != NULL) - g_free (priv->source_uid); - priv->source_uid = g_strdup (e_source_get_uid (priv->source)); + if (dialog->source_uid != NULL) + g_free (dialog->source_uid); + dialog->source_uid = g_strdup (e_source_get_uid (dialog->source)); - id = e_cal_component_get_id (priv->component); + id = e_cal_component_get_id (dialog->component); - if (priv->event_uid != NULL) - g_free (priv->event_uid); - priv->event_uid = g_strdup (id->uid); + if (dialog->event_uid != NULL) + g_free (dialog->event_uid); + dialog->event_uid = g_strdup (id->uid); - if (priv->event_rid != NULL) - g_clear_pointer (&(priv->event_rid), g_free); + if (dialog->event_rid != NULL) + g_clear_pointer (&(dialog->event_rid), g_free); if (id->rid != NULL) { - priv->event_rid = g_strdup (id->rid); + dialog->event_rid = g_strdup (id->rid); } e_cal_component_free_id (id); @@ -826,38 +809,38 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, gcal_edit_dialog_clear_data (dialog); /* update sources list */ - if (priv->sources_menu != NULL) - g_menu_remove_all (priv->sources_menu); + if (dialog->sources_menu != NULL) + g_menu_remove_all (dialog->sources_menu); fill_sources_menu (dialog); /* Load new event data */ /* summary */ - e_cal_component_get_summary (priv->component, &e_summary); + e_cal_component_get_summary (dialog->component, &e_summary); if (e_summary.value == NULL || g_strcmp0 (e_summary.value, "") == 0) - gtk_entry_set_text (GTK_ENTRY (priv->summary_entry), _("Unnamed event")); + gtk_entry_set_text (GTK_ENTRY (dialog->summary_entry), _("Unnamed event")); else - gtk_entry_set_text (GTK_ENTRY (priv->summary_entry), e_summary.value); + gtk_entry_set_text (GTK_ENTRY (dialog->summary_entry), e_summary.value); /* dialog titlebar's title & subtitle */ get_color_name_from_source (data->source, &color); pix = gcal_get_pixbuf_from_color (&color, 16); - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->source_image), pix); + gtk_image_set_from_pixbuf (GTK_IMAGE (dialog->source_image), pix); g_object_unref (pix); - gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->titlebar), + gtk_header_bar_set_subtitle (GTK_HEADER_BAR (dialog->titlebar), e_source_get_display_name (data->source)); /* retrieve start and end dates */ - e_cal_component_get_dtstart (priv->component, &dtstart); - e_cal_component_get_dtend (priv->component, &dtend); + e_cal_component_get_dtstart (dialog->component, &dtstart); + e_cal_component_get_dtend (dialog->component, &dtend); /* check if it's an all-day event */ all_day = (dtstart.value->is_date == 1 && (dtend.value != NULL ? dtend.value->is_date == 1 : FALSE)); /* start date */ - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->start_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->start_date_selector), dtstart.value->day, dtstart.value->month, dtstart.value->year); @@ -873,7 +856,7 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, } *date = icaltime_convert_to_zone (*(dtstart.value), e_cal_util_get_system_timezone ()); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->start_time_selector), + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), date->hour, date->minute); g_free (date); } @@ -881,7 +864,7 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, /* end date */ if (dtend.value != NULL) { - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), dtend.value->day, dtend.value->month, dtend.value->year); if (!all_day) @@ -894,16 +877,16 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, } *date = icaltime_convert_to_zone (*(dtend.value), e_cal_util_get_system_timezone ()); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), date->hour, date->minute); g_free (date); } } else { - gcal_date_selector_set_date (GCAL_DATE_SELECTOR (priv->end_date_selector), + gcal_date_selector_set_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), dtstart.value->day, dtstart.value->month, dtstart.value->year); - gcal_time_selector_set_time (GCAL_TIME_SELECTOR (priv->end_time_selector), + gcal_time_selector_set_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), dtstart.value->hour, dtstart.value->minute); } @@ -911,107 +894,98 @@ gcal_edit_dialog_set_event_data (GcalEditDialog *dialog, e_cal_component_free_datetime (&dtend); /* all_day */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->all_day_check), all_day); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->all_day_check), all_day); /* location */ - e_cal_component_get_location (priv->component, &const_text); - gtk_entry_set_text (GTK_ENTRY (priv->location_entry), + e_cal_component_get_location (dialog->component, &const_text); + gtk_entry_set_text (GTK_ENTRY (dialog->location_entry), const_text != NULL ? const_text : ""); /* notes */ - description = get_desc_from_component (priv->component, "\n"); + description = get_desc_from_component (dialog->component, "\n"); if (description != NULL) { gtk_text_buffer_set_text ( - gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->notes_text)), + gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->notes_text)), description, -1); g_free (description); } - gcal_edit_dialog_set_writable (dialog, gcal_manager_is_client_writable (priv->manager, priv->source)); + gcal_edit_dialog_set_writable (dialog, gcal_manager_is_client_writable (dialog->manager, dialog->source)); - priv->setting_event = FALSE; + dialog->setting_event = FALSE; } void gcal_edit_dialog_set_manager (GcalEditDialog *dialog, GcalManager *manager) { - GcalEditDialogPrivate *priv; - + g_return_if_fail (GCAL_IS_EDIT_DIALOG (dialog)); g_return_if_fail (GCAL_IS_MANAGER (manager)); - priv = gcal_edit_dialog_get_instance_private (dialog); - priv->manager = manager; + dialog->manager = manager; } ECalComponent* gcal_edit_dialog_get_component (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; + g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL); - priv = gcal_edit_dialog_get_instance_private (dialog); - g_object_ref (priv->component); - return priv->component; + g_object_ref (dialog->component); + return dialog->component; } ESource* gcal_edit_dialog_get_source (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; + g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL); - priv = gcal_edit_dialog_get_instance_private (dialog); - return priv->source; + return dialog->source; } const gchar* gcal_edit_dialog_peek_source_uid (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; + g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL); - priv = gcal_edit_dialog_get_instance_private (dialog); - return priv->source_uid; + return dialog->source_uid; } const gchar* gcal_edit_dialog_peek_event_uid (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; + g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL); - priv = gcal_edit_dialog_get_instance_private (dialog); - return priv->event_uid; + return dialog->event_uid; } gchar* gcal_edit_dialog_get_event_uuid (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; gchar *uuid; - priv = gcal_edit_dialog_get_instance_private (dialog); - - if (priv->source_uid == NULL || - priv->event_uid == NULL) + if (dialog->source_uid == NULL || + dialog->event_uid == NULL) { return NULL; } - if (priv->event_rid != NULL) + if (dialog->event_rid != NULL) { uuid = g_strdup_printf ("%s:%s:%s", - priv->source_uid, - priv->event_uid, - priv->event_rid); + dialog->source_uid, + dialog->event_uid, + dialog->event_rid); } else { uuid = g_strdup_printf ("%s:%s", - priv->source_uid, - priv->event_uid); + dialog->source_uid, + dialog->event_uid); } return uuid; @@ -1020,21 +994,18 @@ gcal_edit_dialog_get_event_uuid (GcalEditDialog *dialog) icaltimetype* gcal_edit_dialog_get_start_date (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; icaltimetype *date; gint value1; gint value2; gint value3; - priv = gcal_edit_dialog_get_instance_private (dialog); - date = g_new0 (icaltimetype, 1); icaltime_set_timezone (date, - gcal_manager_get_system_timezone (priv->manager)); + gcal_manager_get_system_timezone (dialog->manager)); - gcal_date_selector_get_date (GCAL_DATE_SELECTOR (priv->start_date_selector), + gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->start_date_selector), &value1, &value2, &value3); @@ -1043,7 +1014,7 @@ gcal_edit_dialog_get_start_date (GcalEditDialog *dialog) date->year = value3; value1 = value2 = 0; - gcal_time_selector_get_time (GCAL_TIME_SELECTOR (priv->start_time_selector), + gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->start_time_selector), &value1, &value2); date->hour = value1; @@ -1061,21 +1032,18 @@ gcal_edit_dialog_get_start_date (GcalEditDialog *dialog) icaltimetype* gcal_edit_dialog_get_end_date (GcalEditDialog *dialog) { - GcalEditDialogPrivate *priv; icaltimetype *date; gint value1; gint value2; gint value3; - priv = gcal_edit_dialog_get_instance_private (dialog); - date = g_new0 (icaltimetype, 1); icaltime_set_timezone (date, - gcal_manager_get_system_timezone (priv->manager)); + gcal_manager_get_system_timezone (dialog->manager)); - gcal_date_selector_get_date (GCAL_DATE_SELECTOR (priv->end_date_selector), + gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->end_date_selector), &value1, &value2, &value3); @@ -1084,7 +1052,7 @@ gcal_edit_dialog_get_end_date (GcalEditDialog *dialog) date->year = value3; value1 = value2 = 0; - gcal_time_selector_get_time (GCAL_TIME_SELECTOR (priv->end_time_selector), + gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->end_time_selector), &value1, &value2); date->hour = value1; diff --git a/src/gcal-edit-dialog.h b/src/gcal-edit-dialog.h index 1053ca2e..fe7abf55 100644 --- a/src/gcal-edit-dialog.h +++ b/src/gcal-edit-dialog.h @@ -30,29 +30,9 @@ G_BEGIN_DECLS #define GCAL_RESPONSE_SAVE_EVENT 4 #define GCAL_RESPONSE_CREATE_EVENT 6 - #define GCAL_TYPE_EDIT_DIALOG (gcal_edit_dialog_get_type ()) -#define GCAL_EDIT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_EDIT_DIALOG, GcalEditDialog)) -#define GCAL_EDIT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_EDIT_DIALOG, GcalEditDialogClass)) -#define GCAL_IS_EDIT_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_EDIT_DIALOG)) -#define GCAL_IS_EDIT_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_EDIT_DIALOG)) -#define GCAL_EDIT_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_EDIT_DIALOG, GcalEditDialogClass)) -typedef struct _GcalEditDialog GcalEditDialog; -typedef struct _GcalEditDialogClass GcalEditDialogClass; - -struct _GcalEditDialog -{ - GtkDialog parent; -}; - -struct _GcalEditDialogClass -{ - GtkDialogClass parent_class; -}; - - -GType gcal_edit_dialog_get_type (void); +G_DECLARE_FINAL_TYPE (GcalEditDialog, gcal_edit_dialog, GCAL, EDIT_DIALOG, GtkDialog); GtkWidget* gcal_edit_dialog_new (gboolean format_24h);