Version bump.
[xtoys] / xshutdown.c
1 /* -*-c-*-
2 *
3 * $Id: xshutdown.c,v 1.7 1999/08/20 07:29:19 mdw Exp $
4 *
5 * Pretty GTK interface to waking up an xwait
6 *
7 * (c) 1998 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the Edgeware X tools collection.
13 *
14 * X tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * X tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with X tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: xshutdown.c,v $
32 * Revision 1.7 1999/08/20 07:29:19 mdw
33 * New command line syntax, and new atom protocol.
34 *
35 * Revision 1.6 1998/12/11 09:51:51 mdw
36 * Use mgLib's `msg' box rather than doing things the hard way.
37 *
38 * Revision 1.5 1998/12/03 01:00:19 mdw
39 * Honour escape presses in the dialogue boxes.
40 *
41 * Revision 1.4 1998/12/03 00:39:45 mdw
42 * Force focus when starting up.
43 *
44 * Revision 1.3 1998/11/30 22:36:49 mdw
45 * Tidy up tabbing in help texts very slightly.
46 *
47 * Revision 1.2 1998/11/21 22:30:23 mdw
48 * Support GNU-style long options throughout, and introduce proper help
49 * text to all programs. Update manual pages to match.
50 *
51 * Revision 1.1 1998/11/16 23:00:49 mdw
52 * Initial versions.
53 *
54 */
55
56 /*----- Header files ------------------------------------------------------*/
57
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
61
62 #include <X11/Xlib.h>
63 #include <X11/Xutil.h>
64
65 #include <gtk/gtk.h>
66 #include <gdk/gdkprivate.h>
67 #include <gdk/gdkkeysyms.h>
68
69 #include <mLib/mdwopt.h>
70 #include <mLib/quis.h>
71 #include <mLib/report.h>
72
73 #include <mgLib/msg.h>
74
75 #include "xatom.h"
76 #include "xwait.h"
77
78 /*----- Main code ---------------------------------------------------------*/
79
80 /* --- @version@ --- */
81
82 static void version(FILE *fp)
83 {
84 fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS);
85 }
86
87 /* --- @usage@ --- */
88
89 static void usage(FILE *fp)
90 {
91 fprintf(fp, "Usage: %s [-p PROMPT] [-t TITLE] [ATOM:MSG]\n", QUIS);
92 }
93
94 /* --- @main@ --- *
95 *
96 * Main program.
97 */
98
99 int main(int argc, char *argv[])
100 {
101 char *atom = XWAIT_DIE;
102 char *xmsg = XWAIT_DIE_MSG;
103 Atom xa, xm;
104
105 char *prompt = "Are you sure you want to shut down this session?";
106 char *title = "xshutdown";
107 ego(argv[0]);
108 gtk_init(&argc, &argv);
109
110 /* --- Parse options --- */
111
112 for (;;) {
113 static struct option opt[] = {
114 { "help", 0, 0, 'h' },
115 { "usage", 0, 0, 'u' },
116 { "version", 0, 0, 'v' },
117 { "atom", OPTF_ARGREQ, 0, 'a' },
118 { "msg", OPTF_ARGREQ, 0, 'm' },
119 { "prompt", OPTF_ARGREQ, 0, 'p' },
120 { "title", OPTF_ARGREQ, 0, 't' },
121 { 0, 0, 0, 0 }
122 };
123 int i;
124
125 i = getopt_long(argc, argv, "huv a:m:p:t:", opt, 0);
126
127 if (i < 0)
128 break;
129
130 switch (i) {
131 case 'h':
132 version(stdout);
133 fputs("\n", stdout);
134 usage(stdout);
135 fputs(
136 "\n"
137 "Kills a waiting `xwait' process. Pops up a confirmation window first.\n"
138 "\n"
139 "Options available are:\n"
140 "\n"
141 "-h, --help Display this help text\n"
142 "-u, --usage Display a short usage summary\n"
143 "-v, --version Display the program's version number\n"
144 "\n"
145 "-a, --atom=ATOM\t Select the property name atom [deprecated]\n"
146 "-m, --msg=MSG Select the message to send [deprecated]\n"
147 "-p, --prompt=PROMPT Select the prompt string in the confirmation box\n"
148 "-t, --title=TITLE Select the title string in the confirmation box\n",
149 stdout);
150 exit(0);
151 break;
152 case 'u':
153 usage(stdout);
154 exit(0);
155 break;
156 case 'v':
157 version(stdout);
158 exit(0);
159 break;
160
161 case 'a':
162 atom = optarg;
163 break;
164 case 'm':
165 xmsg = optarg;
166 break;
167 case 'p':
168 prompt = optarg;
169 break;
170 case 't':
171 title = optarg;
172 break;
173 default:
174 usage(stderr);
175 exit(EXIT_FAILURE);
176 }
177 }
178
179 if (optind < argc) {
180 char *p;
181 if ((atom = strtok(argv[optind++], ":")) == 0)
182 die(EXIT_FAILURE, "missing atom name");
183 if ((p = strtok(0, ",")) != 0)
184 xmsg = p;
185 }
186
187 if (optind < argc) {
188 usage(stderr);
189 exit(EXIT_FAILURE);
190 }
191
192 xa = XInternAtom(gdk_display, atom, False);
193 xm = XInternAtom(gdk_display, xmsg, False);
194
195 /* --- Decide whether there's an xwait listening --- *
196 *
197 * If not, pop up an error box and quit.
198 */
199
200 if (xatom_get(gdk_display, DefaultRootWindow(gdk_display), xa) == None) {
201 msg("!:~OK", "no xwait listening for `%s'", atom);
202 exit(EXIT_FAILURE);
203 }
204
205 /* --- Main code --- */
206
207 if (msg("!:OK,~Cancel", "%s", prompt) == 0)
208 xatom_set(gdk_display, DefaultRootWindow(gdk_display), xa, xm);
209
210 return (0);
211 }
212
213 /*----- That's all, folks -------------------------------------------------*/