Development Team/Almanac/sugar.mime: Difference between revisions
No edit summary |
No edit summary |
||
| Line 37: | Line 37: | ||
print mime_type | print mime_type | ||
</pre> | </pre> | ||
=== Given a specific file, how do I figure out what its mime type is? === | === Given a specific file, how do I figure out what its mime type is? === | ||
The mime.get_from_file_name() method lets you get the mime type based on the name of a given file. The mime.get_for_file() is a little more robust and can get mime types often without an extension. | The mime.get_from_file_name() method lets you get the mime type based on the name of a given file. The mime.get_for_file() is a little more robust and can get mime types often without an extension. | ||
| Line 72: | Line 73: | ||
</pre> | </pre> | ||
= | === Who decides the default activity for opening files of different mime types? === | ||
Take a look at the file | |||
<pre> | |||
/usr/share/sugar/data/mime.defaults | |||
</pre> | |||
Where you will see a file formatted something like this: | |||
<pre> | |||
# MIME Activity service name | |||
application/pdf org.laptop.sugar.ReadActivity | |||
text/rtf org.laptop.AbiWordActivity | |||
text/plain org.laptop.AbiWordActivity | |||
application/x-abiword org.laptop.AbiWordActivity | |||
text/x-xml-abiword org.laptop.AbiWordActivity | |||
application/msword org.laptop.AbiWordActivity | |||
application/rtf org.laptop.AbiWordActivity | |||
image/png org.laptop.WebActivity | |||
image/gif org.laptop.WebActivity | |||
image/jpeg org.laptop.WebActivity | |||
text/html org.laptop.WebActivity | |||
application/xhtml+xml org.laptop.WebActivity | |||
application/xml org.laptop.WebActivity | |||
application/rss+xml org.laptop.WebActivity | |||
application/ogg org.laptop.WebActivity | |||
audio/ogg org.laptop.WebActivity | |||
video/ogg org.laptop.WebActivity | |||
</pre> | |||
=== How do I register my activity as supporting different mime types? === | |||
So, you've made a new image viewer/text editor/audio player and want children to open those files with my activity. Unfortunately, you cannot change the default activity for those files, as those choices are already decided (see [Who decides the default activity for opening files of different mime types?]). | |||
However, you can register your activity as capable of opening files of these mime types so that children can choose to open these files with your activity. | |||
There are two steps involved in supporting different mime types in your activity. First, you need to update your activity's .info file by listing the mime types you are going to support. For a comprehensive overview of everything your activity's info file must include, please see [[Activity_bundles#.info_File_Format]]. | |||
If you wanted to make a new image viewer activity, you might want to modify your .info file to something like: | |||
<pre> | |||
mime_types = image/bmp;image/gif;image/jpeg;image/png;image/tiff | |||
</pre> | |||
The second thing you need to do is handle these files when they are opened with your activity (e.g., show the picture, play the sound, etc.). The file will arrive in your activity via the read_file( self, file ) method in your activity subclass. | |||
=== How can children open files of a certain mime type with my activity? (Since they can't make it the default). === | |||
In their journal, children need to select "more info" about that file's journal entry. Then they need to hover over the "resume" button until a pop-up menu appears listing your activity. | |||