btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / bin / installsound.cpp
blobde013571a519a7ac67c3f2d8ae0d3343b0588e1d
1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2 //
3 // Copyright (c) 2001-2003, OpenBeOS
4 //
5 // This software is part of the OpenBeOS distribution and is covered
6 // by the MIT License.
7 //
8 //
9 // File: installsound.cpp
10 // Author: Jérôme Duval
11 // Description: manages sound events
13 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <Application.h>
18 #include <Entry.h>
19 #include <MediaFiles.h>
20 #include <Path.h>
21 #include <String.h>
23 void
24 usage(void)
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");
36 exit(1);
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");
46 BMediaFiles mfiles;
48 if(strcmp(argv[1], "--list")==0) {
49 mfiles.RewindRefs(BMediaFiles::B_SOUNDS);
51 BString name;
52 entry_ref ref;
53 while(mfiles.GetNextRef(&name,&ref) == B_OK) {
54 printf("%s:\t%s\n", name.String(),BPath(&ref).Path());
56 } else {
57 if (argc != 3) usage();
59 if(strcmp(argv[1], "--test")==0) {
60 entry_ref ref;
61 if(mfiles.GetRefFor(BMediaFiles::B_SOUNDS, argv[2], &ref) == B_OK)
62 printf("%s\n", BPath(&ref).Path());
63 else {
64 printf("%s: No such sound event\n", argv[2]);
65 exit(1);
67 } else if(strcmp(argv[1], "--clear")==0) {
68 entry_ref ref;
69 if(mfiles.GetRefFor(BMediaFiles::B_SOUNDS, argv[2], &ref) == B_OK)
70 mfiles.RemoveRefFor(BMediaFiles::B_SOUNDS, argv[2], ref);
71 else {
72 printf("clear %s: No such sound event\n", argv[2]);
73 exit(1);
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]);
78 exit(1);
80 } else {
81 entry_ref ref;
82 if(get_ref_for_path(argv[2], &ref)!=B_OK || !BEntry(&ref, true).Exists()) {
83 printf("error: %s not found\n", argv[2]);
84 exit(1);
87 mfiles.SetRefFor(BMediaFiles::B_SOUNDS, argv[1], ref);
91 exit(0);