2 * Copyright 2003-2009, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
12 //! VolumeControl and link items in Deskbar
20 #include <Application.h>
26 #include "DeskButton.h"
27 #include "VolumeWindow.h"
30 const char *kAppSignature
= "application/x-vnd.Haiku-desklink";
31 // the application signature used by the replicant to find the
36 main(int, char **argv
)
38 BApplication
app(kAppSignature
);
39 bool atLeastOnePath
= false;
45 for (int32 i
= 1; argv
[i
]!=NULL
; i
++) {
46 if (strcmp(argv
[i
], "--help") == 0)
49 if (strcmp(argv
[i
], "--list") == 0) {
50 int32 count
= deskbar
.CountItems();
53 printf("Deskbar items:\n");
55 while (found
< count
) {
56 const char *name
= NULL
;
57 if (deskbar
.GetItemInfo(j
, &name
) == B_OK
) {
58 printf("Item %" B_PRId32
": '%s'\n", j
, name
);
67 if (strcmp(argv
[i
], "--add-volume") == 0) {
69 if (get_ref_for_path(argv
[0], &ref
) == B_OK
) {
70 deskbar
.AddItem(&ref
);
75 if (strcmp(argv
[i
], "--volume-control") == 0) {
76 BWindow
* window
= new VolumeWindow(BRect(200, 150, 400, 200));
79 wait_for_thread(window
->Thread(), NULL
);
83 if (strncmp(argv
[i
], "--remove", 8) == 0) {
84 BString replicant
= "DeskButton";
85 if (strncmp(argv
[i
] + 8, "=", 1) == 0) {
86 if (strlen(argv
[i
] + 9) > 0) {
87 replicant
= argv
[i
] + 9;
89 printf("desklink: Missing replicant name.\n");
95 while (deskbar
.GetItemInfo(replicant
.String(), &found_id
) == B_OK
) {
96 err
= deskbar
.RemoveItem(found_id
);
98 printf("desklink: Error removing replicant id "
99 "%" B_PRId32
": %s\n", found_id
, strerror(err
));
104 printf("Removed %" B_PRId32
" items.\n", found
);
108 if (strncmp(argv
[i
], "cmd=", 4) == 0) {
109 BString
*title
= new BString(argv
[i
] + 4);
110 int32 index
= title
->FindFirst(':');
112 printf("desklink: usage: cmd=title:action\n");
114 title
->Truncate(index
);
115 BString
*action
= new BString(argv
[i
] + 4);
116 action
->Remove(0, index
+1);
117 titleList
.AddItem(title
);
118 actionList
.AddItem(action
);
123 atLeastOnePath
= true;
125 BEntry
entry(argv
[i
], true);
128 if (entry
.Exists()) {
130 } else if (BMimeType::IsValid(argv
[i
])) {
131 if (be_roster
->FindApp(argv
[i
], &ref
) != B_OK
) {
132 printf("desklink: cannot find '%s'\n", argv
[i
]);
136 printf("desklink: cannot find '%s'\n", argv
[i
]);
140 err
= deskbar
.AddItem(&ref
);
142 err
= deskbar
.AddItem(new DeskButton(BRect(0, 0, 15, 15),
143 &ref
, ref
.name
, titleList
, actionList
));
145 printf("desklink: Deskbar refuses link to '%s': %s\n", argv
[i
], strerror(err
));
150 titleList
.MakeEmpty();
151 actionList
.MakeEmpty();
154 if (!atLeastOnePath
) {
155 printf( "usage: desklink { [ --list|--remove|[cmd=title:action ... ] [ path|signature ] } ...\n"
156 "--add-volume: install volume control into Deskbar.\n"
157 "--volume-control: show window with global volume control.\n"
158 "--list: list all Deskbar addons.\n"
159 "--remove: remove all desklink addons.\n"
160 "--remove=name: remove all 'name' addons.\n");