import-dialog: Add a toast overlay
This toast overlay will be used to display error messages in import operations, namely, files that could not be imported in a drag and drop operation
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
32507534e8
commit
75ad1425e7
@@ -49,6 +49,7 @@ struct _GcalImportDialog
|
||||
GtkWidget *placeholder_spinner;
|
||||
AdwPreferencesPage *preferences_page;
|
||||
GtkSizeGroup *title_sizegroup;
|
||||
AdwToastOverlay *toast_overlay;
|
||||
|
||||
GList *rows;
|
||||
GcalCalendar *selected_calendar;
|
||||
@@ -127,6 +128,37 @@ setup_calendars (GcalImportDialog *self)
|
||||
g_signal_connect_object (manager, "notify::default-calendar", G_CALLBACK (update_default_calendar), self, G_CONNECT_SWAPPED);
|
||||
}
|
||||
|
||||
static void
|
||||
add_file (GcalImportDialog *self,
|
||||
GFile *file,
|
||||
gboolean multiple_files)
|
||||
{
|
||||
AdwPreferencesGroup *group;
|
||||
GtkWidget *row;
|
||||
g_autofree gchar *basename = NULL;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
row = gcal_import_file_row_new (self->context, 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 ());
|
||||
adw_preferences_group_add (group, row);
|
||||
|
||||
if (multiple_files)
|
||||
{
|
||||
basename = g_file_get_basename (file);
|
||||
adw_preferences_group_set_title (group, basename);
|
||||
}
|
||||
|
||||
adw_preferences_page_add (self->preferences_page, group);
|
||||
self->rows = g_list_prepend (self->rows, row);
|
||||
|
||||
gtk_widget_set_visible (self->placeholder_spinner, FALSE);
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_files (GcalImportDialog *self,
|
||||
GFile **files,
|
||||
@@ -137,30 +169,30 @@ setup_files (GcalImportDialog *self,
|
||||
GCAL_ENTRY;
|
||||
|
||||
self->n_files = n_files;
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
add_file(self, files[i], n_files > 1);
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
static void
|
||||
setup_files_list (GcalImportDialog *self,
|
||||
GList *list)
|
||||
{
|
||||
gint n_files = 0;
|
||||
gboolean has_multiple = list->next != NULL;
|
||||
|
||||
GCAL_ENTRY;
|
||||
|
||||
has_multiple = list->next != NULL;
|
||||
for (GList *iter = list; iter != NULL; iter = iter->next)
|
||||
{
|
||||
AdwPreferencesGroup *group;
|
||||
GtkWidget *row;
|
||||
|
||||
row = gcal_import_file_row_new (self->context, files[i], 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 ());
|
||||
adw_preferences_group_add (group, row);
|
||||
|
||||
if (n_files > 1)
|
||||
{
|
||||
g_autofree gchar *basename = g_file_get_basename (files[i]);
|
||||
adw_preferences_group_set_title (group, basename);
|
||||
}
|
||||
|
||||
adw_preferences_page_add (self->preferences_page, group);
|
||||
self->rows = g_list_prepend (self->rows, row);
|
||||
|
||||
gtk_widget_set_visible (self->placeholder_spinner, FALSE);
|
||||
n_files++;
|
||||
add_file (self, G_FILE (iter->data), has_multiple);
|
||||
}
|
||||
|
||||
self->n_files = n_files;
|
||||
|
||||
GCAL_EXIT;
|
||||
}
|
||||
|
||||
@@ -499,6 +531,7 @@ gcal_import_dialog_class_init (GcalImportDialogClass *klass)
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalImportDialog, placeholder_spinner);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalImportDialog, preferences_page);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalImportDialog, title_sizegroup);
|
||||
gtk_widget_class_bind_template_child (widget_class, GcalImportDialog, toast_overlay);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_calendar_combo_row_selected_item_changed_cb);
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_import_button_clicked_cb);
|
||||
@@ -527,3 +560,28 @@ gcal_import_dialog_new_for_files (GcalContext *context,
|
||||
|
||||
return GTK_WIDGET (self);
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_import_dialog_new_for_file_list (GcalContext *context,
|
||||
GList *file_list)
|
||||
{
|
||||
GcalImportDialog *self;
|
||||
|
||||
self = g_object_new (GCAL_TYPE_IMPORT_DIALOG,
|
||||
"context", context,
|
||||
NULL);
|
||||
|
||||
setup_files_list (self, file_list);
|
||||
|
||||
return GTK_WIDGET (self);
|
||||
}
|
||||
|
||||
void
|
||||
gcal_import_dialog_add_toast (GcalImportDialog *self,
|
||||
AdwToast *toast)
|
||||
{
|
||||
g_return_if_fail (GCAL_IS_IMPORT_DIALOG (self));
|
||||
g_return_if_fail (ADW_IS_TOAST (toast));
|
||||
|
||||
adw_toast_overlay_add_toast (self->toast_overlay, toast);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <adwaita.h>
|
||||
|
||||
#include "gcal-context.h"
|
||||
#include "gcal-import-file-row.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -33,4 +34,10 @@ GtkWidget* gcal_import_dialog_new_for_files (GcalContext
|
||||
GFile **files,
|
||||
gint n_files);
|
||||
|
||||
GtkWidget* gcal_import_dialog_new_for_file_list (GcalContext *context,
|
||||
GList *file_list);
|
||||
|
||||
void gcal_import_dialog_add_toast (GcalImportDialog *self,
|
||||
AdwToast *toast);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -5,74 +5,77 @@
|
||||
<property name="content-width">500</property>
|
||||
<property name="content-height">500</property>
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar" id="headerbar">
|
||||
<property name="show-end-title-buttons">False</property>
|
||||
<property name="show-start-title-buttons">False</property>
|
||||
<object class="AdwToastOverlay" id="toast_overlay">
|
||||
<child>
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar" id="headerbar">
|
||||
<property name="show-end-title-buttons">False</property>
|
||||
<property name="show-start-title-buttons">False</property>
|
||||
|
||||
<!-- Cancel button -->
|
||||
<child type="start">
|
||||
<object class="GtkButton" id="cancel_button">
|
||||
<property name="label" translatable="yes">_Cancel</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="action-name">sheet.close</property>
|
||||
<!-- Cancel button -->
|
||||
<child type="start">
|
||||
<object class="GtkButton" id="cancel_button">
|
||||
<property name="label" translatable="yes">_Cancel</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="action-name">sheet.close</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Import button -->
|
||||
<child type="end">
|
||||
<object class="GtkButton" id="import_button">
|
||||
<property name="label" translatable="yes">_Import</property>
|
||||
<property name="use-underline">True</property>
|
||||
<signal name="clicked" handler="on_import_button_clicked_cb" object="GcalImportDialog" swapped="no" />
|
||||
<style>
|
||||
<class name="suggested-action" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="AdwPreferencesPage" id="preferences_page">
|
||||
|
||||
<!-- Calendar -->
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
<object class="AdwComboRow" id="calendar_combo_row">
|
||||
<property name="activatable">True</property>
|
||||
<property name="title" translatable="yes">C_alendar</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="factory">
|
||||
<object class="GtkSignalListItemFactory">
|
||||
<signal name="bind" handler="on_combo_row_signal_factory_bind_cb" object="GcalImportDialog" swapped="no" />
|
||||
<signal name="setup" handler="on_combo_row_signal_factory_setup_cb" object="GcalImportDialog" swapped="no" />
|
||||
</object>
|
||||
</property>
|
||||
<signal name="notify::selected-item" handler="on_calendar_combo_row_selected_item_changed_cb" object="GcalImportDialog" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
<!-- Files overview -->
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup" id="files_group">
|
||||
<child>
|
||||
<object class="GtkSpinner" id="placeholder_spinner">
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spinning">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
<!-- Import button -->
|
||||
<child type="end">
|
||||
<object class="GtkButton" id="import_button">
|
||||
<property name="label" translatable="yes">_Import</property>
|
||||
<property name="use-underline">True</property>
|
||||
<signal name="clicked" handler="on_import_button_clicked_cb" object="GcalImportDialog" swapped="no" />
|
||||
<style>
|
||||
<class name="suggested-action" />
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="AdwPreferencesPage" id="preferences_page">
|
||||
|
||||
<!-- Calendar -->
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
<object class="AdwComboRow" id="calendar_combo_row">
|
||||
<property name="activatable">True</property>
|
||||
<property name="title" translatable="yes">C_alendar</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="factory">
|
||||
<object class="GtkSignalListItemFactory">
|
||||
<signal name="bind" handler="on_combo_row_signal_factory_bind_cb" object="GcalImportDialog" swapped="no" />
|
||||
<signal name="setup" handler="on_combo_row_signal_factory_setup_cb" object="GcalImportDialog" swapped="no" />
|
||||
</object>
|
||||
</property>
|
||||
<signal name="notify::selected-item" handler="on_calendar_combo_row_selected_item_changed_cb" object="GcalImportDialog" swapped="no" />
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
<!-- Files overview -->
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup" id="files_group">
|
||||
<child>
|
||||
<object class="GtkSpinner" id="placeholder_spinner">
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="spinning">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user