Saturday, January 30, 2010

Revise muse-index

Muse is a document writing/publishing tool for Emacs.

Muse-index can be used to show all document in a muse project. But now the file name is shown and sorted by it. I think it will be more useful if document title and create or modify time is shown and sorted by create or modify time. So I revise the muse to do that. The code can be found here.

File Synchronization between N78 and PC

My Nokia N78 have no WIFI support and local GPRS/3G data connection fee is quite high, so I can not synchronize large amount of data between N78 and PC with cloud service. I use N78 disk mode USB link to synchronize, details are as follow. Tested in Debian (gnome version 2.28).

In fact, this is not N78 specific, and can be used to sync files with any devices mountable in Linux.

Setup gnome auto-mount VFAT options

Traditionally VFAT file system is case insensitive, but can preserve case optionally, on the other hand, Linux native file system is case sensitive. So VFAT should be mounted in case sensitive mode for synchronizing software to work properly.

Gnome auto-mount VFAT options can be setup as follow:

Start gconf-editor (System tools -> Configuration editor), check key: /system/storage/default_options/vfat/mount_options, make sure there is "shortname=mixed" instead of something like "shortname=lower" (default value for some distributions) in the value. And "iocharset=utf8" should be set in mount_options too.

Setup autorun upon USB connecting

In gnome, open nautilus-file-management-properties (System -> Preferences -> File management), select tab named "Media", for media handling, set "Open Autorun Prompt" for "Software" media. I have thought gnome-volume-manager will be responsible for autorun script execution, but that is turned off in Debian, and autorun mechanism in nautilus is used instead.

Create a file named ".autorun" in the root directory of the N78 micro-SD card. This is the synchronization script.

Unidirectional synchronization via rsync

Rsync can be used for unidirectional synchronization, such as backup some directories (photos, notes etc) from N78 to PC or push some directories (music, podcast etc) vice versa.

One issue here is that VFAT time resolution is not enough for rsync. This can be fixed via specifying "—modify-window=2" in command line.

Bidirectional synchronization

It seems that unison can be used for bidirectional synchronization. But I have not tried it. Unidirectional synchronization is enough for me.

My autorun script

.autorun in N78

#!/bin/sh

/usr/local/bin/autorun_sync N78

/usr/local/bin/autorun_sync

#!/bin/sh

usage()
{
echo "Usage: $prog <media>"
}

prog=$(basename $0)

if [ $# -lt 1 ]; then
usage
echo -n "Press any key to continue:"
read
exit -1
fi

media=$1
mdir=/media/$media

ldir=$HOME/sync/$media
odir=$ldir/data_out
idir=$ldir/data_in

echo "----------------------------------------------"
echo -n "Rsyncing ..."
rsync -rutv --delete --modify-window=2 $odir/* $mdir/

if [ -f $ldir/dirs.in ]; then
while read d p; do
if [ -z "$d" ]; then
continue;
fi
rsync -rutv --modify-window=2 $p $mdir/$d $idir/
done < $ldir/dirs.in
fi
echo "Done!"
echo "----------------------------------------------"
echo -n "Syncing ..."
sync
echo "Done!"
echo "----------------------------------------------"
echo -n "Unmounting ..."
umount /media/$media
echo "Done!"
echo "----------------------------------------------"
echo -n "Done! press any key to close:"
read

$HOME/sync/N78/dirs.in

Sounds

Work with multiple devices

One big issue of working with multiple devices is synchronizing necessary information among them. For example, synchronizing the document you are writing between multiple PC (notebook, desktop, netbook, handheld), so that you can write it in any time. Synchronizing the web site you are interested between multiple PC and your phone (has web accessing). So the information need to be synchronized should include:

  • PIM information such as calendar, task and contacts etc.
  • Mails
  • Files, including the document you are writing and reading. The bookmark information about your reading progress is necessary too, this can be a reading application specific meta-data file.
  • Web bookmarks, this can be used for URL you want to read but have no time now.

One of the most convenient method to synchronize information amongst multiple devices so far is "cloud" based synchronization. One of the biggest advantages of this method is that it needs not turn on and connect two or more machines simultaneously for synchronization. The disadvantage of this method is the possibility to leak your privacy information, so should use encryption for sensitive information.

I use following cloud services:

  • Google PIM (contacts, calendar, tasks?) for PIM information. On my N78, Google PIM Moblie Sync can be setup as in Nokia Setup Instructions for Google Mobile Sync. Contacts, calendar is supported, but tasks is not supported. On Linux PC, Google PIM Sync can be setup as in How to sync Evolution with Google's PIM apps. Contacts, calendar is supported, but tasks is not supported too.
  • Google GMail for mails. Google Mobile Sync support pushing mail, but my N78 does not support it. But I don't need that too. On Linux PC, GMail can be accessed with IMAP protocol.
  • Dropbox for file synchronization. Dropbox is not opensource software, but UbuntuOne does not work under Debian so far. I may switch to UbuntuOne after it support Debian. Dropbox does not support N78. I use rsync based script to synchronize some data between N78 and my primary PC.
  • Google bookmarks for web bookmarks. N78 can access google bookmarks via web browser, but it is not convenient. Firefox GMarks addon works good with Google bookmarks on PC.

Sony VAIO P

Working on a Sony VAIO P for two days. Some thoughts are as follow.

  • The screen is very good. The backlight is better than my Lenovo Thinkpad X61T, even readable under sun light. But the viewing angle is much worse than X61T. The resolution is good too. The screen size is OK for most tasks, but sometimes I want a bigger screen.
  • It's very thin and light (about 700g?). I can hold it comfortable for hours. So it is very good to be used in holding style. X61T is a little heavy for me to hold (about 1.9kg).
  • Keyboard and trackpoint is good, although the keyboard is a little small for my big hand. I think I can get more comfortable with the keyboard size after more usage. But I hate the position of right shift key. Don't know how long will it take for me to fit in with it. I think I will not programming with it.
  • Terrible Linux support, mainly the graphics drivers. Why does Intel use such graphic card? Hope 2D open source driver ready soon.
  • The CPU of the model I used is only 800MHZ. So the performance is not very good. Not too bad, but not satisfactory too.
  • The battery life is too limited, only 2 to 3 hours.

All in all, I think Sony VAIO P is not the right choice for me. A netbook or CULV notebook with bigger keyboard and screen, longer battery life, better performance and acceptable weight (about 1kg) is better for me.

Linux Softwares for Desktop

Multimedia

EBook management
  • I need an ebook management software, like rhythmbox for musics or f-spot for photos.
Photo management
  • F-spot is an exellent software for photo management. I love it! But it is not very stable, hope it can improve with the time.
  • Comix is good for comics, although I seldom use it.
Music management
  • I think rhythmbox is good. It seems that MP3 ID3 tags editing changes some internal database instead of file itself.
  • For convert the encoding of ID3 tag of MP3 file from GBK to UTF-8, you can use python-mutagen. Command line is: "mid3iconv -e gbk .mp3".
  • To edit ID3 tags of MP3 file, exfalso is good. It seems that easytag is better?

Backup

  • I think backup2l is good for me, because it is very easy to configure.
  • I run backup2l in my working machine for periodic backuping, use rsync to synchronize the backup files to my portable backup hard disk.
  • rsync is used to backup my N78 phone information. It will be run automatically upon plug via ".autorun" mechanism.

Import/sync N78 contacts into/with Evolution

Backup N78 contacts via vcard

In address book of N78, contacts can be backupped from phone to memory card via menu. By default the backupped contacts is saved in Others/Contacts directory of micro-SD card. There is one vcard file (.vcf) for one contact.

Import vcard into Evolution

Vcard can be imported into Evolution, but only one vcard file once. To import vcard files generated by N78, the vcard files from N78 can be catenated into one vcard file, then imported into Evolution.

The vcard file generated by N78 is compatible with Evolution, that is, all information can be imported properly so far. But some information is not displayed in Evolution, and not available when accessed via python-evolution (should be not available in other libedata client too). After changing any field then change back to original value and save the "changes", evething goes OK. Appears a BUG of Evolution, hopes that can be fixed in the future.

Multple contacts in Evolution can exported into one vcard file too. Just select multiple contacts, then click "Save Contact as VCard" in menu, Or save all contacts in one address book with "Save Address Book as VCard".

Import vcard into Evolution via python

Because of the BUG of Evolution vcard importing, I try python-evolution and python-vobject to import N78 vcards into Evolution.

python-vobject is not completely compatible with the vcard 2.1 version, which is used by N78. This can be fixed with simple python scripting or via importing vcards into Evolution then exporting them because Evolution will export vcard 3.0 version file.

This method works good for me. But I encountered one issue too, the address can not be imported because EContactAddress is not wrapped properly in python-evolution yet. Hope that will be resolved in the future. Fortunately, there is only one not so important contact in my N78 address book has address field set.

Import vcard into Evolution via opensync

msynctool --addgroup evo2-file
msynctool --addmember evo2-file evo2-sync
msynctool --addmember evo2-file file-sync
msynctool --configure evo2-file 1
#
# You can keep it as default or use the address book URL in <address_path>
#
msynctool --configure evo2-file 2
#
# Set directory hold the vcard files from N78 in <path>
#

There is issue for this method too. Some information such as phone number is not displayed in imported Evolution contacts, similar with importing vcard with Evolution itself, and can be fixed in same way too. But situation is much better here, that is, more information can be displayed, at least one phone number for each contact.

Bidirectional synchronization with Evolution via opensync

After testing, I found N78 can be bidirectionally synchronized with Evolution via N78 syncml over USB. But again, there is some issues for method too. Like file-Evolution sync via opensync, some information can not be displayed correctly. But among supported object type, contact has the best support, then calendar and task, but notes must be turned off, or opensync will hang.

Firstly, setup USB device file permission for opensync user space driver. Add following lines into udev rules file or put into a rule file under rules.d directory of udev.

BUS=="usb", SYSFS{idProduct}=="007b", SYSFS{idVendor}=="0421", MODE="660", GROUP="plugdev"

Command line as follow can be used to test the USB link.

syncml-obex-client -u
# Found 2 USB OBEX interfaces
# Interface 0:
# Manufacturer: Nokia
# Product: N78
# Interface description: SYNCML-SYNC
# Interface 1:
# Manufacturer: Nokia
# Product: N78
# Interface description: PC Suite Services
syncml-obex-client -u 0 --identifier "PC Suite" --slow-sync text/x-vcard Contacts --wbxml
syncml-obex-client -u 0 --identifier "PC Suite" --slow-sync text/x-vcalendar Calendar --wbxml
syncml-obex-client -u 0 --identifier "PC Suite" --slow-sync text/plain Notes --wbxml

Command line for setup is as follow.

msynctool --addgroup n78-evo2
msynctool --addmember n78-evo2 syncml-obex-client
msynctool --addmember n78-evo2 evo2-sync
msynctool --configure n78-evo2 1
msynctool --configure n78-evo2 2
#
# You can keep it as default or use the address book URL in <address_path>
#

syncml-obex-client configuration is as follow. The notes database name should be left as empty, because notes synchronization for Evolution is not supported, opensync will hang if you set notes database name.

<?xml version="1.0"?>
<config>
<!-- (Only for bluetooth) The bluetooth address if the bluetooth mode is selected -->
<bluetooth_address></bluetooth_address>

<!-- (Only for bluetooth) The bluetooth channel to use. `sdptool browse $MAC` to search for the correct channel -->
<bluetooth_channel></bluetooth_channel>

<!-- (Only for USB) The usb interface number of the SYNCML-SYNC target. use syncml-obex-client -u (you will need access to the USB raw device) to find it. -->
<interface>0</interface>

<!-- The string that the plugin will use to identify itself. Some devices need a special string here. -->
<identifier>PC Suite</identifier>

<!-- The syncml version to use: 0 for 1.0, 1 for 1.1 and 2 for 1.2 -->
<version>1</version>

<!-- if the plugin should use wbxml -->
<wbxml>1</wbxml>

<!-- The username to use. Leave empty to not require a username -->
<username></username>

<!-- the password for the username -->
<password></password>

<!-- sets the connection type to use. 5 means obex over usb, 2 means obex over bluetooth -->
<type>5</type>

<!-- If wbxml is enabled, defines wether the wbxml should use string tables -->
<usestringtable>0</usestringtable>

<!-- Never send ADD command, but send REPLACE (not needed normally) -->
<onlyreplace>0</onlyreplace>

<!-- Workaround around for mobile phones which only use local timestamps and _no_ UTC timestamps! -->
<onlyLocaltime>0</onlyLocaltime>

<!-- Sets the maximum allowed size in bytes of incoming messages (some device need this option set). Example: 10000 -->
<recvLimit>0</recvLimit>

<maxObjSize>0</maxObjSize>

<!-- The name of the contacts db. Must be the same as the phones sends -->
<contact_db>Contacts</contact_db>

<!-- The name of the calendar db. Must be the same as the phones sends -->
<calendar_db>Calendar</calendar_db>

<!-- The name of the note db. Must be the same as the phones sends -->
<note_db></note_db>
</config>

Google Mobile Sync

The last and the best so far. I use it now. The best features of this method are as follow:

  • Works good so far, although some information is not displayed inEvolution, similar with other Evolution importing method.
  • Synchronizing automatically, periodically.
  • Wireless, Evolution side uses WIFI, and N78 side uses GPRS (because my N78 has no WIFI). Some methods above can be done in wireless way too, such as with bluetooth, with some additional work.
  • You need not keep both PC and N78 on for synchronization, because you have the third side now, the Google, in other word, the cloud.

To setup N78 side, you can refer to: Nokia Setup Instructions for Google Mobile Sync.

To setup Evolution side, you can refer to: How to sync Evolution with Google's PIM apps.

Embolden font for PDF rendering

On E-ink devices, PDF seems to be rendered a little light, the readability will improve if it can be rendered a little darker. I found a way to do that, with the "FT_Outline_Embolden", the patch for poppler can be downloaded from here.

Screenshots are as follow:

Hope useful for E-ink PDF viewer or PDF to image converter.

Cellwriter translucence and docking

Cellwriter is my primary on screen virtual keyboard now. But the docking or translucence does not work for me until recently. Now I finally find a way to make it work.

Translucence

Translucence is not the cellwriter's business in fact. It is done by a composite window manager such as compiz. To configure it in compiz, using compizconfig setting manager:

  • Enable "Regex Matching" under "Utility" section.
  • Enable "Opacity, Brightness and Saturation" under "Accessibility" section. Configure this item:
    • In "Opacity" tab page, add "Window specific settings", "class=Cellwriter" for "Windows", "50" for "Window values".
Docking

Cellwriter has full docking support in fact. But it does not work properly in metacity on x86_64. Seems there is a bug of cellwriter and an issue of metacity of gtk+.

  • Enable "window docking" in cellwriter setup.
  • Invoking cellwriter with command line option "—window-struts".
  • Apply the patches to cellwriter (1.3.4).

At first, I found _NET_WM_STRUT_PARTIAL has no effect. After comparing the window strut setting of cellwriter and gnome-panel, I found the main difference lies in data type of struts structure passed into XChangeProperty. Cellwriter uses int, while gnome-panel uses gulong. So I try gulong in cellwriter, and it works like a charm!

Although the format of struts structure passed into XChangeProperty is 32, in "man XChangeProperty", I found following words:

"If the specified format is 32, the property data must be a long array."

So format 32 should be 64-bit on 64 bit machine in fact, and struts should be long instead of int.

Friday, January 29, 2010

Switch network configuration in Debian

Home and office have different network configuration, most lies in proxy setup. A simple script as follow is used to switch configuration. Hope it is useful for someone else too.

#!/bin/bash

prog=$(basename $0)

usage()
{
echo "Usage: $prog <home|work>"
}

if [ $# -ne 1 ]; then
usage
exit -1
fi

tnet=$1
if [ $tnet != "home" -a $tnet != "work" ]; then
usage
exit -1
fi

if [ "$tnet" == "work" ]; then
sudo cp /etc/apt/apt.conf.avail/99proxy /etc/apt/apt.conf.d
gconftool-2 -s -t string /system/proxy/mode auto
else
sudo rm -f /etc/apt/apt.conf.d/99proxy
gconftool-2 -s -t string /system/proxy/mode none
fi

Gnome notify in command line

Method is copied from somebody's blog, can't remember who.

#!/usr/bin/python

import pynotify
import sys

def notify(title="Notify", message=""):
n = pynotify.Notification(title, message)
n.show()


if __name__ == '__main__':
pynotify.init("cli notify")
if len(sys.argv) > 1:
title = sys.argv[1]
msg = " ".join(sys.argv[2:])
notify(title, msg)
else:
notify()

Switch distribution version in Debian

Use testing version of Debian as my primary working environment. But some softwares are available only in sid version, and bugs are fixed in sid firstly. So switching between testing and sid is routine. A simple script as follow is used to simplify/accelerate the operation.

#!/bin/sh

prog=$(basename $0)

usage()
{
echo "Usage: $prog <testing|sid>"
}

current_dist()
{
if grep sid /etc/apt/sources.list > /dev/null; then
echo sid
else
echo testing
fi
}

if [ $# -ne 1 ]; then
usage
exit -1
fi

tdist=$1
if [ $tdist != "sid" -a $tdist != "testing" ]; then
usage
exit -1
fi

cdist=$(current_dist)
if [ "$tdist" != "$cdist" ]; then
cp /etc/apt/sources.list.$tdist /etc/apt/sources.list
mv /var/lib/apt/lists /var/lib/apt/lists.$cdist
if [ -d /var/lib/apt/lists.$tdist ]; then
mv /var/lib/apt/lists.$tdist /var/lib/apt/lists
fi
fi

apt-get update