Added error reporting and a "application does not support file type" warning when
trying to set the preferred app via the "Same As..." or "Select..." buttons. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
43fd6fc453
commit
3648c6cea4
@ -128,6 +128,9 @@ class AttributeItem : public BStringItem {
|
||||
bool fEditable;
|
||||
};
|
||||
|
||||
static void error_alert(const char* message, status_t status = B_OK,
|
||||
alert_type type = B_WARNING_ALERT);
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
@ -142,6 +145,20 @@ compare_menu_items(const void* _a, const void* _b)
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
is_application_in_message(BMessage& applications, const char* app)
|
||||
{
|
||||
const char* signature;
|
||||
int32 i = 0;
|
||||
while (applications.FindString("applications", i++, &signature) == B_OK) {
|
||||
if (!strcasecmp(signature, app))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
name_for_type(BString& string, type_code type)
|
||||
{
|
||||
@ -170,6 +187,19 @@ name_for_type(BString& string, type_code type)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
error_alert(const char* message, status_t status, alert_type type)
|
||||
{
|
||||
char warning[512];
|
||||
if (status != B_OK)
|
||||
snprintf(warning, sizeof(warning), "%s:\n\t%s\n", message, strerror(status));
|
||||
|
||||
(new BAlert("FileTypes Request",
|
||||
status == B_OK ? message : warning,
|
||||
"Ok", NULL, NULL, B_WIDTH_AS_USUAL, type))->Go();
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@ -773,20 +803,17 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
|
||||
if (message->FindRef("refs", &ref) != B_OK)
|
||||
return;
|
||||
|
||||
// TODO: add error reporting!
|
||||
|
||||
BFile file(&ref, B_READ_ONLY);
|
||||
if (file.InitCheck() != B_OK)
|
||||
return;
|
||||
status_t status = file.InitCheck();
|
||||
|
||||
char preferred[B_MIME_TYPE_LENGTH];
|
||||
|
||||
if (status == B_OK) {
|
||||
if (sameAs) {
|
||||
// get preferred app from file
|
||||
BNodeInfo nodeInfo(&file);
|
||||
if (nodeInfo.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
status = nodeInfo.InitCheck();
|
||||
if (status == B_OK) {
|
||||
if (nodeInfo.GetPreferredApp(preferred) != B_OK)
|
||||
preferred[0] = '\0';
|
||||
|
||||
@ -798,18 +825,66 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
|
||||
mimeType.GetPreferredApp(preferred);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// get application signature
|
||||
BAppFileInfo appInfo(&file);
|
||||
if (appInfo.InitCheck() != B_OK)
|
||||
return;
|
||||
status = appInfo.InitCheck();
|
||||
|
||||
if (appInfo.GetSignature(preferred) != B_OK)
|
||||
if (status == B_OK && appInfo.GetSignature(preferred) != B_OK)
|
||||
preferred[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (preferred[0])
|
||||
fCurrentType.SetPreferredApp(preferred);
|
||||
if (status != B_OK) {
|
||||
error_alert("File could not be opened", status, B_STOP_ALERT);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preferred[0]) {
|
||||
error_alert(sameAs ? "Could not retrieve preferred application of this file."
|
||||
: "Could not retrieve application signature.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the application chosen supports this type
|
||||
|
||||
bool found = false;
|
||||
|
||||
BMessage applications;
|
||||
if (fCurrentType.GetSupportingApps(&applications) == B_OK
|
||||
&& is_application_in_message(applications, preferred))
|
||||
found = true;
|
||||
|
||||
applications.MakeEmpty();
|
||||
|
||||
if (!found && fCurrentType.GetWildcardApps(&applications) == B_OK
|
||||
&& is_application_in_message(applications, preferred))
|
||||
found = true;
|
||||
|
||||
if (!found) {
|
||||
// warn user
|
||||
BMimeType appType(preferred);
|
||||
char description[B_MIME_TYPE_LENGTH];
|
||||
if (appType.GetShortDescription(description) != B_OK)
|
||||
description[0] = '\0';
|
||||
|
||||
char warning[512];
|
||||
snprintf(warning, sizeof(warning), "The application \"%s\" does not "
|
||||
"support this file type.\n"
|
||||
"Are you sure you want to set it anyway?",
|
||||
description[0] ? description : preferred);
|
||||
|
||||
BAlert* alert = new BAlert("FileTypes Request", warning,
|
||||
"Set Preferred Application", "Cancel", NULL, B_WIDTH_AS_USUAL,
|
||||
B_WARNING_ALERT);
|
||||
if (alert->Go() == 1)
|
||||
return;
|
||||
}
|
||||
|
||||
status = fCurrentType.SetPreferredApp(preferred);
|
||||
if (status != B_OK)
|
||||
error_alert("Could not set preferred application", status);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user