Proposal: Extended Attribute support in Kioslave: File

Daniel Nakata dnakata at nerdshack.com
Fri May 5 07:31:11 BST 2006


As an initial step toward my goal of saturating KDE with support for extended 
attributes, I'd like to suggest the following modifications to the kdelibs 
codebase:

1) Add --enable-xattr to configure(.in(.in)), and have it define HAVE_XATTR, 
if -lattr works (libattr is available).  If so, add "-lattr" to LIBS.

2) Conditionally #include<attr/xattr.h>, if xattr is enabled, in 
kioslaves/file/file.cc

3) Before KMimeType::findByURL(), call fgetxattr(fd, "user.mime_type", ...); 
to see if a mime_type field is explicitly declared for this specific file, 
and if so, use it. Otherwise, use the normal KMimeType::findByURL() method.

--

Well, it would look something like this:

...
    // Determine the mimetype of the file to be retrieved, and emit it.
    // This is mandatory in all slaves (for KRun/BrowserRun to work).
#ifdef HAVE_XATTR
    char *outBuf = NULL;
    ssize_t getxattrResult = fgetxattr( fd, "user.mime_type", NULL, 0 );
    if( getxattrResult > 0 ) {
        outBuf = malloc( getxattrResult + 1 );
        memset( outBuf, 0, getxattrResult + 1 );
        fgetxattr( fd, "user.mime_type", outBuf, getxattrResult+1 );
        emit mimeType( QString::fromLatin1(outBuf) );
        free( outBuf );
    } else {
#endif
    KMimeType::Ptr mt = KMimeType::findByURL( url, buff.st_mode, true /* local 
URL */ );
    emit mimeType( mt->name() );
#ifdef HAVE_XATTR
    }
#endif

    KIO::filesize_t processed_size = 0;
...

(maybe not exactly, but that was what i had in mind.)

How does this sound?  I'm willing to write it up if there's a chance it would 
make it into KDE officially.





More information about the kde-core-devel mailing list