drag-selection in kfm

I didn’t get anything done on KFM over the weekend (was concentrating on figuring out that IMAP problem), so I felt a bit guilty and did some work today.

I wrote a drag-selection method, which allows you to select files by dragging a rectangle around them.

It’s surprising how many different variables need to be considered, to decide whether a file is selected or not!

For instance, here is the if block which decides whether a file is contained in a selection area, or is touched by it:


In the above, [x1,y1] and [x2,y2] are the top-left and bottom-right of the selection area, and [x3,y3] and [x4,y4] are the top-left and bottom-right of the file icons.

I’m sure there must be a more efficient way than that!

Actually, the code I wrote can easily be made more efficient by applying a binary tree algorithm to find the first and last icons which should be considered at all (if the selection starts at [100,343] for example, then all icons with y4<343 can be confidently pruned).

That’s the visible work for today. I’m going to take a short break, then get onto a bit of files house-keeping.

Oh – demo (use Firefox for best effect), and source.

two imap networking problems

Yesterday, I decided I would sit down and finally get my copy of Kontact connected up properly via IMAP, so I could not only use it for mail, but also for notes, calendering and other crap.

The first step was EMail. I guess this would be bloody simple, as that’s the main use that people subscribe to IMAP for.

I was wrong…

Problem One – connecting

I tried connecting, using the same details I use in work and in webmail, but the client (KMail) would hang and finally timeout.

I tried connecting via telnet, which would start like this:

[kae@kae share]$ telnet verens.com 143
Connected to verens.com (
Escape character is '^]'.

Followed by a pause of three minutes, then finally:

STARTTLS] Courier-IMAP ready. Copyright 1998-2005 Double Precision,
Inc.  See COPYING for distribution information.
Connection closed by foreign host.
[kae@kae share]$

After tests involving a few different machines, it became clear that it was local to my own machine. All other machines connected fine. Beyond that, I was flummoxed.

A few hours later, it occurred to me to examine the differences between a tcpdump of a successful telnet session (from a different machine) and an unsuccessful telnet session (from this machine).

It was suddenly clear that it was something to do with the first tcp header in the tcpdump:

[root@webworks run]# tcpdump host kae.verens.com and port 143 -A
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
21:15:31.501878 IP kae.verens.com.60451 > S
1688597885:1688597885(0) win 5840 <mss 1408,sackOK,timestamp 10763308
0,nop,wscale 7>

I had no clue what “wscale” was, but a quick search online brought me to this page which described exactly the same problem I was experiencing.

Unfortunately, the solution there was not correct for my own kernel (2.6.17), but a quick test showed that the following command solved the problem instantly:

echo 0 > /proc/sys/net/ipv4/tcp_window_scaling

I put that in /etc/rc.local so it would be run on boot.

I still don’t understand the problem completely, but from what I understand, wscale has something to do with the size of a TCP packet that a machine is capable of handling. At some point between my own machine and my IMAP server, one of the routers couldn’t handle the requested wscale, and didn’t have a backup plan for that eventuality. By changing the local value to 0, I essentially simplified my own network, so my machine would only connect with the most default TCP size. If I’m wrong, I’m sorry – I’m no TCP/IP guru.

update: Marcus Furlong pointed me to this post which has a further explanation.

Problem 2 – Kontact

Right, so I then had a successful IMAP connection. I needed to set up KOrganizer, KJournal and KNotes to use it.

The method described by various online resources, is to add IMAP as the default resource through the KDE Control Panel (KDE Components > KDE Resources).

This is not enough. You must then open your Kontact, click Settings > Configure Kontact, then open Mail > Misc > Groupware, and set an IMAP folder as the parent folder of the resources.

Unfortunately, the notes I found didn’t tell me that this only works with Cached Imap (which they also call Disconnected Imap for some reason). So, you must remove your IMAP connection and start all over again using Disconnected Imap. Then download all of your mail (which took me half an hour or so), and restart Kontact. Bloody annoying.

A ridiculous comment in the bug notes:

The imap resource is not designed to be used with online IMAP, only with
cached IMAP. The real bug is that it’s possible to configure it to use online

I totally disagree with the above. Why not allow it to work with proper IMAP??