Commit 8b7c1a23 authored by Adrien Plazas's avatar Adrien Plazas
Browse files

Merge branch 'compatible-device' into 'pureos-store-3-36-1'

Hide apps non-compatible with the device

See merge request !1
parents d948edcf 95de4bfa
......@@ -387,6 +387,8 @@ gs_app_kudos_to_string (guint64 kudos)
g_ptr_array_add (array, "sandboxed");
if ((kudos & GS_APP_KUDO_SANDBOXED_SECURE) > 0)
g_ptr_array_add (array, "sandboxed-secure");
if ((kudos & GS_APP_KUDO_COMPATIBLE_DEVICE) > 0)
g_ptr_array_add (array, "compatible-device");
g_ptr_array_add (array, NULL);
return g_strjoinv ("|", (gchar **) array->pdata);
}
......@@ -3793,6 +3795,8 @@ gs_app_get_kudos_percentage (GsApp *app)
percentage += 20;
if ((priv->kudos & GS_APP_KUDO_SANDBOXED_SECURE) > 0)
percentage += 20;
if ((priv->kudos & GS_APP_KUDO_COMPATIBLE_DEVICE) > 0)
percentage += 20;
/* popular apps should be at *least* 50% */
if ((priv->kudos & GS_APP_KUDO_POPULAR) > 0)
......
......@@ -43,6 +43,7 @@ struct _GsAppClass
* @GS_APP_KUDO_HI_DPI_ICON: Installs a HiDPI icon
* @GS_APP_KUDO_SANDBOXED: Application is sandboxed
* @GS_APP_KUDO_SANDBOXED_SECURE: Application is sandboxed securely
* @GS_APP_KUDO_COMPATIBLE_DEVICE: Compatible with my device
*
* Any awards given to the application.
**/
......@@ -61,6 +62,7 @@ typedef enum {
GS_APP_KUDO_HI_DPI_ICON = 1 << 14,
GS_APP_KUDO_SANDBOXED = 1 << 15,
GS_APP_KUDO_SANDBOXED_SECURE = 1 << 16,
GS_APP_KUDO_COMPATIBLE_DEVICE = 1 << 17,
/*< private >*/
GS_APP_KUDO_LAST
} GsAppKudo;
......
......@@ -398,6 +398,72 @@ gs_appstream_is_recent_release (XbNode *component)
return secs / (60 * 60 * 24) < 365;
}
static const gchar *
get_chassis_type (GCancellable *cancellable)
{
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) inner = NULL;
g_autoptr(GVariant) variant = NULL;
g_autoptr(GDBusConnection) connection = NULL;
static gboolean reentering = FALSE;
static gchar *chassis_type = NULL;
if (reentering)
return chassis_type;
reentering = TRUE;
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM,
cancellable,
&error);
if (!connection) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("system bus not available: %s", error->message);
return chassis_type;
}
variant = g_dbus_connection_call_sync (connection,
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
"org.freedesktop.DBus.Properties",
"Get",
g_variant_new ("(ss)",
"org.freedesktop.hostname1",
"Chassis"),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
cancellable,
&error);
if (!variant) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_debug ("Failed to get property '%s': %s", "Chassis", error->message);
return chassis_type;
}
g_variant_get (variant, "(v)", &inner);
chassis_type = g_ascii_strdown (g_variant_get_string (inner, NULL), -1);
return chassis_type;
}
static gboolean
gs_appstream_is_compatible_device (XbNode *component)
{
const gchar *chassis_type = get_chassis_type (NULL);
g_autofree gchar *chassis_xpath = NULL;
gboolean form_factor_set = !!xb_node_query_text (component, "custom/value[@key='Purism::form_factor']", NULL);
if (g_strcmp0 (chassis_type, "desktop") == 0 ||
g_strcmp0 (chassis_type, "laptop") == 0)
return !form_factor_set || !!xb_node_query_text (component, "custom/value[@key='Purism::form_factor'][lower-case(text())=='workstation']", NULL);
else if (g_strcmp0 (chassis_type, "handset") == 0)
return form_factor_set && !!xb_node_query_text (component, "custom/value[@key='Purism::form_factor'][lower-case(text())=='mobile']", NULL);
else
return TRUE;
}
static gboolean
gs_appstream_copy_metadata (GsApp *app, XbNode *component, GError **error)
{
......@@ -1024,6 +1090,9 @@ gs_appstream_refine_app (GsPlugin *plugin,
break;
}
}
if (gs_appstream_is_compatible_device (component))
gs_app_add_kudo (app, GS_APP_KUDO_COMPATIBLE_DEVICE);
}
/* we have an origin in the XML */
......
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
<g fill="#2e3436">
<path d="M4 1C2.338 1 1 2.338 1 4v1h2V4c0-.554.446-1 1-1h8c.554 0 1 .446 1 1v6c0 .554-.446 1-1 1H9v2h3c1.662 0 3-1.338 3-3V4c0-1.662-1.338-3-3-3zm5 13.025V16h3c1 0 1-1 1-1s-.053-.845-4-.975z"/>
<path d="M2.28 6C1.57 6 1 6.571 1 7.281v7.438C1 15.429 1.57 16 2.28 16h4.438C7.428 16 8 15.429 8 14.719V7.28C8 6.571 7.428 6 6.718 6H4zm.13 1H3c0 .554.446 1 1 1h1c.554 0 1-.446 1-1h.59c.227 0 .41.182.41.41v6.163c0 .228-.183.41-.41.41H2.41a.409.409 0 0 1-.41-.41V7.41c0-.228.182-.41.41-.41z" style="marker:none"/>
</g>
</svg>
......@@ -147,6 +147,8 @@ gs_category_page_get_apps_cb (GObject *source_object,
app = gs_app_list_index (list, i);
if (g_strcmp0 (gs_category_get_id (self->category), "addons") == 0) {
tile = make_addon_tile_for_category (app, self->subcategory);
} else if (!gs_app_has_kudo (app, GS_APP_KUDO_COMPATIBLE_DEVICE)) {
continue;
} else {
tile = gs_popular_tile_new (app);
}
......
......@@ -104,8 +104,7 @@
<property name="margin_start">24</property>
<property name="margin_end">24</property>
<property name="margin_top">36</property>
<property name="row_spacing">12</property>
<property name="column_spacing">9</property>
<property name="spacing">9</property>
<child>
<object class="GtkLabel" id="subcats_filter_label">
<property name="visible">True</property>
......@@ -116,10 +115,6 @@
<relation target="subcats_filter_button" type="label-for"/>
</accessibility>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="subcats_filter_button">
......@@ -159,10 +154,6 @@
<class name="text-button"/>
</style>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="subcats_sort_label">
......@@ -174,10 +165,6 @@
<relation target="subcats_sort_button" type="label-for"/>
</accessibility>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="subcats_sort_button">
......@@ -220,10 +207,6 @@
<class name="text-button"/>
</style>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</child>
......
......@@ -121,11 +121,13 @@ struct _GsDetailsPage
GtkWidget *spinner_remove;
GtkWidget *stack_details;
GtkWidget *grid_details_kudo;
GtkWidget *image_details_kudo_compatible_device;
GtkWidget *image_details_kudo_docs;
GtkWidget *image_details_kudo_sandboxed;
GtkWidget *image_details_kudo_integration;
GtkWidget *image_details_kudo_translated;
GtkWidget *image_details_kudo_updated;
GtkWidget *label_details_kudo_compatible_device;
GtkWidget *label_details_kudo_docs;
GtkWidget *label_details_kudo_sandboxed;
GtkWidget *label_details_kudo_integration;
......@@ -1054,8 +1056,13 @@ gs_details_page_refresh_all (GsDetailsPage *self)
gtk_label_set_label (GTK_LABEL (self->label_details_origin_value), origin);
}
/* set MyLanguage kudo */
/* set CompatibleDevice kudo */
kudos = gs_app_get_kudos (self->app);
ret = (kudos & GS_APP_KUDO_COMPATIBLE_DEVICE) > 0;
gtk_widget_set_sensitive (self->image_details_kudo_compatible_device, ret);
gs_details_page_set_sensitive (self->label_details_kudo_compatible_device, ret);
/* set MyLanguage kudo */
ret = (kudos & GS_APP_KUDO_MY_LANGUAGE) > 0;
gtk_widget_set_sensitive (self->image_details_kudo_translated, ret);
gs_details_page_set_sensitive (self->label_details_kudo_translated, ret);
......@@ -2560,11 +2567,13 @@ gs_details_page_class_init (GsDetailsPageClass *klass)
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, spinner_remove);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, stack_details);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, grid_details_kudo);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_compatible_device);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_docs);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_sandboxed);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_integration);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_translated);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, image_details_kudo_updated);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, label_details_kudo_compatible_device);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, label_details_kudo_docs);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, label_details_kudo_sandboxed);
gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, label_details_kudo_integration);
......
......@@ -465,6 +465,21 @@
<property name="row_spacing">9</property>
<property name="column_spacing">12</property>
<property name="hexpand">True</property>
<child>
<object class="GtkImage" id="image_details_kudo_compatible_device">
<property name="visible">True</property>
<property name="pixel_size">16</property>
<property name="icon_name">device-compatible-symbolic</property>
<property name="icon_size">6</property>
<style>
<class name="kudo-pill"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_details_kudo_translated">
<property name="visible">True</property>
......@@ -477,7 +492,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
......@@ -491,7 +506,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
......@@ -506,7 +521,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
......@@ -521,7 +536,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
......@@ -536,7 +551,18 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_details_kudo_compatible_device">
<property name="visible">True</property>
<property name="label" translatable="yes">Designed for your device</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
......@@ -547,7 +573,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
......@@ -558,7 +584,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
......@@ -569,7 +595,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
......@@ -580,7 +606,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
......@@ -591,7 +617,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
</object>
......
......@@ -144,7 +144,7 @@ gs_overview_page_get_popular_cb (GObject *source_object,
GsOverviewPage *self = GS_OVERVIEW_PAGE (user_data);
GsOverviewPagePrivate *priv = gs_overview_page_get_instance_private (self);
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
guint i;
guint i, j;
GsApp *app;
GtkWidget *tile;
g_autoptr(GError) error = NULL;
......@@ -173,12 +173,18 @@ gs_overview_page_get_popular_cb (GObject *source_object,
gs_container_remove_all (GTK_CONTAINER (priv->box_popular));
for (i = 0; i < gs_app_list_length (list) && i < N_TILES; i++) {
for (i = j = 0; i < gs_app_list_length (list) && j < N_TILES; i++) {
app = gs_app_list_index (list, i);
if (!gs_app_has_kudo (app, GS_APP_KUDO_COMPATIBLE_DEVICE))
continue;
tile = gs_popular_tile_new (app);
g_signal_connect (tile, "clicked",
G_CALLBACK (app_tile_clicked), self);
gtk_container_add (GTK_CONTAINER (priv->box_popular), tile);
j++;
}
gtk_widget_set_visible (priv->box_popular, TRUE);
gtk_widget_set_visible (priv->popular_heading, TRUE);
......@@ -195,7 +201,7 @@ gs_overview_page_get_recent_cb (GObject *source_object, GAsyncResult *res, gpoin
GsOverviewPage *self = GS_OVERVIEW_PAGE (user_data);
GsOverviewPagePrivate *priv = gs_overview_page_get_instance_private (self);
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
guint i;
guint i, j;
GsApp *app;
GtkWidget *tile;
g_autoptr(GError) error = NULL;
......@@ -224,12 +230,18 @@ gs_overview_page_get_recent_cb (GObject *source_object, GAsyncResult *res, gpoin
gs_container_remove_all (GTK_CONTAINER (priv->box_recent));
for (i = 0; i < gs_app_list_length (list) && i < N_TILES; i++) {
for (i = j = 0; i < gs_app_list_length (list) && j < N_TILES; i++) {
app = gs_app_list_index (list, i);
if (!gs_app_has_kudo (app, GS_APP_KUDO_COMPATIBLE_DEVICE))
continue;
tile = gs_popular_tile_new (app);
g_signal_connect (tile, "clicked",
G_CALLBACK (app_tile_clicked), self);
gtk_container_add (GTK_CONTAINER (priv->box_recent), tile);
j++;
}
gtk_widget_set_visible (priv->box_recent, TRUE);
gtk_widget_set_visible (priv->recent_heading, TRUE);
......@@ -265,7 +277,7 @@ gs_overview_page_get_category_apps_cb (GObject *source_object,
GsOverviewPage *self = load_data->self;
GsOverviewPagePrivate *priv = gs_overview_page_get_instance_private (self);
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
guint i;
guint i, j;
GsApp *app;
GtkWidget *box;
GtkWidget *button;
......@@ -331,12 +343,18 @@ gs_overview_page_get_category_apps_cb (GObject *source_object,
gtk_container_add (GTK_CONTAINER (priv->box_popular_rotating), box);
/* add all the apps */
for (i = 0; i < gs_app_list_length (list) && i < N_TILES; i++) {
for (i = j = 0; i < gs_app_list_length (list) && j < N_TILES; i++) {
app = gs_app_list_index (list, i);
if (!gs_app_has_kudo (app, GS_APP_KUDO_COMPATIBLE_DEVICE))
continue;
tile = gs_popular_tile_new (app);
g_signal_connect (tile, "clicked",
G_CALLBACK (app_tile_clicked), self);
gtk_container_add (GTK_CONTAINER (box), tile);
j++;
}
priv->empty = FALSE;
......
......@@ -39,6 +39,7 @@
<file>gtk-style-hc.css</file>
</gresource>
<gresource prefix="/sm/puri/Store/icons/hicolor/scalable/status">
<file preprocess="xml-stripblanks">device-compatible-symbolic.svg</file>
<file preprocess="xml-stripblanks">navigate-symbolic.svg</file>
</gresource>
</gresources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment