KIO

Network transparency with KIO.

First published in the June issue of Linux Journal:
http://www.linuxjournal.com/issue/146

Kioslaves are out-of-process protocol handling plugins that let you access various services as though they were part of your local filesystem. They can be accessed through the Konqueror file manager and any standard file dialog in most KDE applications. The applications using Kio don’t need to be aware of how to access the remote host or device - the ioslave handles it all. This provides powerful and flexible network transparency for KDE applications.

KDE includes a large range of basic kioslaves and some KDE add-on applications install their own. You can add new kioslaves at any time and all KDE Kio aware applications will work with them. If you use Konqueror as a web browser, then you’re already using KIO, as the http, https, and ftp protocols are implemented as kioslaves.

Fish

The KDE fish kioslave provides a graphical interface for manipulating files over Secure SHell (ssh). Fish should work with any POSIX compliant Unix providing it has a bourne compatible shell as /bin/sh and basic file manipulation utilities like cat, chgrp, chmod, chown, cp, dd, env, expr, grep, ls, mkdir, mv, rm, rmdir, sed, and wc. If Perl is available it will be used instead. Then only env and /bin/sh are needed out of the list above, and using Perl has the advantage of being much faster. I’ve used fish to log into Linux, FreeBSD, Mac OSX and Solaris with equal success.

Most of what is discussed below holds true of the ftp and sftp kioslaves as well, which present much the same interface to the user.

Here I’d like to use fish to log in to my Apple Macintosh to grab some files and copy them locally. Since it’s running a variant of UNIX with env and Perl and has sshd running, fish will work with it just fine. To log in to a remote host you would type:

fish://username@host

into the Konqueror address bar. If your remote sshd is listening on a custom port, you can specify this at the end of the URL

fish://username@host:9999

If this is the first time you’ve tried to connect to this host over ssh, Konqueror will bring up a dialog noting that it cannot verify the authenticity of the host and asking for your input to proceed. Select ‘Yes’ to indicate that you wish to continue connecting to this host. ssh will then cache the fingerprint of this host in your ~/.ssh/known_hosts file.

Unless you have ssh keys set up for passwordless login, Konqueror will show a dialog asking you to enter your password. Ticking the box ‘Keep password’ will save the password into your KWallet. This can be very convenient if you plan to access this host often.

Now I’m logged in and looking at my home directory on the remote host, I need to find what image I want out of the image files stored here. With the size of my digital photograph library none of the images are named descriptively and unfortunately, without being able to look at the images I really have no idea which is the one I want.

One of the areas in which fish really shines is in the way in which it lets you preview remote files in much the same way you would local ones. KDE’s preview mechanism is very flexible and powerful, enabling you to see previews of images, PDF files, fonts and office documents as well as hear previews of audio files.

To enable previews over fish, select ‘Configure Konqueror…’ from the Konqueror ‘Settings’ menu. Navigate to ‘Previews & Meta-Data’ in the dialog that appears. Under ‘Internet Protocols’ tick the box next to fish. Adjust the slider beneath ‘Maximum file size’ to a sane value for the speed of the connection you’re using. If you’re accessing hosts over the internet, you probably don’t want Konqueror to attempt to generate thumbnail images of 100MB tiff files. Click OK and you’re done.

To fine tune exactly which file types you want to see previews for, have a look under ‘Preview’ in the ‘View’ menu. Here you can enable various different filetypes to show previews of, and also quickly toggle between enabling and disabling previews globally. If you had a Konqueror window open while adjusting these settings, you may need to click reload before you see any changes.

Now I can see previews of my images, I’ve found the one I want. I can drag and drop it to an open Krita window for editing and then afterwards save my changes directly to the remote host - or I could simply copy the file locally for further processing, also by drag and drop.




KDE’s ability to display previews over remote protocols makes finding the file you want a breeze.

Fish really lends itself well to the simple maintenence of remote web sites. Tasks like moving, renaming and changing permissions on remote files are easy when you approach them from Konqueror’s familiar file management interface.

Changing permissions for files on a webserver is a common task. Often the default permissions on files created on your Linux box can be too restrictive and result in a ‘Forbidden’ error message when people try to access the files over the web. To change the permissions of a file over fish, right click on the file and select ‘Properties’. On the ‘Permissions’ tab choose ‘Can read’ for both ‘Group’ and ‘Other’ permissions and click OK. if you were changing permissions for a CGI you would also tick the box labelled ‘is executable’.

In KDE 3.5, Kate gained the ability to save a working set of documents as a session to be easily resumed again later. When coupled with fish, this makes for me at least the ultimate web development environment.

To open up all of the HTML, CSS and other files associated with my website in Kate I could drag and drop them from an open Konqueror window showing me a fish session to the remote host. Dragging and dropping multiple files in this way will cause them to be opened as separate files I can navigate between in the ‘Documents’ pane.

I could also use the File -> Open dialog. All standard KDE file dialogs have support for kioslaves. To load files over fish, select ‘Open’ from the ‘File’ menu. In the location bar at the top of the file dialog type your fish URL

fish://canllaith@canllaith.org

Navigate to where your files associated with your website or other projects are kept and open the files you wish to be a part of the session. To open multiple files at once, hold down the control key and click once on each file you would like to open. When you’re finished selecting files, click ‘Open’.

If you think you will access this remote host often you can add a shortcut to the iconbar on the left of the dialog. Choose a directory you would like the shortcut to point to and drag it to the iconbar. You can edit the name, icon and other attributes of this shortcut by right clicking on it and selecting ‘Edit Entry’.




The Kate Open File dialog, displaying a remote location over fish.

Once Kate has loaded up the files you want to save as a session, select ‘Save As’ from the ‘Sessions’ menu. Enter a name for your new session - as I’m saving various files relating to my website, I’m going to call my session ‘canllaith.org’.

Now in future when you want to quickly load this set of remote files you can choose the saved session from the ‘Sessions’ menu. I find this tool is one I use time and time again. At the end of a day of working on a website and opening various remote files from all over the directory tree I simply save them as a session with today’s date and a short descriptive name. Tomorrow, remembering where I left off and what files I was working on is now that little bit easier.

Samba

The smb kioslave included with KDE lets you browse Microsoft Windows smb file shares. It requires libsmbclient to be installed. If you navigate to smb:/ in Konqueror (or using the nifty alt+f2 shortcut shown below) you will be shown any Windows workgroups found, and you can browse through them for the host you want. You can also specify a host or a specific share of a host directly with

smb://username@hostname/share

Like fish, if you don’t specify a username Konqueror will prompt you for a username and password pair that you can save with KWallet. If you always use a particular username/password pair on your samba network rather than having to save passwords individually for every host you access you can configure this to be automatically supplied by KDE. In the KDE Control Center, navigate to Internet & Network -> Local Network Browsing. Here you can enter the default username and password pair you would like KDE to use for it’s samba client.

As well as adding shortcuts to the File dialog, you can also add desktop shortcuts to hosts you would like to access frequently. To create a desktop shortcut to a smb URL, right click on the KDE desktop and select Create New -> Link to Location (URL)… from the context menu. Fill in the smb:// (or fish) URL to the share you would like to create a shortcut to in the box labelled ‘Enter link to location (URL):’. KDE will fill in the ‘File name’ box with a suitable name, or you may choose your own. Click OK and you’re done.




Creating a desktop shortcut for a location accessible over samba.

As well as acessing kioslaves through the Konqueror address bar and KDE standard file dialogs, you can quickly load kioslaves with the KDE Run Command box. Try hitting alt+f2 to bring up the Run Command box and type ‘help:/kwrite’. A Konqueror window is launched showing you the KWrite Handbook. This works with all Kioslaves and is a really handy way of looking up help pages or loading a remote URL quickly if like me you tend to have a rather cluttered screen.

Many other interesting kioslaves are included with KDE, and other third party efforts can be downloaded from KDE-apps.org as source code that can be compiled against a recent KDE version. To find them, search for ‘kio’ on the KDE-apps.org search page. if you want to compimle kioslaves you’ve downloaded, you will need to have a working C++ compiler and the appropriate development libraries for KDE and Qt installed. Usually these are packaged separately from the KDE runtime libraries.

To find out what Kioslaves you have installed, type ‘help:/kioslave’ into the Run Command box or the Konqueror address bar. This is the KDE help kioslave, which lets you access the help documentation for installed KDE programs through Konqueror. Some of the more interesting kioslaves include:

cgi:

The CGI kioslave will execute CGI programs without needing to have a running webserver. This is really handy for offline local testing of CGI scripts.

locate:

Kubuntu includes kio-locate by default, and for other distributions the sources can be downloaded from KDE-apps.org. Kio-locate is a kioslave for locate or slocate. Typing ‘locate: query term’ into any KIO enabled field will display the results from the locate database. This is immensely convenient when combined with the File dialog. Want to open that budget spreadsheet in KSpread, but it’s not until you’ve launched the application that you realise you can’t quite remember where you saved it? locate:/ to the rescue, without having to leave the File dialog.




The locate kioslave showing the results of the query ‘kio’ in my home directory.

tar:

The tar kioslave allows you to browse the contents of tar, tar.bz2 and tar.gz archives. It’s registered as the default handler for these files within KDE. This lets every KDE application transparently handle loading and saving files to archives without needing to extract them. With previews enabled it’s very easy to find the single file that you want out of the hundreds or even thousands in the archive.

zip:

The zip kioslave allows you to browse the contents of zip archives, much like the tar kioslave does for tar archives.

info/man:

The man and info kioslaves provide a friendly interface to reading man and info pages. The info kioslave in particular makes navigating pages much easier with a mouse-driven browser interface that’s much easier to use than the command line tool.

audiocd:

The audiocd kioslave provides a simple interface for ripping and encoding files from music CDs to ogg, mp3 or flac via drag and drop.

Konqueror is an application with amazing flexibility as both web browser and file manager, due mostly to its extensibility with kioslaves. The kioslaves featured above are barely the tip of the iceberg. Experiment with those listed in help:/kioslave to see what else Konqueror can do.

Resources:

kde-apps.org
konqueror.org