[recipes] Remove images in the file system
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Remove images in the file system
- Date: Sun, 19 Feb 2017 01:11:15 +0000 (UTC)
commit 88d07e7580b754c0007e22d9011b80a65a910766
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 18 17:36:19 2017 -0500
Remove images in the file system
But only if they are actually stored in our import location.
We don't want to accidentally remove some user data here.
src/gr-edit-page.c | 24 ++++++++++++------------
src/gr-edit-page.ui | 12 ++++++------
src/gr-image-viewer.c | 6 ++++++
src/gr-utils.c | 13 +++++++++++++
src/gr-utils.h | 1 +
5 files changed, 38 insertions(+), 18 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index f42ea98..3978e87 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -144,7 +144,7 @@ dismiss_error (GrEditPage *page)
gtk_revealer_set_reveal_child (GTK_REVEALER (page->error_revealer), FALSE);
}
-static void add_image (GrEditPage *page);
+static void add_image_cb (GrEditPage *page);
static void
populate_image_flowbox (GrEditPage *page)
@@ -174,7 +174,7 @@ populate_image_flowbox (GrEditPage *page)
gtk_container_add (GTK_CONTAINER (button), gtk_image_new_from_icon_name ("list-add-symbolic", 1));
gtk_widget_show_all (button);
gtk_container_add (GTK_CONTAINER (page->image_flowbox), button);
- g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_image), page);
+ g_signal_connect_swapped (button, "clicked", G_CALLBACK (add_image_cb), page);
}
static void
@@ -210,7 +210,7 @@ update_default_image_button (GrEditPage *page)
}
static void
-set_default_image (GrEditPage *page)
+set_default_image_cb (GrEditPage *page)
{
int index;
@@ -235,25 +235,25 @@ index_changed (GrEditPage *page)
}
static void
-add_image (GrEditPage *page)
+add_image_cb (GrEditPage *page)
{
gr_image_viewer_add_image (GR_IMAGE_VIEWER (page->images));
}
static void
-remove_image (GrEditPage *page)
+remove_image_cb (GrEditPage *page)
{
gr_image_viewer_remove_image (GR_IMAGE_VIEWER (page->images));
}
static void
-rotate_image_left (GrEditPage *page)
+rotate_image_left_cb (GrEditPage *page)
{
gr_image_viewer_rotate_image (GR_IMAGE_VIEWER (page->images), 90);
}
static void
-rotate_image_right (GrEditPage *page)
+rotate_image_right_cb (GrEditPage *page)
{
gr_image_viewer_rotate_image (GR_IMAGE_VIEWER (page->images), 270);
}
@@ -1409,10 +1409,10 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GrEditPage, cooking_view);
gtk_widget_class_bind_template_callback (widget_class, dismiss_error);
- gtk_widget_class_bind_template_callback (widget_class, add_image);
- gtk_widget_class_bind_template_callback (widget_class, remove_image);
- gtk_widget_class_bind_template_callback (widget_class, rotate_image_left);
- gtk_widget_class_bind_template_callback (widget_class, rotate_image_right);
+ gtk_widget_class_bind_template_callback (widget_class, add_image_cb);
+ gtk_widget_class_bind_template_callback (widget_class, remove_image_cb);
+ gtk_widget_class_bind_template_callback (widget_class, rotate_image_left_cb);
+ gtk_widget_class_bind_template_callback (widget_class, rotate_image_right_cb);
gtk_widget_class_bind_template_callback (widget_class, images_changed);
gtk_widget_class_bind_template_callback (widget_class, index_changed);
gtk_widget_class_bind_template_callback (widget_class, add_ingredient2);
@@ -1435,7 +1435,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_temperature);
gtk_widget_class_bind_template_callback (widget_class, image_activated);
- gtk_widget_class_bind_template_callback (widget_class, set_default_image);
+ gtk_widget_class_bind_template_callback (widget_class, set_default_image_cb);
gtk_widget_class_bind_template_callback (widget_class, edit_chef);
gtk_widget_class_bind_template_callback (widget_class, time_spin_input);
diff --git a/src/gr-edit-page.ui b/src/gr-edit-page.ui
index e630bfe..627ff68 100644
--- a/src/gr-edit-page.ui
+++ b/src/gr-edit-page.ui
@@ -88,7 +88,7 @@
<property name="visible">1</property>
<signal name="notify::images" handler="images_changed" swapped="yes"/>
<signal name="notify::index" handler="index_changed" swapped="yes"/>
- <signal name="activate" handler="add_image" swapped="yes"/>
+ <signal name="activate" handler="add_image_cb" swapped="yes"/>
<accessibility>
<relation target="add_image_button" type="controlled-by"/>
<relation target="rotate_image_left_button" type="controlled-by"/>
@@ -118,7 +118,7 @@
<class name="image-button"/>
<class name="dim-label"/>
</style>
- <signal name="clicked" handler="add_image" swapped="yes"/>
+ <signal name="clicked" handler="add_image_cb" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">1</property>
@@ -144,7 +144,7 @@
<class name="image-button"/>
<class name="dim-label"/>
</style>
- <signal name="clicked" handler="rotate_image_left" swapped="yes"/>
+ <signal name="clicked" handler="rotate_image_left_cb" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">1</property>
@@ -170,7 +170,7 @@
<class name="image-button"/>
<class name="dim-label"/>
</style>
- <signal name="clicked" handler="rotate_image_right" swapped="yes"/>
+ <signal name="clicked" handler="rotate_image_right_cb" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">1</property>
@@ -196,7 +196,7 @@
<class name="image-button"/>
<class name="dim-label"/>
</style>
- <signal name="clicked" handler="set_default_image" swapped="yes"/>
+ <signal name="clicked" handler="set_default_image_cb" swapped="yes"/>
<child>
<object class="GtkImage" id="default_image_image">
<property name="visible">1</property>
@@ -222,7 +222,7 @@
<class name="image-button"/>
<class name="dim-label"/>
</style>
- <signal name="clicked" handler="remove_image" swapped="yes"/>
+ <signal name="clicked" handler="remove_image_cb" swapped="yes"/>
<child>
<object class="GtkImage">
<property name="visible">1</property>
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index 2b7e337..f7cafe5 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -611,6 +611,12 @@ gr_image_viewer_add_image (GrImageViewer *viewer)
void
gr_image_viewer_remove_image (GrImageViewer *viewer)
{
+ GrRotatedImage *ri;
+
+ ri = &g_array_index (viewer->images, GrRotatedImage, viewer->index);
+
+ remove_image (ri->path);
+
g_array_remove_index (viewer->images, viewer->index);
if (viewer->index < viewer->images->len) {
diff --git a/src/gr-utils.c b/src/gr-utils.c
index 0bc54cd..4db7d5c 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <glib/gi18n.h>
+#include <glib/gstdio.h>
#include <gtk/gtk.h>
#ifdef GDK_WINDOWING_X11
@@ -735,3 +736,15 @@ rotate_image (const char *path,
return;
}
}
+
+void
+remove_image (const char *path)
+{
+ if (g_str_has_prefix (path, get_user_data_dir ())) {
+ g_debug ("Removing image %s", path);
+ g_remove (path);
+ }
+ else {
+ g_print ("Not removing image %s", path);
+ }
+}
diff --git a/src/gr-utils.h b/src/gr-utils.h
index dee0f8d..882b091 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -83,3 +83,4 @@ window_unexport_handle (GtkWindow *window);
char *import_image (const char *path);
void rotate_image (const char *path,
int angle);
+void remove_image (const char *path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]