05 Jul

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:

		if(
			kfm_isPointInBox(x3,y3,x1,y1,x2,y2)||
			kfm_isPointInBox(x4,y3,x1,y1,x2,y2)||
			kfm_isPointInBox(x3,y4,x1,y1,x2,y2)||
			kfm_isPointInBox(x4,y4,x1,y1,x2,y2)||
			kfm_isPointInBox(x1,y1,x3,y3,x4,y4)||
			kfm_isPointInBox(x2,y1,x3,y3,x4,y4)||
			kfm_isPointInBox(x1,y2,x3,y3,x4,y4)||
			kfm_isPointInBox(x2,y2,x3,y3,x4,y4)||
			(x1>=x3&&x2<=x4&&y1<=y3&&y2>=y4)||
			(x1<=x3&&x2>=x4&&y1>=y3&&y2<=y4)
		)kfm_addToSelection(file);

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.

02 Jul

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
Trying 80.76.204.233...
Connected to verens.com (80.76.204.233).
Escape character is '^]'.

Followed by a pause of three minutes, then finally:

* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE
THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION
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 > 192.168.1.9.imap: 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
imap.

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