Exemple #1
0
status_t 
Model::SetTo(const node_ref *dirNode, const node_ref *nodeRef, const char *name,
	bool open, bool writable)
{
	delete fNode;
	fNode = NULL;
	DeletePreferredAppVolumeNameLinkTo();
	fIconFrom = kUnknownSource;
	fBaseType = kUnknownNode;
	fMimeType = "";

	fStatBuf.st_dev = nodeRef->device;
	fStatBuf.st_ino = nodeRef->node;
	fEntryRef.device = dirNode->device;
	fEntryRef.directory = dirNode->node;
	fEntryRef.name = strdup(name);

	BEntry tmpNode(&fEntryRef);
	fStatus = tmpNode.InitCheck();
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = tmpNode.GetStat(&fStatBuf);
	if (fStatus != B_OK)
		return fStatus;

	fStatus = OpenNode(writable);

	if (!open)
		CloseNode();
	
	return fStatus;
}
Exemple #2
0
status_t 
Model::SetTo(const entry_ref *newRef, bool traverse, bool open, bool writable)
{
	delete fNode;
	fNode = NULL;
	DeletePreferredAppVolumeNameLinkTo();
	fIconFrom = kUnknownSource;
	fBaseType = kUnknownNode;
	fMimeType = "";

	BEntry tmpEntry(newRef, traverse);
	fStatus = tmpEntry.InitCheck();
	if (fStatus != B_OK)
		return fStatus;

	if (traverse)
		tmpEntry.GetRef(&fEntryRef);
	else
		fEntryRef = *newRef;

	fStatus = tmpEntry.GetStat(&fStatBuf);
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = OpenNode(writable);
	if (!open)
		CloseNode();
	
	return fStatus;
}
Exemple #3
0
void
Model::UpdateEntryRef(const node_ref *dirNode, const char *name)
{
	if (IsVolume()) {
		if (fVolumeName)
			DeletePreferredAppVolumeNameLinkTo();
	
		fVolumeName = strdup(name);
	}

	fEntryRef.device = dirNode->device;
	fEntryRef.directory = dirNode->node;

	if (fEntryRef.name && strcmp(fEntryRef.name, name) == 0)
		return;

	fEntryRef.set_name(name);
}
Exemple #4
0
Model::~Model()
{
#ifdef CHECK_OPEN_MODEL_LEAKS
	if (writableOpenModelList) 
		writableOpenModelList->RemoveItem(this);
	if (readOnlyOpenModelList) 
		readOnlyOpenModelList->RemoveItem(this);
#endif

	DeletePreferredAppVolumeNameLinkTo();
	if (IconCache::NeedsDeletionNotification((IconSource)fIconFrom))
		// this check allows us to use temporary Model in the IconCache
		// without the danger of a deadlock
		IconCache::sIconCache->Deleting(this);
#if xDEBUG
	if (fNode)
		PRINT(("destructor closing node for %s\n", Name()));
#endif

	delete fNode;
}
Exemple #5
0
status_t 
Model::SetTo(const BEntry *entry, bool open, bool writable)
{
	delete fNode;
	fNode = NULL;
	DeletePreferredAppVolumeNameLinkTo();
	fIconFrom = kUnknownSource;
	fBaseType = kUnknownNode;
	fMimeType = "";

	fStatus = entry->GetRef(&fEntryRef);
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = entry->GetStat(&fStatBuf);
	if (fStatus != B_OK)
		return fStatus;
	
	fStatus = OpenNode(writable);
	if (!open)
		CloseNode();
	
	return fStatus;
}
Exemple #6
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;
	}
}
Exemple #7
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;
	}
}