26 #if defined (HAVE_CONFIG_H)
38 #include <QFontComboBox>
39 #include <QFontDatabase>
40 #include <QLibraryInfo>
41 #include <QMessageBox>
42 #include <QNetworkProxy>
43 #include <QStandardPaths>
67 : m_settings_directory (), m_settings_file (), m_settings (
nullptr),
68 m_default_settings (
nullptr), m_temporary_files (), m_icon_fallbacks ()
72 =
new gui_settings (QSettings::IniFormat, QSettings::UserScope,
73 "octave",
"octave-gui");
75 m_settings_file = m_default_settings->fileName ();
77 QFileInfo sfile (m_settings_file);
78 m_settings_directory = sfile.absolutePath ();
80 QString xdg_config_home
81 = QString::fromLocal8Bit (qgetenv (
"XDG_CONFIG_HOME"));
83 if ((! sfile.exists ()) && xdg_config_home.isEmpty ())
91 #if defined (HAVE_QSTANDARDPATHS)
93 = QStandardPaths::writableLocation (QStandardPaths::HomeLocation);
96 = QDesktopServices::storageLocation (QDesktopServices::HomeLocation);
99 QString old_settings_directory = home_path +
"/.config/octave";
100 QString old_settings_file = old_settings_directory +
"/qt-settings";
102 QFile ofile (old_settings_file);
108 gui_settings old_settings (old_settings_file, QSettings::IniFormat);
110 QStringList keys = old_settings.allKeys ();
111 for (
int i = 0; i < keys.count(); i++)
112 m_default_settings->setValue (keys.at(i),
113 old_settings.
value(keys.at(i)));
115 m_default_settings->sync ();
132 std::string dldir = sys::env::getenv (
"OCTAVE_LOCALE_DIR");
139 QTranslator *qsci_tr,
145 = QLibraryInfo::location (QLibraryInfo::TranslationsPath);
147 QString language =
"SYSTEM";
160 if (language ==
"SYSTEM")
166 qt_tr->load (sys_locale,
"qt",
"_", qt_trans_dir);
167 qsci_tr->load (sys_locale,
"qscintilla",
"_", qt_trans_dir);
173 loaded = qt_tr->load (
"qt_" + language, qt_trans_dir);
175 qt_tr->load (
"qt_" + language.toLower (), qt_trans_dir);
177 loaded = qsci_tr->load (
"qscintilla_" + language, qt_trans_dir);
179 qsci_tr->load (
"qscintilla_" + language.toLower (), qt_trans_dir);
236 QString msg (QT_TR_NOOP (
"Octave has lost its settings.\n"
237 "This should not happen.\n\n"
238 "Please report this bug.\n\n"
239 "Octave GUI must be closed now."));
241 QMessageBox::critical (
nullptr,
242 QString (QT_TR_NOOP (
"Octave Critical Error")),
254 QString msg (QT_TR_NOOP (
"Octave has lost its default settings.\n"
255 "This should not happen.\n"
256 "Please report this bug.\n\n"
257 "Octave GUI must be closed now."));
259 QMessageBox::critical (
nullptr,
260 QString (QT_TR_NOOP (
"Octave Critical Error")),
280 QString default_family;
283 QFontComboBox font_combo_box;
284 font_combo_box.setFontFilters (QFontComboBox::MonospacedFonts);
287 for (
int index = 0; index < font_combo_box.count(); index++)
288 fonts << font_combo_box.itemText(index);
290 #if defined (Q_OS_MAC)
300 if (default_family.isEmpty ())
303 QFont fixed_font = QFontDatabase::systemFont (QFontDatabase::FixedFont);
304 default_family = fixed_font.defaultFamily ();
307 if (! fonts.contains (default_family))
311 default_family = fonts[0];
316 std::string env_default_family = sys::env::getenv (
"OCTAVE_DEFAULT_FONT");
317 if (! env_default_family.empty ())
320 return default_family;
330 QFont font = QApplication::font ();
332 int font_size = font.pointSize ();
334 font_size =
static_cast <int> (
std::floor(font.pointSizeF ()));
337 QString default_font_size =
"10";
339 default_font_size = QString::number (font_size);
341 std::string env_default_font_size
342 = sys::env::getenv (
"OCTAVE_DEFAULT_FONT_SIZE");
344 if (! env_default_font_size.empty ())
348 result << default_family;
349 result << default_font_size;
357 QString custom_editor;
358 QStringList def_font;
367 std::string env_default_editor
368 = sys::env::getenv (
"OCTAVE_DEFAULT_EDITOR");
370 if (! env_default_editor.empty ())
380 if (! custom_editor.isEmpty ())
384 if (def_font.count () > 1)
396 #if defined (HAVE_QSCINTILLA)
400 int actual_style = 0;
403 if ((
lexer->description (actual_style)) !=
"")
404 styles[max_style++] = actual_style;
412 const QFont& base)
const
416 dest.setBold (attr.bold ());
417 dest.setItalic (attr.italic ());
418 dest.setUnderline (attr.underline ());
423 #if defined (HAVE_QSCINTILLA)
442 QStringList lexer_keys =
settings->allKeys ();
456 QFont df (def_font[0], def_font[1].toInt ());
458 lexer->setDefaultFont (dfa);
465 for (
int i = 0; i < max_style; i++)
467 c =
settings->get_color_value (QVariant (
lexer->color (styles[i])),
m);
468 lexer->setColor (c, styles[i]);
469 p =
settings->get_color_value (QVariant (
lexer->paper (styles[i])),
m);
470 lexer->setPaper (p, styles[i]);
472 lexer->setFont (dfa, styles[i]);
475 lexer->setDefaultColor (
lexer->color (styles[0]));
476 lexer->setDefaultPaper (
lexer->paper (styles[0]));
481 const std::string group_str =
group.toStdString ();
489 const std::string group_str =
group.toStdString ();
500 if (
m_settings->status () == QSettings::NoError)
507 if (! (QFile::exists (
m_settings->fileName ())
509 &&
m_settings->status () == QSettings::NoError))
512 = QString (QT_TR_NOOP (
"The settings file\n%1\n"
513 "does not exist and can not be created.\n"
514 "Make sure you have read and write permissions to\n%2\n\n"
515 "Octave GUI must be closed now."));
517 QMessageBox::critical (
nullptr,
518 QString (QT_TR_NOOP (
"Octave Critical Error")),
528 const QString& new_key)
554 QNetworkProxy::ProxyType proxy_type = QNetworkProxy::NoProxy;
560 QUrl proxy_url = QUrl ();
565 QString proxy_type_string
569 if (proxy_type_string ==
"Socks5Proxy")
570 proxy_type = QNetworkProxy::Socks5Proxy;
571 else if (proxy_type_string ==
"HttpProxy")
572 proxy_type = QNetworkProxy::HttpProxy;
575 if (proxy_type_string ==
"HttpProxy"
576 || proxy_type_string ==
"Socks5Proxy")
586 if (proxy_type_string ==
"HttpProxy")
588 else if (proxy_type_string ==
"Socks5Proxy")
591 QUrl env_var_url = QUrl ();
592 proxy_url.setScheme (scheme);
593 proxy_url.setHost (host);
594 proxy_url.setPort (port);
595 if (! user.isEmpty ())
596 proxy_url.setUserName (user);
597 if (! pass.isEmpty ())
598 proxy_url.setPassword (pass);
604 const std::array<std::string, 6> env_vars =
606 "ALL_PROXY",
"all_proxy",
607 "HTTP_PROXY",
"http_proxy",
608 "HTTPS_PROXY",
"https_proxy"
611 unsigned int count = 0;
612 while (! proxy_url.isValid () && count < env_vars.size ())
615 (sys::env::getenv (env_vars[count])));
619 if (proxy_url.isValid ())
622 scheme = proxy_url.scheme ();
624 if (scheme.contains (
"socks", Qt::CaseInsensitive))
625 proxy_type = QNetworkProxy::Socks5Proxy;
627 proxy_type = QNetworkProxy::HttpProxy;
629 host = proxy_url.host ();
630 port = proxy_url.port ();
631 user = proxy_url.userName ();
632 pass = proxy_url.password ();
638 proxy.setType (proxy_type);
639 proxy.setHostName (host);
640 proxy.setPort (port);
641 proxy.setUser (user);
642 proxy.setPassword (pass);
644 QNetworkProxy::setApplicationProxy (proxy);
647 std::string proxy_url_str = proxy_url.toString().toStdString ();
648 sys::env::putenv (
"http_proxy", proxy_url_str);
649 sys::env::putenv (
"HTTP_PROXY", proxy_url_str);
650 sys::env::putenv (
"https_proxy", proxy_url_str);
651 sys::env::putenv (
"HTTPS_PROXY", proxy_url_str);
655 const QString& icon_alt_name)
660 if (QIcon::hasThemeIcon (icon_name))
661 return QIcon (QIcon::fromTheme (icon_name));
662 else if ((! icon_alt_name.isEmpty ()) && QIcon::hasThemeIcon (icon_alt_name))
663 return QIcon (QIcon::fromTheme (icon_alt_name));
668 if (QFile (icon_file).exists ())
669 return QIcon (icon_file);
680 QList<int> all_mibs = QTextCodec::availableMibs ();
681 for (
auto mib : all_mibs)
683 QTextCodec *c = QTextCodec::codecForMib (mib);
684 codecs->append (c->name ().toUpper ());
688 codecs->append (QString (
"SYSTEM (") +
693 codecs->removeDuplicates ();
694 std::sort (codecs->begin (), codecs->end ());
699 const QString& current)
701 QStringList all_codecs;
705 QString enc = current;
711 bool default_exists =
false;
712 bool show_system =
false;
716 default_exists =
true;
718 QString default_enc =
719 QString (
"SYSTEM (") +
736 for (
const auto& c : all_codecs)
740 combo->insertSeparator (0);
741 if (show_system || ! default_exists)
742 combo->insertItem (0, default_enc);
747 int idx = combo->findText (enc, Qt::MatchExactly);
749 combo->setCurrentIndex (idx);
751 combo->setCurrentIndex (0);
753 combo->setMaxVisibleItems (12);
756 QPointer<QTemporaryFile>
758 const QString& contents)
760 QString ext = extension;
761 if ((! ext.isEmpty ()) && (! ext.startsWith (
'.')))
762 ext = QString (
".") + ext;
768 QPointer<QTemporaryFile> tmp_file
769 =
new QTemporaryFile (tmp_dir + QDir::separator() +
770 "octave_XXXXXX" + ext,
this);
772 if (tmp_file->open ())
774 tmp_file->write (contents.toUtf8 ());
787 if (tmp_file->exists ())
QVariant value(const gui_pref &pref) const
void update_network_settings(void)
bool update_settings_key(const QString &new_key, const QString &old_key)
QPointer< QTemporaryFile > create_tmp_file(const QString &extension=QString(), const QString &contents=QString())
QString m_settings_directory
gui_settings * m_settings
gui_settings * get_settings(void) const
void set_settings(const QString &file)
void read_lexer_settings(QsciLexer *lexer, gui_settings *settings, int mode=0, int def=0)
QString get_settings_file(void)
void config_translators(QTranslator *qt_tr, QTranslator *qsci_tr, QTranslator *gui_tr)
void get_codecs(QStringList *codecs)
QList< QTemporaryFile * > m_temporary_files
QString get_gui_translation_dir(void)
QFont copy_font_attributes(const QFont &attr, const QFont &base) const
void config_icon_theme(void)
QIcon icon(const QString &icon_name, bool octave_only=false, const QString &icon_alt_name=QString())
void remove_tmp_file(QPointer< QTemporaryFile > tmp_file)
QStringList get_default_font(void)
QString get_settings_directory(void)
gui_settings * m_default_settings
bool is_first_run(void) const
void combo_encoding(QComboBox *combo, const QString ¤t=QString())
void reload_settings(void)
gui_settings * get_default_settings(void) const
int get_valid_lexer_styles(QsciLexer *lexer, int *styles)
QStringList m_icon_fallbacks
QString get_default_font_family(void)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string oct_locale_dir(void)
const gui_pref cs_font_size("terminal/fontSize", QVariant(10))
const gui_pref cs_font("terminal/fontName", QVariant())
const int ed_max_lexer_styles
const gui_pref ed_default_enc("editor/default_encoding", QVariant("UTF-8"))
const int ed_max_style_number
const gui_pref global_icon_theme_index("icon_theme", QVariant(ICON_THEME_SYSTEM))
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 QStringList global_icon_paths
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 QStringList global_proxy_all_types
const gui_pref global_custom_editor("customFileEditor", QVariant("emacs +%l %f"))
const gui_pref global_proxy_port("proxyPort", QVariant(80))
const QStringList global_all_icon_themes
const gui_pref global_language("language", QVariant("SYSTEM"))
const QStringList settings_color_modes_ext(QStringList()<< ""<< "_2")
const int settings_reload_default_colors_flag
std::complex< T > floor(const std::complex< T > &x)
int system(const std::string &cmd_str)
const char * octave_locale_charset_wrapper(void)
static std::string get_temp_directory(void)
QString fromStdString(const std::string &s)