1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
3 // Copyright (c) 2001-2003, OpenBeOS
5 // This software is part of the OpenBeOS distribution and is covered
9 // File: installsound.cpp
10 // Author: Jérôme Duval
11 // Description: manages sound events
13 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
17 #include <Application.h>
19 #include <MediaFiles.h>
26 printf("installsound eventname filename\n");
27 printf(" installs a new named sound event in the Sounds preferences panel.\n");
28 printf("installsound --list\n");
29 printf(" lists all sound events.\n");
30 printf("installsound --test eventname\n");
31 printf(" prints the file for the given event name, or nothing and returns error if none.\n");
32 printf("installsound --clear eventname\n");
33 printf(" clears a named event in the Sounds preferences panel.\n");
34 printf("installsound --remove eventname\n");
35 printf(" removes a named event from the Sounds preferences panel.\n");
39 int main(int argc
, const char **argv
)
41 // Make sure we have the minimum number of arguments.
42 if (argc
< 2) usage();
44 BApplication
app("application/x-vnd.be.installsound");
48 if(strcmp(argv
[1], "--list")==0) {
49 mfiles
.RewindRefs(BMediaFiles::B_SOUNDS
);
53 while(mfiles
.GetNextRef(&name
,&ref
) == B_OK
) {
54 printf("%s:\t%s\n", name
.String(),BPath(&ref
).Path());
57 if (argc
!= 3) usage();
59 if(strcmp(argv
[1], "--test")==0) {
61 if(mfiles
.GetRefFor(BMediaFiles::B_SOUNDS
, argv
[2], &ref
) == B_OK
)
62 printf("%s\n", BPath(&ref
).Path());
64 printf("%s: No such sound event\n", argv
[2]);
67 } else if(strcmp(argv
[1], "--clear")==0) {
69 if(mfiles
.GetRefFor(BMediaFiles::B_SOUNDS
, argv
[2], &ref
) == B_OK
)
70 mfiles
.RemoveRefFor(BMediaFiles::B_SOUNDS
, argv
[2], ref
);
72 printf("clear %s: No such sound event\n", argv
[2]);
75 } else if(strcmp(argv
[1], "--remove")==0) {
76 if(mfiles
.RemoveItem(BMediaFiles::B_SOUNDS
, argv
[2]) != B_OK
) {
77 printf("remove %s: No such sound event\n", argv
[2]);
82 if(get_ref_for_path(argv
[2], &ref
)!=B_OK
|| !BEntry(&ref
, true).Exists()) {
83 printf("error: %s not found\n", argv
[2]);
87 mfiles
.SetRefFor(BMediaFiles::B_SOUNDS
, argv
[1], ref
);