From eaa0c02f8db46a18d1b7928ff00296d0a24d4417 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 19 Aug 2019 07:10:38 -0400 Subject: [PATCH] [packagechooser] Initial support for appstream items - Use *appstream* as key in one of the items for the package- chooser to load data from the AppStream cache in the system. - Usable for some applications; for DE-selection not so much. - Currently unimplemented. --- src/modules/packagechooser/CMakeLists.txt | 1 + src/modules/packagechooser/ItemAppStream.cpp | 33 +++++++++++++++++++ .../packagechooser/PackageChooserViewStep.cpp | 4 +++ src/modules/packagechooser/PackageModel.cpp | 9 +++++ src/modules/packagechooser/PackageModel.h | 14 ++++++++ .../packagechooser/packagechooser.conf | 18 +++++++--- 6 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 src/modules/packagechooser/ItemAppStream.cpp diff --git a/src/modules/packagechooser/CMakeLists.txt b/src/modules/packagechooser/CMakeLists.txt index e93a5816f..eb84c9bab 100644 --- a/src/modules/packagechooser/CMakeLists.txt +++ b/src/modules/packagechooser/CMakeLists.txt @@ -23,6 +23,7 @@ set_package_properties( if ( AppStreamQt_FOUND ) add_definitions( -DHAVE_APPSTREAM ) list( APPEND _extra_libraries AppStreamQt ) + list( APPEND _extra_src ItemAppStream.cpp ) endif() calamares_add_plugin( packagechooser diff --git a/src/modules/packagechooser/ItemAppStream.cpp b/src/modules/packagechooser/ItemAppStream.cpp new file mode 100644 index 000000000..287e5a139 --- /dev/null +++ b/src/modules/packagechooser/ItemAppStream.cpp @@ -0,0 +1,33 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * Calamares 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 3 of the License, or + * (at your option) any later version. + * + * Calamares 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +/** @brief Loading items from AppData XML files. + * + * Only used if QtXML is found, implements PackageItem::fromAppData(). + */ +#include "PackageModel.h" + +#include "utils/Logger.h" +#include "utils/Variant.h" + +PackageItem +PackageItem::fromAppStream( const QVariantMap& map ) +{ + cWarning() << "AppStream loading not implemented."; + return PackageItem(); +} diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index c2e849d5f..412658394 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -219,6 +219,10 @@ PackageChooserViewStep::fillModel( const QVariantList& items ) { m_model->addPackage( PackageItem::fromAppData( item_map ) ); } + else if ( item_map.contains( "appstream" ) ) + { + m_model->addPackage( PackageItem::fromAppStream( item_map ) ); + } else { m_model->addPackage( PackageItem( item_map ) ); diff --git a/src/modules/packagechooser/PackageModel.cpp b/src/modules/packagechooser/PackageModel.cpp index e15559552..bc80109f3 100644 --- a/src/modules/packagechooser/PackageModel.cpp +++ b/src/modules/packagechooser/PackageModel.cpp @@ -98,6 +98,15 @@ PackageItem::fromAppData( const QVariantMap& item_map ) } #endif +#ifndef HAVE_APPSTREAM +PackageItem +PackageItem::fromAppStream( const QVariantMap& item_map ) +{ + cWarning() << "Loading AppStream data is not supported."; + return PackageItem(); +} +#endif + PackageListModel::PackageListModel( QObject* parent ) : QAbstractListModel( parent ) diff --git a/src/modules/packagechooser/PackageModel.h b/src/modules/packagechooser/PackageModel.h index 869e124f0..49b4bc0dd 100644 --- a/src/modules/packagechooser/PackageModel.h +++ b/src/modules/packagechooser/PackageModel.h @@ -93,6 +93,20 @@ struct PackageItem * return invalid PackageItems. */ static PackageItem fromAppData( const QVariantMap& map ); + + /** @brief Loads an item from AppStream data. + * + * The @p map must have a key *appstream*. That is used as the + * primary source of information from the AppStream cache, but + * keys *id* and *screenshotPath* may be used to override parts + * of the AppStream data -- so that the ID is under the control + * of Calamares, and the screenshot can be forced to a local path + * available on the installation medium. + * + * Requires AppStreamQt, if not present will return invalid + * PackageItems. + */ + static PackageItem fromAppStream( const QVariantMap& map ); }; using PackageList = QVector< PackageItem >; diff --git a/src/modules/packagechooser/packagechooser.conf b/src/modules/packagechooser/packagechooser.conf index e9b2d9329..eebe4dfb4 100644 --- a/src/modules/packagechooser/packagechooser.conf +++ b/src/modules/packagechooser/packagechooser.conf @@ -20,14 +20,15 @@ # or one-or-more). mode: required -# Items to display in the chooser. In general, this should be a +# Items to display in the chooser. In general, this should be a # pretty short list to avoid overwhelming the UI. This is a list # of objects, and the items are displayed in list order. # # Either provide the data for an item in the list (using the keys -# below), or use existing AppData XML files as a source for the data. +# below), or use existing AppData XML files, or use AppStream cache +# as a source for the data. # -# For data provided by the list: the item has an id, which is used in +# For data provided by the list: the item has an id, which is used in # setting the value of *packagechooser_*). The following fields # are mandatory: # @@ -60,6 +61,14 @@ mode: required # be loaded and the screenshot will be missing. An item with *appdata* # **may** specify an ID or screenshot path, as above. This will override # the settings from AppData. +# +# For data provided by AppStream cache: the item has an *appstream* +# key which matches the AppStream identifier in the cache (e.g. +# *org.kde.kwrite.desktop*). Data is retrieved from the AppStream +# cache for that ID. The package name is set from the AppStream data. +# +# An item for AppStream may also contain an *id* and a *screenshot* +# key which will override the data from AppStream. items: - id: "" package: "" @@ -81,4 +90,5 @@ items: - id: calamares appdata: ../io.calamares.calamares.appdata.xml screenshot: ":/images/calamares.png" - + - id: kate + appstream: org.kde.kwrite.desktop