[evince/wip/recent-view: 5/6] ev-window: Integrate the recent view



commit ef68c71e6925bee59dc90aa74640746b40162caa
Author: Aakash Goenka <aakash goenka gmail com>
Date:   Tue May 6 17:22:39 2014 -0700

    ev-window: Integrate the recent view

 shell/ev-application.c |    1 +
 shell/ev-window.c      |  135 ++++++++++++++++++++++++++++++++++++++++++++++-
 shell/ev-window.h      |    3 +-
 3 files changed, 135 insertions(+), 4 deletions(-)
---
diff --git a/shell/ev-application.c b/shell/ev-application.c
index 475dfaf..517e785 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -655,6 +655,7 @@ ev_application_open_window (EvApplication *application,
                            guint32        timestamp)
 {
        GtkWidget *new_window = ev_window_new ();
+       ev_window_show_recent_view (EV_WINDOW (new_window));
 #ifdef GDK_WINDOWING_X11
        GdkWindow *gdk_window;
 #endif
diff --git a/shell/ev-window.c b/shell/ev-window.c
index 3cfafdc..efa8c86 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -51,7 +51,6 @@
 #include "ev-document-images.h"
 #include "ev-document-links.h"
 #include "ev-document-annotations.h"
-#include "ev-document-type-builtins.h"
 #include "ev-document-misc.h"
 #include "ev-file-exporter.h"
 #include "ev-file-helpers.h"
@@ -91,6 +90,8 @@
 #include "ev-bookmark-action.h"
 #include "ev-zoom-action.h"
 #include "ev-toolbar-main.h"
+#include "ev-recent-view.h"
+#include "ev-recent-view-toolbar.h"
 
 #ifdef ENABLE_DBUS
 #include "ev-gdbus-generated.h"
@@ -171,6 +172,7 @@ struct _EvWindowPrivate {
 
        /* UI Builders */
        GtkActionGroup   *action_group;
+       GtkActionGroup   *recent_view_toolbar_action_group;
        GtkActionGroup   *view_popup_action_group;
        GtkActionGroup   *attachment_popup_action_group;
        GtkActionGroup   *zoom_selector_popup_action_group;
@@ -191,6 +193,10 @@ struct _EvWindowPrivate {
        GtkWidget    *attachment_popup;
        GList        *attach_list;
 
+       /* For bookshelf view of recent items*/
+       EvRecentView *recent_view;
+       GtkWidget *recent_view_toolbar;
+       
        /* Document */
        EvDocumentModel *model;
        char *uri;
@@ -381,6 +387,10 @@ static void     ev_window_setup_bookmarks               (EvWindow         *windo
 static void     ev_window_show_find_bar                 (EvWindow         *ev_window,
                                                         gboolean          restart);
 static void     ev_window_close_find_bar                (EvWindow         *ev_window);
+static void     ev_window_swap_out_recent_view_if_needed (EvWindow         *ev_window);
+static void     recent_view_item_activated_cb           (EvRecentView     *recent_view,
+                                                         const char       *uri,
+                                                         EvWindow         *ev_window);
 
 static gchar *nautilus_sendto = NULL;
 
@@ -420,7 +430,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
        gboolean has_pages = FALSE;
        gboolean can_find = FALSE;
 
-       if (document) {
+       if (document && !ev_window->priv->recent_view) {
                has_document = TRUE;
                has_pages = ev_document_get_n_pages (document) > 0;
                info = ev_document_get_info (document);
@@ -495,6 +505,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
        /* Toolbar-specific actions: */
        ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
        ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION,  has_pages);
+       ev_window_set_action_sensitive (ev_window, HISTORY_ACTION, has_document);
 
         ev_window_update_actions_sensitivity (ev_window);
 }
@@ -508,14 +519,20 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
        gboolean presentation_mode;
        gboolean can_find_in_page = FALSE;
        gboolean dual_mode = FALSE;
+       gboolean fullscreen_mode = FALSE;
 
-       if (ev_window->priv->document) {
+       if (ev_window->priv->document && !ev_window->priv->recent_view) {
                page = ev_document_model_get_page (ev_window->priv->model);
                n_pages = ev_document_get_n_pages (ev_window->priv->document);
                has_pages = n_pages > 0;
                dual_mode = ev_document_model_get_dual_page (ev_window->priv->model);
        }
 
+       fullscreen_mode = ev_document_model_get_fullscreen (ev_window->priv->model);
+       ev_window_set_action_sensitive (ev_window, "RecentViewShow",
+                                       ev_window->priv->document ||
+                                       !ev_window->priv->recent_view &&
+                                       !fullscreen_mode);
        can_find_in_page = (ev_window->priv->find_job &&
                            ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
 
@@ -1658,6 +1675,7 @@ ev_window_load_job_cb (EvJob *job,
        g_assert (job_load->uri);
 
        ev_window_hide_loading_message (ev_window);
+       ev_window_swap_out_recent_view_if_needed (ev_window);
 
        /* Success! */
        if (!ev_job_is_failed (job)) {
@@ -2189,6 +2207,7 @@ ev_window_open_document (EvWindow       *ev_window,
        ev_window_close_dialogs (ev_window);
        ev_window_clear_load_job (ev_window);
        ev_window_clear_local_uri (ev_window);
+       ev_window_swap_out_recent_view_if_needed (ev_window);
 
        if (ev_window->priv->monitor) {
                g_object_unref (ev_window->priv->monitor);
@@ -4227,6 +4246,7 @@ ev_window_run_fullscreen (EvWindow *window)
 
        if (window->priv->metadata && !ev_window_is_empty (window))
                ev_metadata_set_boolean (window->priv->metadata, "fullscreen", TRUE);
+       ev_window_update_actions_sensitivity (window);
 }
 
 static void
@@ -4273,6 +4293,7 @@ ev_window_stop_fullscreen (EvWindow *window,
 
        if (window->priv->metadata && !ev_window_is_empty (window))
                ev_metadata_set_boolean (window->priv->metadata, "fullscreen", FALSE);
+       ev_window_update_actions_sensitivity (window);
 }
 
 static void
@@ -4699,6 +4720,21 @@ ev_window_cmd_bookmark_activate (GtkAction *action,
        ev_document_model_set_page (window->priv->model, page);
 }
 
+static void
+ev_window_cmd_show_recent_view (GtkAction *action,
+                                EvWindow  *ev_window)
+{
+       ev_window_show_recent_view (ev_window);
+}
+
+static void
+ev_window_cmd_hide_recent_view (GtkAction *action,
+                                EvWindow  *ev_window)
+{
+       if (ev_window->priv->uri)
+               ev_window_swap_out_recent_view_if_needed (ev_window);
+}
+
 static gint
 compare_bookmarks (EvBookmark *a,
                   EvBookmark *b)
@@ -5352,6 +5388,32 @@ find_sidebar_result_activated_cb (EvFindSidebar *find_sidebar,
 }
 
 static void
+ev_window_swap_out_recent_view_if_needed (EvWindow *ev_window)
+{
+       if (ev_window->priv->recent_view)
+       {
+               gtk_widget_hide (GTK_WIDGET (ev_window->priv->recent_view));
+               gtk_widget_hide (GTK_WIDGET (ev_window->priv->recent_view_toolbar));
+       }
+       gtk_widget_show (ev_window->priv->hpaned);
+       gtk_widget_show (ev_window->priv->toolbar);
+}
+
+static void
+recent_view_item_activated_cb (EvRecentView *recent_view,
+                               const char   *uri,
+                               EvWindow     *ev_window)
+{
+       if (ev_window->priv->uri && g_strcmp0 (ev_window->priv->uri, uri) == 0) {
+               ev_window_swap_out_recent_view_if_needed (ev_window);
+               return;
+       }
+       ev_application_open_uri_at_dest (EV_APP, uri,
+                                        gtk_window_get_screen (GTK_WINDOW (ev_window)),
+                                        NULL, 0, NULL, gtk_get_current_event_time ());
+}
+
+static void
 ev_window_update_find_status_message (EvWindow *ev_window)
 {
        gchar *message;
@@ -5806,6 +5868,9 @@ ev_window_dispose (GObject *object)
                priv->action_group = NULL;
        }
 
+       if (priv->recent_view_toolbar_action_group) {
+               g_clear_object (&priv->recent_view_toolbar_action_group);
+       }
        if (priv->view_popup_action_group) {
                g_object_unref (priv->view_popup_action_group);
                priv->view_popup_action_group = NULL;
@@ -6081,6 +6146,11 @@ static const GtkActionEntry entries[] = {
        { "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
          G_CALLBACK (ev_window_cmd_view_autoscroll) },
 
+       /* View of recent documents */
+       { "RecentViewShow", "view-grid-symbolic", N_("Recent Documents"), NULL,
+         N_("Show recent documents"),
+         G_CALLBACK (ev_window_cmd_show_recent_view) },
+
         /* Go menu */
         { "GoBackHistory", NULL, "", "<alt>P", NULL,
           G_CALLBACK (ev_window_cmd_go_back_history) },
@@ -6240,6 +6310,20 @@ static const GtkToggleActionEntry zoom_selector_popup_actions[] = {
          G_CALLBACK (ev_window_cmd_view_zoom_automatic) }
 };
 
+/* Items for the recent view toolbar */
+static const GtkActionEntry recent_view_toolbar_entries [] = {
+       { "RecentViewHide", "view-grid-symbolic", N_("Recent Documents"), NULL,
+         N_("Hide recent documents"),
+         G_CALLBACK (ev_window_cmd_hide_recent_view) },
+
+       { "ToolbarOpenDocument", "document-open-symbolic", N_("_Open…"), NULL,
+         N_("Open an existing document"),
+         G_CALLBACK (ev_window_cmd_file_open) },
+       { "ToolbarAbout", "dialog-information-symbolic", N_("_About"), NULL,
+         N_("About "),
+         G_CALLBACK (ev_window_cmd_help_about) },
+};
+
 static void
 sidebar_links_link_activated_cb (EvSidebarLinks *sidebar_links, EvLink *link, EvWindow *window)
 {
@@ -7398,6 +7482,12 @@ ev_window_init (EvWindow *ev_window)
                gtk_ui_manager_get_accel_group (ev_window->priv->ui_manager);
        gtk_window_add_accel_group (GTK_WINDOW (ev_window), accel_group);
 
+       action_group = gtk_action_group_new ("RecentViewToolbarActions");
+       ev_window->priv->recent_view_toolbar_action_group = action_group;
+       gtk_action_group_set_translation_domain (action_group, NULL);
+       gtk_action_group_add_actions (action_group, recent_view_toolbar_entries,
+                                     G_N_ELEMENTS (recent_view_toolbar_entries), ev_window);
+
        action_group = gtk_action_group_new ("ViewPopupActions");
        ev_window->priv->view_popup_action_group = action_group;
        gtk_action_group_set_translation_domain (action_group, NULL);
@@ -7466,6 +7556,13 @@ ev_window_init (EvWindow *ev_window)
        gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
                            ev_window->priv->find_bar,
                            FALSE, TRUE, 0);
+       
+       ev_window->priv->recent_view_toolbar = ev_recent_view_toolbar_new (ev_window);
+       gtk_widget_set_halign (ev_window->priv->recent_view_toolbar, GTK_ALIGN_FILL);
+       gtk_widget_set_valign (ev_window->priv->recent_view_toolbar, GTK_ALIGN_START);
+       gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
+                           ev_window->priv->recent_view_toolbar,
+                           FALSE, TRUE, 0);
 
        /* Add the main area */
        ev_window->priv->hpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
@@ -7793,6 +7890,30 @@ ev_window_new (void)
        return ev_window;
 }
 
+void
+ev_window_show_recent_view (EvWindow *ev_window)
+{
+       GtkAction *action = gtk_action_group_get_action (ev_window->priv->recent_view_toolbar_action_group,
+                                                        "RecentViewHide");
+       gtk_widget_hide (ev_window->priv->hpaned);
+       gtk_widget_hide (ev_window->priv->toolbar);
+       gtk_widget_hide (ev_window->priv->find_bar);
+       if (!ev_window->priv->recent_view) {
+               ev_window->priv->recent_view = EV_RECENT_VIEW (ev_recent_view_new ());
+               g_signal_connect_object (ev_window->priv->recent_view,
+                                        "item-activated",
+                                        G_CALLBACK (recent_view_item_activated_cb),
+                                        ev_window, 0);
+               gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
+                                   GTK_WIDGET (ev_window->priv->recent_view),
+                                   TRUE, TRUE, 0);
+       }
+
+       gtk_action_set_sensitive (action, ev_window->priv->document != NULL);
+       gtk_widget_show (ev_window->priv->recent_view_toolbar);
+       gtk_widget_show (GTK_WIDGET (ev_window->priv->recent_view));
+}
+
 const gchar *
 ev_window_get_dbus_object_path (EvWindow *ev_window)
 {
@@ -7826,3 +7947,11 @@ ev_window_get_zoom_selector_action_group (EvWindow *ev_window)
 
        return ev_window->priv->zoom_selector_popup_action_group;
 }
+
+GtkActionGroup *
+ev_window_get_recent_view_toolbar_action_group (EvWindow *ev_window)
+{
+       g_return_val_if_fail (EV_WINDOW (ev_window), NULL);
+
+       return ev_window->priv->recent_view_toolbar_action_group;
+}
diff --git a/shell/ev-window.h b/shell/ev-window.h
index fd2d0b5..27adcfa 100644
--- a/shell/ev-window.h
+++ b/shell/ev-window.h
@@ -89,7 +89,8 @@ const gchar    *ev_window_get_dbus_object_path           (EvWindow       *ev_win
 GtkUIManager   *ev_window_get_ui_manager                 (EvWindow       *ev_window);
 GtkActionGroup *ev_window_get_main_action_group          (EvWindow       *ev_window);
 GtkActionGroup *ev_window_get_zoom_selector_action_group (EvWindow       *ev_window);
-
+void            ev_window_show_recent_view               (EvWindow       *ev_window);
+GtkActionGroup *ev_window_get_recent_view_toolbar_action_group (EvWindow     *ev_window);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]