gui/importer: Replace "context" property with context getter method
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/702>
This commit is contained in:
@@ -1043,7 +1043,6 @@ on_ics_files_filtered_cb (GObject *source_object,
|
||||
GAsyncResult *result,
|
||||
gpointer data)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autofree gchar* toast_title = NULL;
|
||||
AdwToast *error_toast = NULL;
|
||||
@@ -1075,11 +1074,9 @@ on_ics_files_filtered_cb (GObject *source_object,
|
||||
|
||||
if (filter_result->ics_files)
|
||||
{
|
||||
context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
|
||||
g_clear_pointer (&self->import_dialog, gtk_widget_unparent);
|
||||
|
||||
self->import_dialog = gcal_import_dialog_new_for_file_list (context, filter_result->ics_files);
|
||||
self->import_dialog = gcal_import_dialog_new_for_file_list (filter_result->ics_files);
|
||||
adw_dialog_present (ADW_DIALOG (self->import_dialog), GTK_WIDGET (self));
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (self->import_dialog), (gpointer *)&self->import_dialog);
|
||||
@@ -1558,12 +1555,11 @@ gcal_window_import_files (GcalWindow *self,
|
||||
GFile **files,
|
||||
gint n_files)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_return_if_fail (GCAL_IS_WINDOW (self));
|
||||
|
||||
g_clear_pointer (&self->import_dialog, gtk_widget_unparent);
|
||||
|
||||
self->import_dialog = gcal_import_dialog_new_for_files (context, files, n_files);
|
||||
self->import_dialog = gcal_import_dialog_new_for_files (files, n_files);
|
||||
adw_dialog_present (ADW_DIALOG (self->import_dialog), GTK_WIDGET (self));
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (self->import_dialog), (gpointer *)&self->import_dialog);
|
||||
|
||||
@@ -55,7 +55,6 @@ struct _GcalImportDialog
|
||||
GList *rows;
|
||||
|
||||
GCancellable *cancellable;
|
||||
GcalContext *context;
|
||||
gint n_events;
|
||||
gint n_files;
|
||||
};
|
||||
@@ -67,15 +66,6 @@ static void on_import_row_file_loaded_cb (GcalImportFil
|
||||
|
||||
G_DEFINE_TYPE (GcalImportDialog, gcal_import_dialog, ADW_TYPE_DIALOG)
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
static GParamSpec *properties [N_PROPS];
|
||||
|
||||
|
||||
/*
|
||||
* Auxiliary methods
|
||||
@@ -98,10 +88,11 @@ import_data_free (gpointer data)
|
||||
static void
|
||||
update_default_calendar (GcalImportDialog *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
GcalCalendar *default_calendar;
|
||||
GcalManager *manager;
|
||||
|
||||
manager = gcal_context_get_manager (self->context);
|
||||
manager = gcal_context_get_manager (context);
|
||||
default_calendar = gcal_manager_get_default_calendar (manager);
|
||||
|
||||
if (default_calendar)
|
||||
@@ -111,12 +102,11 @@ update_default_calendar (GcalImportDialog *self)
|
||||
static void
|
||||
setup_calendars (GcalImportDialog *self)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autoptr (GListModel) calendars = NULL;
|
||||
GcalManager *manager;
|
||||
|
||||
g_assert (self->context != NULL);
|
||||
|
||||
manager = gcal_context_get_manager (self->context);
|
||||
manager = gcal_context_get_manager (context);
|
||||
calendars = gcal_create_writable_calendars_model (manager);
|
||||
|
||||
// TODO: sort model
|
||||
@@ -138,7 +128,7 @@ add_file (GcalImportDialog *self,
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
row = gcal_import_file_row_new (self->context, file, self->title_sizegroup);
|
||||
row = gcal_import_file_row_new (file, self->title_sizegroup);
|
||||
g_signal_connect (row, "file-loaded", G_CALLBACK (on_import_row_file_loaded_cb), self);
|
||||
|
||||
group = ADW_PREFERENCES_GROUP (adw_preferences_group_new ());
|
||||
@@ -368,52 +358,12 @@ gcal_import_dialog_finalize (GObject *object)
|
||||
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_clear_object (&self->cancellable);
|
||||
g_clear_object (&self->context);
|
||||
|
||||
g_clear_pointer (&self->rows, g_list_free);
|
||||
|
||||
G_OBJECT_CLASS (gcal_import_dialog_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_import_dialog_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalImportDialog *self = GCAL_IMPORT_DIALOG (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, self->context);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_import_dialog_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalImportDialog *self = GCAL_IMPORT_DIALOG (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_assert (self->context == NULL);
|
||||
self->context = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_import_dialog_class_init (GcalImportDialogClass *klass)
|
||||
{
|
||||
@@ -424,21 +374,6 @@ gcal_import_dialog_class_init (GcalImportDialogClass *klass)
|
||||
|
||||
object_class->constructed = gcal_import_dialog_constructed;
|
||||
object_class->finalize = gcal_import_dialog_finalize;
|
||||
object_class->get_property = gcal_import_dialog_get_property;
|
||||
object_class->set_property = gcal_import_dialog_set_property;
|
||||
|
||||
/**
|
||||
* GcalEventPopover::context:
|
||||
*
|
||||
* The context of the import dialog.
|
||||
*/
|
||||
properties[PROP_CONTEXT] = g_param_spec_object ("context",
|
||||
"Context",
|
||||
"Context",
|
||||
GCAL_TYPE_CONTEXT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | 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/calendar/ui/gui/importer/gcal-import-dialog.ui");
|
||||
|
||||
@@ -462,14 +397,12 @@ gcal_import_dialog_init (GcalImportDialog *self)
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_import_dialog_new_for_files (GcalContext *context,
|
||||
GFile **files,
|
||||
gint n_files)
|
||||
gcal_import_dialog_new_for_files (GFile **files,
|
||||
gint n_files)
|
||||
{
|
||||
GcalImportDialog *self;
|
||||
|
||||
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
||||
"context", context,
|
||||
NULL);
|
||||
|
||||
setup_files (self, files, n_files);
|
||||
@@ -478,13 +411,11 @@ gcal_import_dialog_new_for_files (GcalContext *context,
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_import_dialog_new_for_file_list (GcalContext *context,
|
||||
GList *file_list)
|
||||
gcal_import_dialog_new_for_file_list (GList *file_list)
|
||||
{
|
||||
GcalImportDialog *self;
|
||||
|
||||
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
||||
"context", context,
|
||||
NULL);
|
||||
|
||||
setup_files_list (self, file_list);
|
||||
|
||||
@@ -30,12 +30,10 @@ G_BEGIN_DECLS
|
||||
#define GCAL_TYPE_IMPORT_DIALOG (gcal_import_dialog_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalImportDialog, gcal_import_dialog, GCAL, IMPORT_DIALOG, AdwDialog)
|
||||
|
||||
GtkWidget* gcal_import_dialog_new_for_files (GcalContext *context,
|
||||
GFile **files,
|
||||
GtkWidget* gcal_import_dialog_new_for_files (GFile **files,
|
||||
gint n_files);
|
||||
|
||||
GtkWidget* gcal_import_dialog_new_for_file_list (GcalContext *context,
|
||||
GList *file_list);
|
||||
GtkWidget* gcal_import_dialog_new_for_file_list (GList *file_list);
|
||||
|
||||
void gcal_import_dialog_add_toast (GcalImportDialog *self,
|
||||
AdwToast *toast);
|
||||
|
||||
@@ -38,8 +38,6 @@ struct _GcalImportFileRow
|
||||
GFile *file;
|
||||
GPtrArray *ical_components;
|
||||
GPtrArray *ical_timezones;
|
||||
|
||||
GcalContext *context;
|
||||
};
|
||||
|
||||
static void read_calendar_finished_cb (GObject *source_object,
|
||||
@@ -51,7 +49,6 @@ G_DEFINE_TYPE (GcalImportFileRow, gcal_import_file_row, ADW_TYPE_BIN)
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTEXT,
|
||||
PROP_FILE,
|
||||
N_PROPS,
|
||||
};
|
||||
@@ -112,6 +109,7 @@ fill_grid_with_event_data (GcalImportFileRow *self,
|
||||
GtkGrid *grid,
|
||||
ICalComponent *ical_component)
|
||||
{
|
||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||
g_autofree gchar *start_string = NULL;
|
||||
g_autofree gchar *description = NULL;
|
||||
g_autofree gchar *end_string = NULL;
|
||||
@@ -131,7 +129,7 @@ fill_grid_with_event_data (GcalImportFileRow *self,
|
||||
{
|
||||
start_local = g_date_time_to_local (start);
|
||||
|
||||
switch (gcal_context_get_time_format (self->context))
|
||||
switch (gcal_context_get_time_format (context))
|
||||
{
|
||||
case GCAL_TIME_FORMAT_24H:
|
||||
start_string = g_date_time_format (start_local, "%x %R");
|
||||
@@ -157,7 +155,7 @@ fill_grid_with_event_data (GcalImportFileRow *self,
|
||||
{
|
||||
end_local = g_date_time_to_local (end);
|
||||
|
||||
switch (gcal_context_get_time_format (self->context))
|
||||
switch (gcal_context_get_time_format (context))
|
||||
{
|
||||
case GCAL_TIME_FORMAT_24H:
|
||||
end_string = g_date_time_format (end_local, "%x %R");
|
||||
@@ -327,7 +325,6 @@ gcal_import_file_row_finalize (GObject *object)
|
||||
|
||||
g_cancellable_cancel (self->cancellable);
|
||||
g_clear_object (&self->cancellable);
|
||||
g_clear_object (&self->context);
|
||||
g_clear_object (&self->file);
|
||||
g_clear_pointer (&self->ical_components, g_ptr_array_unref);
|
||||
g_clear_pointer (&self->ical_timezones, g_ptr_array_unref);
|
||||
@@ -345,10 +342,6 @@ gcal_import_file_row_get_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_value_set_object (value, self->context);
|
||||
break;
|
||||
|
||||
case PROP_FILE:
|
||||
g_value_set_object (value, self->file);
|
||||
break;
|
||||
@@ -368,11 +361,6 @@ gcal_import_file_row_set_property (GObject *object,
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CONTEXT:
|
||||
g_assert (self->context == NULL);
|
||||
self->context = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_FILE:
|
||||
g_assert (self->file == NULL);
|
||||
self->file = g_value_dup_object (value);
|
||||
@@ -403,12 +391,6 @@ gcal_import_file_row_class_init (GcalImportFileRowClass *klass)
|
||||
1,
|
||||
G_TYPE_PTR_ARRAY);
|
||||
|
||||
properties[PROP_CONTEXT] = g_param_spec_object ("context",
|
||||
"Context",
|
||||
"Context",
|
||||
GCAL_TYPE_CONTEXT,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_FILE] = g_param_spec_object ("file",
|
||||
"An ICS file",
|
||||
"An ICS file",
|
||||
@@ -431,14 +413,12 @@ gcal_import_file_row_init (GcalImportFileRow *self)
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_import_file_row_new (GcalContext *context,
|
||||
GFile *file,
|
||||
gcal_import_file_row_new (GFile *file,
|
||||
GtkSizeGroup *title_sizegroup)
|
||||
{
|
||||
GcalImportFileRow *self;
|
||||
|
||||
self = g_object_new (GCAL_TYPE_IMPORT_FILE_ROW,
|
||||
"context", context,
|
||||
"file", file,
|
||||
NULL);
|
||||
self->title_sizegroup = title_sizegroup;
|
||||
|
||||
@@ -29,8 +29,7 @@ G_BEGIN_DECLS
|
||||
#define GCAL_TYPE_IMPORT_FILE_ROW (gcal_import_file_row_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GcalImportFileRow, gcal_import_file_row, GCAL, IMPORT_FILE_ROW, AdwBin)
|
||||
|
||||
GtkWidget* gcal_import_file_row_new (GcalContext *context,
|
||||
GFile *file,
|
||||
GtkWidget* gcal_import_file_row_new (GFile *file,
|
||||
GtkSizeGroup *title_sizegroup);
|
||||
|
||||
GPtrArray* gcal_import_file_row_get_ical_components (GcalImportFileRow *self);
|
||||
|
||||
Reference in New Issue
Block a user