+ Added fMimeDatabase member

Implemented:
+ {Get,Set}{Long,Short}Description()
+ {Start,Stop}Watching()
+ Install(), Delete(), IsInstalled()


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@788 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-08-16 22:06:51 +00:00
parent fc7d3358e6
commit f231d0901c
2 changed files with 147 additions and 21 deletions
+5 -1
View File
@@ -22,6 +22,10 @@ class BResources;
class BAppFileInfo; class BAppFileInfo;
class BMessenger; class BMessenger;
namespace BPrivate {
class MimeDatabase;
}
enum app_verb { enum app_verb {
B_OPEN B_OPEN
}; };
@@ -182,7 +186,7 @@ private:
char *fType; char *fType;
BFile *fMeta; BFile *fMeta;
char *fMimePath; // Was: "void *_unused;" BPrivate::MimeDatabase *fMimeDatabase; // Was: "void *_unused;"
entry_ref fRef; entry_ref fRef;
int fWhere; int fWhere;
status_t fCStatus; status_t fCStatus;
+132 -10
View File
@@ -11,6 +11,9 @@
#include <new.h> // For new(nothrow) #include <new.h> // For new(nothrow)
#include <stdio.h> // For printf() #include <stdio.h> // For printf()
#include <string.h> // For strncpy() #include <string.h> // For strncpy()
#include <MimeDatabase.h>
#include <RegistrarDefs.h>
#include <Roster.h> // For _send_to_roster_()
#include <sniffer/Rule.h> #include <sniffer/Rule.h>
#include <sniffer/Parser.h> #include <sniffer/Parser.h>
@@ -39,6 +42,7 @@ const char *B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE;
BMimeType::BMimeType() BMimeType::BMimeType()
: fType(NULL) : fType(NULL)
, fCStatus(B_NO_INIT) , fCStatus(B_NO_INIT)
, fMimeDatabase(new(nothrow) BPrivate::MimeDatabase())
{ {
} }
@@ -52,6 +56,7 @@ BMimeType::BMimeType()
BMimeType::BMimeType(const char *mimeType) BMimeType::BMimeType(const char *mimeType)
: fType(NULL) : fType(NULL)
, fCStatus(B_NO_INIT) , fCStatus(B_NO_INIT)
, fMimeDatabase(new(nothrow) BPrivate::MimeDatabase())
{ {
SetTo(mimeType); SetTo(mimeType);
} }
@@ -62,6 +67,7 @@ BMimeType::BMimeType(const char *mimeType)
BMimeType::~BMimeType() BMimeType::~BMimeType()
{ {
Unset(); Unset();
delete fMimeDatabase;
} }
// SetTo // SetTo
@@ -91,6 +97,8 @@ BMimeType::SetTo(const char *mimeType)
{ {
if (!mimeType || !BMimeType::IsValid(mimeType)) { if (!mimeType || !BMimeType::IsValid(mimeType)) {
fCStatus = B_BAD_VALUE; fCStatus = B_BAD_VALUE;
} else if (!fMimeDatabase) {
fCStatus = B_NO_MEMORY;
} else { } else {
Unset(); Unset();
fType = new(nothrow) char[strlen(mimeType)+1]; fType = new(nothrow) char[strlen(mimeType)+1];
@@ -184,7 +192,7 @@ BMimeType::IsSupertypeOnly() const
bool bool
BMimeType::IsInstalled() const BMimeType::IsInstalled() const
{ {
return false; // not implemented return InitCheck() == B_OK && fMimeDatabase->IsInstalled(Type());
} }
// GetSupertype // GetSupertype
@@ -304,7 +312,24 @@ BMimeType::Contains(const BMimeType *type) const
status_t status_t
BMimeType::Install() BMimeType::Install()
{ {
return NOT_IMPLEMENTED; status_t err = InitCheck();
BMessage msg(B_REG_MIME_INSTALL);
BMessage reply;
status_t result;
// Build and send the message, read the reply
if (!err)
err = msg.AddString("type", Type());
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// Delete // Delete
@@ -323,7 +348,24 @@ BMimeType::Install()
status_t status_t
BMimeType::Delete() BMimeType::Delete()
{ {
return NOT_IMPLEMENTED; status_t err = InitCheck();
BMessage msg(B_REG_MIME_DELETE);
BMessage reply;
status_t result;
// Build and send the message, read the reply
if (!err)
err = msg.AddString("type", Type());
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// GetIcon // GetIcon
@@ -480,7 +522,7 @@ BMimeType::GetFileExtensions(BMessage *extensions) const
status_t status_t
BMimeType::GetShortDescription(char *description) const BMimeType::GetShortDescription(char *description) const
{ {
return NOT_IMPLEMENTED; return fMimeDatabase->GetShortDescription(Type(), description);
} }
// GetLongDescription // GetLongDescription
@@ -499,7 +541,7 @@ BMimeType::GetShortDescription(char *description) const
status_t status_t
BMimeType::GetLongDescription(char *description) const BMimeType::GetLongDescription(char *description) const
{ {
return NOT_IMPLEMENTED; return fMimeDatabase->GetLongDescription(Type(), description);
} }
// GetSupportingApps // GetSupportingApps
@@ -718,7 +760,32 @@ BMimeType::SetFileExtensions(const BMessage *extensions)
status_t status_t
BMimeType::SetShortDescription(const char *description) BMimeType::SetShortDescription(const char *description)
{ {
return NOT_IMPLEMENTED; status_t err = description ? B_OK : B_BAD_VALUE;
if (!err)
err = InitCheck();
BMessage msg(B_REG_MIME_SET_PARAM);
BMessage reply;
status_t result;
// Build and send the message, read the reply
if (!err)
err = msg.AddInt32("which", B_REG_MIME_DESCRIPTION);
if (!err)
err = msg.AddString("description", description);
if (!err)
err = msg.AddBool("long", false);
if (!err)
err = msg.AddString("type", Type());
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// SetLongDescription // SetLongDescription
@@ -737,7 +804,32 @@ BMimeType::SetShortDescription(const char *description)
status_t status_t
BMimeType::SetLongDescription(const char *description) BMimeType::SetLongDescription(const char *description)
{ {
return NOT_IMPLEMENTED; status_t err = description ? B_OK : B_BAD_VALUE;
if (!err)
err = InitCheck();
BMessage msg(B_REG_MIME_SET_PARAM);
BMessage reply;
status_t result;
// Build and send the message, read the reply
if (!err)
err = msg.AddInt32("which", B_REG_MIME_DESCRIPTION);
if (!err)
err = msg.AddString("description", description);
if (!err)
err = msg.AddBool("long", true);
if (!err)
err = msg.AddString("type", Type());
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// GetInstalledSupertypes // GetInstalledSupertypes
@@ -1178,7 +1270,7 @@ BMimeType::GuessMimeType(const char *filename, BMimeType *result)
// StartWatching // StartWatching
/*! \brief Starts monitoring the MIME database for a given target. /*! \brief Starts monitoring the MIME database for a given target.
Until StopWatching() is called for the target, an update message is sent Until StopWatching() is called for the target, an update message is sent
to it, whenever the MIME database changes. to it whenever the MIME database changes.
\param target A BMessenger identifying the target for the update messages. \param target A BMessenger identifying the target for the update messages.
\return \return
- \c B_OK: Everything went fine. - \c B_OK: Everything went fine.
@@ -1187,7 +1279,22 @@ BMimeType::GuessMimeType(const char *filename, BMimeType *result)
status_t status_t
BMimeType::StartWatching(BMessenger target) BMimeType::StartWatching(BMessenger target)
{ {
return NOT_IMPLEMENTED; BMessage msg(B_REG_MIME_START_WATCHING);
BMessage reply;
status_t result;
status_t err;
// Build and send the message, read the reply
err = msg.AddMessenger("target", target);
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// StopWatching // StopWatching
@@ -1201,7 +1308,22 @@ BMimeType::StartWatching(BMessenger target)
status_t status_t
BMimeType::StopWatching(BMessenger target) BMimeType::StopWatching(BMessenger target)
{ {
return NOT_IMPLEMENTED; BMessage msg(B_REG_MIME_STOP_WATCHING);
BMessage reply;
status_t result;
status_t err;
// Build and send the message, read the reply
err = msg.AddMessenger("target", target);
if (!err)
err = _send_to_roster_(&msg, &reply, true);
if (!err)
err = reply.what == B_SIMPLE_DATA ? B_OK : B_BAD_VALUE;
if (!err)
err = reply.FindInt32("result", &result);
if (!err)
err = result;
return err;
} }
// SetType // SetType