Monday, December 25, 2006

Another script: revision controlled OpenOffice.org documents

I mentioned that I used OpenOffice.org for my thesis.

However, a problem is that binary files, like .ODT, don't work well with revision control systems.

Firstly, they aren't diff-able so you have to also keep a .TXT file, in the repository, in sync with the .ODT. This is error-prone and the .TXT diffs don't reflect formatting changes.

Secondly, because OpenOffice.org files are compressed (.ZIP format), the binary deltas that revision control systems (e.g. SVN) use to save space fall apart for even the tiniest of changes to documents, due to the characteristics of compression.

But thanks to the second anonymous commenter on that blog post, I came up with a new way of revision-controlling OpenOffice.org documents:

What I now do is keep the unzipped OpenOffice.org document in revision control, not the binary .ODT file. This means that I can diff the content.xml between revisions, not bother keeping a .TXT file in sync and avoid SVN's space-inefficient binary deltas since I'm really only keeping text files in the repository (more on this later).

If you checkout such an unzipped OpenOffice.org document from SVN, you can use my magic Makefile to reconstruct the .ODT from these unzipped contents by typing make. It's just like adding water to milk powder.

And every time you make a change to the .ODT file, the same make command works the other way and updates the unzipped contents to match the changed .ODT. Then you can svn commit a new revision.

Caveats:

* Warning: svn status will not report changes to the .ODT, until you type make. Be careful or you might think that your checkout has no local changes and you decide to delete the checkout to "save space"! A "foolproof" way to get around this problem is to skip the svn propedit svn:ignore . [and type kolourpaint-developer-guide.odt] step.

* It actually does store a binary file in revision control, namely Thumbnails/thumbnail.png. I haven't dared try to work around this though, for fear that OpenOffice.org won't like me playing with it.

* Some files such as layout-cache and settings.xml, while not binary unlike Thumbnails/thumbnail.png, change on every save and probably shouldn't be revision controlled either.

* You can't have 2 people working on the same document as merging two content.xml files is asking for trouble. But at least you can diff between revisions.

* A lot of lines in content.xml may change in response to even a small layout change due to lots of tags changing control numbers.

If you try this scheme, please let me know how it goes.

BTW, in the end, my thesis turned out to be 192 pages (probably, about 100 pages too long :)). It was on porting the L4 microkernel to processors without virtual memory, specifically the Blackfin processor. It was written in a rush so apologies for the awful number of spelling and grammatical errors!

A few scripts that could be useful

I just uploaded some scripts I've had lying around for months. Hope they're useful:

1. kbus: starts the DBUS server since it's not done automatically. Sure beats typing eval `dbus-launch --auto-syntax` and copying environment variables all the time.

Update: It looks like DBUS has an auto-starting feature now, via --ensure, so this script is no longer needed).

2. svnupfast: an "svn up" that takes half the bandwidth.

3. svn-import-changes: a poor person's distributed revision control system.

Full details and "sort of" docs here.

Re: We’ve got a couple of feet in our sights

Regarding a few things Boudewijn Rempt wrote about the look of KDE:

1. I actually thought Keramik was stunning during the early builds of KDE 3.1 - it was the perfect balance between good eye candy and not being so noticeable that it got in the way. Unfortunately, I believe it changed in the final KDE 3.1 (please correct me if I'm wrong) and the gradients became too striking.

I liked it in combination with KDE 3.1's bluish icon set, which was sadly replaced in KDE 3.2.

I still use Keramik with the KDE 2 colour scheme and I like it better than Plastik (which is still a very good theme).

2. The window colour changing on focus switches in KDE 4 is a feature of the style, I believe. It is really slow indeed on my old graphics cards as well and for a while I thought it was a palette bug, until I realised that it was supposed to be highlighting the focused window.

I'm sure this will be fixed eventually but I'd still expect KDE 4 to be a tad slower than KDE 3 because of Qt4's automatic double buffering. But I think this is a reasonable price to pay for less flicker.

On a side note, for those of you who are wondering, that automatic double buffering is actually done per top-level window, rather than per widget (I looked inside the Qt code for this and it's actually quite clever).

Thursday, December 14, 2006

Why UI messages must be carefully worded

I got this email from the university today:


Your overall [average mark]: 87.0

There were no outstanding results at the time of this calculation.


Apparently, none of my results are any good ("outstanding"). I feel insulted...

... but obviously, that's not what they meant. They should have used "unfinalised" instead of "outstanding" to be unambiguous.

And no, 87.0 is not my real mark. I'm not going to post the real mark here because there are some fellow students running around uni trying to find out my marks, for god knows what reason, so no need to make it easy for them :)

Saturday, December 02, 2006

A fix for Radeon Xpress lockups under X.org

I'm writing this article so that people googling can find the fix.

I just helped some fellow UNSW students fix Linux hanging when performing a graphical login (no, even the magic sysrq keys I enabled did not help). They were running X.org 6.8.2 (Fedora Core 4) with an ATI X600 graphics card (Dell Optiplex GX620).

I solved this by switching from the buggy opensource radeon driver to the generic VESA driver i.e. in /etc/X11/xorg.conf under Section "Device", I changed:

Driver "radeon"

to

Driver "vesa"

There are also 2 other solutions that apparently work:

1. Richard Zach suggests using the binary ATI driver.

2. Those students found that the opensource radeon driver worked if they updated to X.org X11R7 (Fedora Core 5) [*]. Unfortunately, they need to run some closed-source software that only supports Fedora Core 4. Furthermore, this upgrade does not seem to help with an ATI X200, which experiences similar lockups.

[*] Does anyone know the exact version X.org number?

Tuesday, October 31, 2006

JoJo - Too Little Too Late

I want to avoid sounding like a derganed teenage JoJo fan but I have to admit that JoJo's new single Too Little Too Late is pretty catchy pop and sounds remarkably similar to her original single, Leave (Get Out).

You can watch the video as linked off her website. Will buy the track once it comes out here.

On the other hand, I dislike all her other songs as they have too much of an R&B feel to them. So no, I'm not one of those diehard fans :)

Rent movies, don't buy them

In Sydney, a movie DVD costs about $US15 to $US22. A rental for a week costs about $US3 to $US5.

Therefore, unless you intend to watch the same movie on, at least, 3 separate occasions - each spaced at least 1 week apart - it makes no sense to buy that movie. But who actually watches a movie that many times?

Therefore, it makes no sense to buy movies instead of renting them.

Wednesday, October 18, 2006

A way to reduce stress

Assumptions:
1. You carry a mobile phone in your pocket.
2. You spend too much time checking your watch to see if you have to be at your next appointment, and this causes anxiety.

Method:
1. Do not wear a watch.
2. Set alarms on your mobile phone to warn you of appointments.

Justification:
1. As reaching into your pocket to check the time on your phone is highly inconvenient, you will check the time less often, compared to wearing a watch.
2. You no longer poll for appointments - your mobile phone alarm generates interrupts instead. This is far more efficient and no polling (i.e. no checking of the time) reduces stress.

Auxiliary Benefits:
* You do not have to buy a watch!

Notes:
If there is something else in the room that displays the current time (e.g. wall clock or computer's taskbar applet), the effectiveness of this method is reduced. However, you still get the benefit of being more relaxed as you have the knowledge that the phone alarm will always warn you about your next appointment, in time.

Sunday, October 15, 2006

KDE's 10th birthday

The Dot story tells all.

KDE's certainly changed my life in more ways than one:

A. I get a highly-configurable desktop that - apart from hardware integration and software installation issues - absolutely kicks Windows or Mac OS X in the face:


Konqueror is an incredible web-browser that loads, responds and renders far faster than Firefox/Linux and actually integrates with the desktop. In fairness, I do still use Firefox/IE for those more stubborn websites.

KMail is my email client of choice - friendly and does threading correctly, which I cannot say about Outlook.

KWrite is the model of how UNIX text editors should be - easy-to-use, while still having power features like syntax highlighting. None of the ESC, beep, colon, w, oops I left caps lock on, behaviour of ViM. And none of the Emacs operating system's crazy shortcuts, nor games (yes, literally; I used to spend far too much time talking to psychiatrist app they had in there :)). My favourite productivity boosting feature has got to be "View / New Window".

Konsole and its tabs and convenient Shift + {Left, Right} for switching tabs and Shift + {Up, Down} for scrolling by one line go well with the UNIX terminal's Shift + {PgUp, PgDn} for scrolling. The power of the UNIX command line is the perfect complement to the ease-of-use of the KDE GUI.

But my favourite app would have to be KTimeMon, the only clear and concise system-monitoring taskbar applet in existence.

And, Amarok, a media player that actually cares about playlists and gives context about the current song or artist. Having said that, it is a bit unstable at times and I wished it played video (else it's not a "_multi_media" player).

And of course, KMix.


Most importantly, it's all opensource and free (in terms of speech and beer) so it will always be around.

B. On the developer side of things, hacking on KDE over the last 5 years has taught me more about developing software - heavier C++ than I was used to, revision control, listening to users, UI design bug management, organisation, release processes, highly collaborative and distributed development, support, effective email communication, team management, the list goes on - than I have learnt anywhere else, even university. I still see closed-source companies that do not understand any of the above.

KDE is wonderful because it brings together the best software development practices and the most passionate people to create a kick-arse, opensource desktop environment that users love and a community where people meet, learn from each other and develop all kinds of skills.

It's a bit scary that I've been hanging around for half of KDE's existence. I started with KOffice filters and remember how friendly people like David Faure and Nicolas Goutte were in helping to get me up to speed. I moved on to write KolourPaint, touched other bits and pieces in KDE but became relatively inactive due to university commitments. But every minute I've been there, KDE's been one of the most rewarding things I've ever been involved in. As bonus, next year I'll be graduating and only working part-time after that, so I should have plenty of time to work on KDE.

Finally, congrats to everyone who has contributed to KDE's success and I'm sure KDE will only get bigger and better. Cheers!

OpenOffice.org for documents

I'm writing my thesis in OpenOffice.org. I vowed a few years ago never to learn LaTeX because the whole idea of spending time writing formatting commands, rather than document content, is so last decade (or maybe the one before that?). Yes \{to_you_too.

For a while, I had used LyX which, apart from having been started by KDE founder, Matthias Ettrich, is a WYSIWYM ('M' means "mean" i.e. document structure not formatting) document editor, that importantly generates LaTeX. The great thing is you can have your cake and eat it too - have the benefits of interactive WYSIWYG editing but also produce nice-looking LaTeX.

I found the interface to be a bit clumsy (e.g. "Edit / Paste External Selection" and the overly fast scrollbar) so resorted to writing all the text in KWrite before dumping it into LyX for formatting. But after a while, things just got too irritating - like the lack of a key shortcut for the "type of text" (e.g. "Standard" or "Section" or "Subsection") or when it generates uncompilable LaTeX (when I tried to force blank lines or add images). And if I changed the text in LyX, I'd have to synchronise the .TXT too.

So I retreated back to OpenOffice.org Writer. LaTeX people scoff at such WYSIWYG editors but with paragraph, character and page styles (Format / Styles and Formatting (F11)) available with just a double click (or none at all, if you've setup "Next Style" correctly), I don't see why. You also get the benefits of WYSIWYM, a reasonable user interface and importantly, an easy way to override the formatting if necessary (use RMB / Default Formatting to revert an override). It doesn't generate LaTeX but the output is good enough for me.

Another really handy feature, if you use headings, is the document outline viewer (Edit / Navigator (F5)).

Of course, the binary .ODT is no good for meaningful SVN or CVS diffs. Unzipping it won't help since the XML for the whole document is on, like, 2 lines. So what I do before I commit is I always save a .TXT version for diff'ing purposes. Works great except that the diff won't show formatting changes. Also, it's important after saving to .TXT to immediately resave back to .ODT before you forget and lose your next set of changes.

Yes, it's slow. Yes, it crashes at the most importune times. But it's opensource, its feature set is sufficient for all of my document editing and the .DOC filters are pretty good. And I just submitted my 106 page thesis draft on Friday. Saves me from learning LaTeX, thanks :)

The fastest way to quit acroread under Linux is...

... killall -9 acroread OR Ctrl+Alt+Esc. It's instant.

On the other hand, File / Exit, when a large document is open, takes forever and drives the disk light nuts for maybe a minute - like most laptops, this one has a really slow hard disk. I don't know the exact amount of time but given that Linux performs extremely badly when the disk is being accessed, it's too slow for me to want to try to reproduce it again.

As far as I can tell, no data is lost this way (maybe config settings but I don't mind) so it brings into question the purpose of writing teardown code if it performs so badly.

Friday, October 06, 2006

Page Styles in OpenOffice.org Writer

I'm writing this while waiting for my document to print...

Changing the current page's Page Style by double clicking the style name in the "Styles and Formatting" window (F11) does not work. It stubbornly insists on using the previous page's style's "Next Style" (RMB / Modify... in the F11 Window).

A solution is to force a page break (you think they'd call it a "Page Style Break") i.e. the "Insert / Manual Break..." menu item. Set the "Type" to "Page break" and the "Style" to the one you want. Then manually delete the blank page it creates (after all, it is a page break).

Saturday, September 23, 2006

Review of Kate Alexa - Broken & Beautiful

Australian pop singer, Kate Alexa's debut album, Broken & Beautiful, was released today in Australia.

Hooked by her radio hits "All I Hear" and "Somebody Out There" (which sound like Avril Lavigne "Under My Skin" tracks but more feminine) and misleadingly good iTunes clips of the other tracks, I bought the 14 track CD from a (physical) music store.

The video for "Somebody Out There" can be found here or on YouTube. The "All I Hear" video is available at Yahoo Launch if you have IE and Windows.

I felt the album was like listening to a Britney album (minus the porn): A few strong tracks that are singles or later become singles but the rest, disappointing fillers. It's similar to Ashlee Simpson's and Delta Goodrem's second albums.

To her credit, apart from her radio hits, "Under the Influence of You" (what a name) is absolutely infectious. Her fame-making single "Always There" is also not bad.

Ironically, the track named after the album (or maybe it was the other way round) "Broken & Beautiful" was the most painful of all to listen to due to the unnecessary screaming of the melody-less chorus.

So in summary: Buy her singles, which are very good teeny bopper/pop/rock, but don't bother with the $A20 ($US15) album.

Thursday, September 21, 2006

Fine resignation speeches

I just got elected unopposed [*] as both the Chair of the IEEE UNSW Student Chapter and 2007 Board Member of the UNSW Engineering Faculty. Unlike typical student representatives and executives, I pledge to actually do something rather than use it for resume points.

But anyway, for a bit of fun, I've been studying the 2003 resignation speeches of two prominent politicans. Guess my next degree will be Arts, majoring in Politics. Politics is a great sport if only it were productive. Now, on with the goods:

1. Robin Cook


The British Leader of the House resigns over the government's handling of the 2nd Iraqi War. Great speech overall with the piece-by-piece deconstruction of the "Weapons of Mass Destruction" argument but this bit is truly exceptional:

I intend to join those tomorrow night who will vote against military action now. It is for that reason, and for that reason alone, and with a heavy heart, that I resign from the government.

If you watch the above link's video, albeit lo-res, it's how he says the last bit so simply and unemotionally, that his betrayal is even more shocking. If I were reading the speech, I would have said it far more forcefully.

He got a standing ovation BTW. A politician willing to stand up for what s/he really believes in deserves one. As a rule of thumb (but doesn't apply in this case), such politicians with the brains and big ideas are generally the ones that don't survive in politics for long due to the party machine men. Think Mark Latham.

Too bad the Prime Minister wasn't in the chamber at the time. I'm surprised the government didn't try to gag this rather damaging speech (as such motions, at least in Australian Federal Parliament, are voted on immediately according to the Standing Orders).


2. Simon Crean


The Australian Leader of the Opposition takes a number of subtle and funny stabs at the people who destabilised his leadership:

Don't let your personal ambition cripple the Labor Party as it puts its case for a fairer and better Australia.

[...]

This ballot next Tuesday, is not only about leadership, it's about Labor standards, Labor values and how we conduct ourselves as a party.

[...]

I especially want to thank my senior front bench colleagues who have served the Parliamentary Party well and have remained loyal to me

In hindsight, the most ironic comment of all would have to be this:

Don't put a revolving door on the entrance of the Opposition Leader's office. That door only leads to permanent opposition.

The Opposition Leaders have been Kim Beazley, Simon Crean (the one in question), Mark Latham and guess what, Kim Beazley again. Full circle, huh?

Time will heal, in my view any personal hurt, thus hurt that comes from events like today.

No video this time but from memory, Crean gets real emotional here. I love his choice of words in true political style. He could have said the more straightforward:

You bastards for stealing my prime ministership!

but being a politician, he didn't. Pity.


[*] In case you missed it (and I wouldn't blame you if you did), the font is satirising the old biography pages for a particular political party. In reality, if you are elected unopposed, this simply reflects the sad state of democracy: it doesn't mean no one wanted to vote against you - it just means there were no other candidates.

Sunday, September 10, 2006

I'll Always Know What You Did Last Summer!

It follows, and is imaginatively named after, the 90s teen horror movies, I Know What You Did Last Summer (1997) and I Still Know What You Did Last Summer" (1998).

Movie info and trailer at IMDB. The DVD hasn't been released yet in Australia but from the trailer, it looks like it spoofs the 1997 original. Completely different cast and production company. Even stars Rachel from Animorphs.

I'm absolutely stunned that this movie was made. Nevertheless, I expect that it should be more of the same. Next thing you know they'll come out with "Even in the Afterlife, I Know What You Did Last Summer" and they can make it a vampire/ghost movie.

Will probably watch all 3 once this one comes out (as I can barely remember now what happened in the first 2).

Speaking of sequels, I thought the Tomorrow, When The War Began (aka "When The War Began") series of novels was finished by the 7th one. But now, 2 more followups have been written. I guess I should have known: if you've ever gotten your hands on the 3rd novel, it mentions on the front cover that it's the last in the "trilogy".

I guess all great trilogies come in threes. Actually, scrub that. Scary Movie and Scream are probably respectively, the most tasteless and boring film series ever. Having watched them in the wrong order, Scream actually appears to be a parody of Scary Movie :) And yes, Scary Movie 1 sends up "I Know What You Did Last Summer" as well.

Saturday, August 26, 2006

Movie Reviews

While claiming I have had no time over the last couple of months, I've watched a whole bunch of DVDs. Here's my take on them:

1. Austin Powers in Goldmember (2002)


Austin Powers goes to battle Dr. Evil's latest plan involving an evil villain (name a villain that isn't evil BTW) Goldmember and save the world as usual.

A plotless movie with hopeless jokes. Similar in content and style to Scary Movie 1/2/3.

I haven't seen the previous Austin Powers so I'm probably missing some in-jokes. According to the credits, Mike Myers plays several of the main characters - must be one incredibly good actor with one incredibly good makeup artist.

The only funny parts worth mentioning are the incomprehensible "English English" (English that only makes sense to people from England, not even Australia or New Zealand) and Powers' reading of some subtitles (for some evil dude who chooses to speak Japanese, even though he knows English).

2. The Day After Tomorrow (2004)


The next ice age has arrived. People are frozen solid. Some people are trapped in a library. Overrated. I could continue with more short sentences. Action story with plenty of special effects. Overacted vice-president. Nice watch but not exactly the greatest movie.

3. The Grudge (2004)


Remake of a Japanese movie - even parts of the DVD extras are in Japanese with no English subtitles. Buffy (not her real name), a health care worker, goes to a haunted house but does not feature as prominently in the movie as the trailers might have suggested. Spooky, inconclusive plot - little is actually explained. A refreshingly different approach to horror movies. Think Tarantino style but not boring.

4. Interview with The Vampire (1994)


One of those deep, artistic movies tend to win awards. Tom Cruise, Brad Pitt, Christian Slater and a young, Kirsten Dunsk (Bring It On, Spiderman). Unnecessarily excessive use of horror in some places and fairly lacklustre. Something you might watch for a literature course (to appreciate otherwise unappreciated movies) but not for fun. If you liked Fargo (1996), The Navigator: A Medieval Odyssey (1988), The Piano (1993) or other such boring movies, you'll like this one. But I'd rather have gone to sleep (why did I stay up late to watch this one?).

5. The Island (2005)


A bunch of human clones (oops, spoiled the plot, sorry :)) live in a world where they are constantly watched and are not supposed to have the intelligence to question their purpose.

A disturbing movie about human behaviour and survival incorporating elements from Blade Runner and 1984/Brave New World. Plenty of nice action sequences (the DVD extras said that they really did blow up a helicopter!) but fairly drawn out.

Probably only sold because of the trailer and Scarlett Johansson who I did not recognise from The Horse Whisperer (1998).

6. Miss Congeniality 2 (2005)


Sandra Bullock needs to save the kidnapped Miss United States (from the previous Miss Congeniality (2000)). Some funny bits esp. when her attempts to foil a bank robbery are foiled by her own fame but not as good as the original.

7. Sweet Home Alabama (2002)


Reese Witherspoon has moved to New York and has just released a fashion line. She is about to marry a high profile politician but has an unfortunate problem: her previous husband in - you guessed it - Alabama hasn't divorced her yet. So she heads south in order to tie up this loose end.

An unexpected twist at the end with plenty of clues that one would have forgotten by the end and don't make sense unless one watches the movie again.

One hour into the movie, there's a song "Falling Down" by, the then not famous, Avril Lavigne (who does not update her website and I can tell you first hand: she cannot sing live; nevertheless, you can't actually buy that track on iTunes).

A couple of laughs here and there but a fairly average movie.

8. The Transporter (2002)


Jason Statham goes around transporting packages for criminals. After discovering that one such package contains a kidnapped girl, an assassination attempt is made against him.

A excellent mix of action and wise remarks, between Statham and the detective, that will keep you surprised and laughing (unfortunately, IMDB doesn't list the good quotes). Die Hard without the brainless, monotonous action. Lethal Weapon but not as intense. One of the best action movies I've ever seen. Absolutely recommended.

I normally don't comment on movie goofs but this one was just too obvious:

One hour into the movie, an evil security guard puts down a bottle of beer he was not holding.

Wednesday, August 23, 2006

Fedora Core 5 pirut bug/feature

I've been using Fedora since mid 2004. I quite like it - bleeding edge and with minimal patches on top of the upstream source so there isn't much bloat nor extra bugs (which is why I switched from Mandrake/Mandriva - that story some other day). The distro's not perfect but like democracy, I've found that it's the least worst.

Now, I've been using Fedora Core 4 for a while now. I decided it would be interesting to try out Fedora 5 for the new development machine
kindly donated by Brad Hards.

Other than updated software, it seems the same as Fedora Core 4 but with an extra "feature":


For the first time in Fedora, we have a tightly integrated package-management system, Pirut.

    -- Inside Fedora Core 5, Red Hat Magazine


Only, it cannot install packages from CD by default! It reminds me of that Michelle Branch song:


Goodbye to user friendliness.
Goodbye to the sanity that I knew.
You were the one thing I tried to install.


[ok, that was terrible, I admit :)]

This is a shocking regression and I'm stunned that this made it past quality control, into the release.

Luckily, it's not that bleak as there are solutions:

The first is to create a repository on your hard disk containing all 5 CDs' RPMs. Of course, this takes a lot of disk space... When following those instructions, if you have the CDs, copy the RPMS and the comps.xml directly - don't bother creating an ISO and dealing with the loopback filesystem business (-o loop). The confusing line for me was:


rpm -Uvh RPMS/createrepo*


That was just a tricky way of saying make sure you install the version of "createrepo" RPM stored on the CDs.

The second method I haven't tried but only found a few minutes ago. You can apparently just point yum to the CD ROM drive. This appears to work just like Fedora 4 - requires no extra disk space as it reads straight from the CDs. I'm wondering: if I'm searching for packages, will it search the current CD in the drive or all of them?

Wednesday, August 16, 2006

Order of the zoom actions - vote for your favourite toolbar layout here

In a previous post I talked about taking the number of KolourPaint toolbar buttons down to a minimum, partly in response to the new KDE 4 default of "Text Under Icons" and partly, to fix the dumping ground the toolbar has become.

Thanks very much to everyone who commented on the proposal.

Recall that KolourPaint in KDE 3 looked like this:



New Proposal for KolourPaint / KDE 4


And now, based on your feedback, my latest proposal for KolourPaint in KDE 4 is:


Due to popular demand, I've added back the "Open" and "Save" buttons. I feel that just having a "Save" button as suggested is not sufficient for a paint app where one may open pictures often - this is different to a database app, like Kexi, where one usually manipulates just one DB.

As for concerns regarding removing buttons effectively hiding functionality from users less comfortable with computers, it is difficult to cater for a broad audience but I think overall, the new toolbar layout is more useful for more people since it's less cluttered and has bigger, easier to click buttons. It is of course configurable - this discussion is merely about the most popular defaults.

As you can see from above, I've also made fixed those Undo / Redo buttons so that they don't keep changing their labels (e.g. from "Undo: Text" to "Undo: Connected Lines") so that their sizes remain small (otherwise, think about the German translationa) and constant.

Also, thanks for some of the more creative ideas that were posed but unfortunately, I won't have time to implement them for now.


Dumping Text from the Zoom Actions


It was suggested that I dump the text from the zoom buttons (like KDE 3) to save space. I played with this but unfortunately, the smaller buttons are much harder to click:


So, large buttons with text it is.


Order of the Zoom Actions


But a remaining issue is the order of the zoom actions:


Which one is the best? Answer: I don't know.

B1 is used by KolourPaint in KDE 4 and Acrobat Reader. The ordering of the zoom actions is certainly more conventional but for some reason, seems clunkier.

B2 is used by okular. But the zoom actions look reversed. Yet, for some reason, the order feels more natural (I guess I zoom in "[+]" more often and as a left-to-right reader, it should come first?).

C2 is used by KolourPaint in KDE 3. The advantage of this scheme is that I frequently press [+] a few times until it's zoomed in enough and then I can just move the mouse a short distance to [-] to adjust. In contrast, this adjusting is made more difficult by the [+] and [-] buttons being far apart as in the cases of B1 and B2. So C2 is my favourite.

But I haven't really decided and in any case, this should be standardised across KDE apps so it would be great if you could vote for the one you prefer by adding a comment to this blog entry.

The final design will be chosen based on your votes so vote now!

Tuesday, August 15, 2006

No one checks credit card signatures

Everyone, I think, knows this. Was just pointed to this article at zug.com:

The Credit Card Prank. Absolutely hilarious, starting with the second page.

Have not had time to read Part 2 because I've spent too much time blogging :)

Log system events to VC 12 (CTRL+ALT+F12)

... as inspired by Mandrake 7.2 (2000):

The service syslog starts the system logger syslogd,
which reads /etc/syslog.conf. Add *.* /dev/tty12
to this config file and voila!

ssh tunnelling, tunneling or port forwarding

This is the most straightforward explanation of SSH tunnelling I have ever found. Unfortunately, this page doesn't show up as the first hit in google if you spell "tunnelling" with one 'l'.

This command is equivalent to the example given on that page:


ssh myuserid@gate -L 7777:work:22 cat -


Now for some clarification of this weird but effective syntax:

1. Traffic on port 7777 on your local machine goes to "gate" via the ordinary ssh port. "gate" forwards this traffic on to port 22 on "work".

As port 7777 is a local port, you can choose this to be pretty much anything from 1024 onwards and don't have to reconfigure your firewall.

You can change port 22 (ssh) to e.g. http to access the web server on "work" as if you were sitting at "gate". Now access http://localhost:7777/!

2. The name lookup for "work" occurs on "gate", not your local machine. This is very useful.

3. The "cat -" is a hack to keep the tunnel open.


I'm no network guru and have been wanting to learn this for ages but only found explanations that go on for pages about how great ssh forwarding is without actually giving a straightforward example. Others were obsessed with the intricacies of command line options.

For these reasons and because I don't have time to read a tutorial longer than documents I give to lawyers, I still have no idea how to write iptables rules by hand. If all documentation was like that we would all be spending most of our lives reading instead using computers. Hardly, a "simple primer" as claimed. So when I find a simple tutorial about iptables, I'll blog it.

Thursday, August 10, 2006

The fun of politics 2: Tuckey vs Beazley

If you think the antics inside Australian parliament are funny, wait till you see our favourite politicians outside of parliament. Wilson Tuckey, a hard right-wing government member takes on I'm-trying-be-prime-minister-for-the-3rd-time, Opposition Leader, Kim Beazley:


Beazley: Take your tablets mate.
[...]
Tuckey: Don't you insult me with tablets ... I am as entitled to stand here as you are.
[...]
Beazley: Why don't you take your weak worthless self in there with the weak worthless legislation?
[...]
Tuckey: Don't you call me weak and worthless you [mouths "stupid"] fat so and so.


But there's nothing like the actual video. Use one of the following links from most direct to least (sometimes, embedded video in Linux can be painful):


Direct WMV Stream

Page with embedded stream

Commentary (click on "clip")

Google News search (it's hard to get to the original story as it seems to have been censored off most news sites' main pages)


This whole confrontation was about the government's proposed, tough, new immigration laws that will have boat people being imprisoned at sea! In fact, so tough that several government members later crossed the floor and one resigned. Notice that Beazley was caught off guard in that video and accused the legislation of being "weak", as Tuckey picked up on.

Other interesting happenings include an opposition member bringing in a
stuffed chicken (check out the pic!), getting ejected from parliament along with a fellow member who exclaimed "such a poultry offence" (pun intended).

Lastly, sorry, I haven't checked my email for a few days. I'm very busy but just couldn't help but put up this gag that made my day. I'll deal with email and LCA preparations on Sunday (I promise this time). If something's urgent, please email me through my yahoo account.

Sunday, July 30, 2006

Brad Hards: thanks!

I met up with Brad Hards who was in Sydney yesterday. It's really great to meet someone in person that until now, I had only known on the internet (the only other person I've met in this way was Bart Oldeman from DOSEMU).

We had a very short meeting but he gave me some of his "old" hardware: a P4 3GHz HT machine and a P3 1GHz laptop, both with loads of disk space and importantly, RAM (1GB and 512MB respectively). This is truly impressive stuff that will dramatically improve my productivity:

With the hardware I was using before (and will still be using for a few days until I get the new stuff setup), a 2 line change to kdelibs/kdeui meant that I had to wait several minutes for cmake/make to rediscover libkdeui's dependencies, compile and install (and yes, I am compiling in the kdeui/ directory only), while the computer was thrashing due to the lack of RAM (224MB), worsened by a slow hard disk (10MB/s maximum sequential read). Not to mention the lack of disk space (7.6MB remaining).

So this new hardware is really, really nice stuff and super appreciated - less time waiting, more time coding. Thanks Brad!

I hope Scott Wheeler's Adopt-a-Geek program will restart at some point so that other KDE developers can benefit from such generous donations as well.

An interesting suggestion that Brad made was that perhaps some of us KDE devels in Australia (e.g. also Seb Ruiz, Hamish Rodda) could get together to do a state-of-KDE-4 talk at linux.conf.au in Sydney 2007. I think that would be a great idea so stay tuned :)

Wednesday, July 12, 2006

Why are languages so hard to learn?

I don't mean programming languages which seem trivial to pick up once one has seen a few. After all, one of my lecturers once said "anyone can program - even I can program".

So I mean natural languages. I've primarily used English since an early age. Since then, I've seriously tried to learn French, Mandarin, Japanese and now Mandarin again i.e. I spent a couple of years on each.

However, I usually only get as far as the basics like "My name is ...", "I live at ..." and "My grandmother is ... years old". After that, I get swamped in too much vocab and cannot remember anything. Did I start at too old an age? I hear that people in Europe learn a lot of languages at an early age (e.g. German, French, Italian and English) and they're very good at it.

What is it that makes natural languages so hard to learn compared to programming languages? Most programming languages are Turing complete after all! Even C++ templates at compiletime but that's another story...

So the only things I can remember now are:

je ne parle francais pas [I'm missing the circumflex under the 'c', sorry]
wakarimasen
我不知道

Any tips on how to pick up a language in the shortest possible time? I only need to be able to participate in conversations and read.

On dodging questions again

About my blog entry on How to dodge questions,
Timothy Warner writes:


'Clarence recommends a three-step approach for dodging a 'stumper' question
...
Clarence Dang's recommendation to "stall for time"'


Nono, you got me wrong there. I definitely do not endorse the three-step "Change, Stall, Intimidate" approach I describe. I simply wrote about it because I hate watching people use it.

In reply to aseigo on toolbars

Regarding my blog entry that the new KToolBar default of "Text Under Icons" takes too much space, Aaron Seigo writes:


"the problem is not bigger toolbar buttons, which are good for usability in many ways ... the real problem is that we cram so many (often stupid) things into our toolbars ...

"so when 'mail' appears in a painting program's toolbar (kolourpaint) one really ought to say themselves, 'wait a minute! this isn't an email program!"


I agree it could be solved by a more careful selection of toolbar actions. But the problem is that I didn't decide on the existing ones like "mail" - kdelibs did. The only ones I added were the zoom actions. Sure I could override the KDE defaults with noMerge="1" like I did with the "View" menu but this something that should really be solved on the kdelibs level.

Back to the question of which ones should go. Here's my personal preference:



6 actions - measuring that up with "Text Under Icons", it's actually smaller than the KDE 3 KolourPaint with "Icons Only". This is great but how do I know that the majority of people agree with my personal opinion? I would fight tooth and nail to keep the undo/redo and zoom actions, at least, but maybe everyone else in the world really does email their doodles all the time?

I agree in principle with bigger icons but the text just adds to the visual clutter after one learns what the buttons are. If we have fewer buttons, won't tooltips be sufficient?

Tuesday, July 11, 2006

KolourPaint paint engine experiment works

Today was one of those days where I started out thinking "I should really do some real [thesis] work today ... but half an hour of KDE hacking first can't hurt ..." Naturally, it is now almost midnight and the only thing I have done is KDE hacking. Maybe KDE programming has a secret ingredient that makes it addictive - NiKotine?

Anyway, given the sweeping Qt4 changes in the painting classes, I was extremely worried that it would not be possible to port the KolourPaint backend such that it would a) still perform OK b) support both XRENDER and non-XRENDER. In the meantime, I was fighting a battle to simply get KolourPaint compiling given the pace of kdelibs changes (see my previous blog entry's comments for an example). But today, I finally managed to hack around the last few important QPixmap/QPainter bugs and can demonstrate some 100% working tools: the Rectangle, Rounded Rectangle, Ellipse, Line, Connected Lines, Curve and Polygon:



[Note: if you appreciate abstract art and can see some deep meaning in the picture that I did not intend, feel free to contact me for licensing terms :)]

From this screenie, it should be obvious that KDE's new toolbar default of "Text Under Icons" does not work unless one has a screen with 5,000 x 5,000 resolution. As for why the Tool Box is in such a weird place and orientation, the short version is: breakages due to KToolBar changes. I will fix this and the longstanding problem of unconfigurable icon size by creating a new KToolPalette class after LiveUi (aka. XMLGUI2) is merged into trunk as I expect the merge will break all underlying assumptions all over again. Hopefully, blackarrow / Hamish Rodda will implement the class before I do so that I won't have to do any work :)

Previously, I got KolourPaint to not suck 100% of CPU doing QPixmap -> QImage -> QPixmap translations for opaque drawing operations but transparency was still unreliable and really slow. Now, I have opaque and transparent operations working with and without XRENDER.

So now that I have the underlying infrastructure working, porting the rest of the tools should be fairly straightforward and more importantly, now appears possible. Expect a set of fully working tools real soon now.

But don't use it for anything serious yet: shortcuts don't work (must have checked out kdelibs at a bad time), attempting to save causes a crash in kdelibs (yes, my previous piece of abstract painting was much better):


ASSERT: "d" in file /home/kde4/dist/include/ksharedptr.h, line 108
Aborted


I doubt the clipboard works due to the Qt4 changes and more importantly, I have rigged up assertions such that almost any tool not in the above list will cause KolourPaint to crash as the way they play with the paint engine violates some invariants. Sorry.

Finally, given the amount of time I've wasted hacking around QPainter bugs (read my commit messages and see), I'm going to try to charge Trolltech for bug reports (hey, they charge for the toolkit). Wish me luck :)

Wednesday, July 05, 2006

Got kdelibs compiling

This is with:

trunk/qt-copy -r558252
trunk/KDE/kdelibs -r558279

Make sure you run the ./apply_patches script in qt-copy.
Manually apply 0119-qaction-widgetfactory.diff - K3WidgetAction from kdelibs needs the QActionWidgetFactory class. Two Hunks will fail. Replace them with this:


--- src/gui/widgets/qtoolbar.cpp (revision 558285)
+++ src/gui/widgets/qtoolbar.cpp (working copy)
@@ -271,7 +271,16 @@ QToolBarItem QToolBarPrivate::createItem
item.hasCustomWidget = true;
return item;
}
+ }
+
+ if (action->toolBarWidgetFactory()) {
+ item.widget = action->toolBarWidgetFactory()->createToolBarWidget(q);
+ if (item.widget) {
+ item.hasCustomWidget = true;
+ return item;
+ }
}
+
if (action->isSeparator()) {
item.widget = new QToolBarSeparator(q);
QObject::connect(q, SIGNAL(orientationChanged(Qt::Orientation)),
--- src/gui/kernel/qaction.cpp (revision 558285)
+++ src/gui/kernel/qaction.cpp (working copy)
@@ -54,7 +54,7 @@ static QString qt_strippedText(QString s

QActionPrivate::QActionPrivate() : group(0), enabled(1), forceDisabled(0),
visible(1), forceInvisible(0), checkable(0), checked(0), separator(0), fontSet(false),
- menuRole(QAction::TextHeuristicRole)
+ menuRole(QAction::TextHeuristicRole), factory (0)
{
#ifdef QT3_SUPPORT
static int qt_static_action_id = -1;


I have no idea if this is correct but KolourPaint -r558316 runs.

If you get this message even after invoking the dbus daemon:


FATAL: Session bus not found


$DBUS_SESSION_BUS_ADDRESS and $DBUS_SESSION_BUS_PID are not set because you ran dbus using:

dbus-launch --auto-syntax


instead of:

eval `dbus-launch --auto-syntax`


as dbus-launch actually prints out the shell commands used to set those environment variables.

Lastly, changing button order and making it not configurable is a worrying trend:



I hope this is a birthday prank or something...

Xine out of memory error message

If you see this when starting xine (1.1.1):


This is xine (X11 gui) - a free video player v0.99.4.
(c) 2000-2004 The xine Team.
video_decoder: can't create new thread (Cannot allocate memory)
abort: video_decoder.c:510: _x_video_decoder_init: Aborting.


check your "ulimit -v". Xine seems to hog at least 256MB of virtual address space, even if it's not actually backing that with physical memory.

Ordinarily, I use the ulimit mechanism to automatically kill runaway processes that are sucking too much vmem (on the assumption that it is all backed with pmem). Without ulimit, Linux would be swapping so badly that I wouldn't be able to run "top" to kill the offending process.

But now, I have to up this figure just for xine...

Tuesday, June 27, 2006

How to dodge questions

Update (2006-07-12): I do not endorse this technique. I hate it (see the "It simply drives me nuts" bit). I am merely documenting it to expose those people who use it.

This is what I call the "CSI" (not the TV show) technique - Change, Stall, Intimidate:

First, change the topic: "I think that's a very good question. It certainly raises some interesting issues related to what I said before."

Second, stall by talking about what you said before, for about 2 minutes.

Third, intimidate the person who posed the question by asking "Does that answer your question?" By this time, the audience is so bored that that person will not have the guts to pursure further questioning, in order to save the audience from listening to junk for another 2 minutes. However, if that person is somehow not discouraged and persists, say "Now as I said before" and repeat the "stall" step. Alternatively, s/he would have forgotten his/her original question by now.

It simply drives me nuts when I'm in a meeting and the speaker uses this technique when they clearly have no clue (I'll blog on other techniques used to say nothing, some other day). But from what I can see, this works like a charm. And now you know how to do it and sound intelligent too - great for those "strategic" business meetings that we all inevitably find ourselves in.

Exams over

Yay! The highlight was an invigilator saying:

"For those whose don't know the date, today is the 26th of June 2002".

Wednesday, June 21, 2006

NULL in SQL

Should a null QString be identical to an empty QString? Is there sanity in having undefined vs empty strings in PERL? What about null vs empty strings in Java?

It's those annoying cases in programming that always require extra checks. In SQL, it's NULL. Comparisons with it almost always return "unknown" (which is usually interpreted as false). Worse still, "NOT unknown" is still "unknown". So when one writes:


CHECK (attribute = 0 OR attribute = 1)


SQL will happily allow the insertion of a row with a NULL "attribute". So this must be rewritten as:


CHECK (attribute IS NOT NULL AND (attribute = 0 OR attribute = 1))


See, I just dropped a few marks for this tiny mistake...

Oh, and BTW, Oracle morphs empty strings into NULLs, which is the pinnacle of insane behaviour.

Poseidon - Movie Review

Watched Poseidon on Monday with a friend from high school. I normally watch movies in the evenings on weekends so it was rather surprising how few people there are on a Monday night (could be counted on 2 hands) even though this cinema is in Sydney city.

It's essentially Titanic except they're trapped in an upside-down ship and it isn't boring (it probably won't win any film awards as a result :)).

Quite a thriller as a bunch of the characters break away from the main group to save themselves, as the water rises inside the ship and fiery debris is abound. They drop one by one. I say "a bunch of characters" because character development is fairly poor, there are too many main characters (think "Copland" but not as bad), some of the actors look the same and could have gotten away with playing another character for a bit without anyone noticing.

For black humour, the kid resembles the one from "The Sixth Sense" so just after the ship has tipped over, and with encouragement from a former fireman, he jumps down from where he's hanging, I could just imagine him making the observation "I see dead people".

Nevertheless, the acting of all the characters is exceptional and the life-death decisions they make are rather gripping. The camera work is excellent in building up and maintaining the tension. The pan around the ship at the start is stunning (and could probably only have been done via computer graphics).

Now for plot problems:
1. The elderly man mentions something to his business partners (?) about someone regrettably leaving and that they know the consequences of this. He seems to try to get in contact with this mystery man (but later throws his mobile phone into the ocean). It is implied that this person leaving is going to result in some disaster but this seems to have no bearing on the plot (unless it was disaster). Anyone know what's going on?

2. The captain orders the ship to do a starboard flank. However, the "rogue wave" is shown to be approaching from the right of the ship. So the captain actually turned the ship into the wave!

3. The area with the main dance floor of the ship is claimed to be airtight and the air bubble will keep the ship afloat. But air must be pulled from the outside otherwise, even in normal situations, air would run out quickly and everyone would die of carbon dioxide poisoning (exhaled breath). Therefore, it can't be airtight.

Summing up, an exceptional thriller for people who appreciate simple entertainment. On my Prime - Spiderman 1/2 - Batman Begins scale, where Prime = hopelessly boring, Spiderman = ok-good and Batman Begins = exceptional, it scores somewhere between Spiderman and Batman.

Monday, June 19, 2006

Oral exam on software engineering ethics, fun

There were 3 questions:

1. Free choice

2. One out of nine possible questions based on seminars. At the examination, three are chosen randomly and the student gets to pick one out of those three.

3. One out of eight possible questions based on lectures. Chosen similarly to 2.

Pigeonhole principle comes in handy here: If one wants to prepare for question 2 fully, they only need to prepare 9 - 3 + 1 possible answers. Similarly for 3. Now, pigeonhole principle seemed to me like a stupidly obvious theorem when it was taught but since it's saved me some work, at least now I can appreciate it.

So what questions did I end up picking? Well for the free choice, I chose a rather controversial topic on copylefting software. I won't start another flamewar except to say that I BSD license everything these days so you know my position. It was rather rushed and unfortunately, I don't think the markers were convinced.

The second was the technical problems with the Therac 25.

The third was about how patents might stifle innovation and aren't suitable for software. A key example I used was Eolas' patent claim against Microsoft: "Distributed hypermedia method for automatically invoking external application providing interaction and display of embedded objects within a hypermedia document", where Microsoft lost $US521 million, for implementing something fundamental to web browsers. Imagine if people went around patenting "1+1" and suing school children for practising maths. You certainly can't get away with that but with software, somehow people have.

Friday, June 09, 2006

QWidget::contextMenuEvent()

KolourPaint places widgets on top of a KToolBar for its "Colour Box" (a great abuse of KToolBar, I know - I'll be looking at fixing this). Unfortunately, in Qt4, right clicking on a colour patch (e.g. the transparent or green, circled in red below):



no longer selects the background colour - it brings up the toolbar popup menu instead:


(neat "Lock Toolbars" option BTW)

It turns out that implementing QWidget::mousePressEvent() no longer stops your parent from receiving the right mouse press that would invoke contextMenuEvent(). Spotting the new contextMenuPolicy, I figured that I would just set my children widgets to Qt::NoContextMenu ("the widget does not feature a context menu"). Doesn't work.

They way I got around it was to get the children to eat/accept() the contextMenuEvent(). Another undocumented, subtle change between Qt3 and 4...

In the meantime, I have started porting KolourPaint4 to a new "kpPainter" that abstracts away QPainter (not committed to SVN yet). Rectangles now work and are no longer 1 pixel higher and wider than they should be. Eventually, this abstraction will allow me to dump the Qt graphics routines for a better graphics library.

C++ class member function pointers

This prints -7:


#include <stdio.h>

struct Moo
{
int func () const { return -value; }
int value;
};

int main ()
{
Moo m; m.value = 7;

int (Moo::*funcPtr) () const = &Moo::func;
printf ("%d\n", (m.*funcPtr) ());
return 0;
}


Gotta love the "int (Moo::*) ()" syntax - pointer to any member function of class "Moo" as long as it returns an "int" an accepts nothing.

And of course, "(m.*funcPtr) ()", which invokes the pointed-to function with "m" as "this".

Wednesday, June 07, 2006

The fun of Politics

Don't buy joke books - read the Australian House of Representatives Hansard instead:

http://www.aph.gov.au/hansard/reps/dailys/dr250506.pdf:


"Mr ABBOTT (Warringah -- Leader of the House)
(12.34 pm) -- I move:
That that snivelling grub over there be not further heard.

[...]

Mr Abbott -- If I have offended grubs, I withdraw
unconditionally

[...]

Mr Swan interjecting --

The DEPUTY SPEAKER -- The member for Lilley
walks a fine line by calling the Deputy Speaker an idiot.

Mr Crean interjecting --

The DEPUTY SPEAKER -- The member for
Hotham walks a fine line by clapping."


I don't understand how politicians can get anything done admist these antics.

Friday, May 26, 2006

Survived Thesis A

Just spent the week rewriting my Thesis A (proposal) report "Optimising L4 on Blackfin 53x: for a high performance L4 microkernel on a processor without virtual memory". 40 pages. That's longer than most people's Thesis B (actual work) report! Maybe I spent too long on it at the expense of other assignments... Did the talk today and here is my killer mascot ("Blackfin"):


It's amazing what one can do in KolourPaint/MSPaint :)

At 4am, I was drawing up the slides for the talk and fired up OpenOffice Impress. I don't normally praise software but having never used a presentation program before, I was really impressed by how intuitive it was, taking only about 10 minutes discover how it worked (even at 4am). But then after drawing up the 15 slides, I went to save:

"Write error" [or a similar message]

After trying to save in different formats and on different disks, I got a message saying "OpenOffice experienced a general failure" and then it disabled most of the menu items... My fault for using a beta version of Fedora Core 4's fault for shipping one?

Having said that, performance aside, OpenOffice Writer has worked great so far to allow me to continue on without LaTeX (figured out how to use the styles - press F11 and right mouse click to change a style).

Friday, May 12, 2006

Strange smell from an old computer

My main and old computer (Pentium II from 1998) is giving off a bad smell, as if rubber/tyres are burning or I'm in a train/bus with new brake lines. It's giving me a headache and I have a bad feeling about its health effects.

No wires are touching the heatsink - I already checked that.

Any ideas on what this is?

Thursday, May 11, 2006

What does a "Cheese and Bacon Pie" mean to you?

Quiche? Or something with lots of cheese and bacon?

It was around midnight in Sydney (I wrote that just so that it sounds more mysterious) that I got one of these "Cheese and Bacon Pies" from 7-11. It tastes mainly like it was made of beef and in fact, a closer look at the ingredients said that the cheese and the bacon forms only 12% of the product (in weight, if I remember correctly). How's that for misleading advertising? It was still a good pie though.

What was that not-so-old adage? Something like "we live in a world where lemonade contains no lemon but detergent does".

Sunday, April 30, 2006

Buffy the Vampire Slayer Audio CDs

Yes, I am a fan of BtVS given than I watched all 144 episodes over 2 months. To cut a long story short, the soundtrack (on 3 CDs released at different points when the series was on TV) finally arrived from Amazon after a few months.

In my opinion, Buffy The Vampire Slayer: The Album (1999 Television Series) [SOUNDTRACK] is really not worth buying except for theme music and "Close Your Eyes", which is played when Buffy murders her boyfriend Angel at the end of Season 2 in order to save the world (so much for "boyfriend"; and yes, Ashlee Simpson can make a song entitled that if she wishes).

Ditto, for Buffy The Vampire Slayer: Radio Sunnydale [SOUNDTRACK] (2003 US Version). A good track is "The Final Fight" - the music for the last episode, when the slayers are somehow kicking all the Ubervamps' butts (a nice plot inconsistency: even though Buffy the veteran slayer had trouble killing a single Ubervamp throughout all of Season 7, in the last episode, other slayers and Giles/Spike/Xander/Dawn had no problems; won't say the same about Anya though...).

The last CD, the infamous Once More, with Feeling (2002) musical soundtrack is pretty good esp. Sarah Michelle Gellar's singing in "Going Through the Motions" and "Walk Through the Fire". A nice addition was not Joss Whedon's wife singing :) but rather "Sacrifice", the track for the Season 5 finale, where Buffy selfishly jumps off the tower to "to save the world" when in reality, she knows she's going to go to heaven instead of her sister (yes, my postmodernist interpretation). Jokes aside, this is probably the best finale in the whole series (it's also the 100th episode by accident).

On the other hand, Season 4 was hopeless and in its final episode, literally nothing happened!

I would really like to see an 8th season, set 10 years after the last, when all the actors are older and can't walk but still have to battle vampires etc. :)

So what's up with KolourPaint in KDE4?

These last couple of weeks I've been trying to find a 1:1 mapping between the Qt3 graphics functions and the Qt4 ones. Later, I'll blog in the detail how to really port QPainter/QPixmap/QImage. The Qt4 porting guide is too scanty on important semantic changes.

In the meantime, KolourPaint in trunk/ has regressed a bit because of the KToolBar/KAction changes:



As you can see, the size hints for the Colour Box and Tool Box are not working and since those 6x6 tool icons are so hard to click, I had to manually add them to the main toolbar. I'll fix this stuff after I get the paint engine porting under control.

And apart from not working, KolourPaint is really slow (and blocks the X server) because of unneeded QPixmap <-> QImage transformations in the deprecated copyBlt() (my local changes have dropped copyBlt()) and calls to QPixmap::mask(). The latter has this rather amusing comment in qt-copy/src/gui/image/qpixmap_x11.cpp:


#ifndef QT_NO_XRENDER
if (data->picture && data->d == 32) {
// #### slow - there must be a better way
mask = QBitmap::fromImage(toImage().createAlphaMask());
} else
#endif


Well, at least it was amusing at 1am... See, QPixmap::mask() in Qt3 returned a pointer to a precomputed mask so it was real fast. In Qt4 however, it does X serverside magic and in the worst case (the above snippet of code for QPixmap's with alpha channels), it does 2 X server roundtrips plus computation. In fact, it takes 450ms for an 800x600 image on a 2.2Ghz processor. Simply unbearable.

But the good news is that most calls to QPixmap::mask() in KolourPaint are either for drawing on the mask (since QPainter3 would happily draw on the QPixmap but not update the mask; for Qt4, I will drop this code shortly) or determining whether the pixmap has a mask. For the latter, this Qt3 code:


if (pixmap.mask ())


should not be ported to:


if (!pixmap.mask ().isNull ())


contrary to a previous blog entry since QPixmap::mask() does expensive computation that we throw away anyway. Do this instead:


if (pixmap.hasAlpha ())


So in a couple of weeks, expect a commit that will make painting work. Also, the next time Trolltech and KDE make such sweeping changes to their APIs, they should feel free to send me a cheque :) I am simply spending far too much time porting 50 thousand lines of code (which feels like a "NOP" job) rather than writing new features or doing real work (uni).

An old joke is that if you don't understand what "deprecated method" means, you should update to Java 1.2 (or maybe it was 1.4?). Now, they can add Qt to that. I now have literally 500 "deprecated" warnings to go through. coolo, mueller and montel have been doing a lot of fixes though - thanks! But on the flip side, I'm duplicating some work (I don't commit often due to internet time limitations) and it means I have to review a lot of patches:


$ wc -l *.diff
36 521415.diff
859 528186.diff
492 530108-533650.diff
1000 535185-535614.diff
0 ALSO_REVIEW_CMAKE.diff
2387 total


Speaking of which, cmake works quite well. In fact, I'm going to remove the remaining Makefile.am's since compat/Makefile.am is already gone. cmake is faster than unsermake, which was faster than automake. cmake supports "make -t". Also, if you want to hack CXXFLAGS long after running "cmake", the file you want is kdegraphics-build/kolourpaint/CMakeFiles/kolourpaint.dir/flags.make.

Now, back to work!

Tuesday, April 11, 2006

Determining if a type is a pointer at compile time

http://doc.trolltech.com/4.1/qlist.html:

"QList is represented as an array of pointers to items. (Exceptionally, if T is a pointer type, a basic type of the size of a pointer, or one of Qt's shared classes, QList stores the item directly in the pointer.)"

So a QList<QRect> is going to be an array of QRect * but QList<QWidget *> will be an array of QWidget * - not QWidget **. But how can we determine whether a type is a pointer at compile time?

Update: This describes the method used in Qt for compilers lacking support for partial template specialisation. If you have partial specialisation, it can be done in a very straightforward way (see blog comments).

Well it seems to be done by abusing our favourite language. QList uses the QTypeInfo class - the interesting bits being:


template <typename T> char QTypeInfoHelper(T*(*)());
void* QTypeInfoHelper(...);

template <typename T>
class QTypeInfo
{
public:
enum {
isPointer = (1 == sizeof(QTypeInfoHelper((T(*)())0))),


int *



Now, consider the case of QTypeInfo<int *>. the last line expands to:

isPointer = (1 == sizeof(QTypeInfoHelper( (int * (*) ()) 0))).

Now I've added some spaces so that it can actually be read. It's saying, pass NULL - casted to a pointer to a function that accepts nothing and returns an int * - to one of the QTypeInfo functions.

But to which 1 of the 2 overloads? Well, the C++ rule for resolving overloaded function calls is to select the function with the most specific matching argument types, assuming no ambiguity. In this case, our function call matches this candidate:

template <typename T> char QTypeInfoHelper(T * (*) ());

because T is int. Now you won't actually find QTypeInfoHelper defined anywhere because all sizeof is interested in is the size of the return value of the function - it doesn't actually execute it. Now, the return type is a char, which is of size 1, therefore isPointer is true.

int



Now we look at a non-pointer type, int. The tricky line expands to:

isPointer = (1 == sizeof(QTypeInfoHelper( (int (*) ()) 0))).

That function pointer argument type accepts nothing and returns an int. It's not going to match the same overload because it's looking for a pointer (the T *):

template <typename T> char QTypeInfoHelper(T * (*) ());

And int is no pointer. Therefore, it can only match the catch-all overload:

void* QTypeInfoHelper(...);

which returns a void* and guess what:

isPointer = (1 == sizeof(void *)).

is false (unless on an 8-bit machine :)). Therefore, int is correctly detected as not a pointer.

Conclusion



QTypeInfo manages to determine whether a type is a pointer without:


  1. actually invoking a function (by merely checking the size of the return type)

  2. ever constructing an element of type T (which might otherwise cause side effects)

Thursday, April 06, 2006

Moving messages in PINE

I'm stuck with using PINE/Mutt at uni - partially because they don't have KMail (or much of KDE for that matter) and mainly because I want to be able to access it over SSH from anywhere. Today my inbox finally got too big to manage so I started splitting it up into multiple folders and combined the scheme with filters.

And guess how you save a message in PINE? Well it's not by pressing 'S' for "Save" (that moves messages between folders). It's 'E' for "Export".

In other news, I had a dream where I swear I saw Terminator 4. Great sequel, plot but as with all good dreams, I forgot by the time I had woken up. Too bad. Would have sold the plot to the Governor of California otherwise.

Sunday, March 05, 2006

Porting to KDE 4

I've just managed to compile KDE 4 so that I can port KolourPaint. A lot of work (thanks mainly to Laurent Montel) has already been done.

I spent yesterday combing through the 15,000 line diff (actually, I did some tricks to reduce my reading down to 5,000 lines) and fixed 2 main kinds of errors:

1. qt3to4 remaining variables like "red" to "Qt::red".

2. "if (!pixmap.mask ())" should not be "if (!pixmap.mask ().isNull ())". It should be "if (pixmap.mask ().isNull ())".

KolourPaint exploited Qt3's painting system to the max. And given the rewrite of the Qt painting system, there's going to have to be a lot more work before KolourPaint compiles, let alone works. With the addition of proper alpha channel support, Qt seems to have done away with the Qt::NotAndROP and friends. Going to be tricky to port.

And I just don't think that breaking source compatibility every few years and saying "now port KDE's several million lines of code" works well. Something to think about for future Qt's & KDE's.

Oh, and this is my first blog post :)