summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-02-15 01:19:04 +0100
committerJacki <jacki@thejackimonster.de>2024-02-15 01:19:04 +0100
commit7b87c26b8fe8f2811d8cbfe706ee8c85189c5457 (patch)
treede1f5f61d243118acc2ad698a4f23c8ca2f2e809
parentb8cc56e6c0ba1a92d6951cc085d8b7d5593a4452 (diff)
Adjust code to allow building without libportal
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--meson.build27
-rw-r--r--src/application.c38
-rw-r--r--src/application.h5
-rw-r--r--src/request.c142
-rw-r--r--src/request.h30
-rw-r--r--src/ui/messenger.c2
-rw-r--r--src/ui/new_contact.c35
-rw-r--r--src/ui/settings.c28
8 files changed, 229 insertions, 78 deletions
diff --git a/meson.build b/meson.build
index b200978..26d2ab8 100644
--- a/meson.build
+++ b/meson.build
@@ -25,6 +25,8 @@ project(
version: run_command('contrib/get_version.sh').stdout().strip(),
)
+use_libportal = true
+
messenger_gtk_id = 'org.gnunet.Messenger'
gnome = import('gnome')
@@ -40,25 +42,36 @@ messenger_gtk_deps = [
dependency('gtk+-3.0'),
dependency('libhandy-1'),
dependency('gstreamer-1.0'),
- dependency('libportal'),
- dependency('libportal-gtk3'),
dependency('libnotify'),
dependency('libqrencode'),
dependency('libpipewire-0.3'),
declare_dependency(link_args: '-lunistring'),
]
+messenger_gtk_args = [
+ '-DMESSENGER_APPLICATION_BINARY="@0@"'.format(meson.project_name()),
+ '-DMESSENGER_APPLICATION_ID="@0@"'.format(messenger_gtk_id),
+ '-DMESSENGER_APPLICATION_VERSION="@0@"'.format(meson.project_version()),
+]
+
+if use_libportal
+ messenger_gtk_deps += [
+ dependency('libportal'),
+ dependency('libportal-gtk3'),
+ ]
+else
+ messenger_gtk_args += [
+ '-DMESSENGER_APPLICATION_NO_PORTAL=1',
+ ]
+endif
+
subdir('resources')
subdir('src')
messenger_gtk_exec = executable(
meson.project_name(),
messenger_gtk_resources + messenger_gtk_sources,
- c_args : [
- '-DMESSENGER_APPLICATION_BINARY="@0@"'.format(meson.project_name()),
- '-DMESSENGER_APPLICATION_ID="@0@"'.format(messenger_gtk_id),
- '-DMESSENGER_APPLICATION_VERSION="@0@"'.format(meson.project_version()),
- ],
+ c_args: messenger_gtk_args,
install: true,
dependencies: messenger_gtk_deps,
extra_files: submodules_headers,
diff --git a/src/application.c b/src/application.c
index bea7209..dd8f93f 100644
--- a/src/application.c
+++ b/src/application.c
@@ -29,10 +29,13 @@
#include <gstreamer-1.0/gst/gst.h>
#include <gtk-3.0/gtk/gtk.h>
#include <libhandy-1/handy.h>
-#include <libportal-gtk3/portal-gtk3.h>
#include <libnotify/notify.h>
#include <pipewire/impl.h>
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
+#include <libportal-gtk3/portal-gtk3.h>
+#endif
+
static void
_load_ui_stylesheets(MESSENGER_Application *app)
{
@@ -76,8 +79,10 @@ _application_init(MESSENGER_Application *app)
ui_messenger_init(app, &(app->ui.messenger));
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
if (app->portal)
app->parent = xdp_parent_new_gtk(GTK_WINDOW(app->ui.messenger.main_window));
+#endif
if (app->chat.identity)
application_show_window(app);
@@ -257,6 +262,7 @@ application_init(MESSENGER_Application *app,
resources_register();
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
GError *error = NULL;
app->portal = xdp_portal_initable_new(&error);
@@ -265,6 +271,7 @@ application_init(MESSENGER_Application *app,
g_printerr("ERROR: %s\n", error->message);
g_error_free(error);
}
+#endif
notify_init(MESSENGER_APPLICATION_NAME);
app->notifications = NULL;
@@ -479,31 +486,14 @@ application_run(MESSENGER_Application *app)
}
static void
-_request_background_callback(GObject *source_object,
- GAsyncResult *result,
+_request_background_callback(MESSENGER_Application *app,
+ gboolean success,
+ gboolean error,
gpointer user_data)
{
- g_assert((source_object) && (result) && (user_data));
-
- XdpPortal *portal = XDP_PORTAL(source_object);
- MESSENGER_Request *request = (MESSENGER_Request*) user_data;
-
- request_cleanup(request);
-
- gboolean *setting = (gboolean*) (request->user_data);
-
- GError *error = NULL;
- gboolean success = xdp_portal_request_background_finish(
- portal, result, &error
- );
-
- request_drop(request);
-
- if (error) {
- g_printerr("ERROR: %s\n", error->message);
- g_error_free(error);
- }
+ g_assert((app) && (user_data));
+ gboolean *setting = (gboolean*) user_data;
*setting = success;
}
@@ -644,10 +634,12 @@ application_exit(MESSENGER_Application *app,
// GNUnet handles of the application.
write(app->chat.pipe[1], &signal, sizeof(signal));
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
if (app->portal)
g_object_unref(app->portal);
app->portal = NULL;
+#endif
if (app->pw.registry)
pw_proxy_destroy((struct pw_proxy*) app->pw.registry);
diff --git a/src/application.h b/src/application.h
index 1195cfe..6f0ad72 100644
--- a/src/application.h
+++ b/src/application.h
@@ -25,7 +25,10 @@
#ifndef APPLICATION_H_
#define APPLICATION_H_
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
#include <libportal/portal.h>
+#endif
+
#include <pipewire/pipewire.h>
#include <pthread.h>
@@ -75,8 +78,10 @@ typedef struct MESSENGER_Application
GList *requests;
guint init;
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
XdpPortal *portal;
XdpParent *parent;
+#endif
struct {
GQuark widget;
diff --git a/src/request.c b/src/request.c
index d35289e..a3a8107 100644
--- a/src/request.c
+++ b/src/request.c
@@ -24,8 +24,47 @@
#include "request.h"
+#ifdef MESSENGER_APPLICATION_NO_PORTAL
+
+static gboolean
+_request_timeout_call(gpointer user_data)
+{
+ g_assert(user_data);
+
+ MESSENGER_Request* request = (MESSENGER_Request*) user_data;
+
+ MESSENGER_Application *app = request->application;
+ MESSENGER_RequestCallback callback = request->callback;
+ gpointer data = request->user_data;
+
+ request_cleanup(request);
+ request_drop(request);
+
+ if (callback)
+ callback(app, TRUE, FALSE, data);
+
+ return FALSE;
+}
+
+static void
+_request_cancel_timeout(gpointer user_data)
+{
+ g_assert(user_data);
+
+ MESSENGER_Request* request = (MESSENGER_Request*) user_data;
+
+ if (request->timeout)
+ g_source_remove(request->timeout);
+
+ request_cleanup(request);
+ request_drop(request);
+}
+
+#endif
+
MESSENGER_Request*
request_new(MESSENGER_Application *application,
+ MESSENGER_RequestCallback callback,
GCancellable *cancellable,
gpointer user_data)
{
@@ -34,9 +73,24 @@ request_new(MESSENGER_Application *application,
MESSENGER_Request* request = g_malloc(sizeof(MESSENGER_Request));
request->application = application;
+ request->callback = callback;
request->cancellable = cancellable;
request->user_data = user_data;
+#ifdef MESSENGER_APPLICATION_NO_PORTAL
+ request->timeout = g_timeout_add(
+ 0, G_SOURCE_FUNC(_request_timeout_call), request
+ );
+
+ if (request->cancellable)
+ g_cancellable_connect (
+ request->cancellable,
+ _request_cancel_timeout,
+ request,
+ NULL
+ );
+#endif
+
application->requests = g_list_append(
application->requests,
request
@@ -45,10 +99,47 @@ request_new(MESSENGER_Application *application,
return request;
}
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
+static void
+_request_background_callback(GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_assert((source_object) && (result) && (user_data));
+
+ XdpPortal *portal = XDP_PORTAL(source_object);
+ MESSENGER_Request *request = (MESSENGER_Request*) user_data;
+
+ request_cleanup(request);
+
+ MESSENGER_Application *app = request->application;
+ MESSENGER_RequestCallback callback = request->callback;
+ gpointer data = request->user_data;
+
+ GError *error = NULL;
+ gboolean success = xdp_portal_request_background_finish(
+ portal, result, &error
+ );
+
+ request_drop(request);
+
+ gboolean error_value = false;
+ if (error) {
+ g_printerr("ERROR: %s\n", error->message);
+ g_error_free(error);
+
+ error_value = true;
+ }
+
+ if (callback)
+ callback(app, success, error_value, data);
+}
+#endif
+
MESSENGER_Request*
request_new_background(MESSENGER_Application *application,
XdpBackgroundFlags flags,
- GAsyncReadyCallback callback,
+ MESSENGER_RequestCallback callback,
gpointer user_data)
{
g_assert((application) && (callback));
@@ -60,10 +151,12 @@ request_new_background(MESSENGER_Application *application,
MESSENGER_Request* request = request_new(
application,
+ callback,
cancellable,
user_data
);
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
xdp_portal_request_background(
application->portal,
application->parent,
@@ -71,17 +164,55 @@ request_new_background(MESSENGER_Application *application,
NULL,
flags,
cancellable,
- callback,
+ _request_background_callback,
request
);
+#endif
return request;
}
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
+static void
+_request_camera_callback(GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_assert((source_object) && (result) && (user_data));
+
+ XdpPortal *portal = (XdpPortal*) source_object;
+ MESSENGER_Request *request = (MESSENGER_Request*) user_data;
+
+ request_cleanup(request);
+
+ MESSENGER_Application *app = request->application;
+ MESSENGER_RequestCallback callback = request->callback;
+ gpointer data = request->user_data;
+
+ GError *error = NULL;
+ gboolean success = xdp_portal_access_camera_finish(
+ portal, result, &error
+ );
+
+ request_drop(request);
+
+ gboolean error_value = false;
+ if (error) {
+ g_printerr("ERROR: %s\n", error->message);
+ g_error_free(error);
+
+ error_value = true;
+ }
+
+ if (callback)
+ callback(app, success, error_value, data);
+}
+#endif
+
MESSENGER_Request*
request_new_camera(MESSENGER_Application *application,
XdpCameraFlags flags,
- GAsyncReadyCallback callback,
+ MESSENGER_RequestCallback callback,
gpointer user_data)
{
g_assert((application) && (callback));
@@ -93,18 +224,21 @@ request_new_camera(MESSENGER_Application *application,
MESSENGER_Request* request = request_new(
application,
+ callback,
cancellable,
user_data
);
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
xdp_portal_access_camera(
application->portal,
application->parent,
flags,
cancellable,
- callback,
+ _request_camera_callback,
request
);
+#endif
return request;
}
diff --git a/src/request.h b/src/request.h
index 18507ae..91789ab 100644
--- a/src/request.h
+++ b/src/request.h
@@ -26,14 +26,39 @@
#define REQUEST_H_
#include <gio/gio.h>
+
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
#include <libportal/portal.h>
+#else
+typedef enum XdpBackgroundFlags {
+ XDP_BACKGROUND_FLAG_ACTIVATABLE = 1,
+ XDP_BACKGROUND_FLAG_AUTOSTART = 2,
+ XDP_BACKGROUND_FLAG_NONE = 0,
+} XdpBackgroundFlags;
+
+typedef enum XdpCameraFlags {
+ XDP_CAMERA_FLAG_NONE = 0,
+} XdpCameraFlags;
+#endif
#include "application.h"
+typedef void (*MESSENGER_RequestCallback)(
+ MESSENGER_Application *application,
+ gboolean success,
+ gboolean error,
+ gpointer user_data
+);
+
typedef struct MESSENGER_Request {
MESSENGER_Application *application;
+ MESSENGER_RequestCallback callback;
GCancellable *cancellable;
gpointer user_data;
+
+#ifdef MESSENGER_APPLICATION_NO_PORTAL
+ guint timeout;
+#endif
} MESSENGER_Request;
/**
@@ -50,6 +75,7 @@ typedef struct MESSENGER_Request {
*/
MESSENGER_Request*
request_new(MESSENGER_Application *application,
+ MESSENGER_RequestCallback callback,
GCancellable *cancellable,
gpointer user_data);
@@ -66,7 +92,7 @@ request_new(MESSENGER_Application *application,
MESSENGER_Request*
request_new_background(MESSENGER_Application *application,
XdpBackgroundFlags flags,
- GAsyncReadyCallback callback,
+ MESSENGER_RequestCallback callback,
gpointer user_data);
/**
@@ -82,7 +108,7 @@ request_new_background(MESSENGER_Application *application,
MESSENGER_Request*
request_new_camera(MESSENGER_Application *application,
XdpCameraFlags flags,
- GAsyncReadyCallback callback,
+ MESSENGER_RequestCallback callback,
gpointer user_data);
/**
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
index 84c7ea3..f4d54c3 100644
--- a/src/ui/messenger.c
+++ b/src/ui/messenger.c
@@ -362,10 +362,12 @@ handle_main_window_destroy(UNUSED GtkWidget *window,
MESSENGER_Application *app = (MESSENGER_Application*) user_data;
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
if (app->parent)
xdp_parent_free(app->parent);
app->parent = NULL;
+#endif
ui_messenger_cleanup(&(app->ui.messenger));
ui_accounts_dialog_cleanup(&(app->ui.accounts));
diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c
index 317957d..9c10ca0 100644
--- a/src/ui/new_contact.c
+++ b/src/ui/new_contact.c
@@ -382,7 +382,11 @@ _init_camera_pipeline(MESSENGER_Application *app,
handle->camera_count = 0;
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
if ((app->portal) && ((access) || xdp_portal_is_camera_present(app->portal)))
+#else
+ if (access)
+#endif
{
app->pw.pending = pw_core_sync(app->pw.core, 0, 0);
@@ -407,31 +411,14 @@ _init_camera_pipeline(MESSENGER_Application *app,
}
static void
-_request_camera_callback(GObject *source_object,
- GAsyncResult *result,
+_request_camera_callback(MESSENGER_Application *app,
+ gboolean success,
+ gboolean error,
gpointer user_data)
{
- g_assert((source_object) && (result) && (user_data));
+ g_assert((app) && (user_data));
- XdpPortal *portal = (XdpPortal*) source_object;
- MESSENGER_Request *request = (MESSENGER_Request*) user_data;
-
- request_cleanup(request);
-
- MESSENGER_Application *app = request->application;
- UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) request->user_data;
-
- GError *error = NULL;
- gboolean success = xdp_portal_access_camera_finish(
- portal, result, &error
- );
-
- request_drop(request);
-
- if (error) {
- g_printerr("ERROR: %s\n", error->message);
- g_error_free(error);
- }
+ UI_NEW_CONTACT_Handle *handle = (UI_NEW_CONTACT_Handle*) user_data;
_init_camera_pipeline(app, handle, success);
}
@@ -446,7 +433,11 @@ ui_new_contact_dialog_init(MESSENGER_Application *app,
_setup_gst_pipeline(handle);
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
if (app->portal)
+#else
+ if (FALSE)
+#endif
{
request_new_camera(
app,
diff --git a/src/ui/settings.c b/src/ui/settings.c
index 6589778..7855902 100644
--- a/src/ui/settings.c
+++ b/src/ui/settings.c
@@ -29,7 +29,10 @@
#include <gnunet/gnunet_chat_lib.h>
#include <gnunet/gnunet_common.h>
+
+#ifndef MESSENGER_APPLICATION_NO_PORTAL
#include <libportal/background.h>
+#endif
static gboolean
handle_general_switch_state(UNUSED GtkSwitch *widget,
@@ -44,31 +47,16 @@ handle_general_switch_state(UNUSED GtkSwitch *widget,
}
static void
-_request_background_callback(GObject *source_object,
- GAsyncResult *result,
+_request_background_callback(MESSENGER_Application *app,
+ gboolean success,
+ gboolean error,
gpointer user_data)
{
- g_assert((source_object) && (result) && (user_data));
-
- XdpPortal *portal = XDP_PORTAL(source_object);
- MESSENGER_Request *request = (MESSENGER_Request*) user_data;
+ g_assert((app) && (user_data));
- request_cleanup(request);
-
- MESSENGER_Application *app = request->application;
- GtkSwitch *widget = GTK_SWITCH(request->user_data);
-
- GError *error = NULL;
- gboolean success = xdp_portal_request_background_finish(
- portal, result, &error
- );
-
- request_drop(request);
+ GtkSwitch *widget = GTK_SWITCH(user_data);
if (error) {
- g_printerr("ERROR: %s\n", error->message);
- g_error_free(error);
-
gtk_widget_set_sensitive(GTK_WIDGET(widget), !success);
gtk_switch_set_active(widget, success);
return;