From 25ef0aaeaec51224a2db0015d90e625b84bab8a1 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 21 Dec 2015 11:13:00 +0100 Subject: [PATCH] lib: Add xdg_app_installation_create_monitor This just returns a new file monitor for the .changes file. --- lib/test-lib.c | 20 ++++++++++++++++++++ lib/xdg-app-installation.c | 26 +++++++++++++++++++++++++- lib/xdg-app-installation.h | 3 +++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/test-lib.c b/lib/test-lib.c index a60d1964..83240034 100644 --- a/lib/test-lib.c +++ b/lib/test-lib.c @@ -14,6 +14,16 @@ progress_cb (const char *status, g_print ("status: %s, progress: %d estimating: %d, user_data: %p\n", status, progress, estimating, user_data); } +static gboolean +monitor_callback (GFileMonitor* monitor, + GFile* child, + GFile* other_file, + GFileMonitorEvent eflags) +{ + g_print ("Database changed\n"); + return TRUE; +} + int main (int argc, char *argv[]) { @@ -32,6 +42,16 @@ main (int argc, char *argv[]) return 1; } + if (argc == 4) + { + GFileMonitor * monitor = xdg_app_installation_create_monitor (installation, NULL, NULL); + GMainLoop *main_loop; + + g_signal_connect (monitor, "changed", (GCallback)monitor_callback, NULL); + main_loop = g_main_loop_new (NULL, FALSE); + g_main_loop_run (main_loop); + } + if (argc == 3) { app1 = xdg_app_installation_install (installation, diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c index c92856be..03fb668d 100644 --- a/lib/xdg-app-installation.c +++ b/lib/xdg-app-installation.c @@ -1050,7 +1050,7 @@ xdg_app_installation_list_remote_refs_sync (XdgAppInstallation *self, /** * xdg_app_installation_fetch_remote_ref_sync: - * @self: a #XdgAppRemove + * @self: a #XdgAppInstallation * @cancellable: (nullable): a #GCancellable * @error: return location for a #GError * @@ -1101,3 +1101,27 @@ xdg_app_installation_fetch_remote_ref_sync (XdgAppInstallation *self, "Reference %s doesn't exist in remote\n", ref); return NULL; } + +/** + * xdg_app_installation_create_monitor: + * @self: a #XdgAppInstallation + * @cancellable: (nullable): a #GCancellable + * @error: return location for a #GError + * + * Gets the current remote branch of a ref in the remote. + * + * Returns: (transfer full): a new #GFileMonitor instance, or %NULL on error + */ +GFileMonitor * +xdg_app_installation_create_monitor (XdgAppInstallation *self, + GCancellable *cancellable, + GError **error) +{ + XdgAppInstallationPrivate *priv = xdg_app_installation_get_instance_private (self); + g_autoptr(GFile) path = NULL; + + path = xdg_app_dir_get_changed_path (priv->dir); + + return g_file_monitor_file (path, G_FILE_MONITOR_NONE, + cancellable, error); +} diff --git a/lib/xdg-app-installation.h b/lib/xdg-app-installation.h index c9dfaea3..a86c06e9 100644 --- a/lib/xdg-app-installation.h +++ b/lib/xdg-app-installation.h @@ -78,6 +78,9 @@ XDG_APP_EXTERN gboolean xdg_app_installation_launch const char *commit, GCancellable *cancellable, GError **error); +XDG_APP_EXTERN GFileMonitor *xdg_app_installation_create_monitor (XdgAppInstallation *self, + GCancellable *cancellable, + GError **error); XDG_APP_EXTERN GPtrArray *xdg_app_installation_list_installed_refs (XdgAppInstallation *self, GCancellable *cancellable, GError **error);