diff libgui/src/dialog.cc @ 16579:7f8db1942dc0

Add Qt link uigetfile dialog implementation. * libgui/src/octave-qt-link.cc, libgui/src/octave-qt-link.h, (octave_qt_link::do_file_dialog): New function. (make_filter_list): New function. * libinterp/interpfcn/octave-link.cc (__octave_link_file_dialog__): New function. * libinterp/interpfcn/octave-link.h: (octave_link::file_dialog): New function. (octave_link::do_file_dialog): New virtual function. * scripts/plot/uigetfile.m: update to call octave_link file dialog if octave link is present. * libgui/src/dialog.cc, libgui/src/dialog.h (class FileDialog): New class. (QUIWidgetCreator::QUIWidgetCreator): added initialization of new var path_name. (QUIWidgetCreator::signal_filedialog): New function. (QUIWidgetCreator::create_filedialog): New function. (QUIWidgetCreator::filedialog_finished): New function. (QUIWidgetCreator::get_dialog_path): New function. * libgui/src/main-window.cc, libgui/src/main-window.h (main_window::connect_uiwidget_links): Added connect for handle_file_dialog. (main_window::handle_create_filedialog): New function.
author John Donoghue <john.donoghue@ieee.org>
date Sun, 28 Apr 2013 09:45:19 -0400
parents e4b94abfeb96
children adc150db1809
line wrap: on
line diff
--- a/libgui/src/dialog.cc	Sun Apr 28 02:29:19 2013 -0400
+++ b/libgui/src/dialog.cc	Sun Apr 28 09:45:19 2013 -0400
@@ -31,6 +31,7 @@
 #include <QStringList>
 #include <QStringListModel>
 #include <QListView>
+#include <QFileInfo>
 // Could replace most of these with #include <QtGui>
 #include <QMessageBox>
 #include <QHBoxLayout>
@@ -45,7 +46,7 @@
 
 QUIWidgetCreator::QUIWidgetCreator (void)
   : QObject (), dialog_result (-1), dialog_button (),
-    string_list (new QStringList ()), list_index (new QIntList ())
+    string_list (new QStringList ()), list_index (new QIntList ()), path_name (new QString ())
 { }
 
 
@@ -53,6 +54,7 @@
 {
   delete string_list;
   delete list_index;
+  delete path_name;
 }
 
 
@@ -94,6 +96,19 @@
   waitcondition.wakeAll ();
 }
 
+void
+QUIWidgetCreator::filedialog_finished (const QStringList& files, const QString & path, const int filterindex)
+{
+  // Store the value so that builtin functions can retrieve.
+  *string_list = files;
+  dialog_result = filterindex;
+  *path_name = path;
+
+  // Wake up Octave process so that it continues.
+  waitcondition.wakeAll ();
+}
+
+
 
 MessageDialog::MessageDialog (const QString& message,
                               const QString& title,
@@ -386,7 +401,6 @@
   done (QDialog::Accepted);
 }
 
-
 void
 InputDialog::buttonCancel_clicked (void)
 {
@@ -403,3 +417,66 @@
 {
   buttonCancel_clicked ();
 }
+
+FileDialog::FileDialog (const QStringList &filters,
+                        const QString& title,
+                        const QString& filename,
+                        const QString &dirname,
+                        bool multiselect)
+  : QFileDialog()
+{
+  // Create a NonModal message.
+  setWindowModality (Qt::NonModal);
+
+  setWindowTitle (title.isEmpty () ? " " : title);
+  setDirectory (dirname);
+
+  if (multiselect)
+    setFileMode (QFileDialog::ExistingFiles);
+  else
+    setFileMode (QFileDialog::ExistingFile);
+
+  setNameFilters (filters);
+  setAcceptMode (QFileDialog::AcceptOpen);
+  selectFile (filename);
+  
+  connect (this, SIGNAL (finish_input (const QStringList&, const QString &, const int)),
+           &uiwidget_creator,
+           SLOT (filedialog_finished (const QStringList&, const QString &, const int)));
+}
+
+void
+FileDialog::reject (void)
+{
+  QStringList empty;
+  emit finish_input (empty, "", 0);
+  done (QDialog::Rejected);
+
+}
+
+void FileDialog::accept(void)
+{
+  QStringList string_result;
+  QString path;
+  int idx = 1;
+
+  string_result = selectedFiles();
+
+  // matlab expects just the file name, whereas the file dialog gave us
+  // pull path names, so fix it
+  for(int i=0;i<string_result.size ();i++)
+    {
+      string_result[i] = QFileInfo (string_result[i]).fileName ();
+    }
+
+
+  path = directory ().absolutePath ();
+
+  QStringList filters = nameFilters ();
+  idx = filters.indexOf( selectedNameFilter ()) + 1;
+  
+  // send the selected info
+  emit finish_input (string_result, path, idx);
+  done (QDialog::Accepted);
+}
+