From e03ccc6269d7e687b4f5a67a0c07a014f301930b Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sun, 25 Nov 2007 16:54:00 +0000 Subject: Add a command line option for search. Fixes bug #497710. 2007-11-25 Carlos Garcia Campos * shell/ev-application.[ch]: (get_find_string_from_args), (ev_application_open_uri_at_dest), (ev_application_open_uri), (ev_application_open_uri_list): * shell/ev-jobs.[ch]: (ev_job_load_dispose), (ev_job_load_new): * shell/ev-window.[ch]: (ev_window_load_job_cb), (ev_window_open_uri), (ev_window_cmd_file_open_copy_at_dest), (ev_window_cmd_recent_file_activate), (ev_window_open_recent_action_item_activated), (ev_window_print_send), (open_remote_link): * shell/main.c: (arguments_parse): Add a command line option for search. Fixes bug #497710. svn path=/trunk/; revision=2746 --- (limited to 'shell') diff --git a/shell/ev-application.c b/shell/ev-application.c index deac0ed..2be350e 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -322,6 +322,18 @@ get_destination_from_args (GHashTable *args) return dest; } +static const gchar * +get_find_string_from_args (GHashTable *args) +{ + GValue *value = NULL; + + g_assert (args != NULL); + + value = g_hash_table_lookup (args, "find-string"); + + return value ? g_value_get_string (value) : NULL; +} + /** * get_unlink_temp_file_from_args: * @args: a #GHashTable with data passed to the application. @@ -520,6 +532,7 @@ ev_application_open_uri_at_dest (EvApplication *application, GdkScreen *screen, EvLinkDest *dest, EvWindowRunMode mode, + const gchar *search_string, gboolean unlink_temp_file, const gchar *print_settings, guint timestamp) @@ -545,7 +558,7 @@ ev_application_open_uri_at_dest (EvApplication *application, /* We need to load uri before showing the window, so we can restore window size without flickering */ - ev_window_open_uri (new_window, uri, dest, mode, + ev_window_open_uri (new_window, uri, dest, mode, search_string, unlink_temp_file, print_settings); ev_document_fc_mutex_lock (); @@ -573,6 +586,7 @@ ev_application_open_uri (EvApplication *application, { EvLinkDest *dest = NULL; EvWindowRunMode mode = EV_WINDOW_MODE_NORMAL; + const gchar *search_string = NULL; gboolean unlink_temp_file = FALSE; const gchar *print_settings = NULL; GdkScreen *screen = NULL; @@ -581,13 +595,15 @@ ev_application_open_uri (EvApplication *application, screen = get_screen_from_args (args); dest = get_destination_from_args (args); mode = get_window_run_mode_from_args (args); + search_string = get_find_string_from_args (args); unlink_temp_file = (mode == EV_WINDOW_MODE_PREVIEW && get_unlink_temp_file_from_args (args)); print_settings = get_print_settings_from_args (args); } ev_application_open_uri_at_dest (application, uri, screen, - dest, mode, unlink_temp_file, + dest, mode, search_string, + unlink_temp_file, print_settings, timestamp); if (dest) @@ -606,8 +622,8 @@ ev_application_open_uri_list (EvApplication *application, for (l = uri_list; l != NULL; l = l->next) { ev_application_open_uri_at_dest (application, (char *)l->data, - screen, NULL, 0, FALSE, - NULL, timestamp); + screen, NULL, 0, NULL, + FALSE, NULL, timestamp); } } diff --git a/shell/ev-application.h b/shell/ev-application.h index 199fd55..7b7588a 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -72,6 +72,7 @@ void ev_application_open_uri_at_dest (EvApplication *applicati GdkScreen *screen, EvLinkDest *dest, EvWindowRunMode mode, + const gchar *search_string, gboolean unlink_temp_file, const gchar *print_settings, guint32 timestamp); diff --git a/shell/ev-jobs.c b/shell/ev-jobs.c index 8c59af8..4bb0bf6 100644 --- a/shell/ev-jobs.c +++ b/shell/ev-jobs.c @@ -499,6 +499,11 @@ ev_job_load_dispose (GObject *object) job->dest = NULL; } + if (job->search_string) { + g_free (job->search_string); + job->search_string = NULL; + } + (* G_OBJECT_CLASS (ev_job_load_parent_class)->dispose) (object); } @@ -514,7 +519,10 @@ ev_job_load_class_init (EvJobLoadClass *class) EvJob * -ev_job_load_new (const gchar *uri, EvLinkDest *dest, EvWindowRunMode mode) +ev_job_load_new (const gchar *uri, + EvLinkDest *dest, + EvWindowRunMode mode, + const gchar *search_string) { EvJobLoad *job; @@ -525,6 +533,8 @@ ev_job_load_new (const gchar *uri, EvLinkDest *dest, EvWindowRunMode mode) job->dest = g_object_ref (dest); job->mode = mode; + if (search_string) + job->search_string = g_strdup (search_string); return EV_JOB (job); } diff --git a/shell/ev-jobs.h b/shell/ev-jobs.h index 6a35c83..c6d73a1 100644 --- a/shell/ev-jobs.h +++ b/shell/ev-jobs.h @@ -189,6 +189,7 @@ struct _EvJobLoad EvLinkDest *dest; EvWindowRunMode mode; + gchar *search_string; GError *error; gchar *uri; }; @@ -276,7 +277,8 @@ void ev_job_fonts_run (EvJobFonts *fonts); GType ev_job_load_get_type (void) G_GNUC_CONST; EvJob *ev_job_load_new (const gchar *uri, EvLinkDest *dest, - EvWindowRunMode mode); + EvWindowRunMode mode, + const gchar *search_string); void ev_job_load_set_uri (EvJobLoad *load, const gchar *uri); void ev_job_load_run (EvJobLoad *load); diff --git a/shell/ev-window.c b/shell/ev-window.c index 6c15e79..c53b772 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -265,6 +265,8 @@ static void ev_window_cmd_view_page_width (GtkAction *action, static void view_handle_link_cb (EvView *view, EvLink *link, EvWindow *window); +static void ev_window_cmd_edit_find (GtkAction *action, + EvWindow *ev_window); static void find_bar_search_changed_cb (EggFindBar *find_bar, GParamSpec *param, EvWindow *ev_window); @@ -1342,6 +1344,10 @@ ev_window_load_job_cb (EvJobLoad *job, find_bar_search_changed_cb (EGG_FIND_BAR (ev_window->priv->find_bar), NULL, ev_window); } + } else if (job->search_string && EV_IS_DOCUMENT_FIND (document)) { + ev_window_cmd_edit_find (NULL, ev_window); + egg_find_bar_set_search_string (EGG_FIND_BAR (ev_window->priv->find_bar), + job->search_string); } ev_window_clear_load_job (ev_window); @@ -1448,6 +1454,7 @@ ev_window_open_uri (EvWindow *ev_window, const char *uri, EvLinkDest *dest, EvWindowRunMode mode, + const gchar *search_string, gboolean unlink_temp_file, const gchar *print_settings) { @@ -1478,7 +1485,7 @@ ev_window_open_uri (EvWindow *ev_window, setup_size_from_metadata (ev_window); - ev_window->priv->load_job = ev_job_load_new (uri, dest, mode); + ev_window->priv->load_job = ev_job_load_new (uri, dest, mode, search_string); g_signal_connect (ev_window->priv->load_job, "finished", G_CALLBACK (ev_window_load_job_cb), @@ -1680,6 +1687,7 @@ ev_window_cmd_file_open_copy_at_dest (EvWindow *window, EvLinkDest *dest) gtk_window_get_screen (GTK_WINDOW (window)), dest, 0, + NULL, TRUE, NULL, GDK_CURRENT_TIME); @@ -1715,7 +1723,7 @@ ev_window_cmd_recent_file_activate (GtkAction *action, ev_application_open_uri_at_dest (EV_APP, uri, gtk_window_get_screen (GTK_WINDOW (window)), - NULL, 0, FALSE, NULL, + NULL, 0, NULL, FALSE, NULL, GDK_CURRENT_TIME); } @@ -1726,7 +1734,7 @@ ev_window_open_recent_action_item_activated (EvOpenRecentAction *action, { ev_application_open_uri_at_dest (EV_APP, uri, gtk_window_get_screen (GTK_WINDOW (window)), - NULL, 0, FALSE, NULL, + NULL, 0, NULL, FALSE, NULL, GDK_CURRENT_TIME); } @@ -2186,6 +2194,7 @@ ev_window_print_send (EvWindow *window, gtk_window_get_screen (GTK_WINDOW (window)), NULL, EV_WINDOW_MODE_PREVIEW, + NULL, TRUE, print_settings_file, GDK_CURRENT_TIME); @@ -3242,7 +3251,7 @@ ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window) gchar *uri; uri = g_strdup (ev_window->priv->uri); - ev_window_open_uri (ev_window, uri, NULL, 0, FALSE, NULL); + ev_window_open_uri (ev_window, uri, NULL, 0, NULL, FALSE, NULL); g_free (uri); } @@ -4740,6 +4749,7 @@ open_remote_link (EvWindow *window, EvLinkAction *action) gtk_window_get_screen (GTK_WINDOW (window)), ev_link_action_get_dest (action), 0, + NULL, FALSE, NULL, GDK_CURRENT_TIME); diff --git a/shell/ev-window.h b/shell/ev-window.h index 0b8158f..863f543 100644 --- a/shell/ev-window.h +++ b/shell/ev-window.h @@ -78,9 +78,11 @@ void ev_window_open_uri (EvWindow *ev_window, const char *uri, EvLinkDest *dest, EvWindowRunMode mode, + const gchar *search_string, gboolean unlink_temp_file, const gchar *print_settings); gboolean ev_window_is_empty (const EvWindow *ev_window); + #ifdef WITH_PRINT void ev_window_print_range (EvWindow *ev_window, int first_page, diff --git a/shell/main.c b/shell/main.c index cd64293..b7362e0 100644 --- a/shell/main.c +++ b/shell/main.c @@ -47,6 +47,7 @@ #include "ev-file-helpers.h" static gchar *ev_page_label; +static gchar *ev_find_string; static gboolean preview_mode = FALSE; static gboolean fullscren_mode = FALSE; static gboolean presentation_mode = FALSE; @@ -60,6 +61,7 @@ static const GOptionEntry goption_options[] = { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscren_mode, N_("Run evince in fullscreen mode"), NULL }, { "presentation", 's', 0, G_OPTION_ARG_NONE, &presentation_mode, N_("Run evince in presentation mode"), NULL }, { "preview", 'w', 0, G_OPTION_ARG_NONE, &preview_mode, N_("Run evince as a previewer"), NULL }, + { "find", 'l', 0, G_OPTION_ARG_STRING, &ev_find_string, N_("The word or phrase to find in the document"), N_("STRING")}, { "unlink-tempfile", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &unlink_temp_file, NULL, NULL }, { "print-settings", 't', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME, &print_settings, NULL, NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &file_arguments, NULL, N_("[FILE...]") }, @@ -134,6 +136,17 @@ arguments_parse (void) ev_page_label = NULL; } + if (ev_find_string) { + value = g_new0 (GValue, 1); + g_value_init (value, G_TYPE_STRING); + g_value_set_string (value, ev_find_string); + + g_hash_table_insert (args, g_strdup ("find-string"), value); + + g_free (ev_find_string); + ev_page_label = NULL; + } + if (fullscren_mode) mode = EV_WINDOW_MODE_FULLSCREEN; else if (presentation_mode) -- cgit v0.9.1