X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-window.c;h=ece97c7415d93068e64a3056a976d56a43001fa1;hb=584f014b63c56fe3770cba9682fc21c31e09a2e9;hp=fa7a16be658f479c25f6686dd326fdd0adc3c383;hpb=3a7664146c781c8b3673fada29286837c9385e41;p=evince.git
diff --git a/shell/ev-window.c b/shell/ev-window.c
index fa7a16be..ece97c74 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -78,6 +78,7 @@
#include "ev-page-action.h"
#include "ev-password-view.h"
#include "ev-properties-dialog.h"
+#include "ev-sidebar-annotations.h"
#include "ev-sidebar-attachments.h"
#include "ev-sidebar.h"
#include "ev-sidebar-links.h"
@@ -94,6 +95,7 @@
#include "ev-window-title.h"
#include "ev-print-operation.h"
#include "ev-progress-message-area.h"
+#include "ev-annotation-properties-dialog.h"
#ifdef ENABLE_DBUS
#include "ev-media-player-keys.h"
@@ -140,6 +142,7 @@ struct _EvWindowPrivate {
GtkWidget *sidebar_links;
GtkWidget *sidebar_attachments;
GtkWidget *sidebar_layers;
+ GtkWidget *sidebar_annots;
/* Settings */
GSettings *settings;
@@ -170,9 +173,10 @@ struct _EvWindowPrivate {
GtkWidget *fullscreen_toolbar;
/* Popup view */
- GtkWidget *view_popup;
- EvLink *link;
- EvImage *image;
+ GtkWidget *view_popup;
+ EvLink *link;
+ EvImage *image;
+ EvAnnotation *annot;
/* Popup attachment */
GtkWidget *attachment_popup;
@@ -246,6 +250,7 @@ struct _EvWindowPrivate {
#define THUMBNAILS_SIDEBAR_ID "thumbnails"
#define ATTACHMENTS_SIDEBAR_ID "attachments"
#define LAYERS_SIDEBAR_ID "layers"
+#define ANNOTS_SIDEBAR_ID "annotations"
#define EV_PRINT_SETTINGS_FILE "print-settings"
#define EV_PRINT_SETTINGS_GROUP "Print Settings"
@@ -314,6 +319,8 @@ static void ev_view_popup_cmd_save_image_as (GtkAction *actio
EvWindow *window);
static void ev_view_popup_cmd_copy_image (GtkAction *action,
EvWindow *window);
+static void ev_view_popup_cmd_annot_properties (GtkAction *action,
+ EvWindow *window);
static void ev_attachment_popup_cmd_open_attachment (GtkAction *action,
EvWindow *window);
static void ev_attachment_popup_cmd_save_attachment_as (GtkAction *action,
@@ -337,6 +344,9 @@ static void ev_window_media_player_key_pressed (EvWindow *windo
const gchar *key,
gpointer user_data);
static void ev_window_update_max_min_scale (EvWindow *window);
+#ifdef ENABLE_DBUS
+static void ev_window_emit_closed (EvWindow *window);
+#endif
static guint ev_window_n_copies = 0;
@@ -930,6 +940,7 @@ setup_sidebar_from_metadata (EvWindow *window)
GtkWidget *links = window->priv->sidebar_links;
GtkWidget *thumbs = window->priv->sidebar_thumbs;
GtkWidget *attachments = window->priv->sidebar_attachments;
+ GtkWidget *annots = window->priv->sidebar_annots;
GtkWidget *layers = window->priv->sidebar_layers;
gchar *page_id;
gint sidebar_size;
@@ -960,6 +971,8 @@ setup_sidebar_from_metadata (EvWindow *window)
ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
} else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
+ } else if (strcmp (page_id, ANNOTS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), annots);
}
} else if (document) {
if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
@@ -970,6 +983,8 @@ setup_sidebar_from_metadata (EvWindow *window)
ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
} else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (annots), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), annots);
}
}
}
@@ -3296,6 +3311,8 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
ev_document_model_set_page (ev_window->priv->model, current_page);
}
+ /* TODO: warn about form fields, and annots not saved */
+
n_print_jobs = ev_window->priv->print_queue ?
g_queue_get_length (ev_window->priv->print_queue) : 0;
@@ -4405,6 +4422,8 @@ ev_window_sidebar_current_page_changed_cb (EvSidebar *ev_sidebar,
id = ATTACHMENTS_SIDEBAR_ID;
} else if (current_page == ev_window->priv->sidebar_layers) {
id = LAYERS_SIDEBAR_ID;
+ } else if (current_page == ev_window->priv->sidebar_annots) {
+ id = ANNOTS_SIDEBAR_ID;
} else {
g_assert_not_reached();
}
@@ -4523,9 +4542,18 @@ view_menu_annot_popup (EvWindow *ev_window,
GtkAction *action;
gboolean show_annot = FALSE;
+ if (ev_window->priv->annot)
+ g_object_unref (ev_window->priv->annot);
+ ev_window->priv->annot = (annot) ? g_object_ref (annot) : NULL;
+
+ action = gtk_action_group_get_action (ev_window->priv->view_popup_action_group,
+ "AnnotProperties");
+ gtk_action_set_visible (action, (annot != NULL && EV_IS_ANNOTATION_MARKUP (annot)));
+
if (annot && EV_IS_ANNOTATION_ATTACHMENT (annot)) {
- EvAttachment *attachment = EV_ANNOTATION_ATTACHMENT (annot)->attachment;
+ EvAttachment *attachment;
+ attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
if (attachment) {
show_annot = TRUE;
if (ev_window->priv->attach_list) {
@@ -4866,6 +4894,7 @@ ev_window_dispose (GObject *object)
#ifdef ENABLE_DBUS
if (priv->dbus_object_id > 0) {
+ ev_window_emit_closed (window);
g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
priv->dbus_object_id);
priv->dbus_object_id = 0;
@@ -5015,6 +5044,11 @@ ev_window_dispose (GObject *object)
priv->image = NULL;
}
+ if (priv->annot) {
+ g_object_unref (priv->annot);
+ priv->annot = NULL;
+ }
+
if (priv->attach_list) {
g_list_foreach (priv->attach_list,
(GFunc) g_object_unref,
@@ -5324,6 +5358,8 @@ static const GtkActionEntry view_popup_entries [] = {
NULL, G_CALLBACK (ev_view_popup_cmd_save_image_as) },
{ "CopyImage", NULL, N_("Copy _Image"), NULL,
NULL, G_CALLBACK (ev_view_popup_cmd_copy_image) },
+ { "AnnotProperties", NULL, N_("Annotation Propertiesâ¦"), NULL,
+ NULL, G_CALLBACK (ev_view_popup_cmd_annot_properties) }
};
static const GtkActionEntry attachment_popup_entries [] = {
@@ -5361,6 +5397,38 @@ sidebar_layers_visibility_changed (EvSidebarLayers *layers,
ev_view_reload (EV_VIEW (window->priv->view));
}
+static void
+sidebar_annots_annot_activated_cb (EvSidebarAnnotations *sidebar_annots,
+ EvMapping *annot_mapping,
+ EvWindow *window)
+{
+ ev_view_focus_annotation (EV_VIEW (window->priv->view), annot_mapping);
+}
+
+static void
+sidebar_annots_begin_annot_add (EvSidebarAnnotations *sidebar_annots,
+ EvAnnotationType annot_type,
+ EvWindow *window)
+{
+ ev_view_begin_add_annotation (EV_VIEW (window->priv->view), annot_type);
+}
+
+static void
+view_annot_added (EvView *view,
+ EvAnnotation *annot,
+ EvWindow *window)
+{
+ ev_sidebar_annotations_annot_added (EV_SIDEBAR_ANNOTATIONS (window->priv->sidebar_annots),
+ annot);
+}
+
+static void
+sidebar_annots_annot_add_cancelled (EvSidebarAnnotations *sidebar_annots,
+ EvWindow *window)
+{
+ ev_view_cancel_add_annotation (EV_VIEW (window->priv->view));
+}
+
static void
register_custom_actions (EvWindow *window, GtkActionGroup *group)
{
@@ -5972,6 +6040,67 @@ ev_view_popup_cmd_copy_image (GtkAction *action, EvWindow *window)
g_object_unref (pixbuf);
}
+static void
+ev_view_popup_cmd_annot_properties (GtkAction *action,
+ EvWindow *window)
+{
+ const gchar *author;
+ GdkColor color;
+ gdouble opacity;
+ gboolean popup_is_open;
+ EvAnnotationPropertiesDialog *dialog;
+ EvAnnotation *annot = window->priv->annot;
+ EvAnnotationsSaveMask mask = EV_ANNOTATIONS_SAVE_NONE;
+
+ if (!annot)
+ return;
+
+ dialog = EV_ANNOTATION_PROPERTIES_DIALOG (ev_annotation_properties_dialog_new_with_annotation (window->priv->annot));
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_APPLY) {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ return;
+ }
+
+ /* Set annotations changes */
+ author = ev_annotation_properties_dialog_get_author (dialog);
+ if (ev_annotation_markup_set_label (EV_ANNOTATION_MARKUP (annot), author))
+ mask |= EV_ANNOTATIONS_SAVE_LABEL;
+
+ ev_annotation_properties_dialog_get_color (dialog, &color);
+ if (ev_annotation_set_color (annot, &color))
+ mask |= EV_ANNOTATIONS_SAVE_COLOR;
+
+ opacity = ev_annotation_properties_dialog_get_opacity (dialog);
+ if (ev_annotation_markup_set_opacity (EV_ANNOTATION_MARKUP (annot), opacity))
+ mask |= EV_ANNOTATIONS_SAVE_OPACITY;
+
+ popup_is_open = ev_annotation_properties_dialog_get_popup_is_open (dialog);
+ if (ev_annotation_markup_set_popup_is_open (EV_ANNOTATION_MARKUP (annot), popup_is_open))
+ mask |= EV_ANNOTATIONS_SAVE_POPUP_IS_OPEN;
+
+ if (EV_IS_ANNOTATION_TEXT (annot)) {
+ EvAnnotationTextIcon icon;
+
+ icon = ev_annotation_properties_dialog_get_text_icon (dialog);
+ if (ev_annotation_text_set_icon (EV_ANNOTATION_TEXT (annot), icon))
+ mask |= EV_ANNOTATIONS_SAVE_TEXT_ICON;
+ }
+
+ if (mask != EV_ANNOTATIONS_SAVE_NONE) {
+ ev_document_doc_mutex_lock ();
+ ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (window->priv->document),
+ window->priv->annot,
+ mask);
+ ev_document_doc_mutex_unlock ();
+
+ /* FIXME: update annot region only */
+ ev_view_reload (EV_VIEW (window->priv->view));
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
static void
ev_attachment_popup_cmd_open_attachment (GtkAction *action, EvWindow *window)
{
@@ -6226,6 +6355,41 @@ ev_window_sync_source (EvWindow *window,
}
}
+static void
+ev_window_emit_closed (EvWindow *window)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "Closed",
+ NULL,
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal Closed: %s\n",
+ error->message);
+ g_error_free (error);
+
+ return;
+ }
+
+ /* If this is the last window call g_dbus_connection_flush_sync()
+ * to make sure the signal is emitted.
+ */
+ if (ev_application_get_n_windows (EV_APP) == 1)
+ g_dbus_connection_flush_sync (connection, NULL, NULL);
+}
+
static void
method_call_cb (GDBusConnection *connection,
const gchar *sender,
@@ -6263,6 +6427,7 @@ static const char introspection_xml[] =
""
""
""
+ ""
""
"";
@@ -6489,6 +6654,24 @@ ev_window_init (EvWindow *ev_window)
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
sidebar_widget);
+ sidebar_widget = ev_sidebar_annotations_new ();
+ ev_window->priv->sidebar_annots = sidebar_widget;
+ g_signal_connect (sidebar_widget,
+ "annot_activated",
+ G_CALLBACK (sidebar_annots_annot_activated_cb),
+ ev_window);
+ g_signal_connect (sidebar_widget,
+ "begin_annot_add",
+ G_CALLBACK (sidebar_annots_begin_annot_add),
+ ev_window);
+ g_signal_connect (sidebar_widget,
+ "annot_add_cancelled",
+ G_CALLBACK (sidebar_annots_annot_add_cancelled),
+ ev_window);
+ gtk_widget_show (sidebar_widget);
+ ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
+ sidebar_widget);
+
ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
ev_window->priv->scrolled_window =
GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
@@ -6530,6 +6713,9 @@ ev_window_init (EvWindow *ev_window)
g_signal_connect_object (ev_window->priv->view, "selection-changed",
G_CALLBACK (view_selection_changed_cb),
ev_window, 0);
+ g_signal_connect_object (ev_window->priv->view, "annot-added",
+ G_CALLBACK (view_annot_added),
+ ev_window, 0);
#ifdef ENABLE_DBUS
g_signal_connect_swapped (ev_window->priv->view, "sync-source",
G_CALLBACK (ev_window_sync_source),
@@ -6692,3 +6878,12 @@ ev_window_new (void)
return ev_window;
}
+const gchar *
+ev_window_get_dbus_object_path (EvWindow *ev_window)
+{
+#ifdef ENABLE_DBUS
+ return ev_window->priv->dbus_object_path;
+#else
+ return NULL;
+#endif
+}