Exemplo n.º 1
0
static const BString*
SetDefaultAppForOneType(const BString* element, void* castToEntryRef)
{
	const entry_ref* appRef = (const entry_ref*)castToEntryRef;

	// set entry as default handler for one mime string
	BMimeType mime(element->String());
	if (!mime.IsInstalled())
		return 0;

	// first set it's app signature as the preferred type
	BFile appFile(appRef, O_RDONLY);
	if (appFile.InitCheck() != B_OK)
		return 0;

	char appSignature[B_MIME_TYPE_LENGTH];
	if (GetAppSignatureFromAttr(&appFile, appSignature) != B_OK)
		return 0;

	if (mime.SetPreferredApp(appSignature) != B_OK)
		return 0;

	// set the app hint on the metamime for this signature
	mime.SetTo(appSignature);
#if xDEBUG
	status_t result =
#endif
	mime.SetAppHint(appRef);

#if xDEBUG
	BEntry debugEntry(appRef);
	BPath debugPath;
	debugEntry.GetPath(&debugPath);

	PRINT(("setting %s, sig %s as default app for %s, result %s\n",
		debugPath.Path(), appSignature, element->String(), strerror(result)));
#endif

	return 0;
}
Exemplo n.º 2
0
void
Model::FinishSettingUpType()
{
	char mimeString[B_MIME_TYPE_LENGTH];

	// while we are reading the node, do a little
	// snooping to see if it even makes sense to look for a node-based
	// icon
	// This serves as a hint to the icon cache, allowing it to not hit the
	// disk again for models that do not have an icon defined by the node
	if (IsNodeOpen()
		&& fBaseType != kLinkNode
		&& !CheckNodeIconHintPrivate(fNode, dynamic_cast<TTracker *>(be_app) == NULL)) {
			// when checking for the node icon hint, if we are libtracker, only check
			// for small icons - checking for the large icons is a little more
			// work for the filesystem and this will speed up the test.
			// This makes node icons only work if there is a small and a large node
			// icon on a file - for libtracker that is not a problem though
		fIconFrom = kUnknownNotFromNode;
	}

	if (fBaseType != kDirectoryNode
		&& fBaseType != kVolumeNode
		&& fBaseType != kLinkNode
		&& IsNodeOpen()) {
		BNodeInfo info(fNode);

		// check if a specific mime type is set
		if (info.GetType(mimeString) == B_OK) {
			// node has a specific mime type
			fMimeType = mimeString;
			if (strcmp(mimeString, B_QUERY_MIMETYPE) == 0)
				fBaseType = kQueryNode;
			else if (strcmp(mimeString, B_QUERY_TEMPLATE_MIMETYPE) == 0)
				fBaseType = kQueryTemplateNode;

			if (info.GetPreferredApp(mimeString) == B_OK) {
				if (fPreferredAppName)
					DeletePreferredAppVolumeNameLinkTo();

				if (mimeString[0])
					fPreferredAppName = strdup(mimeString); 
			}
		}
	}

	switch (fBaseType) {
		case kDirectoryNode:
			fMimeType = B_DIR_MIMETYPE;	// should use a shared string here
			if (IsNodeOpen()) {
				BNodeInfo info(fNode);
				if (info.GetType(mimeString) == B_OK)
					fMimeType = mimeString;

				if (fIconFrom == kUnknownNotFromNode
					&& WellKnowEntryList::Match(NodeRef()) > (directory_which)-1)
					// one of home, beos, system, boot, etc.
					fIconFrom = kTrackerSupplied;
			}
			break;

		case kVolumeNode:
		{
			if (NodeRef()->node == fEntryRef.directory
				&& NodeRef()->device == fEntryRef.device) {
				// promote from volume to file system root
				fBaseType = kRootNode;
				fMimeType = B_ROOT_MIMETYPE;
				break;
			}

			// volumes have to have a B_VOLUME_MIMETYPE type
			fMimeType = B_VOLUME_MIMETYPE;
			if (fIconFrom == kUnknownNotFromNode) {
				if (WellKnowEntryList::Match(NodeRef()) > (directory_which)-1)
					fIconFrom = kTrackerSupplied;
				else
					fIconFrom = kVolume;
			}

			char name[B_FILE_NAME_LENGTH];
			BVolume	volume(NodeRef()->device);
			if (volume.InitCheck() == B_OK && volume.GetName(name) == B_OK) {
				if (fVolumeName)
					DeletePreferredAppVolumeNameLinkTo();

				fVolumeName = strdup(name);
			}
#if DEBUG
			else
				PRINT(("get volume name failed for %s\n", fEntryRef.name));
#endif
			break;
		}

		case kLinkNode:
			fMimeType = B_LINK_MIMETYPE;	// should use a shared string here
			break;

		case kExecutableNode:
			if (IsNodeOpen()) {
				char signature[B_MIME_TYPE_LENGTH];
				if (GetAppSignatureFromAttr(dynamic_cast<BFile *>(fNode), signature)
					== B_OK) {

					if (fPreferredAppName)
						DeletePreferredAppVolumeNameLinkTo();

					if (signature[0])
						fPreferredAppName = strdup(signature); 
				}
			}
			if (!fMimeType.Length())
				fMimeType = B_APP_MIME_TYPE;	// should use a shared string here
			break;

		default:
			if (!fMimeType.Length())
				fMimeType = B_FILE_MIMETYPE;
			break;
	}
}
Exemplo n.º 3
0
bool
SearchForSignatureEntryList::CanOpenWithFilter(const Model* appModel,
	const BMessage* entriesToOpen, const entry_ref* preferredApp)
{
	ThrowOnAssert(appModel != NULL);

	if (!appModel->IsExecutable() || !appModel->Node()) {
		// weed out non-executable
#if xDEBUG
		BPath path;
		BEntry entry(appModel->EntryRef());
		entry.GetPath(&path);
		PRINT(("filtering out %s- not executable \n", path.Path()));
#endif
		return false;
	}

	if (strcasecmp(appModel->MimeType(), B_APP_MIME_TYPE) != 0) {
		// filter out pe containers on PPC etc.
		return false;
	}

	BFile* file = dynamic_cast<BFile*>(appModel->Node());
	ASSERT(file != NULL);

	char signature[B_MIME_TYPE_LENGTH];
	if (GetAppSignatureFromAttr(file, signature) == B_OK
		&& strcasecmp(signature, kTrackerSignature) == 0) {
		// special case the Tracker - make sure only the running copy is
		// in the list
		app_info trackerInfo;
		if (*appModel->EntryRef() != trackerInfo.ref) {
			// this is an inactive copy of the Tracker, remove it

#if xDEBUG
			BPath path1;
			BPath path2;
			BEntry entry(appModel->EntryRef());
			entry.GetPath(&path1);

			BEntry entry2(&trackerInfo.ref);
			entry2.GetPath(&path2);

			PRINT(("filtering out %s, sig %s, active Tracker at %s, "
				   "result %s, refName %s\n",
				path1.Path(), signature, path2.Path(),
				strerror(be_roster->GetActiveAppInfo(&trackerInfo)),
				trackerInfo.ref.name));
#endif
			return false;
		}
	}

	if (FSInTrashDir(appModel->EntryRef()))
		return false;

	if (ShowAllApplications()) {
		// don't check for these if we didn't look for every single app
		// to not slow filtering down
		uint32 flags;
		BAppFileInfo appFileInfo(dynamic_cast<BFile*>(appModel->Node()));
		if (appFileInfo.GetAppFlags(&flags) != B_OK)
			return false;

		if ((flags & B_BACKGROUND_APP) || (flags & B_ARGV_ONLY))
			return false;

		if (!signature[0])
			// weed out apps with empty signatures
			return false;
	}

	int32 relation = Relation(entriesToOpen, appModel, preferredApp, 0);
	if (relation == kNoRelation && !ShowAllApplications()) {
#if xDEBUG
		BPath path;
		BEntry entry(appModel->EntryRef());
		entry.GetPath(&path);

		PRINT(("filtering out %s, does not handle any of opened files\n",
			path.Path()));
#endif
		return false;
	}

	if (relation != kNoRelation && relation != kSuperhandler
		&& !fGenericFilesOnly) {
		// we hit at least one app that is not a superhandler and
		// handles the document
		fFoundOneNonSuperHandler = true;
	}

	return true;
}
Exemplo n.º 4
0
void
Model::FinishSettingUpType()
{
	char mimeString[B_MIME_TYPE_LENGTH];
	BEntry entry;

	// While we are reading the node, do a little snooping to see if it even
	// makes sense to look for a node-based icon. This serves as a hint to the
	// icon cache, allowing it to not hit the disk again for models that do not
	// have an icon defined by the node.
	if (IsNodeOpen() && fBaseType != kLinkNode && !CheckNodeIconHint(fNode))
		fIconFrom = kUnknownNotFromNode;

	if (fBaseType != kDirectoryNode
		&& fBaseType != kVolumeNode
		&& fBaseType != kLinkNode
		&& IsNodeOpen()) {
		BNodeInfo info(fNode);

		// check if a specific mime type is set
		if (info.GetType(mimeString) == B_OK) {
			// node has a specific mime type
			fMimeType = mimeString;
			if (strcmp(mimeString, B_QUERY_MIMETYPE) == 0)
				fBaseType = kQueryNode;
			else if (strcmp(mimeString, B_QUERY_TEMPLATE_MIMETYPE) == 0)
				fBaseType = kQueryTemplateNode;
			else if (strcmp(mimeString, kVirtualDirectoryMimeType) == 0)
				fBaseType = kVirtualDirectoryNode;

			if (info.GetPreferredApp(mimeString) == B_OK) {
				if (fPreferredAppName)
					DeletePreferredAppVolumeNameLinkTo();

				if (mimeString[0])
					fPreferredAppName = strdup(mimeString);
			}
		}
	}

	switch (fBaseType) {
		case kDirectoryNode:
			entry.SetTo(&fEntryRef);
			if (entry.InitCheck() == B_OK) {
				if (FSIsTrashDir(&entry))
					fBaseType = kTrashNode;
				else if (FSIsDeskDir(&entry))
					fBaseType = kDesktopNode;
			}

			fMimeType = B_DIR_MIMETYPE;
				// should use a shared string here
			if (IsNodeOpen()) {
				BNodeInfo info(fNode);
				if (info.GetType(mimeString) == B_OK)
					fMimeType = mimeString;

				if (fIconFrom == kUnknownNotFromNode
					&& WellKnowEntryList::Match(NodeRef())
						> (directory_which)-1) {
					// one of home, beos, system, boot, etc.
					fIconFrom = kTrackerSupplied;
				}
			}
			break;

		case kVolumeNode:
		{
			if (NodeRef()->node == fEntryRef.directory
				&& NodeRef()->device == fEntryRef.device) {
				// promote from volume to file system root
				fBaseType = kRootNode;
				fMimeType = B_ROOT_MIMETYPE;
				break;
			}

			// volumes have to have a B_VOLUME_MIMETYPE type
			fMimeType = B_VOLUME_MIMETYPE;
			if (fIconFrom == kUnknownNotFromNode) {
				if (WellKnowEntryList::Match(NodeRef()) > (directory_which)-1)
					fIconFrom = kTrackerSupplied;
				else
					fIconFrom = kVolume;
			}

			char name[B_FILE_NAME_LENGTH];
			BVolume volume(NodeRef()->device);
			if (volume.InitCheck() == B_OK && volume.GetName(name) == B_OK) {
				if (fVolumeName != NULL)
					DeletePreferredAppVolumeNameLinkTo();

				fVolumeName = strdup(name);
			}
#if DEBUG
			else
				PRINT(("get volume name failed for %s\n", fEntryRef.name));
#endif
			break;
		}

		case kLinkNode:
			fMimeType = B_LINK_MIMETYPE;
				// should use a shared string here
			break;

		case kExecutableNode:
			if (IsNodeOpen()) {
				char signature[B_MIME_TYPE_LENGTH];
				if (GetAppSignatureFromAttr(dynamic_cast<BFile*>(fNode),
						signature) == B_OK) {
					if (fPreferredAppName)
						DeletePreferredAppVolumeNameLinkTo();

					if (signature[0])
						fPreferredAppName = strdup(signature);
				}
			}
			if (fMimeType.Length() <= 0)
				fMimeType = B_APP_MIME_TYPE;
					// should use a shared string here
			break;

		default:
			if (fMimeType.Length() <= 0)
				fMimeType = B_FILE_MIMETYPE;
			break;
	}
}