Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Application #24

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
*~
.flatpak-builder
23 changes: 23 additions & 0 deletions demo/Application.vala
Original file line number Diff line number Diff line change
@@ -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);
}
}
37 changes: 37 additions & 0 deletions demo/MainWindow.vala
Original file line number Diff line number Diff line change
@@ -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 ();
}
}
33 changes: 33 additions & 0 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions demo/Views/AppChooser.vala
Original file line number Diff line number Diff line change
@@ -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);
}
}
16 changes: 16 additions & 0 deletions demo/data/appchooser-demo.txt
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions demo/data/demo.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/io/elementary/portals/demo/">
<file compressed="true">appchooser-demo.txt</file>
</gresource>
</gresources>
7 changes: 7 additions & 0 deletions demo/demo.desktop
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions demo/io.elementary.portals.demo.yml
Original file line number Diff line number Diff line change
@@ -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: .
27 changes: 27 additions & 0 deletions demo/meson.build
Original file line number Diff line number Diff line change
@@ -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
)