[openbeos] Preferences/File Help

  • From: John Tegen <john.tegen@xxxxxxxxxxxxxxxxxx>
  • To: "'openbeos@xxxxxxxxxxxxx'" <openbeos@xxxxxxxxxxxxx>
  • Date: Fri, 18 Jan 2002 11:52:26 -0800

The whole XML <-> BMessage discussion can be simplified by just having Text
translators like the image translators (mentioned by others too).

::Convert( const BMessage & msg, BString & text );

BString text;
BMessage msg;
BTextTranslator *translator = be_roster->Find( "text/xml" );
if( translator )
{
  translator->Convert( msg, text );
  // then save to file or send as stream
}

AND

::Convert( const BMessage & msg, BDataIO * stream );

BMessage should not go directly to XML since the translator may support
other formats.
One of the strengths of the BeOS API is its flexibility.  You can do things
with the API that the authors did not intend for it to do, but it could.

Now preference files can be saved in any format supported by
BTextTranslators.  The application decides which format to save it in.  The
preference file would have its MIME type set so the appropriate translator
would be used to return it as a BMessage.  The application would only need
to archive and restore from a BMessage.  BTextTranslator can be able to
convert from one format to another.  Usually you don't want the end-user to
tweak with the preference file directly.  The application should the only
one doing that.  But nothing would stop a utility to read in a preference
file and display the hierarchy in a outline list view.

Enforcing an application developer to maintain something in a certain file
format may get resistance.  This solution would keep both camps happy.

Other related posts: