Archive for Geek stuff

Blog’s better than backup

It’s very common that people post the scripts they’ve written for their daily tasks. Seems like blogs have become the leading backup solution for Bash scripts these days. I’ve decided to join this growing group of people, and share with you a tiny script from my ~/bin which is called “cleanup”. The code is at the bottom of the post.

When you launch cleanup, it will remove any files that match “*~” (i.e., the backup files which KWrite, Kate and many other apps create), and it will print out any files that have been removed. Additionally, it will look for a Makefile, and execute “make clean” if it has a clean rule. Everything operates on the pwd only. All in all, a very handy tool to clean the ls output.

Disclaimer: The “*~” backup files have use cases, and the “clean” rule may not do what you think it does. So when using the cleanup script, be aware of the possible consequences.


#!/bin/sh
function hasMakeClean()
{
    FALSE=1; TRUE=0
    [ -f Makefile ] || return $FALSE
    grep '^clean *\:' Makefile &>/dev/null || return $FALSE
    return $TRUE
}

case $1 in
    --help|-h|--usage|-u)
        echo Usage: $0 '[-s|--simulate]'
        ;;
    --simulate|-s)
        find . -name '*~'
        hasMakeClean && echo "> make clean located."
        ;;
    *)
        find . -name '*~' -exec rm {} \; -exec echo {} \;
        hasMakeClean && echo "> make clean" && make clean
        ;;
esac

Comments (2) »

Levitation

I usually do not write about stuff not related to KDE. But here is something I would like to share with you: The Levitation project is having a logo contest. If you do not know it yet, Levitation is an effort to rewrite MediaWiki on the basis of a Git repository, to allow for local branches and stuff. The project was started just two weeks ago in response to the controversy about notability criteria in the German Wikipedia. I wish the project all the best. After all, that’s something that, when it reaches production quality, could also be very interesting for the KDE documentation writers.

Comments (8) »

Gnome + KDE

You know about these love calculators? Yes, it’s utter nonsense, but sometimes the calculator is lucky: http://www.lovecalculator.com/love.php?name1=Gnome&name2=KDE

Comments (11) »

And now for something completely different…

Palapeli is in kdereview, and I really got to cool down from the continued QGraphicsView hacking. I decided that the best way to do so would be some Phonon hacking. ;-) Actually, I have never worked with Phonon before, but here’s what I got after two hours of work:

Ljudfil, my own command-line music player

Actually, writing a GUI media player would have been easier, but I’ve grown accustomed to using command-line media players (mplayer and cvlc, to be exact) in combination with screen after a period when my X server crashed quite regularly.

The actual code of Ljudfil is exactly 100 lines long (according to sloccount). All it can do is play all files passed on the CLI in that order, then exit (no keyboard navigation). The name has been chosen with a proven procedure of mine: I opened the Wikipedia page of what the application does or what it handles (“audio file” in this case) and looked for the nicest-sounding translation. This time, it was the Swedish “ljudfil”. By this method, Palapeli’s name was chosen, too. (“palapeli” is Finnish for “jigsaw puzzle”.)

I originally had the intention to write a command-line media player with MPRIS support. There seems to be nothing like this. I would like my media player to survive every X server crash in its screen session, yet be controllable through the “Now playing” applet on my dashboard.

But during hacking together the minimal interface of Ljudfil, I noticed that there is no possibility in Qt to use advanced terminal features. You can only write line by line, although POSIX terminals have much more functions (see “man termios” for a first impression). So, to conclude with a question: Dear lazyweb, is there any library or stuff for Qt that gives me more control over terminal output? (Extra points if it’s portable to Windows.)

Comments (1) »

Windows 7, round 1

Disclaimer: I’m writing the following not as a member of the KDE e.V., but as an individual computer user. As usual, I’m only expressing my very own opinion. Though this should be clear to anyone reading my blog, I’m stating it explicitly now because there have already been more than enough flamewars because of misconceptions and misunderstandings, esp. when it comes to operating system debates.

When Vista had its public beta, I downloaded and installed it on a non-production machine. “Non-production” was a very good idea, because it ate the partition table. I’m not sure how much this has influenced my switch upgrade from XP to Linux some months afterwards. (I was surely also influenced by my first few contacts with Vista, which are very well described by the word “horrible”.)

So I was still running an XP system on my PC at home (mostly for my scanner, which does not work under Linux, and for games that refuse to run under Wine). Eight years after the release of Windows XP, I thought it was time to finally retire XP, and move on to something more stable and secure. (Yes, I know, Linux… but it has to be a Windows for aforementioned reasons. Actually, this machine is a dual-boot with Arch.) So I decided to give Windows 7 a try. Because my university is enrolled in Micro$oft’s MSDNAA program, I could recieve a free copy and license of Windows 7.

I thought that the MSDNAA program was partially meant to attract students from the non-Windows realms to consider the switch. That is, until I wanted to download Windows 7 from their webpage. All I got was “Downloader for Windows 7 RTM.exe” (and the license key). Yuck!

Anyway, let’s see if Wine eats it. Wine wanted to install Gecko, which it uses as a replacement for the Internet Explorer engine that can be used by third-party programs on Windows. Wine crashed. Later I found that the program consists of an Internet Explorer window without interface (think QWebView) that downloads some ActiveX controls (yuck again!) to do the actual downloading. The advantage of this system is that the download can be paused and resumed by simply closing and restarting the program, the disadvantages are about anything else.

Glad am I that I still have a Windows XP installation. This one could execute the Downloader.exe and download Windows 7. I ended up with a 2,4 GB ISO, which I burnt to DVD under Linux. (Windows does not include the necessary tools. Of course.)

Up to now, I’ve already spent three hours of work on an offer that is trying to convince me that Windows is better than Linux. No comment.

Installation of Windows 7 went quite smooth, with the only WTF that it needs to reboot three times, while I have seen Linux distros that install without even a single reboot. I had expected that it would eat my Grub installation in the MBR, but that’s normal (and restored in under three minutes with a Linux live CD.) Actually, I was (for the first time in the process) positively surprised, because Windows did not expose its usual imperialistic behavior when it comes to hard disk partitioning. It showed me a list of all partitions, I selected the Windows XP one, formatted it and clicked “Install”. So far so good.

The desktop showed up in non-native 1024×768 resolution, and with compositing disabled. I’d expected this, because the NVidia video driver is missing. Because my home PC is actually an early 2006 notebook, I expected suitable drivers not to be available, but Dell offered me Vista drivers, which worked very good. On my way, I found another WTF: On the NVidia driver download page, I have to select the exact model of the graphics card, while under Linux one driver serves all. Why can’t Windows be as simple as Linux?

The next possible surprise: The video driver was the only driver I had to install. Under Linux, I expect everything on this notebook to work out of the box, but on Windows, only one missing driver is astonishing. XP required about a dozen driver packages to be installed in a particular order (unless you use the recovery partition, ruin your Linux dual-boot on the way, and get all the nice extra programs that the do-gooders at the notebook manufacturer donate to you; you know what I mean). Another thing which surprised me was Microsoft Paint, which seems to have had its first bigger update since Windows 95.

Of course, something was missing. An open-source browser. An archive reading program. A good text editor. Long story short: KDE was missing. Next surprise: The kdewin-installer has progressed very well (I actually thought that development speed had lowered because of manpower problems). The package list in the simple mode is a bit long because (for some unknown reason) all apps are grouped into module packages, except for kdegames. Also strange: The KDE stuff does not show up in Windows 7’s start menu. I blame this on Windows 7 changing conventions, because this used to work on XP. Adding the bin directory of the KDE installation folder to the $PATH variable solved the problem for me, I’m more used to launching progs with Alt+F2 Win+R than with the start menu.

My conclusion: From my first observations, Windows 7 is definitely the best Windows ever (I won’t judge on how hard it was to achieve this position). However, I do not consider the graphical presentation mature. I mean, I have Aero Glass and such enabled, but to me, Windows 7 feels like a dozen apps, developed in parallel, and combined for the first time only one week before release. There is by far not as much a common style as in KDE.

Okay, there is this glass look all over the place, but the conceptual basis is not much more. The taskbar buttons have nice glow-on-hover effects, everything else doesn’t. The windows have nice compositing effects, the desktop applets don’t. And each of the desktop applets looks, and behaves, different, though there are only nine of them. (Compare this to the dozens of applets shipping with the KDE Software Distribution. And by the way, the desktop applets are not scalable, and of course always too small.)

Using KDE, you do not have to have a widget style that matches your Plasma theme, or suitable color schemes. It’s the behavior and the subtle design elements that make everything feel like a coherent whole. In my opinion, this is absolutely missing from Windows 7, though this should be a key selling point of Windows as a platform. (Many people buy a computer based on the presentation in the computer store, and also based on what friends tell them about their own experience.)

Micro$oft has hundreds of developers working full-time on the user interface, while KDE apps are usually developed by only one or two people at a time, most of them working in their free time as a hobby. Micro$oft has dozens of the best-paid designers in the world, KDE has a handful of mostly freelance artists. Taking all this into account, Windows 7 is a shame for the Microsoft developers, because it’s in my opinion easily surpassed by KDE in terms of polish and design.

The fine print: Just in case someone wants to read this into my post, I am in no way saying that KDE is perfect. I am also not saying that Windows 7 just sucks. (I’ve actually enjoyed using it up to now, esp. when compared to XP and Vista.) What I’m saying is that KDE is far more close to perfection than Windows 7 when it comes to polish, style and taste.

P.S. The rumors about 16 GB installation size of Windows 7 are exaggerated. The Professional edition needs about 9 GB.

Comments (48) »

Say hello to the ModelListModel

Preface: In my new series “Say hello to…”, I regularly present you additions to my Git-based collection of useful helper classes and smaller projects (see its very simple homepage for more information).


Yesterday, you saw me debugging models. Today, you see the result: I’ve implemented a model that lists other models.

The ModelListModel in action

The ModelListModel in action

Perhaps you find this useful for your own application (I’ll use it for fantastic new features in Palapeli’s puzzle library). In an ideal world, I would have implemented a yet more generic model, in which one can “mount” other models at arbitrary positions, but from what I know about model/view programming, this is very hard to do right (i.e., without massive memleaks).

Comments (6) »

Debugging models is hard work

It’s fifteen minutes till midnight and I’m sitting here and analysing pages of boring debug output. What a life. (At least I chose it freely.)

debugging-models

Some of you might read from this that I’m working on model/view stuff currently. I hope to have visible results tomorrow.

Comments (5) »

Say hello to Utils::SelectionDialog

Preface: In my new series “Say hello to…”, I regularly present you additions to my Git-based collection of useful helper classes and smaller projects (see its very simple homepage for more information).


Today, I needed a dialog for Kolf that shows a list view to the user, and lets him select some items from that (plus the “OK/Cancel” buttons which you’re used to from modal dialogs). I had to create a new class, complete with own header and source file, because I needed to declare a new KDialog subclass with a slot.

Incidentally, I’ve already created such dialogs for Palapeli. And much of them. So this is a task that should clearly be simplified. This is how the SelectionDialog class came into life. See the APIDOX in its header for details on how to use it.

Leave a comment »

Say hello to StaticVector!

I present you the second addition to my Git-based collection of smaller code pieces (which now also has a very simple homepage).

This time, I show you a generic container class. There is already a big bunch of container classes in Qt, but I had to make one that fits my needs: the StaticVector.

Its API and purpose is similar to QVector, but it behaves quite differently: A StaticVector does never reallocate or resize its data unless it’s explicity told to do so. Also, any copy of a StaticVector will be read-only, because the data is implicitly shared for performance reasons, but write operations would require the copy to detach from the original data (which is an implicit reallocation, which is forbidden).

The usecase for this is quite simple: In Kolf, we are regularly passing big data arrays to OpenGL and ODE. And passing big arrays to methods from C libraries almost always requires one to pass a base pointer and a size, i.e., two parameters. With such data encapsuled into classes (such as QImage), you might end up with a situation like the following:


void passData(uint* data, int size);

class MyContainer
{
QVector m_payload;
public:
QVector payload() const { return m_data; }
//...
};

MyContainer container;
//...
passData(container.payload().data(), container.payload().size());

This is asking for trouble. The two calls to MyContainer::payload() in the last line create two temporary objects. The latter one is not problematic, because QVector::size() is a const method, but QVector::data() is a non-const method (because the C library wants a modifiable pointer). Calling it causes this temporary QVector instance to detach from the original payload, i.e., allocate new memory and copy the data to there. The C library will remember the pointer to this newly allocated data. After the passData method call, the temporary QVector instances are deleted, which causes the newly allocated data to be deallocated. When the C library tries to access this data later on, we’ll get a SIGSEGV or even uglier things.

That’s where StaticVector comes in. If you substitute QVector with StaticVector in the above example, everything works well, because the temporary StaticVector instances are read-only, but (for this usecase) may return a non-const raw data pointer.

If you ever need to use C libraries which want non-const data pointers, StaticVector might be a good choice for you, because it allows to get this non-const pointer even from const or read-only StaticVector instances, while it minimises misuse of this pointer as much as possible.

Comments (3) »

Say hello to QRangeSelector!

As suggested yesterday, I’ve set up a Git repository for “a broad collection of smaller code pieces which I’ve acquired over the course of my life”. Find it at http://github.com/majewsky/majewsky-misc/, and clone it from git://github.com/majewsky/majewsky-misc.git.

As some first entry, I actually put some stuff I’m currently working on. In line with Andreas Marschke writing about his recent work on a generic video widget, I’m announcing QRangeSelector. This class is similar to a normal slider, but it does not only allow to select a single value, but to select a range of values from some bigger range. (One may also, given some big range, select a small range from it, and select a value within this range.) QRangeSelector also allows for arbitrary contents to be drawn inside its slider area. This screenshot illustrates some usecases which I need in Kolf. (If you do not see the benefit yet, I’ll do a screencast once the QRangeSelector is used in Kolf.)

Testcase for QRangeSelector widget

Testcase for QRangeSelector widget

Note: The white widgets at the top and inbetween the two QRangeSelectors are simple line edits. I needed those to test keyboard focus.

Comments (8) »