Пример #1
0
void
BTrashWatcher::UpdateTrashIcons()
{
	BVolume	boot;
	if (BVolumeRoster().GetBootVolume(&boot) != B_OK)
		return;

	BDirectory trashDir;
	if (FSGetTrashDir(&trashDir, boot.Device()) == B_OK) {
		// pull out the icons for the current trash state from resources and
		// apply them onto the trash directory node
		size_t largeSize = 0;
		size_t smallSize = 0;
		const void *largeData = GetTrackerResources()->LoadResource('ICON',
			fTrashFull ? kResTrashFullIcon : kResTrashIcon, &largeSize);

		const void *smallData = GetTrackerResources()->LoadResource('MICN',
			fTrashFull ? kResTrashFullIcon : kResTrashIcon,  &smallSize);

		if (largeData) 
			trashDir.WriteAttr(kAttrLargeIcon, 'ICON', 0,
				largeData, largeSize);
		else
			TRESPASS();

		if (smallData)
			trashDir.WriteAttr(kAttrMiniIcon, 'MICN', 0,
				smallData, smallSize);
		else
			TRESPASS();
	}
}
bool
TTracker::InstallMimeIfNeeded(const char *type, int32 bitsID,
	const char *shortDescription, const char *longDescription,
	const char *preferredAppSignature, uint32 forceMask)
{
	// used by InitMimeTypes - checks if a metamime of a given <type> is
	// installed and if it has all the specified attributes; if not, the
	// whole mime type is installed and all attributes are set; nulls can
	// be passed for attributes that don't matter; returns true if anything
	// had to be changed
	BBitmap largeIcon(BRect(0, 0, 31, 31), B_CMAP8);
	BBitmap miniIcon(BRect(0, 0, 15, 15), B_CMAP8);
	char tmp[B_MIME_TYPE_LENGTH];

	BMimeType mime(type);
	bool installed = mime.IsInstalled();
	
	if (!installed
		|| (bitsID >= 0 && ((forceMask & kForceLargeIcon)
			|| mime.GetIcon(&largeIcon, B_LARGE_ICON) != B_OK))
		|| (bitsID >= 0 && ((forceMask & kForceMiniIcon)
			|| mime.GetIcon(&miniIcon, B_MINI_ICON) != B_OK))
		|| (shortDescription && ((forceMask & kForceShortDescription)
			|| mime.GetShortDescription(tmp) != B_OK))
		|| (longDescription && ((forceMask & kForceLongDescription)
			|| mime.GetLongDescription(tmp) != B_OK))
		|| (preferredAppSignature && ((forceMask & kForcePreferredApp)
			|| mime.GetPreferredApp(tmp) != B_OK))) {
	
		if (!installed)
			mime.Install();

		if (bitsID >= 0) {
			if (GetTrackerResources()->
					GetIconResource(bitsID, B_LARGE_ICON, &largeIcon) == B_OK) 
				mime.SetIcon(&largeIcon, B_LARGE_ICON);

			if (GetTrackerResources()->
					GetIconResource(bitsID, B_MINI_ICON, &miniIcon) == B_OK) 
				mime.SetIcon(&miniIcon, B_MINI_ICON);
		}

		if (shortDescription)
			mime.SetShortDescription(shortDescription);
		
		if (longDescription)
			mime.SetLongDescription(longDescription);
		
		if (preferredAppSignature)
			mime.SetPreferredApp(preferredAppSignature);	

		return true;
	}
	return false;
}
void
BTrashWatcher::UpdateTrashIcons()
{
	BVolumeRoster roster;
	BVolume volume;
	roster.Rewind();

	BDirectory trashDir;
	while (roster.GetNextVolume(&volume) == B_OK) {
		if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK) {
			// pull out the icons for the current trash state from resources
			// and apply them onto the trash directory node
			size_t largeSize = 0;
			size_t smallSize = 0;
			const void* largeData
				= GetTrackerResources()->LoadResource('ICON',
					fTrashFull ? R_TrashFullIcon : R_TrashIcon, &largeSize);

			const void* smallData
				= GetTrackerResources()->LoadResource('MICN',
					fTrashFull ? R_TrashFullIcon : R_TrashIcon,  &smallSize);

#ifdef HAIKU_TARGET_PLATFORM_HAIKU
			size_t vectorSize = 0;
			const void* vectorData = GetTrackerResources()->LoadResource(
				B_VECTOR_ICON_TYPE,
				fTrashFull ? R_TrashFullIcon : R_TrashIcon, &vectorSize);

			if (vectorData) {
				trashDir.WriteAttr(kAttrIcon, B_VECTOR_ICON_TYPE, 0,
					vectorData, vectorSize);
			} else
				TRESPASS();
#endif

			if (largeData) {
				trashDir.WriteAttr(kAttrLargeIcon, 'ICON', 0,
					largeData, largeSize);
			} else
				TRESPASS();

			if (smallData) {
				trashDir.WriteAttr(kAttrMiniIcon, 'MICN', 0,
					smallData, smallSize);
			} else
				TRESPASS();
		}
	}
}
Пример #4
0
void
BNavigatorButton::AttachedToWindow()
{
	BBitmap *bmpOn = 0;
	GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDOn, &bmpOn);
	SetPicture(bmpOn, true, true);
	delete bmpOn;
	
	BBitmap *bmpOff = 0;
	GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDOff, &bmpOff);
	SetPicture(bmpOff, true, false);
	delete bmpOff;

	BBitmap *bmpDisabled = 0;
	GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, fResIDDisabled, &bmpDisabled);
	SetPicture(bmpDisabled, false, false);
	SetPicture(bmpDisabled, false, true);
	delete bmpDisabled;
}
BStatusView::BStatusView(BRect bounds, thread_id thread, StatusWindowState type)
	:
	BView(bounds, "StatusView", B_FOLLOW_NONE, B_WILL_DRAW),
	fType(type),
	fBitmap(NULL),
	fThread(thread)
{
	Init();

	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	SetLowColor(ViewColor());
	SetHighColor(20, 20, 20);
	SetDrawingMode(B_OP_OVER);

	const float buttonWidth = 22;
	const float buttonHeight = 20;

	BRect rect(bounds);
	rect.OffsetTo(B_ORIGIN);
	rect.left += 40;
	rect.right -= buttonWidth * 2 + 12;
	rect.top += 6;
	rect.bottom = rect.top + 15;

	BString caption;
	int32 id = 0;

	switch (type) {
		case kCopyState:
			caption = B_TRANSLATE("Preparing to copy items" B_UTF8_ELLIPSIS);
			id = R_CopyStatusBitmap;
			break;

		case kMoveState:
			caption = B_TRANSLATE("Preparing to move items" B_UTF8_ELLIPSIS);
			id = R_MoveStatusBitmap;
			break;

		case kCreateLinkState:
			caption = B_TRANSLATE("Preparing to create links"
				B_UTF8_ELLIPSIS);
			id = R_MoveStatusBitmap;
			break;

		case kTrashState:
			caption = B_TRANSLATE("Preparing to empty Trash" B_UTF8_ELLIPSIS);
			id = R_TrashStatusBitmap;
			break;

		case kVolumeState:
			caption = B_TRANSLATE("Searching for disks to mount"
				B_UTF8_ELLIPSIS);
			break;

		case kDeleteState:
			caption = B_TRANSLATE("Preparing to delete items"
				B_UTF8_ELLIPSIS);
			id = R_TrashStatusBitmap;
			break;

		case kRestoreFromTrashState:
			caption = B_TRANSLATE("Preparing to restore items"
				B_UTF8_ELLIPSIS);
			break;

		default:
			TRESPASS();
			break;
	}

	if (caption.Length() != 0) {
		fStatusBar = new BStatusBar(rect, "StatusBar", caption.String());
		fStatusBar->SetBarHeight(12);
		float width, height;
		fStatusBar->GetPreferredSize(&width, &height);
		fStatusBar->ResizeTo(fStatusBar->Frame().Width(), height);
		AddChild(fStatusBar);

		// Figure out how much room we need to display the additional status
		// message below the bar
		font_height fh;
		GetFontHeight(&fh);
		BRect f = fStatusBar->Frame();
		// Height is 3 x the "room from the top" + bar height + room for
		// string.
		ResizeTo(Bounds().Width(), f.top + f.Height() + fh.leading + fh.ascent
			+ fh.descent + f.top);
	}

	if (id != 0) {
		GetTrackerResources()->GetBitmapResource(B_MESSAGE_TYPE, id,
			&fBitmap);
	}

	rect = Bounds();
	rect.left = rect.right - buttonWidth * 2 - 7;
	rect.right = rect.left + buttonWidth;
	rect.top = floorf((rect.top + rect.bottom) / 2 + 0.5) - buttonHeight / 2;
	rect.bottom = rect.top + buttonHeight;

	fPauseButton = new TCustomButton(rect, kPauseButton);
	fPauseButton->ResizeTo(buttonWidth, buttonHeight);
	AddChild(fPauseButton);

	rect.OffsetBy(buttonWidth + 2, 0);
	fStopButton = new TCustomButton(rect, kStopButton);
	fStopButton->ResizeTo(buttonWidth, buttonHeight);
	AddChild(fStopButton);
}