Example #1
0
//! newExtensionsList contains all the entries (char*) which are to be added.
status_t
merge_extensions(BMimeType& type, const BList& newExtensionsList,
	const char* removeExtension)
{
	BMessage extensions;
	status_t status = type.GetFileExtensions(&extensions);
	if (status < B_OK)
		return status;

	// replace the entry, and remove any equivalent entries
	BList mergedList;
	mergedList.AddList(&newExtensionsList);
	int32 originalCount = mergedList.CountItems();

	const char* extension;
	for (int32 i = 0; extensions.FindString("extensions", i,
			&extension) == B_OK; i++) {

		for (int32 j = originalCount; j-- > 0;) {
			if (!strcmp((const char*)mergedList.ItemAt(j), extension)) {
				// Do not add this old item again, since it's already
				// there.
				mergedList.RemoveItem(j);
				originalCount--;
			}
		}

		// The item will be added behind "originalCount", so we cannot
		// remove it accidentally in the next iterations, it's is added
		// for good.
		if (removeExtension == NULL || strcmp(removeExtension, extension))
			mergedList.AddItem((void *)extension);
	}

	mergedList.SortItems(compare_extensions);

	// Copy them to a new message (their memory is still part of the
	// original BMessage)
	BMessage newExtensions;
	for (int32 i = 0; i < mergedList.CountItems(); i++) {
		newExtensions.AddString("extensions",
			(const char*)mergedList.ItemAt(i));
	}

	return type.SetFileExtensions(&newExtensions);
}
Example #2
0
CFtpDialog::CFtpDialog(BRect frame, const char *name, window_type type, int flags,
	BWindow *owner)
	: HDialog(frame, name, type, flags, owner, NULL)
{

	fReply = new char[1024];
	fPath = new char[PATH_MAX];
	fSave = false;
	fSocket = -1;

	Create();
	Layout();

#if 0
	// Build Extension->Mimetype list // Takes looong
	typedef pair<string,string> entry;
	BMessage mimDat;
	BMessage extDat;
	BMimeType mimTyp;
	int32 mimIdx = -1;
	int32 extIdx = 0;
	const char* mimCStr;
	const char* extCStr;
	if (BMimeType::GetInstalledTypes(&mimDat) == B_OK) {
		while (mimDat.FindString("types", ++mimIdx, &mimCStr) == B_OK) {
			if ((mimTyp.SetTo(mimCStr) == B_OK) && (mimTyp.GetFileExtensions(&extDat) == B_OK)) {
				extIdx = -1;
				while (extDat.FindString("extensions", ++extIdx, &extCStr) == B_OK) {
					BString extStr(extCStr);
					extStr.ToLower();
					if (extStr.ByteAt(0) == '.')  extStr.Remove(0, 1);
					fExtMime[extCStr] = mimCStr;
				}
			}
		}
	}
#else
	// perhaps it's better to go with some predefiend types:
	fExtMime["aiff"] = "audio/x-aiff";
	fExtMime["bz2"] = "application/x-bzip2";
	fExtMime["cc"] = "text/x-source-code";
	fExtMime["cpp"] = "text/x-source-code";
	fExtMime["css"] = "text/css";
	fExtMime["gif"] = "image/gif";
	fExtMime["gz"] = "application/x-gzip";
	fExtMime["h"] = "text/x-source-code";
	fExtMime["htm"] = "text/html";
	fExtMime["html"] = "text/html";
	fExtMime["jpeg"] = "image/jpeg";
	fExtMime["jpg"] = "image/jpeg";
	fExtMime["mod"] = "audio/x-mod";
	fExtMime["mov"] = "video/quicktime";
	fExtMime["mp3"] = "audio/x-mpeg";
	fExtMime["ogg"] = "audio/ogg.vorbis";
	fExtMime["pdf"] = "application/pdf";
	fExtMime["php"] = "text/x-php";
	fExtMime["pl"] = "text/x-perl";
	fExtMime["pkg"] = "application/x-scode-UPkg";
	fExtMime["png"] = "image/png";
	fExtMime["py"] = "text/x-source-code";
	fExtMime["rar"] = "application/x-rar";
	fExtMime["swf"] = "application/x-shockwave-flash";
	fExtMime["tar"] = "application/x-tar";
	fExtMime["tga"] = "image/x-targa";
	fExtMime["tgz"] = "application/x-gzip";
	fExtMime["txt"] = "text/plain";
	fExtMime["xml"] = "text/xml";
	fExtMime["zip"] = "application/zip";
#endif

} // CFtpDialog::CFtpDialog