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:
@@ -128,6 +128,9 @@ class AttributeItem : public BStringItem {
|
|||||||
bool fEditable;
|
bool fEditable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void error_alert(const char* message, status_t status = B_OK,
|
||||||
|
alert_type type = B_WARNING_ALERT);
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #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
|
static void
|
||||||
name_for_type(BString& string, type_code type)
|
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 -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -773,43 +803,88 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs)
|
|||||||
if (message->FindRef("refs", &ref) != B_OK)
|
if (message->FindRef("refs", &ref) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: add error reporting!
|
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
if (file.InitCheck() != B_OK)
|
status_t status = file.InitCheck();
|
||||||
return;
|
|
||||||
|
|
||||||
char preferred[B_MIME_TYPE_LENGTH];
|
char preferred[B_MIME_TYPE_LENGTH];
|
||||||
|
|
||||||
if (sameAs) {
|
if (status == B_OK) {
|
||||||
// get preferred app from file
|
if (sameAs) {
|
||||||
BNodeInfo nodeInfo(&file);
|
// get preferred app from file
|
||||||
if (nodeInfo.InitCheck() != B_OK)
|
BNodeInfo nodeInfo(&file);
|
||||||
return;
|
status = nodeInfo.InitCheck();
|
||||||
|
if (status == B_OK) {
|
||||||
if (nodeInfo.GetPreferredApp(preferred) != B_OK)
|
if (nodeInfo.GetPreferredApp(preferred) != B_OK)
|
||||||
preferred[0] = '\0';
|
preferred[0] = '\0';
|
||||||
|
|
||||||
if (!preferred[0]) {
|
if (!preferred[0]) {
|
||||||
// get MIME type from file
|
// get MIME type from file
|
||||||
char type[B_MIME_TYPE_LENGTH];
|
char type[B_MIME_TYPE_LENGTH];
|
||||||
if (nodeInfo.GetType(type) == B_OK) {
|
if (nodeInfo.GetType(type) == B_OK) {
|
||||||
BMimeType mimeType(type);
|
BMimeType mimeType(type);
|
||||||
mimeType.GetPreferredApp(preferred);
|
mimeType.GetPreferredApp(preferred);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
// get application signature
|
||||||
// get application signature
|
BAppFileInfo appInfo(&file);
|
||||||
BAppFileInfo appInfo(&file);
|
status = appInfo.InitCheck();
|
||||||
if (appInfo.InitCheck() != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (appInfo.GetSignature(preferred) != B_OK)
|
if (status == B_OK && appInfo.GetSignature(preferred) != B_OK)
|
||||||
preferred[0] = '\0';
|
preferred[0] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preferred[0])
|
if (status != B_OK) {
|
||||||
fCurrentType.SetPreferredApp(preferred);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user