NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
{
	LOG(("-- nsOSHelperAppService::ExternalProtocolHandlerExists for '%s'\n",
	     aProtocolScheme));
	// look up the protocol scheme in the MIME database
	*aHandlerExists = PR_FALSE;
	if (aProtocolScheme && *aProtocolScheme)
	{
		BString protoStr(aProtocolScheme);
		protoStr.Prepend("application/x-vnd.Be.URL.");
		BMimeType protocol;
		if (protocol.SetTo(protoStr.String()) == B_OK)
		{
			if (protocol.IsInstalled())
				*aHandlerExists = PR_TRUE;
		}
		if ((!*aHandlerExists) && (!strcmp("mailto", aProtocolScheme)))
		{
			// mailto link, no x-vnd.Be.URL.mailto entry
			if (protocol.SetTo("text/x-email") == B_OK)
			{
				if (protocol.IsInstalled())
					*aHandlerExists = PR_TRUE;
			}
		}
	}

	return NS_OK;
}
nsresult nsOSHelperAppService::LoadUriInternal(nsIURI * aURL)
{
	LOG(("-- nsOSHelperAppService::LoadUrl\n"));
	nsresult rv = NS_OK;

	if (aURL) {
		// Get the Protocol
		nsCAutoString scheme;
		aURL->GetScheme(scheme);
		BString protoStr(scheme.get());
		protoStr.Prepend("application/x-vnd.Be.URL.");
		// Get the Spec
		nsCAutoString spec;
		aURL->GetSpec(spec);
		const char* args[] = { spec.get() };
		
		//Launch the app		
		BMimeType protocol;
		bool isInstalled = false;
		if (protocol.SetTo(protoStr.String()) == B_OK)
		{
			if(protocol.IsInstalled())
			{
				isInstalled = true;	
				be_roster->Launch(protoStr.String(), NS_ARRAY_LENGTH(args), (char **)args);
			}
		}
		if ((!isInstalled) && (!strcmp("mailto", scheme.get())))
			be_roster->Launch("text/x-email", NS_ARRAY_LENGTH(args), (char **)args);
	}
	return rv;
}
Example #3
0
/*!	\brief Sets the MIME types supported by the application.

	If \a types is \c NULL the application's supported types are unset.

	The supported MIME types must be stored in a field "types" of type
	\c B_STRING_TYPE in \a types.

	The method informs the registrar about this news.
	For each supported type the result of BMimeType::GetSupportingApps() will
	afterwards include the signature of this application. That is, the
	application file needs to have a signature set.

	\a syncAll specifies whether the not longer supported types shall be
	updated as well, i.e. whether this application shall be remove from the
	lists of supporting applications.

	\param types The supported types to be assigned to the file.
		   May be \c NULL.
	\param syncAll \c true to also synchronize the not longer supported
		   types, \c false otherwise.
	\return
	- \c B_OK: Everything went fine.
	- \c B_NO_INIT: The object is not properly initialized.
	- other error codes
*/
status_t
BAppFileInfo::SetSupportedTypes(const BMessage *types, bool syncAll)
{
	// check initialization
	status_t error = B_OK;
	if (error == B_OK && InitCheck() != B_OK)
		error = B_NO_INIT;
	BMimeType mimeType;
	if (error == B_OK)
		error = GetMetaMime(&mimeType);
	if (error == B_OK || error == B_ENTRY_NOT_FOUND) {
		error = B_OK;
		if (types) {
			// check param -- supported types must be valid
			const char *type;
			for (int32 i = 0;
				 error == B_OK && types->FindString("types", i, &type) == B_OK;
				 i++) {
				if (!BMimeType::IsValid(type))
					error = B_BAD_VALUE;
			}
			// get flattened size
			ssize_t size = 0;
			if (error == B_OK) {
				size = types->FlattenedSize();
				if (size < 0)
					error = size;
			}
			// allocate a buffer for the flattened data
			char *buffer = NULL;
			if (error == B_OK) {
				buffer = new(nothrow) char[size];
				if (!buffer)
					error = B_NO_MEMORY;
			}
			// flatten the message
			if (error == B_OK)
				error = types->Flatten(buffer, size);
			// write the data
			if (error == B_OK) {
				error = _WriteData(kSupportedTypesAttribute,
								   kSupportedTypesResourceID, B_MESSAGE_TYPE,
								   buffer, size);
			}
			// clean up
			delete[] buffer;
		} else
			error = _RemoveData(kSupportedTypesAttribute, B_MESSAGE_TYPE);
		// update the MIME database, if the app signature is installed
		if (error == B_OK && mimeType.IsInstalled())
			error = mimeType.SetSupportedTypes(types, syncAll);
	}
	return error;
}
Example #4
0
		void checkMimeTypes()
		{
			BMimeType mime;
			mime.SetTo("application/x-vnd.BeServed-fileserver");
			mime.Delete();
			if (!mime.IsInstalled())
			{
				mime.Install();
				mime.SetShortDescription("Network File Server");
				mime.SetLongDescription("A network server running BeServed");
				setMimeIcon(&mime, MYNET_ICON_HOST_LARGE, B_LARGE_ICON);
				setMimeIcon(&mime, MYNET_ICON_HOST_SMALL, B_MINI_ICON);
			}

			mime.SetTo("application/x-vnd.BeServed-inetserver");
			mime.Delete();
			if (!mime.IsInstalled())
			{
				mime.Install();
				mime.SetShortDescription("Public File Server");
				mime.SetLongDescription("A remote network server running BeServed");
				setMimeIcon(&mime, MYNET_ICON_INETHOST_LARGE, B_LARGE_ICON);
				setMimeIcon(&mime, MYNET_ICON_INETHOST_SMALL, B_MINI_ICON);
			}

			mime.SetTo("application/x-vnd.BeServed-fileshare");
			mime.Delete();
			if (!mime.IsInstalled())
			{
				mime.Install();
				mime.SetShortDescription("Shared Volume");
				mime.SetLongDescription("A BeServed network shared volume");
				setMimeIcon(&mime, MYNET_ICON_SHARE_LARGE, B_LARGE_ICON);
				setMimeIcon(&mime, MYNET_ICON_SHARE_SMALL, B_MINI_ICON);
			}
		}
Example #5
0
/*!	\brief Sets the icon the application provides for a given MIME type.

	If \a type is \c NULL, the application's icon is set.
	If \a data is \c NULL the icon is unset.

	If the file has a signature, then the icon is also set on the MIME type.
	If the type for the signature has not been installed yet, it is installed
	before.

	\param type The MIME type in question. May be \c NULL.
	\param data A pointer to the data containing the icon to be set.
		   May be \c NULL.
	\param size Specifies the size of buffer provided in \a data.
	\return
	- \c B_OK: Everything went fine.
	- \c B_NO_INIT: The object is not properly initialized.
	- \c B_BAD_VALUE: The provided \a type is not a valid MIME type.
	- other error codes
*/
status_t
BAppFileInfo::SetIconForType(const char* type, const uint8* data,
							 size_t size)
{
	if (InitCheck() != B_OK)
		return B_NO_INIT;

	// set some icon related variables
	BString attributeString = kIconAttribute;
	int32 resourceID = type ? kIconForTypeResourceID : kIconResourceID;
	uint32 attrType = B_VECTOR_ICON_TYPE;

	// check type param
	if (type) {
		if (BMimeType::IsValid(type))
			attributeString += type;
		else
			return B_BAD_VALUE;
	} else
		attributeString += kIconType;

	const char *attribute = attributeString.String();

	status_t error;
	// write/remove the attribute
	if (data)
		error = _WriteData(attribute, resourceID, attrType, data, size, true);
	else	// no icon given => remove
		error = _RemoveData(attribute, attrType);

	// set the attribute on the MIME type, if the file has a signature
	BMimeType mimeType;
	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
		if (!mimeType.IsInstalled())
			error = mimeType.Install();
		if (error == B_OK)
			error = mimeType.SetIconForType(type, data, size);
	}
	return error;
}
Example #6
0
// This handles the filetypes being installed with all the extra attributes over the
// regular R5 types
void MrPeeps::InitFileTypes(void)
{
    BEntry entry("/boot/home/config/settings/MrPeeps");
    BFile file;

    // Check for settings directory
    if(!entry.Exists())
        create_directory("/boot/home/config/settings/MrPeeps",0777);

    entry.SetTo("/boot/home/config/settings/MrPeeps/MrPeeps");
    if(!entry.Exists())
    {
        file.SetTo("/boot/home/config/settings/MrPeeps/MrPeeps",B_READ_WRITE|B_CREATE_FILE);
        file.Unset();
    }


    entry.SetTo("/boot/home/config/settings/MrPeeps/filetypes_installed");
    if(!entry.Exists())
    {
        BFile file("/boot/home/config/settings/MrPeeps/filetypes_installed",B_CREATE_FILE);
        BMimeType mime;
        BString string;
        BMessage msg,info;
        uint8 installtype=2;
        int32 index=0;
        BBitmap	large_icon(BRect(0, 0, B_LARGE_ICON-1, B_LARGE_ICON-1), B_COLOR_8_BIT);
        BBitmap	mini_icon(BRect(0, 0, B_MINI_ICON-1, B_MINI_ICON-1), B_COLOR_8_BIT);

        // install person mime type
        mime.SetType(PERSON_FILE_TYPE);
        if(mime.IsInstalled())
        {
            if (mime.GetAttrInfo(&info) == B_OK)
            {
                while (info.FindString("attr:name", index++, &string) == B_OK)
                {
                    if (string.Compare(PERSON_EMAIL5)==0)
                        installtype=1;

                    if (string.Compare(PERSON_BIRTHDAY)==0)
                    {
                        installtype=0;
                        break;
                    }
                }
                if (installtype>0)
                    mime.Delete();
            }
        }
        if(installtype>0)
        {
            mime.Install();
            large_icon.SetBits(kLargePersonIcon, large_icon.BitsLength(), 0, B_COLOR_8_BIT);
            mini_icon.SetBits(kSmallPersonIcon, mini_icon.BitsLength(), 0, B_COLOR_8_BIT);
            mime.SetShortDescription("Person");
            mime.SetLongDescription("Information about a person");
            mime.SetIcon(&large_icon, B_LARGE_ICON);
            mime.SetIcon(&mini_icon, B_MINI_ICON);

            BAlert *alert=new BAlert("Mr. Peeps!", "Would you like to make Mr. Peeps! the "
                                     "default application for People files? If not sure, choose 'No'.","Yes","No");

            if(alert->Go()==0)
                mime.SetPreferredApp(APP_SIGNATURE);
            else
                mime.SetPreferredApp("application/x-vnd.Be-PEPL");

            // General Person data
            msg.AddString("attr:public_name", "First Name");
            msg.AddString("attr:name", PERSON_FIRSTNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Last Name");
            msg.AddString("attr:name", PERSON_LASTNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Nickname");
            msg.AddString("attr:name", PERSON_NICKNAME);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Title");
            msg.AddString("attr:name", PERSON_TITLE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Group");
            msg.AddString("attr:name", PERSON_GROUP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            // Personal data
            msg.AddString("attr:public_name", "Home Address");
            msg.AddString("attr:name", PERSON_ADDRESS);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Home Address(2)");
            msg.AddString("attr:name", PERSON_ADDRESS2);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "City");
            msg.AddString("attr:name", PERSON_CITY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "State");
            msg.AddString("attr:name", PERSON_STATE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Postal Code");
            msg.AddString("attr:name", PERSON_ZIP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Country");
            msg.AddString("attr:name", PERSON_COUNTRY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Home Phone");
            msg.AddString("attr:name", PERSON_HOME_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            msg.AddString("attr:public_name", "Home Fax");
            msg.AddString("attr:name", PERSON_FAX);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Cell phone");
            msg.AddString("attr:name", PERSON_CELL_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail");
            msg.AddString("attr:name", PERSON_EMAIL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Web Page");
            msg.AddString("attr:name", PERSON_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            // Work data
            msg.AddString("attr:public_name", "Company");
            msg.AddString("attr:name", PERSON_COMPANY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Address");
            msg.AddString("attr:name", PERSON_WORK_ADDRESS);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Address (2)");
            msg.AddString("attr:name", PERSON_WORK_ADDRESS2);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work City");
            msg.AddString("attr:name", PERSON_WORK_CITY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work State");
            msg.AddString("attr:name", PERSON_WORK_STATE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Postal Code");
            msg.AddString("attr:name", PERSON_WORK_ZIP);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 50);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Country");
            msg.AddString("attr:name", PERSON_WORK_COUNTRY);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Phone");
            msg.AddString("attr:name", PERSON_WORK_PHONE);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            msg.AddString("attr:public_name", "Work Fax");
            msg.AddString("attr:name", PERSON_WORK_FAX);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Cell Phone");
            msg.AddString("attr:name", PERSON_WORK_CELL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work E-mail");
            msg.AddString("attr:name", PERSON_WORK_EMAIL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Work Web Address");
            msg.AddString("attr:name", PERSON_WORK_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Pager");
            msg.AddString("attr:name", PERSON_PAGER);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 90);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);


            // Internet stuff
            msg.AddString("attr:public_name", "E-mail 3");
            msg.AddString("attr:name", PERSON_EMAIL3);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail 4");
            msg.AddString("attr:name", PERSON_EMAIL4);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "E-mail 5");
            msg.AddString("attr:name", PERSON_EMAIL4);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "ICQ number");
            msg.AddString("attr:name", PERSON_ICQ);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "AIM number");
            msg.AddString("attr:name", PERSON_AIM);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Jabber name");
            msg.AddString("attr:name", PERSON_JABBER);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Yahoo messenger");
            msg.AddString("attr:name", PERSON_YAHOO);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            msg.AddString("attr:public_name", "Other Web Address");
            msg.AddString("attr:name", PERSON_OTHER_URL);
            msg.AddInt32("attr:type", B_STRING_TYPE);
            msg.AddBool("attr:viewable", true);
            msg.AddBool("attr:editable", true);
            msg.AddInt32("attr:width", 120);
            msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
            msg.AddBool("attr:extra", false);

            if(installtype==2)
            {
                // Attributes used only by Mr. Peeps!
                msg.AddString("attr:public_name", "Birthday");
                msg.AddString("attr:name", PERSON_BIRTHDAY);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Anniversary");
                msg.AddString("attr:name", PERSON_ANNIVERSARY);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Spouse");
                msg.AddString("attr:name", PERSON_SPOUSE);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);

                msg.AddString("attr:public_name", "Children");
                msg.AddString("attr:name", PERSON_CHILDREN);
                msg.AddInt32("attr:type", B_STRING_TYPE);
                msg.AddBool("attr:viewable", true);
                msg.AddBool("attr:editable", true);
                msg.AddInt32("attr:width", 50);
                msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
                msg.AddBool("attr:extra", false);
            }

            mime.SetAttrInfo(&msg);
        }
    }
}
Example #7
0
/*!	\brief Sets the icon the application provides for a given MIME type.

	If \a type is \c NULL, the application's icon is set.
	If \a icon is \c NULL the icon is unset.

	If the file has a signature, then the icon is also set on the MIME type.
	If the type for the signature has not been installed yet, it is installed
	before.

	\param type The MIME type in question. May be \c NULL.
	\param icon A pointer to the BBitmap containing the icon to be set.
		   May be \c NULL.
	\param which Specifies the size of the icon to be set: \c B_MINI_ICON
		   for the mini and \c B_LARGE_ICON for the large icon.
	\return
	- \c B_OK: Everything went fine.
	- \c B_NO_INIT: The object is not properly initialized.
	- \c B_BAD_VALUE: Either the icon size \a which is unkown, bitmap dimensions (\a icon)
		 and icon size (\a which) do not match, or the provided \a type is
		 not a valid MIME type. 
	- other error codes
*/
status_t
BAppFileInfo::SetIconForType(const char *type, const BBitmap *icon,
							 icon_size which)
{
	status_t error = B_OK;
	// set some icon size related variables
	BString attributeString;
	BRect bounds;
	uint32 attrType = 0;
	size_t attrSize = 0;
	int32 resourceID = 0;
	switch (which) {
		case B_MINI_ICON:
			attributeString = kMiniIconAttribute;
			bounds.Set(0, 0, 15, 15);
			attrType = B_MINI_ICON_TYPE;
			attrSize = 16 * 16;
			resourceID = (type ? kMiniIconForTypeResourceID
							   : kMiniIconResourceID);
			break;
		case B_LARGE_ICON:
			attributeString = kLargeIconAttribute;
			bounds.Set(0, 0, 31, 31);
			attrType = B_LARGE_ICON_TYPE;
			attrSize = 32 * 32;
			resourceID = (type ? kLargeIconForTypeResourceID
							   : kLargeIconResourceID);
			break;
		default:
			error = B_BAD_VALUE;
			break;
	}
	// check type param
	if (error == B_OK) {
		if (type) {
			if (BMimeType::IsValid(type))
				attributeString += type;
			else
				error = B_BAD_VALUE;
		} else
			attributeString += kStandardIconType;
	}
	const char *attribute = attributeString.String();
	// check parameter and initialization
	if (error == B_OK && icon
		&& (icon->InitCheck() != B_OK || icon->Bounds() != bounds)) {
		error = B_BAD_VALUE;
	}
	if (error == B_OK && InitCheck() != B_OK)
		error = B_NO_INIT;
	// write/remove the attribute
	if (error == B_OK) {
		if (icon) {
			bool otherColorSpace = (icon->ColorSpace() != B_CMAP8);
			if (otherColorSpace) {
				BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_CMAP8);
				error = bitmap.InitCheck();
				if (error == B_OK)
					error = bitmap.ImportBits(icon);
				if (error == B_OK) {
					error = _WriteData(attribute, resourceID, attrType,
									   bitmap.Bits(), attrSize, true);
				}
			} else {
				error = _WriteData(attribute, resourceID, attrType,
								   icon->Bits(), attrSize, true);
			}
		} else	// no icon given => remove
			error = _RemoveData(attribute, attrType);
	}
	// set the attribute on the MIME type, if the file has a signature
	BMimeType mimeType;
	if (error == B_OK && GetMetaMime(&mimeType) == B_OK) {
		if (!mimeType.IsInstalled())
			error = mimeType.Install();
		if (error == B_OK)
			error = mimeType.SetIconForType(type, icon, which);
	}
	return error;
}
status_t
CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
{
    if (ref == NULL)
        return B_BAD_VALUE;

    BNode typeNode;

    BFile file;
    status_t status = file.SetTo(ref, B_READ_ONLY);
    if (status < B_OK)
        return status;

    bool isDir = file.IsDirectory();
    if (_entryIsDir != NULL)
        *_entryIsDir = isDir;

    if (isDir)
        return B_OK;

    BAppFileInfo appInfo(&file);
    status = appInfo.InitCheck();
    if (status < B_OK)
        return status;

    // Read the app sig (which consequently keeps us from updating
    // non-applications, since we get an error if the file has no
    // app sig)
    BString signature;
    status = file.ReadAttrString("BEOS:APP_SIG", &signature);
    if (status < B_OK)
        return B_BAD_TYPE;

    // Init our various objects

    BMimeType mime;
    status = mime.SetTo(signature.String());
    if (status < B_OK)
        return status;

    InstallNotificationDeferrer _(fDatabase, signature.String());

    if (!mime.IsInstalled())
        mime.Install();

    BString path = "/";
    path.Append(signature);
    path.ToLower();
    // Signatures and MIME types are case insensitive, but we want to
    // preserve the case wherever possible
    path.Prepend(get_database_directory().c_str());

    status = typeNode.SetTo(path.String());
    if (status < B_OK)
        return status;

    // Preferred App
    attr_info info;
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) != B_OK))
        status = mime.SetPreferredApp(signature.String());

    // Short Description (name of the application)
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) != B_OK))
        status = mime.SetShortDescription(ref->name);

    // App Hint
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) != B_OK))
        status = mime.SetAppHint(ref);

    // Vector Icon
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kIconAttr, &info) != B_OK)) {
        uint8* data = NULL;
        size_t size = 0;
        if (appInfo.GetIcon(&data, &size) == B_OK) {
            status = mime.SetIcon(data, size);
            free(data);
        }
    }
    // Mini Icon
    BBitmap miniIcon(BRect(0, 0, 15, 15), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) != B_OK)) {
        if (appInfo.GetIcon(&miniIcon, B_MINI_ICON) == B_OK)
            status = mime.SetIcon(&miniIcon, B_MINI_ICON);
    }
    // Large Icon
    BBitmap largeIcon(BRect(0, 0, 31, 31), B_BITMAP_NO_SERVER_LINK, B_CMAP8);
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kLargeIconAttr, &info) != B_OK)) {
        if (appInfo.GetIcon(&largeIcon, B_LARGE_ICON) == B_OK)
            status = mime.SetIcon(&largeIcon, B_LARGE_ICON);
    }

    // Supported Types
    bool setSupportedTypes = false;
    BMessage supportedTypes;
    if (status == B_OK && (fForce || typeNode.GetAttrInfo(kSupportedTypesAttr, &info) != B_OK)) {
        if (appInfo.GetSupportedTypes(&supportedTypes) == B_OK)
            setSupportedTypes = true;
    }

    // defer notifications for supported types
    const char* type;
    for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++)
        fDatabase->DeferInstallNotification(type);

    // set supported types
    if (setSupportedTypes)
        status = mime.SetSupportedTypes(&supportedTypes);

    // Icons for supported types
    for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++) {
        // vector icon
        uint8* data = NULL;
        size_t size = 0;
        if (status == B_OK && appInfo.GetIconForType(type, &data, &size) == B_OK) {
            status = mime.SetIconForType(type, data, size);
            free(data);
        }
        // mini icon
        if (status == B_OK && appInfo.GetIconForType(type, &miniIcon, B_MINI_ICON) == B_OK)
            status = mime.SetIconForType(type, &miniIcon, B_MINI_ICON);
        // large icon
        if (status == B_OK && appInfo.GetIconForType(type, &largeIcon, B_LARGE_ICON) == B_OK)
            status = mime.SetIconForType(type, &largeIcon, B_LARGE_ICON);
    }

    // undefer notifications for supported types
    for (int32 i = 0; supportedTypes.FindString("types", i, &type) == B_OK; i++)
        fDatabase->UndeferInstallNotification(type);

    return status;
}