+}
+
+static void
+sidebar_widget_model_set (EvSidebarLinks *ev_sidebar_links,
+ GParamSpec *pspec,
+ EvWindow *ev_window)
+{
+ GtkTreeModel *model;
+ GtkAction *action;
+
+ g_object_get (G_OBJECT (ev_sidebar_links),
+ "model", &model,
+ NULL);
+
+ action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
+ ev_page_action_set_model (EV_PAGE_ACTION (action), model);
+ g_object_unref (model);
+}
+
+static gboolean
+view_actions_focus_in_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
+{
+#ifdef ENABLE_DBUS
+ GObject *keys;
+
+ keys = ev_application_get_media_keys (EV_APP);
+ ev_media_player_keys_focused (EV_MEDIA_PLAYER_KEYS (keys));
+#endif /* ENABLE_DBUS */
+
+ update_chrome_flag (window, EV_CHROME_RAISE_TOOLBAR, FALSE);
+ ev_window_set_action_sensitive (window, "ViewToolbar", TRUE);
+
+ ev_window_set_view_accels_sensitivity (window, TRUE);
+
+ update_chrome_visibility (window);
+
+ return FALSE;
+}
+
+static gboolean
+view_actions_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EvWindow *window)
+{
+ ev_window_set_view_accels_sensitivity (window, FALSE);
+
+ return FALSE;
+}
+
+static void
+sidebar_page_main_widget_update_cb (GObject *ev_sidebar_page,
+ GParamSpec *pspec,
+ EvWindow *ev_window)
+{
+ GtkWidget *widget;
+
+ g_object_get (ev_sidebar_page, "main_widget", &widget, NULL);
+
+ if (widget != NULL) {
+ g_signal_connect_object (widget, "focus_in_event",
+ G_CALLBACK (view_actions_focus_in_cb),
+ ev_window, 0);
+ g_signal_connect_object (widget, "focus_out_event",
+ G_CALLBACK (view_actions_focus_out_cb),
+ ev_window, 0);
+ g_object_unref (widget);
+ }
+}
+
+static gboolean
+window_state_event_cb (EvWindow *window, GdkEventWindowState *event, gpointer dummy)
+{
+ if (!(event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN)) {
+ gboolean maximized;
+
+ maximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
+ if (!ev_window_is_empty (window))
+ ev_metadata_manager_set_boolean (window->priv->uri, "window_maximized", maximized);
+ }
+
+ return FALSE;
+}
+
+static gboolean
+window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
+{
+ char *uri = window->priv->uri;
+ GdkWindowState state;
+ int x, y, width, height, document_width, document_height;
+
+ state = gdk_window_get_state (GTK_WIDGET (window)->window);
+
+ if (!(state & GDK_WINDOW_STATE_FULLSCREEN)) {
+ gtk_window_get_position (GTK_WINDOW (window), &x, &y);
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+
+ if (!ev_window_is_empty (window) && window->priv->page_cache) {
+ ev_page_cache_get_max_width (window->priv->page_cache,
+ 0, 1.0,
+ &document_width);
+ ev_page_cache_get_max_height (window->priv->page_cache,
+ 0, 1.0,
+ &document_height);
+ ev_metadata_manager_set_double (uri, "window_width_ratio",
+ (double)width / document_width);
+ ev_metadata_manager_set_double (uri, "window_height_ratio",
+ (double)height / document_height);
+
+ ev_metadata_manager_set_int (uri, "window_x", x);
+ ev_metadata_manager_set_int (uri, "window_y", y);
+ ev_metadata_manager_set_int (uri, "window_width", width);
+ ev_metadata_manager_set_int (uri, "window_height", height);
+ }
+ }
+
+ return FALSE;
+}
+
+static void
+launch_action (EvWindow *window, EvLinkAction *action)
+{
+ const char *filename = ev_link_action_get_filename (action);
+ const char *content_type;
+ GAppInfo *app_info;
+ GFileInfo *file_info;
+ GFile *file;
+ GList *file_list = NULL;
+
+ if (filename == NULL)
+ return;
+
+ if (g_path_is_absolute (filename)) {
+ file = g_file_new_for_path (filename);
+ } else {
+ GFile *base_file;
+
+ base_file = g_file_new_for_uri (window->priv->uri);
+ file = g_file_resolve_relative_path (base_file,
+ filename);
+
+ g_object_unref (base_file);
+ }
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ if (file_info == NULL) {
+ g_object_unref (file);
+ return;
+ }
+
+ content_type = g_file_info_get_content_type (file_info);
+ app_info = g_app_info_get_default_for_type (content_type, TRUE);
+
+ file_list = g_list_append (file_list, file);
+
+ /* FIXME: should we use a GAppLaunchContext? */
+ g_app_info_launch (app_info, file_list,
+ NULL, NULL);
+
+ g_list_free (file_list);
+ g_object_unref (app_info);
+ g_object_unref (file_info);
+ g_object_unref (file);
+
+ /* According to the PDF spec filename can be an executable. I'm not sure
+ allowing to launch executables is a good idea though. -- marco */
+}
+
+static void
+launch_external_uri (EvWindow *window, EvLinkAction *action)
+{
+ const gchar *uri = ev_link_action_get_uri (action);
+ GAppLaunchContext *context = NULL;
+ GError *error = NULL;
+ gboolean ret;
+
+#if GTK_CHECK_VERSION (2, 14, 0)
+ context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+ gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
+ gtk_window_get_screen (GTK_WINDOW (window)));
+ gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context),
+ GDK_CURRENT_TIME);
+#endif
+
+ if (!g_strstr_len (uri, strlen (uri), "://")) {
+ gchar *http;
+
+ /* Not a valid uri, assuming it's http */
+ http = g_strdup_printf ("http://%s", uri);
+ ret = g_app_info_launch_default_for_uri (http, NULL, &error);
+ g_free (http);
+ } else {
+ ret = g_app_info_launch_default_for_uri (uri, NULL, &error);
+ }
+
+ if (ret == FALSE) {
+ ev_window_error_message (GTK_WINDOW (window),
+ _("Unable to open external link"),
+ error);
+ g_error_free (error);
+ }
+}
+
+static void
+open_remote_link (EvWindow *window, EvLinkAction *action)
+{
+ gchar *uri;
+ gchar *dir;
+
+ dir = g_path_get_dirname (window->priv->uri);
+
+ uri = g_build_filename (dir, ev_link_action_get_filename (action),
+ NULL);
+ g_free (dir);
+
+ ev_application_open_uri_at_dest (EV_APP, uri,
+ gtk_window_get_screen (GTK_WINDOW (window)),
+ ev_link_action_get_dest (action),
+ 0,
+ NULL,
+ FALSE,
+ NULL,
+ GDK_CURRENT_TIME);
+
+ g_free (uri);
+}
+
+static void
+do_action_named (EvWindow *window, EvLinkAction *action)
+{
+ const gchar *name = ev_link_action_get_name (action);
+
+ if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
+ ev_window_cmd_go_first_page (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
+ ev_window_cmd_go_previous_page (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
+ ev_window_cmd_go_next_page (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
+ ev_window_cmd_go_last_page (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
+ ev_window_cmd_focus_page_selector (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "Find") == 0) {
+ ev_window_cmd_edit_find (NULL, window);
+ } else if (g_ascii_strcasecmp (name, "Close") == 0) {
+ ev_window_cmd_file_close_window (NULL, window);
+ } else {
+ g_warning ("Unimplemented named action: %s, please post a "
+ "bug report in Evince bugzilla "
+ "(http://bugzilla.gnome.org) with a testcase.",
+ name);
+ }
+}
+
+static void
+view_external_link_cb (EvView *view, EvLinkAction *action, EvWindow *window)
+{
+ switch (ev_link_action_get_action_type (action)) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST: {
+ EvLinkDest *dest;
+
+ dest = ev_link_action_get_dest (action);
+ if (!dest)
+ return;
+
+ ev_window_cmd_file_open_copy_at_dest (window, dest);
+ }
+ break;
+ case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
+ launch_external_uri (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_LAUNCH:
+ launch_action (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
+ open_remote_link (window, action);
+ break;
+ case EV_LINK_ACTION_TYPE_NAMED:
+ do_action_named (window, action);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+ev_view_popup_cmd_open_link (GtkAction *action, EvWindow *window)
+{
+ ev_view_handle_link (EV_VIEW (window->priv->view), window->priv->link);
+}