View Single Post
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#43
Hi rooster,

I just looked at my app-search-widget code again, because it seems
only the Name but not the comment entry is localized (translatable).
The comment entry for the browser is
weba_ap_web_browser_thumb
but I can not find any translated text for this name.
And yes, I don't show any comment, if the desktop file
has a X-Text-Domain entry but no dgettext value for
comment name can be found.
(dgettext(domain, comment_key) is the same as comment_key)

But I can show you some code how to use the QSettings class,
this should be simpler than parsing the raw file:

simple example:

Code:
QT       += core gui

TARGET = settingsreader
TEMPLATE = app


SOURCES += main.cpp\
Code:
#include <QtGui/QApplication>
#include <QSettings>
#include <QMainWindow>
#include <QListWidget>
#include <QDirIterator>
#include <locale>
#include <libintl.h>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow w;
    QListWidget* list = new QListWidget(&w);
    QDirIterator iter("/usr/share/applications/hildon/");
    while(iter.hasNext())
    {
        QString path = iter.next();
        qDebug() << path;
        if(path.endsWith(".desktop"))
        {
            QSettings settings(path, QSettings::IniFormat);
            settings.beginGroup("Desktop Entry");
            QString name = settings.value("Name", "no name").toString();
            QString comment;
            QString domain("maemo-af-desktop");
            if(settings.contains("X-Text-Domain"))
            {
                domain = settings.value("X-Text-Domain").toString();
            }
            name = QString::fromUtf8(dgettext(domain.toLatin1(), name.toLatin1()));
            if(settings.contains("Comment"))
            {
                comment = QString::fromUtf8(dgettext(domain.toLatin1(), settings.value("Comment").toString().toLatin1()));
            }
            list->addItem(name + " " + comment);
        }
    }
    w.setCentralWidget(list);
    w.show();
    return a.exec();
}
nicolai
 

The Following User Says Thank You to nicolai For This Useful Post: