This forum has been archived. All content is frozen. Please use KDE Discuss instead.

kioslave forwarding for local files

Tags: None
(comma "," separated)
fluca1978
Registered Member
Posts
81
Karma
0
OS

kioslave forwarding for local files

Thu May 03, 2012 6:50 am
Hi all,
I'm trying to implement a kioslave and I've got a doubt about its design: for almost every operation I have to check the incoming URL to see if it is a special one, otherwise I have to rewrite it and manage as a local filesystem URL. Therefore in my copy method, for instance, I've got something like:

Code: Select all
copy( KUrl& src, KUrl& dst, ...){
   if( ! isSpecial( src ) && ! isSpecial (dst ) ){
      // rewrite urls to file:///
      // and pass it to the file slave
   }
   else{
     // manage here
   }
}


Now, what is the recommended way to achieve this? Should I inherit also from the file slave and call super when required an action of the file slave or should I forward the call to the file slave (and I don't know exactly how to do that)? Can anybody give me an hint?
dfaure
KDE Developer
Posts
14
Karma
0
OS
fluca1978 wrote:Hi all,
I'm trying to implement a kioslave and I've got a doubt about its design: for almost every operation I have to check the incoming URL to see if it is a special one, otherwise I have to rewrite it and manage as a local filesystem URL.
Now, what is the recommended way to achieve this? Should I inherit also from the file slave and call super when required an action of the file slave or should I forward the call to the file slave (and I don't know exactly how to do that)? Can anybody give me an hint?


You can't inherit from kio_file, it's a plugin, not a public shared library.
However you should use ForwardingSlaveBase, for easy "forwarding to the file slave".

I'm surprised by the statement that you need to check incoming URLs in all methods. get(), put(), listDir(), and many other basic methods will only ever be called with URLs of your own protocol.

copy() however is a special case, it's an optional optimization for copying from local files to your-own-protocol, or for copying from your-own-protocol to local files, or both, depending on the flags you set in the .protocol file. So yes, in that method you need to check which protocols the URLs use. But only in that method.
fluca1978
Registered Member
Posts
81
Karma
0
OS
dfaure wrote:
You can't inherit from kio_file, it's a plugin, not a public shared library.
However you should use ForwardingSlaveBase, for easy "forwarding to the file slave".


Thanks, can you please point to some piece of code and/or other slaves that use ForwardingSlaveBase, so that I can use it as an example?

dfaure wrote:I'm surprised by the statement that you need to check incoming URLs in all methods. get(), put(), listDir(), and many other basic methods will only ever be called with URLs of your own protocol.

copy() however is a special case, it's an optional optimization for copying from local files to your-own-protocol, or for copying from your-own-protocol to local files, or both, depending on the flags you set in the .protocol file. So yes, in that method you need to check which protocols the URLs use. But only in that method.



You are right, the URLs are always related to my protocol, of course. However I'm implementing a slave that is going to present to the user some virtual information along with some real (i.e., coming from the local filesystem) information. Therefore I could have an URL that points to a virtual folder, and so I need to display only virtual content, or to a real folder, and therefore I have to display real content from the local filesystem. That is why I cannot simply forward a whole URL but I have to check it to understand which content has to be presented to the user. If you have any suggestion about how to solve or can spend some time discussing with me the architecture of this slave I will be very happy!

Thanks
dfaure
KDE Developer
Posts
14
Karma
0
OS
Look for ForwardingSlaveBase on http://lxr.kde.org.

> I have to check it to understand which content has to be presented to the user.

Well, yes, obviously, by design ;)
You'll see that most ForwardingSlaveBase-based ioslaves do pretty much the same.
fluca1978
Registered Member
Posts
81
Karma
0
OS
dfaure wrote:Look for ForwardingSlaveBase on http://lxr.kde.org.


Thanks, I'm having a look at the recent documents implementation http://lxr.kde.org/source/kde/kde-runtime/kioslave/recentdocuments/recentdocuments.cpp#42, if you think there is a better one to study on please advice.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft