<ahref="#filling-data">Filling in the data</a><br/>
<ahref="#query-db">Querying the database</a>
</td></tr>
</table>
<h1>Workshop: Filetypes, Attributes, Index and Queries</h1>
<p>This is a workshop to show the use of <ahref="attributes.html">Attributes</a>, <ahref="queries.html">Queries</a>, the <ahref="index.html">Index</a> and custom <ahref="filetypes.html">Filetypes</a>. As an example, we build a database to keep track of our DVD library.</p>
<p>Let's first decide what filetype and attributes would serve our needs. Originally, I planned to use a bookmark file with a link to the movie's IMdB page, but since Haiku didn't have a "bookmarkable" browser like BeOS' <spanclass="app">NetPositive</span> at that time, I came up with this: The file itself will be a JPEG image for the movie cover.<br/>
With <spanclass="app">WebPositive</span>, Haiku now has a browser using bookmark files again, so you could as well use a bookmark file instead of an image as basic filetype for our database files.<br/>
In any case, to these files we add a couple of attributes. Here we have to decide if we want to query it later (then we have to add it to the index) and if so, what type of attribute it should be. Numbers (int, float) can be evaluated differently than text (</=/> vs. is/contains/starts with).</p>
<p>Here are the attributes I'd like to see for my DVDs:</p>
<ul>
<li>Movie title</li>
<li>Genre</li>
<li>URL to e.g. IMdB</li>
<li>Director/Cast</li>
<li>Plot</li>
<li>My rating from 1 to 10</li>
<li>Coordinates in my shelf, e.g. A2, B3, so I find the DVD also in Real Life :)</li>
<aid="custom-filetype"name="custom-filetype">Creating a custom filetype</a></h2>
<p>Start the <spanclass="app">Filetypes</span> preferences, and click on the <spanclass="button">Add...</span> button below the hierarchical list on the left. A small dialog opens and you specify in which MIME Group your new filetype will reside. You can also create a completely new group. Let's put it into "<i>applications</i>" and set the "Internal name" to <i>DVDdb</i>.</p>
<p>Double-click the icon well to open <ahref="applications/icon-o-matic.html">Icon-O-Matic</a> to design an icon for your filetype. You can also drag & drop an icon from the icon well of another type, maybe as starting point for a modified version.</p>
<p>You can add suffixes like .txt, .jpg, .mp3 to recognize files by their extention. Useful when working with files from systems without MIME typing. We don't need that for our example.</p>
<p>This pop-up menu shows a list of all applications that can handle this particular filetype. From here you can choose which program should open this specific file when it's double-clicked.</p>
<tr><td><spanclass="button">pilih...</span></td><td></td><td>opens a file dialog where you choose the application to open with this filetype. Here, we set <spanclass="app">ShowImage</span> to display the DVD's cover.</td></tr>
<tr><tdclass="onelinetop"><spanclass="button">Sama seperti...</span></td><td></td><td>opens a file dialog where you choose any file that already has the preferred application set that you're looking for.</td></tr>
<p>Here we enter all the custom attributes we decided on in our preparations. Clicking the <spanclass="button">Add...</span> button opens a panel to enter all the data for the new attribute. You can edit an existing attribute with a double-click.</p>
<li><i>Visible</i> - This checkbox determines if the attribute is visible in a Tracker window at all. Since the Tracker will be the interface to our DVD database, we check it and define its appearance with:
<ul>
<li><spanclass="menu">Display as</span> - Leave on "Default" if the values are to be displayed according to the attribute's "Type" (e.g. string/integer/float etc.). The other options are:
<li><spanclass="menu">Checkbox</span> - Can be used to show either one of two symbols, see <spanclass="menu">Special</span> below.</li>
<li><spanclass="menu">Duration</span> - Shows an integer as 1/60, e.g. "90" becomes "1:30".</li>
<li><spanclass="menu">Rating</span> - Shows a rating between 0 and 10 as star symbols.</li>
</ul></li>
<li><spanclass="menu">Editable</span> - Determines if the attribute shall be editable in Tracker.</li>
<li><spanclass="menu">Special</span> - Defines the two symbols used for a checkbox display. For example, "xo" will show a "x" for all values >0 and "o" for 0.</li>
<li><spanclass="menu">Width</span> - The default width of that attributes column in a Tracker window.</li>
<li><spanclass="menu">Alignment</span> - The attribute can be displayed left, center, or right aligned.</li>
</ul></li></ul>
<p>Now, insert all the info for our attributes:</p>
<p>Before we start entering data in our little DVD database, we should add certain attributes to the <ahref="index.html">Index</a>. Only indexed attributes can use Haiku's fast <ahref="queries.html">Queries</a>.<br/>
So, what will we be searching in the future? We probably won't ask "What's in the B4 coordinate in my shelf?" or "Does the IMdB URL or the plot of the movie contain the word 'pope-shenooda'?".</p>
<aid="filling-data"name="filling-data">Filling in the data</a></h2>
<p>Now, everything's set and we can begin putting some data into our base.<br/>
Since our basic file is a cover image, we go to some online resource like IMdB, look for our first movie and save the cover or movie poster in a new folder where we want to keep our DVDdb files.</p>
<p>Opening that folder we see a typical Tracker window with one JPEG in it. Right-clicking it, we change its filetype to <tt>application/DVDdb</tt> with the <spanclass="app">Filetype Addon</span>. There's more info on this in the <ahref="filetypes.html">Filetypes</a> document.</p>
<p>Now, we activate all our DVDdb attributes from the <spanclass="menu">Attributes</span> menu of the Tracker window and rearrange the columns to our taste:</p>
<p>By clicking on a yet empty attribute (or pressing <spanclass="key">ALT</span><spanclass="key">E</span>) we enter editing mode and fill each attribute. With <spanclass="key">TAB</span> and <spanclass="key">SHIFT</span><spanclass="key">TAB</span> you can navigate between attributes.</p>
<p>In our example, we usually start with a downloaded JPG cover and change its type to applications/DVDdb. There's another elegant way to produce a file to work with. Just copy an empty file of our filetype to <spanclass="path">/boot/home/config/settings/Tracker/Tracker New Templates</span> and rename it to DVDdb.</p>
<p>Right-clicking into a Tracker window, you'll find a new entry under <spanclass="menu">New...</span> besides the default "New folder".</p>
<aid="query-db"name="query-db">Querying the database</a></h2>
<p>Several hours of grunt work later, we have a nice little database that you can query to find all your Christina Ricci movies that have a 7+ rating... :)</p>
<p>You can assign a sensible attribute layout for query results of a specific filetype.<br/>
Open the folder containing your DVDdb files and arrange the attributes how you'd like to have query results presented. Copy this layout with <spanclass="menu">Attributes | Copy layout</span>.</p>
<p>Open <spanclass="path">/boot/home/config/settings/Tracker/DefaultQueryTemplates</span>, create a new folder and rename it to <i>group/filetype</i>, replacing slashes with underscores; in our case "application_DVDdb".</p>