Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly offer a QIcon from the component #83

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -5,7 +5,7 @@ include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
add_compiler_export_flags()

find_package(Qt5 REQUIRED COMPONENTS Core)
find_package(Qt5 REQUIRED COMPONENTS Gui)
pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.46)
include(GNUInstallDirs)

@@ -50,7 +50,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
)

add_library(AppStreamQt SHARED ${APPSTREAMQT_SRC})
target_link_libraries(AppStreamQt PUBLIC Qt5::Core
target_link_libraries(AppStreamQt PUBLIC Qt5::Gui
PRIVATE appstream
${GLIB2_LIBRARIES}
${SANITIZER_LIBS})
@@ -25,6 +25,8 @@
#include <QUrl>
#include <QMap>
#include <QMultiHash>
#include <QDebug>
#include <QIcon>
#include "chelpers.h"
#include "screenshot.h"
#include "release.h"
@@ -357,3 +359,31 @@ Bundle Component::bundle(Bundle::Kind kind) const
return nullptr;
return bundle;
}

QIcon AppStream::Component::icon() const
{
QIcon ret;
auto icons = as_component_get_icons(m_cpt);
for (int i = 0; i < icons->len; i++) {
AsIcon *icon = AS_ICON (g_ptr_array_index (icons, i));
const QSize size(as_icon_get_width(icon), as_icon_get_height(icon));

switch (as_icon_get_kind (icon)) {
case AS_ICON_KIND_LOCAL:
ret.addFile(as_icon_get_filename(icon), size);
break;
case AS_ICON_KIND_CACHED:
ret.addFile(as_icon_get_filename(icon), size);
break;
case AS_ICON_KIND_STOCK:
if (ret.isNull())
ret = QIcon::fromTheme(as_icon_get_name(icon));
break;
default:
case AS_ICON_KIND_REMOTE:
qWarning() << "Unsupported remote icons";
break;
}
}
return ret;
}
@@ -143,6 +143,11 @@ Q_GADGET
QList<AppStream::Bundle> bundles() const;
AppStream::Bundle bundle(Bundle::Kind kind) const;

/**
* \returns an icon that represents the component
*/
QIcon icon() const;

private:
_AsComponent *m_cpt;
};