June 14th, 2010
The Qt Framework for some reason doesn’t provide any built-in support for Gettext, the quasi-standard for translating software programs. An alternative is provided, Qt Linguist, however there are several reasons why some may still prefer Gettext:
- If your application is already partially translated using Gettext it’s much easier to keep on using it rather than converting all your mo/po files to Qt’s format.
- Another significant advantage of Gettext is that it doesn’t have any dependencies (unlike Qt Linguist which creates a dependency to the Qt Framework) and thus allows creating more portable code.
So for these reasons, I’ve created a small library which parses and manages Gettext catalogues in Qt. The library includes a generic parser and a catalogue manager which can be used in any C++ project. On top of that, a Qt wrapper is provided for easy integration with the Qt framework.
The library can be downloaded from the Google Code project:
Download the Gettext library for the Qt Framework
Setting up and using the library is easy:
#include <QtGettext.h>
QtGettext::instance()->setLocale("cn_TW"); // Set the locale
QtGettext::instance()->setCatalogueName("catalogue"); // Set the name of the mo files
QtGettext::instance()->setCatalogueLocation("Data/Locales"); // Set the catalogue folder
QtGettext is now set to use the file in Data/Locales/cn_TW/catalogue.mo.
Also note that if this file is not available, QtGettext will try to load Data/Locales/cn/catalogue.mo (if available) as an alternative.
To mark a string for translation, simply call:
QtGettext::instance()->getTranslation("Some string to be translated");
Since this is rather long, a _() macro is also provided. It shortens the code to just:
_("Some string to be translated");
Tags: gettext, qt
Posted in C++, Qt Framework | No Comments »
March 19th, 2009
I’ve described in a previous post how to get the URL of a YouTube video in Flash. However this method only returns the low-resolution quality video at 320×240. Getting the high-res one is easy though - you just need to add a “fmt” parameter to the URL link.
These two values in particular can be interesting:
fmt=22: This is an MP4 video in HD quality. On my tests, the resolution can go up to 1280 x 720.
fmt=18: This is a 480 pixels wide version that can be used in portable devices such as iPods.
In order to use this additional parameter, just add an argument to the constructFLVURL method:
// Set "format" to 22 for the high resolution version, or 18 for the iPod one. Or just
// leave to -1 for the low res version.
private function constructFLVURL (video_id:String, t:String, format:Number = -1):String {
var str:String = "http://www.youtube.com/get_video.php?";
str += "video_id=" + video_id;
str += "&t=" + t;
if (format >= 0) {
str += "&fmt=" + format;
}
return str;
}
Tags: flash, flv url, hd, high-resolution, ipod, youtube
Posted in flash | 1 Comment »
November 14th, 2008
Today, I was looking for a way to delete a file to the recycle bin using C++, but couldn’t find any simple example, so here it is:
SHFILEOPSTRUCT operation;
operation.wFunc = FO_DELETE;
operation.pFrom = "c:\\file\to\delete.txt";
operation.fFlags = FOF_ALLOWUNDO;
SHFileOperation(&operation);
Tags: SHFileOperation, Win32
Posted in C++, Win32 | 1 Comment »
November 13th, 2008
Getting the 16×16 and 32×32 icons on Windows is relatively easy and is often as simple as one call to ExtractIconEx.
However, getting the extra large (48×48) and jumbo (256×256) icons introduced respectively by XP and Vista is slighly more complex. This is normally done by:
- Getting the file information, in particular the icon index, for the given file using SHGetFileInfo
- Retrieving the system image list where all the icons are stored
- Casting the image list to an IImageList interface and getting the icon from there
Below is the code I’m using in Appetizer to retrieve the extra large icon. If needed it can easily be adapted to get the jumbo icon.
Update: To do the same thing in C#, see the link in the comments below.
#include <shlobj.h>
#include <shlguid.h>
#include <shellapi.h>
#include <commctrl.h>
#include <commoncontrols.h>
// Get the icon index using SHGetFileInfo
SHFILEINFOW sfi = {0};
SHGetFileInfo(filePath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
// Retrieve the system image list.
// To get the 48x48 icons, use SHIL_EXTRALARGE
// To get the 256x256 icons (Vista only), use SHIL_JUMBO
HIMAGELIST* imageList;
HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);
if (hResult == S_OK) {
// Get the icon we need from the list. Note that the HIMAGELIST we retrieved
// earlier needs to be casted to the IImageList interface before use.
HICON hIcon;
hResult = ((IImageList*)imageList)->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hIcon);
if (hResult == S_OK) {
// Do something with the icon here.
// For example, in wxWidgets:
wxIcon* icon = new wxIcon();
icon->SetHICON((WXHICON)hIcon);
icon->SetSize(48, 48);
}
}
Tags: icon, SHGetFileInfo, SHGetImageList, Win32
Posted in C++, Win32 | 3 Comments »
November 12th, 2008
I have just released version 1.0 of Appetizer. It is a free application launcher, or dock, for Windows. It allows organizing and launching your applications and other shortcuts into a convenient dock. The app is skinable and entirely customizable. It is currently available in five different languages.
The application also supports the PortableApps USB format. So if you use Appetizer on a USB key in the PortableApps format, the application will detect it and automatically import all your applications along with the ‘Documents’, ‘Videos’, ‘Music’ and ‘Pictures’ folders.
Follow this link to download it.

Tags: appetizer, PortableApps
Posted in Software News | No Comments »