Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2014-01-31 10:33:25 +01:00
parent ac8be2d528
commit a45cd0a474
2 changed files with 63 additions and 54 deletions

View file

@ -35,8 +35,7 @@ typedef struct private_s {
} private_t;
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_DBUS, \
private_t))
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_DBUS, private_t))
static const GDBusInterfaceVTable interface_vtable;
@ -92,8 +91,8 @@ bus_acquired(GDBusConnection* connection, const gchar* name, void* data)
private_t* priv = GET_PRIVATE(dbus);
GError* error = NULL;
priv->registration_id = g_dbus_connection_register_object(connection,
DBUS_OBJPATH, priv->introspection_data->interfaces[0],
priv->registration_id = g_dbus_connection_register_object(
connection, DBUS_OBJPATH, priv->introspection_data->interfaces[0],
&interface_vtable, dbus, NULL, &error);
if (priv->registration_id == 0) {
girara_warning("Failed to register object on D-Bus connection: %s",
@ -133,7 +132,8 @@ zathura_dbus_new(zathura_t* zathura)
priv->zathura = zathura;
GError* error = NULL;
priv->introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTERFACE_XML, &error);
priv->introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTERFACE_XML,
&error);
if (priv->introspection_data == NULL) {
girara_warning("Failed to parse introspection data: %s", error->message);
g_error_free(error);
@ -142,8 +142,8 @@ zathura_dbus_new(zathura_t* zathura)
}
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, getpid());
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION,
well_known_name, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, well_known_name,
G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
name_acquired, name_lost, dbus, NULL);
g_free(well_known_name);
@ -217,9 +217,9 @@ highlight_rects(zathura_t* zathura, unsigned int page,
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)
const gchar* interface_name, const gchar* method_name,
GVariant* parameters, GDBusMethodInvocation* invocation,
void* data)
{
ZathuraDbus* dbus = data;
private_t* priv = GET_PRIVATE(dbus);
@ -236,7 +236,8 @@ handle_method_call(GDBusConnection* UNUSED(connection),
document_close(priv->zathura, false);
const bool ret = document_open(priv->zathura, filename,
strlen(password) > 0 ? password : NULL, page);
strlen(password) > 0 ? password : NULL,
page);
g_free(filename);
g_free(password);
@ -253,7 +254,8 @@ handle_method_call(GDBusConnection* UNUSED(connection),
if (priv->zathura->document == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.pwmt.zathura.NoOpenDocumen", "No document has been opened.");
"org.pwmt.zathura.NoOpenDocumen",
"No document has been opened.");
return;
}
@ -333,9 +335,11 @@ handle_method_call(GDBusConnection* UNUSED(connection),
/* get secondary rectangles */
guint temp_page = 0;
while (g_variant_iter_loop(secondary_iter, "(udddd)", &temp_page,
&temp_rect.x1, &temp_rect.x2, &temp_rect.y1, &temp_rect.y2)) {
&temp_rect.x1, &temp_rect.x2, &temp_rect.y1,
&temp_rect.y2)) {
if (temp_page >= number_of_pages) {
/* error out here? */
girara_debug("Got invalid page number.");
continue;
}
@ -372,9 +376,10 @@ handle_method_call(GDBusConnection* UNUSED(connection),
static GVariant*
handle_get_property(GDBusConnection* UNUSED(connection),
const gchar* UNUSED(sender), const gchar* UNUSED(object_path),
const gchar* UNUSED(interface_name), const gchar* property_name,
GError** error, void* data)
const gchar* UNUSED(sender),
const gchar* UNUSED(object_path),
const gchar* UNUSED(interface_name),
const gchar* property_name, GError** error, void* data)
{
ZathuraDbus* dbus = data;
private_t* priv = GET_PRIVATE(dbus);
@ -406,15 +411,14 @@ static const unsigned int TIMEOUT = 3000;
static bool
call_hightlight_rects(GDBusConnection* connection, const char* filename,
const char* name, unsigned int page, girara_list_t* rectangles,
girara_list_t* secondary_rects)
const char* name, unsigned int page,
girara_list_t* rectangles, girara_list_t* secondary_rects)
{
GError* error = NULL;
GVariant* vfilename = g_dbus_connection_call_sync(connection,
name, DBUS_OBJPATH, "org.freedesktop.DBus.Properties",
"Get", g_variant_new("(ss)", DBUS_INTERFACE, "filename"),
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE,
TIMEOUT, NULL, &error);
GVariant* vfilename = g_dbus_connection_call_sync(
connection, name, DBUS_OBJPATH, "org.freedesktop.DBus.Properties", "Get",
g_variant_new("(ss)", DBUS_INTERFACE, "filename"), G_VARIANT_TYPE("(v)"),
G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
if (vfilename == NULL) {
girara_error("Failed to query 'filename' property from '%s': %s",
name, error->message);
@ -448,12 +452,13 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
if (secondary_rects != NULL) {
GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect)
g_variant_builder_add(second_builder, "(udddd)", rect->page,
rect->rect.x1, rect->rect.x2, rect->rect.y1, rect->rect.y2);
rect->rect.x1, rect->rect.x2, rect->rect.y1,
rect->rect.y2);
GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect);
}
GVariant* ret = g_dbus_connection_call_sync(connection,
name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects",
GVariant* ret = g_dbus_connection_call_sync(
connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects",
g_variant_new("(ua(dddd)a(udddd))", page, builder, second_builder),
G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
g_variant_builder_unref(builder);
@ -470,10 +475,9 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
bool
zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
girara_list_t* rectangles, girara_list_t* secondary_rects, pid_t hint)
girara_list_t* rectangles,
girara_list_t* secondary_rects, pid_t hint)
{
/* note: page is [1, number_of_pages] here */
if (filename == NULL) {
return false;
}
@ -490,15 +494,16 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
if (hint != -1) {
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint);
const bool ret = call_hightlight_rects(connection, filename,
well_known_name, page, rectangles, secondary_rects);
well_known_name, page, rectangles,
secondary_rects);
g_free(well_known_name);
return ret;
}
GVariant* vnames = g_dbus_connection_call_sync(connection,
"org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
"ListNames", NULL, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE,
TIMEOUT, NULL, &error);
GVariant* vnames = g_dbus_connection_call_sync(
connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "ListNames", NULL, G_VARIANT_TYPE("(as)"),
G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
if (vnames == NULL) {
girara_error("Could not list available names: %s", error->message);
g_error_free(error);
@ -539,14 +544,15 @@ zathura_dbus_synctex_position(const char* filename, const char* position,
unsigned int page = 0;
girara_list_t* secondary_rects = NULL;
girara_list_t* rectangles = synctex_rectangles_from_position(filename,
position, &page, &secondary_rects);
girara_list_t* rectangles = synctex_rectangles_from_position(
filename, position, &page, &secondary_rects);
if (rectangles == NULL) {
return false;
}
const bool ret = zathura_dbus_goto_page_and_highlight(filename, page,
rectangles, secondary_rects, hint);
rectangles,
secondary_rects, hint);
girara_list_free(rectangles);
girara_list_free(secondary_rects);
return ret;

View file

@ -38,11 +38,13 @@ print(zathura_t* zathura)
gtk_print_operation_set_use_full_page(print_operation, TRUE);
if (zathura->print.settings != NULL) {
gtk_print_operation_set_print_settings(print_operation, zathura->print.settings);
gtk_print_operation_set_print_settings(print_operation,
zathura->print.settings);
}
if (zathura->print.page_setup != NULL) {
gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup);
gtk_print_operation_set_default_page_setup(print_operation,
zathura->print.page_setup);
}
gtk_print_operation_set_embed_page_setup(print_operation, TRUE);
@ -71,7 +73,8 @@ static void
cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
UNUSED(context), zathura_t* zathura)
{
if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL) {
if (zathura == NULL || zathura->ui.session == NULL ||
zathura->document == NULL) {
return;
}