2 * Copyright 2011, Joseph "looncraz" Groover, looncraz@satx.rr.com
3 * Copyright 2007, François Revol, revol@free.fr.
4 * Distributed under the terms of the MIT license.
10 #include <Application.h>
12 #include <InterfaceDefs.h>
17 #include <DecorInfo.h>
21 print_decor_info_header()
23 printf(" Name License\t Description\n");
24 printf("----------------------------------------------------\n");
29 print_decor_summary(DecorInfo
* decor
, bool isCurrent
)
34 printf("%-12s\t%-8s %-30s\n", decor
->Name().String(),
35 decor
->LicenseName().String(), decor
->ShortDescription().String());
40 print_decor_shortcut(DecorInfo
* decor
, bool isCurrent
)
45 printf("%-12s\t%-12s\n", decor
->ShortcutName().String(),
46 decor
->Name().String());
51 print_decor_info_verbose(DecorInfo
* decor
, bool isCurrent
)
53 printf("Name:\t\t%s\n", decor
->Name().String());
54 printf("Version:\t%f\n", decor
->Version());
55 printf("Author(s):\t%s\n", decor
->Authors().String());
56 printf("Description:\t%s\n", decor
->ShortDescription().String());
57 printf("License:\t%s (%s)\n", decor
->LicenseName().String(),
58 decor
->LicenseURL().String());
59 printf("Support URL:\t%s\n", decor
->SupportURL().String());
60 printf("%s\n", isCurrent
? "Currently in use." : "Currently not in use.");
65 main(int argc
, char** argv
)
68 printf("usage: %s [-l|-c|decorname]\n", argv
[0]);
69 printf("\t-l: list available decors\n");
70 printf("\t-s: list shortcut names for available decors\n");
71 printf("\t-c: give current decor name\n");
72 printf("\t-i: detailed information about decor\n");
73 printf("\t-p: see preview window\n");
77 // combine remaining args into one string:
78 BString decoratorName
;
79 for (int i
= 2; i
< argc
; ++i
)
80 decoratorName
<< argv
[i
] << " ";
81 decoratorName
.RemoveLast(" ");
83 BApplication
app("application/x-vnd.Haiku-setdecor");
85 DecorInfoUtility
* util
= new DecorInfoUtility();
86 DecorInfo
* decor
= NULL
;
89 fprintf(stderr
, "error instantiating DecoratorInfoUtility (out of"
95 if (!strcmp(argv
[1], "-l")) {
96 // Print default decorator:
97 print_decor_info_header();
98 int32 count
= util
->CountDecorators();
99 for (int32 i
= 0; i
< count
; ++i
) {
100 decor
= util
->DecoratorAt(i
);
102 fprintf(stderr
, "error NULL entry @ %li / %li - BUG BUG BUG\n",
104 // return 2 to track DecorInfoUtility errors
107 print_decor_summary(decor
, util
->IsCurrentDecorator(decor
));
113 // we want the current decorator
114 if (!strcmp(argv
[1], "-c")) {
115 decor
= util
->CurrentDecorator();
118 fprintf(stderr
, "Unable to determine current decorator, sorry! - "
123 print_decor_info_header();
124 print_decor_summary(decor
, true);
129 if (!strcmp(argv
[1], "-s")) {
131 printf(" Shortcut Name\n");
132 printf("------------------------------------\n");
134 int32 count
= util
->CountDecorators();
135 for (int32 i
= 0; i
< count
; ++i
) {
136 decor
= util
->DecoratorAt(i
);
138 fprintf(stderr
, "error NULL entry @ %li / %li - BUG BUG BUG\n",
140 // return 2 to track DecorInfoUtility errors
143 print_decor_shortcut(decor
, util
->IsCurrentDecorator(decor
));
149 // we want detailed information for a specific decorator ( by name or path )
150 if (!strcmp(argv
[1], "-i")) {
152 fprintf(stderr
, "not enough arguments\n");
156 decor
= util
->FindDecorator(decoratorName
.String());
159 fprintf(stderr
, "Can't find decor named \"%s\", try again\n",
160 decoratorName
.String());
164 print_decor_info_verbose(decor
, util
->IsCurrentDecorator(decor
));
169 if (!strcmp(argv
[1], "-p")) {
171 fprintf(stderr
, "not enough arguments\n");
175 decor
= util
->FindDecorator(decoratorName
.String());
178 fprintf(stderr
, "Can't find decor named \"%s\", try again\n",
179 decoratorName
.String());
183 printf("Preparing preview...\n");
185 BWindow
* previewWindow
= new BWindow(BRect(150, 150, 390, 490),
186 decor
->Name().String(), B_TITLED_WINDOW
, B_NOT_ZOOMABLE
187 | B_QUIT_ON_WINDOW_CLOSE
| B_NOT_RESIZABLE
);
189 previewWindow
->AddChild(new BView(previewWindow
->Bounds(), "",
192 if (util
->Preview(decor
, previewWindow
) != B_OK
) {
193 fprintf(stderr
, "Unable to preview decorator, sorry!\n");
194 // TODO: more detailed error...
198 previewWindow
->Show();
204 // we want to change it
206 for (int i
= 1; i
< argc
; ++i
)
207 decoratorName
<< argv
[i
] << " ";
208 decoratorName
.RemoveLast(" ");
210 decor
= util
->FindDecorator(decoratorName
.String());
213 fprintf(stderr
, "no such decorator \"%s\"\n", decoratorName
.String());
217 if (util
->IsCurrentDecorator(decor
)) {
218 printf("\"%s\" is already the current decorator\n",
219 decor
->Name().String());
223 printf("Setting %s as the current decorator...\n", decor
->Name().String());
224 if (util
->SetDecorator(decor
) != B_OK
) {
225 fprintf(stderr
, "Unable to set decorator, sorry\n\n");
226 return 1; // todo more detailed error...