HOWTO display Chinese in Creative ZenMicro using Amarok

Desktop, Gentoo June 25th, 2007

Creative is less creative in building software, that is why so many users are asking how to display Chinese character in Creative ZenMicro using either Windows Media Player or Creative MediaSource. But this company really build solid hardware, and I could resist the temptation of ZenMicro RED 5G (refurbished) 49$ with free shipping from Outpost. So I got another one and found the same annoyance happened to Amarok 1.4.6. Amarok is open sourced, that leave the door open for me to dig into the problem.

According to the solution,

1. Go to your Control Panel
2. Select Regional and Language Options
3. Go to the Advanced tab
4. See the Language for Non-Unicode programs
5. Select Chinese PRC
6. The system will prompt you to restart.

it looks like the Creative ZenMicro uses the GB2312 code page to display Chinese. So the first move to solve this problem is to convert the ID3 tag to GB2312 before the track is downloaded to the device:

// $TOPSRC/amarok/src/mediadevice/njb/track.cpp
    QTextCodec *codec = QTextCodec::codecFromName("GB2312");
    // orig: NJB_Songid_Addframe( songid, NJB_Songid_Frame_New_Title( m_bundle.title().utf8() ) );
    NJB_Songid_Addframe( songid, NJB_Songid_Frame_New_Title( codec->fromUnicode(m_bundle.title()) ) );

Good news is the old messy code disappeared, the bad news is we have new messy code. It is worthy understanding how the device stores the information and how libnjb is designed for the developers. So I sent an email to the libnjb developers, and got the reply from Linus Walleij in a short period:

The Zen Micro like all Zens use UCS2 as internal representation. However
the libnjb library uses UTF-8 as input/output format if requested, so it
shouldn’t matter.
… …
It is however very important that the client calls the libnjb function
NJB_Set_Unicode() with the UTF-8 flag, in order for it to work. Else
libnjb will assume encoding is in ISO8859-1 and drop a lot of information
by making approximations and mangling chinese totally. The call should be
made before any other initialization

I combed the Amarok’s source code, and found the bug, Amarok’s developers setup the Unicode after call the NJB_Discover, it may be too late. Once we move that function call earlier, it works. You can download this patch here, and if you are a Gentoo user, here is the ebuild. Check out this HOWTO if you are not clear how to setup the portage overlay.

Further reading showed that the problem is caused by the transport layer from Creative which is built without Unicode support, that drops the ball, and Windows user could do nothing but request Creative to rebuild the code with Unicode; or they can use libnjb derived application, such as NomadSync(not tested yet).

Update Some Chinese characters are missing without a hint, like 一, 言, no idea which cause the bug. If you are using Creative ZenMicro, could you help to test it in Windows and leave a comment here?

HOWTO display sharp Chinese in Gentoo Linux?

Desktop, Development, Gentoo May 11th, 2007

It has been the biggest headache to configure Linux desktop environment to display sharp Chinese glyphs. Personally, I would rather trace the segmentation errors rather than setup the Chinese font. For years, I was satisfied with the bottom line, i.e to browse the Chinese web page using Firefox, input Chinese when necessary.

It is quite embarrassing to stick to the ugly Chinese display as a geek, I would summarize my efforts to configure the Chinese fonts.
Read the rest of this entry »

Make it work

Desktop, Gentoo, Palm February 12th, 2007

The KPilot 3.5.5 once worked fine for my Tungsten T, and it still served for the Treo application installation and backup. Unfortunately, the KPilot could not synchronize the TODO or calendar, the kpilotDaemonn just crashed without a trace, in fact that is my fault, the konqi is not installed in my system.

KPilot developers have released 3.5.6, and claimed that it has solved lots of long-lasting bug, including my patch as well. However, the KPilot 3.5.6 depends on >=pilot-link-12.0, while pilot-link is buggy for the python and java binding, which is reverse-dependency of JPilot. Anyway, all of them are masked.

Tim told us “Make it work”, let’s roll the sleeves.

In Gentoo’s bugzilla, #89823 is attached an unofficial ebuild for pilot-link, just copy it to pilot-link-0.12.2. Since we don’t really need the python or java binding, just disable the use flag in package.use and leave the patch where is.

Next, build kpilot-3.5.6, it would not compile for GCC 4.1.1. Em, interesting. The bug is straight-forward anyway, the compiler is just picky in doing const cast. With this patch, it works.

UPDATE Just contacted with kpilot developer, pilot-link has changed the interface in the version bump, so kpilot 3.5.6 is supposed to work fine with pilot-link-0.12.[01], this patch is for pilot-link-0.12.2 only.

Let’s put the pieces together:
pilot-link-0.12.2 ebulild, kpilot-3.5.6 ebuild, kpilot-3.5.6-const.patch

Now, KPilot 3.5.6 works fine, but put duplicated appointment when HotSync with Treo 650. That is quite annoying, I would like to use Undup as the work around, then dig into the code later.

Diagnosis of KPilot/Palm’s messy text

Desktop, Gentoo November 29th, 2006

It is a pain of ass that Palm does not support Unicode, definitely a big design flaw. It is also a pity that CJKOS would not support the Unicode either, we lost the last chance to patch the system by third party hack. I have to use the GBK encoding in Palm before the legendary PalmOS Garnet or Access Linux Platform available. Unfortunately, the KPilot fails to synchronize the name of the contacts from the KAddressbook, for example, 钟章环 becomes 章&, ^. It is quite curious that part of the string is encoded correctly. Later, I dig into the code, and found this code snippet:

if (!text.isEmpty())
        {
                fAddressInfo.entry[field] = (char *) malloc(text.length() + 1);
                strlcpy(fAddressInfo.entry[field], codec()->fromUnicode(text), text.length() + 1);
        }

The bug results in that the length of the UTF8 encoded string is not the same as the GBK encoded string. A workaround is like this:

if (!text.isEmpty())
        {
                QCString locale = codec()->fromUnicode(text);
                fAddressInfo.entry[field] = (char *) malloc(locale.length() + 1);
                strlcpy(fAddressInfo.entry[field], locale, locale.length() + 1);
        }

It has been submitted to the KDE Bugzilla, Bug 138108.

When Palm meets Linux

Desktop, Gentoo, Palm October 15th, 2006

Palm is an open platform for handheld computing, especailly PIM. However, the Palm Inc. / Access do not provide any official support for Linux. Thanks to the open source community to bridge the gap between Linux desktop and Palm handheld.

When Palm meets Linux
Dell Inspiron 700m, Palm Tungsten T, Syba USB Bluetooth Adapter, and Palm Sync cable(not shown in the picture).


Synchronization

Palm supports various synchronization accesses, serial, USB, IrDA, Bluetooth, Modem, Lan, Wireless. We would address three most commonly used ways.

USB Synchronization
This is the most common and reliable way to synchronize the device with the desktop.
1. Besides the standard USB support, build USB Serial(usbserial) and USB Handspring driver(visor) drivers into modules.

<M> USB Serial Converter support
<M>   USB Handspring Visor / Palm m50x / Sony Clie Driver

2. Update the udev rule in /etc/udev/rules.d/10-palm.rules:

# Palm Tungsten T
BUS=="usb",SYSFS{product}=="Palm Handheld",NAME="pilot"

If you use Sony’s CLIE or Handspring’s Visor, you may take a look at cat /proc/bus/usb/devices to figure out how to identify the device. After you push the button of HotSync cradle, or click the BIG button in HotSync application, the device appears as /dev/pilot in Linux desktop.

IrDA Synchronization
Here is a detailed HOWTO about IrDA Synchronization.

Bluetooth Synchronization
Check this HOWTO.

Integration with KDE

TBD

Developement

TBD

Existed problems

  • KPilot does not convert the string from UTF-8 to zh_CN.gbk back and forth in synchronization (FIXED)
  • Mail plugin works only for legacy Palm mail