13501
|
1 /* Quint - A graphical user interface for Octave |
|
2 * Copyright (C) 2011 Jacob Dawid |
|
3 * jacob.dawid@googlemail.com |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #ifndef MAINWINDOW_H |
|
20 #define MAINWINDOW_H |
|
21 |
|
22 #include <QtGui/QMainWindow> |
|
23 #include <QThread> |
|
24 #include <QTabWidget> |
|
25 #include <QMdiArea> |
|
26 #include <QStatusBar> |
|
27 #include <QToolBar> |
|
28 #include <QQueue> |
|
29 #include "OctaveTerminal.h" |
|
30 #include "OctaveLink.h" |
|
31 #include "VariablesDockWidget.h" |
|
32 #include "HistoryDockWidget.h" |
|
33 #include "FilesDockWidget.h" |
|
34 #include "BrowserWidget.h" |
|
35 #include "IRCWidget.h" |
|
36 |
|
37 // Octave includes |
|
38 #undef PACKAGE_BUGREPORT |
|
39 #undef PACKAGE_NAME |
|
40 #undef PACKAGE_STRING |
|
41 #undef PACKAGE_TARNAME |
|
42 #undef PACKAGE_VERSION |
|
43 #undef PACKAGE_URL |
|
44 #include "octave/config.h" |
|
45 |
|
46 #include "octave/debug.h" |
|
47 #include "octave/octave.h" |
|
48 #include "octave/symtab.h" |
|
49 #include "octave/parse.h" |
|
50 #include "octave/unwind-prot.h" |
|
51 #include "octave/toplev.h" |
|
52 #include "octave/load-path.h" |
|
53 #include "octave/error.h" |
|
54 #include "octave/quit.h" |
|
55 #include "octave/variables.h" |
|
56 #include "octave/sighandlers.h" |
|
57 #include "octave/sysdep.h" |
|
58 #include "octave/str-vec.h" |
|
59 #include "octave/cmd-hist.h" |
|
60 #include "octave/cmd-edit.h" |
|
61 #include "octave/oct-env.h" |
|
62 #include "octave/symtab.h" |
|
63 #include "cmd-edit.h" |
|
64 |
|
65 typedef struct yy_buffer_state *YY_BUFFER_STATE; |
|
66 extern OCTINTERP_API YY_BUFFER_STATE create_buffer (FILE *f); |
|
67 extern OCTINTERP_API void switch_to_buffer (YY_BUFFER_STATE buf); |
|
68 extern OCTINTERP_API FILE *get_input_from_stdin (void); |
|
69 |
|
70 // System |
|
71 #include <termios.h> |
|
72 #include <sys/types.h> |
|
73 #include <signal.h> |
|
74 #include <sys/types.h> |
|
75 #include <sys/wait.h> |
|
76 #include <iostream> |
|
77 #include <vector> |
|
78 #include "pty.h" |
|
79 |
|
80 class OctaveMainThread; |
|
81 class OctaveCallbackThread; |
|
82 |
|
83 /** |
|
84 * \class MainWindow |
|
85 * |
|
86 * Represents the main window. |
|
87 */ |
|
88 class MainWindow : public QMainWindow { |
|
89 Q_OBJECT |
|
90 public: |
|
91 MainWindow(QWidget *parent = 0); |
|
92 ~MainWindow(); |
|
93 |
|
94 bool isRunning() { return m_isRunning; } |
|
95 OctaveTerminal *octaveTerminal() { return m_octaveTerminal; } |
|
96 VariablesDockWidget *variablesDockWidget() { return m_variablesDockWidget; } |
|
97 HistoryDockWidget *historyDockWidget() { return m_historyDockWidget; } |
|
98 FilesDockWidget *filesDockWidget() { return m_filesDockWidget; } |
|
99 |
|
100 public slots: |
|
101 void handleOpenFileRequest(QString fileName); |
|
102 void reportStatusMessage(QString statusMessage); |
|
103 void openWebPage(QString url); |
|
104 void handleSaveWorkspaceRequest(); |
|
105 void handleLoadWorkspaceRequest(); |
|
106 void handleClearWorkspaceRequest(); |
|
107 void handleCommandDoubleClicked(QString command); |
|
108 void alignMdiWindows(); |
|
109 void openBugTrackerPage(); |
|
110 void processSettingsDialogRequest(); |
|
111 |
|
112 protected: |
|
113 void closeEvent(QCloseEvent *closeEvent); |
|
114 void readSettings(); |
|
115 void writeSettings(); |
|
116 |
|
117 private: |
|
118 void construct(); |
|
119 void establishOctaveLink(); |
|
120 QMdiArea *m_centralMdiArea; |
|
121 |
|
122 // Mdi sub windows. |
|
123 OctaveTerminal *m_octaveTerminal; |
|
124 BrowserWidget *m_documentationWidget; |
|
125 IRCWidget *m_ircWidget; |
|
126 |
|
127 QMdiSubWindow *m_octaveTerminalSubWindow; |
|
128 QMdiSubWindow *m_documentationWidgetSubWindow; |
|
129 QMdiSubWindow *m_ircWidgetSubWindow; |
|
130 |
|
131 // Dock widgets. |
|
132 VariablesDockWidget *m_variablesDockWidget; |
|
133 HistoryDockWidget *m_historyDockWidget; |
|
134 FilesDockWidget *m_filesDockWidget; |
|
135 |
|
136 // Toolbars. |
|
137 QStatusBar *m_statusBar; |
|
138 |
|
139 QString m_settingsFile; |
|
140 |
|
141 // Threads for running octave and managing the data interaction. |
|
142 OctaveMainThread *m_octaveMainThread; |
|
143 OctaveCallbackThread *m_octaveCallbackThread; |
|
144 bool m_isRunning; |
|
145 }; |
|
146 |
|
147 class OctaveMainThread : public QThread { |
|
148 Q_OBJECT |
|
149 public: |
|
150 OctaveMainThread(QObject *parent) |
|
151 : QThread(parent) { |
|
152 } |
|
153 protected: |
|
154 void run() { |
|
155 int argc = 3; |
|
156 const char* argv[] = {"octave", "--interactive", "--line-editing"}; |
|
157 octave_main(argc, (char**)argv, 1); |
|
158 main_loop(); |
|
159 clean_up_and_exit(0); |
|
160 } |
|
161 }; |
|
162 |
|
163 class OctaveCallbackThread : public QThread { |
|
164 Q_OBJECT |
|
165 public: |
|
166 OctaveCallbackThread(QObject *parent, MainWindow *mainWindow) |
|
167 : QThread(parent), |
|
168 m_mainWindow(mainWindow) { |
|
169 } |
|
170 |
|
171 protected: |
|
172 void run() { |
|
173 while(m_mainWindow->isRunning()) { |
|
174 |
|
175 // Get a full variable list. |
|
176 QList<SymbolRecord> symbolTable = OctaveLink::instance()->currentSymbolTable(); |
|
177 if(symbolTable.size()) { |
|
178 m_mainWindow->variablesDockWidget()->setVariablesList(symbolTable); |
|
179 } |
|
180 |
|
181 // Collect history list. |
|
182 string_vector historyList = OctaveLink::instance()->currentHistory(); |
|
183 if(historyList.length()) { |
|
184 m_mainWindow->historyDockWidget()->updateHistory(historyList); |
|
185 } |
|
186 |
|
187 usleep(100000); |
|
188 } |
|
189 } |
|
190 private: |
|
191 MainWindow *m_mainWindow; |
|
192 }; |
|
193 |
|
194 #endif // MAINWINDOW_H |