-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportal.c
115 lines (92 loc) · 2.82 KB
/
portal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright © 2016 Red Hat, Inc
*
* 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:
* Matthias Clasen <[email protected]>
*/
#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 <gtk/gtk.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 "request.h"
#include "filechooser.h"
static GMainLoop *loop = NULL;
static GHashTable *outstanding_handles = NULL;
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);
}
}
static void
on_name_acquired (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_debug ("org.freedesktop.impl.portal.desktop.gtk2 acquired");
}
static void
on_name_lost (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_main_loop_quit (loop);
}
int
main (int argc, char *argv[])
{
guint owner_id;
g_autoptr(GError) error = NULL;
GDBusConnection *session_bus;
GOptionContext *context;
gtk_init (&argc, &argv);
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.gtk2",
G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
on_bus_acquired,
on_name_acquired,
on_name_lost,
NULL,
NULL);
g_main_loop_run (loop);
g_bus_unown_name (owner_id);
return 0;
}