xref: /haiku/src/bin/setdecor.cpp (revision e6b30aee0fd7a23d6a6baab9f3718945a0cd838a)
1 /*
2  * Copyright 2007, François Revol, revol@free.fr.
3  * Distributed under the terms of the MIT license.
4  */
5 
6 
7 #include <stdio.h>
8 
9 #include <Application.h>
10 #include <InterfaceDefs.h>
11 #include <String.h>
12 
13 class BBitmap;
14 
15 namespace BPrivate {
16 int32 count_decorators(void);
17 int32 get_decorator(void);
18 status_t get_decorator_name(const int32 &index, BString &name);
19 status_t get_decorator_preview(const int32 &index, BBitmap *bitmap);
20 status_t set_decorator(const int32 &index);
21 }
22 
23 using namespace BPrivate;
24 
25 int main(int argc, char **argv)
26 {
27 	status_t err;
28 	if (argc < 2) {
29 		printf("usage: %s [-l|-c|decorname]\n", argv[0]);
30 		printf("\t-l: list available decors\n");
31 		printf("\t-c: give current decor name\n");
32 		return 1;
33 	}
34 	BApplication app("application/x-vnd.Haiku-setdecor");
35 	// we want the list
36 	if (!strcmp(argv[1], "-l")) {
37 		int32 i, count;
38 		count = count_decorators();
39 		if (count < 0) {
40 			fprintf(stderr, "error counting decorators: %s\n", strerror(count));
41 			return 1;
42 		}
43 		for (i = 0; i < count; i++) {
44 			BString name;
45 			err = get_decorator_name(i, name);
46 			if (err < 0)
47 				continue;
48 			printf("%s\n", name.String());
49 		}
50 		return 0;
51 	}
52 	// we want the current one
53 	if (!strcmp(argv[1], "-c")) {
54 		int32 i;
55 		BString name;
56 		i = get_decorator();
57 		if (i < 0) {
58 			fprintf(stderr, "error getting current decorator: %s\n", strerror(i));
59 			return 1;
60 		}
61 		err = get_decorator_name(i, name);
62 		if (err < 0) {
63 			fprintf(stderr, "error getting name of decorator: %s\n", strerror(err));
64 			return 1;
65 		}
66 		printf("%s\n", name.String());
67 		return 0;
68 	}
69 	// we want to change it
70 	int32 i, count;
71 	count = count_decorators();
72 	if (count < 0) {
73 		fprintf(stderr, "error counting decorators: %s\n", strerror(count));
74 		return 1;
75 	}
76 	for (i = 0; i < count; i++) {
77 		BString name;
78 		err = get_decorator_name(i, name);
79 		if (err < 0)
80 			continue;
81 		if (name == argv[1]) {
82 			err = set_decorator(i);
83 			if (err < 0) {
84 				fprintf(stderr, "error setting decorator: %s\n", strerror(err));
85 				return 1;
86 			}
87 			return 0;
88 		}
89 	}
90 	fprintf(stderr, "can't find decorator \"%s\"\n", argv[1]);
91 	return 1;
92 }
93 
94