GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
octave-gui.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 Jacob Dawid
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QApplication>
28 #include <QTextCodec>
29 #include <QThread>
30 #include <QTranslator>
31 #include <QtGlobal>
32 #include <QStyleFactory>
33 
34 #include <cstdio>
35 
36 #include <iostream>
37 
38 #if defined (HAVE_SYS_IOCTL_H)
39 # include <sys/ioctl.h>
40 #endif
41 
42 #include "lo-utils.h"
43 #include "oct-env.h"
44 #include "oct-syscalls.h"
45 #include "signal-wrappers.h"
46 
47 #include "builtin-defun-decls.h"
48 #include "defaults.h"
49 #include "display.h"
50 #include "octave.h"
51 #include "sysdep.h"
52 #include "unistd-wrappers.h"
53 
54 #include "main-window.h"
55 #include "octave-gui.h"
56 #include "resource-manager.h"
57 #include "shortcut-manager.h"
58 #include "welcome-wizard.h"
59 
60 // Disable all Qt messages by default.
61 
62 static void
63 #if defined (QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT)
64 message_handler (QtMsgType, const QMessageLogContext &, const QString &)
65 #else
66 message_handler (QtMsgType, const char *)
67 #endif
68 { }
69 
70 namespace octave
71 {
73  : application (argc, argv), m_argc (argc), m_argv (argv),
74  m_gui_running (false)
75  {
76  // This should probably happen early.
77  sysdep_init ();
78  }
79 
80  bool gui_application::start_gui_p (void) const
81  {
82  return m_options.gui ();
83  }
84 
86  {
88 
90 
91  std::string show_gui_msgs =
92  sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES");
93 
94  // Installing our handler suppresses the messages.
95 
96  if (show_gui_msgs.empty ())
97  {
98 #if defined (HAVE_QINSTALLMESSAGEHANDLER)
99  qInstallMessageHandler (message_handler);
100 #else
101  qInstallMsgHandler (message_handler);
102 #endif
103  }
104 
105  // If START_GUI is false, we still set up the QApplication so that
106  // we can use Qt widgets for plot windows.
107 
108  QApplication qt_app (m_argc, m_argv);
109  QTranslator gui_tr, qt_tr, qsci_tr;
110 
111  // Set the codec for all strings (before wizard or any GUI object)
112 #if ! defined (Q_OS_WIN32)
113  QTextCodec::setCodecForLocale (QTextCodec::codecForName ("UTF-8"));
114 #endif
115 
116 #if defined (HAVE_QT4)
117  QTextCodec::setCodecForCStrings (QTextCodec::codecForName ("UTF-8"));
118 #endif
119 
120  // set windows style for windows
121 #if defined (Q_OS_WIN32)
122  qt_app.setStyle (QStyleFactory::create ("Windows"));
123 #endif
124 
125  bool start_gui = start_gui_p ();
126 
127  // Show welcome wizard if this is the first run.
128 
129  if (resource_manager::is_first_run () && start_gui)
130  {
131  // Before wizard.
132  resource_manager::config_translators (&qt_tr, &qsci_tr, &gui_tr);
133 
134  qt_app.installTranslator (&qt_tr);
135  qt_app.installTranslator (&gui_tr);
136  qt_app.installTranslator (&qsci_tr);
137 
138  welcome_wizard welcomeWizard;
139 
140  if (welcomeWizard.exec () == QDialog::Rejected)
141  exit (1);
142 
143  // Install settings file.
145  }
146  else
147  {
148  // Get settings file.
150 
151  // After settings.
152  resource_manager::config_translators (&qt_tr, &qsci_tr, &gui_tr);
153 
154  qt_app.installTranslator (&qt_tr);
155  qt_app.installTranslator (&gui_tr);
156 
157  if (start_gui)
158  qt_app.installTranslator (&qsci_tr);
159  }
160 
161  if (start_gui)
162  {
164 
165  // We provide specific terminal capabilities, so ensure that
166  // TERM is always set appropriately.
167 
168 #if defined (OCTAVE_USE_WINDOWS_API)
169  sys::env::putenv ("TERM", "cygwin");
170 #else
171  sys::env::putenv ("TERM", "xterm");
172 #endif
173 
175  }
176 
177  // Force left-to-right alignment (see bug #46204)
178  qt_app.setLayoutDirection (Qt::LeftToRight);
179 
180  // Create and show main window.
181 
182  main_window w (nullptr, this);
183 
184  if (start_gui)
185  {
186  w.read_settings ();
187 
188  w.init_terminal_size ();
189 
190  // Connect signals for changes in visibility not before w
191  // is shown.
192 
193  w.connect_visibility_changed ();
194 
195  w.focus_command_window ();
196 
197  gui_running (true);
198  }
199  else
200  qt_app.setQuitOnLastWindowClosed (false);
201 
202  return qt_app.exec ();
203  }
204 }
bool gui_running(void) const
Definition: octave-gui.h:47
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:242
static void config_translators(QTranslator *, QTranslator *, QTranslator *)
static void update_network_settings(void)
void set_application_id(void)
Definition: sysdep.cc:175
int argc
Definition: load-save.cc:646
gui_application(int argc, char **argv)
Definition: octave-gui.cc:72
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
string_vector argv
Definition: load-save.cc:648
static void init_data(void)
std::complex< double > w(std::complex< double > z, double relerr=0)
void octave_block_interrupt_signal(void)
static void message_handler(QtMsgType, const char *)
Definition: octave-gui.cc:66
is false
Definition: cellfun.cc:400
static void reload_settings(void)
Represents the main window.
Definition: main-window.h:96
static bool is_first_run(void)
bool start_gui_p(void) const
Definition: octave-gui.cc:80
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
void sysdep_init(void)
Definition: sysdep.cc:318