Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Please keep this file sorted alphabetically.
data/io.github.kolunmi.Bazaar.desktop.in
data/io.github.kolunmi.Bazaar.metainfo.xml.in
src/bz-addon-tile.blp
src/bz-addon-tile.c
src/bz-addons-dialog.blp
src/bz-addons-dialog.c
src/bz-age-rating-dialog.blp
Expand All @@ -24,6 +26,8 @@ src/bz-comet-overlay.c
src/bz-content-provider.c
src/bz-context-tile.blp
src/bz-context-tile.c
src/bz-context-tile-callbacks.blp
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexanderVanhee This file does not exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as part of #1367.

src/bz-context-tile-callbacks.c
src/bz-curated-view.blp
src/bz-curated-view.c
src/bz-data-graph.c
Expand Down
1 change: 1 addition & 0 deletions src/bazaar.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<file>countries.gvariant</file>

<file preprocess="xml-stripblanks">bz-addon-tile.ui</file>
<file preprocess="xml-stripblanks">bz-addons-dialog.ui</file>
<file preprocess="xml-stripblanks">bz-donations-dialog.ui</file>
<file preprocess="xml-stripblanks">bz-age-rating-dialog.ui</file>
Expand Down
89 changes: 89 additions & 0 deletions src/bz-addon-tile.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Gtk 4.0;

template $BzAddonTile: $BzListTile {
accessibility {
labelled-by: title_label;
described-by: description_label;
}

child: Box {
orientation: horizontal;
spacing: 10;
height-request: 64;

Box {
orientation: vertical;
valign: center;
spacing: 4;
margin-start: 10;

Label title_label {
xalign: 0.0;
ellipsize: end;
single-line-mode: true;
has-tooltip: true;
tooltip-text: bind template.group as <$BzEntryGroup>.id;
label: bind template.group as <$BzEntryGroup>.title;
}

Label description_label {
halign: start;
label: bind template.group as <$BzEntryGroup>.description;
visible: bind eol_label.visible inverted;
xalign: 0.0;
ellipsize: end;
single-line-mode: true;
styles ["dim-label", "caption"]
}

Label eol_label{
visible: bind $invert_boolean($is_null(template.group as <$BzEntryGroup>.eol) as <bool>) as <bool>;
wrap: true;
wrap-mode: word_char;
ellipsize: end;
vexpand: true;
lines: 2;
single-line-mode: true;
halign: start;
hexpand: true;
label: _("Stopped Receiving Updates");

styles [
"warning",
]
}
}

Box {
orientation: horizontal;
spacing: 8;
margin-end: 8;
hexpand: true;
halign: end;

Button install_remove_button {
styles ["flat"]
width-request: 32;
height-request: 32;
valign: center;
has-tooltip: true;
visible: bind $invert_boolean($logical_and($is_zero(template.group as <$BzEntryGroup>.removable) as <bool>, $is_zero(template.group as <$BzEntryGroup>.installable) as <bool>) as <bool>) as <bool>;
tooltip-text: bind $get_install_remove_tooltip(template.group as <$BzEntryGroup>.removable) as <string>;
sensitive: bind $switch_bool(
template.group as <$BzEntryGroup>.removable,
$invert_boolean($is_zero(template.group as <$BzEntryGroup>.removable-and-available) as <bool>) as <bool>,
$invert_boolean($is_zero(template.group as <$BzEntryGroup>.installable-and-available) as <bool>) as <bool>,
) as <bool>;
icon-name: bind $get_install_remove_icon(template.group as <$BzEntryGroup>.removable) as <string>;
clicked => $install_remove_cb() swapped;
}

Image {
pixel-size: 14;
icon-name: "go-next-symbolic";
margin-end: 4;
styles ["dimmed"]
}
}
};
}
239 changes: 239 additions & 0 deletions src/bz-addon-tile.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/* bz-addon-tile.c
*
* Copyright 2026 Alexander Vanhee
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <glib/gi18n.h>

#include "bz-addon-tile.h"
#include "bz-entry-group.h"
#include "bz-state-info.h"
#include "bz-window.h"

struct _BzAddonTile
{
BzListTile parent_instance;

BzEntryGroup *group;

GtkButton *install_remove_button;
};

G_DEFINE_FINAL_TYPE (BzAddonTile, bz_addon_tile, BZ_TYPE_LIST_TILE)

enum
{
PROP_0,

PROP_GROUP,

LAST_PROP
};
static GParamSpec *props[LAST_PROP] = { 0 };

static void
install_remove_cb (BzAddonTile *self,
GtkButton *button)
{
int removable = 0;

if (self->group == NULL)
return;

removable = bz_entry_group_get_removable (self->group);

if (removable > 0)
gtk_widget_activate_action (GTK_WIDGET (self), "window.remove-group", "(sb)",
bz_entry_group_get_id (self->group), FALSE);
else
gtk_widget_activate_action (GTK_WIDGET (self), "window.install-group", "(sb)",
bz_entry_group_get_id (self->group), TRUE);
}

static void
bz_addon_tile_dispose (GObject *object)
{
BzAddonTile *self = BZ_ADDON_TILE (object);

g_clear_object (&self->group);

G_OBJECT_CLASS (bz_addon_tile_parent_class)->dispose (object);
}

static void
bz_addon_tile_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
BzAddonTile *self = BZ_ADDON_TILE (object);

switch (prop_id)
{
case PROP_GROUP:
g_value_set_object (value, bz_addon_tile_get_group (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}

static void
bz_addon_tile_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
BzAddonTile *self = BZ_ADDON_TILE (object);

switch (prop_id)
{
case PROP_GROUP:
bz_addon_tile_set_group (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}

static gboolean
is_zero (gpointer object,
int value)
{
return value == 0;
}

static gboolean
invert_boolean (gpointer object,
gboolean value)
{
return !value;
}

static gboolean
is_null (gpointer object,
GObject *value)
{
return value == NULL;
}

static gboolean
logical_and (gpointer object,
gboolean value1,
gboolean value2)
{
return value1 && value2;
}

static char *
get_install_remove_tooltip (gpointer object,
int removable)
{
if (removable > 0)
return g_strdup (_ ("Uninstall"));
else
return g_strdup (_ ("Install"));
}

static char *
get_install_remove_icon (gpointer object,
int removable)
{
if (removable > 0)
return g_strdup ("user-trash-symbolic");
else
return g_strdup ("document-save-symbolic");
}

static gboolean
switch_bool (gpointer object,
gboolean condition,
gboolean true_value,
gboolean false_value)
{
return condition ? true_value : false_value;
}

static void
bz_addon_tile_class_init (BzAddonTileClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

object_class->dispose = bz_addon_tile_dispose;
object_class->get_property = bz_addon_tile_get_property;
object_class->set_property = bz_addon_tile_set_property;

props[PROP_GROUP] =
g_param_spec_object (
"group",
NULL, NULL,
BZ_TYPE_ENTRY_GROUP,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

g_object_class_install_properties (object_class, LAST_PROP, props);

g_type_ensure (BZ_TYPE_LIST_TILE);
g_type_ensure (BZ_TYPE_ENTRY_GROUP);

gtk_widget_class_set_template_from_resource (widget_class, "/io/github/kolunmi/Bazaar/bz-addon-tile.ui");
gtk_widget_class_bind_template_child (widget_class, BzAddonTile, install_remove_button);
gtk_widget_class_bind_template_callback (widget_class, is_zero);
gtk_widget_class_bind_template_callback (widget_class, invert_boolean);
gtk_widget_class_bind_template_callback (widget_class, is_null);
gtk_widget_class_bind_template_callback (widget_class, logical_and);
gtk_widget_class_bind_template_callback (widget_class, get_install_remove_tooltip);
gtk_widget_class_bind_template_callback (widget_class, get_install_remove_icon);
gtk_widget_class_bind_template_callback (widget_class, switch_bool);
gtk_widget_class_bind_template_callback (widget_class, install_remove_cb);

gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
}

static void
bz_addon_tile_init (BzAddonTile *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}

GtkWidget *
bz_addon_tile_new (void)
{
return g_object_new (BZ_TYPE_ADDON_TILE, NULL);
}

void
bz_addon_tile_set_group (BzAddonTile *self,
BzEntryGroup *group)
{
g_return_if_fail (BZ_IS_ADDON_TILE (self));
g_return_if_fail (group == NULL || BZ_IS_ENTRY_GROUP (group));

g_clear_object (&self->group);
if (group != NULL)
self->group = g_object_ref (group);

g_object_notify_by_pspec (G_OBJECT (self), props[PROP_GROUP]);
}

BzEntryGroup *
bz_addon_tile_get_group (BzAddonTile *self)
{
g_return_val_if_fail (BZ_IS_ADDON_TILE (self), NULL);
return self->group;
}
42 changes: 42 additions & 0 deletions src/bz-addon-tile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* bz-addon-tile.h
*
* Copyright 2026 Alexander Vanhee
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#pragma once

#include "bz-entry-group.h"
#include "bz-list-tile.h"
#include <adwaita.h>

G_BEGIN_DECLS

#define BZ_TYPE_ADDON_TILE (bz_addon_tile_get_type ())
G_DECLARE_FINAL_TYPE (BzAddonTile, bz_addon_tile, BZ, ADDON_TILE, BzListTile)

GtkWidget *
bz_addon_tile_new (void);

void
bz_addon_tile_set_group (BzAddonTile *self,
BzEntryGroup *group);

BzEntryGroup *
bz_addon_tile_get_group (BzAddonTile *self);

G_END_DECLS
Loading
Loading