[gnome-control-center] cc-avatar-chooser.c: Enable remote file selection
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] cc-avatar-chooser.c: Enable remote file selection
- Date: Fri, 7 May 2021 03:41:10 +0000 (UTC)
commit df8eb92efc15b9977765ac7c50b3858827e058cc
Author: Nishal Kulkarni <kulknishu gmail com>
Date: Tue Mar 30 07:05:59 2021 +0530
cc-avatar-chooser.c: Enable remote file selection
Currently user can choose avatar only from local files.
This prevents users from loading a file at a remote location.
Changes made include:
1. Setting local-only property to false in `cc_avatar_chooser_select_file`
2. Getting file uri and creating a GFile from it.
3. Reading the GFile into an input stream.
4. Loading image from this stream.
Closes: #813
panels/user-accounts/cc-avatar-chooser.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/panels/user-accounts/cc-avatar-chooser.c b/panels/user-accounts/cc-avatar-chooser.c
index 1c96854b3..aedc5f7d5 100644
--- a/panels/user-accounts/cc-avatar-chooser.c
+++ b/panels/user-accounts/cc-avatar-chooser.c
@@ -134,21 +134,26 @@ file_chooser_response (CcAvatarChooser *self,
gint response,
GtkDialog *chooser)
{
- g_autofree gchar *filename = NULL;
+ g_autofree gchar *fileuri = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_autoptr(GdkPixbuf) pixbuf2 = NULL;
+ g_autoptr(GFile) file = NULL;
+ g_autoptr(GFileInputStream) stream = NULL;
if (response != GTK_RESPONSE_ACCEPT) {
gtk_widget_destroy (GTK_WIDGET (chooser));
return;
}
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
+ fileuri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
+ file = g_file_new_for_uri (fileuri);
- pixbuf = gdk_pixbuf_new_from_file (filename, &error);
+ stream = g_file_read (file, NULL, &error);
+ pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream),
+ NULL, &error);
if (pixbuf == NULL) {
- g_warning ("Failed to load %s: %s", filename, error->message);
+ g_warning ("Failed to load %s: %s", fileuri, error->message);
}
pixbuf2 = gdk_pixbuf_apply_embedded_orientation (pixbuf);
@@ -230,6 +235,7 @@ cc_avatar_chooser_select_file (CcAvatarChooser *self)
gtk_widget_set_size_request (preview, 128, -1);
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (chooser), preview);
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (chooser), FALSE);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
gtk_widget_show (preview);
/* Preview has to be generated after default handler of "selection-changed"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]