]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
Fix 'Export As...' in non-English localizations
[lyx.git] / src / support / Package.cpp
index ec08a55b7be91ff6058a6185a83ecea416f662f5..26870ed91b94e93c2779b2b84c0e578c5f46382b 100644 (file)
@@ -36,7 +36,9 @@
 #endif
 
 #if defined (USE_MACOSX_PACKAGING)
-# include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
+# include "support/qstring_helpers.h"
+# include <QDir>
+# include <QDesktopServices>
 #endif
 
 using namespace std;
@@ -65,7 +67,7 @@ void init_package(string const & command_line_arg0,
 
 Package const & package()
 {
-       LASSERT(initialised_, /**/);
+       LAPPERR(initialised_);
        return package_;
 }
 
@@ -117,13 +119,13 @@ Package::Package(string const & command_line_arg0,
        lyx_dir_ = FileName(lyx_dir_.realPath());
 
        // Is LyX being run in-place from the build tree?
-       bool in_build_dir = inBuildDir(abs_binary, build_support_dir_, system_support_dir_);
+       in_build_dir_ = inBuildDir(abs_binary, build_support_dir_, system_support_dir_);
 
-       if (!in_build_dir) {
+       if (!in_build_dir_) {
                system_support_dir_ =
                        get_system_support_dir(abs_binary,
                                               command_line_system_support_dir);
-    }
+       }
 
        // Find the LyX executable
        lyx_binary_ = findLyxBinary(abs_binary);
@@ -139,7 +141,8 @@ Package::Package(string const & command_line_arg0,
        FileName const configure_script(addName(system_support().absFileName(), "configure.py"));
        configure_command_ = os::python() + ' ' +
                        quoteName(configure_script.toFilesystemEncoding(), quote_python) +
-                       with_version_suffix();
+                       with_version_suffix() + " --binary-dir=" +
+                       quoteName(FileName(binary_dir().absFileName()).toFilesystemEncoding());
 
        LYXERR(Debug::INIT, "<package>\n"
                << "\tbinary_dir " << binary_dir().absFileName() << '\n'
@@ -162,6 +165,20 @@ void Package::set_temp_dir(FileName const & temp_dir) const
                temp_dir_ = temp_dir;
 }
 
+
+FileName Package::messages_file(string const & c) const
+{
+       if (in_build_dir_) {
+               FileName res = FileName(lyx_dir().absFileName() + "/../po/" + c + ".gmo");
+               if (!res.isReadableFile())
+                       res = FileName(top_srcdir().absFileName() + "/po/" + c + ".gmo");
+               return res;
+       } else
+               return FileName(locale_dir_.absFileName() + "/" + c
+                       + "/LC_MESSAGES/" PACKAGE ".mo");
+}
+
+
 // The specification of home_dir_ is fixed for a given OS.
 // A typical example on Windows: "C:/Documents and Settings/USERNAME"
 // and on a Posix-like machine: "/home/USERNAME".
@@ -169,6 +186,8 @@ FileName const & Package::get_home_dir()
 {
 #if defined (USE_WINDOWS_PACKAGING)
        static FileName const home_dir(getEnv("USERPROFILE"));
+#elif defined (USE_MACOSX_PACKAGING)
+       static FileName const home_dir(fromqstr(QDir::homePath()));
 #else // Posix-like.
        static FileName const home_dir(getEnv("HOME"));
 #endif
@@ -344,7 +363,14 @@ bool lyxBinaryPath(FileName & lyx_binary, string const & search_dir, string cons
 FileName findLyxBinary(FileName const & abs_binary)
 {
     string ext;
-    if (!abs_binary.extension().empty()) {
+    string checkname = abs_binary.toFilesystemEncoding();
+    int check_len = checkname.length();
+    int prgsuffixlen = string(PROGRAM_SUFFIX).length();
+    if ((prgsuffixlen > 0) && (check_len > prgsuffixlen) &&
+       (checkname.substr(check_len-prgsuffixlen) == string(PROGRAM_SUFFIX))) {
+       ext = "";
+    }
+    else if (!abs_binary.extension().empty()) {
         ext = "." + abs_binary.extension();
     }
     
@@ -370,6 +396,12 @@ FileName const get_document_dir(FileName const & home_dir)
        (void)home_dir; // Silence warning about unused variable.
        os::GetFolderPath win32_folder_path;
        return FileName(win32_folder_path(os::GetFolderPath::PERSONAL));
+#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000)
+       (void)home_dir; // Silence warning about unused variable.
+       return FileName(fromqstr(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
+#elif defined (USE_MACOSX_PACKAGING)
+       (void)home_dir; // Silence warning about unused variable.
+       return FileName(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)));
 #else // Posix-like.
        return home_dir;
 #endif
@@ -633,25 +665,13 @@ FileName const get_default_user_support_dir(FileName const & home_dir)
        os::GetFolderPath win32_folder_path;
        return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE));
 
-#elif defined (USE_MACOSX_PACKAGING)
+#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000)
        (void)home_dir; // Silence warning about unused variable.
+       return FileName(addPath(fromqstr(QStandardPaths::writableLocation(QStandardPaths::DataLocation)), PACKAGE));
 
-       FSRef fsref;
-       OSErr const error_code =
-               FSFindFolder(kUserDomain, kApplicationSupportFolderType,
-                            kDontCreateFolder, &fsref);
-       if (error_code != 0)
-               return FileName();
-
-       // FSRefMakePath returns the result in utf8
-       char store[PATH_MAX + 1];
-       OSStatus const status_code =
-               FSRefMakePath(&fsref,
-                             reinterpret_cast<UInt8*>(store), PATH_MAX);
-       if (status_code != 0)
-               return FileName();
-
-       return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
+#elif defined (USE_MACOSX_PACKAGING)
+       (void)home_dir; // Silence warning about unused variable.
+       return FileName(addPath(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DataLocation)), PACKAGE));
 
 #else // USE_POSIX_PACKAGING
        return FileName(addPath(home_dir.absFileName(), string(".") + PACKAGE));