[tepl] Utils: add file_query_exists_async()/finish()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] Utils: add file_query_exists_async()/finish()
- Date: Sat, 18 Apr 2020 17:19:37 +0000 (UTC)
commit 3786c76cb942f76b14a9f1245068536cd7c640d5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Apr 16 12:53:49 2020 +0200
Utils: add file_query_exists_async()/finish()
Copied from gnome-latex.
docs/reference/tepl-sections.txt | 2 ++
tepl/tepl-utils.c | 56 ++++++++++++++++++++++++++++++++++++++++
tepl/tepl-utils.h | 8 ++++++
3 files changed, 66 insertions(+)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index 9321509..ce4ccd5 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -416,6 +416,8 @@ tepl_utils_get_file_shortname
tepl_utils_replace_home_dir_with_tilde
tepl_utils_decode_uri
tepl_utils_create_parent_directories
+tepl_utils_file_query_exists_async
+tepl_utils_file_query_exists_finish
tepl_utils_show_warning_dialog
</SECTION>
diff --git a/tepl/tepl-utils.c b/tepl/tepl-utils.c
index 097c954..0aa5bfb 100644
--- a/tepl/tepl-utils.c
+++ b/tepl/tepl-utils.c
@@ -614,6 +614,62 @@ tepl_utils_create_parent_directories (GFile *file,
return TRUE;
}
+/**
+ * tepl_utils_file_query_exists_async:
+ * @file: a #GFile.
+ * @cancellable: a #GCancellable.
+ * @callback: the callback to call when the operation is finished.
+ * @user_data: the data to pass to the callback function.
+ *
+ * The asynchronous version of g_file_query_exists(). When the operation is
+ * finished, @callback will be called. You can then call
+ * tepl_utils_file_query_exists_finish() to get the result of the operation.
+ *
+ * Since: 5.0
+ */
+void
+tepl_utils_file_query_exists_async (GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_file_query_info_async (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tepl_utils_file_query_exists_finish:
+ * @file: a #GFile.
+ * @result: a #GAsyncResult.
+ *
+ * Finishes the operation started with tepl_utils_file_query_exists_async().
+ * There is no output #GError parameter, so you should check if the operation
+ * has been cancelled (in which case %FALSE will be returned).
+ *
+ * Returns: %TRUE if the file exists and the operation hasn't been cancelled,
+ * %FALSE otherwise.
+ * Since: 5.0
+ */
+gboolean
+tepl_utils_file_query_exists_finish (GFile *file,
+ GAsyncResult *result)
+{
+ GFileInfo *info = g_file_query_info_finish (file, result, NULL);
+
+ if (info != NULL)
+ {
+ g_object_unref (info);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
GtkWidget *
_tepl_utils_create_close_button (void)
{
diff --git a/tepl/tepl-utils.h b/tepl/tepl-utils.h
index 2c89f83..b43877b 100644
--- a/tepl/tepl-utils.h
+++ b/tepl/tepl-utils.h
@@ -64,6 +64,14 @@ gboolean tepl_utils_create_parent_directories (GFile *file,
GCancellable *cancellable,
GError **error);
+void tepl_utils_file_query_exists_async (GFile *file,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean tepl_utils_file_query_exists_finish (GFile *file,
+ GAsyncResult *result);
+
/* Widget utilities */
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]