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

using Gtk 4.0;
using Adw 1;

template $BzInspector: Adw.Window {
  title: "Bazaar Inspector";
  default-width: 1200;
  default-height: 800;
  width-request: 600;
  height-request: 600;

  Adw.ToolbarView {
    top-bar-style: raised_border;
    bottom-bar-style: raised_border;
    reveal-bottom-bars: false;

    [top]
    Adw.HeaderBar {
      [end]
      MenuButton {
        primary: true;
        icon-name: "open-menu-symbolic";
        tooltip-text: _("Inspector Menu");
        menu-model: inspector_menu;
      }
    }

    content: Paned {
      orientation: horizontal;

      start-child: ScrolledWindow {
        child: Box {
          orientation: vertical;
          width-request: 100;
          spacing: 10;

          Box {
            orientation: vertical;

            Box {
              orientation: horizontal;
              spacing: 10;

              Label {
                styles [
                  "heading"
                ]
                label: "Background Task Info:";
                xalign: 0.0;
              }
              Label {
                label: bind template.state as <$BzStateInfo>.background-task-label as <string>;
                xalign: 0.0;
              }
            }
            Box {
              orientation: horizontal;
              spacing: 10;

              Label {
                styles [
                  "heading"
                ]
                label: "Active Entry Objects in Memory:";
                xalign: 0.0;
              }
              Label {
                label: bind $format_uint(template.state as <$BzStateInfo>.cache-manager as <$BzEntryCacheManager>.living-entries) as <string>;
                xalign: 0.0;
              }
            }
          }

          Box {
            orientation: vertical;
            spacing: 3;

            CheckButton debug_mode_check {
              label: "Enable Global Debug Mode";
            }
            CheckButton disable_blocklists_check {
              label: "Disable All Blocklists";
            }
          }

          Box {
            orientation: vertical;
            spacing: 3;

            Label {
              styles [
                "heading"
              ]
              label: "Active Blocklists (YAML)";
              xalign: 0.0;
            }
            ScrolledWindow {
              propagate-natural-height: true;
              child: ListView {
                model: NoSelection {
                  model: bind template.state as <$BzStateInfo>.blocklists;
                };
                factory: string_list_factory;
              };
            }
          }

          Box {
            orientation: vertical;
            spacing: 3;

            Label {
              styles [
                "heading"
              ]
              label: "Active Blocklists (TXT)";
              xalign: 0.0;
            }
            ScrolledWindow {
              propagate-natural-height: true;
              child: ListView {
                model: NoSelection {
                  model: bind template.state as <$BzStateInfo>.txt-blocklists;
                };
                factory: string_list_factory;
              };
            }
          }

          Box {
            orientation: vertical;
            spacing: 3;

            Label {
              styles [
                "heading"
              ]
              label: "Active Curated-Configs";
              xalign: 0.0;
            }
            ScrolledWindow {
              propagate-natural-height: true;
              child: ListView {
                model: NoSelection {
                  model: bind template.state as <$BzStateInfo>.curated-configs;
                };
                factory: string_list_factory;
              };
            }
          }

          Box {
            orientation: vertical;
            spacing: 3;

            Box {
              orientation: horizontal;
              spacing: 10;

              Label {
                styles [
                  "heading"
                ]
                label: "Max Age Rating:";
                xalign: 0.0;
              }
              Label {
                label: bind $format_int(template.state as <$BzStateInfo>.parental-age-rating) as <string>;
                xalign: 0.0;
              }
            }
            Label {
              styles [
                "heading"
              ]
              label: "Restricted App IDs";
              xalign: 0.0;
            }
            ScrolledWindow {
              propagate-natural-height: true;
              child: ListView {
                model: NoSelection {
                  model: bind template.state as <$BzStateInfo>.parental-blocked-ids;
                };
                factory: plain_string_list_factory;
              };
            }
          }
        };
      };

      end-child: Box {
        orientation: vertical;
        spacing: 8;

        Label {
          styles [
            "heading"
          ]
          margin-top: 10;
          label: "All Entry Groups";
          xalign: 0.0;
        }

        Separator {
          orientation: horizontal;
        }

        Expander {
          label: "Serialize All Entries Into File";

          child: Box {
            margin-start: 3;
            margin-end: 3;
            margin-top: 3;
            margin-bottom: 3;

            orientation: vertical;
            spacing: 5;

            Box {
              orientation: horizontal;
              spacing: 5;

              Entry serialize_all_entries_path_entry {
                hexpand: true;
                placeholder-text: "Enter the path to an output file...";
              }

              Button serialize_all_entries_btn {
                styles [
                  "suggested-action",
                ]
                label: "Go";
                clicked => $serialize_all_entries_cb(template);
              }
            }

            ProgressBar serialize_all_entries_progress {
              visible: false;
            }
          };
        }

        Separator {
          orientation: horizontal;
        }

        Box {
          orientation: horizontal;
          spacing: 5;

          CheckButton {
            label: "Preview";
            notify::active => $preview_changed(template);
          }

          Entry search_entry {
            hexpand: true;
            margin-start: 5;
            margin-end: 5;
            margin-top: 5;
            margin-bottom: 5;
            placeholder-text: "Filter...";
            changed => $entry_changed(template);
          }
        }
        ScrolledWindow {
          vscrollbar-policy: always;
          propagate-natural-height: true;
          child: ListView {
            model: SingleSelection groups_selection {
              model: FilterListModel filter_model {
                incremental: true;
                model: bind template.state as <$BzStateInfo>.all-entry-groups;
              };
              notify::selected-item => $selected_group_changed(template);
            };
            factory: BuilderListItemFactory {
              template ListItem {
                activatable: false;
                child: Expander {
                  styles [
                    "bz-monospace",
                  ]

                  resize-toplevel: true;
                  label-widget: Label {
                    label: bind template.item as <$BzEntryGroup>.id as <string>;
                  };

                  child: Box {
                    styles [
                      "card",
                    ]
                    margin-start: 3;
                    margin-end: 3;
                    margin-top: 3;
                    margin-bottom: 3;

                    halign: start;
                    orientation: horizontal;

                    Box {
                      margin-start: 5;
                      margin-end: 5;
                      margin-top: 5;
                      margin-bottom: 5;

                      orientation: vertical;
                      spacing: 2;

                      Box {
                        margin-start: 2;
                        orientation: horizontal;
                        spacing: 2;

                        Label {
                          styles [
                            "accent",
                          ]
                          label: bind template.item as <$BzEntryGroup>.title;
                        }
                        Image {
                          gicon: bind template.item as <$BzEntryGroup>.mini-icon;
                        }

                        Box {
                          styles [
                            "linked",
                          ]
                          hexpand: true;
                          halign: end;
                          orientation: horizontal;

                          MenuButton {
                            styles [
                              "bz-small-button",
                            ]

                            child: Label {
                              styles [
                                "bz-monospace",
                              ]
                              margin-start: 2;
                              margin-end: 2;
                              label: "Entries";
                            };
                            popover: Popover {
                              child: ScrolledWindow {
                                propagate-natural-width: true;
                                propagate-natural-height: true;
                                child: ListView {
                                  model: NoSelection {
                                    model: bind template.item as <$BzEntryGroup>.model;
                                  };
                                  factory: BuilderListItemFactory {
                                    template ListItem {
                                      activatable: false;

                                      child: Box {
                                        margin-top: 1;
                                        margin-bottom: 1;
                                        orientation: horizontal;
                                        spacing: 5;

                                        Box {
                                          styles [
                                            "linked",
                                          ]
                                          orientation: horizontal;

                                          Button {
                                            styles [
                                              "bz-small-button",
                                            ]
                                            tooltip-text: "Decache and Inspect";

                                            child: Image {
                                              icon-name: "external-link-symbolic";
                                              pixel-size: 12;
                                            };
                                            clicked => $decache_and_inspect_cb(template);
                                          }
                                          Button {
                                            styles [
                                              "bz-small-button",
                                            ]
                                            tooltip-text: "Copy Unique ID";

                                            child: Image {
                                              icon-name: "edit-copy-symbolic";
                                              pixel-size: 12;
                                            };
                                            clicked => $copy_unique_id_cb(template);
                                          }
                                        }
                                        Label {
                                          hexpand: true;
                                          ellipsize: end;
                                          xalign: 0.0;
                                          label: bind template.item as <$GtkStringObject>.string as <string>;
                                          selectable: true;
                                        }
                                      };
                                    }
                                  };
                                };
                              };
                            };
                          }

                          MenuButton {
                            styles [
                              "bz-small-button",
                            ]
                            visible: bind $not($is_null(template.item as <$BzEntryGroup>.addons-model as <$GListModel>) as <bool>) as <bool>;

                            child: Label {
                              styles [
                                "bz-monospace",
                              ]
                              margin-start: 2;
                              margin-end: 2;
                              label: "Addons";
                            };
                            popover: Popover {
                              child: ScrolledWindow {
                                propagate-natural-width: true;
                                propagate-natural-height: true;
                                child: ListView {
                                  model: NoSelection {
                                    model: bind template.item as <$BzEntryGroup>.addons-model;
                                  };
                                  factory: BuilderListItemFactory {
                                    template ListItem {
                                      activatable: false;
                                      child: Label {
                                        hexpand: true;
                                        ellipsize: end;
                                        xalign: 0.0;
                                        label: bind template.item as <$GtkStringObject>.string as <string>;
                                        selectable: true;
                                      };
                                    }
                                  };
                                };
                              };
                            };
                          }
                        }
                      }

                      Separator {
                        orientation: horizontal;
                      }

                      Grid {
                        column-spacing: 2;
                        row-spacing: 1;

                        Label {
                          layout {
                            column: 0;
                            row: 0;
                          }
                          label: "Developer:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 1;
                            row: 0;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind template.item as <$BzEntryGroup>.developer;
                          ellipsize: end;
                          xalign: 0.5;
                        }

                        Label {
                          layout {
                            column: 0;
                            row: 1;
                          }
                          label: "Description:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 1;
                            row: 1;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind template.item as <$BzEntryGroup>.description;
                          ellipsize: end;
                          xalign: 0.5;
                        }

                        Label {
                          layout {
                            column: 0;
                            row: 2;
                          }
                          label: "EOL:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 1;
                            row: 2;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind template.item as <$BzEntryGroup>.eol;
                          ellipsize: end;
                          xalign: 0.5;
                        }

                        Label {
                          layout {
                            column: 2;
                            row: 0;
                          }
                          label: "Installable:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 0;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.installable) as <string>;
                          xalign: 0.0;
                        }
                        Label {
                          layout {
                            column: 2;
                            row: 1;
                          }
                          label: "Installable-And-Available:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 1;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.installable-and-available) as <string>;
                          xalign: 0.0;
                        }

                        Label {
                          layout {
                            column: 2;
                            row: 2;
                          }
                          label: "Updatable:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 2;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.updatable) as <string>;
                          xalign: 0.0;
                        }
                        Label {
                          layout {
                            column: 2;
                            row: 3;
                          }
                          label: "Updatable-And-Available:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 3;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.updatable-and-available) as <string>;
                          xalign: 0.0;
                        }

                        Label {
                          layout {
                            column: 2;
                            row: 4;
                          }
                          label: "Removable:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 4;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.removable) as <string>;
                          xalign: 0.0;
                        }
                        Label {
                          layout {
                            column: 2;
                            row: 5;
                          }
                          label: "Removable-And-Available:";
                          xalign: 1.0;
                        }
                        Label {
                          layout {
                            column: 3;
                            row: 5;
                          }
                          styles [
                            "accent",
                          ]
                          label: bind $format_int(template.item as <$BzEntryGroup>.removable-and-available) as <string>;
                          xalign: 0.0;
                        }
                      }
                    }
                  };
                };
              }
            };
          };
        }
      };
    };
  }
}

BuilderListItemFactory string_list_factory {
  template ListItem {
    selectable: false;
    activatable: false;
    child: Box {
      orientation: horizontal;
      spacing: 10;

      Label {
        styles [
          "dimmed",
          "bz-monospace",
        ]
        width-request: 30;
        label: bind $format_uint(template.position) as <string>;
        xalign: 1.0;
      }
      Label {
        styles [
          "bz-monospace",
        ]

        hexpand: true;
        margin-top: 2;
        margin-bottom: 2;
        xalign: 0.0;
        selectable: true;
        label: bind template.item as <$GtkStringObject>.string as <string>;
      }
      Button {
        label: "Open";
        clicked => $open_file_externally_cb(template);
      }
    };
  }
}

BuilderListItemFactory plain_string_list_factory {
  template ListItem {
    selectable: false;
    activatable: false;
    child: Box {
      orientation: horizontal;
      spacing: 10;

      Label {
        styles [
          "dimmed",
          "bz-monospace",
        ]
        width-request: 30;
        label: bind $format_uint(template.position) as <string>;
        xalign: 1.0;
      }
      Label {
        styles [
          "bz-monospace",
        ]
        hexpand: true;
        margin-top: 2;
        margin-bottom: 2;
        xalign: 0.0;
        selectable: true;
        label: bind template.item as <$GtkStringObject>.string as <string>;
      }
    };
  }
}

menu inspector_menu {
  section {
    item {
      label: "_Quit Bazaar";
      action: "app.quit";
    }
  }
}