summaryrefslogtreecommitdiff
path: root/noncore/tools/opie-sh
authorspiralman <spiralman>2002-05-17 15:29:12 (UTC)
committer spiralman <spiralman>2002-05-17 15:29:12 (UTC)
commit36f5c2e7ebce170c083d75cefdabfbaaf5acdc10 (patch) (side-by-side diff)
tree968f79ff7f54fb0d034015fbd7454185e6e18dbf /noncore/tools/opie-sh
parenta008476dc0612c5c28e5c36eea33b212f68f2ace (diff)
downloadopie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.zip
opie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.tar.gz
opie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.tar.bz2
initial upload
Diffstat (limited to 'noncore/tools/opie-sh') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/opie-sh/fviewer.cpp56
-rw-r--r--noncore/tools/opie-sh/fviewer.h35
-rw-r--r--noncore/tools/opie-sh/inputdialog.cpp117
-rw-r--r--noncore/tools/opie-sh/inputdialog.h38
-rw-r--r--noncore/tools/opie-sh/mbox.cpp90
-rw-r--r--noncore/tools/opie-sh/mbox.h38
-rw-r--r--noncore/tools/opie-sh/opie-sh.control10
-rw-r--r--noncore/tools/opie-sh/opie-sh.cpp269
-rw-r--r--noncore/tools/opie-sh/opie-sh.pro10
9 files changed, 663 insertions, 0 deletions
diff --git a/noncore/tools/opie-sh/fviewer.cpp b/noncore/tools/opie-sh/fviewer.cpp
new file mode 100644
index 0000000..1a0acc6
--- a/dev/null
+++ b/noncore/tools/opie-sh/fviewer.cpp
@@ -0,0 +1,56 @@
+/*
+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 "fviewer.h"
+
+FViewer::FViewer(QString filename, QString title, QWidget *parent=0, const char*name=0):QWidget(parent, name)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ textView = new QTextBrowser(this, "textview");
+ layout->addWidget(textView);
+
+ QString string;
+
+ if(title.isNull())
+ {
+ setCaption(filename);
+ }
+ else
+ {
+ setCaption(title);
+ }
+
+ file = new QFile();
+
+ if(!filename.isNull())
+ {
+ file->setName(filename);
+ file->open(IO_ReadOnly);
+ }
+ else
+ {
+ file->open(IO_ReadOnly, 0);
+ }
+
+ stream = new QTextStream(file);
+
+ string = stream->read();
+ textView->setText(string);
+ textView->mimeSourceFactory()->setFilePath(QDir::currentDirPath());
+ file->close();
+
+}
+
diff --git a/noncore/tools/opie-sh/fviewer.h b/noncore/tools/opie-sh/fviewer.h
new file mode 100644
index 0000000..488b6ed
--- a/dev/null
+++ b/noncore/tools/opie-sh/fviewer.h
@@ -0,0 +1,35 @@
+/*
+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 <qwidget.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qtextbrowser.h>
+#include <qlayout.h>
+#include <qtimer.h>
+#include <qdir.h>
+
+class FViewer :public QWidget
+{
+ Q_OBJECT
+public:
+ FViewer(QString filename, QString title, QWidget *parent=0, const char*name=0);
+private:
+ QFile *file;
+ QTextBrowser *textView;
+ QTextStream *stream;
+ QTimer *timer;
+};
diff --git a/noncore/tools/opie-sh/inputdialog.cpp b/noncore/tools/opie-sh/inputdialog.cpp
new file mode 100644
index 0000000..0780def
--- a/dev/null
+++ b/noncore/tools/opie-sh/inputdialog.cpp
@@ -0,0 +1,117 @@
+/*
+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=0, const char *name=0, bool modal=true, WFlags f=0):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;
+ }
+ layout->addSpacing(5);
+
+ x=(w/2)-(width()/2);
+ y=(h/2)-(height()/2);
+
+ move(x,y);
+}
+
+QString InputDialog::getString()
+{
+ switch (type)
+ {
+ case 0:
+ 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;
+ }
+}
diff --git a/noncore/tools/opie-sh/inputdialog.h b/noncore/tools/opie-sh/inputdialog.h
new file mode 100644
index 0000000..9624db7
--- a/dev/null
+++ b/noncore/tools/opie-sh/inputdialog.h
@@ -0,0 +1,38 @@
+/*
+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 <qdialog.h>
+#include <qstring.h>
+#include <qlineedit.h>
+#include <qlayout.h>
+#include <qlabel.h>
+#include <qcombobox.h>
+#include <qfile.h>
+#include <qtextstream.h>
+#include <qlistbox.h>
+
+class InputDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent=0, const char *name=0, bool modal=true, WFlags f=0);
+ QString getString();
+private:
+ int type;
+ QLineEdit *lineEdit;
+ QComboBox *comboBox;
+ QListBox *listBox;
+};
diff --git a/noncore/tools/opie-sh/mbox.cpp b/noncore/tools/opie-sh/mbox.cpp
new file mode 100644
index 0000000..cb3ea1b
--- a/dev/null
+++ b/noncore/tools/opie-sh/mbox.cpp
@@ -0,0 +1,90 @@
+/*
+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 "mbox.h"
+
+MBox::MBox(int w, int h, int type, QString title, QString message, QString *btext0 = 0, QString *btext1= 0, QString *btext2 = 0, QWidget *parent=0, const char*name=0, bool modal=true, WFlags f=0):QDialog(parent, name, modal, f)
+{
+ QVBoxLayout *layout = new QVBoxLayout(this);
+
+ QHBoxLayout *hlayout1 = new QHBoxLayout(this);
+ QHBoxLayout *hlayout2 = new QHBoxLayout(this);
+
+ int x, y;
+
+ layout->addLayout(hlayout1);
+ layout->addLayout(hlayout2);
+
+ setCaption(title);
+
+ QLabel *image = new QLabel(this, "image");
+ QLabel *text = new QLabel(message, this, "text");
+
+ switch (type)
+ {
+ case 0:
+ image->setPixmap(Resource::loadPixmap("opie-sh/info"));
+ break;
+ case 1:
+ image->setPixmap(Resource::loadPixmap("opie-sh/warning"));
+ break;
+ case 2:
+ image->setPixmap(Resource::loadPixmap("opie-sh/error"));
+ break;
+ }
+
+ hlayout1->addWidget(image);
+ hlayout1->addSpacing(5);
+ hlayout1->addWidget(text);
+
+ if(!btext0->isNull())
+ {
+ QPushButton *button0 = new QPushButton((const QString)*btext0, this, "button0");
+ hlayout2->addSpacing(5);
+ hlayout2->addWidget(button0);
+ hlayout2->addSpacing(5);
+ connect(button0, SIGNAL(clicked()), this, SLOT(b0pressed()) );
+ }
+ else
+ {
+ QPushButton *button0 = new QPushButton("Ok", this, "button0");
+ hlayout2->addSpacing(5);
+ hlayout2->addWidget(button0);
+ hlayout2->addSpacing(5);
+ connect(button0, SIGNAL(clicked()), this, SLOT(b0pressed()) );
+ }
+
+ if(!btext1->isNull())
+ {
+ QPushButton *button1 = new QPushButton((const QString)*btext1, this, "button1");
+ hlayout2->addWidget(button1);
+ hlayout2->addSpacing(5);
+ connect(button1, SIGNAL(clicked()), this, SLOT(b1pressed()) );
+ }
+
+ if(!btext2->isNull())
+ {
+ QPushButton *button2 = new QPushButton((const QString)*btext2, this, "button2");
+ hlayout2->addWidget(button2);
+ hlayout2->addSpacing(5);
+ connect(button2, SIGNAL(clicked()), this, SLOT(b2pressed()) );
+ }
+
+ x=(w/2)-(width()/2);
+ y=(h/2)-(height()/2);
+
+ move(x, y);
+}
diff --git a/noncore/tools/opie-sh/mbox.h b/noncore/tools/opie-sh/mbox.h
new file mode 100644
index 0000000..66c982a
--- a/dev/null
+++ b/noncore/tools/opie-sh/mbox.h
@@ -0,0 +1,38 @@
+/*
+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 <qpe/resource.h>
+#include <qdialog.h>
+#include <qstring.h>
+#include <qiconset.h>
+#include <qpixmap.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qwidget.h>
+
+#include <unistd.h>
+
+class MBox : public QDialog
+{
+ Q_OBJECT
+public:
+ MBox(int w, int h, int type, QString title, QString message, QString *btext0 = 0, QString *btext1= 0, QString *btext2 = 0, QWidget *parent=0, const char*name=0, bool modal=true, WFlags f=0);
+public slots:
+ void b0pressed(){done(2);};
+ void b1pressed(){done(3);};
+ void b2pressed(){done(4);};
+};
diff --git a/noncore/tools/opie-sh/opie-sh.control b/noncore/tools/opie-sh/opie-sh.control
new file mode 100644
index 0000000..e9b13a5
--- a/dev/null
+++ b/noncore/tools/opie-sh/opie-sh.control
@@ -0,0 +1,10 @@
+Files: bin/opie-sh pics/opie-sh/*.png
+Priority: optional
+Section: opie/applications
+Maintainer: Thomas Stephens <spiralman@softhome.net>
+Architecture: arm
+Version: 0.4-$SUB_VERSION
+Depends: opie-base ($QPE_VERSION)
+License: GPL
+Description: a QDialog shell frontend
+ A program to let you use various dialogs from the console (or a shell script)
diff --git a/noncore/tools/opie-sh/opie-sh.cpp b/noncore/tools/opie-sh/opie-sh.cpp
new file mode 100644
index 0000000..a1b8035
--- a/dev/null
+++ b/noncore/tools/opie-sh/opie-sh.cpp
@@ -0,0 +1,269 @@
+/*
+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;
+ }
+}
+
+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(" -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;
+ 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] == "-t")
+ {
+ title = args[i+1];
+ }
+ }
+ FViewer *fview = new FViewer(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] == "-t")
+ {
+ title = args[i+1];
+ }
+
+ if(args[i] == "-L")
+ {
+ label = args[i+1];
+ }
+
+ if(args[i] == "-F")
+ {
+ 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;
+}
+
diff --git a/noncore/tools/opie-sh/opie-sh.pro b/noncore/tools/opie-sh/opie-sh.pro
new file mode 100644
index 0000000..5c0d36c
--- a/dev/null
+++ b/noncore/tools/opie-sh/opie-sh.pro
@@ -0,0 +1,10 @@
+TEMPLATE =app
+CONFIG +=qt warn_on release
+DESTDIR =$(OPIEDIR)/bin
+HEADERS =mbox.h fviewer.h inputdialog.h
+SOURCES =opie-sh.cpp mbox.cpp fviewer.cpp inputdialog.cpp
+INCLUDEPATH +=$(OPIEDIR)/include
+DEPENDPATH +=$(OPIEDIR)/include
+LIBS +=-lqpe
+TRANSLATIONS =
+TARGET = opie-sh