4141#include "ev-stock-icons.h"
4242
4343#ifdef ENABLE_DBUS
44+ #include "ev-gdbus-generated.h"
4445#include "ev-media-player-keys.h"
4546#endif /* ENABLE_DBUS */
4647
@@ -54,7 +55,7 @@ struct _EvApplication {
5455
5556#ifdef ENABLE_DBUS
5657 GDBusConnection * connection ;
57- guint registration_id ;
58+ EvAtrilApplication * skeleton ;
5859 EvMediaPlayerKeys * keys ;
5960 gboolean doc_registered ;
6061#endif
@@ -604,6 +605,9 @@ ev_application_open_uri_in_window (EvApplication *application,
604605{
605606 GdkWindow * gdk_window ;
606607
608+ if (uri == NULL )
609+ uri = application -> uri ;
610+
607611 if (screen ) {
608612 ev_stock_icons_set_screen (screen );
609613 gtk_window_set_screen (GTK_WINDOW (ev_window ), screen );
@@ -717,110 +721,92 @@ ev_application_open_window (EvApplication *application,
717721}
718722
719723#ifdef ENABLE_DBUS
720- static void
721- method_call_cb (GDBusConnection * connection ,
722- const gchar * sender ,
723- const gchar * object_path ,
724- const gchar * interface_name ,
725- const gchar * method_name ,
726- GVariant * parameters ,
727- GDBusMethodInvocation * invocation ,
728- gpointer user_data )
724+ static gboolean
725+ handle_get_window_list_cb (EvAtrilApplication * object ,
726+ GDBusMethodInvocation * invocation ,
727+ EvApplication * application )
729728{
730- EvApplication * application = EV_APPLICATION (user_data );
731- GList * windows , * l ;
732- guint timestamp ;
733- GVariantIter * iter ;
734- const gchar * key ;
735- GVariant * value ;
736- GdkDisplay * display = NULL ;
737- EvLinkDest * dest = NULL ;
738- EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL ;
739- const gchar * search_string = NULL ;
740- GdkScreen * screen = NULL ;
741-
742- if (g_strcmp0 (method_name , "Reload" ) == 0 ) {
743- g_variant_get (parameters , "(a{sv}u)" , & iter , & timestamp );
744-
745- while (g_variant_iter_loop (iter , "{&sv}" , & key , & value )) {
746- if (strcmp (key , "display" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
747- display = ev_display_open_if_needed (g_variant_get_string (value , NULL ));
748- } else if (strcmp (key , "mode" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_UINT32 ) {
749- mode = g_variant_get_uint32 (value );
750- } else if (strcmp (key , "page-label" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
751- dest = ev_link_dest_new_page_label (g_variant_get_string (value , NULL ));
752- } else if (strcmp (key , "named-dest" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
753- dest = ev_link_dest_new_named (g_variant_get_string (value , NULL ));
754- } else if (strcmp (key , "page-index" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_UINT32 ) {
755- dest = ev_link_dest_new_page (g_variant_get_uint32 (value ));
756- } else if (strcmp (key , "find-string" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
757- search_string = g_variant_get_string (value , NULL );
758- }
759- }
760- g_variant_iter_free (iter );
729+ GList * windows , * l ;
730+ GPtrArray * paths ;
761731
762- if (display != NULL )
763- screen = gdk_display_get_default_screen (display );
764- else
765- screen = gdk_screen_get_default ();
732+ paths = g_ptr_array_new ();
766733
767- windows = ev_application_get_windows (application );
768- for (l = windows ; l != NULL ; l = g_list_next (l )) {
769- EvWindow * ev_window = EV_WINDOW ( l -> data ) ;
734+ windows = ev_application_get_windows (application );
735+ for (l = windows ; l ; l = g_list_next (l )) {
736+ EvWindow * window = ( EvWindow * ) l -> data ;
770737
771- ev_application_open_uri_in_window (application , application -> uri ,
772- ev_window ,
773- screen , dest , mode ,
774- search_string ,
775- timestamp );
776- }
777- g_list_free (windows );
738+ g_ptr_array_add (paths , (gpointer ) ev_window_get_dbus_object_path (window ));
739+ }
740+ g_list_free (windows );
778741
779- if (dest )
780- g_object_unref (dest );
742+ g_ptr_array_add (paths , NULL );
743+ ev_atril_application_complete_get_window_list (object , invocation ,
744+ (const char * const * ) paths -> pdata );
781745
782- g_dbus_method_invocation_return_value (invocation , g_variant_new ("()" ));
783- } else if (g_strcmp0 (method_name , "GetWindowList" ) == 0 ) {
784- GList * windows = ev_application_get_windows (application );
785- GVariantBuilder builder ;
786- GList * l ;
746+ g_ptr_array_free (paths , TRUE);
787747
788- g_variant_builder_init ( & builder , G_VARIANT_TYPE ( "(ao)" )) ;
789- g_variant_builder_open ( & builder , G_VARIANT_TYPE ( "ao" ));
748+ return TRUE ;
749+ }
790750
791- for (l = windows ; l ; l = g_list_next (l )) {
792- EvWindow * window = (EvWindow * )l -> data ;
751+ static gboolean
752+ handle_reload_cb (EvAtrilApplication * object ,
753+ GDBusMethodInvocation * invocation ,
754+ GVariant * args ,
755+ guint timestamp ,
756+ EvApplication * application )
757+ {
758+ GList * windows , * l ;
759+ GVariantIter iter ;
760+ const gchar * key ;
761+ GVariant * value ;
762+ GdkDisplay * display = NULL ;
763+ EvLinkDest * dest = NULL ;
764+ EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL ;
765+ const gchar * search_string = NULL ;
766+ GdkScreen * screen = NULL ;
767+
768+ g_variant_iter_init (& iter , args );
769+
770+ while (g_variant_iter_loop (& iter , "{&sv}" , & key , & value )) {
771+ if (strcmp (key , "display" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
772+ display = ev_display_open_if_needed (g_variant_get_string (value , NULL ));
773+ } else if (strcmp (key , "mode" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_UINT32 ) {
774+ mode = g_variant_get_uint32 (value );
775+ } else if (strcmp (key , "page-label" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
776+ dest = ev_link_dest_new_page_label (g_variant_get_string (value , NULL ));
777+ } else if (strcmp (key , "named-dest" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
778+ dest = ev_link_dest_new_named (g_variant_get_string (value , NULL ));
779+ } else if (strcmp (key , "page-index" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_UINT32 ) {
780+ dest = ev_link_dest_new_page (g_variant_get_uint32 (value ));
781+ } else if (strcmp (key , "find-string" ) == 0 && g_variant_classify (value ) == G_VARIANT_CLASS_STRING ) {
782+ search_string = g_variant_get_string (value , NULL );
783+ }
784+ }
793785
794- g_variant_builder_add (& builder , "o" , ev_window_get_dbus_object_path (window ));
795- }
786+ if (display != NULL )
787+ screen = gdk_display_get_default_screen (display );
788+ else
789+ screen = gdk_screen_get_default ();
796790
797- g_variant_builder_close (& builder );
798- g_list_free (windows );
791+ windows = ev_application_get_windows (application );
792+ for (l = windows ; l != NULL ; l = g_list_next (l )) {
793+ EvWindow * ev_window = EV_WINDOW (l -> data );
799794
800- g_dbus_method_invocation_return_value (invocation , g_variant_builder_end (& builder ));
801- }
802- }
795+ ev_application_open_uri_in_window (application , NULL ,
796+ ev_window ,
797+ screen , dest , mode ,
798+ search_string ,
799+ timestamp );
800+ }
801+ g_list_free (windows );
803802
804- static const char introspection_xml [] =
805- "<node>"
806- "<interface name='org.mate.atril.Application'>"
807- "<method name='Reload'>"
808- "<arg type='a{sv}' name='args' direction='in'/>"
809- "<arg type='u' name='timestamp' direction='in'/>"
810- "</method>"
811- "<method name='GetWindowList'>"
812- "<arg type='ao' name='window_list' direction='out'/>"
813- "</method>"
814- "</interface>"
815- "</node>" ;
816-
817- static const GDBusInterfaceVTable interface_vtable = {
818- method_call_cb ,
819- NULL ,
820- NULL
821- };
803+ if (dest )
804+ g_object_unref (dest );
822805
823- static GDBusNodeInfo * introspection_data ;
806+ ev_atril_application_complete_reload (object , invocation );
807+
808+ return TRUE;
809+ }
824810#endif /* ENABLE_DBUS */
825811
826812void
@@ -916,19 +902,15 @@ ev_application_shutdown (EvApplication *application)
916902 g_object_unref (application -> keys );
917903 application -> keys = NULL ;
918904 }
919- if (application -> registration_id != 0 ) {
920- g_dbus_connection_unregister_object ( application -> connection ,
921- application -> registration_id );
922- application -> registration_id = 0 ;
905+ if (application -> skeleton != NULL ) {
906+ g_dbus_interface_skeleton_unexport ( G_DBUS_INTERFACE_SKELETON ( application -> skeleton ));
907+ g_object_unref ( application -> skeleton );
908+ application -> skeleton = NULL ;
923909 }
924910 if (application -> connection != NULL ) {
925911 g_object_unref (application -> connection );
926912 application -> connection = NULL ;
927913 }
928- if (introspection_data ) {
929- g_dbus_node_info_ref (introspection_data );
930- introspection_data = NULL ;
931- }
932914#endif /* ENABLE_DBUS */
933915
934916 g_free (application -> dot_dir );
@@ -971,17 +953,22 @@ static void ev_application_init(EvApplication* ev_application)
971953#ifdef ENABLE_DBUS
972954 ev_application -> connection = g_bus_get_sync (G_BUS_TYPE_SESSION , NULL , & error );
973955 if (ev_application -> connection != NULL ) {
974- introspection_data = g_dbus_node_info_new_for_xml (introspection_xml , NULL );
975- g_assert (introspection_data != NULL );
976-
977- ev_application -> registration_id =
978- g_dbus_connection_register_object (ev_application -> connection ,
979- APPLICATION_DBUS_OBJECT_PATH ,
980- introspection_data -> interfaces [0 ],
981- & interface_vtable ,
982- ev_application , NULL ,
983- & error );
984- if (ev_application -> registration_id == 0 ) {
956+ EvAtrilApplication * skeleton ;
957+
958+ skeleton = ev_atril_application_skeleton_new ();
959+ if (g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton ),
960+ ev_application -> connection ,
961+ APPLICATION_DBUS_OBJECT_PATH ,
962+ & error )) {
963+ ev_application -> skeleton = skeleton ;
964+ g_signal_connect (skeleton , "handle-get-window-list" ,
965+ G_CALLBACK (handle_get_window_list_cb ),
966+ ev_application );
967+ g_signal_connect (skeleton , "handle-reload" ,
968+ G_CALLBACK (handle_reload_cb ),
969+ ev_application );
970+ } else {
971+ g_object_unref (skeleton );
985972 g_printerr ("Failed to register bus object: %s\n" , error -> message );
986973 g_error_free (error );
987974 }
0 commit comments