diff --git a/app/xdg-app-builtins-add-remote.c b/app/xdg-app-builtins-add-remote.c
index 4b795f2e..01091a78 100644
--- a/app/xdg-app-builtins-add-remote.c
+++ b/app/xdg-app-builtins-add-remote.c
@@ -39,6 +39,7 @@ static gboolean opt_do_gpg_verify;
static gboolean opt_do_enumerate;
static gboolean opt_no_enumerate;
static gboolean opt_if_not_exists;
+static int opt_prio = -11;
static char *opt_title;
static char *opt_url;
static char **opt_gpg_import;
@@ -59,6 +60,7 @@ static GOptionEntry modify_options[] = {
static GOptionEntry common_options[] = {
{ "no-gpg-verify", 0, 0, G_OPTION_ARG_NONE, &opt_no_gpg_verify, "Disable GPG verification", NULL },
{ "no-enumerate", 0, 0, G_OPTION_ARG_NONE, &opt_do_enumerate, "Mark the remote as don't enumerate", NULL },
+ { "prio", 0, 0, G_OPTION_ARG_INT, &opt_prio, "Set priority (default 1, higher is more prioritized)", NULL },
{ "title", 0, 0, G_OPTION_ARG_STRING, &opt_title, "A nice name to use for this remote", "TITLE" },
{ "gpg-import", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_import, "Import GPG key from FILE (- for stdin)", "FILE" },
{ "gpg-key", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_import, "Optionally only import the named key(s) from the keyring files", "KEY" },
@@ -153,6 +155,7 @@ xdg_app_builtin_add_remote (int argc, char **argv,
g_autofree char *remote_url = NULL;
const char *remote_name;
const char *url_or_path;
+ g_autofree char *prio_as_string = NULL;
context = g_option_context_new ("NAME LOCATION - Add a remote repository");
@@ -185,6 +188,14 @@ xdg_app_builtin_add_remote (int argc, char **argv,
"xa.noenumerate",
g_variant_new_variant (g_variant_new_boolean (TRUE)));
+ if (opt_prio != -1)
+ {
+ prio_as_string = g_strdup_printf ("%d", opt_prio);
+ g_variant_builder_add (optbuilder, "{s@v}",
+ "xa.prio",
+ g_variant_new_variant (g_variant_new_string (prio_as_string)));
+ }
+
if (opt_title)
{
g_free (title);
@@ -278,6 +289,12 @@ xdg_app_builtin_modify_remote (int argc, char **argv, GCancellable *cancellable,
if (opt_do_enumerate)
g_key_file_set_boolean (config, group, "xa.noenumerate", FALSE);
+ if (opt_prio != -1)
+ {
+ g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio);
+ g_key_file_set_string (config, group, "xa.prio", prio_as_string);
+ }
+
if (!ostree_repo_write_config (xdg_app_dir_get_repo (dir), config, error))
return FALSE;
diff --git a/app/xdg-app-builtins-install.c b/app/xdg-app-builtins-install.c
index c2214dfb..e7c5bc75 100644
--- a/app/xdg-app-builtins-install.c
+++ b/app/xdg-app-builtins-install.c
@@ -465,6 +465,10 @@ xdg_app_builtin_install_bundle (int argc, char **argv, GCancellable *cancellable
"xa.noenumerate",
g_variant_new_variant (g_variant_new_boolean (TRUE)));
+ g_variant_builder_add (optbuilder, "{s@v}",
+ "xa.prio",
+ g_variant_new_variant (g_variant_new_string ("0")));
+
if (!ostree_repo_remote_add (repo,
remote, origin, g_variant_builder_end (optbuilder), cancellable, error))
goto out;
diff --git a/app/xdg-app-builtins-list-remotes.c b/app/xdg-app-builtins-list-remotes.c
index 0d1a647b..6ddf1fe5 100644
--- a/app/xdg-app-builtins-list-remotes.c
+++ b/app/xdg-app-builtins-list-remotes.c
@@ -93,6 +93,8 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
{
g_autofree char *remote_url = NULL;
g_autofree char *title = NULL;
+ int prio;
+ g_autofree char *prio_as_string = NULL;
gboolean gpg_verify = TRUE;
xdg_app_table_printer_add_column (printer, remote_name);
@@ -107,6 +109,10 @@ xdg_app_builtin_list_remotes (int argc, char **argv, GCancellable *cancellable,
xdg_app_table_printer_add_column (printer, remote_url);
+ prio = xdg_app_dir_get_remote_prio (dir, remote_name);
+ prio_as_string = g_strdup_printf ("%d", prio);
+ xdg_app_table_printer_add_column (printer, prio_as_string);
+
xdg_app_table_printer_add_column (printer, ""); /* Options */
ostree_repo_remote_get_gpg_verify (xdg_app_dir_get_repo (dir), remote_name,
diff --git a/common/xdg-app-dir.c b/common/xdg-app-dir.c
index 9f31d3f6..b3ff8ba2 100644
--- a/common/xdg-app-dir.c
+++ b/common/xdg-app-dir.c
@@ -2205,6 +2205,19 @@ xdg_app_dir_get_remote_title (XdgAppDir *self,
return NULL;
}
+int
+xdg_app_dir_get_remote_prio (XdgAppDir *self,
+ const char *remote_name)
+{
+ GKeyFile *config = ostree_repo_get_config (self->repo);
+ g_autofree char *group = get_group (remote_name);
+
+ if (config && g_key_file_has_key (config, group, "xa.prio", NULL))
+ return g_key_file_get_integer (config, group, "xa.prio", NULL);
+
+ return 1;
+}
+
gboolean
xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
const char *remote_name)
@@ -2218,6 +2231,23 @@ xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
return TRUE;
}
+gint
+cmp_remote (gconstpointer a,
+ gconstpointer b,
+ gpointer user_data)
+{
+ XdgAppDir *self = user_data;
+ const char *a_name = *(const char **)a;
+ const char *b_name = *(const char **)b;
+ int prio_a, prio_b;
+
+ prio_a = xdg_app_dir_get_remote_prio (self, a_name);
+ prio_b = xdg_app_dir_get_remote_prio (self, b_name);
+
+ return prio_b - prio_a;
+}
+
+
char **
xdg_app_dir_list_remotes (XdgAppDir *self,
GCancellable *cancellable,
@@ -2232,6 +2262,9 @@ xdg_app_dir_list_remotes (XdgAppDir *self,
if (res == NULL)
res = g_new0 (char *, 1); /* Return empty array, not error */
+ g_qsort_with_data (res, g_strv_length (res), sizeof (char *),
+ cmp_remote, self);
+
return res;
}
diff --git a/common/xdg-app-dir.h b/common/xdg-app-dir.h
index cb3465e6..0447f274 100644
--- a/common/xdg-app-dir.h
+++ b/common/xdg-app-dir.h
@@ -210,6 +210,8 @@ char **xdg_app_dir_list_remotes (XdgAppDir *self,
GError **error);
char *xdg_app_dir_get_remote_title (XdgAppDir *self,
const char *remote_name);
+int xdg_app_dir_get_remote_prio (XdgAppDir *self,
+ const char *remote_name);
gboolean xdg_app_dir_get_remote_noenumerate (XdgAppDir *self,
const char *remote_name);
gboolean xdg_app_dir_list_remote_refs (XdgAppDir *self,
diff --git a/doc/xdg-app-add-remote.xml b/doc/xdg-app-add-remote.xml
index 3d45b440..bb7559e5 100644
--- a/doc/xdg-app-add-remote.xml
+++ b/doc/xdg-app-add-remote.xml
@@ -91,6 +91,15 @@
+
+
+
+
+ Set the priority for the remote. Default is 1, higher is more prioritized. This is
+ mainly used for graphical installation tools.
+
+
+
diff --git a/doc/xdg-app-list-remotes.xml b/doc/xdg-app-list-remotes.xml
index f41db2fc..88ac32f1 100644
--- a/doc/xdg-app-list-remotes.xml
+++ b/doc/xdg-app-list-remotes.xml
@@ -39,7 +39,7 @@
Description
- Lists the known remote repositories.
+ Lists the known remote repositories, in priority order.
By default, both per-user and system-wide installations
diff --git a/doc/xdg-app-modify-remote.xml b/doc/xdg-app-modify-remote.xml
index c3dc0380..612133ec 100644
--- a/doc/xdg-app-modify-remote.xml
+++ b/doc/xdg-app-modify-remote.xml
@@ -97,6 +97,15 @@
+
+
+
+
+ Set the priority for the remote. Default is 1, higher is more prioritized. This is
+ mainly used for graphical installation tools.
+
+
+
diff --git a/lib/test-lib.c b/lib/test-lib.c
index e3686c99..a60d1964 100644
--- a/lib/test-lib.c
+++ b/lib/test-lib.c
@@ -220,8 +220,9 @@ main (int argc, char *argv[])
{
XdgAppRemote *remote = g_ptr_array_index(remotes, i);
g_autoptr(GPtrArray) refs = NULL;
- g_print ("\nRemote: %s %s %s %d %d\n",
+ g_print ("\nRemote: %s %d %s %s %d %d\n",
xdg_app_remote_get_name (remote),
+ xdg_app_remote_get_prio (remote),
xdg_app_remote_get_url (remote),
xdg_app_remote_get_title (remote),
xdg_app_remote_get_gpg_verify (remote),
diff --git a/lib/xdg-app-installation.c b/lib/xdg-app-installation.c
index 1deb89de..a4d89d19 100644
--- a/lib/xdg-app-installation.c
+++ b/lib/xdg-app-installation.c
@@ -502,7 +502,8 @@ xdg_app_installation_list_installed_refs_for_update (XdgAppInstallation *self,
* @cancellable: (nullable): a #GCancellable
* @error: return location for a #GError
*
- * Lists the remotes.
+ * Lists the remotes, in priority (highest first) order. For same priority,
+ * earlier added remote comes before a later added one.
*
* Returns: (transfer container) (element-type XdgAppRemote): an GPtrArray of
* #XdgAppRemote instances
diff --git a/lib/xdg-app-remote.c b/lib/xdg-app-remote.c
index 1ab4727f..b27dd938 100644
--- a/lib/xdg-app-remote.c
+++ b/lib/xdg-app-remote.c
@@ -158,6 +158,14 @@ xdg_app_remote_get_noenumerate (XdgAppRemote *self)
return xdg_app_dir_get_remote_noenumerate (priv->dir, priv->name);
}
+int
+xdg_app_remote_get_prio (XdgAppRemote *self)
+{
+ XdgAppRemotePrivate *priv = xdg_app_remote_get_instance_private (self);
+
+ return xdg_app_dir_get_remote_prio (priv->dir, priv->name);
+}
+
gboolean
xdg_app_remote_get_gpg_verify (XdgAppRemote *self)
{
diff --git a/lib/xdg-app-remote.h b/lib/xdg-app-remote.h
index f8be547f..2e86633e 100644
--- a/lib/xdg-app-remote.h
+++ b/lib/xdg-app-remote.h
@@ -53,5 +53,6 @@ XDG_APP_EXTERN char * xdg_app_remote_get_url (XdgAppRemote *self);
XDG_APP_EXTERN char * xdg_app_remote_get_title (XdgAppRemote *self);
XDG_APP_EXTERN gboolean xdg_app_remote_get_gpg_verify (XdgAppRemote *self);
XDG_APP_EXTERN gboolean xdg_app_remote_get_noenumerate (XdgAppRemote *self);
+XDG_APP_EXTERN int xdg_app_remote_get_prio (XdgAppRemote *self);
#endif /* __XDG_APP_REMOTE_H__ */