Mercurial > octave
annotate libgui/src/resource-manager.cc @ 25440:893344cee100
rename defaults source files to installation-data
* installation-data.h, installation-data.cc: New files, adapted from
defaults.h and defaults.cc. Include installation-data.h instead of
defaults.h, but only in files that require it.
* defaults.h: Preserve for backward compatibility. Define deprecated
functions as inline.
* libinterp/corefcn/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 08 Jun 2018 15:43:36 -0400 |
parents | 69fc8935020b |
children | 627d6bde9b8d |
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 |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24827
diff
changeset
|
3 Copyright (C) 2011-2018 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 |
13570
7828e1bf5b0d
Default settings are now loaded it there is no user-defined settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13551
diff
changeset
|
29 #include <QFile> |
14845
9a355dfc7701
Fixed bug with GUI not starting the first time.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14804
diff
changeset
|
30 #include <QDir> |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
31 #include <QNetworkProxy> |
17790
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
32 #include <QLibraryInfo> |
17943
efe3e288a20c
check the creation of settings object for success before starting the gui
Torsten <ttl@justmail.de>
parents:
17938
diff
changeset
|
33 #include <QMessageBox> |
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> |
2fd4f1a3f4a8
allow building with Qt5 (bug #40252)
John W. Eaton <jwe@octave.org>
parents:
22177
diff
changeset
|
36 #endif |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
37 #include <QTextCodec> |
14845
9a355dfc7701
Fixed bug with GUI not starting the first time.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14804
diff
changeset
|
38 |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
39 #include "error.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
40 #include "file-ops.h" |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
41 #include "help.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
42 #include "oct-env.h" |
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
43 |
25440
893344cee100
rename defaults source files to installation-data
John W. Eaton <jwe@octave.org>
parents:
25439
diff
changeset
|
44 #include "installation-data.h" |
25439
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
45 #include "interpreter-private.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
46 |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
47 #include "QTerminal.h" |
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
48 #include "workspace-model.h" |
23927
e3a36f84d01d
provide variable-editor widget for the GUI
Michael Barnes <mjbcode@runbox.com>
parents:
23807
diff
changeset
|
49 #include "variable-editor.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
50 #include "resource-manager.h" |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
51 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
52 namespace octave |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
53 { |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
54 resource_manager *resource_manager::instance = nullptr; |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
55 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
56 static QString |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
57 default_qt_settings_file (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
58 { |
25336
389757b7b6af
eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
59 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
|
60 |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
61 if (dsf.empty ()) |
25439
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
62 { |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
63 // Hmm. |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
64 installation_data& inst_data |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
65 = __get_installation_data__ ("default_qt_settings_file"); |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
66 |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
67 dsf = (inst_data.oct_etc_dir () |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
68 + sys::file_ops::dir_sep_str () |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
69 + "default-qt-settings"); |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
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 return QString::fromStdString (dsf); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
73 } |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
74 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
75 resource_manager::resource_manager (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
76 : m_settings_directory (), m_settings_file (), m_settings (nullptr), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
77 m_default_settings (nullptr) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
78 { |
24827
1e0718c1867c
eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents:
24718
diff
changeset
|
79 #if defined (HAVE_QSTANDARDPATHS) |
1e0718c1867c
eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents:
24718
diff
changeset
|
80 QString home_path |
1e0718c1867c
eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents:
24718
diff
changeset
|
81 = QStandardPaths::writableLocation (QStandardPaths::HomeLocation); |
1e0718c1867c
eliminate most Qt version checks
John W. Eaton <jwe@octave.org>
parents:
24718
diff
changeset
|
82 #else |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
83 QString home_path |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
84 = QDesktopServices::storageLocation (QDesktopServices::HomeLocation); |
22250
2fd4f1a3f4a8
allow building with Qt5 (bug #40252)
John W. Eaton <jwe@octave.org>
parents:
22177
diff
changeset
|
85 #endif |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
86 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
87 m_settings_directory = home_path + "/.config/octave"; |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
88 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
89 m_settings_file = m_settings_directory + "/qt-settings"; |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
90 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
91 m_default_settings = new QSettings (default_qt_settings_file (), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
92 QSettings::IniFormat); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
93 } |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
94 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
95 resource_manager::~resource_manager (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
96 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
97 delete m_settings; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
98 delete m_default_settings; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
99 } |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
100 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
101 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
|
102 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
103 // 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
|
104 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
|
105 if (dldir.empty ()) |
25439
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
106 { |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
107 // Hmm. |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
108 installation_data& inst_data |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
109 = __get_installation_data__ ("resource_manager::get_gui_translation_dir"); |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
110 |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
111 // env-var empty, load the default location |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
112 dldir = inst_data.oct_locale_dir (); |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
113 } |
69fc8935020b
move some static configuration variables inside a class
John W. Eaton <jwe@octave.org>
parents:
25336
diff
changeset
|
114 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
115 return QString::fromStdString (dldir); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
116 } |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
117 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
118 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
|
119 QTranslator *qsci_tr, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
120 QTranslator *gui_tr) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
121 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
122 bool loaded; |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
123 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
124 QString qt_trans_dir |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
125 = QLibraryInfo::location (QLibraryInfo::TranslationsPath); |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
126 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
127 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
|
128 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
129 QSettings *settings = resource_manager::get_settings (); |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
130 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
131 if (settings) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
132 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
133 // get the locale from the settings if already available |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
134 language = settings->value ("language", "SYSTEM").toString (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
135 } |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
136 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
137 if (language == "SYSTEM") |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
138 language = QLocale::system ().name (); // get system wide locale |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
139 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
140 // load the translator file for qt strings |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
141 loaded = qt_tr->load ("qt_" + language, qt_trans_dir); |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
142 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
143 if (! loaded) // try lower case |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
144 qt_tr->load ("qt_" + language.toLower (), qt_trans_dir); |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
145 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
146 // load the translator file for qscintilla settings |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
147 loaded = qsci_tr->load ("qscintilla_" + language, qt_trans_dir); |
18020
5d42ffc6850a
load translators before welcome wizard and take system language as default
Torsten <ttl@justmail.de>
parents:
18004
diff
changeset
|
148 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
149 if (! loaded) // try lower case |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
150 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
|
151 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
152 // load the translator file for gui strings |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
153 gui_tr->load (language, get_gui_translation_dir ()); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
154 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
155 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
156 QStringList resource_manager::storage_class_names (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
157 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
158 return workspace_model::storage_class_names (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
159 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
160 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
161 QList<QColor> resource_manager::storage_class_default_colors (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
162 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
163 return workspace_model::storage_class_default_colors (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
164 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
165 |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
166 QStringList resource_manager::terminal_color_names (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
167 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
168 return QTerminal::color_names (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
169 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
170 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
171 QList<QColor> resource_manager::terminal_default_colors (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
172 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
173 return QTerminal::default_colors (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
175 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
176 QList<QColor> resource_manager::varedit_default_colors(void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
177 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
178 return variable_editor::default_colors (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
179 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
180 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
181 QStringList resource_manager::varedit_color_names(void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
182 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
183 return variable_editor::color_names (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
184 } |
24014
bffd7d826887
style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents:
23927
diff
changeset
|
185 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
186 bool resource_manager::instance_ok (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
187 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
188 bool retval = true; |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
189 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
190 if (! instance) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
191 instance = new resource_manager (); |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
192 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
193 if (! instance) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
194 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
195 error ("unable to create resource_manager object!"); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
196 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
197 retval = false; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
198 } |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
199 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
200 return retval; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
201 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
202 |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
203 QSettings * resource_manager::do_get_settings (void) const |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
204 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
205 return m_settings; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
206 } |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
207 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
208 QSettings * resource_manager::do_get_default_settings (void) const |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
209 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
210 return m_default_settings; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
211 } |
13539
a4b5cad8f7c6
Added command line parser class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13537
diff
changeset
|
212 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
213 QString resource_manager::do_get_settings_directory (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
214 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
215 return m_settings_directory; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
216 } |
17515
c8c0dff02538
gui: welcome wizard with new message text
Torsten <ttl@justmail.de>
parents:
17421
diff
changeset
|
217 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
218 QString resource_manager::do_get_settings_file (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
219 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
220 return m_settings_file; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
221 } |
17515
c8c0dff02538
gui: welcome wizard with new message text
Torsten <ttl@justmail.de>
parents:
17421
diff
changeset
|
222 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
223 void resource_manager::do_reload_settings (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
224 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
225 if (! QFile::exists (m_settings_file)) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
226 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
227 QDir ("/").mkpath (m_settings_directory); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
228 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
|
229 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
230 if (! qt_settings.open (QFile::ReadOnly)) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
231 return; |
18004
b001d9e9fd17
add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents:
17943
diff
changeset
|
232 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
233 QTextStream in (&qt_settings); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
234 QString settings_text = in.readAll (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
235 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
|
236 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
237 // Get the default monospaced font |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
238 #if defined (HAVE_QFONT_MONOSPACE) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
239 QFont fixed_font; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
240 fixed_font.setStyleHint (QFont::Monospace); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
241 QString default_family = fixed_font.defaultFamily (); |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
242 #elif defined (Q_WS_X11) || defined (Q_WS_WIN) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
243 QString default_family = "Courier New"; |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
244 #elif defined (Q_WS_MAC) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
245 QString default_family = "Courier"; |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
246 #else |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
247 QString default_family = "courier"; |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
248 #endif |
19916
6049bdfa8d56
make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents:
19899
diff
changeset
|
249 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
250 // Get the default custom editor |
19916
6049bdfa8d56
make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents:
19899
diff
changeset
|
251 #if defined (Q_OS_WIN32) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
252 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
|
253 #else |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
254 QString custom_editor = "emacs +%l %f"; |
19916
6049bdfa8d56
make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents:
19899
diff
changeset
|
255 #endif |
6049bdfa8d56
make notepad++ the custom default editor in windows
Torsten <ttl@justmail.de>
parents:
19899
diff
changeset
|
256 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
257 // Replace placeholders |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
258 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
|
259 settings_text.replace ("__default_font__", default_family); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
260 settings_text.replace ("__default_font_size__", "10"); |
18004
b001d9e9fd17
add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents:
17943
diff
changeset
|
261 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
262 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
|
263 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
264 if (! user_settings.open (QIODevice::WriteOnly)) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
265 return; |
18004
b001d9e9fd17
add systems default monospace font for terminal and editor to default settings
Torsten <ttl@justmail.de>
parents:
17943
diff
changeset
|
266 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
267 QTextStream out (&user_settings); |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
268 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
269 out << settings_text; |
18036
c97ee13f1027
fix build for systems without QFont::Monospace
John W. Eaton <jwe@octave.org>
parents:
18020
diff
changeset
|
270 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
271 user_settings.close (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
272 } |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
273 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
274 do_set_settings (m_settings_file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
275 } |
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
|
276 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
277 void resource_manager::do_set_settings (const QString& file) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
278 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
279 delete m_settings; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
280 m_settings = new QSettings (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
|
281 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
282 if (! (m_settings |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
283 && QFile::exists (m_settings->fileName ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
284 && m_settings->isWritable () |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
285 && m_settings->status () == QSettings::NoError)) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
286 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
287 QString msg = QString (QT_TR_NOOP ( |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
288 "The settings file\n%1\n" |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
289 "does not exist and can not be created.\n" |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
290 "Make sure you have read and write permissions to\n%2\n\n" |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
291 "Octave GUI must be closed now.")); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
292 QMessageBox::critical (nullptr, QString (QT_TR_NOOP ("Octave Critical Error")), |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
293 msg.arg (do_get_settings_file ()).arg (do_get_settings_directory ())); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
294 exit (1); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
295 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
296 } |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
297 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
298 bool resource_manager::do_update_settings_key (const QString& old_key, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
299 const QString& new_key) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
300 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
301 if (m_settings->contains (old_key)) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
302 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
303 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
|
304 m_settings->setValue (new_key, preference); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
305 m_settings->remove (old_key); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
306 return true; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
307 } |
24282
a669809df612
update wrong setting keys accidentally introduced into the settings file
Torsten <mttl@mailbox.org>
parents:
23219
diff
changeset
|
308 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
309 return false; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
310 } |
24282
a669809df612
update wrong setting keys accidentally introduced into the settings file
Torsten <mttl@mailbox.org>
parents:
23219
diff
changeset
|
311 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
312 bool resource_manager::do_is_first_run (void) const |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
313 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
314 return ! QFile::exists (m_settings_file); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
315 } |
13668
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
316 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
317 void resource_manager::do_update_network_settings (void) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
318 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
319 if (m_settings) |
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 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy; |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
322 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
323 if (m_settings->value ("useProxyServer",false).toBool ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
324 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
325 QString proxyTypeString = m_settings->value ("proxyType").toString (); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
326 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
327 if (proxyTypeString == "Socks5Proxy") |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
328 proxyType = QNetworkProxy::Socks5Proxy; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
329 else if (proxyTypeString == "HttpProxy") |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
330 proxyType = QNetworkProxy::HttpProxy; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
331 } |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
332 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
333 QNetworkProxy proxy; |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
334 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
335 proxy.setType (proxyType); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
336 proxy.setHostName (m_settings->value ("proxyHostName").toString ()); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
337 proxy.setPort (m_settings->value ("proxyPort",80).toInt ()); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
338 proxy.setUser (m_settings->value ("proxyUserName").toString ()); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
339 proxy.setPassword (m_settings->value ("proxyPassword").toString ()); |
17930
ffdbb82a0c78
allow welcome wizard dialog to be canceled
John W. Eaton <jwe@octave.org>
parents:
17790
diff
changeset
|
340 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
341 QNetworkProxy::setApplicationProxy (proxy); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
342 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
343 else |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
344 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
345 // 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
|
346 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
347 } |
13613
8728061cd0ec
Icons are now maintained by the ResourceManager.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13609
diff
changeset
|
348 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
349 QIcon resource_manager::do_icon (const QString& icon_name, bool fallback) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
350 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
351 if (fallback) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
352 return QIcon::fromTheme (icon_name, |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
353 QIcon (":/actions/icons/" + icon_name + ".png")); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
354 else |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
355 return QIcon::fromTheme (icon_name); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
356 } |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
357 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
358 // initialize a given combo box with available text encodings |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
359 void resource_manager::do_combo_encoding (QComboBox *combo, QString current) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
360 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
361 // 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
|
362 QList<int> all_mibs = QTextCodec::availableMibs (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
363 QStringList all_codecs; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
364 foreach (int mib, all_mibs) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
365 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
366 QTextCodec *c = QTextCodec::codecForMib (mib); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
367 all_codecs << c->name ().toUpper (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
368 } |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
369 all_codecs.removeDuplicates (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
370 qSort (all_codecs); |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
371 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
372 // the default encoding |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
373 #if defined (Q_OS_WIN32) |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
374 QString def_enc = "SYSTEM"; |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
375 #else |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
376 QString def_enc = "UTF-8"; |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
377 #endif |
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
378 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
379 // 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
|
380 QString enc = current; |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
381 if (enc.isEmpty ()) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
382 { |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
383 enc = m_settings->value ("editor/default_encoding",def_enc).toString (); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
384 if (enc.isEmpty ()) // still empty? |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
385 enc = def_enc; // take default |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
386 } |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
387 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
388 // fill the combo box |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
389 foreach (QString c, all_codecs) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
390 combo->addItem (c); |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
391 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
392 // prepend the default item |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
393 combo->insertSeparator (0); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
394 combo->insertItem (0, def_enc); |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
395 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
396 // select the current/default item |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
397 int idx = combo->findText (enc); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
398 if (idx >= 0) |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
399 combo->setCurrentIndex (idx); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
400 else |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
401 combo->setCurrentIndex (0); |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
402 |
24718
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
403 combo->setMaxVisibleItems (12); |
ea1c88bd4430
move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
404 } |
20774
5c5e085a1ae6
allow selecting an encoding when saving a file (bug #45688)
Torsten <ttl@justmail.de>
parents:
20428
diff
changeset
|
405 } |