2003-02-25 18:00:40 +00:00
|
|
|
/* Launches an application/document from the shell
|
|
|
|
**
|
|
|
|
** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
|
|
|
** Distributed under the terms of the OpenBeOS License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <InterfaceDefs.h>
|
|
|
|
#include <Roster.h>
|
|
|
|
#include <Entry.h>
|
2004-08-15 16:37:30 +00:00
|
|
|
#include <String.h>
|
2003-02-25 18:00:40 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *progName = argv[0];
|
2004-10-31 12:10:01 +00:00
|
|
|
char *openWith = "application/x-vnd.Be-TRAK";
|
2003-02-25 18:00:40 +00:00
|
|
|
if (strrchr(progName, '/'))
|
|
|
|
progName = strrchr(progName, '/') + 1;
|
|
|
|
|
|
|
|
if (argc < 2)
|
2004-08-15 16:37:30 +00:00
|
|
|
fprintf(stderr,"usage: %s <file or url or application signature> ...\n", progName);
|
2003-02-25 18:00:40 +00:00
|
|
|
|
|
|
|
BRoster roster;
|
|
|
|
|
|
|
|
while (*++argv) {
|
2004-10-31 12:10:01 +00:00
|
|
|
status_t rc = B_OK;
|
|
|
|
argc--;
|
2003-02-25 18:00:40 +00:00
|
|
|
|
|
|
|
BEntry entry(*argv);
|
|
|
|
if ((rc = entry.InitCheck()) == B_OK && entry.Exists()) {
|
|
|
|
entry_ref ref;
|
|
|
|
entry.GetRef(&ref);
|
|
|
|
|
2004-10-31 12:10:01 +00:00
|
|
|
BMessenger target(openWith);
|
|
|
|
if (target.IsValid()) {
|
2003-02-25 18:00:40 +00:00
|
|
|
BMessage message(B_REFS_RECEIVED);
|
|
|
|
message.AddRef("refs", &ref);
|
2004-10-31 12:10:01 +00:00
|
|
|
/* tell the app to open the file */
|
|
|
|
rc = target.SendMessage(&message);
|
2003-02-25 18:00:40 +00:00
|
|
|
} else
|
|
|
|
rc = roster.Launch(&ref);
|
|
|
|
} else if (!strncasecmp("application/", *argv, 12)) {
|
|
|
|
// maybe it's an application-mimetype?
|
2004-10-31 12:10:01 +00:00
|
|
|
|
|
|
|
// subsequent files are open with that app
|
|
|
|
openWith = *argv;
|
|
|
|
|
|
|
|
// in the case the app is already started,
|
|
|
|
// don't start it twice if we have other args
|
|
|
|
BList teams;
|
|
|
|
if (argc > 1) {
|
|
|
|
roster.GetAppList(*argv, &teams);
|
|
|
|
}
|
|
|
|
if (teams.IsEmpty())
|
|
|
|
rc = roster.Launch(*argv);
|
2004-10-28 22:29:12 +00:00
|
|
|
} else if (strstr(*argv, ":")) {
|
2004-08-15 16:37:30 +00:00
|
|
|
BString mimetype = "application/x-vnd.Be.URL.";
|
|
|
|
BString arg(*argv);
|
2004-10-28 22:29:12 +00:00
|
|
|
if (strstr(*argv, "://"))
|
|
|
|
mimetype.Append(arg, arg.FindFirst("://"));
|
|
|
|
else
|
|
|
|
mimetype.Append(arg, arg.FindFirst(":"));
|
2004-08-15 16:37:30 +00:00
|
|
|
char *args[2] = { *argv, NULL };
|
|
|
|
rc = roster.Launch(mimetype.String(), 1, args);
|
|
|
|
if (rc == B_ALREADY_RUNNING)
|
|
|
|
rc = B_OK;
|
2003-02-25 18:00:40 +00:00
|
|
|
} else if (rc == B_OK)
|
|
|
|
rc = B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
if (rc != B_OK)
|
|
|
|
fprintf(stderr, "%s: \"%s\": %s\n", progName, *argv, strerror(rc));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|