summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Wilmet <swilmet@gnome.org>2016-04-29 16:33:21 +0200
committerSébastien Wilmet <swilmet@gnome.org>2016-04-30 18:21:27 +0200
commit921cf84d39c8469b38da4b201a51280b326a7f34 (patch)
tree91e5fec97841d9e25c3c97ddfa90c401ef817ee9
parent754ba2f79185cdff4079e10317b82cf085cf961c (diff)
downloadgtksourceview-921cf84d39c8469b38da4b201a51280b326a7f34.tar.gz
FileSaver: add save_metadata(), sync and async versions
-rw-r--r--docs/reference/gtksourceview-3.0-sections.txt3
-rw-r--r--gtksourceview/gtksourcefilesaver.c136
-rw-r--r--gtksourceview/gtksourcefilesaver.h19
3 files changed, 158 insertions, 0 deletions
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index be54a3c0..03fea7e1 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -329,6 +329,9 @@ gtk_source_file_saver_set_flags
gtk_source_file_saver_get_flags
gtk_source_file_saver_save_async
gtk_source_file_saver_save_finish
+gtk_source_file_saver_save_metadata
+gtk_source_file_saver_save_metadata_async
+gtk_source_file_saver_save_metadata_finish
<SUBSECTION Standard>
GTK_SOURCE_FILE_SAVER
GTK_SOURCE_FILE_SAVER_CLASS
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index cfeff1d0..247129e6 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -1487,3 +1487,139 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
return ok;
}
+
+/**
+ * gtk_source_file_saver_save_metadata:
+ * @saver: a #GtkSourceFileSaver.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
+ * @error: location to a %NULL #GError, or %NULL.
+ *
+ * Saves synchronously the metadata.
+ *
+ * Returns: whether the metadata was saved successfully.
+ * Since: 3.22
+ */
+gboolean
+gtk_source_file_saver_save_metadata (GtkSourceFileSaver *saver,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GFileInfo *metadata;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), FALSE);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (saver->priv->file == NULL ||
+ saver->priv->location == NULL)
+ {
+ return FALSE;
+ }
+
+ metadata = _gtk_source_file_get_metadata_info (saver->priv->file);
+
+ return g_file_set_attributes_from_info (saver->priv->location,
+ metadata,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable,
+ error);
+}
+
+static void
+save_metadata_async_cb (GFile *location,
+ GAsyncResult *result,
+ GTask *task)
+{
+ GError *error = NULL;
+
+ DEBUG ({
+ g_print ("%s\n", G_STRFUNC);
+ });
+
+ g_file_set_attributes_finish (location, result, NULL, &error);
+
+ if (error != NULL)
+ {
+ DEBUG ({
+ g_print ("Save metadata error: %s\n", error->message);
+ });
+
+ g_task_return_error (task, error);
+ g_object_unref (task);
+ return;
+ }
+
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
+}
+
+/**
+ * gtk_source_file_saver_save_metadata_async:
+ * @saver: a #GtkSourceFileSaver.
+ * @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
+ * %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
+ * @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is
+ * satisfied.
+ * @user_data: user data to pass to @callback.
+ *
+ * Saves asynchronously the metadata. See the #GAsyncResult documentation to
+ * know how to use this function.
+ *
+ * Since: 3.22
+ */
+void
+gtk_source_file_saver_save_metadata_async (GtkSourceFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+ GFileInfo *metadata;
+
+ g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ if (saver->priv->file == NULL ||
+ saver->priv->location == NULL)
+ {
+ return;
+ }
+
+ task = g_task_new (saver, cancellable, callback, user_data);
+
+ metadata = _gtk_source_file_get_metadata_info (saver->priv->file);
+
+ g_file_set_attributes_async (saver->priv->location,
+ metadata,
+ G_FILE_QUERY_INFO_NONE,
+ io_priority,
+ cancellable,
+ (GAsyncReadyCallback) save_metadata_async_cb,
+ task);
+}
+
+/**
+ * gtk_source_file_saver_save_metadata_finish:
+ * @saver: a #GtkSourceFileSaver.
+ * @result: a #GAsyncResult.
+ * @error: location to a %NULL #GError, or %NULL.
+ *
+ * Finishes the metadata saving started with
+ * gtk_source_file_saver_save_metadata_async().
+ *
+ * Returns: whether the metadata was saved successfully.
+ * Since: 3.22
+ */
+gboolean
+gtk_source_file_saver_save_metadata_finish (GtkSourceFileSaver *saver,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail (g_task_is_valid (result, saver), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index 3a424531..be88687a 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -161,6 +161,25 @@ gboolean gtk_source_file_saver_save_finish (GtkSourceFileSaver *saver,
GAsyncResult *result,
GError **error);
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean gtk_source_file_saver_save_metadata (GtkSourceFileSaver *saver,
+ GCancellable *cancellable,
+ GError **error);
+
+GTK_SOURCE_AVAILABLE_IN_3_22
+void gtk_source_file_saver_save_metadata_async
+ (GtkSourceFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GTK_SOURCE_AVAILABLE_IN_3_22
+gboolean gtk_source_file_saver_save_metadata_finish
+ (GtkSourceFileSaver *saver,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif /* GTK_SOURCE_FILE_SAVER_H */