author | spiralman <spiralman> | 2002-05-17 15:29:12 (UTC) |
---|---|---|
committer | spiralman <spiralman> | 2002-05-17 15:29:12 (UTC) |
commit | 36f5c2e7ebce170c083d75cefdabfbaaf5acdc10 (patch) (unidiff) | |
tree | 968f79ff7f54fb0d034015fbd7454185e6e18dbf /noncore/tools/opie-sh/inputdialog.cpp | |
parent | a008476dc0612c5c28e5c36eea33b212f68f2ace (diff) | |
download | opie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.zip opie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.tar.gz opie-36f5c2e7ebce170c083d75cefdabfbaaf5acdc10.tar.bz2 |
initial upload
Diffstat (limited to 'noncore/tools/opie-sh/inputdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/tools/opie-sh/inputdialog.cpp | 117 |
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 | /* | ||
2 | Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts) | ||
3 | Copyright (C) 2002 Thomas Stephens | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | ||
7 | version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
11 | Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | ||
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | */ | ||
16 | #include "inputdialog.h" | ||
17 | |||
18 | 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) | ||
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 | |||
91 | QString 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 | } | ||