changeset 16479:7a71ea0b7ae9

eliminate event listener class * main-window.h, main-window.cc (main_window::exit): New function. (main_window::_ocxtave_qt_event_listener): Delete member variable and all uses. main_window::construct_octave_qt_link): connect _octave_qt_link::octave_thread_finished to main_window::exit. * octave-qt-event-listener.h, octave-qt-event-listener.cc: Delete. * libgui/src/module.mk (octave_gui_MOC, noinst_HEADERS, src_libgui_src_la_SOURCES): Update lists. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::octave_thread_finished): New signal. (octave_qt_link::~octave_qt_link): Delete main_thread. (octave_qt_link::octave_qt_link): Connect main_thread::finished and main_thread::terminated to octave_qt_link::octave_thread_finished signal. * octave-event-listener.h: Delete. * libinterp/interp-core/module.mk (INTERPFCN_INC): Remove it from the list. * octave-link.h, octave-link.cc (octave_exit_hook): Delete. (octave_link::discard_events, octave_link::do_discard_events, octave_link::exit, octave_link::do_exit): New functions. (octave_link::event_listener): Delete member variable and all uses. (octave_link::about_to_exit, octave_link::register_event_listener, octave_link::do_about_to_exit, octave_link::do_register_event_listener): Delete. (octave_link::accepting_events): New member variable. (octave_link::octave_link): Set octave_exit to octave_link::exit. Initialize accepting_events. (octave_link::do_post_event): Only add to gui_event_queue if accepting_events is true.
author John W. Eaton <jwe@octave.org>
date Tue, 09 Apr 2013 13:47:43 -0400
parents 079ec7ce60e0
children 3731a1992083
files libgui/src/main-window.cc libgui/src/main-window.h libgui/src/module.mk libgui/src/octave-qt-event-listener.cc libgui/src/octave-qt-event-listener.h libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h libinterp/interp-core/module.mk libinterp/interp-core/octave-event-listener.h libinterp/interpfcn/octave-link.cc libinterp/interpfcn/octave-link.h
diffstat 11 files changed, 53 insertions(+), 196 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Tue Apr 09 03:40:28 2013 -0400
+++ b/libgui/src/main-window.cc	Tue Apr 09 13:47:43 2013 -0400
@@ -91,9 +91,6 @@
   // deleted before this main_window is.  Otherwise, some will be
   // attached to a non-existent parent.
 
-  if (_octave_qt_event_listener)
-    delete _octave_qt_event_listener;
-
   octave_link::connect_link (0);
   delete _octave_qt_link;
 }
@@ -266,6 +263,12 @@
 }
 
 void
+main_window::exit (void)
+{
+  qApp->quit ();
+}
+
+void
 main_window::reset_windows ()
 {
   // TODO: Implement.
@@ -577,10 +580,6 @@
 
   setStatusBar (status_bar);
 
-  _octave_qt_event_listener = new octave_qt_event_listener ();
-
-  // FIXME -- is it possible to eliminate the event_listenter?
-
   construct_octave_qt_link ();
 
   QDir curr_dir;
@@ -592,6 +591,9 @@
 {
   _octave_qt_link = new octave_qt_link ();
 
+  connect (_octave_qt_link, SIGNAL (octave_thread_finished ()),
+           this, SLOT (exit ()));
+
   connect (_octave_qt_link,
            SIGNAL (set_workspace_signal
                    (const QString&, const QStringList&, const QStringList&,
@@ -648,8 +650,6 @@
   _octave_qt_link->execute_interpreter ();
 
   octave_link::connect_link (_octave_qt_link);
-
-  octave_link::register_event_listener (_octave_qt_event_listener);
 }
 
 void
--- a/libgui/src/main-window.h	Tue Apr 09 03:40:28 2013 -0400
+++ b/libgui/src/main-window.h	Tue Apr 09 13:47:43 2013 -0400
@@ -51,7 +51,6 @@
 #include "files-dock-widget.h"
 #include "terminal-dock-widget.h"
 #include "documentation-dock-widget.h"
-#include "octave-qt-event-listener.h"
 #include "octave-qt-link.h"
 
 /**
@@ -93,6 +92,7 @@
   void show_about_octave (void);
   void notice_settings (const QSettings *settings);
   void prepare_to_exit (void);
+  void exit (void);
   void reset_windows (void);
 
   void change_directory (const QString& dir);
@@ -206,8 +206,6 @@
   static const int current_directory_max_count = 16;
   QLineEdit *_current_directory_line_edit;
 
-  octave_qt_event_listener *_octave_qt_event_listener;
-
   octave_qt_link *_octave_qt_link;
 
   // Flag for closing whole application.
--- a/libgui/src/module.mk	Tue Apr 09 03:40:28 2013 -0400
+++ b/libgui/src/module.mk	Tue Apr 09 13:47:43 2013 -0400
@@ -72,7 +72,6 @@
   src/moc-files-dock-widget.cc \
   src/moc-history-dock-widget.cc \
   src/moc-main-window.cc \
-  src/moc-octave-qt-event-listener.cc \
   src/moc-octave-qt-link.cc \
   src/moc-settings-dialog.cc \
   src/moc-terminal-dock-widget.cc \
@@ -107,7 +106,6 @@
   src/main-window.h \
   src/octave-gui.h \
   src/octave-main-thread.h \
-  src/octave-qt-event-listener.h \
   src/octave-qt-link.h \
   src/qtinfo/parser.h \
   src/qtinfo/webinfo.h \
@@ -130,7 +128,6 @@
   src/main-window.cc \
   src/octave-gui.cc \
   src/octave-main-thread.cc \
-  src/octave-qt-event-listener.cc \
   src/octave-qt-link.cc \
   src/qtinfo/parser.cc \
   src/qtinfo/webinfo.cc \
--- a/libgui/src/octave-qt-event-listener.cc	Tue Apr 09 03:40:28 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*
-
-Copyright (C) 2011-2012 Jacob Dawid
-
-This file is part of Octave.
-
-Octave 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.
-
-Octave 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 Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <iostream>
-
-#include "octave-qt-event-listener.h"
-#include <QApplication>
-
-octave_qt_event_listener::octave_qt_event_listener (QObject *p)
-  : QObject (p), octave_event_listener ()
-{
-}
-
-void
-octave_qt_event_listener::current_directory_has_changed (const std::string& directory)
-{
-  emit current_directory_has_changed_signal
-    (QString::fromUtf8 (directory.data (), directory.size ()));
-}
-
-void
-octave_qt_event_listener::update_workspace (void)
-{
-  emit update_workspace_signal ();
-}
-
-void
-octave_qt_event_listener::about_to_exit ()
-{
-  qApp->quit ();
-}
--- a/libgui/src/octave-qt-event-listener.h	Tue Apr 09 03:40:28 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
-
-Copyright (C) 2011-2012 Jacob Dawid
-
-This file is part of Octave.
-
-Octave 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.
-
-Octave 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 Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef OCTAVEQTEVENTLISTENER_H
-#define OCTAVEQTEVENTLISTENER_H
-
-#include <QObject>
-#include <QString>
-#include "octave-event-listener.h"
-
-class octave_qt_event_listener
-  : public QObject, public octave_event_listener
-{
-  Q_OBJECT
-  public:
-  octave_qt_event_listener (QObject *parent = 0);
-
-  void current_directory_has_changed (const std::string& directory);
-  void update_workspace (void);
-  void about_to_exit ();
-
-signals:
-  void current_directory_has_changed_signal (const QString& directory);
-  void update_workspace_signal (void);
-};
-
-#endif // OCTAVEQTEVENTLISTENER_H
--- a/libgui/src/octave-qt-link.cc	Tue Apr 09 03:40:28 2013 -0400
+++ b/libgui/src/octave-qt-link.cc	Tue Apr 09 13:47:43 2013 -0400
@@ -37,6 +37,13 @@
 octave_qt_link::octave_qt_link (void)
   : octave_link (), main_thread (new octave_main_thread)
 {
+  connect (main_thread, SIGNAL (finished ()),
+           this, SIGNAL (octave_thread_finished ()));
+}
+
+octave_qt_link::~octave_qt_link (void)
+{
+  delete main_thread;
 }
 
 void
--- a/libgui/src/octave-qt-link.h	Tue Apr 09 03:40:28 2013 -0400
+++ b/libgui/src/octave-qt-link.h	Tue Apr 09 13:47:43 2013 -0400
@@ -51,7 +51,7 @@
 
   octave_qt_link (void);
 
-  ~octave_qt_link (void) { }
+  ~octave_qt_link (void);
 
   void execute_interpreter (void);
 
@@ -115,6 +115,8 @@
 
   void insert_debugger_pointer_signal (const QString&, int);
   void delete_debugger_pointer_signal (const QString&, int);
+
+  void octave_thread_finished (void);
 };
 
 #endif
--- a/libinterp/interp-core/module.mk	Tue Apr 09 03:40:28 2013 -0400
+++ b/libinterp/interp-core/module.mk	Tue Apr 09 13:47:43 2013 -0400
@@ -35,7 +35,6 @@
   interp-core/mex.h \
   interp-core/mexproto.h \
   interp-core/mxarray.in.h \
-  interp-core/octave-event-listener.h \
   interp-core/oct-errno.h \
   interp-core/oct-fstrm.h \
   interp-core/oct-hdf5.h \
--- a/libinterp/interp-core/octave-event-listener.h	Tue Apr 09 03:40:28 2013 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
-
-Copyright (C) 2011-2012 Jacob Dawid
-
-This file is part of Octave.
-
-Octave 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.
-
-Octave 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 Octave; see the file COPYING.  If not, see
-<http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef OCTAVEEVENTLISTENER_H
-#define OCTAVEEVENTLISTENER_H
-
-#include <string>
-
-class octave_event_listener
-{
-  public:
-    octave_event_listener () { }
-    virtual ~octave_event_listener () { }
-
-    virtual void
-    update_workspace (void) = 0;
-
-    virtual void about_to_exit () = 0;
-};
-
-#endif // OCTAVEEVENTLISTENER_H
--- a/libinterp/interpfcn/octave-link.cc	Tue Apr 09 03:40:28 2013 -0400
+++ b/libinterp/interpfcn/octave-link.cc	Tue Apr 09 13:47:43 2013 -0400
@@ -46,21 +46,15 @@
   return 0;
 }
 
-static void
-octave_exit_hook (int)
-{
-  octave_link::about_to_exit ();
-}
-
 octave_link *octave_link::instance = 0;
 
 octave_link::octave_link (void)
-  : event_listener (0), event_queue_mutex (new octave_mutex ()),
-    gui_event_queue (), debugging (false)
+  : event_queue_mutex (new octave_mutex ()), gui_event_queue (),
+    debugging (false), accepting_events (true)
 {
   command_editor::add_event_hook (octave_readline_hook);
 
-  octave_exit = octave_exit_hook;
+  octave_exit = octave_link::exit;
 }
 
 // OBJ should be an object of a class that is derived from the base
@@ -77,12 +71,6 @@
 }
 
 void
-octave_link::do_register_event_listener (octave_event_listener *el)
-{
-  event_listener = el;
-}
-
-void
 octave_link::do_generate_events (void)
 {
 }
@@ -98,16 +86,21 @@
 }
 
 void
-octave_link::do_about_to_exit (void)
+octave_link::do_discard_events (void)
 {
   event_queue_mutex->lock ();
 
   gui_event_queue.discard ();
 
   event_queue_mutex->unlock ();
+}
 
-  if (event_listener)
-    event_listener->about_to_exit ();
+void
+octave_link::do_exit (int)
+{
+  accepting_events = false;
+
+  do_process_events ();
 }
 
 bool
--- a/libinterp/interpfcn/octave-link.h	Tue Apr 09 03:40:28 2013 -0400
+++ b/libinterp/interpfcn/octave-link.h	Tue Apr 09 13:47:43 2013 -0400
@@ -28,7 +28,6 @@
 #include <string>
 
 #include "event-queue.h"
-#include "octave-event-listener.h"
 
 class octave_mutex;
 class string_vector;
@@ -52,12 +51,6 @@
 
   virtual ~octave_link (void) { }
 
-  static void register_event_listener (octave_event_listener *el)
-  {
-    if (instance_ok ())
-      instance->do_register_event_listener (el);
-  }
-
   static void generate_events (void)
   {
     if (instance_ok ())
@@ -70,6 +63,18 @@
       instance->do_process_events ();
   }
 
+  static void discard_events (void)
+  {
+    if (instance_ok ())
+      instance->do_discard_events ();
+  }
+
+  static void exit (int status)
+  {
+    if (instance_ok ())
+      instance->do_exit (status);
+  }
+
   template <class T>
   static void post_event (T *obj, void (T::*method) (void))
   {
@@ -91,12 +96,6 @@
       instance->do_post_event (obj, method, arg);
   }
 
-  static void about_to_exit (void)
-  {
-    if (instance_ok ())
-      instance->do_about_to_exit ();
-  }
-
   static void entered_readline_hook (void)
   {
     if (instance_ok ())
@@ -214,8 +213,6 @@
 
 protected:
 
-  octave_event_listener *event_listener;
-
   // Semaphore to lock access to the event queue.
   octave_mutex *event_queue_mutex;
 
@@ -224,31 +221,35 @@
 
   bool debugging;
 
-  void do_register_event_listener (octave_event_listener *oel);
+  bool accepting_events;
 
   void do_generate_events (void);
   void do_process_events (void);
+  void do_discard_events (void);
+
+  void do_exit (int status);
 
   template <class T>
   void do_post_event (T *obj, void (T::*method) (void))
   {
-    gui_event_queue.add_method (obj, method);
+    if (accepting_events)
+      gui_event_queue.add_method (obj, method);
   }
 
   template <class T, class A>
   void do_post_event (T *obj, void (T::*method) (A), A arg)
   {
-    gui_event_queue.add_method (obj, method, arg);
+    if (accepting_events)
+      gui_event_queue.add_method (obj, method, arg);
   }
 
   template <class T, class A>
   void do_post_event (T *obj, void (T::*method) (const A&), const A& arg)
   {
-    gui_event_queue.add_method (obj, method, arg);
+    if (accepting_events)
+      gui_event_queue.add_method (obj, method, arg);
   }
 
-  void do_about_to_exit (void);
-
   void do_entered_readline_hook (void) { }
   void do_finished_readline_hook (void) { }