From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13042 invoked by alias); 5 Aug 2018 22:10:21 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 12958 invoked by uid 89); 5 Aug 2018 22:10:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=Actions, Hx-languages-length:5596 X-HELO: rgout03.bt.lon5.cpcloud.co.uk Received: from rgout0301.bt.lon5.cpcloud.co.uk (HELO rgout03.bt.lon5.cpcloud.co.uk) (65.20.0.207) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 05 Aug 2018 22:10:17 +0000 X-OWM-Source-IP: 86.151.121.200 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-SNCR-VADESECURE: CLEAN Received: from localhost.localdomain (86.151.121.200) by rgout03.bt.lon5.cpcloud.co.uk (9.0.019.26-1) (authenticated as jonturney@btinternet.com) id 5B4CE16C01FB5BEF; Sun, 5 Aug 2018 23:10:17 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 06/13] Add methods for listing possible actions on, and applying one to, a package Date: Sun, 05 Aug 2018 22:10:00 -0000 Message-Id: <20180805220851.270212-7-jon.turney@dronecode.org.uk> In-Reply-To: <20180805220851.270212-1-jon.turney@dronecode.org.uk> References: <20180805220851.270212-1-jon.turney@dronecode.org.uk> X-SW-Source: 2018-08/txt/msg00013.txt.bz2 The 'action id' is a value of the _actions enum, if positive, otherwise it's absolute value is a 0-based index into the 'versions' collection to identify a specific version to install. v2: Fix select_action() to consider deftrust v3: Fix select_action() for keep --- ActionList.h | 55 +++++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + PickView.h | 2 +- package_meta.cc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ package_meta.h | 5 +++- 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 ActionList.h diff --git a/ActionList.h b/ActionList.h new file mode 100644 index 0000000..2e2d424 --- /dev/null +++ b/ActionList.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 Jon Turney + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + */ + +#ifndef SETUP_ACTIONLIST_H +#define SETUP_ACTIONLIST_H + +#include +#include + +// --------------------------------------------------------------------------- +// interface to class ActionList +// +// a list of Actions possible on a package +// --------------------------------------------------------------------------- + +class Action +{ + public: + Action(const std::string &_name, int _id, bool _selected, bool _enabled) : + name(_name), + id(_id), + selected(_selected), + enabled(_enabled) + { }; + + std::string name; + int id; + bool selected; + bool enabled; +}; + +typedef std::vector Actions; + +class ActionList +{ + public: + void add(const std::string &name, int id, bool selected, bool enabled) + { + Action act(name, id, selected, enabled); + list.push_back(act); + }; + Actions list; +}; + +#endif /* SETUP_ACTIONLIST_H */ diff --git a/Makefile.am b/Makefile.am index bce4c8c..b58c9b7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -95,6 +95,7 @@ inilint_SOURCES = \ -lshlwapi -lcomctl32 -lole32 -lpsapi -luuid -lntdll -lwininet -lws2_32 -lmingw32 @SETUP@_LDFLAGS = -mwindows -Wc,-static -static-libtool-libs @SETUP@_SOURCES = \ + actionlist.h \ AntiVirus.cc \ AntiVirus.h \ archive.cc \ diff --git a/PickView.h b/PickView.h index 9777d15..fc9216e 100644 --- a/PickView.h +++ b/PickView.h @@ -152,7 +152,7 @@ public: pkg != _cat.second.end(); ++pkg) { - (*pkg)->set_action(action_id, (*pkg)->trustp(true, deftrust)); + (*pkg)->select_action(action_id, deftrust); l++; } diff --git a/package_meta.cc b/package_meta.cc index dffe3ac..f55c3f3 100644 --- a/package_meta.cc +++ b/package_meta.cc @@ -487,6 +487,75 @@ packagemeta::set_action (trusts const trust) user_picked = true; } +void +packagemeta::select_action (int id, trusts const deftrust) +{ + if (id <= 0) + { + // Install a specific version + set::iterator i = versions.begin (); + for (int j = -id; j > 0; j--) + i++; + + set_action(Install_action, *i); + } + else + { + if (id == packagemeta::Default_action) + set_action((packagemeta::_actions)id, installed); + else + set_action((packagemeta::_actions)id, trustp (true, deftrust)); + } + + /* Memorize the fact that the user picked at least once. */ + if (!installed) + user_picked = true; +} + +ActionList * +packagemeta::list_actions(trusts const trust) +{ + // first work out the current action, so we can indicate that + _actions action; + + if (!desired && installed) + action = Uninstall_action; + else if (!desired) + action = Default_action; // skip + else if (desired == installed && picked()) + action = Reinstall_action; + else if (desired == installed) + action = Default_action; // keep + else + action = Install_action; + + // now build the list of possible actions + ActionList *al = new ActionList(); + + al->add("Uninstall", (int)Uninstall_action, (action == Uninstall_action), bool(installed)); + al->add("Skip", (int)Default_action, (action == Default_action) && !installed, !installed); + + set::iterator i; + for (i = versions.begin (); i != versions.end (); ++i) + { + if (*i == installed) + { + al->add("Keep", (int)Default_action, (action == Default_action), TRUE); + al->add(packagedb::task == PackageDB_Install ? "Reinstall" : "Retrieve", + (int)Reinstall_action, (action == Reinstall_action), TRUE); + } + else + { + al->add(i->Canonical_version().c_str(), + -std::distance(versions.begin (), i), + (action == Install_action) && (*i == desired), + TRUE); + } + } + + return al; +} + // Set a particular type of action. void packagemeta::set_action (_actions action, packageversion const &default_version) diff --git a/package_meta.h b/package_meta.h index df66bda..0f01837 100644 --- a/package_meta.h +++ b/package_meta.h @@ -26,6 +26,7 @@ class packagemeta; #include "package_version.h" #include "package_message.h" #include "script.h" +#include "ActionList.h" typedef std::pair > Category; @@ -52,7 +53,7 @@ public: enum _actions { - Default_action, + Default_action = 1, Install_action, Reinstall_action, Uninstall_action, @@ -61,6 +62,8 @@ public: void set_action (trusts const t); void set_action (_actions, packageversion const & default_version); + ActionList *list_actions(trusts const trust); + void select_action (int id, trusts const deftrust); void set_message (const std::string& message_id, const std::string& message_string) { -- 2.17.0