-rw-r--r-- | noncore/tools/opie-sh/inputdialog.cpp | 6 | ||||
-rw-r--r-- | noncore/tools/opie-sh/opie-sh.cpp | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/noncore/tools/opie-sh/inputdialog.cpp b/noncore/tools/opie-sh/inputdialog.cpp index 1c4e688..8046795 100644 --- a/noncore/tools/opie-sh/inputdialog.cpp +++ b/noncore/tools/opie-sh/inputdialog.cpp @@ -1,118 +1,124 @@ /* Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts) Copyright (C) 2002 Thomas Stephens This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "inputdialog.h" InputDialog::InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent, const char *name, bool modal, WFlags f):QDialog(parent, name, modal, f) { type = newtype; QHBoxLayout *layout = new QHBoxLayout(this); layout->addStrut(32); QLabel *label = new QLabel(labelString, this, "label"); setCaption(title); int x, y; layout->addSpacing(5); layout->addWidget(label); layout->addSpacing(5); switch(type) { case 0: lineEdit = new QLineEdit(this, "line edit"); layout->addWidget(lineEdit); break; case 1: comboBox = new QComboBox(edit, this, "combo box"); layout->addWidget(comboBox); if(!filename.isNull()) { QFile file(filename); file.open(IO_ReadOnly); QTextStream stream(&file); QString string = stream.read(); comboBox->insertStringList(QStringList::split('\n', string)); } else { QFile file; file.open(IO_ReadOnly, 0); QTextStream stream(&file); QString string = stream.read(); comboBox->insertStringList(QStringList::split('\n', string)); } break; case 2: listBox = new QListBox(this, "list box"); listBox->setSelectionMode(QListBox::Multi); layout->addWidget(listBox); if(!filename.isNull()) { QFile file(filename); file.open(IO_ReadOnly); QTextStream stream(&file); QString string = stream.read(); listBox->insertStringList(QStringList::split('\n', string)); } else { QFile file; file.open(IO_ReadOnly, 0); QTextStream stream(&file); QString string = stream.read(); listBox->insertStringList(QStringList::split('\n', string)); } break; + case 3: + lineEdit = new QLineEdit(this, "line edit"); + lineEdit->setEchoMode(QLineEdit::Password); + layout->addWidget(lineEdit); + break; } layout->addSpacing(5); x=(w/2)-(width()/2); y=(h/2)-(height()/2); move(x,y); } QString InputDialog::getString() { switch (type) { case 0: + case 3: return ((QLineEdit *)child("line edit"))->text(); break; case 1: return ((QComboBox *)child("combo box"))->currentText(); break; case 2: QString string; int i; for(i = 0; i < listBox->count(); i++) { if(listBox->isSelected(i)) { string+=listBox->text(i)+'\n'; } } if(string[string.length()-1] == '\n') { string.truncate(string.length()-1); } return string; } return QString::null; } diff --git a/noncore/tools/opie-sh/opie-sh.cpp b/noncore/tools/opie-sh/opie-sh.cpp index 96b4b93..a353d3f 100644 --- a/noncore/tools/opie-sh/opie-sh.cpp +++ b/noncore/tools/opie-sh/opie-sh.cpp @@ -1,278 +1,284 @@ /* Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts) Copyright (C) 2002 Thomas Stephens This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <qstring.h> #include <qstringlist.h> #include <qpe/qpeapplication.h> #include <qmessagebox.h> #include <qwidget.h> #include <stdio.h> #include "mbox.h" #include "fviewer.h" #include "inputdialog.h" int myMessageBox(int wi, int h, QWidget *w, int argc, QStringList args) { int i, type=0; QString button0Text, button1Text, button2Text, string, title; bool full=true; for(i=0; i<argc; i++) { if(args[i] == "-t") { title = args[i+1]; } if(args[i] == "-M") { string = args[i+1]; } if(args[i] == "-0") { button0Text = args[i+1]; } if(args[i] == "-1") { button1Text = args[i+1]; } if(args[i] == "-2") { button2Text = args[i+1]; } if(args[i] == "-I") { type=0; } if(args[i] == "-w") { type = 1; } if(args[i] == "-e") { type = 2; } if(args[i] == "-g") { full = false; } } MBox *mbox = new MBox(wi, h, (int)type, title, string, &button0Text, &button1Text, &button2Text, w, (QString)"messagebox"); if(full) { w->setCaption(title); w->showMaximized(); } // mbox->show(); switch(mbox->exec() ) { case 0: return -1; case 1: return -1; case 2: return 0; case 3: return 1; case 4: return 2; default: return -1; } } void printusage() { printf("Usage instructions for Opie-sh\n"); printf("Usage: opie-sh [dialog type] [type specific options]\n"); printf("Types:\n"); printf(" -m Message Box\n"); printf(" -f [filename] View file [Default = stdin]\n"); printf(" -i Input dialog\n"); printf(" -h --help These instructions\n"); printf(" -t [title] The window/dialog title\n"); printf("Message box options:\n"); printf(" -M [message] The message to display\n"); printf(" -I Use information icon\n"); printf(" -w Use the warning icon\n"); printf(" -e Use the error icon\n"); printf(" -0 [text] First button text [Default = OK]\n"); printf(" -1 [text] Second button text\n"); printf(" -2 [text] Third button text\n"); printf(" -g Disable fullscreen\n"); printf("Input Dialog options:\n"); printf(" -s A single line of input (output to console)\n"); printf(" -l List input (newline separated list read in from file)\n"); printf(" -b A list box, enabling multiple selections (input same as -l)\n"); + printf(" -p Password input (display '*'s)\n"); printf(" -L [label] The label for the input field\n"); printf(" -F [filename] An input file (for when it makes sense) [Default = stdin]\n"); printf(" -E Makes list input editable\n"); printf(" -g Disable fullscreen\n"); } int fileviewer(QPEApplication *a, int argc, QStringList args) { int i; QString filename, title, icon; bool update=false; for(i=0; i < argc; i++) { if(args[i] == "-f") { if(args[i+1][0] != '-') { filename = args[i+1]; } } if(args[i] == "-I") { icon=args[i+1]; } if(args[i] == "-t") { title = args[i+1]; } } FViewer *fview = new FViewer(icon, filename, title, 0, (QString) "fileviewer"); a->setMainWidget(fview); fview->showMaximized(); return a->exec(); } int input(int wi, int h, QWidget *w, int argc, QStringList args) { int i, type = 0; QString title, label, filename; bool edit=false, full=true; for(i=0; i < argc; i++) { if(args[i] == "-s") { type = 0; } if(args[i] == "-l") { type = 1; } if(args[i] == "-b") { type = 2; } + if(args[i] == "-p") + { + type = 3; + } + if(args[i] == "-t") { title = args[i+1]; } if(args[i] == "-L") { label = args[i+1]; } if(args[i] == "-F") { if(args[i+1][0] != '-') { filename = args[i+1]; } } if(args[i] =="-E") { edit = true; } if(args[i] == "-g") { full = false; } } InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w); if(full) { w->setCaption(title); w->showMaximized(); } if( id->exec() == 1) { printf("%s\n", id->getString().latin1()); return 0; } else { return -1; } } int main(int argc, char **argv) { int i; QStringList args; QPEApplication a(argc, argv); QWidget w; a.setMainWidget(&w); QWidget *d = a.desktop(); int width=d->width(); int height=d->height(); for(i=0; i < argc; i++) { args += argv[i]; } for(i=0; i < argc; i++) { if(args[i] == "-m") { return myMessageBox(width, height, &w, argc, args); } if(args[i] == "-f") { return fileviewer(&a, argc, args); } if(args[i] == "-i") { return input(width, height, &w, argc, args); } if(args[i] == "-h" || args[i] =="--help") { printusage(); return -1; } } printusage(); return -1; } |