26 #if defined (HAVE_CONFIG_H)
35 #include <QFontComboBox>
36 #include <QFontDatabase>
37 #include <QLibraryInfo>
38 #include <QMessageBox>
39 #include <QNetworkProxy>
40 #if defined (HAVE_QSTANDARDPATHS)
41 # include <QStandardPaths>
43 # include <QDesktopServices>
74 +
"default-qt-settings");
80 : m_settings_directory (), m_settings_file (), m_settings (nullptr),
81 m_default_settings (nullptr), m_temporary_files ()
85 =
new gui_settings (QSettings::IniFormat, QSettings::UserScope,
86 "octave",
"octave-gui");
93 QString xdg_config_home
94 = QString::fromLocal8Bit (qgetenv (
"XDG_CONFIG_HOME"));
96 if ((! sfile.exists ()) && xdg_config_home.isEmpty ())
104 #if defined (HAVE_QSTANDARDPATHS)
106 = QStandardPaths::writableLocation (QStandardPaths::HomeLocation);
109 = QDesktopServices::storageLocation (QDesktopServices::HomeLocation);
112 QString old_settings_directory = home_path +
"/.config/octave";
113 QString old_settings_file = old_settings_directory +
"/qt-settings";
115 QFile ofile (old_settings_file);
121 gui_settings old_settings (old_settings_file, QSettings::IniFormat);
123 QStringList keys = old_settings.allKeys ();
124 for (
int i = 0; i < keys.count(); i++)
126 old_settings.
value(keys.at(i)));
152 QTranslator *qsci_tr,
158 = QLibraryInfo::location (QLibraryInfo::TranslationsPath);
160 QString language =
"SYSTEM";
173 if (language ==
"SYSTEM")
177 QLocale sys_locale = QLocale::system ();
179 qt_tr->load (sys_locale,
"qt",
"_", qt_trans_dir);
180 qsci_tr->load (sys_locale,
"qscintilla",
"_", qt_trans_dir);
186 loaded = qt_tr->load (
"qt_" + language, qt_trans_dir);
188 qt_tr->load (
"qt_" + language.toLower (), qt_trans_dir);
190 loaded = qsci_tr->load (
"qscintilla_" + language, qt_trans_dir);
192 qsci_tr->load (
"qscintilla_" + language.toLower (), qt_trans_dir);
221 QString default_family;
223 #if defined (Q_OS_MAC)
228 QFontComboBox font_combo_box;
229 font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts);
232 for (
int index = 0; index < font_combo_box.count(); index++)
233 fonts << font_combo_box.itemText(index);
242 if (default_family.isEmpty ())
244 #if defined (HAVE_QFONTDATABASE_SYSTEMFONT)
246 QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont);
247 default_family = fixed_font.defaultFamily ();
248 #elif defined (HAVE_QFONT_MONOSPACE)
250 fixed_font.setStyleHint (QFont::Monospace);
251 default_family = fixed_font.defaultFamily ();
259 if (! env_default_family.empty ())
262 return default_family;
274 if (! qt_settings.open (QFile::ReadOnly))
277 QTextStream in (&qt_settings);
278 QString settings_text = in.readAll ();
279 qt_settings.close ();
283 QString default_font_size =
"10";
285 std::string env_default_font_size
288 if (! env_default_font_size.empty ())
292 #if defined (Q_OS_WIN32)
293 QString custom_editor =
"notepad++ -n%l %f";
295 QString custom_editor =
"emacs +%l %f";
298 std::string env_default_editor
301 if (! env_default_editor.empty ())
305 settings_text.replace (
"__default_custom_editor__", custom_editor);
306 settings_text.replace (
"__default_font__", default_family);
307 settings_text.replace (
"__default_font_size__", default_font_size);
311 if (! user_settings.open (QIODevice::WriteOnly))
314 QTextStream out (&user_settings);
316 out << settings_text;
318 user_settings.close ();
335 if (! (QFile::exists (
m_settings->fileName ())
337 &&
m_settings->status () == QSettings::NoError))
340 = QString (QT_TR_NOOP (
"The settings file\n%1\n"
341 "does not exist and can not be created.\n"
342 "Make sure you have read and write permissions to\n%2\n\n"
343 "Octave GUI must be closed now."));
345 QMessageBox::critical (
nullptr,
346 QString (QT_TR_NOOP (
"Octave Critical Error")),
354 const QString& new_key)
376 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
380 QString proxyTypeString
383 if (proxyTypeString ==
"Socks5Proxy")
384 proxyType = QNetworkProxy::Socks5Proxy;
385 else if (proxyTypeString ==
"HttpProxy")
386 proxyType = QNetworkProxy::HttpProxy;
391 proxy.setType (proxyType);
401 QNetworkProxy::setApplicationProxy (proxy);
413 return QIcon (
":/actions/icons/" + icon_name +
".png");
418 return QIcon::fromTheme (icon_name,
419 QIcon (
":/actions/icons/" + icon_name +
".png"));
421 return QIcon::fromTheme (icon_name);
428 QList<int> all_mibs = QTextCodec::availableMibs ();
429 for (
auto mib : all_mibs)
431 QTextCodec *c = QTextCodec::codecForMib (mib);
432 codecs->append (c->name ().toUpper ());
436 codecs->append (QString (
"SYSTEM (") +
441 codecs->removeDuplicates ();
442 std::sort (codecs->begin (), codecs->end ());
447 const QString& current)
449 QStringList all_codecs;
453 QString enc = current;
459 bool default_exists =
false;
460 bool show_system =
false;
464 default_exists =
true;
466 QString default_enc =
467 QString (
"SYSTEM (") +
484 for (
const auto& c : all_codecs)
488 combo->insertSeparator (0);
489 if (show_system || ! default_exists)
490 combo->insertItem (0, default_enc);
495 int idx = combo->findText (enc, Qt::MatchExactly);
497 combo->setCurrentIndex (idx);
499 combo->setCurrentIndex (0);
501 combo->setMaxVisibleItems (12);
504 QPointer<QTemporaryFile>
506 const QString& contents)
508 QString ext = extension;
509 if ((! ext.isEmpty ()) && (! ext.startsWith (
'.')))
510 ext = QString (
".") + ext;
513 QString tmp_dir = QDir::tempPath () + QDir::separator() +
"octave";
514 QDir::temp ().mkdir (
"octave");
517 QPointer<QTemporaryFile> tmp_file
518 =
new QTemporaryFile (tmp_dir + QDir::separator() +
519 "octave_XXXXXX" + ext,
this);
521 if (tmp_file->open ())
523 tmp_file->write (contents.toUtf8 ());
536 if (tmp_file->exists ())
QVariant value(const gui_pref &pref) const
QString get_default_font_family(void)
void combo_encoding(QComboBox *combo, const QString ¤t=QString())
gui_settings * get_settings(void) const
gui_settings * get_default_settings(void) const
QString get_settings_file(void)
gui_settings * m_settings
void get_codecs(QStringList *codecs)
QString m_settings_directory
gui_settings * m_default_settings
QString get_gui_translation_dir(void)
bool is_first_run(void) const
QList< QTemporaryFile * > m_temporary_files
QPointer< QTemporaryFile > create_tmp_file(const QString &extension=QString(), const QString &contents=QString())
void update_network_settings(void)
QIcon icon(const QString &icon_name, bool fallback=true)
void remove_tmp_file(QPointer< QTemporaryFile > tmp_file)
bool update_settings_key(const QString &new_key, const QString &old_key)
QString get_settings_directory(void)
void set_settings(const QString &file)
void config_translators(QTranslator *qt_tr, QTranslator *qsci_tr, QTranslator *gui_tr)
void reload_settings(void)
static std::string getenv(const std::string &name)
const gui_pref ed_default_enc("editor/default_encoding", QVariant(QString("SYSTEM (")+QString(octave_locale_charset_wrapper()).toUpper()+QString(")")))
const gui_pref global_use_proxy("useProxyServer", QVariant(false))
const gui_pref global_mono_font("monospace_font", global_font_family)
const gui_pref global_proxy_pass("proxyPassword", QVariant(QString()))
const gui_pref global_proxy_host("proxyHostName", QVariant(QString()))
const gui_pref global_proxy_type("proxyType", QVariant(QString()))
const gui_pref global_proxy_user("proxyUserName", QVariant(QString()))
const gui_pref global_icon_theme("use_system_icon_theme", QVariant(true))
const QString global_font_family
const gui_pref global_proxy_port("proxyPort", QVariant(80))
const gui_pref global_language("language", QVariant("SYSTEM"))
const char * octave_locale_charset_wrapper(void)
QString fromStdString(const std::string &s)
std::string oct_locale_dir(void)
std::string oct_etc_dir(void)
std::string dir_sep_str(void)
static QString default_qt_settings_file(void)