wxMimeTypeManager Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

wxMimeTypeManager

Post by MoonKid » Fri May 22, 2009 5:47 pm

I am not sure If I use the manager correct. I check if there is a registration for the given filetype and I try to set one.
But it doesn't work. On restarting the code it doesn't found a registration.

Code: Select all

void BFApp::CheckFileTypeRegistration ()
{
	//
	bool bDoRegister = true;

	// the mime types manager
	wxMimeTypesManager mgr;

	// get our file type
	wxFileType* pFileType = mgr.GetFileTypeFromExtension (BF_PROJECT_EXTENSION);

	// is there still a registration?
	if ( pFileType )
	{		
		wxString strCmd = pFileType->GetOpenCommand(wxString("test.") + BF_PROJECT_EXTENSION);

		if ( strCmd == BFEnvironment::GetDocumentOpenCommand() )
		{
			bDoRegister = false;
		}
		delete pFileType;
	}

	if ( bDoRegister )
	{
        static const wxFileTypeInfo fallbacks[] =
        {
            wxFileTypeInfo(_("document/bfp"),
							BFEnvironment::GetDocumentOpenCommand(),
                           "xxx",
                           _("Blackfisk Backup Project"),
						   "bfp", wxNullPtr, wxNullPtr),
            wxFileTypeInfo()
        };

        mgr.AddFallbacks(fallbacks);
	}
}

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: wxMimeTypeManager

Post by tan » Sat May 23, 2009 10:37 am

Hi.
MoonKid wrote:I am not sure If I use the manager correct. I check if there is a registration for the given filetype and I try to set one.
But it doesn't work. On restarting the code it doesn't found a registration.
Do you expect that AddFallbacks() creates permanent association? But it doesn't. Comment in mimetype.h:

// these functions can be used to provide default values for some of the
// MIME types inside the program itself (you may also use
// ReadMailcap(filenameWithDefaultTypes, true /* use as fallback */) to
// achieve the same goal, but this requires having this info in a file).
//
// The filetypes array should be terminated by either NULL entry or an
// invalid wxFileTypeInfo (i.e. the one created with default ctor)
void AddFallbacks(const wxFileTypeInfo *filetypes);
void AddFallback(const wxFileTypeInfo& ft) { m_fallbacks.Add(ft); }
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Sun May 24, 2009 2:04 pm

Didn't try it myself, but it looks like that

Code: Select all

wxMimeTypesManager::Associate(const wxFileTypeInfo& ftInfo);
does the job.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

Post Reply