summaryrefslogtreecommitdiff
path: root/noncore/tools/opie-sh/opie-sh.cpp
Unidiff
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.cpp492
1 files changed, 249 insertions, 243 deletions
diff --git a/noncore/tools/opie-sh/opie-sh.cpp b/noncore/tools/opie-sh/opie-sh.cpp
index a353d3f..7d54a03 100644
--- a/noncore/tools/opie-sh/opie-sh.cpp
+++ b/noncore/tools/opie-sh/opie-sh.cpp
@@ -1,284 +1,290 @@
1/* 1/*
2Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts) 2Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 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 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 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 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 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 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16 16
17
18#include "mbox.h"
19#include "fviewer.h"
20#include "inputdialog.h"
21
22/* OPIE */
23#include <qpe/qpeapplication.h>
24
25/* QT */
17#include <qstring.h> 26#include <qstring.h>
18#include <qstringlist.h> 27#include <qstringlist.h>
19#include <qpe/qpeapplication.h>
20#include <qmessagebox.h> 28#include <qmessagebox.h>
21#include <qwidget.h> 29#include <qwidget.h>
22 30
31/* STD */
23#include <stdio.h> 32#include <stdio.h>
24 33
25#include "mbox.h"
26#include "fviewer.h"
27#include "inputdialog.h"
28 34
29int myMessageBox(int wi, int h, QWidget *w, int argc, QStringList args) 35int myMessageBox(int wi, int h, QWidget *w, int argc, QStringList args)
30{ 36{
31 int i, type=0; 37 int i, type=0;
32 QString button0Text, button1Text, button2Text, string, title; 38 QString button0Text, button1Text, button2Text, string, title;
33 bool full=true; 39 bool full=true;
34 40
35 for(i=0; i<argc; i++) 41 for(i=0; i<argc; i++)
36 { 42 {
37 if(args[i] == "-t") 43 if(args[i] == "-t")
38 { 44 {
39 title = args[i+1]; 45 title = args[i+1];
40 } 46 }
41 47
42 if(args[i] == "-M") 48 if(args[i] == "-M")
43 { 49 {
44 string = args[i+1]; 50 string = args[i+1];
45 } 51 }
46 52
47 if(args[i] == "-0") 53 if(args[i] == "-0")
48 { 54 {
49 button0Text = args[i+1]; 55 button0Text = args[i+1];
50 } 56 }
51 57
52 if(args[i] == "-1") 58 if(args[i] == "-1")
53 { 59 {
54 button1Text = args[i+1]; 60 button1Text = args[i+1];
55 } 61 }
56 62
57 if(args[i] == "-2") 63 if(args[i] == "-2")
58 { 64 {
59 button2Text = args[i+1]; 65 button2Text = args[i+1];
60 } 66 }
61 67
62 if(args[i] == "-I") 68 if(args[i] == "-I")
63 { 69 {
64 type=0; 70 type=0;
65 } 71 }
66 72
67 if(args[i] == "-w") 73 if(args[i] == "-w")
68 { 74 {
69 type = 1; 75 type = 1;
70 } 76 }
71 77
72 if(args[i] == "-e") 78 if(args[i] == "-e")
73 { 79 {
74 type = 2; 80 type = 2;
75 } 81 }
76 82
77 if(args[i] == "-g") 83 if(args[i] == "-g")
78 { 84 {
79 full = false; 85 full = false;
80 } 86 }
81 } 87 }
82 88
83 MBox *mbox = new MBox(wi, h, (int)type, title, string, &button0Text, &button1Text, &button2Text, w, (QString)"messagebox"); 89 MBox *mbox = new MBox(wi, h, (int)type, title, string, &button0Text, &button1Text, &button2Text, w, (QString)"messagebox");
84 if(full) 90 if(full)
85 { 91 {
86 w->setCaption(title); 92 w->setCaption(title);
87 w->showMaximized(); 93 QPEApplication::showWidget( w );
88 } 94 }
89 //mbox->show(); 95 //mbox->show();
90 switch(mbox->exec() ) 96 switch(mbox->exec() )
91 { 97 {
92 case 0: 98 case 0:
93 return -1; 99 return -1;
94 case 1: 100 case 1:
95 return -1; 101 return -1;
96 case 2: 102 case 2:
97 return 0; 103 return 0;
98 case 3: 104 case 3:
99 return 1; 105 return 1;
100 case 4: 106 case 4:
101 return 2; 107 return 2;
102 default: return -1; 108 default: return -1;
103 } 109 }
104} 110}
105 111
106void printusage() 112void printusage()
107{ 113{
108 printf("Usage instructions for Opie-sh\n"); 114 printf("Usage instructions for Opie-sh\n");
109 printf("Usage: opie-sh [dialog type] [type specific options]\n"); 115 printf("Usage: opie-sh [dialog type] [type specific options]\n");
110 printf("Types:\n"); 116 printf("Types:\n");
111 printf(" -m Message Box\n"); 117 printf(" -m Message Box\n");
112 printf(" -f [filename] View file [Default = stdin]\n"); 118 printf(" -f [filename] View file [Default = stdin]\n");
113 printf(" -i Input dialog\n"); 119 printf(" -i Input dialog\n");
114 printf(" -h --help These instructions\n"); 120 printf(" -h --help These instructions\n");
115 printf(" -t [title] The window/dialog title\n"); 121 printf(" -t [title] The window/dialog title\n");
116 printf("Message box options:\n"); 122 printf("Message box options:\n");
117 printf(" -M [message] The message to display\n"); 123 printf(" -M [message] The message to display\n");
118 printf(" -I Use information icon\n"); 124 printf(" -I Use information icon\n");
119 printf(" -w Use the warning icon\n"); 125 printf(" -w Use the warning icon\n");
120 printf(" -e Use the error icon\n"); 126 printf(" -e Use the error icon\n");
121 printf(" -0 [text] First button text [Default = OK]\n"); 127 printf(" -0 [text] First button text [Default = OK]\n");
122 printf(" -1 [text] Second button text\n"); 128 printf(" -1 [text] Second button text\n");
123 printf(" -2 [text] Third button text\n"); 129 printf(" -2 [text] Third button text\n");
124 printf(" -g Disable fullscreen\n"); 130 printf(" -g Disable fullscreen\n");
125 printf("Input Dialog options:\n"); 131 printf("Input Dialog options:\n");
126 printf(" -s A single line of input (output to console)\n"); 132 printf(" -s A single line of input (output to console)\n");
127 printf(" -l List input (newline separated list read in from file)\n"); 133 printf(" -l List input (newline separated list read in from file)\n");
128 printf(" -b A list box, enabling multiple selections (input same as -l)\n"); 134 printf(" -b A list box, enabling multiple selections (input same as -l)\n");
129 printf(" -p Password input (display '*'s)\n"); 135 printf(" -p Password input (display '*'s)\n");
130 printf(" -L [label] The label for the input field\n"); 136 printf(" -L [label] The label for the input field\n");
131 printf(" -F [filename] An input file (for when it makes sense) [Default = stdin]\n"); 137 printf(" -F [filename] An input file (for when it makes sense) [Default = stdin]\n");
132 printf(" -E Makes list input editable\n"); 138 printf(" -E Makes list input editable\n");
133 printf(" -g Disable fullscreen\n"); 139 printf(" -g Disable fullscreen\n");
134} 140}
135 141
136int fileviewer(QPEApplication *a, int argc, QStringList args) 142int fileviewer(QPEApplication *a, int argc, QStringList args)
137{ 143{
138 int i; 144 int i;
139 QString filename, title, icon; 145 QString filename, title, icon;
140 bool update=false; 146 bool update=false;
141 147
142 for(i=0; i < argc; i++) 148 for(i=0; i < argc; i++)
143 { 149 {
144 if(args[i] == "-f") 150 if(args[i] == "-f")
145 { 151 {
146 if(args[i+1][0] != '-') 152 if(args[i+1][0] != '-')
147 { 153 {
148 filename = args[i+1]; 154 filename = args[i+1];
149 } 155 }
150 } 156 }
151 157
152 if(args[i] == "-I") 158 if(args[i] == "-I")
153 { 159 {
154 icon=args[i+1]; 160 icon=args[i+1];
155 } 161 }
156 162
157 if(args[i] == "-t") 163 if(args[i] == "-t")
158 { 164 {
159 title = args[i+1]; 165 title = args[i+1];
160 } 166 }
161 } 167 }
162 FViewer *fview = new FViewer(icon, filename, title, 0, (QString) "fileviewer"); 168 FViewer *fview = new FViewer(icon, filename, title, 0, (QString) "fileviewer");
163 a->setMainWidget(fview); 169 a->setMainWidget(fview);
164 fview->showMaximized(); 170 QPEApplication::showWidget( fview );
165 return a->exec(); 171 return a->exec();
166} 172}
167 173
168int input(int wi, int h, QWidget *w, int argc, QStringList args) 174int input(int wi, int h, QWidget *w, int argc, QStringList args)
169{ 175{
170 int i, type = 0; 176 int i, type = 0;
171 QString title, label, filename; 177 QString title, label, filename;
172 bool edit=false, full=true; 178 bool edit=false, full=true;
173 179
174 for(i=0; i < argc; i++) 180 for(i=0; i < argc; i++)
175 { 181 {
176 if(args[i] == "-s") 182 if(args[i] == "-s")
177 { 183 {
178 type = 0; 184 type = 0;
179 } 185 }
180 186
181 if(args[i] == "-l") 187 if(args[i] == "-l")
182 { 188 {
183 type = 1; 189 type = 1;
184 } 190 }
185 191
186 if(args[i] == "-b") 192 if(args[i] == "-b")
187 { 193 {
188 type = 2; 194 type = 2;
189 } 195 }
190 196
191 if(args[i] == "-p") 197 if(args[i] == "-p")
192 { 198 {
193 type = 3; 199 type = 3;
194 } 200 }
195 201
196 if(args[i] == "-t") 202 if(args[i] == "-t")
197 { 203 {
198 title = args[i+1]; 204 title = args[i+1];
199 } 205 }
200 206
201 if(args[i] == "-L") 207 if(args[i] == "-L")
202 { 208 {
203 label = args[i+1]; 209 label = args[i+1];
204 } 210 }
205 211
206 if(args[i] == "-F") 212 if(args[i] == "-F")
207 { 213 {
208 if(args[i+1][0] != '-') 214 if(args[i+1][0] != '-')
209 { 215 {
210 filename = args[i+1]; 216 filename = args[i+1];
211 } 217 }
212 } 218 }
213 219
214 if(args[i] =="-E") 220 if(args[i] =="-E")
215 { 221 {
216 edit = true; 222 edit = true;
217 } 223 }
218 224
219 if(args[i] == "-g") 225 if(args[i] == "-g")
220 { 226 {
221 full = false; 227 full = false;
222 } 228 }
223 } 229 }
224 InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w); 230 InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w);
225 if(full) 231 if(full)
226 { 232 {
227 w->setCaption(title); 233 w->setCaption(title);
228 w->showMaximized(); 234 QPEApplication::showWidget( w );
229 } 235 }
230 if( id->exec() == 1) 236 if( id->exec() == 1)
231 { 237 {
232 printf("%s\n", id->getString().latin1()); 238 printf("%s\n", id->getString().latin1());
233 return 0; 239 return 0;
234 } 240 }
235 else 241 else
236 { 242 {
237 return -1; 243 return -1;
238 } 244 }
239} 245}
240 246
241int main(int argc, char **argv) 247int main(int argc, char **argv)
242{ 248{
243 int i; 249 int i;
244 QStringList args; 250 QStringList args;
245 QPEApplication a(argc, argv); 251 QPEApplication a(argc, argv);
246 QWidget w; 252 QWidget w;
247 a.setMainWidget(&w); 253 a.setMainWidget(&w);
248 QWidget *d = a.desktop(); 254 QWidget *d = a.desktop();
249 int width=d->width(); 255 int width=d->width();
250 int height=d->height(); 256 int height=d->height();
251 257
252 for(i=0; i < argc; i++) 258 for(i=0; i < argc; i++)
253 { 259 {
254 args += argv[i]; 260 args += argv[i];
255 } 261 }
256 262
257 for(i=0; i < argc; i++) 263 for(i=0; i < argc; i++)
258 { 264 {
259 if(args[i] == "-m") 265 if(args[i] == "-m")
260 { 266 {
261 return myMessageBox(width, height, &w, argc, args); 267 return myMessageBox(width, height, &w, argc, args);
262 } 268 }
263 269
264 if(args[i] == "-f") 270 if(args[i] == "-f")
265 { 271 {
266 return fileviewer(&a, argc, args); 272 return fileviewer(&a, argc, args);
267 } 273 }
268 274
269 if(args[i] == "-i") 275 if(args[i] == "-i")
270 { 276 {
271 return input(width, height, &w, argc, args); 277 return input(width, height, &w, argc, args);
272 } 278 }
273 279
274 if(args[i] == "-h" || args[i] =="--help") 280 if(args[i] == "-h" || args[i] =="--help")
275 { 281 {
276 printusage(); 282 printusage();
277 return -1; 283 return -1;
278 } 284 }
279 } 285 }
280 286
281 printusage(); 287 printusage();
282 return -1; 288 return -1;
283} 289}
284 290