lunedì 26 settembre 2011

Translating C++/Qml applications

I have spent a bit of time to understand how to translate qml applications since examples on the web are a different between each others.
Just a reminder, this is for compiled sofware using C++ and QDeclarativeView; for QML files loaded with QMLViewer there is no need since it's already set (and you just need to put qm files in a subdirectory).

Any translatable string in qml must be wrapped inside qsTr(), like this:

Than, assuming you have put all qml files in the same directory, you have to run lupdate to generate the ts file:


Now you have a ts file to open with QtLinguist. After you are done release it and put it in the translations subdir. To make the application locale-aware, we need to load the translation automatically at runtime. If we're using last QtSdk than we can implement a public function in the QmlApplicationViewer class, otherwise we can simply implement it in the main.cpp. This function must be called before the QDeclarativeView::showFullScreen() and QDeclarativeView::setSource() are called.


void QmlApplicationViewer::loadTranslator()
{
    QString locale = QLocale::system().name();
    QTranslator* translator = new QTranslator;
    qDebug()<<"Translating: "<<translator->load(QString("/opt/myproject/translations/myproject_") + locale + QString(".qm"));
    qApp->installTranslator(translator);
}

In this way the application will look for an available translation for the current set locale, and will load it if founf. Otherwise application will keep staying in source language. Coded in this way, to add a new translation is really simple: just add another qm file in the translations subdir.
This Subdir does not have to stay in the file system, it can be put in the resource file of the application.

sabato 10 settembre 2011

Internet Radio Player for Harmattan



Internet Radio Player is a software written in C++/Qt-QML to listen and manage streaming radios. Stations are saved in a sqlite3 database which gets created when application is run for the first time. Location of the database is /home/user/.config/internetradioplayer/stations.db and is kept when disintalling the application.


Features: 
  • 10band equalizer with several preconfigured presets.
  • Automatically add new stations into database when app is updated.
  • Can filter by station name, genre or country. Only one filter at time.
  • Shows station metadata (Artist, Title, StationName, Bitrare, Genre)
  • Favourites management.
  • Cronology Logging inside app and in a text file in Documents.
  • Current stations included in the database: 196
  • Has a savescreen window available for power saving mode.
  • Support for A2DP Bluetooth Control.
  • Uses Nokia Push Notifications to update stations.
  • Can show current track in standby screen.
  • DBus interface available for remote control.
  • Subscriber APIs available to retrieve status and current played track.


Available translations:
  • Italian.
  • German.

DBus interface allows the following operations: Toggle, Previous, Next. DBus shell commands to control from remote/ssh: 

  • dbus-send --type=method_call --dest=it.ggiovanni88.internetradioplayer /it/ggiovanni88/internetradioplayer it.ggiovanni88.internetradioplayer.toggle
  • dbus-send --type=method_call --dest=it.ggiovanni88.internetradioplayer /it/ggiovanni88/internetradioplayer it.ggiovanni88.internetradioplayer.prev
  • dbus-send --type=method_call --dest=it.ggiovanni88.internetradioplayer /it/ggiovanni88/internetradioplayer it.ggiovanni88.internetradioplayer.next


Available ContextKit properties for Subscriber APIs:

  • /InternetRadioPlayer/active
  • /InternetRadioPlayer/artist
  • /InternetRadioPlayer/title

















Changelog:
  • 0.0.4 (12-09-2011)
    • Initial release.
  • 0.0.5 (18-09-2011)
    • Added resource policy configuration file (volume can be set using volume keys within the app).
    • Stations can be  sorted by Name, Genre or Country.
  • 0.0.6 (23-09-2011)
    • Added new stations.
    • Added live filtering in the stations page.
    • Program automatically adds default stations upon software update.
    • Added italian translation.
  • 0.0.7 (04-10-2011)
    • Added splashscreen.
    • Changed view header.
    • Added favourites management.
    • Some minor improvements in the UI.
    • "Back" button no longer closes the application when in Main Page.
    • Added more stations. 
    • Implemented 10bands equalizer.
    • Added "placeholder" label in cronology page and favourites page: it will be shown when there is no entries.
  • 0.0.8 (23-10-2011)
    • Improved Main Page UI.
    • Menus get closed when changing page.
    • Added support for stations sending album art as metadata (Like RadioParadise.com).
    • Multimedia controls refear to last used list: as default they refear to all stations list, but when playing a station from favourite list they refear to the last ones.
    • Selecting a station will play a vibration feedback and will bring to main page.
    • Equalizer is disabled by default when running app for the first time.
    • Added a validator not to allow user to include char ' in station fields.
    • Added options to show status bar in portrait/landscape
  • 1.0.1 (04-11-2011)
    • Fixed some utf-8 encoding.
    • Added more stations.
    • Added resource policy support.
    • Player works in silent profile.
    • Volume can be set when application is in background or device is locked, when playing.
    • Playback resumes after interruptions (calls, messages etc).
  • 1.0.2 (23-11-2011)
    • It's now possible to create menu shortcuts within the application. Tap and hold on a station in Stations Page and pick "Create menu shortcut" or "Remove menu shortcut". Shortcuts open the application and directly play the selected stream.
    • Added option to play last heard station at application startup.
    • Back button in Main Page has a "disabled" look.
    • Removed lyrics support.
    • Added an info banner when player encountered an error.
  • 1.0.3 (12-01-2012)
    • UI Layout redesigned.
    • Improved the name filtering.
    • Added genre and country filtering.
    • Fixed a bug with TextField.
    • Removed Light theme, StatusBar visibility option and Landscape Mode.
  • 1.0.4 (14-01-2012)
    • Added a savescreen window.
  • 1.0.5 (14-01-2012)
    • Implemented A2DP bluetooth control.
  • 1.0.7 (27-03-2012)
    • Added Nokia Push Notifications support.
  • 1.2.1 (20-04-2012)
    • Added more stations.
    • Sevaral improvements to UI.
  • 1.3.0 (26-06-2012)
    • Added more stations.
    • New feature: showing current song on standby screen.
  • 1.4.0 (12-08-2012)
    • Added more stations.
    • Added German and Italian translations.
    • Fixed support for Nokia Push Notifications and standby screen plugin for PR1.3 devices.
    • Added DBus interface support (you can control Internet Radio Player from ssh with dbus commands).
    • Added Subscriber APIs support (information about player status and current played track can be retrieved from 3rd part softwares).
  • 1.4.1 (29-08-2012)
    • Added more stations.
    • Some UI minor changes.
    • No more possible to share already included default stations.
    • Added theme colour for PR1.3.