コード例 #1
0
ファイル: TranslationUtils.cpp プロジェクト: mmanley/Antares
// ---------------------------------------------------------------
// GetDefaultSettings
//
// Attempts to find the translator settings for 
// the translator named kTranslatorName with a version of
// translatorVersion.
//
// Preconditions:
//
// Parameters: kTranslatorName, the name of the translator
//                              the settings are for
//             translatorVersion, the version of the translator
//                                to retrieve
//
// Postconditions:
//
// Returns: NULL, if anything went wrong
//          BMessage * of configuration data for kTranslatorName
// ---------------------------------------------------------------
BMessage *
BTranslationUtils::GetDefaultSettings(const char *kTranslatorName,
	int32 translatorVersion)
{
	BTranslatorRoster *roster = BTranslatorRoster::Default();
	translator_id *translators = NULL;
	int32 numTranslators = 0;
	if (roster == NULL
		|| roster->GetAllTranslators(&translators, &numTranslators) != B_OK)
		return NULL;

	// Cycle through all of the default translators
	// looking for a translator that matches the name and version
	// that I was given
	BMessage *pMessage = NULL;
	const char *currentTranName = NULL, *currentTranInfo = NULL;
	int32 currentTranVersion = 0;
	for (int i = 0; i < numTranslators; i++) {

		if (roster->GetTranslatorInfo(translators[i], &currentTranName,
			&currentTranInfo, &currentTranVersion) == B_OK) {

			if (currentTranVersion == translatorVersion
				&& strcmp(currentTranName, kTranslatorName) == 0) {
				pMessage = GetDefaultSettings(translators[i], roster);
				break;				
			}
		}
	}
	
	delete[] translators;
	return pMessage;
}
コード例 #2
0
// Reads the installed translators and adds them to our BListView
status_t
DataTranslationsWindow::_PopulateListView()
{
	BTranslatorRoster* roster = BTranslatorRoster::Default();

	// Get all Translators on the system. Gives us the number of translators
	// installed in num_translators and a reference to the first one
	int32 numTranslators;
	translator_id* translators = NULL;
	roster->GetAllTranslators(&translators, &numTranslators);

	float maxWidth = 0;

	for (int32 i = 0; i < numTranslators; i++) {
		// Getting the first three Infos: Name, Info & Version
		int32 version;
		const char* name;
		const char* info;
		roster->GetTranslatorInfo(translators[i], &name, &info, &version);
		fTranslatorListView->AddItem(new TranslatorItem(translators[i], name));
		maxWidth = std::max(maxWidth, fTranslatorListView->StringWidth(name));
	}

	fTranslatorListView->SortItems();

	fTranslatorListView->SetExplicitSize(BSize(maxWidth + 20, B_SIZE_UNSET));

	delete[] translators;
	return B_OK;
}
コード例 #3
0
ファイル: Utility.cpp プロジェクト: mariuz/haiku
const char*
Utility::_GetMimeString(uint32 imageType) const
{
	const char *dummy = "";
	translator_id* translators = NULL;
	int32 numTranslators = 0;
	BTranslatorRoster* roster = BTranslatorRoster::Default();
	status_t status = roster->GetAllTranslators(&translators, &numTranslators);
	if (status != B_OK)
		return dummy;

	for (int32 x = 0; x < numTranslators; x++) {
		const translation_format* formats = NULL;
		int32 numFormats;

		if (roster->GetOutputFormats(x, &formats, &numFormats) == B_OK) {
			for (int32 i = 0; i < numFormats; ++i) {
				if (formats[i].type == imageType) {
					delete [] translators;
					return formats[i].MIME;
				}
			}
		}
	}
	delete [] translators;
	return dummy;
}
コード例 #4
0
ファイル: CodyCam.cpp プロジェクト: mmanley/Antares
status_t
AddTranslationItems(BMenu* intoMenu, uint32 fromType)
{

	BTranslatorRoster* use;
	char* translatorTypeName;
	const char* translatorIdName;

	use = BTranslatorRoster::Default();
	translatorIdName = "be:translator";
	translatorTypeName = (char *)"be:type";
	translator_id* ids = NULL;
	int32 count = 0;

	status_t err = use->GetAllTranslators(&ids, &count);
	if (err < B_OK)
		return err;

	for (int tix = 0; tix < count; tix++) {
		const translation_format* formats = NULL;
		int32 num_formats = 0;
		bool ok = false;
		err = use->GetInputFormats(ids[tix], &formats, &num_formats);
		if (err == B_OK)
			for (int iix = 0; iix < num_formats; iix++) {
				if (formats[iix].type == fromType) {
					ok = true;
					break;
				}
			}

		if (!ok)
			continue;

		err = use->GetOutputFormats(ids[tix], &formats, &num_formats);
		if (err == B_OK)
			for (int oix = 0; oix < num_formats; oix++) {
 				if (formats[oix].type != fromType) {
					BMessage* itemmsg;
					itemmsg = new BMessage(msg_translate);
					itemmsg->AddInt32(translatorIdName, ids[tix]);
					itemmsg->AddInt32(translatorTypeName, formats[oix].type);
					intoMenu->AddItem(new BMenuItem(formats[oix].name, itemmsg));
				}
			}
	}
	delete[] ids;
	return B_OK;
}
コード例 #5
0
// Reads the installed translators and adds them to our BListView
status_t
DataTranslationsWindow::_PopulateListView()
{
	BTranslatorRoster *roster = BTranslatorRoster::Default();

	// Get all Translators on the system. Gives us the number of translators
	// installed in num_translators and a reference to the first one
	int32 numTranslators;
	translator_id *translators = NULL;
	roster->GetAllTranslators(&translators, &numTranslators);

	for (int32 i = 0; i < numTranslators; i++) {
		// Getting the first three Infos: Name, Info & Version
		int32 version;
		const char *name, *info;
		roster->GetTranslatorInfo(translators[i], &name, &info, &version);
		fTranslatorListView->AddItem(new TranslatorItem(translators[i], name));
	}

	delete[] translators;
	return B_OK;
}
コード例 #6
0
ファイル: DragonView.cpp プロジェクト: Taffer/BeOS
BMessage *DragonView::_MakeDragMessage( void )
{
	DragonApp *app = dynamic_cast<DragonApp *>( be_app );

	BMessage *msg = new BMessage( B_SIMPLE_DATA );

	// We can handle any image type that's supported by the currently
	// installed Translators.
	//
	// A "real" application would want to add the Translators in order,
	// from best to worst using the quality and capability data in the
	// Translator information structure.  It would also want to make sure
	// that there weren't any duplicate types in the drag message.
	
	BTranslatorRoster *translators = BTranslatorRoster::Default();
	translator_id *all_translators = NULL;
	int32 num_translators = 0;
	
	status_t retval = translators->GetAllTranslators( &all_translators,
													  &num_translators );
	if( retval == B_OK ) {
		// Only add translators that support appropriate inputs/outputs.
		
		for( int32 idx = 0; idx < num_translators; idx++ ) {
			const translation_format *in_formats = NULL;
			int32 num_in = 0;
			
			// Get the list of input formats for this Translator.
			retval = translators->GetInputFormats( all_translators[idx],
												   &in_formats,
												   &num_in );
			if( retval != B_OK ) continue;
			
			// Make sure it supports BBitmap inputs.
			
			for( int32 in = 0; in < num_in; in++ ) {
				if( !strcmp( in_formats[in].MIME, "image/x-be-bitmap" ) ) {
					// Add this translator's output formats to the message.
					
					const translation_format *out_formats = NULL;
					int32 num_out = 0;
					
					retval = translators->GetOutputFormats( all_translators[idx],
															&out_formats,
															&num_out );
					if( retval != B_OK ) break;
					
					for( int32 out = 0; out < num_out; out++ ) {
						// Add every type except "image/x-be-bitmap",
						// which won't be of any use to us.

						if( strcmp( out_formats[out].MIME, "image/x-be-bitmap" ) ) {
							msg->AddString( "be:types", 
											out_formats[out].MIME );
							msg->AddString( "be:filetypes", 
											out_formats[out].MIME );
							msg->AddString( "be:type_descriptions",
											out_formats[out].name );
						}
					}
				}
			}
		}
	}

	// We can also handle raw data.

	msg->AddString( "be:types", B_FILE_MIME_TYPE );
	msg->AddString( "be:filetypes", B_FILE_MIME_TYPE );
	msg->AddString( "be:type_descriptions", 
					app->rsrc_strings->FindString( RSRC_Raw_Data ) );

	// Add the actions that we'll support.  B_LINK_TARGET doesn't make much
	// sense in this context, so we'll leave it out.  B_MOVE_TARGET is a
	// B_COPY_TARGET followed by B_TRASH_TARGET...

	msg->AddInt32( "be:actions", B_COPY_TARGET );
	msg->AddInt32( "be:actions", B_TRASH_TARGET );
	msg->AddInt32( "be:actions", B_MOVE_TARGET );

	// A file name for dropping onto things (like the Tracker) that create
	// files.
	
	msg->AddString( "be:clip_name", "Dropped Bitmap" );

	return msg;
}
コード例 #7
0
void
ScreenshotWindow::_ShowSettings(bool activate)
{
	if (!fSettingsWindow && !activate)
		return;

	// Find a translator
	translator_id translator = 0;
	BTranslatorRoster *roster = BTranslatorRoster::Default();
	translator_id* translators = NULL;
	int32 numTranslators = 0;
	if (roster->GetAllTranslators(&translators, &numTranslators) != B_OK)
		return;
	bool foundTranslator = false;
	for (int32 x = 0; x < numTranslators; x++) {
		const translation_format* formats = NULL;
		int32 numFormats;
		if (roster->GetOutputFormats(translators[x], &formats,
			&numFormats) == B_OK) {
			for (int32 i = 0; i < numFormats; ++i) {
				if (formats[i].type == static_cast<uint32>(fImageFileType)) {
					translator = translators[x];
					foundTranslator = true;
					break;
				}
			}
		}
		if (foundTranslator)
			break;
	}
	delete [] translators;
	if (!foundTranslator)
		return;

	// Create a window with a configuration view
	BView *view;
	BRect rect(0, 0, 239, 239);

	status_t err = roster->MakeConfigurationView(translator, NULL, &view,
		&rect);
	if (err < B_OK || view == NULL) {
		BAlert *alert = new BAlert(NULL, strerror(err), "OK");
		alert->Go();
	} else {
		if (fSettingsWindow) {
			fSettingsWindow->RemoveChild(fSettingsWindow->ChildAt(0));
			float width, height;
			view->GetPreferredSize(&width, &height);
			fSettingsWindow->ResizeTo(width, height);
			fSettingsWindow->AddChild(view);
			if (activate)
				fSettingsWindow->Activate();
		} else {
			fSettingsWindow = new BWindow(rect,
				B_TRANSLATE("Translator Settings"),
				B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
				B_NOT_ZOOMABLE | B_NOT_RESIZABLE);
			fSettingsWindow->AddFilter(new QuitMessageFilter(this));
			fSettingsWindow->AddChild(view);
			fSettingsWindow->CenterOnScreen();
			fSettingsWindow->Show();
		}
	}
}
コード例 #8
0
ファイル: Sketch.cpp プロジェクト: jwiggins/BeOS-Projects
void SketchApp::ReadyToRun()
{
	// Build a menu into your filepanel for fun and profit!
	SketchWindow	*mainWindow = ((SketchWindow *)FindWindow("Etch-A-Sketch"B_UTF8_REGISTERED));
	//BFilePanel		*saver = NULL;
	BMenuField		*formatMenu = NULL;
	BMenu			*menu = NULL;
	BView			*saverView = NULL;
	BRect			rect, bounds;
	menu_info		m_info;
	int32			menubarheight=0;
	
	// get some menu measurements
	get_menu_info(&m_info);
	menubarheight = (int32)m_info.font_size + 8;
	
	// make the filepanel
	saver = new BFilePanel(B_SAVE_PANEL, NULL, NULL, B_FILE_NODE, false); // _ctor
	
	if(saver->Window()->Lock())
	{
		// get a pointer to a view
		saverView = (BView *)saver->Window()->ChildAt(0);
	
		// get a rect for the filepanel's window
		bounds = saverView->Bounds();
	
		// make a menu
		menu = new BMenu("Format");
	
		// construct the BMenuFeild for the menu
		rect.Set(bounds.right - 100, bounds.top + menubarheight, bounds.right - 40, bounds.top + menubarheight + 15);
		formatMenu = new BMenuField(rect, "format menu", "", menu);
	
		formatMenu->SetDivider(0);
		
		// Below was ganked from the BeBook
		//find all the translators
		BTranslatorRoster *roster = BTranslatorRoster::Default(); 
		int32 num_translators, i; 
		translator_id *translators; 
		const char *translator_name, *translator_info;
		int32 translator_version; 

		roster->GetAllTranslators(&translators, &num_translators); // function allocates the memory for translators
		for (i=0;i<num_translators;i++)
		{ 
			const translation_format *fmts; 
        	int32 num_fmts;
			roster->GetTranslatorInfo(translators[i], &translator_name, &translator_info, &translator_version); 
   			roster->GetOutputFormats(translators[i], &fmts, &num_fmts);
   			
   			if(fmts[0].group == B_TRANSLATOR_BITMAP) // make sure we only get bitmap translators
   			{
   				BMessage *message = new BMessage(TRANSLATOR);
   				message->AddString("save format", fmts[0].MIME);
   				if(i == 0)
   					mainWindow->PostMessage(message); // this will init 'format' for us
					menu->AddItem(new BMenuItem(translator_name, message));
			}
			//printf("%s: %s (%.2f)\n", translator_name, translator_info, translator_version/100.); 
		} 
   
		delete [] translators; // clean up our droppings
		// found em all
		
		menu->SetRadioMode(true);
		menu->ItemAt(0)->SetMarked(true);
		menu->SetTargetForItems(mainWindow);
	
	
		saverView->AddChild(formatMenu);
		saver->Window()->Unlock();
	}
}