]> www.fi.muni.cz Git - evince.git/blobdiff - shell/main.c
[windows] Fix localization on Windows
[evince.git] / shell / main.c
index 078b421e6d2f72608be4dc0d8fcb95cc6f2dd6c9..4ed0b05ebd42067d934d64b144599ba637c43df7 100644 (file)
@@ -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.
  *
  */
 
@@ -146,6 +146,28 @@ launch_previewer (void)
        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)
 {
@@ -171,13 +193,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);
 
@@ -187,14 +220,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,
@@ -206,6 +232,33 @@ load_files (const char **files)
         }
 }
 
+static gchar*
+ev_get_locale_dir ()
+{
+#ifdef G_OS_WIN32
+       gchar *install_dir = NULL, *locale_dir;
+       gchar *retval = NULL;
+
+       install_dir =
+           g_win32_get_package_installation_directory_of_module (NULL);
+
+       if (install_dir) {
+               locale_dir = g_build_filename (install_dir,
+                                       "share", "locale", NULL);
+               retval = g_win32_locale_filename_from_utf8 (locale_dir);
+               g_free (install_dir);
+               g_free (locale_dir);
+       }
+
+       if (retval)
+               return retval;
+       else
+               return g_strdup ("");
+#else
+       return g_strdup (GNOMELOCALEDIR);
+#endif
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -243,7 +296,9 @@ main (int argc, char *argv[])
 
 #ifdef ENABLE_NLS
        /* Initialize the i18n stuff */
-       bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+       gchar *tmp = ev_get_locale_dir ();
+       bindtextdomain (GETTEXT_PACKAGE, tmp);
+       g_free (tmp);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);
 #endif
@@ -290,14 +345,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 ();