[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: mimetypes for zipped files
From:       aleXXX <alexander.neundorf () gmx ! net>
Date:       2002-04-08 20:58:07
[Download RAW message or body]

On Monday 08 April 2002 14:46, David Faure wrote:
> On Sunday 07 April 2002 23:32, Alex Zepeda wrote:
> > On Sun, Apr 07, 2002 at 11:50:14AM +0200, aleXXX wrote:
> > > Do you have another suggestion which can be implemented without major
> > > problems for KDE 3.x ?
> >
> > Is there any way that having the appropiate ([gb]zip) filter slave modify
> > the resulting mimetype would work?
>
> Yes, one could decompress the file with one of the above, perform a
> mime-magic-from-contents on the beginning of the result, to get the inner
> mimetype... but then what? The next step is to launch the appropriate
> application / part,
> and either
> - feed it the compressed file, assuming the app can decompress it by itself
> (this might need some flag in the .desktop file saying "yes, I'm using
> KFilterDev so I can handle compressed files"
> - or feed it the uncompressed data. For parts, the new "streaming" API
> would allow just that. But for apps, I don't see a way.
>
> Anyway, alex's current approach is most probably to add support for
> KFilterDev in the apps, which fits the above first point. If apps can

Yes.

> handle compressed files just fine, the only missing bit is the mimetype
> determination (e.g. when clicking on a file in Konq, i.e. more generally in
> KRun), to launch the right app. If that's done using the above, then
> there's no need for combined mimetypes like application/postscript-gzip
> etc.

I.e. app/postscript-gzip would be simply also app/postscript ?
Yes, this was basically my question whether we'd need new mimetypes or not.

Well, here's my source.
Of course it could be simply modified to return only the "inner" mimetype.

Bye
Alex

["kmimemagic.cpp.diff" (text/x-diff)]

Index: kmimemagic.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/kmimemagic.cpp,v
retrieving revision 1.51
diff -c -b -u -r1.51 kmimemagic.cpp
--- kmimemagic.cpp	2002/03/31 19:47:01	1.51
+++ kmimemagic.cpp	2002/04/08 20:25:56
@@ -24,6 +24,11 @@
 #include <kstaticdeleter.h>
 #include <assert.h>
 
+#include <qcstring.h>
+#include <qbuffer.h>
+#include <kfilterdev.h>
+
+
 KMimeMagic* KMimeMagic::s_pSelf = 0L;
 KStaticDeleter<KMimeMagic> kmimemagicsd;
 
@@ -1705,6 +1710,39 @@
 #ifdef DEBUG_MIMEMAGIC
                     kdDebug(7018) << "match: matched" << endl;
 #endif
+
+                    if ((resultBuf=="application/x-gzip") || (resultBuf=="application/x-bzip2"))
+                    {
+                       QByteArray a;
+                       a.setRawData((const char*)s,nbytes);
+                       QBuffer b(a);
+                       QString backup=resultBuf;
+                       QIODevice *dev= KFilterDev::device(&b,resultBuf);
+                       if (dev!=0)
+                       {
+                          dev->open(IO_ReadOnly);
+                          unsigned char buffer[HOWMANY+1];
+                          int read=dev->readBlock((char*)buffer, HOWMANY);
+                          const unsigned char* cont=buffer;
+                          tryit(buffer,read);
+                          if (accuracy>0)
+                          {
+                             if (backup=="application/x-gzip")
+                                resultBuf+="-gzip";
+                             else
+                                resultBuf+="-bzip2";
+                          }
+                          else
+                          {
+                             resultBuf=backup;
+                          };
+                          dev->close();
+                          delete dev;
+                       };
+                       a.resetRawData((const char*)s,nbytes);
+                    };
+
+
                     return 1;       /* all through */
                 }
 	}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic