diff --git a/.gitignore b/.gitignore index dee53c53..2313da7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build *~ +.flatpak-builder \ No newline at end of file diff --git a/demo/Application.vala b/demo/Application.vala new file mode 100644 index 00000000..3d609a6a --- /dev/null +++ b/demo/Application.vala @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrigthText: 2021 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +public class PortalsDemo.Application: Gtk.Application { + + public Application () { + Object ( + application_id: "io.elementary.portals.demo", + flags: GLib.ApplicationFlags.FLAGS_NONE + ); + } + + protected override void activate () { + var main_window = new MainWindow (this); + main_window.show_all (); + } + + public static int main (string[] args) { + return new Application ().run (args); + } +} diff --git a/demo/MainWindow.vala b/demo/MainWindow.vala new file mode 100644 index 00000000..c9a08ce8 --- /dev/null +++ b/demo/MainWindow.vala @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrigthText: 2021 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +public class PortalsDemo.MainWindow: Gtk.ApplicationWindow { + + public MainWindow (Gtk.Application application) { + Object (application: application); + } + + construct { + var appchooser_view = new Views.AppChooser (); + + var main_stack = new Gtk.Stack (); + main_stack.add_titled (appchooser_view, "appchooser", "AppChooser"); + + var stack_sidebar = new Gtk.StackSidebar (); + stack_sidebar.stack = main_stack; + + var paned = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); + paned.add1 (stack_sidebar); + paned.add2 (main_stack); + + var headerbar = new Gtk.HeaderBar (); + headerbar.get_style_context ().add_class ("default-decoration"); + headerbar.show_close_button = true; + + add (paned); + set_default_size (900, 600); + set_size_request (750, 500); + set_titlebar (headerbar); + title = "Portals Demo"; + + show_all (); + } +} diff --git a/demo/README.md b/demo/README.md new file mode 100644 index 00000000..2a9664bd --- /dev/null +++ b/demo/README.md @@ -0,0 +1,33 @@ +# Demo for Pantheon XDG Desktop Portals + +A demo application to test pantheon xdg desktop portals. + +## Dependencies + +You'll need the following dependencies to successfully build the demo application: + + sudo apt install elementary-sdk + flatpak install --user --assumeyes appcenter io.elementary.Platform io.elementary.Sdk + +## Install + +Run `flatpak-builder` to build and install the application: + + flatpak-builder build demo/io.elementary.portals.demo.yml --user --install --force-clean + +## Run + +To start the demo application, execute the following: + + flatpak run io.elementary.portals.demo + +**IMPORTANT:** Make sure xdg-desktop-portal running, otherwise +this demo app won't work as expected: + + /usr/libexec/xdg-desktop-portal -r + +## Uninstall + +Run the `flatpak` command to remove the application once your done with testing: + + flatpak uninstall --user io.elementary.portals.demo diff --git a/demo/Views/AppChooser.vala b/demo/Views/AppChooser.vala new file mode 100644 index 00000000..08a3c9cb --- /dev/null +++ b/demo/Views/AppChooser.vala @@ -0,0 +1,60 @@ + +/* + * Copyright 2019 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-3.0-or-later + */ + +public class PortalsDemo.Views.AppChooser: Gtk.Grid { + + construct { + margin = 12; + row_spacing = 3; + vexpand = true; + halign = Gtk.Align.CENTER; + valign = Gtk.Align.CENTER; + orientation = Gtk.Orientation.VERTICAL; + + var title_label = new Granite.HeaderLabel ("AppChooser Portal"); + var subtitle_label = new Gtk.Label ("Interface for choosing an application: org.freedesktop.impl.portal.AppChooser") { + margin_bottom = 24 + }; + + var open_image_button = new Gtk.Button.with_label ("Open Text"); + open_image_button.clicked.connect (() => { + var resource_file = File.new_for_uri ("resource:///io/elementary/portals/demo/appchooser-demo.txt"); + if (!resource_file.query_exists (null)) { + warning ("Resource file not found."); + return; + } + + // To trigger the AppChooser portal, we first need to copy the + // file outside of the Flatpak sandbox. We do this by copying + // it to the user's Downloads directory: + GLib.File file_to_open; + try { + file_to_open = File.new_for_path ("%s/appchooser-demo.txt".printf ( + Environment.get_user_special_dir (GLib.UserDirectory.DOWNLOAD) + )); + resource_file.copy (file_to_open, GLib.FileCopyFlags.OVERWRITE); + } catch (Error e) { + warning ("Error copying resource file: %s", e.message); + return; + } + + // Since the file is now outside of the sandbox in the user's + // Downloads directory, we are no able to open it - which triggers + // the AppChooser portal: + var file_uri_to_open = file_to_open.get_uri (); + try { + GLib.AppInfo.launch_default_for_uri (file_uri_to_open, null); + } catch (Error e) { + warning ("Error open file uri '%s': %s", file_uri_to_open, e.message); + return; + } + }); + + attach (title_label, 0, 0, 4); + attach_next_to (subtitle_label, title_label, Gtk.PositionType.BOTTOM, 4); + attach_next_to (open_image_button, subtitle_label, Gtk.PositionType.BOTTOM, 1); + } +} diff --git a/demo/data/appchooser-demo.txt b/demo/data/appchooser-demo.txt new file mode 100644 index 00000000..57c366c3 --- /dev/null +++ b/demo/data/appchooser-demo.txt @@ -0,0 +1,16 @@ +# elementary OS 6 Odin Available Now + +_Cassidy James Blaede Co-founder & CXO_ + +It’s been a long road to elementary OS 6—what with a whole global pandemic dropped +on us in the middle of development—but it’s finally here. elementary OS 6 Odin is +available to download now. And it’s the biggest update to the platform yet! + +With OS 6, we’ve focused in on: + +- Empowering you to **be in control** and **express yourself**, +- Continuing to innovate with **new features**, and +- Making elementary OS **easier to get** and **more inclusive** + +To get elementary OS 6 now, head to elementary.io for the download — or read on +for an overview of what’s new. \ No newline at end of file diff --git a/demo/data/demo.gresource.xml b/demo/data/demo.gresource.xml new file mode 100644 index 00000000..6ac791ca --- /dev/null +++ b/demo/data/demo.gresource.xml @@ -0,0 +1,6 @@ + + + + appchooser-demo.txt + + \ No newline at end of file diff --git a/demo/demo.desktop b/demo/demo.desktop new file mode 100644 index 00000000..0391b082 --- /dev/null +++ b/demo/demo.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=Portals Demo +Comment=A demo application to test portals +Exec=io.elementary.portals.demo +Icon=preferences-system-notifications +Type=Application +NoDisplay=true \ No newline at end of file diff --git a/demo/io.elementary.portals.demo.yml b/demo/io.elementary.portals.demo.yml new file mode 100644 index 00000000..b9ddc279 --- /dev/null +++ b/demo/io.elementary.portals.demo.yml @@ -0,0 +1,18 @@ +app-id: io.elementary.portals.demo +runtime: io.elementary.Platform +runtime-version: '6' +sdk: io.elementary.Sdk +command: io.elementary.portals.demo +finish-args: + - '--share=ipc' + - '--socket=fallback-x11' + - '--socket=wayland' + + # Needed by: AppChooser + - '--filesystem=home' +modules: + - name: demo + buildsystem: meson + sources: + - type: dir + path: . \ No newline at end of file diff --git a/demo/meson.build b/demo/meson.build new file mode 100644 index 00000000..e1389e99 --- /dev/null +++ b/demo/meson.build @@ -0,0 +1,27 @@ +project('io.elementary.portals.demo', 'vala', 'c') + +install_data( + 'demo.desktop', + install_dir: get_option('datadir') / 'applications', + rename: meson.project_name() + '.desktop' +) + +gnome = import('gnome') +resources = gnome.compile_resources( + 'demo-resources', 'data/demo.gresource.xml', + source_dir: 'data', + c_name: 'demo' +) + +executable( + meson.project_name(), + 'Application.vala', + 'MainWindow.vala', + 'Views' / 'AppChooser.vala', + resources, + dependencies: [ + dependency('gtk+-3.0'), + dependency('granite', version: '>= 6.0.0') + ], + install: true +) \ No newline at end of file