Thomas Fischer's Weblog

Life, Linux, LaTeX

Archive for the ‘Linux’ Category

KParts Browser Plugin

with 21 comments

One of the biggest advantages of Konqueror is that it smoothly integrates with the KDE desktop. Any file type can be opened within Konqueror as it loads KParts modules to handle non-HTML files. For example, to display PDF files within the browser, the embeddable part from Okular is used. Unfortunately, this technology is KDE-only, at least no other browser supports KParts.

On the other side, most browsers support a plugin technology originally coming from the good ol’ Netscape 2.0. Most prominently, it is used for the Flash plugin from Adobe and the PDF plugin as part of the of Acrobat Reader.

So, why not combine both technologies to use KDE parts in “normal” browsers?
With quite little effort, based on some examples by Qt/Nokia, I was able to hack a proof of concept: A small plugin which can be used with browsers such as Mozilla Firefox, Opera, Arora, or Chromium.

So far, the plugin supports PDF and PostScript files (via Okular), OpenDocument text, presentation, and spreadsheet (via KOffice) and MP3/OggVorbis files (via DragonPlayer). More file types can be added with only a few lines of code, given that there is a KDE part installed which can handle this file.

Interested? Visit the project’s homepage and try it out yourself!

Written by Thomas Fischer

May 22, 2010 at 17:09

Posted in KDE, Linux

Recording VoIP Phone Calls with ALSA

with one comment

Recently I stumbled upon the problem of how to record a phone call when using Skype (or any other VoIP technology) under Linux. For Windows and Mac OS X, there is a bunch of commercial software available, but nothing for Linux. But hey, it is open source and everything is documented, so why not figuring out how to do it anyway?

After searching for options, I found a pointer to the tee device, which works similar like the tee command on the command line: You can transparently pipe data through it and a copy of all data will be written to a file as well. A new ALSA output device can be configured in ~/.asoundrc using the tee device. It can either record the default device or a specific device:

pcm.tee00 {
        type empty
        slave.pcm "tee:'plughw:0,0','/tmp/out0.wav',wav"

Above example will save all audio recording going through plughw:0,0 to file /tmp/out0.wav. If you have different recording and playback devices (e.g. an USB microphone and standard speakers), add multiple section with the corresponding plughw number (also change the device’s name, e.g. pcm.tee10).
In the VoIP application, you have to set the new sound devices for microphone and speakers accordingly:

Skype Audio Settings
(numbers and names of devices may differ for you!)

If you make a test call, you will get two output files: one with your microphone’s recording and one with your speaker’s recording. Using a sound editor like Audacity or SoX, you can edit and merge both files.

This approach, however, has one drawback. Every time an application “opens” a sound device, the output file will be recreated and the previous recording will be lost. With Skype, the hangup sound at the end of the recording is such a case. I haven’t found out if you can configure ALSA’s tee device to append to a file instead of overwriting it, but the solution I came up with is to copy the output files to a different location before the phone call is over. To automatize the process, I wrote the following shell script:


while true ; do
        timestamp=$(date '+%Y%m%d-%H%M%S')
        for wav in /tmp/out*.wav ; do
                test -f "$wav" || break
                newwav="$HOME/out/"$(echo "$wav" | sed -e 's/\/tmp\///;s/.wav$/-'$timestamp'.wav/')
                echo "Copying  $wav  to  $newwav"
                cp "$wav" "$newwav"
        sleep 10

When running, it will copy every 10 seconds all output wav files from /tmp/ to the out/ directory in your home and append a time stamp to the file name. You simply start this script before starting the phone call and exit it with Ctrl+C. Then, the largest of files out0*.wav or out1*.wav, respectively, in the out directory will be your microphone or speaker recording, respectively.

Written by Thomas Fischer

March 20, 2010 at 12:00

Posted in Linux

Mounting devices in KDE without Konqueror, Dolphin, or digiKam …

leave a comment »

KDE 4 has this nice plasma widget called ‘device notifier’, which shows attached devices such as USB flash drives, CD/DVD drives, or digital cameras.

Device Notifier

Device Notifier

Clicking on this icon shows all attached devices, in my example it is a single USB flash drive named ‘256MThFisch’.

Device Notifier plasma widget

Device Notifier plasma widget

Clicking on such a device brings up a list of possible actions, e.g. to browse the files with Dolphin or Konqueror, downloading all photos with digiKam, or playing music titles with Amarok.

List of actions with device

List of actions with device

Well, this is quite nice for users relying on KDE software only. But what happens if you are a power-user, using terminals such as Konsole? Whenever you want to mount a device, you have to start an application such as Dolphin, Konqueror, or digiKam even if you do not want to use it …

Adding your own Action for Mounting

As KDE4 is very configurable, you can improve this situation. In the System Settings you can configure which action are available when a storage medium becomes available. Here, we are going to add our own action which ‘just’ mounts a device.

System Settings - Advanced

System Settings - Advanced

Configuration of Actions for Devices

Configuration of Actions for Devices

To add you own action, click on the ‘Add’ button and enter a name for the new action, such as ‘Mount’.

Adding a new action

Adding a new action

In this new action, you can an icon which resembles that action of mounting. In my case, I chose emblem-mounted.png from the emblems directory in the Oxygen icon set. For the command to execute, you can enter any command you like. If you want to see no feedback, use /bin/true. In my example, I used /usr/bin/kdialog --msgbox to get a message box showing a confirmation once the mount process is complete.

Next time you plug in an USB drive, a new option will show up to ‘just’ mount you device without starting any bloated application.

List of actions, 'just mount' option included

List of actions, 'just mount' option included

Once you activate the ‘Mount’ option, it takes 1-2 seconds and a message box pops up confirming the mount operation. The device is read to use in any application.

Message box

Message box

Current Issues

The current approach has some minor issues which may get addressed in later improvements:

  • Cases where the mounting operation fails are not handled
  • The message box does not show the devices name, type or mount point

Still, good luck with testing this ‘hack’ 🙂

Written by Thomas Fischer

November 9, 2009 at 22:43

Posted in KDE, Linux

Tagged with , , , , , , ,

Automatic AdBlock filter list updates in Konqueror

with 4 comments

As a KDE user, Konqueror is my favorite browser. It offers smooth integration into KDE, both in looks and features (e.g. using the Okular part to view PDFs). Its rendering engine is so good that it was forked into WebKit used in Apple’s Safari and Qt. One aspect Konqueror lacks in comparison to Firefox, though, is the support of plugins/addons of all kinds to add more features to the browser. There is a set of security and privacy enhancing plugins for Firefox I use myself and recommend to others. One of them is AdBlock Plus which uses a well-maintained list of URLs to block if you want to experience the net with less annoyance.

On the other side, Konqueror has a similar adblocking functionality built-in since KDE 3.5 (late 2005). In the configuration dialog, users can add fragments or regular expressions of URLs to be blocked. Maintaining such a list yourself is quite cumbersome, especially if you have accounts on several computers. At least since March 2007 there has been a feature request in KDE’s bug tracking system to add an automatic updater to Konqueror’s ad-filtering.

Last weekend, I started to scratch the itch and implemented an automatic filter list updater. Luckily, the internal format of AdBlock entries in Konqueror matches the one use by AdBlock Plus, except that some advanced features are not (yet) supported. Based on the then-current KDE 4.2.4 code I made changes to both kdelibs and kdebase. The former one contains the KHTML component including the actual filter, the latter contains the code for Konqueror’s settings GUI.

The changes I made to kdelibs work as follows: Read the khtmlrc configuration file to get a list of filter files following the format used by AdBlock Plus. My example configuration file contains several lists from The filter list files are downloaded and cached if no local copy is available or if it is outdated. Each filter list file is loaded and added to Konqueror’s current filter list each time the browser is started. The user-configured filter list is not modified, as the changes occur in memory only.

If you edit your khtmlrc manually to add new filter lists, this works already fine without GUI. For a better usability experience, I modified Konqueror’s settings dialog so that users can select from a list of preconfigured filter lists (currently, all lists from EasyList) which to actually use. Additionally, the time interval to refresh the lists can be configured.

Manual filter in Konqueror's AdBlockAutomatic filter in Konqueror's AdBlock

I refrained from adding an option to add, modify or delete list entries in the GUI. This is simply for two reasons: (1) Users may tend to enter filter lists that do not follow the format (e.g. from other adblocking filter sites) and (2) the list of available filter lists does not change that often that it cannot be changed in the next monthly update of KDE. If users are eager to add more lists not officially approved, they can still edit their configuration files manually.

All patches and an example configuration file are available from bug report 143495 in KDE’s bug tracking system. If you have constructive suggestions, please add you comments to the bug report (do not post comments in this blog, that won’t help). To support the patch in getting approved and added to the official code base, vote for the bug (login required).

Update (20091201): I posted the patches on KDE’s Review Board a few days ago and got a review from David Faure. There are some minor issues to change and fix, but his overall comment was “Nice (but obviously not for 4.4 due to the feature freeze, it will have to be for 4.5)” 🙂

Update (20100812): My AdBlock extension has become part of KDE 4.5 🙂 Check out this screen shot:AdBlock filter list in KDE 4.5

Written by Thomas Fischer

August 5, 2009 at 22:08

Posted in KDE, Linux

Tagged with , ,

Enlarge Fullscreen Programs in Wine

with 8 comments

Back in the good old days, PC games used a resolution of 320×200, 640×480, or maybe 800×600 for the game play. This was even true for Windows games. Then it was common to have a 15″ CRT monitor which could display a large number of different resolutions with only little loss in quality.

Today, we have nice and shiny LCD displays, which are perfect for common office tasks. But with a horizontal resolution of e.g. 1600 pixel, you have a problem when playing these old games. Basically, you have two options when running your games with Wine: Scale the game’s small resolution to your display’s physical resolution (which looks ugly depending on the interpolation and the display’s aspect ration, e.g. widescreen displays) or run the game in a small window which makes a game designed for fullscreen displaying as large as your palm. No fun playing games here…

As far as I know, there is no possibility to scale a Windows program in Wine to make it more readable for high-resolution displays. However, I was able to create an ugly hack which allows us to “zoom” into these programs. The basic idea is to set up a dedicated X server with a fixed resolution for the Windows program and use a VNC connection (which can scale images) to get an enlarged view on this program.

If you like to follow the examples below, you will need to have the following programs installed:

  • Xephyr, which is part of your X server installation
  • Wine, installed and configured to run programs fullscreen (deselect “Emulate a virtual desktop” in winecfg)
  • x11vnc
  • RealVNC, TightVNC, or any other VNC client (server component not required here)

Most distributions such as Gentoo Linux provide packages for above programs.

Getting started

To run Windows programs within a scaled VNC session, the following four easy steps are neccessary. You can start each program in the background by appending an ampersand (&) or opening a terminal (simplifies debugging if something doesn’t work).

  1. Start Xephyr to initiate a nested X server session. Set the resolution to match the requirements of your game (here, it is set to 640×480). I observed that some programs crash if the GLX extension is activated, so I disabled it here. The display number is set to 5 (arbitrarily).
    Xephyr -once -screen 640x480 -extension GLX :5
  2. Start Wine and your Windows program. Take care to use the display provided by the new Xephyr instance.
    DISPLAY=:5 wine path/to/your/windows/program
  3. Start the VNC server which attachs to Xephyr’s display. Only connections from localhost will be accepted (for security purposes) and the scaling factor will be set to 2 (change to other factor to match your requirements). Option “:nb” speeds up the scaling.
    x11vnc -localhost -scale 2:nb -display :5
  4. Start the VNC client which connects to the server (the following example is for RealVNC).
    vncviewer -FullColor -ZlibLevel 0 localhost

Well, this is rather cumbersome, but it works 🙂

Shell script

Here is a shell script which performs above operations:



# start Xephyr in background
# note: *with* GLX extension wine crashs sometimes
${XEPHYR_BIN} -once -screen 640x480 -extension GLX ${XDISPLAY} &
sleep 2

# start wine

# start VNC server
${X11VNC_BIN} -localhost -scale 2:nb -display :5 &
sleep 3

# RealVNC
## ${VNCVIEWER_BIN} -FullColor -ZlibLevel 0 localhost &
# TightVNC
${VNCVIEWER_BIN} -compresslevel 0 -nojpeg localhost &
# keep for both RealVNC and TightVNC

wait ${WINE_PID}
sleep 1
sleep 1
sleep 1
kill ${XEPHYR_PID}

Written by Thomas Fischer

February 14, 2009 at 14:50

Posted in Linux

Tagged with ,