cat /dev/maxilys

A glance in the mind of a KDE/Linux developer to see how ideas turn into code.

2007-02-23

KDE: Itch by itch

I found an itch to scratch. I wanted to be able to let Akregator open the links I click in tabs instead of scattering windows all over the desktop. That proved to be an itch very difficult to scratch. "Brain Yoga for the Dummies" didn't help. Your brain has to be more flexible than a contortionist.

The stick I used to scratch the itch is DCOP. This is the only way to open a tab in Konqueror programmatically. I could remember that it was possible but I didn't retrieve what should have been stored in my "database" on my harddisk.

So, I launched kdcop and started digging. Here is what I got:

#! /bin/bash
ALLKONQ=`dcop "konqueror*"`
for THIS in $ALLKONQ
do
HIDDEN=`dcop $THIS konqueror-mainwindow#1 hidden`
PROFILE=`dcop $THIS konqueror-mainwindow#1 currentProfile`
if [ "$HIDDEN"=="false" -a "$PROFILE"=="webbrowsing" ]
then
KONQ=$THIS
fi
done
if [ -z $KONQ ]
then
konqueror $1 &
else
dcop $KONQ konqueror-mainwindow#1 newTab $1
fi


What this little script does is to ask through DCOP the list of all actually running Konquerors. It picks the first one that uses the webbrowser profile and isn't hidden some way. Then it asks this Konqueror to open a new tab with the URL from the command line or, eventually, it launches a new Konqueror if it hasn't found any suitable one.

This way, the script doesn't re-use a Konqueror with which you opened views to directories. The size of my Konqueror window when I browse through files isn't suitable to view HTML pages and I didn't want the script to force me to resize windows. Besides, when I'm done and close --instinctively-- the window, I won't loose all the tabs --intentionally-- opened onto directories.

Well, I put this script under the name newTab in my path and I asked Akregator to use the command newTab %u when I middle-click a link.

Now, in Akregator, I gather all the articles I may find interesting in a row of tabs for me to review later. And since the script doesn't ask Konqueror to raise its window, the tabs are opened in the background, i.e. Akregator remains on top until I feel I'm done with it.

The only problem is... the virtual desktops. They are very handy but, so far, I haven't found the DCOP way to distinguish what's on the current desktop from what's on the other ones --if it exists-- so the tabs may be opened in an invisible Konqueror, depending on in which way DCOP sorts all the available ones.

This is a KDE problem. Of course, the KApplications don't need to know on which desktop they are but IMHO there should still be an easy way to know where they are. Ask to the developer of Taskbar v2...

Any way, it's still a handy script. I haven't tested it yet but it should be possible to use this script as "default browser" so that all KApplications use tabs instead of launching multiple instances of Konqueror. Well, if there wasn't this problem of invisible openings.

After that, I found another itch to scratch: This --excellent-- Kate Sessions Menu applet. It's no longer on my Kicker but I loved it. When I didn't use Kate as a simple viewer, I always used K.S.M. I can't even remember how I worked without Kate's sessions.

What I didn't like was that I had to keep another Kate icon in my Kicker just to be able to drop files on it. And I lost too many drops because I dropped on K.S.M. I asked the author if he intended to implement the possibility of dropping. It's been such a long time that I don't remember what he answered.

I tried to implement the feature into K.S.M. and I understood why the author hasn't done anything yet. It's simply impossible.

Kicker's world is a kind of very private club. You can enter in its garden, talk a walk, sit on a bench and pretend you belong but, sooner or later, you will encounter a sign saying "Members only". In other words, Kicker isn't opened enough. If your applet doesn't belong to Kicker's build tree, you have a very limited access to its lib. You can choose either a container to do what you want in it or an icon with a menu.

If you go the icon way, like K.S.M. does, you're a KPanelMenu and, as the name says, you're a menu. The icon is, well, elsewhere, out of your reach to enable drops on it.

So, I went the other way: the KPanelApplet. That's not much better. Kicker provides some facilities so that your applet shows the same menu than the other applets when you click on the --ridiculously-- small menu button but that's all. You have a container but you're on your own.

I will spare you how I got the --stupid-- idea of using the KPanelApplet from developer.kde.org tutorials section and what I had to do to build it on KDE 3 while it is still designed for KDE 2.

By the way... Come on! KDE 4 is on its way, how is that possible to find anything related to KDE 2 on the big KDE central website. Ever heard of spring cleansing?

Whatever. After a night spent in coding and learning new tricks, I have rebuilt K.S.M. under the name "Kate Sessions Applet". For the developers who understand this kind of things, this is QToolButton and QPopupMenu that I open manually when the button is clicked. I didn't use the intergated popup menu because the menu arrow always points to the bottom whereever K.S.A. is and the menu always tries to open itself under the applet while there are well-established positions for an applet to open it.

Talking about menus. I made something that I always wanted to see in KDE: an auto-reverse menu. If K.S.A. is in the bottom panel, the Kate sessions are ordered from bottom to top and the other entries are on top of the menu. I've always found stupid that the least used entries are the first ones your mouse encounters when a menu opens itself above something.

That's why I put the KMenu on a panel on top of the screen so that its menu looks "normal". With the KMenu in a bottom panel, the first entry your mouse hovers is "Shutdown". I don't think that's the most logical way it should be.

Interlude...

I had to go away to take care of my 5 year-old niece, Alice. We played with Dora the Explorer on the family computer. It's funny to hear her trying to speak English.

She's quite amazing with a computer. She already knows how to switch it on, select her account (on Windows) and double-click to launch a game. I taught her everything because, when she comes to my house, I let her play with SuperTux, TuxPaint, Mr Tuberling or even LBreakout in kids mode.

We also played with Legos then I re-learned how to plait Scoubidous. (According to Google, it's also the english name, instead of "Scooby-Doo" as I supposed it was.)

During these few hours, she says something that stunned me: She's eager to have her own baby and she already knows that she wants a baby girl. She complained that it takes too much time even if she summed up the whole process as going to the hospital, taking a meal and putting the baby in bed. I think she mixes things up --a lot!

Whatever. I love to hear her talking about the fantasy world she lives in. I better do because she never stop talking... :-)

...Interlude


Back into my own fantasy world. I was saying "auto-reverse menu". Here is what I'm talking about:

[Image] [Image]


As you can see, K.S.A. is already working, including the drop feature. I will think about adding a menu arrow if it doesn't pose other problems. What I really need to do is adding the possibility to close the menu with a second click on the icon. And the extra feature I want to add is the possibility to launch Kate with a middle-click. A left-click opens the menu, a right-click opens Kicker's menu. Only the middle-click does nothing yet. And I also have to tune the build tree because K.S.A. still uses the name "helloworldapplet". :-D

Well, I hope Blogger won't flood the Planet with all my old blogs. It forced me to change to the new version... against my will. I didn't want to gave my email address to Google but, apparently, I had no choice. Now, let's hope I won't receive more spam that I already do. Wait and see...

Labels: , ,

3 Comments:

At 23 February, 2007 20:50, Blogger Fela Winkelmolen said...

in the settings panel of konqueror, section "web behavoir" go to the avandced options of Tabbed Browsing and select
[x] open as tab in existing konqueror when URL is called externally
:)

 
At 23 February, 2007 22:47, Blogger dbdkmezz said...

I love the konqueror open in new tab script, very handy :)

 
At 23 February, 2007 23:28, Blogger Maxilys said...

@Nimitar: I have a twisted mind, I prefer twisted solutions. Besides, with all I learnt about DCOP, I didn't waste my time... until KDE 4 makes this knowledge obsolete. I already hate DBus! ;-)

 

Post a Comment

<< Home