Commit 5bcbe9bd authored by Debarshi Ray's avatar Debarshi Ray

application, base-item: Rework photos_base_item_save_async

The UX design expects the user to specify the sub-directory within
which the item will be saved. Plus, we can simplify things a bit by
using the BaseItem's filename, which must be present if it is
editable, instead of trying to generate one.

Therefore, we rework the API to accept the sub-directory and not the
complete path to the final image.

https://bugzilla.gnome.org/show_bug.cgi?id=759363
parent 6e669bef
......@@ -901,18 +901,11 @@ static void
photos_application_save (PhotosApplication *self)
{
PhotosApplicationPrivate *priv = self->priv;
GDateTime *now = NULL;
GError *error = NULL;
GFile *parent = NULL;
PhotosBaseItem *item;
const gchar *mime_type;
const gchar *pictures_path;
gchar *filename = NULL;
gchar *extension = NULL;
gchar *origin = NULL;
gchar *parent_path = NULL;
gchar *path = NULL;
gchar *uri = NULL;
item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->state->item_mngr));
g_return_if_fail (item != NULL);
......@@ -927,29 +920,11 @@ photos_application_save (PhotosApplication *self)
goto out;
}
now = g_date_time_new_now_local ();
origin = g_date_time_format (now, "%Y-%m-%d %H-%M-%S");
mime_type = photos_base_item_get_mime_type (item);
extension = photos_utils_get_extension_from_mime_type (mime_type);
filename = g_strdup_printf ("%s.%s", origin, extension);
path = g_build_filename (parent_path, filename, NULL);
uri = photos_utils_convert_path_to_uri (path);
g_application_hold (G_APPLICATION (self));
photos_base_item_save_async (item, uri, NULL, photos_application_save_save, self);
photos_base_item_save_async (item, parent, NULL, photos_application_save_save, self);
out:
if (now != NULL)
g_date_time_unref (now);
g_free (extension);
g_free (filename);
g_free (origin);
g_free (parent_path);
g_free (path);
g_free (uri);
g_clear_object (&parent);
}
......
......@@ -2012,7 +2012,7 @@ photos_base_item_refresh (PhotosBaseItem *self)
void
photos_base_item_save_async (PhotosBaseItem *self,
const gchar *uri,
GFile *dir,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
......@@ -2025,7 +2025,7 @@ photos_base_item_save_async (PhotosBaseItem *self,
g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
priv = self->priv;
g_return_if_fail (uri != NULL && uri[0] != '\0');
g_return_if_fail (G_IS_FILE (dir));
g_return_if_fail (priv->edit_graph != NULL);
g_return_if_fail (priv->load_graph != NULL);
g_return_if_fail (priv->processor != NULL);
......@@ -2038,7 +2038,7 @@ photos_base_item_save_async (PhotosBaseItem *self,
g_task_set_source_tag (task, photos_base_item_save_async);
g_task_set_task_data (task, g_strdup (type), g_free);
file = g_file_new_for_uri (uri);
file = g_file_get_child (dir, priv->filename);
g_file_replace_async (file,
NULL,
TRUE,
......
......@@ -218,7 +218,7 @@ gboolean photos_base_item_process_finish (PhotosBaseItem *se
void photos_base_item_refresh (PhotosBaseItem *self);
void photos_base_item_save_async (PhotosBaseItem *self,
const gchar *uri,
GFile *dir,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment