summaryrefslogtreecommitdiff
path: root/noncore/tools/opie-sh/inputdialog.cpp
Unidiff
Diffstat (limited to 'noncore/tools/opie-sh/inputdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/opie-sh/inputdialog.cpp117
1 files changed, 117 insertions, 0 deletions
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 @@
1/*
2Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
3Copyright (C) 2002 Thomas Stephens
4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version.
8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/
16#include "inputdialog.h"
17
18InputDialog::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)
19{
20 type = newtype;
21 QHBoxLayout *layout = new QHBoxLayout(this);
22 layout->addStrut(32);
23 QLabel *label = new QLabel(labelString, this, "label");
24 setCaption(title);
25 int x, y;
26
27 layout->addSpacing(5);
28 layout->addWidget(label);
29 layout->addSpacing(5);
30
31 switch(type)
32 {
33 case 0:
34 lineEdit = new QLineEdit(this, "line edit");
35 layout->addWidget(lineEdit);
36 break;
37 case 1:
38 comboBox = new QComboBox(edit, this, "combo box");
39 layout->addWidget(comboBox);
40 if(!filename.isNull())
41 {
42 QFile file(filename);
43 file.open(IO_ReadOnly);
44 QTextStream stream(&file);
45 QString string = stream.read();
46
47 comboBox->insertStringList(QStringList::split('\n', string));
48 }
49 else
50 {
51 QFile file;
52 file.open(IO_ReadOnly, 0);
53 QTextStream stream(&file);
54 QString string = stream.read();
55
56 comboBox->insertStringList(QStringList::split('\n', string));
57 }
58 break;
59 case 2:
60 listBox = new QListBox(this, "list box");
61 listBox->setSelectionMode(QListBox::Multi);
62 layout->addWidget(listBox);
63 if(!filename.isNull())
64 {
65 QFile file(filename);
66 file.open(IO_ReadOnly);
67 QTextStream stream(&file);
68 QString string = stream.read();
69
70 listBox->insertStringList(QStringList::split('\n', string));
71 }
72 else
73 {
74 QFile file;
75 file.open(IO_ReadOnly, 0);
76 QTextStream stream(&file);
77 QString string = stream.read();
78
79 listBox->insertStringList(QStringList::split('\n', string));
80 }
81 break;
82 }
83 layout->addSpacing(5);
84
85 x=(w/2)-(width()/2);
86 y=(h/2)-(height()/2);
87
88 move(x,y);
89}
90
91QString InputDialog::getString()
92{
93 switch (type)
94 {
95 case 0:
96 return ((QLineEdit *)child("line edit"))->text();
97 break;
98 case 1:
99 return ((QComboBox *)child("combo box"))->currentText();
100 break;
101 case 2:
102 QString string;
103 int i;
104 for(i = 0; i < listBox->count(); i++)
105 {
106 if(listBox->isSelected(i))
107 {
108 string+=listBox->text(i)+'\n';
109 }
110 }
111 if(string[string.length()-1] == '\n')
112 {
113 string.truncate(string.length()-1);
114 }
115 return string;
116 }
117}