From b070b3ccd740c1ed495661dbc8df439921c29f63 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 10 Jan 2019 18:37:31 -0500 Subject: [PATCH] Add FlatpakQuietTransaction This is FlatpakTransaction subclass that doesn't ask questions only talks the bare minimum. Closes: #2556 Approved by: alexlarsson --- app/Makefile.am.inc | 2 + app/flatpak-quiet-transaction.c | 132 ++++++++++++++++++++++++++++++++ app/flatpak-quiet-transaction.h | 33 ++++++++ 3 files changed, 167 insertions(+) create mode 100644 app/flatpak-quiet-transaction.c create mode 100644 app/flatpak-quiet-transaction.h diff --git a/app/Makefile.am.inc b/app/Makefile.am.inc index f104f238..7c9b4f30 100644 --- a/app/Makefile.am.inc +++ b/app/Makefile.am.inc @@ -77,6 +77,8 @@ flatpak_SOURCES = \ app/flatpak-complete.h \ app/flatpak-cli-transaction.c \ app/flatpak-cli-transaction.h \ + app/flatpak-quiet-transaction.c \ + app/flatpak-quiet-transaction.h \ app/parse-datetime.h \ $(polkit_sources) \ $(NULL) diff --git a/app/flatpak-quiet-transaction.c b/app/flatpak-quiet-transaction.c new file mode 100644 index 00000000..40fd58b3 --- /dev/null +++ b/app/flatpak-quiet-transaction.c @@ -0,0 +1,132 @@ +/* + * Copyright © 2019 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: + * Matthias Clasen + */ + +#include "config.h" + +#include "flatpak-quiet-transaction.h" +#include "flatpak-transaction-private.h" +#include "flatpak-installation-private.h" +#include "flatpak-run-private.h" +#include "flatpak-table-printer.h" +#include "flatpak-utils-private.h" +#include "flatpak-error.h" +#include + + +struct _FlatpakQuietTransaction +{ + FlatpakTransaction parent; +}; + +struct _FlatpakQuietTransactionClass +{ + FlatpakTransactionClass parent_class; +}; + +G_DEFINE_TYPE (FlatpakQuietTransaction, flatpak_quiet_transaction, FLATPAK_TYPE_TRANSACTION); + +static int +choose_remote_for_ref (FlatpakTransaction *transaction, + const char *for_ref, + const char *runtime_ref, + const char * const *remotes) +{ + return 0; +} + +static gboolean +add_new_remote (FlatpakTransaction *transaction, + FlatpakTransactionRemoteReason reason, + const char *from_id, + const char *remote_name, + const char *url) +{ + return TRUE; +} + +static void +new_operation (FlatpakTransaction *transaction, + FlatpakTransactionOperation *op, + FlatpakTransactionProgress *progress) +{ + FlatpakTransactionOperationType op_type = flatpak_transaction_operation_get_operation_type (op); + const char *ref = flatpak_transaction_operation_get_ref (op); + + switch (op_type) + { + case FLATPAK_TRANSACTION_OPERATION_INSTALL_BUNDLE: + case FLATPAK_TRANSACTION_OPERATION_INSTALL: + g_print (_("Installing %s\n"), ref); + break; + + case FLATPAK_TRANSACTION_OPERATION_UPDATE: + g_print (_("Updating %s\n"), ref); + break; + + case FLATPAK_TRANSACTION_OPERATION_UNINSTALL: + g_print (_("Uninstalling %s\n"), ref); + break; + + default: + g_assert_not_reached (); + break; + } +} + +static void +flatpak_quiet_transaction_init (FlatpakQuietTransaction *transaction) +{ +} + +static void +flatpak_quiet_transaction_class_init (FlatpakQuietTransactionClass *class) +{ + FlatpakTransactionClass *transaction_class = FLATPAK_TRANSACTION_CLASS (class); + + transaction_class->choose_remote_for_ref = choose_remote_for_ref; + transaction_class->add_new_remote = add_new_remote; + transaction_class->new_operation = new_operation; +} + +FlatpakTransaction * +flatpak_quiet_transaction_new (FlatpakDir *dir, + GError **error) +{ + g_autoptr(FlatpakQuietTransaction) self = NULL; + g_autoptr(FlatpakInstallation) installation = NULL; + + installation = flatpak_installation_new_for_dir (dir, NULL, error); + if (installation == NULL) + return NULL; + + flatpak_installation_set_no_interaction (installation, TRUE); + + self = g_initable_new (FLATPAK_TYPE_QUIET_TRANSACTION, + NULL, error, + "installation", installation, + NULL); + + if (self == NULL) + return NULL; + + flatpak_transaction_add_default_dependency_sources (FLATPAK_TRANSACTION (self)); + + return FLATPAK_TRANSACTION (g_steal_pointer (&self)); +} diff --git a/app/flatpak-quiet-transaction.h b/app/flatpak-quiet-transaction.h new file mode 100644 index 00000000..fe2136ee --- /dev/null +++ b/app/flatpak-quiet-transaction.h @@ -0,0 +1,33 @@ +/* + * Copyright © 2019 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: + * Matthias Clasen + */ + +#ifndef __FLATPAK_QUIET_TRANSACTION_H__ +#define __FLATPAK_QUIET_TRANSACTION_H__ + +#include "flatpak-transaction.h" +#include "flatpak-dir-private.h" + +#define FLATPAK_TYPE_QUIET_TRANSACTION flatpak_quiet_transaction_get_type () +G_DECLARE_FINAL_TYPE (FlatpakQuietTransaction, flatpak_quiet_transaction, FLATPAK, QUIET_TRANSACTION, FlatpakTransaction) + +FlatpakTransaction * flatpak_quiet_transaction_new (FlatpakDir *dir, + GError **error); + +#endif /* __FLATPAK_QUIET_TRANSACTION_H__ */