X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fmain.c;h=ab4b8dfb9ab06fbda8701680168cd052a576eb66;hb=85026726e8c77369cceb9ed1ca459266cefb6e9d;hp=2b926c967c8ce5f76387acb97a944d1a5c241a6b;hpb=766adb9bff7a5c8ada0d18cafd3643e647fb6f23;p=evince.git diff --git a/shell/main.c b/shell/main.c index 2b926c96..ab4b8dfb 100644 --- a/shell/main.c +++ b/shell/main.c @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -41,9 +41,6 @@ #endif /* WITH_SMCLIENT */ #ifdef G_OS_WIN32 -#ifdef DATADIR -#undef DATADIR -#endif #include #include #if !(_WIN32_WINNT >= 0x0500) @@ -54,6 +51,7 @@ static gchar *ev_page_label; static gchar *ev_find_string; +static gint ev_page_index = 0; static gboolean preview_mode = FALSE; static gboolean fullscreen_mode = FALSE; static gboolean presentation_mode = FALSE; @@ -61,6 +59,7 @@ static gboolean unlink_temp_file = FALSE; static gchar *print_settings; static const char **file_arguments = NULL; + static gboolean option_version_cb (const gchar *option_name, const gchar *value, @@ -75,7 +74,8 @@ option_version_cb (const gchar *option_name, static const GOptionEntry goption_options[] = { - { "page-label", 'p', 0, G_OPTION_ARG_STRING, &ev_page_label, N_("The page of the document to display."), N_("PAGE")}, + { "page-label", 'p', 0, G_OPTION_ARG_STRING, &ev_page_label, N_("The page label of the document to display."), N_("PAGE")}, + { "page-index", 'i', 0, G_OPTION_ARG_INT, &ev_page_index, N_("The page number of the document to display."), N_("NUMBER")}, { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen_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 }, @@ -92,8 +92,6 @@ launch_previewer (void) { GString *cmd_str; gchar *cmd; - gint argc; - gchar **argv; gboolean retval = FALSE; GError *error = NULL; @@ -123,16 +121,16 @@ launch_previewer (void) } cmd = g_string_free (cmd_str, FALSE); - g_shell_parse_argv (cmd, &argc, &argv, &error); - g_free (cmd); - + if (!error) { - retval = gdk_spawn_on_screen (gdk_screen_get_default (), - NULL, argv, NULL, - G_SPAWN_SEARCH_PATH, - NULL, NULL, NULL, - &error); - g_strfreev (argv); + GAppInfo *app; + + app = g_app_info_create_from_commandline (cmd, NULL, 0, &error); + + if (app != NULL) { + retval = g_app_info_launch (app, NULL, NULL, &error); + g_object_unref (app); + } } if (error) { @@ -140,9 +138,33 @@ launch_previewer (void) g_error_free (error); } + g_free (cmd); + return retval; } +static gchar * +get_label_from_filename (const gchar *filename) +{ + GFile *file; + gchar *label; + gboolean exists; + + label = g_strrstr (filename, "#"); + if (!label) + return NULL; + + /* Filename contains a #, check + * whether it's part of the path + * or a label + */ + file = g_file_new_for_commandline_arg (filename); + exists = g_file_query_exists (file, NULL); + g_object_unref (file); + + return exists ? NULL : label; +} + static void load_files (const char **files) { @@ -159,6 +181,8 @@ load_files (const char **files) if (ev_page_label) global_dest = ev_link_dest_new_page_label (ev_page_label); + else if (ev_page_index) + global_dest = ev_link_dest_new_page (MAX (0, ev_page_index - 1)); if (fullscreen_mode) mode = EV_WINDOW_MODE_FULLSCREEN; @@ -166,13 +190,24 @@ load_files (const char **files) mode = EV_WINDOW_MODE_PRESENTATION; for (i = 0; files[i]; i++) { + const gchar *filename; gchar *uri; gchar *label; GFile *file; EvLinkDest *dest = NULL; const gchar *app_uri; - file = g_file_new_for_commandline_arg (files[i]); + filename = files[i]; + label = get_label_from_filename (filename); + if (label) { + *label = 0; + label++; + dest = ev_link_dest_new_page_label (label); + } else if (global_dest) { + dest = g_object_ref (global_dest); + } + + file = g_file_new_for_commandline_arg (filename); uri = g_file_get_uri (file); g_object_unref (file); @@ -182,14 +217,7 @@ load_files (const char **files) continue; } - label = strchr (uri, '#'); - if (label) { - *label = 0; - label++; - dest = ev_link_dest_new_page_label (label); - } else if (global_dest) { - dest = g_object_ref (global_dest); - } + ev_application_open_uri_at_dest (EV_APP, uri, screen, dest, mode, ev_find_string, @@ -238,7 +266,7 @@ main (int argc, char *argv[]) #ifdef ENABLE_NLS /* Initialize the i18n stuff */ - bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bindtextdomain (GETTEXT_PACKAGE, ev_get_locale_dir()); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif @@ -285,14 +313,13 @@ main (int argc, char *argv[]) ev_application_load_session (EV_APP); load_files (file_arguments); - if (ev_application_has_window (EV_APP)) { - /* Change directory so we don't prevent unmounting in case the initial cwd - * is on an external device (see bug #575436) - */ - g_chdir (g_get_home_dir ()); - gtk_main (); - } + /* Change directory so we don't prevent unmounting in case the initial cwd + * is on an external device (see bug #575436) + */ + g_chdir (g_get_home_dir ()); + + gtk_main (); ev_shutdown (); ev_stock_icons_shutdown ();