Notices


Reply
Thread Tools
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#41
OK, no worries I'll have a look at it when I get back to my PC.
 
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#42
Originally Posted by nicolai View Post
I don't remember :-)
I found this one in some example code or in the maemo developer
guide.

Nicolai
Hi Nicolai,

I tried with your approach but can't get it to work. As I'm usin Qt I can't use your code as is.

Here is how I am trying to get the comment.
First the translate QString, which returns the dgettext string passed in:
Code:
QStringDialog::translate(QStringdomain,QStringstr) 
{
QByteArraydomainBytes=domain.toLatin1(); constchar*domainPtr=domainBytes.data(); QByteArraystrBytes=str.toLatin1(); constchar*strPtr=strBytes.data(); setlocale(LC_ALL,""); returnQString::fromUtf8(dgettext(domainPtr,strPtr)); 
}
And then when reading the Desktop -files where I get the Comment and X-Text-Domain strings:
Code:
if(line.startsWith("Comment=")) { strList=line.split("="); if(strList.length()>=2) { comment=strList[strList.length()-1]; realComment=translate("maemo-af-desktop",comment); } } if(line.startsWith("X-Text-Domain=")) { strList=line.split("="); if(strList.length()>=2){ xTextDomain=strList[strList.length()-1]; realName=translate(xTextDomain,name); realComment=translate(xTextDomain,comment); } }
First I am trying to get the comment from the Comment -field of the Desktop -file. And then I am trying to get it from the X-Text-Domain. I am passing the values like this, because if dgettext finds nothing it returns the msgid passed to dgettext. A little bit of dodgy coding, but I'll fix it once I get this to work.

Do you have any ideas? Or is it that in GTK this stuff just works and not in Qt?

Last edited by rooster13; 2010-11-17 at 18:51.
 
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:
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#44
Thanks Nicolai!

Definately looks easier than parsing the raw files
 
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#45
Originally Posted by nicolai View Post
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...

nicolai
Hi Nicolai,

I used your Qt settings code and modified it a little to suit my needs. It turned out that your solution was just a little bit faster than mine .
Thank you for the code.

As for the app descriptions. I am dropping it for the time being, because there is not a good enough solution to read them.

I tried to read the descriptions from 'apt-cache show', but that turned out to be too slow and description could not be determined for all packages from the information in the desktop -files. Also I don't want to read those into a file and save them. This is the code I made for reading the descriptions from the package (it contains a nice little trick for piping commands in QProcess, if someone is interested):
Code:
QString Dialog::getComment(QString xTextDomain, QString execPath)
{
    QString retComment = "";
    QStringList execList = execPath.split("/");
    QString execName = execList[execList.length() - 1];
    bool isFound = false;
    QProcess apt;
    apt.start("sh -c \"apt-cache show " + xTextDomain.replace("_", "-") + " | grep 'Description:' | tail -1\"");
    apt.waitForFinished();
    while(apt.canReadLine())
    {
        QString outData = apt.readLine();
        if (outData.startsWith("Description:"))
        {
            //qDebug() << outData;
            QStringList tmpSplit = outData.split(":");
            if (tmpSplit.length() >= 2)
            {
                retComment = tmpSplit[tmpSplit.length() - 1];
                isFound = true;
            }
        }
    }
    apt.close();
    if (!isFound)
    {
        apt.start("sh -c \"apt-cache show " + execName.replace("_", "-") + " | grep 'Description:' | tail -1\"");
        apt.waitForFinished();
        while(apt.canReadLine())
        {
            QString outData = apt.readLine();
            if (outData.startsWith("Description:"))
            {
                //qDebug() << outData;
                QStringList tmpSplit = outData.split(":");
                if (tmpSplit.length() >= 2)
                {
                    retComment = tmpSplit[tmpSplit.length() - 1];
                    isFound = true;
                }
            }
        }
        apt.close();
    }
    return retComment.trimmed();
}
I am still open for new suggestions on getting the app descriptions if somebody has a solution.

Next I will try to implement "Live Search" and fix a minor bug when double clicking on the widgets buttons the list is opened twice or more times.

I have now posted a new version of the deb -file. It actually does not contain any fixes, it is just using Nicolais method of reading desktop -files, which is a little bit faster than mine.

Please test and post bug reports / comments here.
 

The Following User Says Thank You to rooster13 For This Useful Post:
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#46
I am pleased to announce a new version of Shortcut Stash.
Now with "Live Search".
Name:  Screenshot-20101120-140858.jpg
Views: 495
Size:  22.0 KB

Since this is Qt I had to do it all from scratch, so it is not the Maemo "Live Search", but it works pretty good.

Bug reports and comments may be posted here.
 

The Following 4 Users Say Thank You to rooster13 For This Useful Post:
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#47
I am finally ready to release this app to Extras-Devel, but...

When I try to submit it to the autobuilder it always fails.
Here is the error log:
Code:
TMP="/var/tmp"
TEMP="/var/tmp"
DEBIAN_FRONTEND="noninteractive"
DEBIAN_PRIORITY="critical"
DEB_BUILD_OPTIONS="parallel=4"
TMPDIR="/var/tmp"
dpkg-buildpackage: set CFLAGS to default value: -g -O2
dpkg-buildpackage: set CPPFLAGS to default value: 
dpkg-buildpackage: set LDFLAGS to default value: 
dpkg-buildpackage: set FFLAGS to default value: -g -O2
dpkg-buildpackage: set CXXFLAGS to default value: -g -O2
dpkg-buildpackage: source package maemostash
dpkg-buildpackage: source version 0.1-1
dpkg-buildpackage: host architecture armel
dpkg-checkbuilddeps: Using Scratchbox tools to satisfy builddeps
 fakeroot debian/rules clean
dh_testdir
dh_testroot
rm -f build-stamp
# Add here commands to clean up after the build process.
rm -rf builddir
dh_clean 
 dpkg-source -b maemostash-0.1
dpkg-source: info: using source format `1.0'
dpkg-source: info: building maemostash using existing maemostash_0.1.orig.tar.gz
dpkg-source: info: building maemostash in maemostash_0.1-1.diff.gz
dpkg-source: warning: the diff modifies the following upstream files: 
 Makefile
dpkg-source: info: use the '3.0 (quilt)' format to have separate and documented changes to upstream files, see dpkg-source(1)
dpkg-source: info: building maemostash in maemostash_0.1-1.dsc
 debian/rules build
mkdir -p builddir
cd builddir && qmake-qt4 PREFIX=/usr ../MaemoStash.pro
/scratchbox/tools/bin/sh: line 1: qmake-qt4: command not found
make: *** [builddir/Makefile] Error 127
dpkg-buildpackage: error: debian/rules build gave error exit status 2
I tried to fix the qmake error from instructions in several threads discussing similar problem with QT packages.

If anyone could help me out with this, I'd really appreciate it.
 
MohammadAG's Avatar
Posts: 2,473 | Thanked: 12,265 times | Joined on Oct 2009 @ Jerusalem, PS/IL
#48
Add libqt4-dev to Build Depends: in debian/control.
 

The Following User Says Thank You to MohammadAG For This Useful Post:
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#49
Originally Posted by MohammadAG View Post
Add libqt4-dev to Build Depends: in debian/control.
Thanks, I will try that.

EDIT: It worked! I am pass the qmake error.
Though other errors appeared this is good news.

I'll keep on trying to fix the errors.

Last edited by rooster13; 2010-11-22 at 17:42.
 
rooster13's Avatar
Posts: 319 | Thanked: 221 times | Joined on Jan 2010 @ Finland
#50
Ok, now the autobuilder was ok.
BUT... I see that there is a problem. The package is missing my images file:
Code:
/usr/bin/rcc: File does not exist '../images.qrc'
Is this a problem? Will the images be on the packages or not?
 
Reply


 
Forum Jump


All times are GMT. The time now is 02:13.