Mercurial > hg > octave-lyh
annotate libgui/src/resource-manager.cc @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | 096280194ca3 |
children |
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 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
3 Copyright (C) 2011-2012 Jacob Dawid |
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 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
10 option) any later version. |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
11 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
15 for more details. |
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 |
359098ad343e
update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents:
15196
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
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 |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
24 #include <config.h> |
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> |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
32 #include <QLibraryInfo> |
14845
9a355dfc7701
Fixed bug with GUI not starting the first time.
Jacob Dawid <jacob.dawid@gmail.com>
parents:
14804
diff
changeset
|
33 |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
34 #include "error.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
35 #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
|
36 #include "help.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
37 #include "oct-env.h" |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
38 #include "singleton-cleanup.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
39 |
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
40 #include "defaults.h" |
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
41 |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
42 #include "QTerminal.h" |
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
43 #include "workspace-model.h" |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
44 #include "resource-manager.h" |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
45 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
46 resource_manager *resource_manager::instance = 0; |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
47 |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
48 static QString |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
49 default_qt_settings_file (void) |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
50 { |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
51 std::string dsf = octave_env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS"); |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
52 |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
53 if (dsf.empty ()) |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
54 dsf = Voct_etc_dir + file_ops::dir_sep_str () + "default-qt-settings"; |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
55 |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
56 return QString::fromStdString (dsf); |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
57 } |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
58 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
59 resource_manager::resource_manager (void) |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
60 : settings (0), home_path (), first_run (false) |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
61 { |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
62 do_reload_settings (); |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
63 |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
64 default_settings = new QSettings (default_qt_settings_file (), |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
65 QSettings::IniFormat); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
66 } |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
67 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
68 resource_manager::~resource_manager (void) |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
69 { |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
70 delete settings; |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
71 delete default_settings; |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
72 } |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
73 |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
74 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
75 QString |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
76 resource_manager::get_gui_translation_dir (void) |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
77 { |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
78 // get environment variable for the locale dir (e.g. from run-octave) |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
79 std::string dldir = octave_env::getenv ("OCTAVE_LOCALE_DIR"); |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
80 if (dldir.empty ()) |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
81 dldir = Voct_locale_dir; // env-var empty, load the default location |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
82 return QString::fromStdString (dldir); |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
83 } |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
84 |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
85 void |
16858
cd29604214c5
Use the Qscintilla langiage file if available
Torsten <ttl@justmail.de>
parents:
16641
diff
changeset
|
86 resource_manager::config_translators (QTranslator *qt_tr, |
cd29604214c5
Use the Qscintilla langiage file if available
Torsten <ttl@justmail.de>
parents:
16641
diff
changeset
|
87 QTranslator *qsci_tr, |
cd29604214c5
Use the Qscintilla langiage file if available
Torsten <ttl@justmail.de>
parents:
16641
diff
changeset
|
88 QTranslator *gui_tr) |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
89 { |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
90 bool loaded; |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
91 |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
92 QString qt_trans_dir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
93 QSettings *settings = resource_manager::get_settings (); |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
94 // FIXME -- what should happen if settings is 0? |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
95 |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
96 // get the locale from the settings |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
97 QString language = settings->value ("language","SYSTEM").toString (); |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
98 if (language == "SYSTEM") |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
99 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
|
100 |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
101 // load the translator file for qt strings |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
102 loaded = qt_tr->load("qt_" + language, qt_trans_dir); |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
103 if (!loaded) // try lower case |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
104 qt_tr->load("qt_" + language.toLower (), qt_trans_dir); |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
105 |
16858
cd29604214c5
Use the Qscintilla langiage file if available
Torsten <ttl@justmail.de>
parents:
16641
diff
changeset
|
106 // load the translator file for qscintilla settings |
16863
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
107 loaded = qsci_tr->load("qscintilla_" + language, qt_trans_dir); |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
108 if (!loaded) // try lower case |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
109 qsci_tr->load("qscintilla_" + language.toLower (), qt_trans_dir); |
c82b3614eace
try harder to load the qt translation files at start up
Torsten <ttl@justmail.de>
parents:
16858
diff
changeset
|
110 |
15972
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
111 // load the translator file for gui strings |
22ab4fe661d7
gui: selectable language in settings dialog
Torsten <ttl@justmail.de>
parents:
15927
diff
changeset
|
112 gui_tr->load (language, get_gui_translation_dir ()); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
113 } |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
114 |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
115 bool |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
116 resource_manager::instance_ok (void) |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
117 { |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
118 bool retval = true; |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
119 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
120 if (! instance) |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
121 { |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
122 instance = new resource_manager (); |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
123 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
124 if (instance) |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
125 singleton_cleanup_list::add (cleanup_instance); |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
126 } |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
127 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
128 if (! instance) |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
129 { |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
130 ::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
|
131 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
132 retval = false; |
15161
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
133 } |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
134 |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
135 return retval; |
ad9523348676
Make resource_manager a singleton with Octave conventions
Mike Miller <mtmiller@ieee.org>
parents:
15159
diff
changeset
|
136 } |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
137 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
138 QSettings * |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
139 resource_manager::do_get_settings (void) const |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
140 { |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
141 return settings; |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
142 } |
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
143 |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
144 QSettings * |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
145 resource_manager::do_get_default_settings (void) const |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
146 { |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
147 return default_settings; |
13537
a43ecce77eec
Introduced a central ResourceManager class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
148 } |
13539
a4b5cad8f7c6
Added command line parser class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13537
diff
changeset
|
149 |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
150 QString |
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
151 resource_manager::do_get_home_path (void) const |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
152 { |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
153 return home_path; |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
154 } |
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
155 |
13539
a4b5cad8f7c6
Added command line parser class.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13537
diff
changeset
|
156 void |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
157 resource_manager::do_reload_settings (void) |
13668
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
158 { |
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
159 QDesktopServices desktopServices; |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
160 home_path = desktopServices.storageLocation (QDesktopServices::HomeLocation); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
161 QString settings_path = home_path + "/.config/octave/"; |
15159
098546e95a5e
allow location of default settings file to be configurable
John W. Eaton <jwe@octave.org>
parents:
15081
diff
changeset
|
162 QString settings_file = settings_path + "qt-settings"; |
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
|
163 |
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
|
164 if (!QFile::exists (settings_file)) |
15367
501a9cc2c68f
maint: whitespace cleanup in GUI code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15300
diff
changeset
|
165 { |
501a9cc2c68f
maint: whitespace cleanup in GUI code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15300
diff
changeset
|
166 QDir("/").mkpath (settings_path); |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
167 QFile::copy (default_qt_settings_file (), settings_file); |
15367
501a9cc2c68f
maint: whitespace cleanup in GUI code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15300
diff
changeset
|
168 first_run = true; |
501a9cc2c68f
maint: whitespace cleanup in GUI code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15300
diff
changeset
|
169 } |
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
|
170 else |
15367
501a9cc2c68f
maint: whitespace cleanup in GUI code
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15300
diff
changeset
|
171 first_run = false; |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
172 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
173 do_set_settings (settings_file); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
174 } |
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
|
175 |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
176 void |
15300
fd27e10b9b05
pass QString by const reference instead of value
John W. Eaton <jwe@octave.org>
parents:
15204
diff
changeset
|
177 resource_manager::do_set_settings (const QString& file) |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
178 { |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
179 delete settings; |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
180 settings = new QSettings (file, QSettings::IniFormat); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
181 } |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
182 |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
183 bool |
16593
e13051d7a472
allow GUI window layout to be restored
John W. Eaton <jwe@octave.org>
parents:
16379
diff
changeset
|
184 resource_manager::do_is_first_run (void) const |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
185 { |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
186 return first_run; |
13668
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
187 } |
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
188 |
421afeae929b
Added a settings wizard that appears at first startup of Octave GUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13665
diff
changeset
|
189 void |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
190 resource_manager::do_update_network_settings (void) |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
191 { |
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
192 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy; |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
193 |
16379
4bb1b82076e5
gui: provide defaults for all values read from the settings file
Torsten <ttl@justmail.de>
parents:
15972
diff
changeset
|
194 if (settings->value ("useProxyServer",false).toBool ()) |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
195 { |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
196 QString proxyTypeString = settings->value ("proxyType").toString (); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
197 |
13609
b355901aade4
Added username and password field to proxy settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13607
diff
changeset
|
198 if (proxyTypeString == "Socks5Proxy") |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
199 proxyType = QNetworkProxy::Socks5Proxy; |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
200 else if (proxyTypeString == "HttpProxy") |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
201 proxyType = QNetworkProxy::HttpProxy; |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
202 } |
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
203 |
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
204 QNetworkProxy proxy; |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
205 |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
206 proxy.setType (proxyType); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
207 proxy.setHostName (settings->value ("proxyHostName").toString ()); |
16379
4bb1b82076e5
gui: provide defaults for all values read from the settings file
Torsten <ttl@justmail.de>
parents:
15972
diff
changeset
|
208 proxy.setPort (settings->value ("proxyPort",80).toInt ()); |
15164
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
209 proxy.setUser (settings->value ("proxyUserName").toString ()); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
210 proxy.setPassword (settings->value ("proxyPassword").toString ()); |
bc801a44bb1f
follow Octave pattern for resource_manager singleton
John W. Eaton <jwe@octave.org>
parents:
15161
diff
changeset
|
211 |
13607
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
212 QNetworkProxy::setApplicationProxy (proxy); |
fd31226d4c3a
Proxy settings can now be configured.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13571
diff
changeset
|
213 } |
13613
8728061cd0ec
Icons are now maintained by the ResourceManager.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13609
diff
changeset
|
214 |
16610
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
215 QStringList |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
216 resource_manager::storage_class_names (void) |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
217 { |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
218 return workspace_model::storage_class_names (); |
16610
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
219 } |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
220 |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
221 QList<QColor> |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
222 resource_manager::storage_class_default_colors (void) |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
223 { |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
224 return workspace_model::storage_class_default_colors (); |
16610
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
225 } |
a1f613e5066d
workspace view colors based upon variable scope (derived from Dan's patch #8013)
Torsten <ttl@justmail.de>
parents:
16593
diff
changeset
|
226 |
16620
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
227 QStringList |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
228 resource_manager::terminal_color_names (void) |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
229 { |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
230 return QTerminal::color_names (); |
16620
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
231 } |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
232 |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
233 QList<QColor> |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
234 resource_manager::terminal_default_colors (void) |
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
235 { |
16641
64f9a3e301d3
don't store default values in resource manager class
John W. Eaton <jwe@octave.org>
parents:
16620
diff
changeset
|
236 return QTerminal::default_colors (); |
16620
818eef7b2618
allow terminal colors to be set from preferences dialog
John W. Eaton <jwe@octave.org>
parents:
16610
diff
changeset
|
237 } |