# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1364935091 18000
# Node ID d5d67625f96109dac48d186d5a66a1aebd1fa8cf
# Parent  b1ea3813e37dc7a60403e75b4d1d97df721b74eb
Remove _terminal pointer from main_window. It is contained by other Qt object.

* main-window.cc, main-window.h (main_window : QMainWindow): Removed variable
_terminal because the terminal is contained within an object inheriting
QDockWidget. The object pointed to by _terminal is deleted by that container
class and can be recovered with the simple referenece
_terminal_dock_widget->widget (). Also removed a number of public member
functions no longer in use. (main_window::notice_settings): Changed the slot
to accept QSettings pointer rather than retrieve from resource_manager.  Also
moved a large amount of code from here to the QTerminal object. Focus now uses
widget contained in _terminal_dock_widget rather than _terminal pointer.
(main_window::handle_command_double_clicked): The terminal is now connected
to history via signal/slot so there is no longer a need for main_window to
send the terminal a command. (main_window::process_settings_dialog_request):
Include QSettings pointer as part of emitted signal.
(main_window::read_settings): Verify QSettings pointer before using and add
qDebug message if null. Include QSettings pointer as part of emitted signal.
(main_window::write_settings): Verify QSettings pointer before using and add
qDebug message if null. (main_window::construct): Change _terminal to a local
variable and drop underscore. Adjust and add signal/slot connections where
necessary.

* QTerminal.cc: Added to project. (QTerminal::notice_settings): Added this slot
so that the code, which was in main_window.cc, can be signaled rather than the
main window needing to handle this specific code. (QTerminal::relay_command):
Added this slot so that command can be a signal rather than called by
main_window.

* QTerminal.h (QTerminal : <baseclass>): Added slots notice_settings and
relay_command to both Windows and Unix definitions.  The code is similar to
both so it goes in new file QTerminal.cc rather than propogate further.

* QTerminal: Removed from project.

* files_dockwidget.cc, files_dockwidget.h (files_dock_widget::notice_settings):
Changed the slot to accept QSettings pointer rather than retrieve from
resource_manager.

* file_editor_tab.cc, file_editor_tab.h (file_editor_tab::notice_settings):
Changed the slot to accept QSettings pointer rather than retrieve from
resource_manager. (file_editor_tabl::file_editor_tab,
file_editor_tab::update_lexer): Check that QSettings pointer is not null
before using.

* file_editor.cc, file_editor.h (file_editor::notice_settings,
file_editor::fetab_settings_changed): Changed the slot/signal to accept
QSettings pointer rather than retrieve from resource_manager.
(file_editor::update_lexer, file_editor::file_editor_tab): Check that
QSettings pointer is not null before using.

* qterminal-module.mk (qterminal_libqterminal_la_SOURCES): Added QTerminal.cc
to source list.

diff -r b1ea3813e37d -r d5d67625f961 libgui/qterminal-module.mk
--- a/libgui/qterminal-module.mk	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/qterminal-module.mk	Tue Apr 02 15:38:11 2013 -0500
@@ -46,7 +46,8 @@
 
 qterminal_libqterminal_la_SOURCES = \
   qterminal/libqterminal/win32/QTerminalColors.cpp \
-  qterminal/libqterminal/win32/QWinTerminalImpl.cpp
+  qterminal/libqterminal/win32/QWinTerminalImpl.cpp \
+  qterminal/libqterminal/QTerminal.cc
 
 qterminal_libqterminal_la_MOC += \
   qterminal/libqterminal/win32/moc-QWinTerminalImpl.cc
@@ -73,7 +74,8 @@
   qterminal/libqterminal/unix/Vt102Emulation.cpp \
   qterminal/libqterminal/unix/SelfListener.cpp \
   qterminal/libqterminal/unix/TerminalModel.cpp \
-  qterminal/libqterminal/unix/TerminalView.cpp
+  qterminal/libqterminal/unix/TerminalView.cpp \
+  qterminal/libqterminal/QTerminal.cc
 
 qterminal_libqterminal_la_MOC += \
   qterminal/libqterminal/unix/moc-Emulation.cc \
diff -r b1ea3813e37d -r d5d67625f961 libgui/qterminal/libqterminal/QTerminal
--- a/libgui/qterminal/libqterminal/QTerminal	Mon Apr 01 22:19:35 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-/*
-
-Copyright (C) 2012 Michael Goffioul.
-Copyright (C) 2012 Jacob Dawid.
-
-This file is part of QTerminal.
-
-Foobar is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-QTerminal is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "QTerminal.h"
diff -r b1ea3813e37d -r d5d67625f961 libgui/qterminal/libqterminal/QTerminal.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/qterminal/libqterminal/QTerminal.cc	Tue Apr 02 15:38:11 2013 -0500
@@ -0,0 +1,50 @@
+/*
+
+Copyright (C) 2012 Michael Goffioul.
+Copyright (C) 2012 Jacob Dawid.
+
+This file is part of QTerminal.
+
+Foobar is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+QTerminal is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "QTerminal.h"
+
+#include <QSettings>
+
+void QTerminal::notice_settings (const QSettings *settings)
+{
+  // QSettings pointer is checked before emitting.
+
+  // Set terminal font:
+  QFont term_font = QFont();
+  term_font.setFamily(settings->value("terminal/fontName","Courier New").toString());
+  term_font.setPointSize(settings->value("terminal/fontSize",10).toInt ());
+  setTerminalFont (term_font);
+
+  QString cursorType = settings->value ("terminal/cursorType","ibeam").toString ();
+  bool cursorBlinking = settings->value ("terminal/cursorBlinking",true).toBool ();
+  if (cursorType == "ibeam")
+    setCursorType(QTerminalInterface::IBeamCursor, cursorBlinking);
+  else if (cursorType == "block")
+    setCursorType(QTerminalInterface::BlockCursor, cursorBlinking);
+  else if (cursorType == "underline")
+    setCursorType(QTerminalInterface::UnderlineCursor, cursorBlinking);
+}
+
+void QTerminal::relay_command (const QString& command)
+{
+  sendText (command);
+}
diff -r b1ea3813e37d -r d5d67625f961 libgui/qterminal/libqterminal/QTerminal.h
--- a/libgui/qterminal/libqterminal/QTerminal.h	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/qterminal/libqterminal/QTerminal.h	Tue Apr 02 15:38:11 2013 -0500
@@ -34,6 +34,10 @@
         QTerminal(QWidget *xparent = 0)
             : QWinTerminalImpl(xparent) { }
         ~QTerminal() { }
+
+    public slots:
+        void notice_settings (const QSettings *settings);
+        void relay_command (const QString& text);
     };
 #else
     #include "unix/QUnixTerminalImpl.h"
@@ -44,6 +48,10 @@
         QTerminal(QWidget *xparent = 0)
             : QUnixTerminalImpl(xparent) { }
         ~QTerminal() { }
+
+    public slots:
+        void notice_settings (const QSettings *settings);
+        void relay_command (const QString& command);
     };
 #endif
 
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/files-dockwidget.cc
--- a/libgui/src/files-dockwidget.cc	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/files-dockwidget.cc	Tue Apr 02 15:38:11 2013 -0500
@@ -185,11 +185,9 @@
 }
 
 void
-files_dock_widget::notice_settings ()
+files_dock_widget::notice_settings (const QSettings *settings)
 {
-  QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
+  // QSettings pointer is checked before emitting.
 
   _file_tree_view->setColumnHidden (0, !settings->value ("showFilenames",true).toBool ());
   _file_tree_view->setColumnHidden (1, !settings->value ("showFileSize",false).toBool ());
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/files-dockwidget.h
--- a/libgui/src/files-dockwidget.h	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/files-dockwidget.h	Tue Apr 02 15:38:11 2013 -0500
@@ -34,6 +34,7 @@
 #include <QVBoxLayout>
 #include <QAction>
 #include <QTreeView>
+#include <QSettings>
 
 #include <QLineEdit>
 #include "octave-dock-widget.h"
@@ -67,7 +68,7 @@
   void display_directory (const QString& directory);
 
   /** Tells the widget to react on changed settings. */
-  void notice_settings ();
+  void notice_settings (const QSettings *settings);
 
 signals:
   /** Emitted, whenever the user requested to open a file. */
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/m-editor/file-editor-tab.cc
--- a/libgui/src/m-editor/file-editor-tab.cc	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Tue Apr 02 15:38:11 2013 -0500
@@ -116,7 +116,9 @@
   connect (&_file_system_watcher, SIGNAL (fileChanged (QString)),
            this, SLOT (file_has_changed (QString)));
 
-  notice_settings ();
+  QSettings *settings = resource_manager::get_settings ();
+  if (settings)
+    notice_settings (settings);
 }
 
 file_editor_tab::~file_editor_tab ()
@@ -242,7 +244,8 @@
     }
 
   QSettings *settings = resource_manager::get_settings ();
-  lexer->readSettings (*settings);
+  if (settings)
+    lexer->readSettings (*settings);
   _edit_area->setLexer (lexer);
 
 }
@@ -1003,14 +1006,12 @@
 }
 
 void
-file_editor_tab::notice_settings ()
+file_editor_tab::notice_settings (const QSettings *settings)
 {
+  // QSettings pointer is checked before emitting.
+
   update_lexer ();
   QFontMetrics lexer_font_metrics (_edit_area->lexer ()->defaultFont (0));
-  QSettings *settings = resource_manager::get_settings ();
-
-  if (settings==NULL)
-    return; // this shouldn't happen!
 
   _edit_area->setCaretLineVisible(settings->value ("editor/highlightCurrentLine",true).toBool ());
 
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/m-editor/file-editor-tab.h
--- a/libgui/src/m-editor/file-editor-tab.h	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.h	Tue Apr 02 15:38:11 2013 -0500
@@ -27,6 +27,7 @@
 #include <QWidget>
 #include <QCloseEvent>
 #include <QFileSystemWatcher>
+#include <QSettings>
 
 #include "find-dialog.h"
 
@@ -44,7 +45,7 @@
   void handle_margin_clicked (int line, int margin, Qt::KeyboardModifiers state);
 
   /** Tells the editor tab to react on changed settings. */
-  void notice_settings ();
+  void notice_settings (const QSettings *settings);
   /** Will initiate close if associated with the identifier tag. */
   void conditional_close (const QWidget* ID);
   /** Change to a different editor tab by identifier tag. */
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/m-editor/file-editor.cc
--- a/libgui/src/m-editor/file-editor.cc	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Tue Apr 02 15:38:11 2013 -0500
@@ -594,10 +594,10 @@
 }
 
 void
-file_editor::notice_settings ()
+file_editor::notice_settings (const QSettings *settings)
 {
   // Relay signal to file editor tabs.
-  emit fetab_settings_changed ();
+  emit fetab_settings_changed (settings);
 }
 
 void
@@ -874,8 +874,8 @@
            parent (), SLOT (handle_command_double_clicked (const QString&)));
   
   // Signals from the file_editor non-trivial operations
-  connect (this, SIGNAL (fetab_settings_changed ()),
-           f, SLOT (notice_settings ()));
+  connect (this, SIGNAL (fetab_settings_changed (const QSettings *)),
+           f, SLOT (notice_settings (const QSettings *)));
   connect (this, SIGNAL (fetab_close_request (const QWidget*)),
            f, SLOT (conditional_close (const QWidget*)));
   connect (this, SIGNAL (fetab_change_request (const QWidget*)),
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/m-editor/file-editor.h
--- a/libgui/src/m-editor/file-editor.h	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/m-editor/file-editor.h	Tue Apr 02 15:38:11 2013 -0500
@@ -29,6 +29,7 @@
 #include <QStatusBar>
 #include <QCloseEvent>
 #include <QTabWidget>
+#include <QSettings>
 
 #include <map>
 
@@ -60,7 +61,7 @@
   void handle_quit_debug_mode ();
 
 signals:
-  void fetab_settings_changed ();
+  void fetab_settings_changed (const QSettings *settings);
   void fetab_close_request (const QWidget* ID);
   void fetab_change_request (const QWidget* ID);
   void fetab_file_name_query (const QWidget* ID);
@@ -138,7 +139,7 @@
   void handle_edit_file_request (const QString& file);
 
   /** Tells the editor to react on changed settings. */
-  void notice_settings ();
+  void notice_settings (const QSettings *settings);
 
 private slots:
   void request_open_file (const QString& fileName, int line = -1,
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/main-window.cc
--- a/libgui/src/main-window.cc	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/main-window.cc	Tue Apr 02 15:38:11 2013 -0500
@@ -161,9 +161,8 @@
 }
 
 void
-main_window::handle_command_double_clicked (const QString& command)
+main_window::handle_command_double_clicked (const QString&)
 {
-  _terminal->sendText (command);
   focus_command_window ();
 }
 
@@ -199,34 +198,18 @@
   if (change_settings == QDialog::Accepted)
     {
       settingsDialog->write_changed_settings ();
-      emit settings_changed ();
+      QSettings *settings = resource_manager::get_settings ();
+      if (settings)
+        emit settings_changed (settings);
     }
   delete settingsDialog;
 }
 
 
 void
-main_window::notice_settings ()
+main_window::notice_settings (const QSettings *settings)
 {
-  QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
-
-  // Set terminal font:
-  QFont term_font = QFont();
-  term_font.setFamily(settings->value("terminal/fontName","Courier New").toString());
-  term_font.setPointSize(settings->value("terminal/fontSize",10).toInt ());
-  _terminal->setTerminalFont (term_font);
-
-  QString cursorType = settings->value ("terminal/cursorType","ibeam").toString ();
-  bool cursorBlinking = settings->value ("terminal/cursorBlinking",true).toBool ();
-  if (cursorType == "ibeam")
-    _terminal->setCursorType(QTerminalInterface::IBeamCursor, cursorBlinking);
-  else if (cursorType == "block")
-    _terminal->setCursorType(QTerminalInterface::BlockCursor, cursorBlinking);
-  else if (cursorType == "underline")
-    _terminal->setCursorType(QTerminalInterface::UnderlineCursor,
-                             cursorBlinking);
+  // QSettings pointer is checked before emitting.
 
   // the widget's icons (when floating)
   QString icon_set = settings->value ("DockWidgets/widget_icon_set","NONE").
@@ -365,9 +348,9 @@
   _terminal_dock_widget->activateWindow ();
   _terminal_dock_widget->raise ();
 
-  _terminal->setFocus ();
-  _terminal->activateWindow ();
-  _terminal->raise ();
+  _terminal_dock_widget->widget ()->setFocus ();
+  _terminal_dock_widget->widget ()->activateWindow ();
+  _terminal_dock_widget->widget ()->raise ();
 }
 
 void
@@ -592,8 +575,11 @@
 main_window::read_settings ()
 {
   QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
+  if (!settings)
+    {
+      qDebug("Error: QSettings pointer from resource manager is NULL.");
+      return;
+    }
 
   restoreState (settings->value ("MainWindow/windowState").toByteArray ());
   settings->beginGroup ("DockWidgets");
@@ -621,15 +607,18 @@
     {
       _current_directory_combo_box->addItem (curr_dirs.at (i));
     }
-  emit settings_changed ();
+  emit settings_changed (settings);
 }
 
 void
 main_window::write_settings ()
 {
   QSettings *settings = resource_manager::get_settings ();
-
-  // FIXME -- what should happen if settings is 0?
+  if (!settings)
+    {
+      qDebug("Error: QSettings pointer from resource manager is NULL.");
+      return;
+    }
 
   settings->setValue ("MainWindow/geometry", saveGeometry ());
   settings->beginGroup ("DockWidgets");
@@ -719,10 +708,10 @@
   current_directory_up_tool_button->setIcon (QIcon(":/actions/icons/up.png"));
 
   // Octave Terminal subwindow.
-  _terminal = new QTerminal (this);
-  _terminal->setObjectName ("OctaveTerminal");
-  _terminal->setFocusPolicy (Qt::StrongFocus);
-  _terminal_dock_widget = new terminal_dock_widget (_terminal, this);
+  QTerminal *terminal = new QTerminal (this);
+  terminal->setObjectName ("OctaveTerminal");
+  terminal->setFocusPolicy (Qt::StrongFocus);
+  _terminal_dock_widget = new terminal_dock_widget (terminal, this);
 
   // Create and set the central widget.  QMainWindow takes ownership of
   // the widget (pointer) so there is no need to delete the object upon
@@ -1101,21 +1090,25 @@
   connect (reset_windows_action,        SIGNAL (triggered ()),
            this,                        SLOT   (reset_windows ()));
 #ifdef HAVE_QSCINTILLA
-  connect (this,                        SIGNAL (settings_changed ()),
-           _file_editor,                SLOT   (notice_settings ()));
+  connect (this,                        SIGNAL (settings_changed (const QSettings *)),
+           _file_editor,                SLOT   (notice_settings (const QSettings *)));
 #endif
-  connect (this,                        SIGNAL (settings_changed ()),
-           _files_dock_widget,          SLOT   (notice_settings ()));
-  connect (this,                        SIGNAL (settings_changed ()),
-           this,                        SLOT   (notice_settings ()));
+  connect (this,                        SIGNAL (settings_changed (const QSettings *)),
+           terminal,                    SLOT   (notice_settings (const QSettings *)));
+  connect (this,                        SIGNAL (settings_changed (const QSettings *)),
+           _files_dock_widget,          SLOT   (notice_settings (const QSettings *)));
+  connect (this,                        SIGNAL (settings_changed (const QSettings *)),
+           this,                        SLOT   (notice_settings (const QSettings *)));
   connect (_files_dock_widget,          SIGNAL (open_file (QString)),
            this,                        SLOT   (open_file (QString)));
   connect (_files_dock_widget,          SIGNAL (displayed_directory_changed(QString)),
            this,                        SLOT   (set_current_working_directory(QString)));
   connect (_history_dock_widget,        SIGNAL (information (QString)),
            this,                        SLOT   (report_status_message (QString)));
-  connect (_history_dock_widget,        SIGNAL (command_double_clicked (QString)),
-           this,                        SLOT   (handle_command_double_clicked (QString)));
+  connect (_history_dock_widget,        SIGNAL (command_double_clicked (const QString&)),
+           this,                        SLOT   (handle_command_double_clicked (const QString&)));
+  connect (_history_dock_widget,        SIGNAL (command_double_clicked (const QString&)),
+           terminal,                    SLOT   (relay_command (const QString&)));
   connect (save_workspace_action,       SIGNAL (triggered ()),
            this,                        SLOT   (handle_save_workspace_request ()));
   connect (load_workspace_action,       SIGNAL (triggered ()),
@@ -1127,9 +1120,9 @@
   connect (current_directory_up_tool_button, SIGNAL (clicked ()),
            this,                        SLOT   (current_working_directory_up()));
   connect (copy_action,                 SIGNAL (triggered()),
-           _terminal,                   SLOT   (copyClipboard ()));
+           terminal,                    SLOT   (copyClipboard ()));
   connect (paste_action,                SIGNAL (triggered()),
-           _terminal,                   SLOT   (pasteClipboard ()));
+           terminal,                    SLOT   (pasteClipboard ()));
   connect (_current_directory_combo_box, SIGNAL (activated (QString)),
            this,                        SLOT (set_current_working_directory (QString)));
   connect (_current_directory_line_edit, SIGNAL (returnPressed ()),
diff -r b1ea3813e37d -r d5d67625f961 libgui/src/main-window.h
--- a/libgui/src/main-window.h	Mon Apr 01 22:19:35 2013 -0400
+++ b/libgui/src/main-window.h	Tue Apr 02 15:38:11 2013 -0500
@@ -62,19 +62,8 @@
   main_window (QWidget * parent = 0);
   ~main_window ();
 
-  QTerminal *get_terminal_view () { return _terminal; }
-  history_dock_widget *get_history_dock_widget ()
-  {
-    return _history_dock_widget;
-  }
-  files_dock_widget *get_files_dock_widget ()
-  {
-    return _files_dock_widget;
-  }
-  bool is_closing () { return _closing; }
-
 signals:
-  void settings_changed ();
+  void settings_changed (const QSettings *);
 
 public slots:
   void report_status_message (const QString& statusMessage);
@@ -92,7 +81,7 @@
   void open_agora_page ();
   void process_settings_dialog_request ();
   void show_about_octave ();
-  void notice_settings ();
+  void notice_settings (const QSettings *settings);
   void prepare_for_quit ();
   void reset_windows ();
   void current_working_directory_has_changed (const QString& directory);
@@ -161,7 +150,6 @@
 
   void exit_callback (void);
 
-  QTerminal *               _terminal;
 #ifdef HAVE_QSCINTILLA
   file_editor_interface *   _file_editor;
 #endif
