コード例 #1
0
ファイル: DockItem.cpp プロジェクト: HaikuArchives/LaunchPad
void
DockItem::GetGenericIcon( void )
{
	if ( IsFolder() ) {
		BMimeType type;
		type.SetType( "application/x-vnd.Be-directory" );
		type.GetIcon( mLargeIcon, B_LARGE_ICON );
		type.GetIcon( mSmallIcon, B_MINI_ICON );
	} else {
		app_info appInfo;
		BFile appFile;
		BAppFileInfo appFileInfo;
		be_app->GetAppInfo( &appInfo );
		appFile.SetTo( &appInfo.ref, B_READ_WRITE );
		appFileInfo.SetTo( &appFile );
		appFileInfo.GetIconForType( "application/x-be-executable", mLargeIcon, B_LARGE_ICON );
		appFileInfo.GetIconForType( "application/x-be-executable", mSmallIcon, B_MINI_ICON );
		/*
		BMimeType appType;
		appType.SetType( "application/x-vnd.HK-LaunchPad" );
		appType.GetIcon( mLargeIcon, B_LARGE_ICON );
		appType.GetIcon( mSmallIcon, B_MINI_ICON );
		*/
	}
}
コード例 #2
0
status_t
icon_for_type(const BMimeType& type, uint8** _data, size_t* _size,
	icon_source* _source)
{
	if (_data == NULL || _size == NULL)
		return B_BAD_VALUE;

	icon_source source = kNoIcon;
	uint8* data;
	size_t size;

	if (type.GetIcon(&data, &size) == B_OK)
		source = kOwnIcon;

	if (source == kNoIcon) {
		// check for icon from preferred app

		char preferred[B_MIME_TYPE_LENGTH];
		if (type.GetPreferredApp(preferred) == B_OK) {
			BMimeType preferredApp(preferred);

			if (preferredApp.GetIconForType(type.Type(), &data, &size) == B_OK)
				source = kApplicationIcon;
		}
	}

	if (source == kNoIcon) {
		// check super type for an icon

		BMimeType superType;
		if (type.GetSupertype(&superType) == B_OK) {
			if (superType.GetIcon(&data, &size) == B_OK)
				source = kSupertypeIcon;
			else {
				// check the super type's preferred app
				char preferred[B_MIME_TYPE_LENGTH];
				if (superType.GetPreferredApp(preferred) == B_OK) {
					BMimeType preferredApp(preferred);

					if (preferredApp.GetIconForType(superType.Type(),
							&data, &size) == B_OK)
						source = kSupertypeIcon;
				}
			}
		}
	}

	if (source != kNoIcon) {
		*_data = data;
		*_size = size;
	} // NOTE: else there is no data, so nothing is leaked.
	if (_source)
		*_source = source;

	return source != kNoIcon ? B_OK : B_ERROR;
}
コード例 #3
0
ファイル: Enclosures.cpp プロジェクト: mmanley/Antares
static status_t 
GetTrackerIcon(BMimeType &type, BBitmap *icon, icon_size iconSize)
{
	// set some icon size related variables
	status_t error = B_OK;
	BRect bounds;
	switch (iconSize) {
		case B_MINI_ICON:
			bounds.Set(0, 0, 15, 15);
			break;
		case B_LARGE_ICON:
			bounds.Set(0, 0, 31, 31);
			break;
		default:
			error = B_BAD_VALUE;
			break;
	}
	// check parameters and initialization
	if (error == B_OK
		&& (!icon || icon->InitCheck() != B_OK || icon->Bounds() != bounds))
		return B_BAD_VALUE;

	bool success = false;

	// Ask the MIME database for the preferred application for the file type
	// and whether this application has a special icon for the type.
	char signature[B_MIME_TYPE_LENGTH];
	if (type.GetPreferredApp(signature) == B_OK) {
		BMimeType type(signature);
		success = (type.GetIconForType(type.Type(), icon, iconSize) == B_OK);
	}

	// Ask the MIME database whether there is an icon for the node's file type.
	if (error == B_OK && !success)
		success = (type.GetIcon(icon, iconSize) == B_OK);

	// Ask the MIME database for the super type and start all over
	if (error == B_OK && !success) {
		BMimeType super;
		if (type.GetSupertype(&super) == B_OK)
			return GetTrackerIcon(super, icon, iconSize);
	}

	// Return the icon for "application/octet-stream" from the MIME database.
	if (error == B_OK && !success) {
		// get the "application/octet-stream" icon
		BMimeType type("application/octet-stream");
		error = type.GetIcon(icon, iconSize);
	}

	return error;
}
コード例 #4
0
IconMenuItem::IconMenuItem(BMenu* submenu, BMessage* message,
                           const char* iconType, icon_size which)
    :
    PositionPassingMenuItem(submenu, message),
    fDeviceIcon(NULL),
    fHeightDelta(0),
    fWhich(which)
{
    BMimeType mime(iconType);
    fDeviceIcon = new BBitmap(BRect(0, 0, which - 1, which - 1),
                              kDefaultIconDepth);

    if (mime.GetIcon(fDeviceIcon, which) != B_OK) {
        BMimeType super;
        mime.GetSupertype(&super);
        if (super.GetIcon(fDeviceIcon, which) != B_OK) {
            delete fDeviceIcon;
            fDeviceIcon = NULL;
        }
    }

    // IconMenuItem is used in synchronously invoked menus, make sure
    // we invoke with a timeout
    SetTimeout(kSynchMenuInvokeTimeout);
}
コード例 #5
0
status_t
icon_for_type(const BMimeType& type, BBitmap& bitmap, icon_size size,
	icon_source* _source)
{
	icon_source source = kNoIcon;

	if (type.GetIcon(&bitmap, size) == B_OK)
		source = kOwnIcon;

	if (source == kNoIcon) {
		// check for icon from preferred app

		char preferred[B_MIME_TYPE_LENGTH];
		if (type.GetPreferredApp(preferred) == B_OK) {
			BMimeType preferredApp(preferred);

			if (preferredApp.GetIconForType(type.Type(), &bitmap, size) == B_OK)
				source = kApplicationIcon;
		}
	}

	if (source == kNoIcon) {
		// check super type for an icon

		BMimeType superType;
		if (type.GetSupertype(&superType) == B_OK) {
			if (superType.GetIcon(&bitmap, size) == B_OK)
				source = kSupertypeIcon;
			else {
				// check the super type's preferred app
				char preferred[B_MIME_TYPE_LENGTH];
				if (superType.GetPreferredApp(preferred) == B_OK) {
					BMimeType preferredApp(preferred);

					if (preferredApp.GetIconForType(superType.Type(),
							&bitmap, size) == B_OK)
						source = kSupertypeIcon;
				}
			}
		}
	}

	if (_source)
		*_source = source;

	return source != kNoIcon ? B_OK : B_ERROR;
}
コード例 #6
0
ファイル: BarApp.cpp プロジェクト: kbjava/haiku
void
TBarApp::FetchAppIcon(BarTeamInfo* barInfo)
{
	int32 width = IconSize();
	int32 index = (width - kMinimumIconSize) / kIconSizeInterval;

	// first look in the icon cache
	barInfo->icon = barInfo->iconCache[index];
	if (barInfo->icon != NULL)
		return;

	// icon wasn't in cache, get it from be_roster and cache it
	app_info appInfo;
	icon_size size = width >= 31 ? B_LARGE_ICON : B_MINI_ICON;
	BBitmap* icon = new BBitmap(IconRect(), kIconColorSpace);
	if (be_roster->GetAppInfo(barInfo->sig, &appInfo) == B_OK) {
		// fetch the app icon
		BFile file(&appInfo.ref, B_READ_ONLY);
		BAppFileInfo appMime(&file);
		if (appMime.GetIcon(icon, size) == B_OK) {
			delete barInfo->iconCache[index];
			barInfo->iconCache[index] = barInfo->icon = icon;
			return;
		}
	}

	// couldn't find the app icon
	// fetch the generic 3 boxes icon and cache it
	BMimeType defaultAppMime;
	defaultAppMime.SetTo(B_APP_MIME_TYPE);
	if (defaultAppMime.GetIcon(icon, size) == B_OK) {
		delete barInfo->iconCache[index];
		barInfo->iconCache[index] = barInfo->icon = icon;
		return;
	}

	// couldn't find generic 3 boxes icon
	// fill with transparent
	uint8* iconBits = (uint8*)icon->Bits();
	if (icon->ColorSpace() == B_RGBA32) {
		int32 i = 0;
		while (i < icon->BitsLength()) {
			iconBits[i++] = B_TRANSPARENT_32_BIT.red;
			iconBits[i++] = B_TRANSPARENT_32_BIT.green;
			iconBits[i++] = B_TRANSPARENT_32_BIT.blue;
			iconBits[i++] = B_TRANSPARENT_32_BIT.alpha;
		}
	} else {
		// Assume B_CMAP8
		for (int32 i = 0; i < icon->BitsLength(); i++)
			iconBits[i] = B_TRANSPARENT_MAGIC_CMAP8;
	}

	delete barInfo->iconCache[index];
	barInfo->iconCache[index] = barInfo->icon = icon;
}
コード例 #7
0
ファイル: InfoWin.cpp プロジェクト: AmirAbrams/haiku
status_t
IconView::SetIcon(const char* mimeTypeString)
{
	if (!mimeTypeString)
		return B_BAD_VALUE;

	// get type icon
	BMimeType mimeType(mimeTypeString);
	status_t status = mimeType.GetIcon(fIconBitmap, B_LARGE_ICON);

	// get supertype icon
	if (status != B_OK) {
		BMimeType superType;
		status = mimeType.GetSupertype(&superType);
		if (status == B_OK)
			status = superType.GetIcon(fIconBitmap, B_LARGE_ICON);
	}

	return status;
}
コード例 #8
0
ファイル: BarApp.cpp プロジェクト: nielx/haiku-serviceskit
void
TBarApp::FetchAppIcon(const char* signature, BBitmap* icon)
{
	app_info appInfo;
	icon_size size = icon->Bounds().IntegerHeight() >= 32
		? B_LARGE_ICON : B_MINI_ICON;

	if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) {
		// fetch the app icon
		BFile file(&appInfo.ref, B_READ_ONLY);
		BAppFileInfo appMime(&file);
		if (appMime.GetIcon(icon, size) == B_OK)
			return;
	}

	// couldn't find the app icon
	// fetch the generic 3 boxes icon
	BMimeType defaultAppMime;
	defaultAppMime.SetTo(B_APP_MIME_TYPE);
	if (defaultAppMime.GetIcon(icon, size) == B_OK)
		return;

	// couldn't find generic 3 boxes icon
	// fill with transparent
	uint8* iconBits = (uint8*)icon->Bits();
	if (icon->ColorSpace() == B_RGBA32) {
		int32 i = 0;
		while (i < icon->BitsLength()) {
			iconBits[i++] = B_TRANSPARENT_32_BIT.red;
			iconBits[i++] = B_TRANSPARENT_32_BIT.green;
			iconBits[i++] = B_TRANSPARENT_32_BIT.blue;
			iconBits[i++] = B_TRANSPARENT_32_BIT.alpha;
		}
	} else {
		// Assume B_CMAP8
		for (int32 i = 0; i < icon->BitsLength(); i++)
			iconBits[i] = B_TRANSPARENT_MAGIC_CMAP8;
	}
}