calendar-manager/new: Switch to GtkFileDialog
Cleans up a few more compiler warnings.
This commit is contained in:
@@ -26,7 +26,8 @@ struct _GcalFileChooserButton
|
|||||||
{
|
{
|
||||||
GtkButton parent_instance;
|
GtkButton parent_instance;
|
||||||
|
|
||||||
GtkFileChooser *filechooser;
|
GCancellable *cancellable;
|
||||||
|
GtkFileFilter *filter;
|
||||||
GFile *file;
|
GFile *file;
|
||||||
gchar *title;
|
gchar *title;
|
||||||
};
|
};
|
||||||
@@ -37,6 +38,7 @@ enum
|
|||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_FILE,
|
PROP_FILE,
|
||||||
|
PROP_FILTER,
|
||||||
PROP_TITLE,
|
PROP_TITLE,
|
||||||
N_PROPS
|
N_PROPS
|
||||||
};
|
};
|
||||||
@@ -63,62 +65,47 @@ update_label (GcalFileChooserButton *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_filechooser_dialog_response_cb (GtkFileChooser *filechooser,
|
on_file_opened_cb (GObject *source,
|
||||||
gint response,
|
GAsyncResult *result,
|
||||||
GcalFileChooserButton *self)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
if (response == GTK_RESPONSE_ACCEPT)
|
GcalFileChooserButton *self;
|
||||||
{
|
g_autoptr (GError) error = NULL;
|
||||||
g_autoptr(GFile) file = NULL;
|
g_autoptr (GFile) file = NULL;
|
||||||
|
|
||||||
file = gtk_file_chooser_get_file (filechooser);
|
file = gtk_file_dialog_open_finish (GTK_FILE_DIALOG (source), result, &error);
|
||||||
gcal_file_chooser_button_set_file (self, file);
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_warning ("Error opening file: %s", error->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_widget_set_visible (GTK_WIDGET (filechooser), FALSE);
|
self = GCAL_FILE_CHOOSER_BUTTON (user_data);
|
||||||
|
gcal_file_chooser_button_set_file (self, file);
|
||||||
}
|
}
|
||||||
static void
|
|
||||||
ensure_filechooser (GcalFileChooserButton *self)
|
|
||||||
{
|
|
||||||
GtkNative *native;
|
|
||||||
GtkWidget *dialog;
|
|
||||||
|
|
||||||
if (self->filechooser)
|
|
||||||
return;
|
|
||||||
|
|
||||||
native = gtk_widget_get_native (GTK_WIDGET (self));
|
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new (get_title (self),
|
|
||||||
GTK_WINDOW (native),
|
|
||||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
||||||
_("Cancel"),
|
|
||||||
GTK_RESPONSE_CANCEL,
|
|
||||||
_("Open"),
|
|
||||||
GTK_RESPONSE_ACCEPT,
|
|
||||||
NULL);
|
|
||||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
|
|
||||||
gtk_window_set_hide_on_close (GTK_WINDOW (dialog), TRUE);
|
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
||||||
|
|
||||||
if (self->file)
|
|
||||||
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (dialog), self->file, NULL);
|
|
||||||
|
|
||||||
g_signal_connect (dialog, "response", G_CALLBACK (on_filechooser_dialog_response_cb), self);
|
|
||||||
|
|
||||||
self->filechooser = GTK_FILE_CHOOSER (dialog);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gcal_file_chooser_button_clicked (GtkButton *button)
|
gcal_file_chooser_button_clicked (GtkButton *button)
|
||||||
{
|
{
|
||||||
GcalFileChooserButton *self = GCAL_FILE_CHOOSER_BUTTON (button);
|
g_autoptr (GtkFileDialog) file_dialog = NULL;
|
||||||
GtkNative *native = gtk_widget_get_native (GTK_WIDGET (self));
|
GcalFileChooserButton *self;
|
||||||
|
GtkRoot *root;
|
||||||
|
|
||||||
ensure_filechooser (self);
|
self = GCAL_FILE_CHOOSER_BUTTON (button);
|
||||||
|
root = gtk_widget_get_root (GTK_WIDGET (self));
|
||||||
|
|
||||||
gtk_window_set_transient_for (GTK_WINDOW (self->filechooser), GTK_WINDOW (native));
|
file_dialog = gtk_file_dialog_new ();
|
||||||
gtk_window_present (GTK_WINDOW (self->filechooser));
|
gtk_file_dialog_set_initial_file (file_dialog, self->file);
|
||||||
|
gtk_file_dialog_set_default_filter (file_dialog, self->filter);
|
||||||
|
|
||||||
|
gtk_file_dialog_open (file_dialog,
|
||||||
|
GTK_WINDOW (root),
|
||||||
|
self->cancellable,
|
||||||
|
on_file_opened_cb,
|
||||||
|
self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -126,7 +113,11 @@ gcal_file_chooser_button_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
GcalFileChooserButton *self = (GcalFileChooserButton *)object;
|
GcalFileChooserButton *self = (GcalFileChooserButton *)object;
|
||||||
|
|
||||||
|
g_cancellable_cancel (self->cancellable);
|
||||||
|
|
||||||
g_clear_pointer (&self->title, g_free);
|
g_clear_pointer (&self->title, g_free);
|
||||||
|
g_clear_object (&self->cancellable);
|
||||||
|
g_clear_object (&self->filter);
|
||||||
g_clear_object (&self->file);
|
g_clear_object (&self->file);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gcal_file_chooser_button_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gcal_file_chooser_button_parent_class)->finalize (object);
|
||||||
@@ -146,6 +137,10 @@ gcal_file_chooser_button_get_property (GObject *object,
|
|||||||
g_value_set_object (value, self->file);
|
g_value_set_object (value, self->file);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_FILTER:
|
||||||
|
g_value_set_object (value, self->filter);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
g_value_set_string (value, self->title);
|
g_value_set_string (value, self->title);
|
||||||
break;
|
break;
|
||||||
@@ -169,6 +164,10 @@ gcal_file_chooser_button_set_property (GObject *object,
|
|||||||
gcal_file_chooser_button_set_file (self, g_value_get_object (value));
|
gcal_file_chooser_button_set_file (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_FILTER:
|
||||||
|
gcal_file_chooser_button_set_filter (self, g_value_get_object (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
gcal_file_chooser_button_set_title (self, g_value_get_string (value));
|
gcal_file_chooser_button_set_title (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
@@ -193,6 +192,9 @@ gcal_file_chooser_button_class_init (GcalFileChooserButtonClass *klass)
|
|||||||
properties[PROP_FILE] = g_param_spec_object ("file", "", "",
|
properties[PROP_FILE] = g_param_spec_object ("file", "", "",
|
||||||
G_TYPE_FILE,
|
G_TYPE_FILE,
|
||||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||||
|
properties[PROP_FILTER] = g_param_spec_object ("filter", "", "",
|
||||||
|
GTK_TYPE_FILE_FILTER,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||||
properties[PROP_TITLE] = g_param_spec_string ("title", "", "", NULL,
|
properties[PROP_TITLE] = g_param_spec_string ("title", "", "", NULL,
|
||||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||||
@@ -201,6 +203,8 @@ gcal_file_chooser_button_class_init (GcalFileChooserButtonClass *klass)
|
|||||||
static void
|
static void
|
||||||
gcal_file_chooser_button_init (GcalFileChooserButton *self)
|
gcal_file_chooser_button_init (GcalFileChooserButton *self)
|
||||||
{
|
{
|
||||||
|
self->cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
update_label (self);
|
update_label (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,9 +222,7 @@ gcal_file_chooser_button_set_file (GcalFileChooserButton *self,
|
|||||||
|
|
||||||
if (g_set_object (&self->file, file))
|
if (g_set_object (&self->file, file))
|
||||||
{
|
{
|
||||||
gtk_file_chooser_set_file (self->filechooser, file, NULL);
|
|
||||||
update_label (self);
|
update_label (self);
|
||||||
|
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FILE]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FILE]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,12 +259,13 @@ gcal_file_chooser_button_get_title (GcalFileChooserButton *self)
|
|||||||
return self->title;
|
return self->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkFileChooser*
|
void
|
||||||
gcal_file_chooser_button_get_filechooser (GcalFileChooserButton *self)
|
gcal_file_chooser_button_set_filter (GcalFileChooserButton *self,
|
||||||
|
GtkFileFilter *filter)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GCAL_IS_FILE_CHOOSER_BUTTON (self), NULL);
|
g_return_if_fail (GCAL_IS_FILE_CHOOSER_BUTTON (self));
|
||||||
|
g_return_if_fail (filter == NULL || GTK_IS_FILE_FILTER (filter));
|
||||||
|
|
||||||
ensure_filechooser (self);
|
if (g_set_object (&self->filter, filter))
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FILTER]);
|
||||||
return self->filechooser;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ void gcal_file_chooser_button_set_title (GcalFileChoose
|
|||||||
|
|
||||||
const gchar* gcal_file_chooser_button_get_title (GcalFileChooserButton *self);
|
const gchar* gcal_file_chooser_button_get_title (GcalFileChooserButton *self);
|
||||||
|
|
||||||
GtkFileChooser* gcal_file_chooser_button_get_filechooser (GcalFileChooserButton *self);
|
void gcal_file_chooser_button_set_filter (GcalFileChooserButton *self,
|
||||||
|
GtkFileFilter *filter);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ struct _GcalNewCalendarPage
|
|||||||
GtkEntry *calendar_address_entry;
|
GtkEntry *calendar_address_entry;
|
||||||
EntryState calendar_address_entry_state;
|
EntryState calendar_address_entry_state;
|
||||||
GcalFileChooserButton *calendar_file_chooser_button;
|
GcalFileChooserButton *calendar_file_chooser_button;
|
||||||
GtkFileFilter *calendar_file_filter;
|
|
||||||
GtkWidget *cancel_button;
|
GtkWidget *cancel_button;
|
||||||
GtkWidget *credentials_cancel_button;
|
GtkWidget *credentials_cancel_button;
|
||||||
GtkWidget *credentials_connect_button;
|
GtkWidget *credentials_connect_button;
|
||||||
@@ -659,7 +658,6 @@ gcal_new_calendar_page_class_init (GcalNewCalendarPageClass *klass)
|
|||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, add_button);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, add_button);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_address_entry);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_address_entry);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_file_chooser_button);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_file_chooser_button);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, calendar_file_filter);
|
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, cancel_button);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, cancel_button);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_cancel_button);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_cancel_button);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_connect_button);
|
gtk_widget_class_bind_template_child (widget_class, GcalNewCalendarPage, credentials_connect_button);
|
||||||
@@ -686,14 +684,7 @@ gcal_new_calendar_page_class_init (GcalNewCalendarPageClass *klass)
|
|||||||
static void
|
static void
|
||||||
gcal_new_calendar_page_init (GcalNewCalendarPage *self)
|
gcal_new_calendar_page_init (GcalNewCalendarPage *self)
|
||||||
{
|
{
|
||||||
GtkFileChooser *chooser;
|
|
||||||
|
|
||||||
self->cancellable = g_cancellable_new ();
|
self->cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
|
||||||
gtk_file_filter_set_name (self->calendar_file_filter, _("Calendar files"));
|
|
||||||
|
|
||||||
chooser = gcal_file_chooser_button_get_filechooser (self->calendar_file_chooser_button);
|
|
||||||
gtk_file_chooser_add_filter (chooser, self->calendar_file_filter);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,18 @@
|
|||||||
<child>
|
<child>
|
||||||
<object class="GcalFileChooserButton" id="calendar_file_chooser_button">
|
<object class="GcalFileChooserButton" id="calendar_file_chooser_button">
|
||||||
<property name="title" translatable="yes">Open a File</property>
|
<property name="title" translatable="yes">Open a File</property>
|
||||||
|
<property name="filter">
|
||||||
|
<object class="GtkFileFilter">
|
||||||
|
<property name="name" translatable="yes">Calendar files</property>
|
||||||
|
<patterns>
|
||||||
|
<pattern>*.ical</pattern>
|
||||||
|
<pattern>*.icalendar</pattern>
|
||||||
|
<pattern>*.ics</pattern>
|
||||||
|
<pattern>*.ifb</pattern>
|
||||||
|
<pattern>*.vcs</pattern>
|
||||||
|
</patterns>
|
||||||
|
</object>
|
||||||
|
</property>
|
||||||
<signal name="notify::file" handler="on_file_chooser_button_file_changed_cb" object="GcalNewCalendarPage" swapped="no" />
|
<signal name="notify::file" handler="on_file_chooser_button_file_changed_cb" object="GcalNewCalendarPage" swapped="no" />
|
||||||
<layout>
|
<layout>
|
||||||
<property name="column">1</property>
|
<property name="column">1</property>
|
||||||
@@ -274,17 +286,6 @@
|
|||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
||||||
<!-- Calendar file filter -->
|
|
||||||
<object class="GtkFileFilter" id="calendar_file_filter">
|
|
||||||
<patterns>
|
|
||||||
<pattern>*.ical</pattern>
|
|
||||||
<pattern>*.icalendar</pattern>
|
|
||||||
<pattern>*.ics</pattern>
|
|
||||||
<pattern>*.ifb</pattern>
|
|
||||||
<pattern>*.vcs</pattern>
|
|
||||||
</patterns>
|
|
||||||
</object>
|
|
||||||
|
|
||||||
<!-- Headerbar buttons -->
|
<!-- Headerbar buttons -->
|
||||||
<object class="GtkButton" id="cancel_button">
|
<object class="GtkButton" id="cancel_button">
|
||||||
<property name="label" translatable="yes">Cancel</property>
|
<property name="label" translatable="yes">Cancel</property>
|
||||||
|
|||||||
Reference in New Issue
Block a user