changeset 30882:b77b321f1ac5

use common function for getting temp dir in GUI (bug #62215) * resource-manager.cc (octave_getenv): removed; (get_temp_dir): removed; (create_tmp_file): use sys::env::get_temp_directory () * resource-manager.h: removed octave_getenv and get_temp_dir
author Torsten Lilge <ttl-octave@mailbox.org>
date Sun, 03 Apr 2022 14:28:45 +0200
parents 1921d9d0e62b
children 960909469245
files libgui/src/resource-manager.cc libgui/src/resource-manager.h
diffstat 2 files changed, 1 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/resource-manager.cc	Sun Apr 03 12:38:19 2022 +0200
+++ b/libgui/src/resource-manager.cc	Sun Apr 03 14:28:45 2022 +0200
@@ -728,57 +728,6 @@
   }
 
 
-  // Extending getenv such taht is gets and returns std::string
-  std::string resource_manager::octave_getenv (const std::string& name)
-  {
-    char *value = ::getenv (name.c_str ());
-    return value ? value : "";
-  }
-
-  // The following routine for determining the current temp directory
-  // is taken from mkoctfile.in.cc and updated such that the fallback
-  // is the location that QStandardPaths::writableLocation returns.
-  QString resource_manager::get_temp_dir ()
-  {
-    std::string tempd;
-
-    tempd = octave_getenv ("TMPDIR");
-
-#if defined (__MINGW32__) || defined (_MSC_VER)
-
-    if (tempd.empty ())
-      tempd = octave_getenv ("TEMP");
-
-    if (tempd.empty ())
-      tempd = octave_getenv ("TMP");
-
-#if defined (P_tmpdir)
-    if (tempd.empty ())
-      tempd = P_tmpdir;
-#endif
-
-    // Some versions of MinGW and MSVC either don't define P_tmpdir, or
-    // define it to a single backslash.
-    if (tempd == R"(\)")
-      tempd = "";
-
-#else
-
-#if defined (P_tmpdir)
-    if (tempd.empty ())
-      tempd = P_tmpdir;
-#endif
-
-#endif
-
-    if (tempd.empty ())
-      return QStandardPaths::writableLocation (QStandardPaths::TempLocation) +
-             QDir::separator() + "octave";
-    else
-      return QString::fromStdString (tempd);
-  }
-
-
   QPointer<QTemporaryFile>
   resource_manager::create_tmp_file (const QString& extension,
                                      const QString& contents)
@@ -788,7 +737,7 @@
       ext = QString (".") + ext;
 
     // Create octave dir within temp. dir
-    QString tmp_dir = get_temp_dir ();
+    QString tmp_dir = QString::fromStdString (sys::env::get_temp_directory ());
 
     // Create temp. file
     QPointer<QTemporaryFile> tmp_file
--- a/libgui/src/resource-manager.h	Sun Apr 03 12:38:19 2022 +0200
+++ b/libgui/src/resource-manager.h	Sun Apr 03 14:28:45 2022 +0200
@@ -115,10 +115,6 @@
     */
     QFont copy_font_attributes (const QFont& attr, const QFont& base) const;
 
-    std::string octave_getenv (const std::string& name);
-
-    QString get_temp_dir (void);
-
     QString m_settings_directory;
 
     QString m_settings_file;