BUrl: Add missing functionality from support kit BUrl
This commit is contained in:
parent
2573655b79
commit
72f6b787cf
|
@ -71,6 +71,12 @@ public:
|
||||||
static BString UrlDecode(const BString& url,
|
static BString UrlDecode(const BString& url,
|
||||||
bool strict = false);
|
bool strict = false);
|
||||||
|
|
||||||
|
// utility functionality
|
||||||
|
bool HasPreferredApplication() const;
|
||||||
|
BString PreferredApplication() const;
|
||||||
|
status_t OpenWithPreferredApplication(
|
||||||
|
bool onProblemAskUser = true) const;
|
||||||
|
|
||||||
// BArchivable members
|
// BArchivable members
|
||||||
virtual status_t Archive(BMessage* into,
|
virtual status_t Archive(BMessage* into,
|
||||||
bool deep = true) const;
|
bool deep = true) const;
|
||||||
|
@ -104,6 +110,8 @@ private:
|
||||||
static bool _IsGenDelim(char c);
|
static bool _IsGenDelim(char c);
|
||||||
static bool _IsSubDelim(char c);
|
static bool _IsSubDelim(char c);
|
||||||
|
|
||||||
|
BString _UrlMimeType() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable BString fUrlString;
|
mutable BString fUrlString;
|
||||||
mutable BString fAuthority;
|
mutable BString fAuthority;
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
#include <MimeType.h>
|
||||||
|
#include <Roster.h>
|
||||||
|
|
||||||
#include <RegExp.h>
|
#include <RegExp.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -573,6 +576,76 @@ BUrl::UrlDecode(bool strict)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - utility functionality
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BUrl::HasPreferredApplication() const
|
||||||
|
{
|
||||||
|
BString appSignature = PreferredApplication();
|
||||||
|
BMimeType mime(appSignature.String());
|
||||||
|
|
||||||
|
if (appSignature.IFindFirst("application/") == 0
|
||||||
|
&& mime.IsValid())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
BUrl::PreferredApplication() const
|
||||||
|
{
|
||||||
|
BString appSignature;
|
||||||
|
BMimeType mime(_UrlMimeType().String());
|
||||||
|
mime.GetPreferredApp(appSignature.LockBuffer(B_MIME_TYPE_LENGTH));
|
||||||
|
appSignature.UnlockBuffer();
|
||||||
|
|
||||||
|
return BString(appSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BUrl::OpenWithPreferredApplication(bool onProblemAskUser) const
|
||||||
|
{
|
||||||
|
if (!IsValid())
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
BString urlString = UrlString();
|
||||||
|
if (urlString.Length() > B_PATH_NAME_LENGTH) {
|
||||||
|
// TODO: BAlert
|
||||||
|
// if (onProblemAskUser)
|
||||||
|
// BAlert ... Too long URL!
|
||||||
|
#if DEBUG
|
||||||
|
fprintf(stderr, "URL too long");
|
||||||
|
#endif
|
||||||
|
return B_NAME_TOO_LONG;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* argv[] = {
|
||||||
|
const_cast<char*>("BUrlInvokedApplication"),
|
||||||
|
const_cast<char*>(urlString.String()),
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
if (HasPreferredApplication())
|
||||||
|
printf("HasPreferredApplication() == true\n");
|
||||||
|
else
|
||||||
|
printf("HasPreferredApplication() == false\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
status_t status = be_roster->Launch(_UrlMimeType().String(), 1, argv+1);
|
||||||
|
if (status != B_OK) {
|
||||||
|
#if DEBUG
|
||||||
|
fprintf(stderr, "Opening URL failed: %s\n", strerror(status));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Url encoding/decoding of string
|
// #pragma mark Url encoding/decoding of string
|
||||||
|
|
||||||
|
|
||||||
|
@ -982,3 +1055,13 @@ BUrl::_IsSubDelim(char c)
|
||||||
|| c == ')' || c == '*' || c == '+' || c == ',' || c == ';'
|
|| c == ')' || c == '*' || c == '+' || c == ',' || c == ';'
|
||||||
|| c == '=';
|
|| c == '=';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
BUrl::_UrlMimeType() const
|
||||||
|
{
|
||||||
|
BString mime;
|
||||||
|
mime << "application/x-vnd.Be.URL." << fProtocol;
|
||||||
|
|
||||||
|
return BString(mime);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue