Migrate to MTP

Desktop, Gentoo December 15th, 2007

About nine months ago, I tried to embrace MTP since Creative Lab does not support their own proprietorial protocol(libnjb is the open source implementation) in Windows Vista, and I was really frustrated by the lame upgrade support.

Here is a chance for me to get a 2nd generation Zune which is powered by MTP. Although libmtp is still in very early stage to bridge the gap, we could predict its future from the history.

Amarok supports MTP if the USE flag mtp is enabled. However, the latest stable version 1.4.7-r2 has a bug when transfer file with CJK characters. The bug happens when interfacing with libmtp:

int ret = LIBMTP_Send_Track_From_File(
-        m_device, bundle.url().path().latin1(), trackmeta,
+        m_device, bundle.url().path().local8Bit(), trackmeta,
         progressCallback, this, parent_id
     );

The bug is fixed in SVN (ticket), but if we take non-utf8-locale users into account, for example, MagicLinux takes GB2312 as the default locale, local8Bit may have more flexibility than hard-coded utf8, and it also worked in the UTF8 environment.

Here is the patch , and as usual, an ebuild for Gentoo users (manual).

Small fix for libnjb to transfer Chinese tags

Desktop, Gentoo July 17th, 2007

I once mentioned that some Chinese characters are missing in Creative ZenMirco when using Amarok + libnjb. I checked the libnjb-2.4.4 source code and found that the text codec conversion from UTF-8/ISO8859-1 to UCS2 big-endian is home-brew instead of the standard libiconv, maybe the libiconv is overkill since only three codecs are really needed. According to the specification of UTF-8

U-00000000 – U-0000007F: 0xxxxxxx
U-00000080 – U-000007FF: 110xxxxx 10xxxxxx
U-00000800 – U-0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
U-00010000 – U-001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
U-00200000 – U-03FFFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx
10xxxxxx
U-04000000 – U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx
10xxxxxx 10xxxxxx

while the libnjb developers made a small mistake, so all 0x80xx characters are categorized as abnormal.

if (numbytes == 2 && str[i+1] > 0×80) {
                        … …
                } else if (numbytes == 3 && str[i+1] > 0×80 && str[i+2] > 0×80) {
                        … …
                } else {
                  /* Abnormal string character, just skip */

Here is a patch against libnjb-2.2.4, you may adapt it to libnjb-2.2.5 as well. For Gentoo users’ convenience, here is the ebuild.

I am just curious why this bug has been here for such a long time. How many Chinese Linux/BSD users take UTF-8 as the locale, transfer music to Creative ZenMicro? Are these three factors are really small that make this almost never gonna happen?

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.