Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / Tests / wmfile.c
1 /*
2  * Author: Len Trigg <trigg@cs.waikato.ac.nz>
3  */
4
5 /*
6  Update: Franck Wolff <frawolff@club-internet.fr>
7  -----------------------------------------------------------------------
8  List of updated functions :
9  - main :
10  add -s option for a save panel...
11  -----------------------------------------------------------------------
12  */
13
14 #include <WINGs/WINGs.h>
15
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 #include "logo.xpm"
21
22 void wAbort()
23 {
24         exit(1);
25 }
26
27 char *ProgName;
28
29 void usage(void)
30 {
31         fprintf(stderr,
32                 "usage:\n"
33                 "\t%s [-options]\n"
34                 "\n"
35                 "options:\n"
36                 "  -s\t\tSave panel (default open panel)\n"
37                 "  -i <str>\tInitial directory (default /)\n"
38                 "  -t <str>\tQuery window title (default none)\n"
39                 "\n"
40                 "information:\n"
41                 "\t%s pops up a WindowMaker style file selection panel.\n"
42                 "\n" "version:\n" "\t%s\n", ProgName, ProgName, __DATE__);
43         exit(0);
44 }
45
46 #define OPEN_PANEL_TYPE 0
47 #define SAVE_PANEL_TYPE 1
48
49 int main(int argc, char **argv)
50 {
51         Display *dpy = XOpenDisplay("");
52         WMScreen *scr;
53         WMPixmap *pixmap;
54         WMOpenPanel *oPanel;
55         WMSavePanel *sPanel;
56         /*  RImage *image; */
57         char *title = NULL;
58         char *initial = "/";
59         int ch;
60         int panelType = OPEN_PANEL_TYPE;
61         extern char *optarg;
62         extern int optind;
63
64         if (!dpy) {
65                 puts("could not open display");
66                 exit(1);
67         }
68
69         WMInitializeApplication("WMFile", &argc, argv);
70
71         ProgName = argv[0];
72
73         while ((ch = getopt(argc, argv, "si:ht:")) != -1)
74                 switch (ch) {
75                 case 's':
76                         panelType = SAVE_PANEL_TYPE;
77                         break;
78                 case 'i':
79                         initial = optarg;
80                         break;
81                 case 't':
82                         title = optarg;
83                         break;
84                 default:
85                         usage();
86                 }
87
88         for (; optind < argc; optind++)
89                 usage();
90
91         scr = WMCreateSimpleApplicationScreen(dpy);
92
93         pixmap = WMCreatePixmapFromXPMData(scr, GNUSTEP_XPM);
94         WMSetApplicationIconPixmap(scr, pixmap);
95         WMReleasePixmap(pixmap);
96         if (panelType == SAVE_PANEL_TYPE) {
97                 sPanel = WMGetSavePanel(scr);
98                 if (WMRunModalFilePanelForDirectory(sPanel, NULL, initial,
99                                                     /*title */ NULL, NULL) == True)
100                         printf("%s\n", WMGetFilePanelFileName(sPanel));
101                 else
102                         printf("\n");
103         } else {
104                 oPanel = WMGetOpenPanel(scr);
105                 if (WMRunModalFilePanelForDirectory(oPanel, NULL, initial,
106                                                     /*title */ NULL, NULL) == True)
107                         printf("%s\n", WMGetFilePanelFileName(oPanel));
108                 else
109                         printf("\n");
110         }
111         return 0;
112 }