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

detail-view: Add info bar #492

Merged
merged 1 commit into from
Nov 16, 2023
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
2 changes: 2 additions & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ src/exm-error-dialog.blp
src/exm-error-dialog.c
src/exm-extension-row.blp
src/exm-extension-row.c
src/exm-info-bar.blp
src/exm-info-bar.c
src/exm-install-button.c
src/exm-installed-page.blp
src/exm-installed-page.c
Expand Down
18 changes: 2 additions & 16 deletions src/exm-detail-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ template $ExmDetailView : Adw.NavigationPage {
}
}

$ExmInfoBar ext_info_bar {}

Gtk.Box {
orientation: vertical;

Expand Down Expand Up @@ -208,22 +210,6 @@ template $ExmDetailView : Adw.NavigationPage {
}
}

Gtk.Box {
orientation: vertical;

Gtk.Label {
styles ["title-4", "detail-heading"]

label: _("Supported Versions");
xalign: 0;
}

Gtk.FlowBox supported_versions {
max-children-per-line: 100;
selection-mode: none;
}
}

Gtk.Box {
orientation: vertical;

Expand Down
32 changes: 21 additions & 11 deletions src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "exm-screenshot.h"
#include "exm-zoom-picture.h"
#include "exm-info-bar.h"
#include "exm-comment-tile.h"
#include "exm-comment-dialog.h"

Expand Down Expand Up @@ -63,7 +64,7 @@ struct _ExmDetailView
GtkOverlay *ext_screenshot_container;
GtkButton *ext_screenshot_popout_button;
GtkButton *ext_screenshot_popin_button;
GtkFlowBox *supported_versions;
ExmInfoBar *ext_info_bar;
GtkScrolledWindow *scroll_area;
GtkStack *comment_stack;
GtkFlowBox *comment_box;
Expand Down Expand Up @@ -286,7 +287,7 @@ on_data_loaded (GObject *source,

if ((data = exm_data_provider_get_finish (EXM_DATA_PROVIDER (source), result, &error)) != FALSE)
{
gint pk;
gint pk, downloads;
gboolean is_installed, is_supported;
gchar *uuid, *name, *creator, *icon_uri, *screenshot_uri, *link, *description, *url;
g_object_get (data,
Expand All @@ -300,6 +301,7 @@ on_data_loaded (GObject *source,
"shell_version_map", &version_map,
"pk", &pk,
"url", &url,
"downloads", &downloads,
NULL);

adw_window_title_set_title (self->title, name);
Expand All @@ -311,6 +313,7 @@ on_data_loaded (GObject *source,
gtk_label_set_label (self->ext_title, name);
gtk_label_set_label (self->ext_author, creator);
gtk_label_set_label (self->ext_description, description);
exm_info_bar_set_downloads (self->ext_info_bar, downloads);

if (self->resolver_cancel)
{
Expand Down Expand Up @@ -357,28 +360,24 @@ on_data_loaded (GObject *source,
adw_action_row_set_subtitle (self->link_homepage, self->uri_homepage);
adw_action_row_set_subtitle (self->link_extensions, self->uri_extensions);

// Clear Flowbox
while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->supported_versions))))
gtk_flow_box_remove (self->supported_versions, child);
exm_info_bar_set_version (self->ext_info_bar, -1);

for (version_iter = version_map->map;
version_iter != NULL;
version_iter = version_iter->next)
{
gchar *version;
MapEntry *entry;
GtkWidget *label;

entry = version_iter->data;

if (entry->shell_minor_version)
version = g_strdup_printf ("%s.%s", entry->shell_major_version, entry->shell_minor_version);
else
version = g_strdup (entry->shell_major_version);
version = g_strdup_printf ("%s.0", entry->shell_major_version);

label = gtk_label_new (version);
gtk_widget_add_css_class (label, "version-label");
gtk_flow_box_prepend (self->supported_versions, label);
if (strcmp (version, self->shell_version) == 0 || strncmp(version, self->shell_version, strchr(version, '.') - version) == 0)
exm_info_bar_set_version (self->ext_info_bar, entry->extension_version);

g_free (version);
}
Expand Down Expand Up @@ -440,6 +439,17 @@ exm_detail_view_update (ExmDetailView *self)
}
}

void
exm_detail_view_adaptive (ExmDetailView *self, AdwBreakpoint *breakpoint)
{
GValue value = G_VALUE_INIT;

g_value_init (&value, GTK_TYPE_ORIENTATION);
g_value_set_enum (&value, GTK_ORIENTATION_VERTICAL);

adw_breakpoint_add_setter (breakpoint, G_OBJECT (self->ext_info_bar), "orientation", &value);
}

static void
open_link (ExmDetailView *self,
const char *action_name,
Expand Down Expand Up @@ -545,7 +555,7 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_screenshot_container);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_screenshot_popout_button);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_screenshot_popin_button);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, supported_versions);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, ext_info_bar);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, link_homepage);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, link_extensions);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, scroll_area);
Expand Down
3 changes: 3 additions & 0 deletions src/exm-detail-view.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ exm_detail_view_load_for_uuid (ExmDetailView *self,
void
exm_detail_view_update (ExmDetailView *self);

void
exm_detail_view_adaptive (ExmDetailView *self, AdwBreakpoint *breakpoint);

G_END_DECLS
43 changes: 43 additions & 0 deletions src/exm-info-bar-item.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Gtk 4.0;
using Adw 1;

template $ExmInfoBarItem: Adw.Bin {
styles [
"card"
]

focusable: true;
height-request: 54;

Gtk.Box {
orientation: horizontal;

Gtk.Image icon {
margin-start: 12;
margin-end: 12;
}

Gtk.Box {
orientation: vertical;
valign: center;

Gtk.Label title {
xalign: 0;
}

Gtk.Label subtitle {
styles [
"dim-label",
"numeric"
]

xalign: 0;
}
}
}

accessibility {
labelled-by: title;
described-by: subtitle;
}
}
154 changes: 154 additions & 0 deletions src/exm-info-bar-item.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include "exm-info-bar-item.h"

struct _ExmInfoBarItem
{
AdwBin parent_instance;

GtkImage *icon;
GtkLabel *title;
GtkLabel *subtitle;
};

G_DEFINE_FINAL_TYPE (ExmInfoBarItem, exm_info_bar_item, ADW_TYPE_BIN)

enum {
PROP_0,
PROP_ICON,
PROP_TITLE,
PROP_SUBTITLE,
N_PROPS
};

static GParamSpec *properties [N_PROPS];

ExmInfoBarItem *
exm_info_bar_info_item_new (void)
{
return g_object_new (EXM_TYPE_INFO_BAR_ITEM, NULL);
}

static void
exm_info_bar_item_finalize (GObject *object)
{
ExmInfoBarItem *self = (ExmInfoBarItem *)object;

G_OBJECT_CLASS (exm_info_bar_item_parent_class)->finalize (object);
}

GtkLabel *
exm_info_bar_item_get_subtitle (ExmInfoBarItem *self)
{
g_return_val_if_fail (EXM_IS_INFO_BAR_ITEM (self), NULL);

return self->subtitle;
}

void
exm_info_bar_item_set_subtitle (ExmInfoBarItem *self,
const char *subtitle)
{
g_return_if_fail (EXM_IS_INFO_BAR_ITEM (self));

if (g_strcmp0 (gtk_label_get_label (self->subtitle), subtitle) == 0)
return;

gtk_label_set_label (self->subtitle, subtitle);

g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SUBTITLE]);
}

static void
exm_info_bar_item_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ExmInfoBarItem *self = EXM_INFO_BAR_ITEM (object);

switch (prop_id)
{
case PROP_ICON:
g_value_set_string (value, gtk_image_get_icon_name (self->icon));
break;
case PROP_TITLE:
g_value_set_string (value, gtk_label_get_label (self->title));
break;
case PROP_SUBTITLE:
g_value_set_string (value, gtk_label_get_text (exm_info_bar_item_get_subtitle (self)));
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}

static void
exm_info_bar_item_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ExmInfoBarItem *self = EXM_INFO_BAR_ITEM (object);

switch (prop_id)
{
case PROP_ICON:
gtk_image_set_from_icon_name (self->icon, g_value_get_string (value));
break;
case PROP_TITLE:
gtk_label_set_label (self->title, g_value_get_string (value));
break;
case PROP_SUBTITLE:
exm_info_bar_item_set_subtitle (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}

static void
exm_info_bar_item_class_init (ExmInfoBarItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

object_class->finalize = exm_info_bar_item_finalize;
object_class->get_property = exm_info_bar_item_get_property;
object_class->set_property = exm_info_bar_item_set_property;

properties [PROP_ICON] =
g_param_spec_string ("icon",
"Icon",
"The icon for the item",
NULL,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

properties [PROP_TITLE] =
g_param_spec_string ("title",
"Title",
"The title for the item",
NULL,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

properties [PROP_SUBTITLE] =
g_param_spec_string ("subtitle",
"Subtitle",
"The subtitle for the item",
NULL,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_properties (object_class, N_PROPS, properties);

GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

gtk_widget_class_set_template_from_resource (widget_class, "/com/mattjakeman/ExtensionManager/exm-info-bar-item.ui");

g_type_ensure (EXM_TYPE_INFO_BAR_ITEM);

gtk_widget_class_bind_template_child (widget_class, ExmInfoBarItem, icon);
gtk_widget_class_bind_template_child (widget_class, ExmInfoBarItem, title);
gtk_widget_class_bind_template_child (widget_class, ExmInfoBarItem, subtitle);
}

static void
exm_info_bar_item_init (ExmInfoBarItem *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
17 changes: 17 additions & 0 deletions src/exm-info-bar-item.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <adwaita.h>

G_BEGIN_DECLS

#define EXM_TYPE_INFO_BAR_ITEM (exm_info_bar_item_get_type())

G_DECLARE_FINAL_TYPE (ExmInfoBarItem, exm_info_bar_item, EXM, INFO_BAR_ITEM, AdwBin)

ExmInfoBarItem *
exm_info_bar_item_new (void);

void
exm_info_bar_item_set_subtitle (ExmInfoBarItem *info_bar_item, const char *subtitle);

G_END_DECLS
21 changes: 21 additions & 0 deletions src/exm-info-bar.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Gtk 4.0;

template $ExmInfoBar: Gtk.Box {
styles [
"info-bar"
]

homogeneous: true;
orientation: horizontal;

$ExmInfoBarItem downloads_item {
icon: "folder-download-symbolic";
title: _("Downloads");
}

$ExmInfoBarItem version_item {
icon: "system-software-install-symbolic";
title: _("Version");
subtitle: _("Unsupported");
}
}
Loading