🏡 index : quine-global-labs/bazaar.git

using Gtk 4.0;
using Adw 1;

template $BzAddonsDialog: Adw.Dialog {
  content-width: 500;
  content-height: 550;
  title: _("Add-on");

  child: Adw.ToastOverlay {
    child:Adw.NavigationView navigation_view {
      notify::visible-page-tag => $on_visible_page_tag_changed();

      Adw.NavigationPage {
        tag: "list";
        title: _("Manage Add-Ons");

        child: Adw.ToolbarView {
          [top]
          Adw.HeaderBar {
            title-widget: Label {
              styles ["heading"]
              label: _("Manage Add-Ons");
            };
          }

          content: ScrolledWindow {
            propagate-natural-height: true;
            vexpand: true;
            hscrollbar-policy: never;

            child: Adw.Clamp list_clamp {
              maximum-size: 450;
              tightening-threshold: 500;
              margin-start: 6;
              margin-end: 6;
              margin-bottom: 12;

              child: ListView {
                styles [
                  "navigation-sidebar",
                  "installed-list-view",
                ]

                model: NoSelection {
                  model: SortListModel {
                    sorter: CustomSorter sorter {};
                    model: bind template.addon-groups;
                  };
                };

                factory: BuilderListItemFactory {
                  template ListItem {
                    activatable: false;
                    selectable: false;
                    focusable: false;

                    child: $BzAddonTile {
                      group: bind template.item as <$BzEntryGroup>;
                      activated => $tile_activated_cb();
                    };
                  }
                };
              };
            };
          };
        };
      }

      Adw.NavigationPage {
        tag: "empty";
        title: _("Manage Add-Ons");

        child: Adw.ToolbarView {
          [top]
          Adw.HeaderBar {
            show-title: false;
          }

          content: Adw.StatusPage {
            icon-name: "application-x-addon-symbolic";
            title: _("No Add-Ons Visible");
            description: _("Your current filter preferences are hiding all known add-ons. Try adjusting them.");
          };
        };
      }

      Adw.NavigationPage {
        tag: "full-view";
        title: bind try { template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.title, _("Add-on Page") };

        child: Adw.ToolbarView {
          [top]
          Adw.HeaderBar {
            show-title: false;
          }

          content: ScrolledWindow {
            vexpand: true;
            hscrollbar-policy: never;

            child: Adw.Clamp {
              maximum-size: 450;
              tightening-threshold: 500;
              margin-start: 12;
              margin-end: 12;

              child: Box full_view_clamp {
                orientation: vertical;
                spacing: 4;
                margin-top: 12;

                Box {
                  halign: center;
                  spacing: 8;
                  orientation: vertical;
                  margin-bottom: 12;

                  Image {
                    pixel-size: 96;
                    paintable: bind template.parent-ui-entry as <$BzResult>.object as <$BzEntry>.icon-paintable;
                    visible: bind $invert_boolean($is_null(template.parent-ui-entry as <$BzResult>.object as <$BzEntry>.icon-paintable) as <bool>) as <bool>;

                    styles ["icon-dropshadow"]
                  }

                  Box {
                    orientation: vertical;
                    valign: center;
                    halign: center;
                    spacing: 2;
                    margin-bottom: 8;

                    Label {
                      label: bind template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.title;
                      justify: center;
                      max-width-chars: 25;
                      wrap: true;
                      wrap-mode: word_char;
                      selectable: true;

                      styles ["title-3"]
                    }

                    Label {
                      label: bind $format_parent_title(template.parent-ui-entry as <$BzResult>.object as <$BzEntry>.title) as <string>;
                      justify: center;
                      selectable: true;

                      styles ["dim-label"]
                    }
                  }
                }

                Box {
                  homogeneous: true;
                  margin-bottom: 12;
                  orientation: horizontal;
                  halign: fill;

                  styles ["app-context-bar"]

                  Stack size_tile_stack {
                    visible-child-name: bind $get_size_tile_child_name(template.selected-group as <$BzEntryGroup>.removable) as <string>;
                    transition-type: crossfade;

                    StackPage {
                      name: "download";
                      child: $BzContextTile download_size_tile {
                        label: bind try {$get_download_size_label(
                          template.selected-group as <$BzEntryGroup>.ui-entry as <$BzResult>.object as <$BzFlatpakEntry>.runtime as <$BzResult>.object as <$BzEntry>.installed,
                          template.selected-group as <$BzEntryGroup>.ui-entry as <$BzResult>.object as <$BzFlatpakEntry>.runtime as <$BzResult>.object as <$BzEntry>.size,
                        ) as <string>, _("Download")};
                        tooltip-text: bind $format_download_size_tooltip(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.size) as <string>;
                        lozenge-style: "grey";
                        clicked => $size_cb(template);

                        lozenge-child: Label {
                          label: bind $format_size(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.size) as <string>;
                          use-markup: true;
                        };
                      };
                    }

                    StackPage {
                      name: "installed";
                      child: $BzContextTile installed_size_tile {
                        label: _("Installed");
                        tooltip-text: bind $format_installed_size_tooltip(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.installed-size) as <string>;
                        lozenge-style: "grey";
                        clicked => $size_cb(template);
                        lozenge-child: Label {
                          label: bind $format_size(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.installed-size) as <string>;
                          use-markup: true;
                        };
                      };
                    }
                  }

                  $BzContextTile {
                    label: bind $get_license_label(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>) as <string>;
                    clicked => $license_cb(template);
                    lozenge-style: bind $bool_to_string(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.is-floss, "grey", "warning") as <string>;
                    tooltip-text: bind $format_license_tooltip(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>) as <string>;

                    lozenge-child: Box {
                      spacing: 6;

                      Image {
                        icon-name: bind $get_license_icon(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.is-floss, 0) as <string>;
                      }

                      Image {
                        icon-name: bind $get_license_icon(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.is-floss, 1) as <string>;
                      }
                    };
                  }

                  $BzContextTile {
                    can-target: bind $invert_boolean($is_null(template.selected-ui-entry) as <bool>) as <bool>;
                    sensitive: bind $invert_boolean($is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.recent-downloads) as <bool>) as <bool>;
                    label: _("Downloads/Month");
                    clicked => $dl_stats_cb(template);
                    tooltip-text: bind $format_recent_downloads_tooltip(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.recent-downloads) as <string>;
                    lozenge-style: "grey";

                    lozenge-child: Label {
                      justify: center;
                      label: bind $format_recent_downloads(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.recent-downloads) as <string>;
                      halign: center;
                      use-markup: true;
                    };
                  }
                }

                Box {
                  visible: bind $invert_boolean($is_null(template.selected-group as <$BzEntryGroup>.eol) as <bool>) as <bool>;
                  orientation: vertical;
                  spacing: 8;

                  styles [
                    "card",
                    "colored",
                    "warning",
                  ]

                  Label {
                    label: _("Stopped Receiving Core Updates");
                    margin-top: 8;
                    margin-start: 8;
                    margin-end: 8;
                    wrap: true;
                    wrap-mode: word_char;
                    justify: center;

                    styles [
                      "title-4",
                    ]
                  }

                  Label {
                    label: _("This add-on uses a runtime that no longer receives updates or security fixes. It may become unsafe to use.");
                    margin-bottom: 8;
                    margin-start: 8;
                    margin-end: 8;
                    wrap: true;
                    wrap-mode: word_char;
                    justify: center;
                  }
                }

                Label {
                  visible: bind $logical_and($invert_boolean($is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.description) as <bool>) as <bool>, $is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.long-description) as <bool>) as <bool>;
                  label: bind template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.description;
                  selectable: true;
                  wrap: true;
                  wrap-mode: word_char;
                  justify: center;
                  halign: center;
                  margin-bottom: 6;

                  styles ["dimmed"]
                }

                $BzInstallControls install_controls {
                  halign: center;
                  margin-top: 6;
                  margin-bottom: 8;
                  wide: false;
                  entry-group: bind template.selected-group;
                  state: bind template.state;
                  settings: bind template.state as <$BzStateInfo>.settings;
                }

                Label {
                  visible: bind $logical_and($invert_boolean($is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.description) as <bool>) as <bool>, $invert_boolean($is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.long-description) as <bool>) as <bool>) as <bool>;
                  label: bind template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.description;
                  selectable: true;
                  wrap: true;
                  wrap-mode: word_char;
                  xalign: 0;
                  halign: fill;
                  margin-top: 12;
                  margin-bottom: 4;

                  styles ["title-4"]
                }

                $BzFadingClamp fading_clamp {
                  visible: bind $invert_boolean($is_null(template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.long-description) as <bool>) as <bool>;
                  max-height: bind $get_description_max_height(description_toggle.active) as <int>;
                  min-max-height: 170;

                  child: $BzAppstreamDescriptionRender {
                    appstream-description: bind template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.long-description;
                  };
                }

                ToggleButton description_toggle {
                  styles ["circular"]
                  visible: bind fading_clamp.will-change;
                  halign: center;

                  child: Label {
                    label: bind $get_description_toggle_text(description_toggle.active) as <string>;
                    margin-start: 16;
                    margin-end: 16;
                  };
                  margin-bottom: 12;
                }

                Revealer {
                  transition-type: swing_up;
                  reveal-child: bind $logical_and(
                      $logical_and(
                        $is_le(template.selected-group as <$BzEntryGroup>.removable, 0) as <bool>,
                        $is_gt(template.selected-group as <$BzEntryGroup>.installable, 0) as <bool>
                      ) as <bool>,
                      $not(install_controls.in-progress) as <bool>
                    ) as <bool>;

                  child: Box {
                    orientation: vertical;

                    Label {
                      halign: start;
                      label: _("Other Sources");
                      margin-top: 5;
                      margin-bottom: 8;
                      margin-start: 3;
                      visible: bind other_sources.visible;

                      styles [
                        "heading",
                      ]
                    }

                    $BzOtherSourcesList other_sources {
                      entry-group: bind template.selected-group as <$BzEntryGroup>;
                      download => $other_source_download_cb(template);
                      margin-bottom: 8;
                    }
                  };
                }

                $BzShareList {
                  urls: bind template.selected-ui-entry as <$BzResult>.object as <$BzEntry>.share-urls;
                  margin-bottom: 24;
                }
              };
            };
          };
        };
      }
    };
  };
}