This is a MARVELOUS piece of software!! I couldn't believe myself at first :S, here is its description from the official website:
This software helps you add a little more security to your desktop. It does so by detecting one of your bluetooth devices, most likely your mobile phone, and keeping track of its distance. If you move away from your computer and the distance is above a certain level (no measurement in meters is possible) for a given time, it automatically locks your desktop (or starts any other shell command you want).
Once away your computer awaits its master back - if you are nearer than a given level for a set time your computer unlocks magically without any interaction (or starts any other shell command you want).
You can find it in the Ubuntu repositories; just Applications -> Add/Remove Programs, Enjooy!!
Note: You should have a screensaver set, don't set it to "Blank Screen" as this might cause the software not to work properly. If you're using Compiz, then you'd better use a simple screensaver, such as "Deco" as it might crash your desktop.