Archive for October, 2007

KDE4 Bash Functions

25th October 2007

I’m in the mood for sharing my tips and tricks. TechBase has some nice bash functions for the user you built KDE as (kde-devel for most people). However, if you installed as another user, there are two common tasks: running a KDE 4 app from your normal user’s account, and switching to your kde-devel user and running a KDE 4 app from there.

A few functions in your main user’s .bashrc and in kde-devel’s .bashrc make all this simple.

Disclaimer: these functions are tailored to my set up (Arch Linux) and will probably need adapting for your system. Especially the kde3 and qt3 functions.

First of all: running KDE 4 apps as your normal user. Put the following in your user’s ~/.bashrc (you just insert removefrom, qt4-copy and kde4 if you like):

function removefrom()
{
    local varname=$1
    local entry="$2"

    unset newvar
    for value in `IFS=: eval echo \\$$varname`; do
	if [ "$value" != "$entry" ]; then
	    newvar="${newvar}${newvar+:}${value}"
	fi
    done

    # Set it again
    eval $varname="$newvar"
    unset newvar
}

function qt3()
{
    removefrom PATH $QTDIR/bin
    removefrom LD_LIBRARY_PATH $QTDIR/lib
    removefrom PKG_CONFIG_PATH $QTDIR/lib
    removefrom MANPATH $QTDIR/man

    source /etc/profile.d/qt.sh

    echo "Using QT 3 ($QTDIR)"
}

function qt4()
{
    removefrom PATH $QTDIR/bin
    removefrom LD_LIBRARY_PATH $QTDIR/lib
    removefrom PKG_CONFIG_PATH $QTDIR/lib
    removefrom MANPATH $QTDIR/man

    source /etc/profile.d/qt4.sh

    echo "Using system QT 4 ($QTDIR)"
}

function qt4-copy()
{
    removefrom PATH $QTDIR/bin
    removefrom LD_LIBRARY_PATH $QTDIR/lib
    removefrom PKG_CONFIG_PATH $QTDIR/lib
    removefrom MANPATH $QTDIR/man

    export QTDIR=/home/kde-devel/build/qt-copy
    export PATH=$QTDIR/bin:$PATH
    export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
    export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
    export MANPATH=$MANPATH:$QTDIR/man
    export QMAKESPEC=$QTDIR/mkspecs/linux-g++

    echo "Using QT 4 from KDE SVN ($QTDIR)"
}

function kde3()
{
    qt3

    # Remove the current KDE from variables
    removefrom PATH $KDEDIR/bin
    removefrom LD_LIBRARY_PATH $KDEDIR/lib
    unset QT_PLUGIN_PATH
    unset KDEHOME
    unset KDETMP
    unset KDEVARTMP

    # Add the new ones
    source /etc/profile.d/kde.sh

    echo "Using KDE 3 ($KDEDIR)"
}

function kde4()
{
    qt4-copy

    # Remove the current KDE from variables
    removefrom PATH $KDEDIR/bin
    removefrom LD_LIBRARY_PATH $KDEDIR/lib
    removefrom PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig

    # Add the new one
    export KDEDIR=/home/kde-devel/kde
    export KDEDIRS=$KDEDIR
    export KDEHOME=$HOME/.kde4
    export KDETMP=${TMPDIR-/tmp}/kde4-$USER
    export KDEVARTMP=/var/tmp/kde4cache-$USER
    export KDE_DATA_DIRS=$KDEDIR/share
    export PATH=$KDEDIR/bin:$PATH
    export XDG_CONFIG_DIRS=$KDEDIR/etc/xdg
    export QT_PLUGIN_PATH=$KDEDIR/lib/plugins
    export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH
    export PKG_CONFIG_PATH=$KDEDIR/lib/pkgconfig:$LD_LIBRARY_PATH
    export KDE_COLOR_DEBUG=1

    # Ensure that they exist
    mkdir -p $KDEDIR $KDETMP $KDEVARTMP

    echo "Using KDE 4 ($KDEDIR)"
}

Now you can type "kde4" at a prompt, and thereafter you are in a KDE4 environment. So typing konqueror will give you Konqi from KDE 4 (exactly how I'm typing this post). "kde3" will get you back to a KDE 3 session.

Now for switching to kde-devel. The problem is that you want kde-devel to have the magic cookie that allows it to connect to your X server. Your normal user needs to give it out like so:

function go-kde()
{
    xauth list $DISPLAY | sed "s/^.*$DISPLAY/$DISPLAY/" > /tmp/x.auth
    sudo su - kde-devel
    rm -f /tmp/x.auth
}

Typing "go-kde" should now take you to a kde-devel session, with your magic cookie saved in /tmp/x.auth. But how do applications find out about it? Put the following in kde-devel's ~/.bashrc:

if [ -f /tmp/x.auth ]; then
	xauth add $(cat /tmp/x.auth)
fi

Easy, huh?

KDE 4 Sessions

25th October 2007

So: you’ve installed KDE 4 under the kde-devel user (following the instructions at TechBase). Now you want to try out KDE 4 in all its glory, but as your main user. Well, here’s how.

First of all, we’ll need a script that sets up the environment and starts KDE 4. /home/kde-devel/kde/bin/startkde does most of this, of course, but it expects some things set up first, like PATH. To this end, we’ll set up a couple of bash functions that give us a KDE environment. Create a file /home/kde-devel/bin/startkde4 with the following contents:

#!/bin/bash

# startkde4

function removefrom()
{
    local varname=$1
    local entry="$2"

    unset newvar
    for value in `IFS=: eval echo \\$$varname`; do
	if [ "$value" != "$entry" ]; then
	    newvar="${newvar}${newvar+:}${value}"
	fi
    done

    # Set it again
    eval $varname="$newvar"
    unset newvar
}

if [ -n "$QTDIR" ]; then
    removefrom PATH $QTDIR/bin
    removefrom LD_LIBRARY_PATH $QTDIR/lib
    removefrom PKG_CONFIG_PATH $QTDIR/lib
    removefrom MANPATH $QTDIR/man
fi

export QTDIR=/home/kde-devel/build/qt-copy
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH
export MANPATH=$MANPATH:$QTDIR/man
export QMAKESPEC=$QTDIR/mkspecs/linux-g++

# Remove the current KDE from variables
if [ -n "$KDEDIR" ]; then
    removefrom PATH $KDEDIR/bin
    removefrom LD_LIBRARY_PATH $KDEDIR/lib
    removefrom PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig
fi

# Add the new one
export KDEDIR=/home/kde-devel/kde
export KDEDIRS=$KDEDIR
export KDEHOME=$HOME/.kde4
export KDETMP=${TMPDIR-/tmp}/kde4-$USER
export KDEVARTMP=/var/tmp/kde4cache-$USER
export KDE_DATA_DIRS=$KDEDIR/share
export PATH=$KDEDIR/bin:$PATH
export XDG_CONFIG_DIRS=$KDEDIR/etc/xdg
export QT_PLUGIN_PATH=$KDEDIR/lib/plugins
export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$KDEDIR/lib/pkgconfig:$LD_LIBRARY_PATH
export KDE_COLOR_DEBUG=1

# Ensure that they exist
mkdir -p $KDEDIR $KDETMP $KDEVARTMP

exec /home/kde-devel/kde/bin/startkde

Of course, you can turn most of this file into a bash function called kde4 and place it into your ~/.bashrc, then turn your terminal into a place to run kde4 apps from (in your kde3/gnome/whatever session) by typing "kde4" at the prompt.

Now make sure it's executable (chmod +x /home/kde-devel/bin/startkde4).

Finally, we need a session for KDE4. In /etc/X11, there should be a folder called sessions. This should contain kde.desktop. You can copy this to kde4.desktop and edit it to look like the following (ie: change the Name, Exec and TryExec):

[Desktop Entry]
Encoding=UTF-8
Type=XSession
Exec=/home/kde-devel/bin/startkde4
TryExec=/home/kde-devel/bin/startkde4
Name=KDE4
Comment=The K Desktop Environment. A powerful Open Source graphical desktop environment

Now you should be able to select "KDE4" as the session type in KDM and log in to a KDE 4 session.

libkdeprint

21st October 2007

Having been working on the move away from libkdeprint and to relying almost entirely on Qt’s printing framework, it’s become clear to people the power of Michael Goffioul’s creation. Unfortunately, the only people who understand the code base, as far as I can see, are Michael himself (who has moved on to other projects) and the maintainer, Cristian Tibirna, who doesn’t have enough time available to port the library (a none-trivial task, given the size and complexity of the library and the fact that it is supposed to work as a drop-in replacement for QPrinter, which has had significant API changes).

There has been much wailing and gnashing of teeth over its removal. Just yesterday I wanted to print a booklet from Scribus, and so went looking on the internet for how to do it. A page on Scribus’ wiki told how to do it using the kprinter utility. It was a really simple task, as well, although the way I’d done it meant made it a little more complicated (I had made the pages the final size – A5 – rather than twice the original size, which requires an extra parameter to the psnup utility).

Perhaps people with the time (ie: not Cristian) and expertise (ie: not me) will cause it to make a triumphant return. Perhaps advancements in Qt’s own printing system will make it unnecessary. We shall see. Certainly, some of it needs to be salvaged for the printing kcm and for a kprinter utility. I suspect Qt will never have a “printFiles()” method that will take postscript or pdf files and print them, if only because it’s hard to implement on Windows. In fact, really the only way to do it that I can see is to take the same path as Scribus and use Ghostscript.

As KDE’s resident printing guru (Kurt Pfeifle) has commented before, printing is one of those things that is not sexy (and so doesn’t get worked on) but is necessary and really noticed by the user if it is below par. And, indeed, if it is exceptional, as KDE’s has been up to now.


Follow

Get every new post delivered to your Inbox.