xref: /haiku/src/bin/draggers.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 /*
2  * Copyright 2016, François Revol, <revol@free.fr>. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 /*
7  * draggers - show/hide draggers from CLI
8  */
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <Application.h>
14 #include <Dragger.h>
15 
16 
17 int usage(int ret)
18 {
19 	fprintf(stderr, "draggers [show|hide]\n");
20 	fprintf(stderr, "Shows/sets draggers state\n");
21 	return ret;
22 }
23 
24 
25 int main(int argc, char **argv)
26 {
27 	int i;
28 	BApplication app("application/x-vnd.Haiku-draggers");
29 	if (argc < 2) {
30 		printf("%s\n", BDragger::AreDraggersDrawn()?"shown":"hidden");
31 		return EXIT_SUCCESS;
32 	}
33 	for (i = 1; i < argc; i++) {
34 		if (!strncmp(argv[i], "-h", 2)) {
35 			return usage(EXIT_SUCCESS);
36 		}
37 		if (!strcmp(argv[i], "1")
38 		 || !strncmp(argv[i], "en", 2)
39 		 || !strncmp(argv[i], "sh", 2)
40 		 || !strncmp(argv[i], "on", 2))
41 			BDragger::ShowAllDraggers();
42 		else if (!strcmp(argv[i], "0")
43 		 || !strncmp(argv[i], "di", 2)
44 		 || !strncmp(argv[i], "hi", 2)
45 		 || !strncmp(argv[i], "of", 2))
46 			BDragger::HideAllDraggers();
47 		else
48 			return usage(EXIT_FAILURE);
49 	}
50 	return EXIT_SUCCESS;
51 }
52