mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-16 05:55:50 +01:00
Split handle_method_call
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
eda1dcec63
commit
f6754d7a00
1 changed files with 192 additions and 152 deletions
|
@ -193,27 +193,16 @@ zathura_dbus_edit(ZathuraDbus* edit, unsigned int page, unsigned int x, unsigned
|
|||
/* D-Bus handler */
|
||||
|
||||
static void
|
||||
handle_method_call(GDBusConnection* UNUSED(connection),
|
||||
const gchar* UNUSED(sender), const gchar* object_path,
|
||||
const gchar* interface_name, const gchar* method_name,
|
||||
GVariant* parameters, GDBusMethodInvocation* invocation,
|
||||
void* data)
|
||||
handle_open_document(zathura_t* zathura, GVariant* parameters,
|
||||
GDBusMethodInvocation* invocation)
|
||||
{
|
||||
ZathuraDbus* dbus = data;
|
||||
private_t* priv = GET_PRIVATE(dbus);
|
||||
|
||||
girara_debug("Handling call '%s.%s' on '%s'.", interface_name, method_name,
|
||||
object_path);
|
||||
|
||||
/* methods that work without open document */
|
||||
if (g_strcmp0(method_name, "OpenDocument") == 0) {
|
||||
gchar* filename = NULL;
|
||||
gchar* password = NULL;
|
||||
gint page = ZATHURA_PAGE_NUMBER_UNSPECIFIED;
|
||||
g_variant_get(parameters, "(ssi)", &filename, &password, &page);
|
||||
|
||||
document_close(priv->zathura, false);
|
||||
document_open_idle(priv->zathura, filename,
|
||||
document_close(zathura, false);
|
||||
document_open_idle(zathura, filename,
|
||||
strlen(password) > 0 ? password : NULL,
|
||||
page,
|
||||
NULL, NULL);
|
||||
|
@ -222,26 +211,24 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
|||
|
||||
GVariant* result = g_variant_new("(b)", true);
|
||||
g_dbus_method_invocation_return_value(invocation, result);
|
||||
return;
|
||||
} else if (g_strcmp0(method_name, "CloseDocument") == 0) {
|
||||
const bool ret = document_close(priv->zathura, false);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_close_document(zathura_t* zathura, GVariant* UNUSED(parameters),
|
||||
GDBusMethodInvocation* invocation)
|
||||
{
|
||||
const bool ret = document_close(zathura, false);
|
||||
|
||||
GVariant* result = g_variant_new("(b)", ret);
|
||||
g_dbus_method_invocation_return_value(invocation, result);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->zathura->document == NULL) {
|
||||
g_dbus_method_invocation_return_dbus_error(invocation,
|
||||
"org.pwmt.zathura.NoOpenDocumen",
|
||||
"No document has been opened.");
|
||||
return;
|
||||
}
|
||||
static void
|
||||
handle_goto_page(zathura_t* zathura, GVariant* parameters,
|
||||
GDBusMethodInvocation* invocation)
|
||||
{
|
||||
const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
||||
|
||||
const unsigned int number_of_pages = zathura_document_get_number_of_pages(priv->zathura->document);
|
||||
|
||||
/* methods that require an open document */
|
||||
if (g_strcmp0(method_name, "GotoPage") == 0) {
|
||||
guint page = 0;
|
||||
g_variant_get(parameters, "(u)", &page);
|
||||
|
||||
|
@ -249,12 +236,19 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
|||
if (page >= number_of_pages) {
|
||||
ret = false;
|
||||
} else {
|
||||
page_set(priv->zathura, page);
|
||||
page_set(zathura, page);
|
||||
}
|
||||
|
||||
GVariant* result = g_variant_new("(b)", ret);
|
||||
g_dbus_method_invocation_return_value(invocation, result);
|
||||
} else if (g_strcmp0(method_name, "HighlightRects") == 0) {
|
||||
}
|
||||
|
||||
static void
|
||||
handle_highlight_rects(zathura_t* zathura, GVariant* parameters,
|
||||
GDBusMethodInvocation* invocation)
|
||||
{
|
||||
const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
||||
|
||||
guint page = 0;
|
||||
GVariantIter* iter = NULL;
|
||||
GVariantIter* secondary_iter = NULL;
|
||||
|
@ -346,22 +340,68 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
|||
}
|
||||
g_variant_iter_free(secondary_iter);
|
||||
|
||||
synctex_highlight_rects(priv->zathura, page, rectangles);
|
||||
synctex_highlight_rects(zathura, page, rectangles);
|
||||
g_free(rectangles);
|
||||
|
||||
GVariant* result = g_variant_new("(b)", true);
|
||||
g_dbus_method_invocation_return_value(invocation, result);
|
||||
} else if (g_strcmp0(method_name, "SynctexView") == 0) {
|
||||
}
|
||||
|
||||
static void
|
||||
handle_synctex_view(zathura_t* zathura, GVariant* parameters,
|
||||
GDBusMethodInvocation* invocation)
|
||||
{
|
||||
gchar* input_file = NULL;
|
||||
guint line = 0;
|
||||
guint column = 0;
|
||||
g_variant_get(parameters, "(suu)", &input_file, &line, &column);
|
||||
|
||||
const bool ret = synctex_view(priv->zathura, input_file, line, column);
|
||||
const bool ret = synctex_view(zathura, input_file, line, column);
|
||||
g_free(input_file);
|
||||
|
||||
GVariant* result = g_variant_new("(b)", ret);
|
||||
g_dbus_method_invocation_return_value(invocation, result);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_method_call(GDBusConnection* UNUSED(connection),
|
||||
const gchar* UNUSED(sender), const gchar* object_path,
|
||||
const gchar* interface_name, const gchar* method_name,
|
||||
GVariant* parameters, GDBusMethodInvocation* invocation,
|
||||
void* data)
|
||||
{
|
||||
ZathuraDbus* dbus = data;
|
||||
private_t* priv = GET_PRIVATE(dbus);
|
||||
|
||||
girara_debug("Handling call '%s.%s' on '%s'.", interface_name, method_name,
|
||||
object_path);
|
||||
|
||||
static const struct {
|
||||
const char* method;
|
||||
void (*handler)(zathura_t*, GVariant*, GDBusMethodInvocation*);
|
||||
bool needs_document;
|
||||
} handlers[] = {
|
||||
{ "OpenDocument", handle_open_document, false },
|
||||
{ "CloseDocument", handle_close_document, false },
|
||||
{ "GotoPage", handle_goto_page, true },
|
||||
{ "HighlightRects", handle_highlight_rects, true },
|
||||
{ "SynctexView", handle_synctex_view, true }
|
||||
};
|
||||
|
||||
for (size_t idx = 0; idx != sizeof(handlers) / sizeof(handlers[0]); ++idx) {
|
||||
if (g_strcmp0(method_name, handlers[idx].method) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (handlers[idx].needs_document == true && priv->zathura->document == NULL) {
|
||||
g_dbus_method_invocation_return_dbus_error(
|
||||
invocation, "org.pwmt.zathura.NoOpenDocumen",
|
||||
"No document has been opened.");
|
||||
return;
|
||||
}
|
||||
|
||||
(*handlers[idx].handler)(priv->zathura, parameters, invocation);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue