Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e9aa91
commit df1eff5
Showing
3 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "Account", | ||
"category": "platform", | ||
"description": "Request information about the user", | ||
"panels": [ | ||
"code", | ||
"preview" | ||
], | ||
"autorun": true | ||
} |