view libgui/src/interpreter-qobject.cc @ 27218:a044202208af

more refactoring of GUI classes that manage the interpreter * interpreter-qobject.h, interpreter-qobject.cc (interpreter_qobject::m_app_context): Delete. (interpreter_qobject::m_octave_qobject, interpreter_qobject::m_qt_link): New data members. (interpreter_qobject::interpreter_qobject): Accept reference to base_qobject as argument instead of qt_application object. Make octave_qt_link connections here. (interpreter_qobject::confirm_shutdown, interpreter_qobject::qt_link): New functions. * main-window.h, main-window.cc (main_window::m_octave_qapp, main_window::m_octave_qt_link): Delete data members. (main_window::m_octave_qobj): New data membeer. (main_window::main_window): Don't pass pointer to octave_qt_link as separate argument. In other member functions, get QApplication and octave_qt_link objects from m_octave_qobj as needed. * octave-qobject.h, octave-qobject.cc (base_qobject::m_octave_qt_link): Delete. (base_qobject::base_qobject): Don't make connections to octave_qt_lnk signals here. (base_qobject::confirm_shutdown_octave_internal): Delete. (base_qobject::confirm_shutdown_octave): Call interpreter_qobject::confirm_shutdown instead of confirm_shutdown_octave_internal. (gui_qobject::confirm_shutdown_octave): Likewise.
author John W. Eaton <jwe@octave.org>
date Fri, 28 Jun 2019 14:42:44 -0400
parents b8c0d5ad024f
children 5ac60319575b
line wrap: on
line source

/*

Copyright (C) 2013-2019 John W. Eaton
Copyright (C) 2011-2019 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
<https://www.gnu.org/licenses/>.

*/

#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include "interpreter-qobject.h"
#include "octave-qobject.h"
#include "octave-qt-link.h"
#include "qt-application.h"

#include "input.h"
#include "interpreter.h"

namespace octave
{
  interpreter_qobject::interpreter_qobject (base_qobject *oct_qobj)
    : QObject (), m_octave_qobject (oct_qobj),
      m_qt_link (new octave_qt_link ())
  {
    octave_link::connect_link (m_qt_link);

    connect (m_qt_link, SIGNAL (confirm_shutdown_signal (void)),
             m_octave_qobject, SLOT (confirm_shutdown_octave (void)));

    connect (m_qt_link,
             SIGNAL (copy_image_to_clipboard_signal (const QString&, bool)),
             m_octave_qobject,
             SLOT (copy_image_to_clipboard (const QString&, bool)));
  }

  void interpreter_qobject::execute (void)
  {
    // The Octave application context owns the interpreter.

    qt_application& app_context = m_octave_qobject->app_context ();

    interpreter& interp = app_context.create_interpreter ();

    int exit_status = 0;

    try
      {
        // Final initialization.

        interp.initialize ();

        if (app_context.start_gui_p ())
          {
            input_system& input_sys = interp.get_input_system ();

            input_sys.PS1 (">> ");
            input_sys.PS2 ("");
          }

        if (interp.initialized ())
          {
            // The interpreter should be completely ready at this point so let
            // the GUI know.

            emit octave_ready_signal ();

            // Start executing commands in the command window.

            exit_status = interp.execute ();
          }
      }
    catch (const exit_exception& ex)
      {
        exit_status = ex.exit_status ();
      }

    // Whether or not initialization succeeds we need to clean up the
    // interpreter once we are done with it.

    app_context.delete_interpreter ();

    emit octave_finished_signal (exit_status);
  }

  void interpreter_qobject::confirm_shutdown (bool closenow)
  {
    // Wait for link thread to go to sleep state.
    m_qt_link->lock ();

    m_qt_link->shutdown_confirmation (closenow);

    m_qt_link->unlock ();

    // Awake the worker thread so that it continues shutting down (or not).
    m_qt_link->wake_all ();
  }
}