Skip to content

Commit

Permalink
Merge pull request #698 from mjakeman/oscfdezdz/badge-number-on-avail…
Browse files Browse the repository at this point in the history
…able-updates

window: Show badge number when updates are available
  • Loading branch information
mjakeman authored Aug 28, 2024
2 parents 26cd389 + 4313731 commit 22fd65d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/exm-window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ template $ExmWindow : Adw.ApplicationWindow {
Adw.ViewStack view_stack {
vexpand: true;
hexpand: true;
notify::visible-child => $on_needs_attention();

Adw.ViewStackPage {
Adw.ViewStackPage installed_stack {
name: "installed";
title: C_("Navigation", "_Installed");
icon-name: "puzzle-piece-symbolic";
Expand Down
27 changes: 27 additions & 0 deletions src/exm-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct _ExmWindow
ExmDetailView *detail_view;
AdwViewSwitcher *title;
AdwViewStack *view_stack;
AdwViewStackPage *installed_stack;
AdwToastOverlay *toast_overlay;
AdwAlertDialog *remove_dialog;
AdwAlertDialog *unsupported_dialog;
Expand Down Expand Up @@ -332,6 +333,24 @@ on_error (ExmManager *manager,
gtk_widget_activate_action (GTK_WIDGET (self), "win.show-error", "s", error_text);
}

static void
on_updates_available (ExmManager *manager,
int n_updates,
ExmWindow *self)
{
adw_view_stack_page_set_badge_number (self->installed_stack, (guint) n_updates);
}

static void
on_needs_attention (AdwViewStack *view_stack,
GtkWidget *widget,
ExmWindow *self)
{
adw_view_stack_page_set_needs_attention (self->installed_stack,
EXM_IS_BROWSE_PAGE (adw_view_stack_get_visible_child (view_stack))
&& adw_view_stack_page_get_badge_number (self->installed_stack) > 0);
}

static void
exm_window_class_init (ExmWindowClass *klass)
{
Expand Down Expand Up @@ -361,10 +380,13 @@ exm_window_class_init (ExmWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExmWindow, detail_view);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, title);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, view_stack);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, installed_stack);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, toast_overlay);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, remove_dialog);
gtk_widget_class_bind_template_child (widget_class, ExmWindow, unsupported_dialog);

gtk_widget_class_bind_template_callback (widget_class, on_needs_attention);

// TODO: Refactor ExmWindow into a separate ExmController and supply the
// necessary actions/methods/etc in there. A reference to this new object can
// then be passed to each page.
Expand Down Expand Up @@ -422,6 +444,11 @@ exm_window_init (ExmWindow *self)
"shell-version",
G_BINDING_SYNC_CREATE);

g_signal_connect (self->manager,
"updates-available",
G_CALLBACK (on_updates_available),
self);

// Window must be mapped to show version check dialog
g_signal_connect (self, "map", G_CALLBACK (do_version_check), NULL);
}

0 comments on commit 22fd65d

Please sign in to comment.