Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed Jan 15, 2024
1 parent 27afccb commit 097dc88
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 9 deletions.
4 changes: 4 additions & 0 deletions data/org.freedesktop.impl.portal.desktop.tau.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.impl.portal.desktop.tau
Exec=@libexecdir@/xdg-desktop-portal-tau
SystemdService=xdg-desktop-portal-tau.service
4 changes: 4 additions & 0 deletions data/tau.portal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.tau
Interfaces=org.freedesktop.impl.portal.Account;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.ScreenCast;org.freedesktop.impl.portal.RemoteDesktop;org.freedesktop.impl.portal.Lockdown;org.freedesktop.impl.portal.Background;org.freedesktop.impl.portal.Settings;org.freedesktop.impl.portal.Wallpaper;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Print;org.freedesktop.impl.portal.DynamicLauncher;
UseIn=gnome
7 changes: 7 additions & 0 deletions data/xdg-desktop-portal-tau.desktop.in.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=Portal
# TRANSLATORS: Don't translate this text (this is icon name)
Icon=applications-system-symbolic
Exec=@libexecdir@/xdg-desktop-portal-tau
NoDisplay=true
7 changes: 7 additions & 0 deletions data/xdg-desktop-portal-tau.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Portal service (tauOS implementation)

[Service]
Type=dbus
BusName=org.freedesktop.impl.portal.desktop.tau
ExecStart=@libexecdir@/xdg-desktop-portal-tau
2 changes: 1 addition & 1 deletion src/accountdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<template class="AccountDialog" parent="GtkWindow">
<property name="title" translatable="yes">Share Details</property>
<property name="resizable">0</property>
Expand Down
2 changes: 1 addition & 1 deletion src/appchooserdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="AppChooserDialog" parent="GtkWindow">
<property name="title" translatable="yes">Open With…</property>
Expand Down
2 changes: 1 addition & 1 deletion src/appchooserrow.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="AppChooserRow" parent="GtkListBoxRow">
<property name="child">
Expand Down
2 changes: 1 addition & 1 deletion src/remotedesktopdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="RemoteDesktopDialog" parent="GtkWindow">
<property name="default-width">500</property>
Expand Down
2 changes: 1 addition & 1 deletion src/screencastdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="ScreenCastDialog" parent="GtkWindow">
<property name="title" translatable="yes">Screen Share</property>
Expand Down
2 changes: 1 addition & 1 deletion src/screencastwidget.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="ScreenCastWidget" parent="GtkBox">
<property name="orientation">vertical</property>
Expand Down
2 changes: 1 addition & 1 deletion src/screenshotdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="ScreenshotDialog" parent="GtkWindow">
<property name="resizable">0</property>
Expand Down
2 changes: 1 addition & 1 deletion src/wallpaperdialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="WallpaperDialog" parent="GtkWindow">
<property name="default-width">500</property>
Expand Down
2 changes: 1 addition & 1 deletion src/wallpaperpreview.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="xdg-desktop-portal-gnome">
<interface domain="xdg-desktop-portal-tau">
<requires lib="gtk" version="4.0"/>
<template class="WallpaperPreview" parent="GtkBox">
<property name="hexpand">0</property>
Expand Down
291 changes: 291 additions & 0 deletions src/xdg-desktop-portal-tau.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
/*
* Copyright © 2016 Red Hat, Inc
* Copyright © 2021 Endless OS Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Georges Basile Stavracas Neto <georges@endlessos.org>
* Matthias Clasen <mclasen@redhat.com>
*/

#define _GNU_SOURCE 1

#include "config.h"

#include <errno.h>
#include <locale.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <adwaita.h>

#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <gio/gunixfdlist.h>

#include <glib/gi18n.h>
#include <locale.h>

#include "xdg-desktop-portal-dbus.h"

#include "account.h"
#include "appchooser.h"
#include "background.h"
#include "filechooser.h"
#include "lockdown.h"
#include "print.h"
#include "screenshot.h"
#include "screencast.h"
#include "remotedesktop.h"
#include "request.h"
#include "settings.h"
#include "wallpaper.h"
#include "dynamic-launcher.h"


static GMainLoop *loop = NULL;
static GHashTable *outstanding_handles = NULL;

static gboolean opt_verbose;
static gboolean opt_replace;
static gboolean show_version;

static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
{ "replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, "Replace a running instance", NULL },

{ "version", 0, 0, G_OPTION_ARG_NONE, &show_version, "Show program version.", NULL},
{ NULL }
};

static void
message_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
/* Make this look like normal console output */
if (log_level & G_LOG_LEVEL_DEBUG)
printf ("XDP: %s\n", message);
else
printf ("%s: %s\n", g_get_prgname (), message);
}

static void
printerr_handler (const gchar *string)
{
int is_tty = isatty (1);
const char *prefix = "";
const char *suffix = "";
if (is_tty)
{
prefix = "\x1b[31m\x1b[1m"; /* red, bold */
suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
}
fprintf (stderr, "%serror: %s%s\n", prefix, suffix, string);
}

static void
on_bus_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
GError *error = NULL;

if (!file_chooser_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!account_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!app_chooser_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!background_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!lockdown_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!print_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!screenshot_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!screen_cast_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!remote_desktop_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!settings_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!wallpaper_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}

if (!dynamic_launcher_init (connection, &error))
{
g_warning ("error: %s\n", error->message);
g_clear_error (&error);
}
}

static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("org.freedesktop.impl.portal.desktop.tau acquired");
}

static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("name lost");
g_main_loop_quit (loop);
}

int
main (int argc, char *argv[])
{
guint owner_id;
g_autoptr(GError) error = NULL;
GDBusConnection *session_bus;
g_autoptr(GOptionContext) context = NULL;

setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);

/* Avoid pointless and confusing recursion */
g_unsetenv ("GTK_USE_PORTAL");

if (G_UNLIKELY (!g_setenv ("ADW_DISABLE_PORTAL", "1", TRUE)))
{
g_printerr ("Failed to set ADW_DISABLE_PORTAL: %s\n", g_strerror (errno));
return 1;
}

if (G_UNLIKELY (!g_setenv ("GSK_RENDERER", "cairo", TRUE)))
{
g_printerr ("Failed to set GSK_RENDERER: %s\n", g_strerror (errno));
return 1;
}

gtk_init ();

context = g_option_context_new ("- portal backends");
g_option_context_set_summary (context,
"A backend implementation for xdg-desktop-portal.");
g_option_context_set_description (context,
"xdg-desktop-portal-tau provides D-Bus interfaces that\n"
"are used by xdg-desktop-portal to implement portals\n"
"\n"
"Documentation for the available D-Bus interfaces can be found at\n"
"https://flatpak.github.io/xdg-desktop-portal/portal-docs.html\n"
"\n"
"Please report issues at https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/issues");
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, &error))
{
g_printerr ("%s: %s", g_get_application_name (), error->message);
g_printerr ("\n");
g_printerr ("Try \"%s --help\" for more information.",
g_get_prgname ());
g_printerr ("\n");
return 1;
}

if (show_version)
{
g_print (PACKAGE_STRING "\n");
return 0;
}

g_set_printerr_handler (printerr_handler);

if (opt_verbose)
g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, message_handler, NULL);

g_set_prgname ("xdg-desktop-portal-tau");

loop = g_main_loop_new (NULL, FALSE);

outstanding_handles = g_hash_table_new (g_str_hash, g_str_equal);

session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (session_bus == NULL)
{
g_printerr ("No session bus: %s\n", error->message);
return 2;
}

owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
"org.freedesktop.impl.portal.desktop.tau",
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
on_bus_acquired,
on_name_acquired,
on_name_lost,
NULL,
NULL);

adw_init ();

g_main_loop_run (loop);

g_bus_unown_name (owner_id);

return 0;
}
16 changes: 16 additions & 0 deletions src/xdg-desktop-portal-tau.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<gresources>
<gresource prefix='/org/freedesktop/portal/desktop/tau'>
<file>accountdialog.ui</file>
<file>appchooserdialog.ui</file>
<file>appchooserrow.ui</file>
<file>screenshotdialog.ui</file>
<file>screencastwidget.ui</file>
<file>screencastdialog.ui</file>
<file>remotedesktopdialog.ui</file>
<file>wallpaperdialog.ui</file>
<file>wallpaperpreview.ui</file>
<file>wallpaperpreview.css</file>
</gresource>
</gresources>

Loading

0 comments on commit 097dc88

Please sign in to comment.