Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

opie-sh.cpp

Go to the documentation of this file.
00001 /*
00002 Opie-sh.  convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
00003 Copyright (C) 2002 Thomas Stephens
00004  
00005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
00006 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
00007 version.
00008  
00009 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
00010 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00011 Public License for more details.
00012  
00013 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
00014 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 */
00016 
00017 
00018 #include "mbox.h"
00019 #include "fviewer.h"
00020 #include "inputdialog.h"
00021 
00022 /* OPIE */
00023 #include <qpe/qpeapplication.h>
00024 
00025 /* QT */
00026 #include <qstring.h>
00027 #include <qstringlist.h>
00028 #include <qmessagebox.h>
00029 #include <qwidget.h>
00030 
00031 /* STD */
00032 #include <stdio.h>
00033 
00034 
00035 int myMessageBox(int wi, int h, QWidget *w, int argc, QStringList args)
00036 {
00037     int i, type=0;
00038     QString button0Text, button1Text, button2Text, string, title;
00039     bool full=true;
00040 
00041     for(i=0; i<argc; i++)
00042     {
00043         if(args[i] == "-t")
00044         {
00045             title = args[i+1];
00046         }
00047 
00048         if(args[i] == "-M")
00049         {
00050             string =  args[i+1];
00051         }
00052 
00053         if(args[i] == "-0")
00054         {
00055             button0Text = args[i+1];
00056         }
00057 
00058         if(args[i] == "-1")
00059         {
00060             button1Text = args[i+1];
00061         }
00062 
00063         if(args[i] == "-2")
00064         {
00065             button2Text = args[i+1];
00066         }
00067 
00068         if(args[i] == "-I")
00069         {
00070             type=0;
00071         }
00072 
00073         if(args[i] == "-w")
00074         {
00075             type = 1;
00076         }
00077 
00078         if(args[i] == "-e")
00079         {
00080             type = 2;
00081         }
00082 
00083         if(args[i] == "-g")
00084         {
00085             full = false;
00086         }
00087     }
00088 
00089     MBox *mbox = new MBox(wi, h, (int)type, title, string, &button0Text, &button1Text, &button2Text, w, (QString)"messagebox");
00090     if(full)
00091     {
00092         w->setCaption(title);
00093         QPEApplication::showWidget( w );
00094     }
00095     //  mbox->show();
00096     switch(mbox->exec() )
00097     {
00098     case 0:
00099         return -1;
00100     case 1:
00101         return -1;
00102     case 2:
00103         return 0;
00104     case 3:
00105         return 1;
00106     case 4:
00107         return 2;
00108     default: return -1;
00109     }
00110 }
00111 
00112 void printusage()
00113 {
00114     printf("Usage instructions for Opie-sh\n");
00115     printf("Usage: opie-sh [dialog type] [type specific options]\n");
00116     printf("Types:\n");
00117     printf("      -m                 Message Box\n");
00118     printf("      -f [filename]      View file [Default = stdin]\n");
00119     printf("      -i                 Input dialog\n");
00120     printf("      -h --help          These instructions\n");
00121     printf("      -t [title]         The window/dialog title\n");
00122     printf("Message box options:\n");
00123     printf("      -M [message]       The message to display\n");
00124     printf("      -I                 Use information icon\n");
00125     printf("      -w                 Use the warning icon\n");
00126     printf("      -e                 Use the error icon\n");
00127     printf("      -0 [text]          First button text [Default = OK]\n");
00128     printf("      -1 [text]          Second button text\n");
00129     printf("      -2 [text]          Third button text\n");
00130     printf("      -g                 Disable fullscreen\n");
00131     printf("Input Dialog options:\n");
00132     printf("      -s                 A single line of input (output to console)\n");
00133     printf("      -l                 List input (newline separated list read in from file)\n");
00134     printf("      -b                 A list box, enabling multiple selections (input same as -l)\n");
00135     printf("      -p                 Password input (display '*'s)\n");
00136     printf("      -L [label]         The label for the input field\n");
00137     printf("      -F [filename]      An input file (for when it makes sense) [Default = stdin]\n");
00138     printf("      -E                 Makes list input editable\n");
00139     printf("      -g                 Disable fullscreen\n");
00140 }
00141 
00142 int fileviewer(QPEApplication *a, int argc, QStringList args)
00143 {
00144     int i;
00145     QString filename, title, icon;
00146     bool update=false;
00147 
00148     for(i=0; i < argc; i++)
00149     {
00150         if(args[i] == "-f")
00151         {
00152             if(args[i+1][0] != '-')
00153             {
00154                 filename = args[i+1];
00155             }
00156         }
00157 
00158         if(args[i] == "-I")
00159         {
00160             icon=args[i+1];
00161         }
00162 
00163         if(args[i] == "-t")
00164         {
00165             title = args[i+1];
00166         }
00167     }
00168     FViewer *fview = new FViewer(icon, filename, title, 0, (QString) "fileviewer");
00169     a->setMainWidget(fview);
00170     QPEApplication::showWidget( fview );
00171     return a->exec();
00172 }
00173 
00174 int input(int wi, int h, QWidget *w, int argc, QStringList args)
00175 {
00176     int i, type = 0;
00177     QString title, label, filename;
00178     bool edit=false, full=true;
00179 
00180     for(i=0; i < argc; i++)
00181     {
00182         if(args[i] == "-s")
00183         {
00184             type = 0;
00185         }
00186 
00187         if(args[i] == "-l")
00188         {
00189             type = 1;
00190         }
00191 
00192         if(args[i] == "-b")
00193         {
00194             type = 2;
00195         }
00196 
00197         if(args[i] == "-p")
00198         {
00199             type = 3;
00200         }
00201 
00202         if(args[i] == "-t")
00203         {
00204             title = args[i+1];
00205         }
00206 
00207         if(args[i] == "-L")
00208         {
00209             label = args[i+1];
00210         }
00211 
00212         if(args[i] == "-F")
00213         {
00214             if(args[i+1][0] != '-')
00215             {
00216                 filename = args[i+1];
00217             }
00218         }
00219 
00220         if(args[i] =="-E")
00221         {
00222             edit = true;
00223         }
00224 
00225         if(args[i] == "-g")
00226         {
00227             full = false;
00228         }
00229     }
00230     InputDialog *id = new InputDialog(wi, h, type, label, title, filename, edit, w);
00231     if(full)
00232     {
00233         w->setCaption(title);
00234         QPEApplication::showWidget( w );
00235     }
00236     if( id->exec() == 1)
00237     {
00238         printf("%s\n", id->getString().latin1());
00239         return 0;
00240     }
00241     else
00242     {
00243         return -1;
00244     }
00245 }
00246 
00247 int main(int argc, char **argv)
00248 {
00249     int i;
00250     QStringList args;
00251     QPEApplication a(argc, argv);
00252     QWidget w;
00253     a.setMainWidget(&w);
00254     QWidget *d = a.desktop();
00255     int width=d->width();
00256     int height=d->height();
00257 
00258     for(i=0; i < argc; i++)
00259     {
00260         args += argv[i];
00261     }
00262 
00263     for(i=0; i < argc; i++)
00264     {
00265         if(args[i] == "-m")
00266         {
00267             return myMessageBox(width, height, &w, argc, args);
00268         }
00269 
00270         if(args[i] == "-f")
00271         {
00272             return fileviewer(&a, argc, args);
00273         }
00274 
00275         if(args[i] == "-i")
00276         {
00277             return input(width, height, &w, argc, args);
00278         }
00279 
00280         if(args[i] == "-h" || args[i] =="--help")
00281         {
00282             printusage();
00283             return -1;
00284         }
00285     }
00286 
00287     printusage();
00288     return -1;
00289 }
00290 

Generated on Sat Nov 5 16:18:02 2005 for OPIE by  doxygen 1.4.2