# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1365846384 18000
# Node ID 264710b5daee000d6a27d1253dfff8c72b2de5e3
# Parent  5293cee91891c330738c884cbecad7744e88ce5c
THIS IS SIMPLY A PROTOTYPE TO TRANSFER octave_value_list OVER THREADS

diff -r 5293cee91891 -r 264710b5daee libgui/guifcn/dialog.cc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/guifcn/dialog.cc	Sat Apr 13 04:46:24 2013 -0500
@@ -0,0 +1,387 @@
+/*
+
+Copyright (C) 1993-2013 John W. Eaton
+
+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 "defun.h"
+#include "builtin-defun-decls.h"
+
+#include "dialog.h"
+
+#include "Cell.h"
+#include "error.h"
+#include "ov.h"
+
+#include <QMutex>
+#include <QWaitCondition>
+#include <QString>
+#include <QStringList>
+#include <QStringListModel>
+#include <QListView>
+// Could replace most of these with #include <QtGui>
+#include <QMessageBox>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QGridLayout>
+#include <QLabel>
+
+// GUI objects cannot be accessed in the non-GUI thread.  However, signals
+// can be sent to slots across threads with proper syncronization.  Hence,
+// the use of QWaitCondition.
+QMutex mutex;
+QWaitCondition waitcondition;
+
+QUIWidgetCreator uiwidget_creator;
+
+bool QUIWidgetCreator::qt_gui_valid ()
+{
+#define MAIN_WINDOW_POINTER_INACCESSIBLE
+#ifdef MAIN_WINDOW_POINTER_INACCESSIBLE
+  octave_value_list guitest = Fisguirunning ();
+  if (!guitest (0).bool_value ())
+    {
+      error ("Qt main GUI window must be active to run this routine.");
+      return false;
+    }
+#else
+  if (!uiwidget_creator)
+    {
+      uiwidget_creator = new QUIWidgetCreator ();
+      if (!uiwidget_creator)
+        {
+          error ("Cannot create object to communicate with Qt GUI.");
+          return false;
+        }
+      // Establish connections here, but pointer to main window is
+      // currently not accessible.  So that code is in a routine called
+      // main_window::connect_uiwidget_links () right now.
+      return true;
+    }
+#endif
+  else
+    return true; 
+}
+
+
+QUIWidgetCreator::QUIWidgetCreator ()
+  : QObject ()
+{
+  dialog_result = -1;
+  dialog_button = QString ();
+  string_list = new QStringList ();
+  list_index = new QIntList;
+first_command = new QString ("ones(3);");
+second_command = new QString ("ones(3);");
+first_qobject = 0;
+second_qobject = 0;
+first_nout = 0;
+second_nout = 0;
+}
+
+
+QUIWidgetCreator::~QUIWidgetCreator ()
+{
+delete second_command;
+delete first_command;
+  // Clean up all dynamically created objects
+  delete string_list;
+  delete list_index;
+}
+
+
+void
+QUIWidgetCreator::dialog_finished (int)
+{
+  // Store the value so that builtin functions can retrieve.
+  // The value should always be 1 for the Octave functions.
+
+  // Value returned by message box is not quite always 1.  If the
+  // window upper-right close button is pressed, 'result' is 0.
+  dialog_result = 1;
+
+  // Wake up Octave process so that it continues.
+  waitcondition.wakeAll();
+}
+
+
+void
+QUIWidgetCreator::dialog_button_clicked (QAbstractButton *button)
+{
+  // Store information about what button was pressed so that builtin
+  // functions can retrieve.
+  dialog_button = button->text ();
+}
+
+
+void
+QUIWidgetCreator::list_select_finished (const QIntList& selected, const int button_pressed)
+{
+  // Store the value so that builtin functions can retrieve.
+  *list_index = selected;
+  dialog_result = button_pressed;
+
+  // Wake up Octave process so that it continues.
+  waitcondition.wakeAll();
+}
+
+
+void
+QUIWidgetCreator::input_finished (const QStringList& input, const int button_pressed)
+{
+  // Store the value so that builtin functions can retrieve.
+  *string_list = input;
+  dialog_result = button_pressed;
+
+  // Wake up Octave process so that it continues.
+  waitcondition.wakeAll();
+}
+
+
+/***** PROTOTYPE CONCEPT *****/
+void
+QUIWidgetCreator::handle_queue_an_octave_command (const QString& command, const int nout)
+{
+  *first_command = *second_command;
+  *second_command = command;
+  first_qobject = second_qobject;
+  second_qobject = sender ();
+  first_nout = second_nout;
+  second_nout = nout;
+}
+
+
+int
+proc_first_two_args_dlg (const octave_value_list& args, QString& message,
+                         QString& title)
+{
+  octave_value ovmessage = args (0);
+
+  if (ovmessage.is_string () || ovmessage.is_cell ())
+    {
+      if (ovmessage.is_string ())
+        message = ovmessage.string_value ().c_str ();
+      else
+        {
+          Cell c_val = ovmessage.cell_value ();
+          for (octave_idx_type i = 0; i < c_val.length (); i++)
+            {
+              if (i > 0)
+                message.append ("\n");
+
+              if (c_val (i).is_string ())
+                message.append (c_val (i).string_value ().c_str ());
+              else
+                {
+                  error ("qtlistdlg: cell %d is not a string", i+1);
+                  return 1;
+                }
+            }
+        }
+
+      if (args.length () > 1)
+        {
+          octave_value ovtitle = args (1);
+
+          if (ovtitle.is_string ())
+            title = ovtitle.string_value ().c_str ();
+          else
+            {
+              error ("second argument must be a string");
+              return 1;
+            }
+        }
+    }
+  else
+    {
+      error ("qtquestdlg: first argument must be a string or string cell");
+      return 1;
+    }
+
+  return 0;
+}
+
+
+octave_value_list
+qtdlg (const octave_value_list& args, const char *default_title,
+       const char *default_icon)
+{
+  if (!QUIWidgetCreator::qt_gui_valid ())
+    {
+      octave_value_list retval;
+      return retval;
+    }
+
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 0 && nargin <= 3)
+    {
+      QString message, title;
+      title = default_title;
+      if (proc_first_two_args_dlg (args, message, title))
+        return retval;
+
+      QString icon;
+      if (nargin > 2)
+        {
+          octave_value ovicon = args (2);
+
+          if (ovicon.is_string ())
+            icon = ovicon.string_value ().c_str ();
+          else
+            {
+              error ("third argument must be a string");
+              return retval;
+            }
+        }
+      else
+        icon = default_icon;
+
+      if (icon != "error" && icon != "help" &&
+          icon != "none" && icon != "warn")
+        {
+          error ("invalid icon string");
+          return retval;
+        }
+
+      // Signal GUI thread to put up simple message box using OK
+      // as the only button.
+      uiwidget_creator.signal_dialog (message, title, icon, QStringList (),
+                                      QString (), QStringList ());
+
+      // Wait while the user is responding to message box.
+      waitcondition.wait (&mutex);
+
+      // The GUI has sent a signal and the process has been awakened.
+      retval (0) = uiwidget_creator.get_dialog_result ();
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
+
+octave_value_list
+qtdlg2 (const octave_value_list& args, const char *default_title,
+        const char *icon)
+{
+  octave_value_list retval;
+
+  int nargin = args.length ();
+
+  if (nargin > 0 && nargin <= 2)
+    retval = qtdlg (args, default_title, icon);
+  else
+    print_usage ();
+
+  return retval;
+}
+
+
+DEFUN (qterrordlg, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn  {Function File} {@var{h} =} qterrordlg (@var{msg})\n\
+@deftypefnx {Function File} {@var{h} =} qterrordlg (@var{msg}, @var{title})\n\
+Display @var{msg} using an error dialog box.\n\
+\n\
+The message may have multiple lines separated by newline characters\n\
+(\"\\n\"), or it may be a cellstr array with one element for each\n\
+line.  The optional input @var{title} (character string) can be used to\n\
+set the dialog caption.  The default title is \"Error Dialog\".\n\
+\n\
+The return value is always 1.\n\
+@seealso{qthelpdlg, qtinputdlg, qtlistdlg, qtmsgbox, qtquestdlg, qtwarndlg}\n\
+@end deftypefn")
+{
+  octave_value_list retval = qtdlg2 (args, "Error Dialog", "error");
+
+/***** PROTOTYPE CONCEPT *****/
+  uiwidget_creator.process_queued_commands ();
+
+  return retval;
+
+}
+
+MessageDialog::MessageDialog (const QString& message, const QString& title,
+                              const QString& qsicon,
+                              const QStringList& qsbutton,
+                              const QString& defbutton,
+                              const QStringList& role)
+  : QMessageBox (QMessageBox::NoIcon, title, message, 0, 0)
+{
+  // Create a NonModal message.
+  setWindowModality (Qt::NonModal);
+
+  // Interpret the icon string, because enumeration QMessageBox::Icon can't
+  // easily be made to pass through a signal.
+  QMessageBox::Icon eicon = QMessageBox::NoIcon;
+  if (qsicon == "error")
+    eicon = QMessageBox::Critical;
+  else if (qsicon == "warn")
+    eicon = QMessageBox::Warning;
+  else if (qsicon == "help")
+    eicon = QMessageBox::Information;
+  else if (qsicon == "quest")
+    eicon = QMessageBox::Question;
+  setIcon (eicon);
+
+  int N = qsbutton.size () < role.size () ? qsbutton.size () : role.size ();
+  if (N == 0)
+    addButton (QMessageBox::Ok);
+  else
+    {
+      for (int i = 0; i < N; i++)
+        {
+          // Interpret the button role string, because enumeration
+          // QMessageBox::ButtonRole can't be made to pass through a signal.
+          QString srole = role.at (i);
+          QMessageBox::ButtonRole erole = QMessageBox::InvalidRole;
+          if (srole == "YesRole")
+            erole = QMessageBox::YesRole;
+          else if (srole == "NoRole")
+            erole = QMessageBox::NoRole;
+          else if (srole == "RejectRole")
+            erole = QMessageBox::RejectRole;
+          else if (srole == "AcceptRole")
+            erole = QMessageBox::AcceptRole;
+
+          QPushButton *pbutton = addButton (qsbutton.at (i), erole);
+          if (qsbutton.at (i) == defbutton)
+            setDefaultButton (pbutton);
+          // Make the last button the button pressed when <esc> key activated.
+          if (i == N-1)
+            setEscapeButton (pbutton);
+        }
+    }
+
+  connect (this,              SIGNAL (buttonClicked (QAbstractButton *)),
+           &uiwidget_creator, SLOT (dialog_button_clicked (QAbstractButton *)));
+  connect (this,              SIGNAL (finished (int)),
+           &uiwidget_creator, SLOT (dialog_finished (int)));
+}
+
diff -r 5293cee91891 -r 264710b5daee libgui/guifcn/dialog.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/guifcn/dialog.h	Sat Apr 13 04:46:24 2013 -0500
@@ -0,0 +1,174 @@
+/*
+
+Copyright (C) 1993-2013 John W. Eaton
+
+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/>.
+
+*/
+
+#if !defined (octave_guifcn_dialog_h)
+#define octave_guifcn_dialog_h 1
+
+// FIXME -- we should not be including config.h in header files.
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "parse.h"
+
+#include <QAbstractButton>
+#include <QList>
+#include <QItemSelectionModel>
+#include <QDialog>
+#include <QMessageBox>
+#include <QLineEdit>
+
+// Defined for purposes of sending QList<int> as part of signal.
+typedef QList<int> QIntList;
+// Defined for purposes of sending QList<float> as part of signal.
+typedef QList<float> QFloatList;
+
+
+class QUIWidgetCreator : public QObject
+{
+  Q_OBJECT
+
+  int dialog_result;
+  QString dialog_button;
+
+  // The list could conceivably be big.  Not sure how things are
+  // stored internally, so keep off of the stack.
+  QStringList *string_list;
+  QIntList *list_index;
+
+  /***** PROTOTYPE CONCEPT *****/
+  QString *first_command;
+  QString *second_command;
+  QObject *first_qobject;
+  QObject *second_qobject;
+  int first_nout;
+  int second_nout;
+
+public:
+  QUIWidgetCreator ();
+  ~QUIWidgetCreator ();
+
+public:
+  static bool qt_gui_valid ();
+
+  void signal_dialog (const QString& message, const QString& title,
+                      const QString& icon, const QStringList& button,
+                      const QString& defbutton, const QStringList& role) {
+
+    // Use the last button in the list as the reject result, i.e., when no
+    // button is pressed such as in the case of <esc> and close button.
+    if (!button.isEmpty ())
+      dialog_button = button.last ();
+
+    emit create_dialog (message, title, icon, button, defbutton, role);
+  };
+  int get_dialog_result (void) {
+    return dialog_result;
+  }
+  const QString *get_dialog_button (void) {
+    return &dialog_button;
+  }
+  bool signal_listview (const QString& mode, const QIntList& size,
+                        const QStringList& text) {
+    if (string_list->isEmpty ())
+      return false;
+    // Default value if none assigned.
+    if (list_index->isEmpty ())
+      *list_index << 1;
+    emit create_listview (*string_list, *list_index, mode, size, text);
+    return true;
+  };
+  void clear_list (void) {
+    string_list->clear ();
+    list_index->clear ();
+  };
+  void add_string_list (const QString& string) {
+    *string_list << string;
+  };
+  // Index value begins at 1.
+  void add_list_index (const int index) {
+    *list_index << index;
+  };
+  const QIntList *get_list_index (void) {
+    return list_index;
+  }
+  bool signal_inputlayout (const QString& title, const QFloatList& rowscols) {
+    if (string_list->isEmpty ())
+      return false;
+    emit create_inputlayout (*string_list, title, rowscols);
+    return true;
+  };
+  const QStringList *get_string_list (void) {
+    return string_list;
+  }
+
+/***** PROTOTYPE CONCEPT *****/
+  void process_queued_commands (void) {
+    octave_value_list retval;
+    int parse_status;
+    retval = eval_string (first_command->toStdString (), false, parse_status, first_nout);
+    if (!parse_status && !error_state)
+      {
+        emit octave_command_result (first_qobject, retval);
+      }
+    retval = eval_string (second_command->toStdString (), false, parse_status, second_nout);
+    if (!parse_status && !error_state)
+      {
+        emit octave_command_result (second_qobject, retval);
+      }
+  }
+
+signals:
+  void create_dialog (const QString&, const QString&, const QString&,
+                      const QStringList&, const QString&, const QStringList&);
+  void create_listview (const QStringList&, const QIntList&, const QString&,
+                        const QIntList&, const QStringList&);
+  void create_inputlayout (const QStringList&, const QString&, const QFloatList&);
+
+  /***** PROTOTYPE CONCEPT *****/
+  void octave_command_result (const QObject *, const octave_value_list&);
+
+public slots:
+  void dialog_finished (int result);
+  void dialog_button_clicked (QAbstractButton *button);
+  void list_select_finished (const QIntList& selected, const int button_pressed);
+  void input_finished (const QStringList& input, const int button_pressed);
+
+  /***** PROTOTYPE CONCEPT *****/
+  void handle_queue_an_octave_command (const QString& command, const int nout);
+};
+
+extern QUIWidgetCreator uiwidget_creator;
+
+
+class MessageDialog : public QMessageBox
+{
+  Q_OBJECT
+
+public:
+  explicit MessageDialog (const QString& message, const QString& title,
+                          const QString& icon, const QStringList& button,
+                          const QString& defbutton,
+                          const QStringList& role);
+};
+
+#endif
diff -r 5293cee91891 -r 264710b5daee libgui/guifcn/module.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/guifcn/module.mk	Sat Apr 13 04:46:24 2013 -0500
@@ -0,0 +1,57 @@
+
+EXTRA_DIST += \
+  ../libgui/guifcn/module.mk
+
+GUIFCN_INC = \
+  ../libgui/guifcn/dialog.h
+
+GUIFCN_SRC = \
+  ../libgui/guifcn/dialog.cc
+
+octave_gui_MOC =
+octave_gui_MOC += \
+  ../libgui/guifcn/moc-dialog.cc
+
+moc-%.cc: %.h
+	$(MOC) -o$@ $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(MOC_CPPFLAGS) $(liboctgui_la_CPPFLAGS) $<
+
+noinst_LTLIBRARIES += guifcn/libguifcn.la
+
+## DJS 2013mar17.  Remove this comment in near future, since that
+## indicates no one had the energy or time to follow up.
+##
+## I built up the following list one at a time.  It got to the point
+## where I thought header files were being included that shouldn't
+## have much to do with the simple function I was attempting to
+## create.  For example, why would sparse-related code be necessary:
+##  ../../octave/liboctave/operators/Sparse-op-defs.h:29:20: fatal error: mx-ops.h: No such file or directory
+## The mx-ops.h isn't in the source tree.  It must be a generated file,
+## which means I could no longer simply go to "libgui" and run "make".
+## I needed to compile the whole project first.  It might be worth
+## untangling some of this by starting from the end of the list and
+## strip off one include directory at a time and see if it can be
+## removed from dependency by editing some header files.
+fcn_libgui_fcn_la_CPPFLAGS = \
+  -Iparse-tree -I$(top_srcdir)/libinterp/parse-tree \
+  -I$(top_srcdir)/libinterp/interpfcn \
+  -I$(top_srcdir)/libinterp/interp-core \
+  -I$(top_srcdir)/libinterp/octave-value \
+  -I$(top_srcdir)/liboctave/system \
+  -I$(top_srcdir)/liboctave/util \
+  -I$(top_srcdir)/liboctave/array \
+  -I$(top_srcdir)/liboctave/cruft/misc/ \
+  -I$(top_srcdir)/liboctave/numeric/ \
+  -I$(top_srcdir)/liboctave/operators/ \
+  -I$(top_builddir)/liboctave/operators \
+  -I$(top_builddir)/libinterp
+
+nodist_guifcn_libguifcn_la_SOURCES = $(octave_gui_MOC)
+
+guifcn_libguifcn_la_SOURCES = $(GUIFCN_SRC)
+guifcn_libguifcn_la_CPPFLAGS = \
+  @QT_CPPFLAGS@ \
+  $(liboctinterp_la_CPPFLAGS)
+guifcn_libguifcn_la_LIBADD = @QT_LIBS@
+
+CLEANFILES = \
+  $(octave_gui_MOC)
diff -r 5293cee91891 -r 264710b5daee libgui/src/files-dockwidget.cc
--- a/libgui/src/files-dockwidget.cc	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/files-dockwidget.cc	Sat Apr 13 04:46:24 2013 -0500
@@ -34,9 +34,13 @@
 #include <QProcess>
 #include <QDebug>
 #include <QHeaderView>
+#include <QInputDialog>
+#include <QTableWidget>
+
+#include "dialog.h"
 
 files_dock_widget::files_dock_widget (QWidget *p)
-  : octave_dock_widget (p)
+  : octave_dock_widget (p), command_count (0)
 {
   setObjectName ("FilesDockWidget");
   setWindowIcon (QIcon(":/actions/icons/logo.png"));
@@ -49,6 +53,12 @@
   _navigation_tool_bar->setMovable (false);
   _navigation_tool_bar->setIconSize (QSize (20, 20));
 
+_directory_icon = QIcon(":/actions/icons/redled.png");
+_directory_up_action = new QAction (_directory_icon, "", _navigation_tool_bar);
+_navigation_tool_bar->addAction (_directory_up_action);
+connect (_directory_up_action, SIGNAL (triggered ()), this,
+         SLOT (do_prototype_input ()));
+
   _directory_icon = QIcon(":/actions/icons/up.png");
   _directory_up_action = new QAction (_directory_icon, "", _navigation_tool_bar);
   _directory_up_action->setStatusTip (tr ("Move up one directory."));
@@ -115,6 +125,14 @@
   _current_directory->setCompleter (completer);
 
   setFocusProxy (_current_directory);
+
+// Register QIntList so that list of ints may be part of a signal.
+qRegisterMetaType<octave_value_list> ("octave_value_list");
+connect (this, SIGNAL (queue_an_octave_command (const QString&, const int)),
+         &uiwidget_creator, SLOT (handle_queue_an_octave_command (const QString&, const int)));
+connect (&uiwidget_creator, SIGNAL (octave_command_result (const QObject *, const octave_value_list&)),
+         this, SLOT (handle_octave_command_result (const QObject*, const octave_value_list&)));
+
 }
 
 files_dock_widget::~files_dock_widget ()
@@ -149,6 +167,67 @@
 }
 
 void
+files_dock_widget::do_prototype_input ()
+{
+  bool ok;
+  QString text = QInputDialog::getText(this, tr("Crude Proof Of Concept"),
+                                       tr("Enter matrix variable in the Octave workspace,\nlike \"x = [1:5]'*[1:5]\", and enter the name of\nthe variable here.  Then type 'qterrordlg ('foo')'\nat the command line.\nVariable Name:"), QLineEdit::Normal,
+                                       "", &ok);
+  if (ok && !text.isEmpty())
+  {
+    QString command;
+    command = "size(";
+    command += text;
+    command += ");";
+    emit queue_an_octave_command (command, 1);
+    command = text;
+    command += ";";
+    emit queue_an_octave_command (command, 1);
+  }
+}
+
+void
+files_dock_widget::handle_octave_command_result (const QObject* ID, const octave_value_list& ovlres)
+{
+  // Check if this is the info I requested.
+  if (ID != this)
+    return;
+
+  // I sent first a size command, and second the data command
+  if (!(command_count & 1))
+    {
+      octave_value octval = ovlres (0);
+      if (octval.is_numeric_type ())
+        matsize = octval.array_value ();
+    }
+  else
+    {
+      octave_value octval = ovlres (0);
+      if (octval.is_numeric_type ())
+        {
+          Matrix matval = octval.matrix_value ();
+fprintf(stderr,"HERE'S YOUR MATRIX\n\n");
+          QTableWidget *qtable = new QTableWidget (matsize(0), matsize (1));
+          for (int m = 0; m < matsize(0); m++)
+            {
+            for (int n = 0; n < matsize(1); n++)
+              {
+                QString cellval;
+                cellval.setNum (matval (m, n));
+                QTableWidgetItem *qtwi = new QTableWidgetItem (cellval);
+                qtable->setItem (m, n, qtwi);
+fprintf(stderr,"%5g ",matval(m,n));
+              }
+fprintf(stderr,"\n");
+            }
+          qtable->setAttribute (Qt::WA_DeleteOnClose);
+          qtable->show ();
+        }
+    }
+  command_count++;
+}
+
+void
 files_dock_widget::do_up_directory ()
 {
   QDir dir = QDir (_file_system_model->filePath (_file_tree_view->rootIndex ()));
diff -r 5293cee91891 -r 264710b5daee libgui/src/files-dockwidget.h
--- a/libgui/src/files-dockwidget.h	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/files-dockwidget.h	Sat Apr 13 04:46:24 2013 -0500
@@ -38,6 +38,12 @@
 #include <QLineEdit>
 #include "octave-dock-widget.h"
 
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "ov.h"
+
 /**
    \class files_dock_widget
    \brief Dock widget to display files in the current directory.
@@ -55,6 +61,9 @@
   /** Slot for handling a change in directory via double click. */
   void item_double_clicked (const QModelIndex & index);
 
+void do_prototype_input ();
+void handle_octave_command_result (const QObject* ID, const octave_value_list& ovlres);
+
   /** Slot for handling the up-directory button in the toolbar. */
   void do_up_directory ();
 
@@ -76,9 +85,14 @@
   /** Emitted, whenever the currently displayed directory changed. */
   void displayed_directory_changed (const QString& directory);
 
+void queue_an_octave_command (const QString &, const int nout);
+
 protected:
 
 private:
+int command_count;
+NDArray matsize;
+
   // TODO: Add toolbar with buttons for navigating the path, creating dirs, etc
 
   QString           _last_current_directory;
diff -r 5293cee91891 -r 264710b5daee libgui/src/main-window.cc
--- a/libgui/src/main-window.cc	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/main-window.cc	Sat Apr 13 04:46:24 2013 -0500
@@ -36,6 +36,7 @@
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QIcon>
+#include <QMetaType>
 
 #ifdef HAVE_QSCINTILLA
 #include "file-editor.h"
@@ -640,6 +641,39 @@
 }
 
 
+// Connect the signals emitted when the Octave thread wants to create
+// a dialog box of some sort.  Perhaps a better place for this would be
+// as part of the QUIWidgetCreator class.  However, mainWindow currently
+// is not a global variable and not accessible for connecting.  This
+// could be changed easily enough. 
+void
+main_window::connect_uiwidget_links ()
+{
+  connect (&uiwidget_creator, SIGNAL (create_dialog (const QString&,
+                              const QString&, const QString&,
+                              const QStringList&, const QString&,
+                              const QStringList&)),
+           this,              SLOT (handle_create_dialog (const QString&,
+                              const QString&, const QString&,
+                              const QStringList&, const QString&,
+                              const QStringList&)));
+}
+
+ 
+// Create a message dialog with specified string, buttons and decorative text.
+void
+main_window::handle_create_dialog (const QString& message, const QString& title,
+                                   const QString& icon, const QStringList& button,
+                                   const QString& defbutton,
+                                   const QStringList& role)
+{
+  MessageDialog *message_dialog = new MessageDialog (message, title, icon,
+                                                     button, defbutton, role);
+  message_dialog->setAttribute (Qt::WA_DeleteOnClose);
+  message_dialog->show ();
+}
+
+
 // Main subroutine of the constructor
 void
 main_window::construct ()
diff -r 5293cee91891 -r 264710b5daee libgui/src/main-window.h
--- a/libgui/src/main-window.h	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/main-window.h	Sat Apr 13 04:46:24 2013 -0500
@@ -50,6 +50,7 @@
 #include "terminal-dockwidget.h"
 #include "documentation-dockwidget.h"
 #include "octave-qt-event-listener.h"
+#include "dialog.h"
 
 /**
  * \class MainWindow
@@ -126,6 +127,11 @@
   void write_settings ();
   void connect_visibility_changed ();
 
+  void connect_uiwidget_links ();
+  void handle_create_dialog (const QString& message, const QString& title,
+                             const QString& icon, const QStringList& button,
+                             const QString& defbutton, const QStringList& role);
+
 protected:
   void closeEvent (QCloseEvent * closeEvent);
 
diff -r 5293cee91891 -r 264710b5daee libgui/src/module.mk
--- a/libgui/src/module.mk	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/module.mk	Sat Apr 13 04:46:24 2013 -0500
@@ -80,7 +80,8 @@
   src/octave-adapter/moc-octave-main-thread.cc \
   src/qtinfo/moc-parser.cc \
   src/qtinfo/moc-webinfo.cc \
-  src/moc-octave-dock-widget.cc
+  src/moc-octave-dock-widget.cc \
+  guifcn/moc-dialog.cc
 
 octave_gui_RC = src/qrc-resource.cc
 
@@ -152,6 +153,7 @@
   -I$(srcdir)/src/m-editor \
   -I$(srcdir)/src/octave-adapter \
   -I$(srcdir)/src/qtinfo \
+  -I$(srcdir)/guifcn \
   -I$(top_srcdir)/liboctave/cruft/misc \
   -I$(top_srcdir)/liboctave/array \
   -I$(top_builddir)/liboctave/numeric -I$(top_srcdir)/liboctave/numeric \
diff -r 5293cee91891 -r 264710b5daee libgui/src/octave-gui.cc
--- a/libgui/src/octave-gui.cc	Sun Mar 17 05:12:56 2013 -0400
+++ b/libgui/src/octave-gui.cc	Sat Apr 13 04:46:24 2013 -0500
@@ -111,6 +111,8 @@
           w.focus_command_window ();
           w.connect_visibility_changed (); // connect signals for changes in
                                            // visibility not before w is shown
+          w.connect_uiwidget_links (); // connect signals across GUI thread and
+                                       // Octave thread
           return application.exec ();
         }
     }
diff -r 5293cee91891 -r 264710b5daee libinterp/Makefile.am
--- a/libinterp/Makefile.am	Sun Mar 17 05:12:56 2013 -0400
+++ b/libinterp/Makefile.am	Sat Apr 13 04:46:24 2013 -0500
@@ -108,6 +108,7 @@
   builtins.h \
   builtin-defun-decls.h \
   octave.h \
+  ../libgui/$(GUIFCN_INC) \
   $(OCTAVE_VALUE_INC) \
   $(PARSE_TREE_INC) \
   $(PARSER_INC) \
@@ -124,6 +125,7 @@
 
 DIST_SRC = \
   octave.cc \
+  ../libgui/$(GUIFCN_SRC) \
   $(OCTAVE_VALUE_SRC) \
   $(PARSE_TREE_SRC) \
   $(PARSER_SRC) \
@@ -133,6 +135,7 @@
 
 noinst_LTLIBRARIES =
 
+include ../libgui/guifcn/module.mk
 include parse-tree/module.mk
 include octave-value/module.mk
 include operators/module.mk
@@ -178,6 +181,7 @@
 include link-deps.mk
 
 liboctinterp_la_LIBADD = \
+  guifcn/libguifcn.la \
   octave-value/liboctave-value.la \
   parse-tree/libparse-tree.la \
   parse-tree/libparser.la \
@@ -238,8 +242,8 @@
 ## FIXME -- Shouldn't the build stop if CPP fails here?
 %.df: %.cc
 	$(CXXCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
-	  $(AM_CPPFLAGS) $(JAVA_CPPFLAGS) $(CPPFLAGS) \
-	  $(AM_CXXFLAGS) $(CXXFLAGS) \
+	  $(AM_CPPFLAGS) $(JAVA_CPPFLAGS) $(QT_CPPFLAGS) \
+          $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
 	  -DMAKE_BUILTINS $< | $(srcdir)/mkdefs $(srcdir) $< > $@-t
 	mv $@-t $@
 
