[PC-BSD Commits] r15119 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Tue Jan 31 15:39:53 PST 2012


Author: kenmoore
Date: 2012-01-31 23:39:53 +0000 (Tue, 31 Jan 2012)
New Revision: 15119

Modified:
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:
Add a new function to libpcbsd-utils: QStringList quickUserInputBox(QString, QStringList)



Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-01-31 16:30:48 UTC (rev 15118)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-01-31 23:39:53 UTC (rev 15119)
@@ -57,6 +57,7 @@
    static QStringList runShellCommand( QString command );
    static QString runShellCommandSearch( QString command, QString sch );
    static QStringList listShellCommandSearch( QString command, QString sch );
+   static QStringList quickUserInputBox( QString title, QStringList inputList );
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-01-31 16:30:48 UTC (rev 15118)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-01-31 23:39:53 UTC (rev 15119)
@@ -33,6 +33,14 @@
 #include <QProcess>
 #include <QApplication>
 #include <QDebug>
+
+#include <QObject>
+#include <QDialog>
+#include <QFormLayout>
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+
 #include "pcbsd-utils.h"
 
 #include "../config.h"
@@ -434,3 +442,43 @@
   }
   return L;
 }
+
+QStringList Utils::quickUserInputBox(QString title, QStringList inputList){
+  //inputList:=  list of labels, one entry for each user input required
+  //returns:=  list of user inputs - 1 per label in inputList, element number corresponds to input labels
+  
+  //Create the dialog
+  QDialog *inputDialog = new QDialog;
+  inputDialog->setModal(TRUE);
+  inputDialog->setWindowTitle(title);
+  //Add a label and editbox for each row (one per input in list)
+  QList<QLineEdit *> iboxes;
+  QFormLayout *layout = new QFormLayout;
+  for(int i=0; i<inputList.length(); i++){
+    //Create the widgets
+    QLabel *label = new QLabel(inputList[i]);
+    iboxes << new QLineEdit;
+    //add them to the layout
+    layout->addRow(label,iboxes[i]);
+  }
+  //Add the "Done" button to the bottom
+  QPushButton *pushdone = new QPushButton("Done");
+  const QString blank = "";
+  layout->addRow(blank,pushdone);
+  inputDialog->setLayout(layout);
+  QObject::connect(pushdone,SIGNAL(clicked()),inputDialog,SLOT(accept()));
+  
+  //Initialize output list
+  QStringList outputList;
+  
+  //Start the dialog
+  if( inputDialog->exec() == QDialog::Accepted ){ //If the dialog was not cancelled
+    //Retrieve the user inputs and return them for each edit box created (in order)
+    for(int i=0; i<iboxes.length(); i++){
+      outputList << iboxes[i]->text();
+    }
+  }
+  
+  delete inputDialog; //delete the dialog - we are done with it
+  return outputList; //Ouput will be empty if an error or if box cancelled
+}



More information about the Commits mailing list