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