[libhandy] demo: Add export to file to HdyAvatar
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] demo: Add export to file to HdyAvatar
- Date: Tue, 15 Dec 2020 08:05:14 +0000 (UTC)
commit 6f9b2dee76cc9ac9ab4d85d8b4c9e7b58ce5f10f
Author: Julian Sparber <julian sparber net>
Date: Tue Oct 27 18:47:26 2020 +0100
demo: Add export to file to HdyAvatar
examples/hdy-demo-window.c | 41 ++++++++++++++++++++++
examples/hdy-demo-window.ui | 21 +++++++++++
src/handy.gresources.xml | 1 +
.../scalable/actions/avatar-save-symbolic.svg | 1 +
4 files changed, 64 insertions(+)
---
diff --git a/examples/hdy-demo-window.c b/examples/hdy-demo-window.c
index 707b5758..5ba903d8 100644
--- a/examples/hdy-demo-window.c
+++ b/examples/hdy-demo-window.c
@@ -350,6 +350,46 @@ avatar_file_set_cb (HdyDemoWindow *self)
hdy_avatar_set_image_load_func (self->avatar, (HdyAvatarImageLoadFunc) avatar_load_file, self, NULL);
}
+static void
+file_chooser_response_cb (HdyDemoWindow *self,
+ gint response_id,
+ GtkFileChooser *chooser)
+{
+ if (response_id == GTK_RESPONSE_ACCEPT) {
+ g_autofree gchar *filename = NULL;
+ g_autoptr (GdkPixbuf) pixbuf = NULL;
+
+ filename = gtk_file_chooser_get_filename (chooser);
+ pixbuf = hdy_avatar_draw_to_pixbuf (self->avatar,
+ hdy_avatar_get_size (self->avatar),
+ gtk_widget_get_scale_factor (GTK_WIDGET (self)));
+
+ if (pixbuf != NULL)
+ gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL);
+ }
+
+ g_object_unref (chooser);
+}
+
+static void
+avatar_save_to_file_cb (HdyDemoWindow *self)
+{
+ GtkFileChooserNative *chooser = NULL;
+
+ g_assert (HDY_IS_DEMO_WINDOW (self));
+
+ chooser = gtk_file_chooser_native_new (_("Save Avatar"),
+ GTK_WINDOW (self),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ _("_Save"),
+ _("_Cancel"));
+
+ gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (chooser), TRUE);
+ g_signal_connect_swapped (chooser, "response", G_CALLBACK (file_chooser_response_cb), self);
+
+ gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
+}
+
static gchar *
avatar_new_random_name (void)
{
@@ -487,6 +527,7 @@ hdy_demo_window_class_init (HdyDemoWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, carousel_return_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, avatar_file_remove_cb);
gtk_widget_class_bind_template_callback (widget_class, avatar_file_set_cb);
+ gtk_widget_class_bind_template_callback (widget_class, avatar_save_to_file_cb);
}
static void
diff --git a/examples/hdy-demo-window.ui b/examples/hdy-demo-window.ui
index 44d3e559..67ffda23 100644
--- a/examples/hdy-demo-window.ui
+++ b/examples/hdy-demo-window.ui
@@ -2015,6 +2015,27 @@
</child>
</object>
</child>
+ <child>
+ <object class="HdyActionRow">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Export to file</property>
+ <child>
+ <object class="GtkButton" id="avatar_save_file">
+ <property name="visible">True</property>
+ <property name="valign">center</property>
+ <signal name="clicked" swapped="yes"
handler="avatar_save_to_file_cb"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon_name">avatar-save-symbolic</property>
+ <property name="icon_size">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/src/handy.gresources.xml b/src/handy.gresources.xml
index b1d948ab..86182174 100644
--- a/src/handy.gresources.xml
+++ b/src/handy.gresources.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/sm/puri/handy">
+ <file preprocess="xml-stripblanks">icons/scalable/actions/avatar-save-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/hdy-expander-arrow-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/object-select-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/pan-down-symbolic.svg</file>
diff --git a/src/icons/scalable/actions/avatar-save-symbolic.svg
b/src/icons/scalable/actions/avatar-save-symbolic.svg
new file mode 100644
index 00000000..1f7bbd0d
--- /dev/null
+++ b/src/icons/scalable/actions/avatar-save-symbolic.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><g color="#000" fill="#2e3436"><path d="M7
1v7.563L5.719 7.28A1.015 1.015 0 005 7H4v1c0 .265.093.53.281.719l3 3 .282.281h.875l.28-.281 3-3A1.01 1.01 0
0012 8V7h-1c-.265 0-.53.093-.719.281L9 8.563V1z"
style="line-height:normal;-inkscape-font-specification:'Bitstream Vera
Sans';text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;marker:none"
font-weight="400" font-family="Bitstream Vera Sans" overflow="visible"/><path d="M1.994 13L2 15h12l-.006-2z"
style="marker:none" overflow="visible" fill-rule="evenodd"/></g></svg>
\ No newline at end of file
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]