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:

#!/bin/sh

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"
        done
        sleep 10
done

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 easylist.adblock.org. 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:


#!/bin/sh

XEPHYR_BIN=/usr/bin/Xephyr
WINE_BIN=/usr/bin/wine
WINPROG_BIN=/path/to/windows/program.exe
X11VNC_BIN=/usr/bin/x11vnc
VNCVIEWER_BIN=/usr/bin/vncviewer
XDISPLAY=:5

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

# start wine
DISPLAY=${XDISPLAY} ${WINE_BIN} "${WINPROG_BIN}" &
WINE_PID=$!

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

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

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

Written by Thomas Fischer

February 14, 2009 at 14:50

Posted in Linux

Tagged with ,

Searchable PDFs with Linux

with 15 comments

Recently, I came across a news posting that there is an open source document management software called ArchivistaBox 2008/IX that can create searchable PDFs from scanned documents. Core components of this software package are Cuneiform (an OCR system) and hocr2pdf (a special PDF generator from ExactCODE).

Using these two programs (both are GPL-2), everyone can generated searchable PDFs which I will demonstrate in the following example.

Lacking a scanned document, I created a LaTeX document using a sample text from Project Gutenberg and generated a TIFF file using GhostScript:

pdflatex mammalia.tex
gs -r320 -dBATCH -sOutputFile=mammalia.tiff -sDEVICE=tiffgray mammalia.pdf

Tip: When scanning or generating TIFF images, try different image resolutions where the recognization rate is sufficient and the image size is still acceptable small.

Generating a searchable PDFs is a two-step process. First, cuneiform is used to generate a special HTML document which contains information where letters and words are located on the TIFF image.
This HTML document uses the suffix .hocr:

cuneiform -f hocr -o mammalia.hocr mammalia.tiff

Tip: You can use cuneiform to write its output in different other formats such as normal HTML or plain text. Use cuneiform -f to get a list of formats.
Tip: Linked against ImageMagick, cuneiform can read a large number of image formats, not only TIFF.

Once mammalia.hocr has been generated, the searchable PDF document is generated using hocr2pdf:

hocr2pdf -i mammalia.tiff -o mammalia-ocr.pdf <mammalia.hocr

Here, the TIFF image is used for the PDF’s visual content, but when you search for text, the meta information from the .hocr file is used to find and highlight the search hits in the document.

Above example is rather artificial, as the used TIFF image has a much better quality compared to a scanned document. If scan results degenerate (not all letters are recognized and some word boundaries are detected wrong), you may want to try the optional switch -s for hocr2pdf to use a more sloppy approach on detecting words.

Now you can use above tools to run your own document management system at home e.g. to scan incomming letters. Happy OCRing… 🙂

Note: Gentoo Linux users can use ebuilds from bug reports for cuneiform and exactimage.

Written by Thomas Fischer

November 26, 2008 at 22:23

Posted in Linux

Tagged with ,

Unix-AG feiert 15-jähriges Jubiläum

leave a comment »

Die Unix-AG der TU Kaiserslautern feierte am 30. August ihr 15-jähriges Jubiläum unter dem Beisein von etwa 40 Gästen. Das Jubiläum wurde mit einer Reihe von Festvorträgen und einer anschließenden Grillfeier gewürdigt. In den Festreden berichteten ehemalige Mitglieder über die Gründungsphase 1992/93 und die späteren Jahren.

Die Unix-AG wurde als Zusammenschluss dreier Vorgängerinitiativen gegründet: Einer Gruppe von Informatikstudenten mit der Forderung zu freiem Netzzugang, den Entwicklern des ersten Campus-Informationsdienstes „KL-Info“ und einer Initiative für ein selbstorganisiertes Lernen an der Universität. Nach der Gründung im Januar 1993 wurde beim Kultusministerium eine Grundausstattung beantragt und genehmigt. Wenig später konnte der erste Rechner der AG unter dem Namen „pizza.unix-ag.uni-kl.de“ in Betrieb genommen werden. Der Name rührte von der Gehäuseform des Rechners her, aber seit dem ist es Tradition, alle Rechner nach leckeren Speisen zu benennen.

15-jähriges Jubiläum der Unix-AG – Grillen

Motivation für die Gründung der AG waren die bescheidenen Ressourcen an den damaligen Universitätsrechner, die Studenten zur Verfügung gestellt wurden. So konnte z.B. der Dekan des Fachbereichs Informatik keinen vernünftigen Grund sehen, Studenten E-Mail-Accounts zu vergeben. Desweiteren sollte die Unix-AG einen Rahmen für den Betrieb von „KL-Info“ bieten und als hochschulpolitische Kraft die Studenten zum „verantwortlichen Handeln in einem freiheitlichen, demokratischen und sozialen Rechtsstaat“ zu befähigen.

In den nächsten Jahren wurde wahre Pionierarbeit von der AG geleistet: So wurde von der Unix-AG einer der ersten Web-Server in Rheinland-Pfalz in Betrieb genommen. Kurzzeitig war eine „Liste Freies Linux“ im Stupa vertreten. 1996 wurde der erste LinuxTag organisiert und fand im Foyer 42 mit einigen Messeständen statt. Die Benutzerzahlen stiegen rasant an: Während 1997 ca. 150 Gäste nach Kaiserslautern kamen, waren es beim LinuxTag 2008 (mittlerweile nach Berlin umgezogen und als e.V. unabhängig von der Unix-AG) über 11.000 Besucher. Der Umzug weg von Kaiserslautern kam nicht freiwillig. Von der Uni-Leitung wurde gefordert, die (damals noch bescheidene) Größe des LinuxTags einzuschränken oder den LinuxTag nicht am Uni-Campus zu veranstalten.

Rückblickend sehen die Gründungsmitglieder die Unix-AG als wichtiges Umfeld, um über den Tellerrand des Studiums hinauszublicken. Nicht nur, daß die Ausstattung der Unix-AG eine viel intensivere Beschäftigung mit der Materie (wichtig für Informatiker) erlaubt, auch die „soft skills“ beim Organisieren von Kursen (auch damals gab es schon einen LaTeX-Kurs) und Veranstaltungen wie dem LinuxTag wurden gefördert. Diese Erfahrungen haben den Unix-AG-Mitgliedern geholfen in ihrem späteren Berufsleben erfolgreich zu sein. Wie es ein Festredner sinngemäß ausdrückte: Bill Gates mag vielleicht sein Imperium von einer Garage aus aufgebaut haben, die Unix-AG-Mitglieder jedenfalls starteten ihre Karrieren in einem Kellerraum in Gebäude 34.

Die Unix-AG ist so erfolgreich nicht nur durch das Engagement ihrer Mitglieder in den vergangenen 15 Jahren, sondern auch durch die Unterstützung von Mitarbeitern des RHRK, denen ein besonderer Dank gebührt. Die Organisatoren der 15-Jahres-Feier möchten allen Gästen für ihr Kommen und dem AStA für seine freundliche Unterstützung danken und hoffen, daß wir uns alle wieder sehen werden zum 30-jährigen Jubiläum.

Die Unix-AG ist eine Arbeitsgruppe an der Universität, deren Mitglieder sich mit Computersystem aus dem Bereichen Linux, BSD und Solaris beschäftigen, aber auch mit weniger technischen „Problemen“ wie z.B. Schach und Online-Spielen die Zeit vertreiben. Außerdem grillen wir auch gerne, sodaß sich die Tradition des „Schneegrillens“ gebildet hat. Als Angebot an alle Universitätsangehörigen veranstaltet die AG jedes Sommersemester einen LaTeX-Kurs, weitere Kurse für das Wintersemester sind z.Z. in Planung. Neue Mitglieder (ob Studenten oder Mitarbeiter) sind immer willkommen. Die Mitglieder der Unix-AG treffen sich jeden Dienstag um 18:15 im Raum 34/349.

Written by Thomas Fischer

September 1, 2008 at 0:00

Posted in Linux, University