status_t
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);

	if (res == B_OK) {
		res = rsrc.AddResource('CADA', mangledLanguage,
			mallocIO.Buffer(), mallocIO.BufferLength(),
			BString(fLanguageName));
	}

	return res;
}
Пример #2
0
int32
Project::UpdateAttributes(void)
{
	BResources res;
	
	BPath path(fPath.GetFolder());
	path.Append(GetTargetName());
	
	BFile file(path.Path(), B_READ_WRITE);
	if (file.InitCheck() != B_OK)
		return B_BAD_VALUE;
	
	if (res.SetTo(&file) != B_OK)
		return B_ERROR;
	
	ResourceToAttribute(file,res,'MIMS',"BEOS:APP_SIG");
	ResourceToAttribute(file,res,'MIMS',"BEOS:TYPE");
	ResourceToAttribute(file,res,'MSGG',"BEOS:FILE_TYPES");
	ResourceToAttribute(file,res,'APPV',"BEOS:APP_VERSION");
	ResourceToAttribute(file,res,'APPF',"BEOS:APP_FLAGS");
	ResourceToAttribute(file,res,'ICON',"BEOS:L:STD_ICON");
	ResourceToAttribute(file,res,'MICN',"BEOS:M:STD_ICON");
	ResourceToAttribute(file,res,'VICN',"BEOS:ICON");
	
	return B_OK;
}
Пример #3
0
BBitmap*
MediaAlert::InitIcon()
{
	// The alert icons are in the app_server resources
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
			BResources resources;
			if (resources.SetTo(&file) == B_OK) {
				// Which icon are we trying to load?
				const char* iconName = "warn";

				// Load the raw icon data
				size_t size;
				const void* rawIcon =
					resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size);

				if (rawIcon != NULL) {
					// Now build the bitmap
					icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
					if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
							icon) != B_OK) {
						delete icon;
						return NULL;
					}
				}
			}
		}
	}

	return icon;
}
Пример #4
0
BBitmap * BitmapUtils::LoadFromResource(int32 id)
{
	BArchivable *archivable;
	BResources resources;
	BMessage message;
	const void *data;
	BBitmap *bitmap;
	app_info info;
	BFile file;
	size_t len;

	if (be_app->GetAppInfo(&info) != B_OK) return NULL;
	if (file.SetTo(&(info.ref), B_READ_ONLY) != B_OK) return NULL;
	if (resources.SetTo(&file, false) != B_OK) return NULL;
	data = resources.LoadResource('BBMP', id, &len);
	if (data == NULL || len <= 0) return NULL;
	if (message.Unflatten((const char *)data) != B_OK) return NULL;
	archivable = BBitmap::Instantiate(&message);
	if (archivable == NULL) return NULL;
	bitmap = dynamic_cast<BBitmap*>(archivable);
	if (bitmap == NULL) {
		delete archivable;
		return NULL;
	}
	return bitmap;
}
Пример #5
0
status_t
DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	if (res == B_OK) {
		res = rsrc.AddResource(B_MESSAGE_TYPE, BLocaleRoster::kEmbeddedCatResId,
			mallocIO.Buffer(), mallocIO.BufferLength(), "embedded catalog");
	}

	return res;
}
Пример #6
0
BBitmap*
AlertView::InitIcon()
{
	// This is how BAlert gets to its icon
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BResources resources;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& resources.SetTo(&file) == B_OK) {
			size_t size;
			const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
				"warn", &size);
			if (data) {
				icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
				if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
						!= B_OK) {
					delete icon;
					icon = NULL;
				}
			}
		}
	}

	return icon;
}
Пример #7
0
// read_boot_code_data
static uint8 *
read_boot_code_data(const char* programPath)
{
	// open our executable
	BFile executableFile;
	status_t error = executableFile.SetTo(programPath, B_READ_ONLY);
	if (error != B_OK) {
		fprintf(stderr, "Error: Failed to open my executable file (\"%s\": "
			"%s\n", programPath, strerror(error));
		exit(1);
	}

	uint8 *bootCodeData = new uint8[kBootCodeSize];

	// open our resources
	BResources resources;
	error = resources.SetTo(&executableFile);
	const void *resourceData = NULL;
	if (error == B_OK) {
		// read the boot block from the resources
		size_t resourceSize;
		resourceData = resources.LoadResource(B_RAW_TYPE, 666, &resourceSize);

		if (resourceData && resourceSize != (size_t)kBootCodeSize) {
			resourceData = NULL;
			printf("Warning: Something is fishy with my resources! The boot "
				"code doesn't have the correct size. Trying the attribute "
				"instead ...\n");
		}
	}

	if (resourceData) {
		// found boot data in the resources
		memcpy(bootCodeData, resourceData, kBootCodeSize);
	} else {
		// no boot data in the resources; try the attribute
		ssize_t bytesRead = executableFile.ReadAttr("BootCode", B_RAW_TYPE,
			0, bootCodeData, kBootCodeSize);
		if (bytesRead < 0) {
			fprintf(stderr, "Error: Failed to read boot code from resources "
				"or attribute.\n");
			exit(1);
		}
		if (bytesRead != kBootCodeSize) {
			fprintf(stderr, "Error: Failed to read boot code from resources, "
				"and the boot code in the attribute has the wrong size!\n");
			exit(1);
		}
	}

	return bootCodeData;
}
Пример #8
0
DeviceWatcher::DeviceWatcher()
	: BLooper("MIDI devices watcher"),
	fDeviceEndpointsMap(), fVectorIconData(NULL), fVectorIconDataSize(0),
	fLargeIcon(NULL), fMiniIcon(NULL)
{
	// Load midi endpoint vector icon data
	app_info info;
	be_app->GetAppInfo(&info);
	BFile file(&info.ref, B_READ_ONLY);

	BResources resources;
	if (resources.SetTo(&file) == B_OK) {
		size_t dataSize;
		// Load MIDI port endpoint vector icon
		const uint8* data = (const uint8*)resources.LoadResource(
			B_VECTOR_ICON_TYPE,	"endpoint_vector_icon", &dataSize);

		if (data != NULL && dataSize > 0)
			fVectorIconData = new(std::nothrow) uint8[dataSize];

		if (fVectorIconData) {
			// data is own by resources local object: copy its content for
			// later use
			memcpy(fVectorIconData, data, dataSize);
			fVectorIconDataSize = dataSize;
		}
	}

	// Render 32x32 and 16x16 B_CMAP8 icons for R5 compatibility
	if (fVectorIconData != NULL) {
		fLargeIcon = new(std::nothrow) BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
		fMiniIcon  = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), B_CMAP8);

		if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
			fLargeIcon) != B_OK) {
			delete fLargeIcon;
			fLargeIcon = NULL;
		}
		if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
			fMiniIcon) != B_OK) {
			delete fMiniIcon;
			fMiniIcon = NULL;
		}
	}

	Start();
}
Пример #9
0
static status_t
open_output_file()
{
	status_t err = entry.SetTo(rsrc_file, true);
	if (err == B_OK) {
		uint32 openMode = B_READ_WRITE | B_CREATE_FILE;
		bool clobber = false;

		if (!(flags & RDEF_MERGE_RESOURCES)) {
			openMode |= B_ERASE_FILE;
			clobber   = true;
		}

		err = file.SetTo(&entry, openMode);
		if (err == B_OK)
			err = rsrc.SetTo(&file, clobber);
	}

	return err;
}
Пример #10
0
BBitmap *GetCicnFromResource(const char *theResource)
{	
	// Get application info
	app_info info;
	
	be_app->GetAppInfo(&info);
	BFile file(&info.ref, O_RDONLY);	
	if (file.InitCheck())
		return NULL;
	
	size_t 		size;
	cicn 		*icon;
	
	BResources res; 
	status_t err; 
	if ( (err = res.SetTo(&file)) != B_NO_ERROR ) 
		return NULL;
		
	icon = (cicn *)res.FindResource('cicn', theResource, &size);
	if (!icon)			
		return NULL;
			
	// 	Swap bytes if needed.  We do this because the resources are currently
	// 	built on Macintosh BeOS
	if (B_HOST_IS_LENDIAN)
	{
		status_t retVal;
		retVal = swap_data(B_INT16_TYPE, &icon->width, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);		
		retVal = swap_data(B_INT16_TYPE, &icon->height, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);
	}
	
	// Get cicn bounding rect
	BRect bounds(0, 0, icon->width-1, icon->height-1);
		
	// Load bitmap
	BBitmap *bitmap = new BBitmap(bounds, B_COLOR_8_BIT);
	ASSERT(bitmap);
	bitmap->SetBits(&icon->data, size - sizeof(int16)*2, 0, B_COLOR_8_BIT);
	
	return (bitmap);	
}
Пример #11
0
void
ResView::OpenFile(const entry_ref &ref)
{
	// Add all the 133t resources and attributes of the file
	BFile file(&ref, B_READ_ONLY);
	BResources resources;
	if (resources.SetTo(&file) != B_OK)
		return;
	file.Unset();
	
	resources.PreloadResourceType();
	
	int32 index = 0;
	ResDataRow *row;
	ResourceData *resData = new ResourceData();
	while (resData->SetFromResource(index, resources)) {
		row = new ResDataRow(resData);
		fListView->AddRow(row);
		fDataList.AddItem(resData);
		resData = new ResourceData();
		index++;
	}
	delete resData;

	BNode node;
	if (node.SetTo(&ref) == B_OK) {
		char attrName[B_ATTR_NAME_LENGTH];
		node.RewindAttrs();
		resData = new ResourceData();
		while (node.GetNextAttrName(attrName) == B_OK) {
			if (resData->SetFromAttribute(attrName, node)) {
				row = new ResDataRow(resData);
				fListView->AddRow(row);
				fDataList.AddItem(resData);
				resData = new ResourceData();
			}
		}
		delete resData;
	}
}
Пример #12
0
BBitmap* MainWindow::ResourceVectorToBitmap(const char *resName, float iconSize)
{
	BResources res;
	size_t size;
	app_info appInfo;

	be_app->GetAppInfo(&appInfo);
	BFile appFile(&appInfo.ref, B_READ_ONLY);
	res.SetTo(&appFile);
	BBitmap *aBmp = NULL;
	const uint8* iconData = (const uint8*) res.LoadResource('VICN', resName, &size);

	if (size > 0 ) {
		aBmp = new BBitmap (BRect(0,0, iconSize, iconSize), 0, B_RGBA32);
		status_t result = BIconUtils::GetVectorIcon(iconData, size, aBmp);
		if (result != B_OK) {
			delete aBmp;
			aBmp = NULL;
		}
	}
	return aBmp;
}
Пример #13
0
void PanelView::LoadResources(void)
////////////////////////////////////////////////////////////////////////
{
	entry_ref	ref;
	app_info 	info;

	m_ParentIcon = NULL;
	m_UnknownIcon = NULL;

	if (be_app->GetAppInfo(&info)==B_OK)
	{
		BFile file(&info.ref, B_READ_ONLY);
		
		if (file.InitCheck()==B_OK)
		{
			BResources rsrcs;
			size_t len = 0;
			
			if (rsrcs.SetTo(&file)==B_OK)
			{
				const void *data;
				data = rsrcs.LoadResource('MICN',1,&len);
				if (data)
				{
					m_ParentIcon = new unsigned char[len];
					memcpy(m_ParentIcon,data,len);
				}					

				data = rsrcs.LoadResource('MICN',2,&len);
				if (data)
				{
					m_UnknownIcon = new unsigned char[len];
					memcpy(m_UnknownIcon,data,len);
				}
			}
		}
	}	
}
Пример #14
0
status_t
DefaultCatalog::ReadFromResource(entry_ref *appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(appOrAddOnRef, B_READ_ONLY);
	if (res != B_OK) {
		log_team(LOG_ERR,
			"couldn't find app or add-on (dev=%lu, dir=%Lu, name=%s)",
			appOrAddOnRef->device, appOrAddOnRef->directory,
			appOrAddOnRef->name);
		return B_ENTRY_NOT_FOUND;
	}

	log_team(LOG_DEBUG,
		"looking for embedded catalog-resource in app/add-on"
		"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device,
		appOrAddOnRef->directory, appOrAddOnRef->name);

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK) {
		log_team(LOG_DEBUG, "file has no resources");
		return res;
	}

	size_t sz;
	const void *buf = rsrc.LoadResource(B_MESSAGE_TYPE,
		BLocaleRoster::kEmbeddedCatResId, &sz);
	if (!buf) {
		log_team(LOG_DEBUG, "file has no catalog-resource");
		return B_NAME_NOT_FOUND;
	}

	BMemoryIO memIO(buf, sz);
	res = Unflatten(&memIO);

	return res;
}
status_t
DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_ONLY);
	if (res != B_OK)
		return B_ENTRY_NOT_FOUND;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	size_t sz;
	const void *buf = rsrc.LoadResource('CADA', fLanguageName, &sz);
	if (!buf)
		return B_NAME_NOT_FOUND;

	BMemoryIO memIO(buf, sz);
	res = Unflatten(&memIO);

	return res;
}
Пример #16
0
// fill out the icons with the stop and warn symbols from app_server
void
ConflictView::_FillIcons()
{
	// return if the icons have already been filled out
	if (fStopIcon != NULL && fStopIcon->InitCheck() == B_OK
		&& fWarnIcon != NULL && fWarnIcon->InitCheck() == B_OK) {
		return;
	}

	BPath path;
	status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
	if (status < B_OK) {
		FTRACE((stderr,
			"_FillIcons() - find_directory failed: %s\n",
			strerror(status)));
		return;
	}

	path.Append("app_server");
	BFile file;
	status = file.SetTo(path.Path(), B_READ_ONLY);
	if (status < B_OK) {
		FTRACE((stderr,
			"_FillIcons() - BFile init failed: %s\n",
			strerror(status)));
		return;
	}

	BResources resources;
	status = resources.SetTo(&file);
	if (status < B_OK) {
		FTRACE((stderr,
			"_FillIcons() - BResources init failed: %s\n",
			strerror(status)));
		return;
	}

	size_t size = 0;

	if (fStopIcon == NULL) {
		// Allocate the fStopIcon bitmap
		fStopIcon = new (std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0,
			B_RGBA32);
		if (fStopIcon->InitCheck() != B_OK) {
			FTRACE((stderr, "_FillIcons() - No memory for stop bitmap\n"));
			delete fStopIcon;
			fStopIcon = NULL;
			return;
		}

		// load stop icon bitmap from app_server
		const uint8* stopVector
			= (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, "stop",
				&size);
		if (stopVector == NULL
			|| BIconUtils::GetVectorIcon(stopVector, size, fStopIcon)
				!= B_OK) {
			delete fStopIcon;
			fStopIcon = NULL;
		}
	}

	if (fWarnIcon == NULL) {
		// Allocate the fWarnIcon bitmap
		fWarnIcon = new (std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0,
			B_RGBA32);
		if (fWarnIcon->InitCheck() != B_OK) {
			FTRACE((stderr, "_FillIcons() - No memory for warn bitmap\n"));
			delete fWarnIcon;
			fWarnIcon = NULL;
			return;
		}

		// load warn icon bitmap from app_server
		const uint8* warnVector
			= (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, "warn",
				&size);
		if (warnVector == NULL
			|| BIconUtils::GetVectorIcon(warnVector, size, fWarnIcon)
				!= B_OK) {
			delete fWarnIcon;
			fWarnIcon = NULL;
		}
	}
}
Пример #17
0
BBitmap*
BAlert::_InitIcon()
{
	// Save the desired alert type and set it to "empty" until
	// loading the icon was successful
	alert_type alertType = fMsgType;
	fMsgType = B_EMPTY_ALERT;

	// After a bit of a search, I found the icons in app_server. =P
	BBitmap* icon = NULL;
	BPath path;
	status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
	if (status < B_OK) {
		FTRACE((stderr, "BAlert::_InitIcon() - find_directory failed: %s\n",
			strerror(status)));
		return NULL;
	}

	path.Append("app_server");
	BFile file;
	status = file.SetTo(path.Path(), B_READ_ONLY);
	if (status < B_OK) {
		FTRACE((stderr, "BAlert::_InitIcon() - BFile init failed: %s\n",
			strerror(status)));
		return NULL;
	}

	BResources resources;
	status = resources.SetTo(&file);
	if (status < B_OK) {
		FTRACE((stderr, "BAlert::_InitIcon() - BResources init failed: %s\n",
			strerror(status)));
		return NULL;
	}

	// Which icon are we trying to load?
	const char* iconName = "";	// Don't want any seg faults
	switch (alertType) {
		case B_INFO_ALERT:
			iconName = "info";
			break;
		case B_IDEA_ALERT:
			iconName = "idea";
			break;
		case B_WARNING_ALERT:
			iconName = "warn";
			break;
		case B_STOP_ALERT:
			iconName = "stop";
			break;

		default:
			// Alert type is either invalid or B_EMPTY_ALERT;
			// either way, we're not going to load an icon
			return NULL;
	}

	int32 iconSize = 32 * icon_layout_scale();
	// Allocate the icon bitmap
	icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
		0, B_RGBA32);
	if (icon == NULL || icon->InitCheck() < B_OK) {
		FTRACE((stderr, "BAlert::_InitIcon() - No memory for bitmap\n"));
		delete icon;
		return NULL;
	}

	// Load the raw icon data
	size_t size = 0;
	const uint8* rawIcon;

#ifdef __ANTARES__
	// Try to load vector icon
	rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
		iconName, &size);
	if (rawIcon != NULL
		&& BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK) {
		// We have an icon, restore the saved alert type
		fMsgType = alertType;
		return icon;
	}
#endif

	// Fall back to bitmap icon
	rawIcon = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE,
		iconName, &size);
	if (rawIcon == NULL) {
		FTRACE((stderr, "BAlert::_InitIcon() - Icon resource not found\n"));
		delete icon;
		return NULL;
	}

	// Handle color space conversion
#ifdef __ANTARES__
	if (icon->ColorSpace() != B_CMAP8) {
		BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize,
			iconSize, icon);
	}
#else
	icon->SetBits(rawIcon, iconSize, 0, B_CMAP8);
#endif

	// We have an icon, restore the saved alert type
	fMsgType = alertType;

	return icon;
}
Пример #18
0
void BeGadu::MessageReceived( BMessage *aMessage ) {
	switch( aMessage->what ) {
		/* sending mesgs from libgadu to network */
		case GOT_MESSAGE:
		case ADD_HANDLER:
		case DEL_HANDLER:
			BMessenger( iWindow->GetNetwork() ).SendMessage( aMessage );
			break;
		case ADD_MESSENGER:
			DEBUG_TRACE( "BeGadu::MessageReceived( ADD_MESSENGER )\n" );
			aMessage->FindMessenger( "messenger", &iMessenger );
			if( iWindow ) {
				iWindow->SetMessenger( iMessenger );
				BMessenger( iMessenger ).SendMessage( PROFILE_SELECTED );
			}
			break;
		case SET_AVAIL:
		case SET_BRB:
		case SET_INVIS:
		case SET_NOT_AVAIL:
		case SET_DESCRIPTION:
		case BEGG_ABOUT:
		case SHOW_MAIN_WINDOW:
		case CHANGE_DESCRIPTION:
		case PREFERENCES_SWITCH:
			if( iWindow )
				BMessenger( iWindow ).SendMessage( aMessage );
			break;
		case OPEN_PROFILE_WIZARD:
			{
			DEBUG_TRACE( "BeGadu::MessageReceived( OPEN_PROFILE_WIZARD )\n" );
//			if( iProfileSelector )
//				iProfileSelector = NULL;
			if( iWindow ) {
				BMessenger( iWindow ).SendMessage( new BMessage( CLOSE_MAIN_WINDOW ) );
				if( iWindow->Lock() )
					iWindow->Quit();
				iWindow = NULL;
			}
			ProfileWizard *pw = new ProfileWizard();
			pw->Show();
			break;
			}
		case CONFIG_OK:
			{
			DEBUG_TRACE( "BeGadu::MessageReceived( CONFIG_OK )\n" );
			iReadyToRun = true;
			AddDeskbarIcon();
			Profile *profile = new Profile();
			int ret = profile->Load( iLastProfile );
			if( ret != 0 ) {
				delete profile;
				BMessenger( be_app ).SendMessage( new BMessage( PROFILE_SELECT ) );
				break;
			}
			if( strcmp( profile->GetProfilePassword(), "" ) != 0 ) {
				BResources res;
				BRoster roster;
				entry_ref ref;
				BFile resfile;
				roster.FindApp( APP_MIME, &ref );
				resfile.SetTo( &ref, B_READ_ONLY );
				res.SetTo( &resfile );
				BScreen *screen = new BScreen( B_MAIN_SCREEN_ID );
				display_mode mode;
				screen->GetMode( &mode );
//				int32 width = 250;
//				int32 height = 110; // 70
//				int32 x_wind = mode.timing.h_display / 2 - ( width / 2);
//				int32 y_wind = mode.timing.v_display / 2 - ( height / 2 );
//				int32 new_width = x_wind + width;	// x 2
//				int32 new_height = y_wind + height;		// x 2
				BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) );
//				iProfileSelector = new ProfileSelector( iLastProfile, BRect( x_wind, y_wind, new_width, new_height ), &res );
//				if( iProfileSelector->LockLooper() ) {
//					iProfileSelector->Show();
//					iProfileSelector->UnlockLooper();
//				}
			} else {
				BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) );
				iWindow = new MainWindow( iLastProfile );
				if( !iHideAtStart ) {
					if( iWindow->LockLooper() ) {
						iWindow->Show();
						iWindow->UnlockLooper();
					}
				} else {
					if( iWindow->LockLooper() ) {
						iWindow->Show();
						iWindow->Hide();
						iWindow->UnlockLooper();
					}
				}
			}
			break;
			}
		case PROFILE_CREATED:
			DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_CREATED )\n" );
			iReadyToRun = true;
			AddDeskbarIcon();
			aMessage->FindString( "ProfileName", iLastProfile );
			fprintf( stderr, _T("Setting last profile to %s\n"), iLastProfile->String() );
			iFirstRun = false;
			BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) );
			iWindow = new MainWindow( iLastProfile );
			if( iWindow->LockLooper() ) {
				if( iWindow->IsHidden() )
					iWindow->Show();
				else
					iWindow->Activate();
				iWindow->UnlockLooper();
			}
			break;
		case PROFILE_SELECT:
			DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SELECT )\n" );
//			if( iProfileSelector )
//				iProfileSelector->Activate();
//			else
				{
				BResources res;
				BRoster roster;
				entry_ref ref;
				BFile resfile;
				roster.FindApp( APP_MIME, &ref );
				resfile.SetTo( &ref, B_READ_ONLY );
				res.SetTo( &resfile );
				BScreen *screen = new BScreen( B_MAIN_SCREEN_ID );
				display_mode mode;
				screen->GetMode( &mode );
//				int32 width = 250;
//				int32 height = 110; // 70
//				int32 x_wind = mode.timing.h_display / 2 - ( width / 2);
//				int32 y_wind = mode.timing.v_display / 2 - ( height / 2 );
//				int32 new_width = x_wind + width;	// x 2
//				int32 new_height = y_wind + height;		// x 2
				BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) );
//				iProfileSelector = new ProfileSelector( iLastProfile, BRect( x_wind, y_wind, new_width, new_height ), &res );
//				if( iProfileSelector->LockLooper() ) {
//					iProfileSelector->Show();
//					iProfileSelector->UnlockLooper();
//				}
			}
			break;
		case PROFILE_SWITCH:
			{
			DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SWITCH )\n" );
			if( iWindow ) {
				BMessenger( iWindow ).SendMessage( new BMessage( CLOSE_MAIN_WINDOW ) );
				if( iWindow->Lock() )
					iWindow->Quit();
				iWindow = NULL;
			}
			Profile* profile = new Profile();
			BString* name = new BString( "" );
			aMessage->FindString( "iProfileName", name );
			int ret = profile->Load( name );
			if( ret != 0 ) {
				delete profile;
				BMessenger( this ).SendMessage( new BMessage( PROFILE_SELECT ) );
				break;
			}
			// XXX loaded profile password empty?
			if( strcmp( profile->GetProfilePassword(), "" ) == 0 ) {
				BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) );
				iWindow = new MainWindow( iLastProfile );
//				iWindow = new MainWindow( name );
				if( iWindow->LockLooper() ) {
					iWindow->Show();
					iWindow->UnlockLooper();
				}
			} else {
			// XXX what's that for?
				BResources res;
				BRoster roster;
				entry_ref ref;
				BFile resfile;
				roster.FindApp( APP_MIME, &ref );
				resfile.SetTo( &ref, B_READ_ONLY );
				res.SetTo( &resfile );
				BScreen *screen = new BScreen( B_MAIN_SCREEN_ID );
				display_mode mode;
				screen->GetMode( &mode );
//				int32 width = 250;
//				int32 height = 110; // 70
//				int32 x_wind = mode.timing.h_display / 2 - ( width / 2);
//				int32 y_wind = mode.timing.v_display / 2 - ( height / 2 );
//				int32 new_width = x_wind + width;	// x 2
//				int32 new_height = y_wind + height;		// x 2
				BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) );
//				iProfileSelector = new ProfileSelector( name, BRect( x_wind, y_wind, new_width, new_height ), &res );
//				if( iProfileSelector->LockLooper() ) {
//					iProfileSelector->Show();
//					iProfileSelector->UnlockLooper();
//				}
			}
			break;
			}
		case PROFILE_SELECTED:
			{
			DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_SELECTED )\n" );
//			if( iProfileSelector )
//				iProfileSelector = NULL;
			BString *profile = new BString( "" );
			aMessage->FindString( "iProfileName", profile );
			BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_SELECTED ) );
			iWindow = new MainWindow( profile );
			if( !iHideAtStart ) {
				if( iWindow->LockLooper() ) {
					iWindow->Show();
					iWindow->UnlockLooper();
				}
			} else {
				if( iWindow->LockLooper() ) {
					iWindow->Show();
					iWindow->Hide();
					iWindow->UnlockLooper();
				}
			}
			break;
			}
		case PROFILE_NOT_SELECTED:
			DEBUG_TRACE( "BeGadu::MessageReceived( PROFILE_NOT_SELECTED )\n" );
//			if( iProfileSelector )
//				iProfileSelector = NULL;
			BMessenger( iMessenger ).SendMessage( new BMessage( PROFILE_NOT_SELECTED ) );
			break;
		case BEGG_QUIT:
			DEBUG_TRACE( "BeGadu::MessageReceived( BEGG_QUIT )\n" );
			if( iWindow )
				BMessenger( iWindow ).SendMessage( aMessage );
			else
				BMessenger( be_app ).SendMessage( B_QUIT_REQUESTED );
			break;
		default:
			BApplication::MessageReceived( aMessage );
			break;
		}
}
Пример #19
0
// fill out the icon with the stop symbol from app_server
void
ConflictView::_FillSavedIcon()
{
    // return if the fSavedIcon has already been filled out
    if (fSavedIcon != NULL && fSavedIcon->InitCheck() == B_OK)
        return;

    BPath path;
    status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
    if (status < B_OK) {
        FTRACE((stderr,
                "_FillWarningIcon() - find_directory failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    path.Append("app_server");
    BFile file;
    status = file.SetTo(path.Path(), B_READ_ONLY);
    if (status < B_OK) {
        FTRACE((stderr,
                "_FillWarningIcon() - BFile init failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    BResources resources;
    status = resources.SetTo(&file);
    if (status < B_OK) {
        FTRACE((stderr,
                "_WarningIcon() - BResources init failed: %s\n",
                strerror(status)));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    // Allocate the fSavedIcon bitmap
    fSavedIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0, B_RGBA32);
    if (fSavedIcon->InitCheck() < B_OK) {
        FTRACE((stderr, "_WarningIcon() - No memory for warning bitmap\n"));
        delete fSavedIcon;
        fSavedIcon = NULL;
        return;
    }

    // Load the raw stop icon data
    size_t size = 0;
    const uint8* rawIcon;
    rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
              "stop", &size);

    // load vector warning icon into fSavedIcon
    if (rawIcon == NULL
            || BIconUtils::GetVectorIcon(rawIcon, size, fSavedIcon) < B_OK) {
        delete fSavedIcon;
        fSavedIcon = NULL;
    }
}
Пример #20
0
int main(int argc, char *argv[])
{
	yyin = stdin;

	int i = getoptions(argc, argv);

	char buf[PATH_MAX];
	if (out[0] == '/')
		strcpy(buf, out);
	else
	{
		getcwd(buf, PATH_MAX);
		strcat(buf, "/");
		strcat(buf, out);
	}

	BEntry e;
	if (e.SetTo(out)) error("entry set to %s", out);

	BDirectory d;
	if (e.GetParent(&d)) error("get parent of %s", out);
	if ((gTruncate || gSaveAsHeader) && e.Exists() && e.Remove())
		error("removing %s", out);

	BFile f;
	BResources res;

	if (!gDump)
	{
		if (gTruncate || !e.Exists())
		{
			if (d.CreateFile(buf, &f)) error("creating %s", buf);
			gTruncate = true;
		}
		else
			if (f.SetTo(buf, B_READ_WRITE)) error("opening %s", buf);

		if (gSaveAsHeader)
		{
			gHeader = fopen(buf, "w");
			if (!gHeader) error("Error creating %s", buf);
		}
		else if (res.SetTo(&f, gTruncate) != B_NO_ERROR)
			error("opening resource file %s", buf);
	}

	resFile = &res;

	if (i == argc)
		Work(NULL);
	else
	{
		while (i < argc)
			Work(in = argv[i++]);
	}

	if (verbose)
		puts("done");

	if (gHeader)
		fclose(gHeader);
	else
		f.Sync();

	return 0;
} /* main */
Пример #21
0
BBitmap*
BAlert::_CreateTypeIcon()
{
	if (Type() == B_EMPTY_ALERT)
		return NULL;

	// The icons are in the app_server resources
	BBitmap* icon = NULL;
	BPath path;
	status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - find_directory "
			"failed: %s\n", strerror(status)));
		return NULL;
	}

	path.Append("app_server");
	BFile file;
	status = file.SetTo(path.Path(), B_READ_ONLY);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - BFile init failed: %s\n",
			strerror(status)));
		return NULL;
	}

	BResources resources;
	status = resources.SetTo(&file);
	if (status != B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - BResources init "
			"failed: %s\n", strerror(status)));
		return NULL;
	}

	// Which icon are we trying to load?
	const char* iconName;
	switch (fType) {
		case B_INFO_ALERT:
			iconName = "info";
			break;
		case B_IDEA_ALERT:
			iconName = "idea";
			break;
		case B_WARNING_ALERT:
			iconName = "warn";
			break;
		case B_STOP_ALERT:
			iconName = "stop";
			break;

		default:
			// Alert type is either invalid or B_EMPTY_ALERT;
			// either way, we're not going to load an icon
			return NULL;
	}

	int32 iconSize = 32 * icon_layout_scale();
	// Allocate the icon bitmap
	icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
		0, B_RGBA32);
	if (icon == NULL || icon->InitCheck() < B_OK) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - No memory for bitmap\n"));
		delete icon;
		return NULL;
	}

	// Load the raw icon data
	size_t size = 0;
	const uint8* rawIcon;

	// Try to load vector icon
	rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
		iconName, &size);
	if (rawIcon != NULL
		&& BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK) {
		return icon;
	}

	// Fall back to bitmap icon
	rawIcon = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE,
		iconName, &size);
	if (rawIcon == NULL) {
		FTRACE((stderr, "BAlert::_CreateTypeIcon() - Icon resource not found\n"));
		delete icon;
		return NULL;
	}

	// Handle color space conversion
	if (icon->ColorSpace() != B_CMAP8) {
		BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize,
			iconSize, icon);
	}

	return icon;
}