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:
Diego Iván
2024-08-05 12:09:55 -03:00
committed by Georges Basile Stavracas Neto
parent 32507534e8
commit 75ad1425e7
3 changed files with 149 additions and 81 deletions
+77 -19
View File
@@ -49,6 +49,7 @@ struct _GcalImportDialog
GtkWidget *placeholder_spinner; GtkWidget *placeholder_spinner;
AdwPreferencesPage *preferences_page; AdwPreferencesPage *preferences_page;
GtkSizeGroup *title_sizegroup; GtkSizeGroup *title_sizegroup;
AdwToastOverlay *toast_overlay;
GList *rows; GList *rows;
GcalCalendar *selected_calendar; 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); 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 static void
setup_files (GcalImportDialog *self, setup_files (GcalImportDialog *self,
GFile **files, GFile **files,
@@ -137,29 +169,29 @@ setup_files (GcalImportDialog *self,
GCAL_ENTRY; GCAL_ENTRY;
self->n_files = n_files; self->n_files = n_files;
for (i = 0; i < n_files; i++) 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; n_files++;
GtkWidget *row; add_file (self, G_FILE (iter->data), has_multiple);
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->n_files = n_files;
self->rows = g_list_prepend (self->rows, row);
gtk_widget_set_visible (self->placeholder_spinner, FALSE);
}
GCAL_EXIT; 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, placeholder_spinner);
gtk_widget_class_bind_template_child (widget_class, GcalImportDialog, preferences_page); 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, 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_calendar_combo_row_selected_item_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, on_import_button_clicked_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); 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);
}
+7
View File
@@ -23,6 +23,7 @@
#include <adwaita.h> #include <adwaita.h>
#include "gcal-context.h" #include "gcal-context.h"
#include "gcal-import-file-row.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@@ -33,4 +34,10 @@ GtkWidget* gcal_import_dialog_new_for_files (GcalContext
GFile **files, GFile **files,
gint n_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 G_END_DECLS
+4 -1
View File
@@ -4,6 +4,8 @@
<property name="title" translatable="yes">Import Files…</property> <property name="title" translatable="yes">Import Files…</property>
<property name="content-width">500</property> <property name="content-width">500</property>
<property name="content-height">500</property> <property name="content-height">500</property>
<child>
<object class="AdwToastOverlay" id="toast_overlay">
<child> <child>
<object class="AdwToolbarView"> <object class="AdwToolbarView">
<child type="top"> <child type="top">
@@ -31,7 +33,6 @@
</style> </style>
</object> </object>
</child> </child>
</object> </object>
</child> </child>
<property name="content"> <property name="content">
@@ -75,6 +76,8 @@
</property> </property>
</object> </object>
</child> </child>
</object>
</child>
<!-- Shortcuts --> <!-- Shortcuts -->
<child> <child>