![]() ![]()
|
![]() |
![]() BeOS Technical Note: MIME Types and FileTypes Note: This Tech Note originally appeared as a long BeDevTalk post. It's been reproduced here due to the volume of requests for MIME information we've received. There is also a Icons & Resources tutorial available which graphically walks through setting up an application's icon.] There seems to be a bit of confusion about MIME types, what happens with mimeset, etc. Hopefully this will clear some of that up. First off, mimeset. The mimeset command actually doesn't do very much at all. Essentially it just tells the registrar (a server) to examine various files and set their mime type. When the registrar receives a request to set the mime type of a file it tries to "sniff" the file and guess its mime type (essentially it does what the Unix `file' command does). The registrar first looks at the data in the file to determine its type and, failing that, it uses any filename extension (".gif") to determine the type. Unfortunately in PR the list of known file types is not extensible. This will be changed in the future. When the registrar figures out the mime type of a file, it add the attribute BEOS:TYPE and writes the associated mime string into that attribute. Setting the mime type of an application is a special case because apps have additional information about what types of data files they understand. Apps can have resources (embedded in the executable). In those resources you can specify what types of files your app understands, icons to associate with file types, whether an app is single or multiple launch, etc. You can edit all of this information using the FileTypes app (in the preferences folder). How does an app get its resources? The first time the compiler creates an app, it has no resources. Using the FileTypes tool (in the preferences folder) you can create resources indicating what file types your apps supports, etc. To edit the resources of your app, drag the icon of the app onto FileTypes. Chances are if it's a new app it will have no resources at all and the window that FileTypes opens will be mostly empty. The first thing you need to do is to set the application signature. The app signature is a MIME string of the form: application/x-vnd.YourCompany-YourAppName Make sure that the signature matches the signature you use in your BApplication constructor. To give your app an icon, fire up IconWorld, do your Michelangelo impression, and then chose "Copy" from the Edit menu. Go back to the FileTypes window for your app (where you entered the app signature) and select the inset box next to the app signature field. Press "Alt-V" (Command-V on a Mac keyboard) and that will paste in your icon. An alternative way to get an icon is to use Photoshop (or some other paint app) and do your best 32x32 artwork (using the Be palette). Then export the file as a raw image (along with a separate mask file if you want, make sure the mask file has the same name as the raw icon file with a ".mask" extension). The format of the raw file is literally just plain bytes, RGB, per pixel. Then either transfer the file to the BeBox or access it from your Macintosh and drag the file from the Tracker to the inset icon box of FileTypes. You can do the same thing for the mini-icon (16x16) but you will not get any feedback when you drag it onto the icon box of FileTypes (yes this UI will improve). Then you can edit the supported types of the app. Click the "Add" button to add new types (like image/gif, image/jpeg, etc). You can add icons for the supported types in the same way you did for the app icon (or you can open another apps resources and copy the icons from there -- FileTypes supports copying, cutting and pasting icons with Alt-C, Alt-X and Alt-V respectively). Once you're happy with the supported types for your app, chose "Save" from the File menu of FileTypes. If you're doing development on the app you will also want to choose "Save into Resource File" so that you can have the resources added to the app each time it gets recompiled. I believe the IDE has options for doing this automatically and from the command line you can use the copyres tool to add resources to an executable. Pavel also recommends that you do a "rmattr BEOS:TYPE" just to be sure that if you just changes resources and relink that the right thing happens. Using the FileTypes tool on regular files you can change their icon (the same way you would for apps), set a specific application to open the file, and even change the type of a file (if it were wrong or you wanted to experiment). In the main FileTypes window (titled "System File Types") you can manipulate file types on a system wide basis. For example if you would like to change the icon for all GIF files, select the type image/gif from the listview in the top left of the window. Then using the same technique as for an application icon, paste in an icon in the small box on the right side of the FileTypes window. Right now, if there is a preferred app for a given type and that preferred app has an icon for that type, the app's icon will override your selection (though this behavior may change in the future). You can also add new mime types if you want and set which application will open that type by default. Also, FileTypes only uses public api so there is no real magic going on. You can access all of the same functionality with the classes in Mime.h, NodeInfo.h, and AppFileInfo.h (which are part of the Storage Kit). That in a nutshell is most everything you need to know about MIME type, file types, etc.
|