* Better error output in LaunchButton
* Load both the app signature and the entry_ref from the settings in any case, but do not use the entry_ref if the entry does not exist anymore. * Prefer the entry_ref when launch something. This make it much easier to launch a specific executable, especially if multiple copies exist on the harddrive. If launching via ref failed, or no ref is provided in the first place, fall back to launching by signature. * Much improved error output when launching fails, now via BAlert. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24703 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2008, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -247,10 +247,9 @@ LaunchButton::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessa
|
|||||||
void
|
void
|
||||||
LaunchButton::SetTo(const entry_ref* ref)
|
LaunchButton::SetTo(const entry_ref* ref)
|
||||||
{
|
{
|
||||||
if (fAppSig) {
|
free(fAppSig);
|
||||||
free(fAppSig);
|
fAppSig = NULL;
|
||||||
fAppSig = NULL;
|
|
||||||
}
|
|
||||||
delete fRef;
|
delete fRef;
|
||||||
if (ref) {
|
if (ref) {
|
||||||
fRef = new entry_ref(*ref);
|
fRef = new entry_ref(*ref);
|
||||||
@@ -267,10 +266,10 @@ LaunchButton::SetTo(const entry_ref* ref)
|
|||||||
if (info.GetSignature(mimeSig) >= B_OK) {
|
if (info.GetSignature(mimeSig) >= B_OK) {
|
||||||
SetTo(mimeSig, false);
|
SetTo(mimeSig, false);
|
||||||
} else {
|
} else {
|
||||||
printf("no MIME sig\n");
|
fprintf(stderr, "no MIME signature for '%s'\n", fRef->name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("no app\n");
|
fprintf(stderr, "no BAppFileInfo for '%s'\n", fRef->name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fRef = NULL;
|
fRef = NULL;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2008, Haiku.
|
* Copyright 2006-2008, Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -112,30 +112,67 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_LAUNCH: {
|
case MSG_LAUNCH: {
|
||||||
BView* pointer;
|
BView* pointer;
|
||||||
if (message->FindPointer("be:source", (void**)&pointer) >= B_OK) {
|
if (message->FindPointer("be:source", (void**)&pointer) < B_OK)
|
||||||
if (LaunchButton* button
|
break;
|
||||||
= dynamic_cast<LaunchButton*>(pointer)) {
|
LaunchButton* button = dynamic_cast<LaunchButton*>(pointer);
|
||||||
if (button->AppSignature()) {
|
if (button == NULL)
|
||||||
be_roster->Launch(button->AppSignature());
|
break;
|
||||||
} else {
|
BString errorMessage;
|
||||||
BEntry entry(button->Ref(), true);
|
bool launchedByRef = false;
|
||||||
if (entry.IsDirectory()) {
|
if (button->Ref()) {
|
||||||
// open in Tracker
|
BEntry entry(button->Ref(), true);
|
||||||
BMessenger messenger("application/x-vnd.Be-TRAK");
|
if (entry.IsDirectory()) {
|
||||||
if (messenger.IsValid()) {
|
// open in Tracker
|
||||||
BMessage trackerMessage(B_REFS_RECEIVED);
|
BMessenger messenger("application/x-vnd.Be-TRAK");
|
||||||
trackerMessage.AddRef("refs", button->Ref());
|
if (messenger.IsValid()) {
|
||||||
messenger.SendMessage(&trackerMessage);
|
BMessage trackerMessage(B_REFS_RECEIVED);
|
||||||
}
|
trackerMessage.AddRef("refs", button->Ref());
|
||||||
} else {
|
status_t ret = messenger.SendMessage(&trackerMessage);
|
||||||
status_t ret = be_roster->Launch(button->Ref());
|
if (ret < B_OK) {
|
||||||
if (ret < B_OK)
|
errorMessage = "Failed to send 'open folder' "
|
||||||
fprintf(stderr, "launching %s failed: %s\n",
|
"command to Tracker.\n\nError: ";
|
||||||
button->Ref()->name, strerror(ret));
|
errorMessage << strerror(ret);
|
||||||
}
|
} else
|
||||||
}
|
launchedByRef = true;
|
||||||
|
} else
|
||||||
|
errorMessage = "Failed to open folder - is Tracker "
|
||||||
|
"running?";
|
||||||
|
} else {
|
||||||
|
status_t ret = be_roster->Launch(button->Ref());
|
||||||
|
if (ret < B_OK) {
|
||||||
|
errorMessage = "Failed to launch '";
|
||||||
|
BPath path(button->Ref());
|
||||||
|
if (path.InitCheck() >= B_OK)
|
||||||
|
errorMessage << path.Path();
|
||||||
|
else
|
||||||
|
errorMessage << button->Ref()->name;
|
||||||
|
errorMessage << "'.\n\nError: ";
|
||||||
|
errorMessage << strerror(ret);
|
||||||
|
} else
|
||||||
|
launchedByRef = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!launchedByRef && button->AppSignature()) {
|
||||||
|
status_t ret = be_roster->Launch(button->AppSignature());
|
||||||
|
if (ret != B_OK) {
|
||||||
|
errorMessage = "Failed to launch application with "
|
||||||
|
"signature '";
|
||||||
|
errorMessage << button->AppSignature() << "'.\n\nError: ";
|
||||||
|
errorMessage << strerror(ret);
|
||||||
|
} else {
|
||||||
|
// clear error message on success (might have been
|
||||||
|
// filled when trying to launch by ref)
|
||||||
|
errorMessage = "";
|
||||||
|
}
|
||||||
|
} else if (!launchedByRef) {
|
||||||
|
errorMessage = "Failed to launch 'something', error in "
|
||||||
|
"Pad data.";
|
||||||
|
}
|
||||||
|
if (errorMessage.Length() > 0) {
|
||||||
|
BAlert* alert = new BAlert("error", errorMessage.String(),
|
||||||
|
"Bummer", NULL, NULL, B_WIDTH_FROM_WIDEST);
|
||||||
|
alert->Go(NULL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_ADD_SLOT: {
|
case MSG_ADD_SLOT: {
|
||||||
@@ -331,11 +368,13 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||||||
if (message->FindString("signature", i, &signature) >= B_OK
|
if (message->FindString("signature", i, &signature) >= B_OK
|
||||||
&& signature.CountChars() > 0) {
|
&& signature.CountChars() > 0) {
|
||||||
button->SetTo(signature.String(), true);
|
button->SetTo(signature.String(), true);
|
||||||
} else {
|
|
||||||
entry_ref ref;
|
|
||||||
if (get_ref_for_path(path, &ref) >= B_OK)
|
|
||||||
button->SetTo(&ref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entry_ref ref;
|
||||||
|
BEntry entry(&ref, true);
|
||||||
|
if (entry.Exists())
|
||||||
|
button->SetTo(&ref);
|
||||||
|
|
||||||
const char* text;
|
const char* text;
|
||||||
if (message->FindString("description", i, &text) >= B_OK)
|
if (message->FindString("description", i, &text) >= B_OK)
|
||||||
button->SetDescription(text);
|
button->SetDescription(text);
|
||||||
|
|||||||
Reference in New Issue
Block a user