Skip to content

Commit

Permalink
library: Add Account entry (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoNiC-HeRE committed Jun 20, 2023
1 parent 8e9aa91 commit df1eff5
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
78 changes: 78 additions & 0 deletions src/Library/demos/Account/main.blp
@@ -0,0 +1,78 @@
using Gtk 4.0;
using Adw 1;

Adw.StatusPage {
title: _("Account");
description: _("Request information about the user");
margin-top: 48;

Adw.Clamp {
maximum-size: 340;

Box {
orientation: vertical;

Box {
orientation: vertical;
margin-bottom: 30;
spacing: 18;


Adw.EntryRow entry {
title: _("Reason");
styles ["card"]
halign: fill;
}

Button button {
label: _("Request");
halign: center;
styles ["suggested-action", "pill"]
}
}

Revealer revealer {
transition-duration: 300;
transition-type: slide_up;

ListBox {
selection-mode: none;
margin-bottom: 18;

styles ["boxed-list"]

Gtk.ListBoxRow {
activatable: false;
Adw.Avatar avatar {
hexpand: true;
size: 80;
margin-bottom: 18;
margin-top: 18;
}
}

Adw.ActionRow {
title: _("ID :");

Label username {
label: _("N/A");
}
}

Adw.ActionRow {
title: _("Name :");

Label name {
label: _("N/A");
}
}
}
}

LinkButton {
label: "API Reference";
uri: "https://libportal.org/method.Portal.get_user_information.html";
}
}
}
}
51 changes: 51 additions & 0 deletions src/Library/demos/Account/main.js
@@ -0,0 +1,51 @@
import Xdp from "gi://Xdp";
import XdpGtk from "gi://XdpGtk4";
import Gio from "gi://Gio";
import Gdk from "gi://Gdk";

Gio._promisify(
Xdp.Portal.prototype,
"get_user_information",
"get_user_information_finish",
);

const portal = new Xdp.Portal();
const parent = XdpGtk.parent_new_gtk(workbench.window);

const revealer = workbench.builder.get_object("revealer");
const button = workbench.builder.get_object("button");
const avatar = workbench.builder.get_object("avatar");
const entry = workbench.builder.get_object("entry");
const username = workbench.builder.get_object("username");
const display = workbench.builder.get_object("name");

async function onClicked() {
const reason = entry.get_text();
const result = await portal.get_user_information(parent, reason, null, null);

/*
result is a GVariant dictionary containing the following fields
id (s): the user ID
name (s): the users real name
image (s): the uri of an image file for the users avatar picture
*/

const user_info = result.deepUnpack();
const id = user_info["id"].deepUnpack();
const name = user_info["name"].deepUnpack();
const uri = user_info["image"].deepUnpack();
const file = Gio.File.new_for_uri(uri);
const texture = Gdk.Texture.new_from_file(file);

username.label = id;
display.label = name;
avatar.set_custom_image(texture);
revealer.reveal_child = true;

entry.set_text("");
console.log("Information retrieved");
}

button.connect("clicked", () => {
onClicked().catch(logError);
});
10 changes: 10 additions & 0 deletions src/Library/demos/Account/main.json
@@ -0,0 +1,10 @@
{
"name": "Account",
"category": "platform",
"description": "Request information about the user",
"panels": [
"code",
"preview"
],
"autorun": true
}

0 comments on commit df1eff5

Please sign in to comment.