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
1 change: 1 addition & 0 deletions src/bazaar.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<file preprocess="xml-stripblanks">icons/io.github.kolunmi.Bazaar.google.svg</file>

<file>bz-global-progress.wdgt</file>
<file>bz-install-controls.wdgt</file>

</gresource>
</gresources>
51 changes: 4 additions & 47 deletions src/bz-addons-dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -262,56 +262,13 @@ template $BzAddonsDialog: Adw.Dialog {
styles ["dimmed"]
}

Stack {
transition-type: crossfade;
$BzInstallControls {
halign: center;
margin-top: 6;
margin-bottom: 8;
visible-child-name: bind $get_install_stack_page(template.selected-group as <$BzEntryGroup>.installable, template.selected-group as <$BzEntryGroup>.removable) as <string>;

StackPage {
name: "install";
child: Button {
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;
styles ["pill", "suggested-action"]
label: _("Install");
sensitive: bind $invert_boolean($is_zero(template.selected-group as <$BzEntryGroup>.installable-and-available) as <bool>) as <bool>;
clicked => $install_cb();
};
}

StackPage {
name: "open";
child: Box {
spacing: 8;
margin-top: 6;
margin-bottom: 6;
margin-start: 6;
margin-end: 6;

Button {
styles ["pill"]
label: _("Open");
sensitive: bind $invert_boolean($is_zero(template.selected-group as <$BzEntryGroup>.removable-and-available) as <bool>) as <bool>;
clicked => $run_cb();
}

Button {
styles ["pill", "destructive-action"]
label: _("Remove");
sensitive: bind $invert_boolean($is_zero(template.selected-group as <$BzEntryGroup>.removable-and-available) as <bool>) as <bool>;
clicked => $remove_cb();
}
};
}

StackPage {
name: "empty";
child: Adw.Bin {};
}
wide: false;
entry-group: bind template.selected-group;
state: bind template.state;
}

Label {
Expand Down
71 changes: 16 additions & 55 deletions src/bz-addons-dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct _BzAddonsDialog
DexFuture *selected_ui_future;
BzResult *parent_ui_entry;
DexFuture *parent_ui_future;
BzStateInfo *state;

AdwAnimation *width_animation;
AdwAnimation *height_animation;
Expand All @@ -74,6 +75,7 @@ enum
PROP_SELECTED_GROUP,
PROP_SELECTED_UI_ENTRY,
PROP_PARENT_UI_ENTRY,
PROP_STATE,

LAST_PROP
};
Expand All @@ -87,10 +89,6 @@ static void license_cb (BzAddonsDialog *self, GtkButton *button);
static void dl_stats_cb (BzAddonsDialog *self, GtkButton *button);
static void animate_to_size (BzAddonsDialog *self);
static void on_visible_page_tag_changed (AdwNavigationView *nav_view, GParamSpec *pspec, BzAddonsDialog *self);
static char *get_install_stack_page (gpointer object, int installable, int removable);
static void install_cb (GtkButton *button, BzAddonsDialog *self);
static void remove_cb (GtkButton *button, BzAddonsDialog *self);
static void run_cb (GtkButton *button, BzAddonsDialog *self);
static DexFuture *on_parent_ui_entry_resolved (DexFuture *future, GWeakRef *wr);
static DexFuture *on_selected_ui_entry_resolved (DexFuture *future, GWeakRef *wr);
static void set_selected_group (BzAddonsDialog *self, BzEntryGroup *group);
Expand All @@ -108,6 +106,7 @@ bz_addons_dialog_dispose (GObject *object)
g_clear_object (&self->selected_group);
g_clear_object (&self->selected_ui_entry);
g_clear_object (&self->parent_ui_entry);
g_clear_object (&self->state);
g_clear_object (&self->width_animation);
g_clear_object (&self->height_animation);

Expand Down Expand Up @@ -136,6 +135,9 @@ bz_addons_dialog_get_property (GObject *object,
case PROP_PARENT_UI_ENTRY:
g_value_set_object (value, self->parent_ui_entry);
break;
case PROP_STATE:
g_value_set_object (value, bz_state_info_get_default ());
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
Expand Down Expand Up @@ -204,6 +206,13 @@ bz_addons_dialog_class_init (BzAddonsDialogClass *klass)
BZ_TYPE_RESULT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);

props[PROP_STATE] =
g_param_spec_object (
"state",
NULL, NULL,
BZ_TYPE_STATE_INFO,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);

g_object_class_install_properties (object_class, LAST_PROP, props);

g_type_ensure (BZ_TYPE_ADDON_TILE);
Expand Down Expand Up @@ -233,10 +242,6 @@ bz_addons_dialog_class_init (BzAddonsDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, format_parent_title);
gtk_widget_class_bind_template_callback (widget_class, get_description_max_height);
gtk_widget_class_bind_template_callback (widget_class, get_description_toggle_text);
gtk_widget_class_bind_template_callback (widget_class, get_install_stack_page);
gtk_widget_class_bind_template_callback (widget_class, install_cb);
gtk_widget_class_bind_template_callback (widget_class, remove_cb);
gtk_widget_class_bind_template_callback (widget_class, run_cb);

gtk_widget_class_bind_template_callback (widget_class, license_cb);
gtk_widget_class_bind_template_callback (widget_class, size_cb);
Expand Down Expand Up @@ -283,9 +288,9 @@ bz_addons_dialog_new (BzEntryGroup *group)
NULL);

if (groups == NULL || g_list_model_get_n_items (groups) == 0)
adw_navigation_view_replace (self->navigation_view,
(AdwNavigationPage *[]) { adw_navigation_view_find_page (self->navigation_view, "empty") },
1);
adw_navigation_view_replace (self->navigation_view,
(AdwNavigationPage *[]) { adw_navigation_view_find_page (self->navigation_view, "empty") },
1);
else if (g_list_model_get_n_items (groups) == 1)
{
g_autoptr (BzEntryGroup) single = g_list_model_get_item (groups, 0);
Expand Down Expand Up @@ -483,50 +488,6 @@ on_visible_page_tag_changed (AdwNavigationView *nav_view,
g_idle_add_once ((GSourceOnceFunc) animate_to_size, self);
}

static char *
get_install_stack_page (gpointer object,
int installable,
int removable)
{
if (removable > 0)
return g_strdup ("open");
else if (installable > 0)
return g_strdup ("install");
else
return g_strdup ("empty");
}

static void
install_cb (GtkButton *button,
BzAddonsDialog *self)
{
if (self->selected_group == NULL)
return;
gtk_widget_activate_action (GTK_WIDGET (self), "window.install-group", "(sb)",
bz_entry_group_get_id (self->selected_group), TRUE);
}

static void
remove_cb (GtkButton *button,
BzAddonsDialog *self)
{
if (self->selected_group == NULL)
return;
gtk_widget_activate_action (GTK_WIDGET (self), "window.remove-group", "(sb)",
bz_entry_group_get_id (self->selected_group), TRUE);
}

static void
run_cb (GtkButton *button,
BzAddonsDialog *self)
{
BzEntry *entry = NULL;
entry = bz_result_get_object (self->parent_ui_entry);

gtk_widget_activate_action (GTK_WIDGET (self), "window.launch-group", "s",
bz_entry_get_id (entry));
}

static DexFuture *
on_parent_ui_entry_resolved (DexFuture *future,
GWeakRef *wr)
Expand Down
35 changes: 19 additions & 16 deletions src/bz-install-controls.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,39 @@ using Gtk 4.0;
using Adw 1;

template $BzInstallControls: Box {
homogeneous: bind $invert_boolean(template.wide) as <bool>;
spacing: bind $choose(template.wide, 10, 8) as <int>;
hexpand: bind $invert_boolean(template.wide) as <bool>;
valign: center;

Stack {
transition-type: crossfade;
visible-child-name: bind $get_visible_page(template.entry-group as <$BzEntryGroup>.installable, template.entry-group as <$BzEntryGroup>.removable, template.state as <$BzStateInfo>.available-updates) as <string>;
visible-child-name: bind try {
$get_visible_page(template.entry-group as <$BzEntryGroup>.installable, template.entry-group as <$BzEntryGroup>.removable, template.state as <$BzStateInfo>.available-updates, template.tracker as <$BzTransactionEntryTracker>.active as <bool> ) as <string>,
$get_visible_page(template.entry-group as <$BzEntryGroup>.installable, template.entry-group as <$BzEntryGroup>.removable, template.state as <$BzStateInfo>.available-updates, false ) as <string>
};
hexpand: bind $invert_boolean(template.wide) as <bool>;
hhomogeneous: false;
valign: center;

StackPage install {
name: "install";

child: Button install_button {
styles [
"suggested-action",
"pill",
]

child: $BgeWdgtRenderer animated_button {
margin-top: 3;
margin-bottom: 3;
margin-start: 3;
margin-end: 3;

resource: "/io/github/kolunmi/Bazaar/bz-install-controls.wdgt";
reference: bind template.tracker as <$BzTransactionEntryTracker>;

state: bind try { $get_install_btn_state(
template.tracker as <$BzTransactionEntryTracker>.status as <$BzTransactionEntryStatus>,
template.tracker as <$BzTransactionEntryTracker>.active as <bool>,
template.tracker as <$BzTransactionEntryTracker>.pending as <bool>,
template.tracker as <$BzTransactionEntryTracker>.progress as <double>
) as <string>, "inactive"};

has-tooltip: true;
hexpand: bind $invert_boolean(template.wide) as <bool>;
halign: bind $choose(template.wide, 2, 0) as <int>;
sensitive: bind $invert_boolean($is_zero(template.entry-group as <$BzEntryGroup>.installable-and-available) as <bool>) as <bool>;
label: _("_Install");
use-underline: true;
clicked => $install_cb(template);
};
}

Expand All @@ -44,6 +45,7 @@ template $BzInstallControls: Box {
spacing: bind $choose(template.wide, 10, 8) as <int>;
homogeneous: bind $invert_boolean(template.wide) as <bool>;
halign: bind $choose(template.wide, 2, 0) as <int>;
valign: center;

margin-top: 3;
margin-bottom: 3;
Expand Down Expand Up @@ -102,6 +104,7 @@ template $BzInstallControls: Box {
spacing: bind $choose(template.wide, 10, 8) as <int>;
homogeneous: bind $invert_boolean(template.wide) as <bool>;
halign: bind $choose(template.wide, 2, 0) as <int>;
valign: center;

margin-top: 3;
margin-bottom: 3;
Expand Down Expand Up @@ -155,4 +158,4 @@ template $BzInstallControls: Box {
child: Adw.Bin {};
}
}
}
}
Loading
Loading