Skip to content

Commit

Permalink
detail-view: Add info bar
Browse files Browse the repository at this point in the history
  • Loading branch information
oscfdezdz committed Oct 15, 2023
1 parent 0b09818 commit f5593ca
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 36 deletions.
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.ListBox {
styles ["boxed-list"]

Expand All @@ -184,22 +186,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
21 changes: 10 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 @@ -284,7 +285,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;
g_object_get (data,
Expand All @@ -297,6 +298,7 @@ on_data_loaded (GObject *source,
"description", &description,
"shell_version_map", &version_map,
"pk", &pk,
"downloads", &downloads,
NULL);

adw_window_title_set_title (self->title, name);
Expand All @@ -308,6 +310,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 @@ -348,28 +351,24 @@ on_data_loaded (GObject *source,

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 @@ -536,7 +535,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_extensions);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, scroll_area);
gtk_widget_class_bind_template_child (widget_class, ExmDetailView, comment_box);
Expand Down
30 changes: 30 additions & 0 deletions src/exm-info-bar-item.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Gtk 4.0;

template $ExmInfoBarItem : Gtk.Box {
hexpand: true;
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"]
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
{
GtkBox parent_instance;

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

G_DEFINE_FINAL_TYPE (ExmInfoBarItem, exm_info_bar_item, GTK_TYPE_BOX)

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 <gtk/gtk.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, GtkBox)

ExmInfoBarItem *
exm_info_bar_item_new (void);

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

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

template $ExmInfoBar : Gtk.Box {
styles ["linked", "card", "info-bar"]
height-request: 54;
homogeneous: true;

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

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

0 comments on commit f5593ca

Please sign in to comment.