annotate libgui/src/resource-manager.cc @ 27893:465ac679e976

Fix typos and grammar errors in comments in libgui (patch #9790) * color-picker.cc, documentation.cc, dw-main-window.cc, files-dock-widget.cc, gui-preferences-mw.h, history-dock-widget.h, file-editor-tab.cc, file-editor-tab.h, file-editor.cc, find-dialog.cc, octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc, octave-dock-widget.h, resource-manager.cc, shortcut-manager.cc, tab-bar.cc, tab-bar.h, variable-editor.cc, variable-editor.h, workspace-model.cc, workspace-view.cc: Fix typos and grammar errors in comments.
author Andrew Janke <andrew@apjanke.net>
date Thu, 11 Apr 2019 07:37:20 -0400
parents f68c7c56e5f2
children b442ec6dda5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
1 /*
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26291
diff changeset
3 Copyright (C) 2011-2019 Jacob Dawid
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
4
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
5 This file is part of Octave.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24290
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24290
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
10 (at your option) any later version.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
15 GNU General Public License for more details.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
16
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
17 You should have received a copy of the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24290
diff changeset
19 <https://www.gnu.org/licenses/>.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
20
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
21 */
13539
a4b5cad8f7c6 Added command line parser class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13537
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21568
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
24 # include "config.h"
15159
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
25 #endif
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
26
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
27 #include <string>
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
28
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
29 #include <QDir>
13570
7828e1bf5b0d Default settings are now loaded it there is no user-defined settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13551
diff changeset
30 #include <QFile>
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17744
diff changeset
31 #include <QLibraryInfo>
17943
efe3e288a20c check the creation of settings object for success before starting the gui
Torsten <ttl@justmail.de>
parents: 17938
diff changeset
32 #include <QMessageBox>
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
33 #include <QNetworkProxy>
24827
1e0718c1867c eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents: 24718
diff changeset
34 #if defined (HAVE_QSTANDARDPATHS)
22250
2fd4f1a3f4a8 allow building with Qt5 (bug #40252)
John W. Eaton <jwe@octave.org>
parents: 22177
diff changeset
35 # include <QStandardPaths>
27841
f68c7c56e5f2 add missing include (bug #57420)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27805
diff changeset
36 #else
f68c7c56e5f2 add missing include (bug #57420)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27805
diff changeset
37 # include <QDesktopServices>
22250
2fd4f1a3f4a8 allow building with Qt5 (bug #40252)
John W. Eaton <jwe@octave.org>
parents: 22177
diff changeset
38 #endif
27841
f68c7c56e5f2 add missing include (bug #57420)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27805
diff changeset
39
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
40 #include <QTextCodec>
14845
9a355dfc7701 Fixed bug with GUI not starting the first time.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14804
diff changeset
41
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
42 #include "QTerminal.h"
27560
3fcc650de22f split gui-preferences.h into one file per widget
John W. Eaton <jwe@octave.org>
parents: 27556
diff changeset
43 #include "gui-preferences-ed.h"
3fcc650de22f split gui-preferences.h into one file per widget
John W. Eaton <jwe@octave.org>
parents: 27556
diff changeset
44 #include "gui-preferences-global.h"
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
45 #include "octave-qobject.h"
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
46 #include "resource-manager.h"
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
47 #include "variable-editor.h"
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
48 #include "workspace-model.h"
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
49
15159
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
50 #include "file-ops.h"
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
51 #include "oct-env.h"
098546e95a5e allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents: 15081
diff changeset
52
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
53 #include "defaults.h"
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
54 #include "error.h"
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
55 #include "help.h"
13537
a43ecce77eec Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
56
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
57 namespace octave
16593
e13051d7a472 allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents: 16379
diff changeset
58 {
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
59 static QString
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
60 default_qt_settings_file (void)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
61 {
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
62 std::string dsf = sys::env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS");
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
63
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 if (dsf.empty ())
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
65 dsf = (config::oct_etc_dir ()
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
66 + sys::file_ops::dir_sep_str ()
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
67 + "default-qt-settings");
16593
e13051d7a472 allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents: 16379
diff changeset
68
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
69 return QString::fromStdString (dsf);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
70 }
16593
e13051d7a472 allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents: 16379
diff changeset
71
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
72 resource_manager::resource_manager (void)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
73 : m_settings_directory (), m_settings_file (), m_settings (nullptr),
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
74 m_default_settings (nullptr), m_temporary_files ()
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
75 {
27611
0495b64288f7 use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents: 27583
diff changeset
76 // Let gui_settings decide where to put the ini file with gui preferences
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
77 m_default_settings
27611
0495b64288f7 use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents: 27583
diff changeset
78 = new gui_settings (QSettings::IniFormat, QSettings::UserScope,
0495b64288f7 use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents: 27583
diff changeset
79 "octave", "octave-gui");
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
80
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
81 m_settings_file = m_default_settings->fileName ();
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
82
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
83 QFileInfo sfile (m_settings_file);
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
84 m_settings_directory = sfile.absolutePath ();
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
85
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
86 QString xdg_config_home
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
87 = QString::fromLocal8Bit (qgetenv ("XDG_CONFIG_HOME"));
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
88
26959
3ed8955dcdf9 * resource-manager.cc (ctor): test XDG_CONFIG_HOME before importing old gui settings
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26955
diff changeset
89 if ((! sfile.exists ()) && xdg_config_home.isEmpty ())
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
90 {
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
91 // File does not exist yet: Look for a settings file at the old
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
92 // location ($HOME/.config/octave/qt-settings) for impoting all
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
93 // available keys into the new settings file.
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
94 // Do not look for an old settings file if XDG_CONFIG_HOME is set,
27893
465ac679e976 Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents: 27841
diff changeset
95 // since then a nonexistent new settings file does not necessarily
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
96 // indicate a first run of octave with new config file locations.
24827
1e0718c1867c eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents: 24718
diff changeset
97 #if defined (HAVE_QSTANDARDPATHS)
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
98 QString home_path
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
99 = QStandardPaths::writableLocation (QStandardPaths::HomeLocation);
24827
1e0718c1867c eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents: 24718
diff changeset
100 #else
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
101 QString home_path
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
102 = QDesktopServices::storageLocation (QDesktopServices::HomeLocation);
22250
2fd4f1a3f4a8 allow building with Qt5 (bug #40252)
John W. Eaton <jwe@octave.org>
parents: 22177
diff changeset
103 #endif
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
104
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
105 QString old_settings_directory = home_path + "/.config/octave";
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
106 QString old_settings_file = old_settings_directory + "/qt-settings";
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
107
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
108 QFile ofile (old_settings_file);
26837
47bf66f0dc6b gui honors XDG_CONFIG_HOME at startup (bug #55822)
Torsten <mttl@mailbox.org>
parents: 26377
diff changeset
109
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
110 if (ofile.exists ())
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
111 {
27893
465ac679e976 Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents: 27841
diff changeset
112 // Old settings file exists; create a gui_settings object related
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
113 // to it and copy all available keys to the new settings
27611
0495b64288f7 use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents: 27583
diff changeset
114 gui_settings old_settings (old_settings_file, QSettings::IniFormat);
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
115
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
116 QStringList keys = old_settings.allKeys ();
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
117 for (int i = 0; i < keys.count(); i++)
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
118 m_default_settings->setValue (keys.at(i),
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
119 old_settings.value(keys.at(i)));
16593
e13051d7a472 allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents: 16379
diff changeset
120
26955
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
121 m_default_settings->sync (); // Done, make sure keys are written
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
122 }
9e2f69c1a05d use standard location on each platform for gui preferences file (bug #55855)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26866
diff changeset
123 }
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
124 }
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 15161
diff changeset
125
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
126 resource_manager::~resource_manager (void)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
127 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
128 delete m_settings;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
129 delete m_default_settings;
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
130
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
131 for (int i = m_temporary_files.count () - 1; i >=0; i--)
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
132 remove_tmp_file (m_temporary_files.at (i));
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
133 }
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 15161
diff changeset
134
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
135 QString resource_manager::get_gui_translation_dir (void)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
136 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
137 // get environment variable for the locale dir (e.g. from run-octave)
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
138 std::string dldir = sys::env::getenv ("OCTAVE_LOCALE_DIR");
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
139 if (dldir.empty ())
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
140 dldir = config::oct_locale_dir (); // env-var empty, load the default location
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
141 return QString::fromStdString (dldir);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
142 }
15972
22ab4fe661d7 gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents: 15927
diff changeset
143
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
144 void resource_manager::config_translators (QTranslator *qt_tr,
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
145 QTranslator *qsci_tr,
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
146 QTranslator *gui_tr)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
147 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
148 bool loaded;
16863
c82b3614eace try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents: 16858
diff changeset
149
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
150 QString qt_trans_dir
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
151 = QLibraryInfo::location (QLibraryInfo::TranslationsPath);
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
152
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
153 QString language = "SYSTEM"; // take system language per default
18020
5d42ffc6850a load translators before welcome wizard and take system language as default
Torsten <ttl@justmail.de>
parents: 18004
diff changeset
154
27649
91d43a00620d eliminate static instance variable from octave_qobject class
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
155 // FIXME: can we somehow ensure that the settings object will always
91d43a00620d eliminate static instance variable from octave_qobject class
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
156 // be initialize and valid?
16863
c82b3614eace try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents: 16858
diff changeset
157
27649
91d43a00620d eliminate static instance variable from octave_qobject class
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
158 if (m_settings)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
159 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
160 // get the locale from the settings if already available
27805
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
161 language = m_settings->value (global_language.key,
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
162 global_language.def).toString ();
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
163 }
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
164
26866
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
165 // load the translations depending on the settings
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
166 if (language == "SYSTEM")
26866
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
167 {
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
168 // get the system locale and pass it to the translators for loading
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
169 // the suitable translation files
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
170 QLocale sys_locale = QLocale::system ();
16863
c82b3614eace try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents: 16858
diff changeset
171
26866
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
172 qt_tr->load (sys_locale, "qt", "_", qt_trans_dir);
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
173 qsci_tr->load (sys_locale, "qscintilla", "_", qt_trans_dir);
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
174 gui_tr->load (sys_locale, "", "", get_gui_translation_dir ());
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
175 }
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
176 else
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
177 {
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
178 // load the translation files depending on the given locale name
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
179 loaded = qt_tr->load ("qt_" + language, qt_trans_dir);
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
180 if (! loaded) // try lower case
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
181 qt_tr->load ("qt_" + language.toLower (), qt_trans_dir);
18020
5d42ffc6850a load translators before welcome wizard and take system language as default
Torsten <ttl@justmail.de>
parents: 18004
diff changeset
182
26866
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
183 loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir);
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
184 if (! loaded) // try lower case
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
185 qsci_tr->load ("qscintilla_" + language.toLower (), qt_trans_dir);
15161
ad9523348676 Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents: 15159
diff changeset
186
26866
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
187 gui_tr->load (language, get_gui_translation_dir ());
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
188 }
65e5526ad987 improve system locale detection for loading gui translations (bug #41072)
Torsten <mttl@mailbox.org>
parents: 26842
diff changeset
189
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
190 }
24014
bffd7d826887 style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents: 23927
diff changeset
191
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
192 gui_settings * resource_manager::get_settings (void) const
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
193 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
194 return m_settings;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
195 }
13537
a43ecce77eec Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
196
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
197 gui_settings * resource_manager::get_default_settings (void) const
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
198 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
199 return m_default_settings;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
200 }
13539
a4b5cad8f7c6 Added command line parser class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13537
diff changeset
201
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
202 QString resource_manager::get_settings_directory (void)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
203 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
204 return m_settings_directory;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
205 }
17515
c8c0dff02538 gui: welcome wizard with new message text
Torsten <ttl@justmail.de>
parents: 17421
diff changeset
206
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
207 QString resource_manager::get_settings_file (void)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
208 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
209 return m_settings_file;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
210 }
17515
c8c0dff02538 gui: welcome wizard with new message text
Torsten <ttl@justmail.de>
parents: 17421
diff changeset
211
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
212 QString resource_manager::get_default_font_family (void)
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
213 {
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
214 // Get the default monospaced font
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
215 #if defined (HAVE_QFONT_MONOSPACE)
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
216 QFont fixed_font;
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
217 fixed_font.setStyleHint (QFont::Monospace);
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
218 QString default_family = fixed_font.defaultFamily ();
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
219 #else
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
220 QString default_family = global_font_family;
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
221 #endif
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
222
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
223 std::string env_default_family = sys::env::getenv ("OCTAVE_DEFAULT_FONT");
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
224 if (! env_default_family.empty ())
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
225 default_family = QString::fromStdString (env_default_family);
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
226
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
227 return default_family;
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
228 }
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
229
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
230 void resource_manager::reload_settings (void)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
231 {
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
232 QString default_family = get_default_font_family ();
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
233
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
234 if (! QFile::exists (m_settings_file))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
235 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
236 QDir ("/").mkpath (m_settings_directory);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
237 QFile qt_settings (default_qt_settings_file ());
18004
b001d9e9fd17 add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents: 17943
diff changeset
238
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
239 if (! qt_settings.open (QFile::ReadOnly))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
240 return;
18004
b001d9e9fd17 add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents: 17943
diff changeset
241
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
242 QTextStream in (&qt_settings);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
243 QString settings_text = in.readAll ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
244 qt_settings.close ();
18004
b001d9e9fd17 add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents: 17943
diff changeset
245
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
246 default_family = get_default_font_family ();
25821
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
247
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
248 QString default_font_size = "10";
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
249
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
250 std::string env_default_font_size
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
251 = sys::env::getenv ("OCTAVE_DEFAULT_FONT_SIZE");
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
252
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
253 if (! env_default_font_size.empty ())
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
254 default_font_size = QString::fromStdString (env_default_font_size);
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
255
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
256 // Get the default custom editor
19916
6049bdfa8d56 make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents: 19899
diff changeset
257 #if defined (Q_OS_WIN32)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
258 QString custom_editor = "notepad++ -n%l %f";
19916
6049bdfa8d56 make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents: 19899
diff changeset
259 #else
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
260 QString custom_editor = "emacs +%l %f";
19916
6049bdfa8d56 make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents: 19899
diff changeset
261 #endif
6049bdfa8d56 make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents: 19899
diff changeset
262
25821
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
263 std::string env_default_editor
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
264 = sys::env::getenv ("OCTAVE_DEFAULT_EDITOR");
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
265
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
266 if (! env_default_editor.empty ())
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
267 custom_editor = QString::fromStdString (env_default_editor);
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
268
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
269 // Replace placeholders
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
270 settings_text.replace ("__default_custom_editor__", custom_editor);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
271 settings_text.replace ("__default_font__", default_family);
25821
bd473c0cc34b allow default font, size, and external editor to be set from environment
John W. Eaton <jwe@octave.org>
parents: 25702
diff changeset
272 settings_text.replace ("__default_font_size__", default_font_size);
18004
b001d9e9fd17 add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents: 17943
diff changeset
273
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
274 QFile user_settings (m_settings_file);
18036
c97ee13f1027 fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents: 18020
diff changeset
275
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
276 if (! user_settings.open (QIODevice::WriteOnly))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
277 return;
18004
b001d9e9fd17 add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents: 17943
diff changeset
278
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
279 QTextStream out (&user_settings);
18036
c97ee13f1027 fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents: 18020
diff changeset
280
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
281 out << settings_text;
18036
c97ee13f1027 fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents: 18020
diff changeset
282
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
283 user_settings.close ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
284 }
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 15161
diff changeset
285
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
286 set_settings (m_settings_file);
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
287
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
288 // Write the default monospace font into the settings for later use by
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
289 // console and editor as fallbacks of their font prefernces.
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
290 if (m_settings)
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
291 m_settings->setValue (global_mono_font.key, default_family);
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25821
diff changeset
292
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
293 }
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
294
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
295 void resource_manager::set_settings (const QString& file)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
296 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
297 delete m_settings;
27611
0495b64288f7 use new gui_settings class instead of using QSettings directly
John W. Eaton <jwe@octave.org>
parents: 27583
diff changeset
298 m_settings = new gui_settings (file, QSettings::IniFormat);
17943
efe3e288a20c check the creation of settings object for success before starting the gui
Torsten <ttl@justmail.de>
parents: 17938
diff changeset
299
26369
0249ba4c9589 Fix static analyzer detected V668 issues (bug #55347).
Andreas Weber <octave@josoansi.de>
parents: 26291
diff changeset
300 if (! (QFile::exists (m_settings->fileName ())
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
301 && m_settings->isWritable ()
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
302 && m_settings->status () == QSettings::NoError))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
303 {
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
304 QString msg
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
305 = QString (QT_TR_NOOP ("The settings file\n%1\n"
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
306 "does not exist and can not be created.\n"
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
307 "Make sure you have read and write permissions to\n%2\n\n"
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
308 "Octave GUI must be closed now."));
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
309
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
310 QMessageBox::critical (nullptr,
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
311 QString (QT_TR_NOOP ("Octave Critical Error")),
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
312 msg.arg (get_settings_file ()).arg (get_settings_directory ()));
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27272
diff changeset
313
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
314 exit (1);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
315 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
316 }
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 15161
diff changeset
317
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
318 bool resource_manager::update_settings_key (const QString& old_key,
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
319 const QString& new_key)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
320 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
321 if (m_settings->contains (old_key))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
322 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
323 QVariant preference = m_settings->value (old_key);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
324 m_settings->setValue (new_key, preference);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
325 m_settings->remove (old_key);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
326 return true;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
327 }
24282
a669809df612 update wrong setting keys accidentally introduced into the settings file
Torsten <mttl@mailbox.org>
parents: 23219
diff changeset
328
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
329 return false;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
330 }
24282
a669809df612 update wrong setting keys accidentally introduced into the settings file
Torsten <mttl@mailbox.org>
parents: 23219
diff changeset
331
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
332 bool resource_manager::is_first_run (void) const
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
333 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
334 return ! QFile::exists (m_settings_file);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
335 }
13668
421afeae929b Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13665
diff changeset
336
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
337 void resource_manager::update_network_settings (void)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
338 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
339 if (m_settings)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
340 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
341 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
342
27805
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
343 if (m_settings->value (global_use_proxy.key, global_use_proxy.def).toBool ())
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
344 {
27805
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
345 QString proxyTypeString
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
346 = m_settings->value (global_proxy_type.key, global_proxy_type.def).toString ();
15164
bc801a44bb1f follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents: 15161
diff changeset
347
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
348 if (proxyTypeString == "Socks5Proxy")
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
349 proxyType = QNetworkProxy::Socks5Proxy;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
350 else if (proxyTypeString == "HttpProxy")
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
351 proxyType = QNetworkProxy::HttpProxy;
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
352 }
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
353
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
354 QNetworkProxy proxy;
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
355
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
356 proxy.setType (proxyType);
27805
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
357 proxy.setHostName (m_settings->value (global_proxy_host.key,
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
358 global_proxy_host.def).toString ());
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
359 proxy.setPort (m_settings->value (global_proxy_port.key,
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
360 global_proxy_port.def).toInt ());
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
361 proxy.setUser (m_settings->value (global_proxy_user.key,
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
362 global_proxy_user.def).toString ());
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
363 proxy.setPassword (m_settings->value (global_proxy_pass.key,
dccc551aa83b replace literal strings by symbolic constants for global preferences
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
364 global_proxy_pass.def).toString ());
17930
ffdbb82a0c78 allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
365
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
366 QNetworkProxy::setApplicationProxy (proxy);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
367 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
368 else
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
369 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
370 // FIXME: Is this an error? If so, what should we do?
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
371 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
372 }
13613
8728061cd0ec Icons are now maintained by the ResourceManager.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13609
diff changeset
373
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
374 QIcon resource_manager::icon (const QString& icon_name, bool fallback)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
375 {
26140
8fb8cb4a03f8 preference for (not) using system icon theme
Torsten <mttl@mailbox.org>
parents: 26008
diff changeset
376 // If system icon theme is not desired, take own icon files
27672
a36443e94f8a simplify gui_settings->value (PREF.key, PREF.def) calls
John W. Eaton <jwe@octave.org>
parents: 27662
diff changeset
377 if (! m_settings->value (global_icon_theme).toBool ())
26140
8fb8cb4a03f8 preference for (not) using system icon theme
Torsten <mttl@mailbox.org>
parents: 26008
diff changeset
378 return QIcon (":/actions/icons/" + icon_name + ".png");
8fb8cb4a03f8 preference for (not) using system icon theme
Torsten <mttl@mailbox.org>
parents: 26008
diff changeset
379
27893
465ac679e976 Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents: 27841
diff changeset
380 // Use system icon theme with own files as fallback except when the
465ac679e976 Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents: 27841
diff changeset
381 // fallback is explicitly disabled (fallback=false)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
382 if (fallback)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
383 return QIcon::fromTheme (icon_name,
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
384 QIcon (":/actions/icons/" + icon_name + ".png"));
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
385 else
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
386 return QIcon::fromTheme (icon_name);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
387 }
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
388
25700
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
389 // get a list of all available encodings
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
390 void resource_manager::get_codecs (QStringList *codecs)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
391 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
392 // get the codec name for each mib
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
393 QList<int> all_mibs = QTextCodec::availableMibs ();
27676
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
394 for (auto mib : all_mibs)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
395 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
396 QTextCodec *c = QTextCodec::codecForMib (mib);
25700
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
397 codecs->append (c->name ().toUpper ());
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
398 }
26291
f73bcf1d0b5a make SYSTEM alias for locale encoding if not suported on windows (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26226
diff changeset
399
27272
9de4741a896e Do not ignore user preferences for locale encoding on non-Windows platforms.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27271
diff changeset
400 // Append SYSTEM
9de4741a896e Do not ignore user preferences for locale encoding on non-Windows platforms.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27271
diff changeset
401 codecs->append (QTextCodec::codecForLocale ()->name ().toUpper ().prepend
9de4741a896e Do not ignore user preferences for locale encoding on non-Windows platforms.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27271
diff changeset
402 ("SYSTEM (").append (")"));
26291
f73bcf1d0b5a make SYSTEM alias for locale encoding if not suported on windows (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26226
diff changeset
403
f73bcf1d0b5a make SYSTEM alias for locale encoding if not suported on windows (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26226
diff changeset
404 // Clean up and sort list of codecs
25700
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
405 codecs->removeDuplicates ();
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
406 qSort (*codecs);
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
407 }
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
408
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
409 // initialize a given combo box with available text encodings
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
410 void resource_manager::combo_encoding (QComboBox *combo,
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
411 const QString& current)
25700
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
412 {
ba8227df92ae synchronize gui editor encoding when changing __mfile_encdoing__ (bug #54310)
Torsten <mttl@mailbox.org>
parents: 25460
diff changeset
413 QStringList all_codecs;
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
414 get_codecs (&all_codecs);
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
415
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
416 // get the value from the settings file if no current encoding is given
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
417 QString enc = current;
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
418
27271
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
419 // Check for valid codec for the default. If this fails, "SYSTEM" (i.e.
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
420 // codecForLocale) will be chosen.
27272
9de4741a896e Do not ignore user preferences for locale encoding on non-Windows platforms.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27271
diff changeset
421 // FIXME: The default is "SYSTEM" on all platforms. So can this fallback
9de4741a896e Do not ignore user preferences for locale encoding on non-Windows platforms.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27271
diff changeset
422 // logic be removed completely?
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
423 bool default_exists = false;
26291
f73bcf1d0b5a make SYSTEM alias for locale encoding if not suported on windows (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26226
diff changeset
424 if (QTextCodec::codecForName (ed_default_enc.def.toString ().toLatin1 ())
27271
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
425 || (ed_default_enc.def.toString ().startsWith ("SYSTEM")))
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
426 default_exists = true;
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
427
27271
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
428 QString default_enc =
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
429 QTextCodec::codecForLocale ()->name ().toUpper ().prepend
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
430 ("SYSTEM (").append (")");
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
431 if (enc.isEmpty ())
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
432 {
27672
a36443e94f8a simplify gui_settings->value (PREF.key, PREF.def) calls
John W. Eaton <jwe@octave.org>
parents: 27662
diff changeset
433 enc = m_settings->value (ed_default_enc).toString ();
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
434
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
435 if (enc.isEmpty ()) // still empty?
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
436 {
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
437 if (default_exists)
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
438 enc = ed_default_enc.def.toString ();
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
439 else
27271
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
440 enc = default_enc;
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
441 }
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
442 }
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
443
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
444 // fill the combo box
27676
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
445 for (const auto& c : all_codecs)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
446 combo->addItem (c);
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
447
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
448 // prepend the default item
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
449 combo->insertSeparator (0);
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
450 if (default_exists)
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
451 combo->insertItem (0, ed_default_enc.def.toString ());
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
452 else
27271
a4416cd6bb4f Append name of actual encoding used if "SYSTEM" is selected.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26959
diff changeset
453 combo->insertItem (0, default_enc);
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
454
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
455 // select the default or the current one
26226
3a90eff58fb5 editor encodings in prefs dialog only in uppercase (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26186
diff changeset
456 int idx = combo->findText (enc, Qt::MatchExactly);
26186
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
457 if (idx >= 0)
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
458 combo->setCurrentIndex (idx);
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
459 else
b23954fd0ea6 fix encoding combo box for not supported default encoding (bug #55139)
Torsten <mttl@mailbox.org>
parents: 26172
diff changeset
460 combo->setCurrentIndex (0);
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
461
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
462 combo->setMaxVisibleItems (12);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
463 }
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
464
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
465 QPointer<QTemporaryFile>
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
466 resource_manager::create_tmp_file (const QString& extension,
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
467 const QString& contents)
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
468 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
469 QString ext = extension;
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
470 if ((! ext.isEmpty ()) && (! ext.startsWith ('.')))
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
471 ext = QString (".") + ext;
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
472
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
473 // Create octave dir within temp. dir
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
474 QString tmp_dir = QDir::tempPath () + QDir::separator() + "octave";
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
475 QDir::temp ().mkdir ("octave");
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
476
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
477 // Create temp. file
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
478 QPointer<QTemporaryFile> tmp_file
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
479 = new QTemporaryFile (tmp_dir + QDir::separator() +
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
480 "octave_XXXXXX" + ext, this);
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
481
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
482 if (tmp_file->open ())
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
483 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
484 tmp_file->write (contents.toUtf8 ());
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
485 tmp_file->close ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
486
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
487 m_temporary_files << tmp_file;
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
488 }
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
489
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
490 return tmp_file;
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
491 }
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
492
27620
45bb5bbaf291 don't use singleton pattern for resource manager in GUI
John W. Eaton <jwe@octave.org>
parents: 27611
diff changeset
493 void resource_manager::remove_tmp_file (QPointer<QTemporaryFile> tmp_file)
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
494 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
495 if (tmp_file)
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
496 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
497 if (tmp_file->exists ())
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
498 tmp_file->remove ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
499
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
500 m_temporary_files.removeAll (tmp_file);
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
501 }
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27412
diff changeset
502 }
20774
5c5e085a1ae6 allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents: 20428
diff changeset
503 }