Diffstat (limited to 'noncore/tools/opie-sh/opie-sh.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/tools/opie-sh/opie-sh.cpp | 269 |
1 files changed, 269 insertions, 0 deletions
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 @@ | |||
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 | |||
17 | #include <qstring.h> | ||
18 | #include <qstringlist.h> | ||
19 | #include <qpe/qpeapplication.h> | ||
20 | #include <qmessagebox.h> | ||
21 | #include <qwidget.h> | ||
22 | |||
23 | #include <stdio.h> | ||
24 | |||
25 | #include "mbox.h" | ||
26 | #include "fviewer.h" | ||
27 | #include "inputdialog.h" | ||
28 | |||
29 | int myMessageBox(int wi, int h, QWidget *w, int argc, QStringList args) | ||
30 | { | ||
31 | int i, type=0; | ||
32 | QString button0Text, button1Text, button2Text, string, title; | ||
33 | bool full=true; | ||
34 | |||
35 | for(i=0; i<argc; i++) | ||
36 | { | ||
37 | if(args[i] == "-t") | ||
38 | { | ||
39 | title = args[i+1]; | ||
40 | } | ||
41 | |||
42 | if(args[i] == "-M") | ||
43 | { | ||
44 | string = args[i+1]; | ||
45 | } | ||
46 | |||
47 | if(args[i] == "-0") | ||
48 | { | ||
49 | button0Text = args[i+1]; | ||
50 | } | ||
51 | |||
52 | if(args[i] == "-1") | ||
53 | { | ||
54 | button1Text = args[i+1]; | ||
55 | } | ||
56 | |||
57 | if(args[i] == "-2") | ||
58 | { | ||
59 | button2Text = args[i+1]; | ||
60 | } | ||
61 | |||
62 | if(args[i] == "-I") | ||
63 | { | ||
64 | type=0; | ||
65 | } | ||
66 | |||
67 | if(args[i] == "-w") | ||
68 | { | ||
69 | type = 1; | ||
70 | } | ||
71 | |||
72 | if(args[i] == "-e") | ||
73 | { | ||
74 | type = 2; | ||
75 | } | ||
76 | |||
77 | if(args[i] == "-g") | ||
78 | { | ||
79 | full = false; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | MBox *mbox = new MBox(wi, h, (int)type, title, string, &button0Text, &button1Text, &button2Text, w, (QString)"messagebox"); | ||
84 | if(full) | ||
85 | { | ||
86 | w->setCaption(title); | ||
87 | w->showMaximized(); | ||
88 | } | ||
89 | //mbox->show(); | ||
90 | switch(mbox->exec() ) | ||
91 | { | ||
92 | case 0: | ||
93 | return -1; | ||
94 | case 1: | ||
95 | return -1; | ||
96 | case 2: | ||
97 | return 0; | ||
98 | case 3: | ||
99 | return 1; | ||
100 | case 4: | ||
101 | return 2; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | void printusage() | ||
106 | { | ||
107 | printf("Usage instructions for Opie-sh\n"); | ||
108 | printf("Usage: opie-sh [dialog type] [type specific options]\n"); | ||
109 | printf("Types:\n"); | ||
110 | printf(" -m Message Box\n"); | ||
111 | printf(" -f [filename] View file [Default = stdin]\n"); | ||
112 | printf(" -i Input dialog\n"); | ||
113 | printf(" -h --help These instructions\n"); | ||
114 | printf(" -t [title] The window/dialog title\n"); | ||
115 | printf("Message box options:\n"); | ||
116 | printf(" -M [message] The message to display\n"); | ||
117 | printf(" -I Use information icon\n"); | ||
118 | printf(" -w Use the warning icon\n"); | ||
119 | printf(" -e Use the error icon\n"); | ||
120 | printf(" -0 [text] First button text [Default = OK]\n"); | ||
121 | printf(" -1 [text] Second button text\n"); | ||
122 | printf(" -2 [text] Third button text\n"); | ||
123 | printf(" -g Disable fullscreen\n"); | ||
124 | printf("Input Dialog options:\n"); | ||
125 | printf(" -s A single line of input (output to console)\n"); | ||
126 | printf(" -l List input (newline separated list read in from file)\n"); | ||
127 | printf(" -b A list box, enabling multiple selections (input same as -l)\n"); | ||
128 | printf(" -L [label] The label for the input field\n"); | ||
129 | printf(" -F [filename] An input file (for when it makes sense) [Default = stdin]\n"); | ||
130 | printf(" -E Makes list input editable\n"); | ||
131 | printf(" -g Disable fullscreen\n"); | ||
132 | } | ||
133 | |||
134 | int fileviewer(QPEApplication *a, int argc, QStringList args) | ||
135 | { | ||
136 | int i; | ||
137 | QString filename, title; | ||
138 | bool update=false; | ||
139 | |||
140 | for(i=0; i < argc; i++) | ||
141 | { | ||
142 | if(args[i] == "-f") | ||
143 | { | ||
144 | if(args[i+1][0] != '-') | ||
145 | { | ||
146 | filename = args[i+1]; | ||
147 | } | ||
148 | } | ||
149 | |||
150 | if(args[i] == "-t") | ||
151 | { | ||
152 | title = args[i+1]; | ||
153 | } | ||
154 | } | ||
155 | FViewer *fview = new FViewer(filename, title, 0, (QString) "fileviewer"); | ||
156 | a->setMainWidget(fview); | ||
157 | fview->showMaximized(); | ||
158 | return a->exec(); | ||
159 | } | ||
160 | |||
161 | int input(int wi, int h, QWidget *w, int argc, QStringList args) | ||
162 | { | ||
163 | int i, type = 0; | ||
164 | QString title, label, filename; | ||
165 | bool edit=false, full=true; | ||
166 | |||
167 | for(i=0; i < argc; i++) | ||
168 | { | ||
169 | if(args[i] == "-s") | ||
170 | { | ||
171 | type = 0; | ||
172 | } | ||
173 | |||
174 | if(args[i] == "-l") | ||
175 | { | ||
176 | type = 1; | ||
177 | } | ||
178 | |||
179 | if(args[i] == "-b") | ||
180 | { | ||
181 | type = 2; | ||
182 | } | ||
183 | |||
184 | if(args[i] == "-t") | ||
185 | { | ||
186 | title = args[i+1]; | ||
187 | } | ||
188 | |||
189 | if(args[i] == "-L") | ||
190 | { | ||
191 | label = args[i+1]; | ||
192 | } | ||
193 | |||
194 | if(args[i] == "-F") | ||
195 | { | ||
196 | filename = args[i+1]; | ||
197 | } | ||
198 | |||
199 | if(args[i] =="-E") | ||
200 | { | ||
201 | edit = true; | ||
202 | } | ||
203 | |||
204 | if(args[i] == "-g") | ||
205 | { | ||
206 | full = false; | ||
207 | } | ||
208 | } | ||
209 | InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w); | ||
210 | if(full) | ||
211 | { | ||
212 | w->setCaption(title); | ||
213 | w->showMaximized(); | ||
214 | } | ||
215 | if( id->exec() == 1) | ||
216 | { | ||
217 | printf("%s\n", id->getString().latin1()); | ||
218 | return 0; | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | return -1; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | int main(int argc, char **argv) | ||
227 | { | ||
228 | int i; | ||
229 | QStringList args; | ||
230 | QPEApplication a(argc, argv); | ||
231 | QWidget w; | ||
232 | a.setMainWidget(&w); | ||
233 | QWidget *d = a.desktop(); | ||
234 | int width=d->width(); | ||
235 | int height=d->height(); | ||
236 | |||
237 | for(i=0; i < argc; i++) | ||
238 | { | ||
239 | args += argv[i]; | ||
240 | } | ||
241 | |||
242 | for(i=0; i < argc; i++) | ||
243 | { | ||
244 | if(args[i] == "-m") | ||
245 | { | ||
246 | return myMessageBox(width, height, &w, argc, args); | ||
247 | } | ||
248 | |||
249 | if(args[i] == "-f") | ||
250 | { | ||
251 | return fileviewer(&a, argc, args); | ||
252 | } | ||
253 | |||
254 | if(args[i] == "-i") | ||
255 | { | ||
256 | return input(width, height, &w, argc, args); | ||
257 | } | ||
258 | |||
259 | if(args[i] == "-h" || args[i] =="--help") | ||
260 | { | ||
261 | printusage(); | ||
262 | return -1; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | printusage(); | ||
267 | return -1; | ||
268 | } | ||
269 | |||