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,
|
GAsyncResult *result,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
|
||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
g_autofree gchar* toast_title = NULL;
|
g_autofree gchar* toast_title = NULL;
|
||||||
AdwToast *error_toast = NULL;
|
AdwToast *error_toast = NULL;
|
||||||
@@ -1075,11 +1074,9 @@ on_ics_files_filtered_cb (GObject *source_object,
|
|||||||
|
|
||||||
if (filter_result->ics_files)
|
if (filter_result->ics_files)
|
||||||
{
|
{
|
||||||
context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
|
||||||
|
|
||||||
g_clear_pointer (&self->import_dialog, gtk_widget_unparent);
|
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));
|
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);
|
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,
|
GFile **files,
|
||||||
gint n_files)
|
gint n_files)
|
||||||
{
|
{
|
||||||
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
|
||||||
g_return_if_fail (GCAL_IS_WINDOW (self));
|
g_return_if_fail (GCAL_IS_WINDOW (self));
|
||||||
|
|
||||||
g_clear_pointer (&self->import_dialog, gtk_widget_unparent);
|
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));
|
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);
|
g_object_add_weak_pointer (G_OBJECT (self->import_dialog), (gpointer *)&self->import_dialog);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ struct _GcalImportDialog
|
|||||||
GList *rows;
|
GList *rows;
|
||||||
|
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
GcalContext *context;
|
|
||||||
gint n_events;
|
gint n_events;
|
||||||
gint n_files;
|
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)
|
G_DEFINE_TYPE (GcalImportDialog, gcal_import_dialog, ADW_TYPE_DIALOG)
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
PROP_0,
|
|
||||||
PROP_CONTEXT,
|
|
||||||
N_PROPS
|
|
||||||
};
|
|
||||||
|
|
||||||
static GParamSpec *properties [N_PROPS];
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Auxiliary methods
|
* Auxiliary methods
|
||||||
@@ -98,10 +88,11 @@ import_data_free (gpointer data)
|
|||||||
static void
|
static void
|
||||||
update_default_calendar (GcalImportDialog *self)
|
update_default_calendar (GcalImportDialog *self)
|
||||||
{
|
{
|
||||||
|
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||||
GcalCalendar *default_calendar;
|
GcalCalendar *default_calendar;
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
|
|
||||||
manager = gcal_context_get_manager (self->context);
|
manager = gcal_context_get_manager (context);
|
||||||
default_calendar = gcal_manager_get_default_calendar (manager);
|
default_calendar = gcal_manager_get_default_calendar (manager);
|
||||||
|
|
||||||
if (default_calendar)
|
if (default_calendar)
|
||||||
@@ -111,12 +102,11 @@ update_default_calendar (GcalImportDialog *self)
|
|||||||
static void
|
static void
|
||||||
setup_calendars (GcalImportDialog *self)
|
setup_calendars (GcalImportDialog *self)
|
||||||
{
|
{
|
||||||
|
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||||
g_autoptr (GListModel) calendars = NULL;
|
g_autoptr (GListModel) calendars = NULL;
|
||||||
GcalManager *manager;
|
GcalManager *manager;
|
||||||
|
|
||||||
g_assert (self->context != NULL);
|
manager = gcal_context_get_manager (context);
|
||||||
|
|
||||||
manager = gcal_context_get_manager (self->context);
|
|
||||||
calendars = gcal_create_writable_calendars_model (manager);
|
calendars = gcal_create_writable_calendars_model (manager);
|
||||||
|
|
||||||
// TODO: sort model
|
// TODO: sort model
|
||||||
@@ -138,7 +128,7 @@ add_file (GcalImportDialog *self,
|
|||||||
|
|
||||||
GCAL_ENTRY;
|
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);
|
g_signal_connect (row, "file-loaded", G_CALLBACK (on_import_row_file_loaded_cb), self);
|
||||||
|
|
||||||
group = ADW_PREFERENCES_GROUP (adw_preferences_group_new ());
|
group = ADW_PREFERENCES_GROUP (adw_preferences_group_new ());
|
||||||
@@ -368,52 +358,12 @@ gcal_import_dialog_finalize (GObject *object)
|
|||||||
|
|
||||||
g_cancellable_cancel (self->cancellable);
|
g_cancellable_cancel (self->cancellable);
|
||||||
g_clear_object (&self->cancellable);
|
g_clear_object (&self->cancellable);
|
||||||
g_clear_object (&self->context);
|
|
||||||
|
|
||||||
g_clear_pointer (&self->rows, g_list_free);
|
g_clear_pointer (&self->rows, g_list_free);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gcal_import_dialog_parent_class)->finalize (object);
|
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
|
static void
|
||||||
gcal_import_dialog_class_init (GcalImportDialogClass *klass)
|
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->constructed = gcal_import_dialog_constructed;
|
||||||
object_class->finalize = gcal_import_dialog_finalize;
|
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");
|
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*
|
GtkWidget*
|
||||||
gcal_import_dialog_new_for_files (GcalContext *context,
|
gcal_import_dialog_new_for_files (GFile **files,
|
||||||
GFile **files,
|
gint n_files)
|
||||||
gint n_files)
|
|
||||||
{
|
{
|
||||||
GcalImportDialog *self;
|
GcalImportDialog *self;
|
||||||
|
|
||||||
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
||||||
"context", context,
|
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
setup_files (self, files, n_files);
|
setup_files (self, files, n_files);
|
||||||
@@ -478,13 +411,11 @@ gcal_import_dialog_new_for_files (GcalContext *context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
gcal_import_dialog_new_for_file_list (GcalContext *context,
|
gcal_import_dialog_new_for_file_list (GList *file_list)
|
||||||
GList *file_list)
|
|
||||||
{
|
{
|
||||||
GcalImportDialog *self;
|
GcalImportDialog *self;
|
||||||
|
|
||||||
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
||||||
"context", context,
|
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
setup_files_list (self, file_list);
|
setup_files_list (self, file_list);
|
||||||
|
|||||||
@@ -30,12 +30,10 @@ G_BEGIN_DECLS
|
|||||||
#define GCAL_TYPE_IMPORT_DIALOG (gcal_import_dialog_get_type())
|
#define GCAL_TYPE_IMPORT_DIALOG (gcal_import_dialog_get_type())
|
||||||
G_DECLARE_FINAL_TYPE (GcalImportDialog, gcal_import_dialog, GCAL, IMPORT_DIALOG, AdwDialog)
|
G_DECLARE_FINAL_TYPE (GcalImportDialog, gcal_import_dialog, GCAL, IMPORT_DIALOG, AdwDialog)
|
||||||
|
|
||||||
GtkWidget* gcal_import_dialog_new_for_files (GcalContext *context,
|
GtkWidget* gcal_import_dialog_new_for_files (GFile **files,
|
||||||
GFile **files,
|
|
||||||
gint n_files);
|
gint n_files);
|
||||||
|
|
||||||
GtkWidget* gcal_import_dialog_new_for_file_list (GcalContext *context,
|
GtkWidget* gcal_import_dialog_new_for_file_list (GList *file_list);
|
||||||
GList *file_list);
|
|
||||||
|
|
||||||
void gcal_import_dialog_add_toast (GcalImportDialog *self,
|
void gcal_import_dialog_add_toast (GcalImportDialog *self,
|
||||||
AdwToast *toast);
|
AdwToast *toast);
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ struct _GcalImportFileRow
|
|||||||
GFile *file;
|
GFile *file;
|
||||||
GPtrArray *ical_components;
|
GPtrArray *ical_components;
|
||||||
GPtrArray *ical_timezones;
|
GPtrArray *ical_timezones;
|
||||||
|
|
||||||
GcalContext *context;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void read_calendar_finished_cb (GObject *source_object,
|
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
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_CONTEXT,
|
|
||||||
PROP_FILE,
|
PROP_FILE,
|
||||||
N_PROPS,
|
N_PROPS,
|
||||||
};
|
};
|
||||||
@@ -112,6 +109,7 @@ fill_grid_with_event_data (GcalImportFileRow *self,
|
|||||||
GtkGrid *grid,
|
GtkGrid *grid,
|
||||||
ICalComponent *ical_component)
|
ICalComponent *ical_component)
|
||||||
{
|
{
|
||||||
|
GcalContext *context = gcal_application_get_context (GCAL_DEFAULT_APPLICATION);
|
||||||
g_autofree gchar *start_string = NULL;
|
g_autofree gchar *start_string = NULL;
|
||||||
g_autofree gchar *description = NULL;
|
g_autofree gchar *description = NULL;
|
||||||
g_autofree gchar *end_string = 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);
|
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:
|
case GCAL_TIME_FORMAT_24H:
|
||||||
start_string = g_date_time_format (start_local, "%x %R");
|
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);
|
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:
|
case GCAL_TIME_FORMAT_24H:
|
||||||
end_string = g_date_time_format (end_local, "%x %R");
|
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_cancellable_cancel (self->cancellable);
|
||||||
g_clear_object (&self->cancellable);
|
g_clear_object (&self->cancellable);
|
||||||
g_clear_object (&self->context);
|
|
||||||
g_clear_object (&self->file);
|
g_clear_object (&self->file);
|
||||||
g_clear_pointer (&self->ical_components, g_ptr_array_unref);
|
g_clear_pointer (&self->ical_components, g_ptr_array_unref);
|
||||||
g_clear_pointer (&self->ical_timezones, 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)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_CONTEXT:
|
|
||||||
g_value_set_object (value, self->context);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_FILE:
|
case PROP_FILE:
|
||||||
g_value_set_object (value, self->file);
|
g_value_set_object (value, self->file);
|
||||||
break;
|
break;
|
||||||
@@ -368,11 +361,6 @@ gcal_import_file_row_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_CONTEXT:
|
|
||||||
g_assert (self->context == NULL);
|
|
||||||
self->context = g_value_dup_object (value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PROP_FILE:
|
case PROP_FILE:
|
||||||
g_assert (self->file == NULL);
|
g_assert (self->file == NULL);
|
||||||
self->file = g_value_dup_object (value);
|
self->file = g_value_dup_object (value);
|
||||||
@@ -403,12 +391,6 @@ gcal_import_file_row_class_init (GcalImportFileRowClass *klass)
|
|||||||
1,
|
1,
|
||||||
G_TYPE_PTR_ARRAY);
|
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",
|
properties[PROP_FILE] = g_param_spec_object ("file",
|
||||||
"An ICS file",
|
"An ICS file",
|
||||||
"An ICS file",
|
"An ICS file",
|
||||||
@@ -431,14 +413,12 @@ gcal_import_file_row_init (GcalImportFileRow *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
gcal_import_file_row_new (GcalContext *context,
|
gcal_import_file_row_new (GFile *file,
|
||||||
GFile *file,
|
|
||||||
GtkSizeGroup *title_sizegroup)
|
GtkSizeGroup *title_sizegroup)
|
||||||
{
|
{
|
||||||
GcalImportFileRow *self;
|
GcalImportFileRow *self;
|
||||||
|
|
||||||
self = g_object_new (GCAL_TYPE_IMPORT_FILE_ROW,
|
self = g_object_new (GCAL_TYPE_IMPORT_FILE_ROW,
|
||||||
"context", context,
|
|
||||||
"file", file,
|
"file", file,
|
||||||
NULL);
|
NULL);
|
||||||
self->title_sizegroup = title_sizegroup;
|
self->title_sizegroup = title_sizegroup;
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ G_BEGIN_DECLS
|
|||||||
#define GCAL_TYPE_IMPORT_FILE_ROW (gcal_import_file_row_get_type())
|
#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)
|
G_DECLARE_FINAL_TYPE (GcalImportFileRow, gcal_import_file_row, GCAL, IMPORT_FILE_ROW, AdwBin)
|
||||||
|
|
||||||
GtkWidget* gcal_import_file_row_new (GcalContext *context,
|
GtkWidget* gcal_import_file_row_new (GFile *file,
|
||||||
GFile *file,
|
|
||||||
GtkSizeGroup *title_sizegroup);
|
GtkSizeGroup *title_sizegroup);
|
||||||
|
|
||||||
GPtrArray* gcal_import_file_row_get_ical_components (GcalImportFileRow *self);
|
GPtrArray* gcal_import_file_row_get_ical_components (GcalImportFileRow *self);
|
||||||
|
|||||||
Reference in New Issue
Block a user