libyui-qt-pkg  2.45.28
YQPkgFilters.cc
1 /**************************************************************************
2 Copyright (C) 2018 SUSE LLC
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 Textdomain "qt-pkg"
20 
21 /-*/
22 
23 #include <algorithm>
24 
25 #define YUILogComponent "qt-pkg"
26 #include "YUILog.h"
27 
28 #include <zypp/ResPool.h>
29 #include <zypp/PoolItem.h>
30 
31 #include "YQPkgFilters.h"
32 
33 
34 ZyppProduct
35 YQPkgFilters::singleProductFilter(std::function<bool(const zypp::PoolItem& item)> filter)
36 {
37  ZyppProduct product;
38 
39  auto it = zypp::ResPool::instance().byKindBegin( zypp::ResKind::product );
40  auto end = zypp::ResPool::instance().byKindEnd( zypp::ResKind::product );
41 
42  // Find the first product
43  auto product_it = std::find_if(it, end, [&](const zypp::PoolItem& item) {
44  return filter(item);
45  });
46 
47  if (product_it == end)
48  {
49  yuiMilestone() << "No product found " << std::endl;
50  return product;
51  }
52 
53  product = zypp::asKind<zypp::Product>( product_it->resolvable() );
54  yuiMilestone() << "Found product " << product->name() << std::endl;
55 
56  // Check if there is another product
57  product_it = std::find_if(++product_it, end, [&](const zypp::PoolItem& item) {
58  return filter(item);
59  });
60 
61  if (product_it == end)
62  return product;
63 
64  product = zypp::asKind<zypp::Product>( product_it->resolvable() );
65  yuiMilestone() << "Found another product " << product->name() << std::endl;
66 
67  // nullptr
68  return ZyppProduct();
69 }
static ZyppProduct singleProductFilter(std::function< bool(const zypp::PoolItem &item)> filter)
Returns the product if the filter finds a single product or null product if there are no or multiple ...
Definition: YQPkgFilters.cc:35