Friday, 2 March 2012

a backlog of lightbulb moments

Okay I admit. The title of the blog posts are usually as random as a phrase from a song I'm listening to while I write or something. Any way, I've been toiling with the idea of starting an open source project to create a download-able 'text' yoruba bible (I admit that there's probably one but I've not found it yet).

Thanks to the qbiblefree app (yes, I still use my N900 - and I'm not changing it till something better - read more hackable - comes along), I found out about Zefania XML format. So now I kinda know what format the bible would be in if I were ever to consider starting the project. The next question - were to get actual yoruba bible data from was kinda solved with a quick google search. The good people at http://www.africanportal.net/ABO/BibeliAtoka/ have uploaded pdf files containing bible books. Yes, there's still the problem of breaking it down into chapters and perhaps verses. Sejda has been a little helpful there - the books can be broken down into pages. It's not a one-to-one mapping with the chapters but it's a start. I figure I can actually use the pages as they are now with a little of meta data stored in a noSQL database or just flat files.

Then there's the really crazy part of how to type of all the pdf text through a web interface. My javascript is presentable at best. Or put another way, I program better in scala than in javascript - and you won't want to gamble your life on the quality of my scala code. Any way today something cool happened. I found this site here: http://www.jawish.org/blog/archives/314-Javascript-Thaana-Keyboard-version-3.0.html. It's basically the same problem as I'm trying to solve but for a different language. So I've spent the last two hours adding little modifications and I think it's works... almost. In fact, here's an example., there's an example text field at the end of this post that uses the modified script to allow you to type yoruba alphabets. Hopefully you can toil with it and probably even leave a comment on what you think.

I realize now that there's very little excuse for me not to go ahead with this project now - that's the scary part. I even found an example of how the keyboard interface can be designed: http://www.branah.com/dhivehi. But maybe it's time I started it anyway. I know it's time to sleep - lightbulb!

I'll upload a downloadable script with tutorials and all that. For now - use the non-yoruba letters (q, z, c, x, and v) on the keyboard for the non-english letters (Ọ, Ṣ, Ẹ) in the yoruba alphabet. The x and v are for acute and grave marks (ami) - type them before typing yoruba alphabets that require ami - hope it works :)

Monday, 30 January 2012

What a game!!!

I've been playing around, pro-actively for a change, with Qt and coding for my phone: over the holidays I created a SDA hymnal app for my phone. I don't mean to brag but the Mrs and an aunt were both jealous enough to request that I port it to work on their Symbian phones. I plan to blog about my experience learning Qt maybe once every blue moon.

Actually I'll start right now and talk about event filters. There's code out there that serves as an example of how event filters work but I strongly doubt that the availability tutorials have reached a level of verbosity that can render my own take on the topic redundant. On the N900 (hildon/maemo 5), there are a few applications that have this nifty search functionality where once you slide open the keyboard and start typing the application starts to search for what you are typing. I wanted that functionality on the aforementioned hymnal. For this to work I first attempted to override the keyPressEvent method of the main window but found out that the QListView on the main window actually was stopping the key press event from getting to the main window. To handle scenarios like this on possible solution is to use event filters implemented by two functions - installEventFilter and eventFilter - that together allow a widget to pass responsibility for handling events to some other widget.

So with the QListView example above, let's assume the instance of the QListView is called listView and the instance of the QMainWindow on which the listView is displayed is called mainWindow. Then to redirect listView's events to mainWindow you have to call listView.installEventFilter(mainWindow). A way of understanding the installEventFilter function is that you've installed a siphon in the process by which listView usually handles it's events so that listView's events now slip out of its hands into mainWindow's. You then have to get mainWindow to handle the events that come its way from listView - this is where eventFilter method comes in. You have to override mainWindow's eventFilter method such that you do any event specific checks and target object checks.


I've included the code portion based on the example in the documentation here for for the fun of it. Now this is not my code o. I copied it almost verbatim from the Qt documentation but added some comments that may be useful if you read the epistle leading up to this paragraph

//within MainWindow's constructor set up the siphon filter
listView->installEventFilter(this); 

//then you override the eventFilter method
bool MainWindow::eventFilter(QObject *object, QEvent *event)
 {
     if (object == target && event->type() == QEvent::KeyPress) {
         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
         if (keyEvent->key() == Qt::Key_Tab) {
             // Special tab handling
             return true;
         } else
             return false;
     }
     return false;
 }



Now that you've read this you can now go on and read the Qt documentation here (http://developer.qt.nokia.com/doc/qt-4.8/eventsandfilters.html#event-filters) for actual code.