changeset 29511:2a4980872234

remove default-qt-settings * configure.ac: remove mk-default-qt-settings.sh from OCTAVE_CONFIG_MOVE_IF_CHANGE_FILES * default-qt-settings.in: remove file * libgui/module.mk: remove all occurrences of default-qt-settings and mk-default-qt-settings.in.sh * gui-preferences-global.h: set defaults for the custom editor depending on the target system here and not in the resource manager * resource-manager.cc (default_qt_settings_file): remove; (reload_settings): if settings file does not yet exist, determine default font and custom editor - possibly from environment variable - and write them into the newly created settings file, otherwise use existing settings file; (set_settings): create settings and write a test settings to make sure a newly created file does really exist * run-octave.in: remove setting the environment variable OCTAVE_DEFAULT_QT_SETTINGS
author Torsten Lilge <ttl-octave@mailbox.org>
date Thu, 08 Apr 2021 21:19:10 +0200
parents e4bdc6959125
children 1591e7470f1a
files configure.ac libgui/default-qt-settings.in libgui/module.mk libgui/src/gui-preferences-global.h libgui/src/resource-manager.cc run-octave.in
diffstat 6 files changed, 42 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Thu Apr 08 13:20:17 2021 -0400
+++ b/configure.ac	Thu Apr 08 21:19:10 2021 +0200
@@ -3070,7 +3070,6 @@
   [$SHELL $srcdir/build-aux/move-if-change oct-conf-post.h-tmp oct-conf-post.h])
 
 OCTAVE_CONFIG_MOVE_IF_CHANGE_FILES([
-  libgui/mk-default-qt-settings.sh
   liboctave/external/mk-f77-def.sh
   liboctave/mk-version-h.sh
   libinterp/corefcn/mk-mxtypes-h.sh
--- a/libgui/default-qt-settings.in	Thu Apr 08 13:20:17 2021 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-[General]
-customFileEditor=__default_custom_editor__
-
-[editor]
-showLineNumbers=true
-highlightCurrentLine=true
-codeCompletion=true
-longWindowTitle=false
-restoreSession=false
-savedSessionTabs=@Invalid()
-mru_file_list=@Invalid()
-
-[terminal]
-fontSize=__default_font_size__
-fontName=__default_font__
-cursorType=ibeam
-
-[workspaceview]
-local_collapsed=false
-global_collapsed=false
-persistent_collapsed=false
-column_state=@ByteArray(\0\0\0\xff\0\0\0\0\0\0\0\x1\0\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x2\x12\0\0\0\x5\x1\0\0\x1\0\0\0\0\0\0\0\0\0\0\0\0\x64\xff\xff\xff\xff\0\0\0\x81\0\0\0\0\0\0\0\x2\0\0\x1\x90\0\0\0\x4\0\0\0\0\0\0\0\x82\0\0\0\x1\0\0\0\0)
--- a/libgui/module.mk	Thu Apr 08 13:20:17 2021 -0400
+++ b/libgui/module.mk	Thu Apr 08 21:19:10 2021 +0200
@@ -76,13 +76,8 @@
   $(LIBOCTGUI_LINK_OPTS) \
   $(WARN_LDFLAGS)
 
-octetc_DATA += %reldir%/default-qt-settings
-
 octlocale_DATA += $(LOCALES)
 
-%reldir%/default-qt-settings: %reldir%/default-qt-settings.in %reldir%/mk-default-qt-settings.sh | %reldir%/$(octave_dirstamp)
-	$(AM_V_GEN)$(call simple-filter-rule,%reldir%/mk-default-qt-settings.sh)
-
 DIRSTAMP_FILES += \
   %reldir%/$(octave_dirstamp)
 
@@ -130,15 +125,12 @@
 
 %canon_reldir%_EXTRA_DIST += \
   $(TRANSLATIONS) \
-  %reldir%/default-qt-settings.in \
-  %reldir%/liboctgui-build-info.in.cc \
-  %reldir%/mk-default-qt-settings.in.sh
+  %reldir%/liboctgui-build-info.in.cc
 
 EXTRA_DIST += $(%canon_reldir%_EXTRA_DIST)
 
 %canon_reldir%_CLEANFILES += \
   $(LOCALES) \
-  %reldir%/default-qt-settings \
   %reldir%/liboctgui-build-info.cc
 
 CLEANFILES += $(%canon_reldir%_CLEANFILES)
@@ -157,7 +149,4 @@
 %reldir%/liboctgui-build-info.cc: %reldir%/liboctgui-build-info.in.cc HG-ID | %reldir%/$(octave_dirstamp)
 	$(AM_V_GEN)$(build-info-commands)
 
-GEN_CONFIG_SHELL += \
-  %reldir%/mk-default-qt-settings.sh
-
 endif
--- a/libgui/src/gui-preferences-global.h	Thu Apr 08 13:20:17 2021 -0400
+++ b/libgui/src/gui-preferences-global.h	Thu Apr 08 21:19:10 2021 +0200
@@ -115,8 +115,14 @@
 
 const gui_pref
 global_use_custom_editor ("useCustomFileEditor", QVariant (false));
+
+#if defined (Q_OS_WIN32)
+const gui_pref
+global_custom_editor ("customFileEditor", QVariant ("notepad++ -n%l %f"));
+#else
 const gui_pref
 global_custom_editor ("customFileEditor", QVariant ("emacs +%l %f"));
+#endif
 
 const gui_pref
 global_prompt_to_exit ("prompt_to_exit", QVariant (false));
--- a/libgui/src/resource-manager.cc	Thu Apr 08 13:20:17 2021 -0400
+++ b/libgui/src/resource-manager.cc	Thu Apr 08 21:19:10 2021 +0200
@@ -47,6 +47,7 @@
 #include <QTextCodec>
 
 #include "QTerminal.h"
+#include "gui-preferences-cs.h"
 #include "gui-preferences-ed.h"
 #include "gui-preferences-global.h"
 #include "octave-qobject.h"
@@ -64,19 +65,6 @@
 
 namespace octave
 {
-  static QString
-  default_qt_settings_file (void)
-  {
-    std::string dsf = sys::env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS");
-
-    if (dsf.empty ())
-      dsf = (config::oct_etc_dir ()
-             + sys::file_ops::dir_sep_str ()
-             + "default-qt-settings");
-
-    return QString::fromStdString (dsf);
-  }
-
   resource_manager::resource_manager (void)
     : m_settings_directory (), m_settings_file (), m_settings (nullptr),
       m_default_settings (nullptr), m_temporary_files ()
@@ -287,59 +275,45 @@
 
   void resource_manager::reload_settings (void)
   {
+    // Declare some empty options, which may be set at first startup for
+    // writing them into the newly created settings file
+    QString custom_editor;
+    QStringList def_font;
+
+    // Check whether the settings file does not yet exist
     if (! QFile::exists (m_settings_file))
       {
-        QDir ("/").mkpath (m_settings_directory);
-        QFile qt_settings (default_qt_settings_file ());
-
-        if (! qt_settings.open (QFile::ReadOnly))
-          return;
-
-        QTextStream in (&qt_settings);
-        QString settings_text = in.readAll ();
-        qt_settings.close ();
+        // Get the default font (for terminal)
+        def_font = get_default_font ();
 
-        // Get the default font
-        QStringList def_font = get_default_font ();
-
-        // Get the default custom editor
-#if defined (Q_OS_WIN32)
-        QString custom_editor = "notepad++ -n%l %f";
-#else
-        QString custom_editor = "emacs +%l %f";
-#endif
-
+        // Get a custom editor defined as env variable
         std::string env_default_editor
           = sys::env::getenv ("OCTAVE_DEFAULT_EDITOR");
 
         if (! env_default_editor.empty ())
           custom_editor = QString::fromStdString (env_default_editor);
-
-        // Replace placeholders
-        settings_text.replace ("__default_custom_editor__", custom_editor);
-        settings_text.replace ("__default_font__", def_font.at(0));
-        settings_text.replace ("__default_font_size__", def_font.at (1));
-
-        QFile user_settings (m_settings_file);
-
-        if (! user_settings.open (QIODevice::WriteOnly))
-          return;
-
-        QTextStream out (&user_settings);
-
-        out << settings_text;
-
-        user_settings.close ();
       }
 
     set_settings (m_settings_file);
 
-    // Write the default monospace font into the settings for later use by
-    // console and editor as fallbacks of their font preferences.
+    // Write some settings that were dynamically determined at first startup
     if (m_settings)
-      m_settings->setValue (global_mono_font.key,
-                            get_default_font_family ());
+      {
+        // Custom editor
+        if (! custom_editor.isEmpty ())
+          m_settings->setValue (global_custom_editor.key, custom_editor);
 
+        // Default monospace font for the terminal
+        if (def_font.count () > 1)
+          {
+            m_settings->setValue (cs_font.key, def_font[0]);
+            m_settings->setValue (cs_font_size.key, def_font[1].toInt ());
+          }
+
+        // Write the default monospace font into the settings for later use by
+        // console and editor as fallbacks of their font preferences.
+        m_settings->setValue (global_mono_font.key, get_default_font_family ());
+      }
   }
 
 #if defined (HAVE_QSCINTILLA)
@@ -439,6 +413,13 @@
     delete m_settings;
     m_settings = new gui_settings (file, QSettings::IniFormat);
 
+    if (m_settings->status () == QSettings::NoError)
+      {
+        // Test usability (force file to be really created)
+        m_settings->setValue ("dummy", 0);
+        m_settings->sync ();
+      }
+
     if (! (QFile::exists (m_settings->fileName ())
            && m_settings->isWritable ()
            && m_settings->status () == QSettings::NoError))
@@ -455,6 +436,8 @@
 
         exit (1);
       }
+    else
+      m_settings->remove ("dummy"); // Remove test entry
   }
 
   bool resource_manager::update_settings_key (const QString& old_key,
--- a/run-octave.in	Thu Apr 08 13:20:17 2021 -0400
+++ b/run-octave.in	Thu Apr 08 21:19:10 2021 +0200
@@ -111,7 +111,6 @@
 
 OCTAVE_ARCHLIBDIR="$builddir/src"; export OCTAVE_ARCHLIBDIR
 OCTAVE_BINDIR="$builddir/src"; export OCTAVE_BINDIR
-OCTAVE_DEFAULT_QT_SETTINGS="$builddir/libgui/default-qt-settings"; export OCTAVE_DEFAULT_QT_SETTINGS
 OCTAVE_FONTS_DIR="$top_srcdir/etc/fonts"; export OCTAVE_FONTS_DIR
 OCTAVE_JAVA_DIR="$builddir/scripts/java"; export OCTAVE_JAVA_DIR
 OCTAVE_LOCALE_DIR="$builddir/libgui/languages"; export OCTAVE_LOCALE_DIR