Commit 3b1bc283 authored by David Faure's avatar David Faure
Browse files

Also use the filename when determining the mimetype of a file; useful when...

Also use the filename when determining the mimetype of a file; useful when e.g. attaching a remote excel file in kmail,
since the mimetype used to be determined from the contents only, which would always look like a msword document.

svn path=/trunk/KDE/kdebase/runtime/; revision=624082
parent 10751007
......@@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <kinstance.h>
#include <kdebug.h>
#include <kmimemagic.h>
#include <kmimetype.h>
#include <kfilterbase.h>
#include "filter.h"
......@@ -116,9 +116,9 @@ void FilterProtocol::get( const KUrl & )
}
if (bNeedMimetype)
{
KMimeMagicResult * result = KMimeMagic::self()->findBufferFileType( outputBuffer, subURL.fileName() );
kDebug(7110) << "Emitting mimetype " << result->mimeType() << endl;
mimeType( result->mimeType() );
KMimeType::Ptr mime = KMimeType::findByNameAndContent( subURL.fileName(), outputBuffer );
kDebug(7110) << "Emitting mimetype " << mime->name() << endl;
mimeType( mime->name() );
bNeedMimetype = false;
}
data( outputBuffer ); // Send data
......
......@@ -72,7 +72,6 @@
#include <time.h>
#include <sys/stat.h>
#include <kmimetype.h>
#include <kmimemagic.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <errno.h>
......@@ -1205,7 +1204,7 @@ int fishProtocol::received(const char *buffer, KIO::fileoffset_t buflen)
myDebug( << "wait for more" << endl);
break;
}
sendmimeType(KMimeMagic::self()->findBufferFileType(mimeBuffer,url.path())->mimeType());
sendmimeType(KMimeType::findByNameAndContent(url.path(), mimeBuffer)->name());
mimeTypeSent = true;
if (fishCommand != FISH_READ) {
totalSize(dataRead + rawRead);
......
......@@ -62,7 +62,6 @@ So we can't connect.
#include <kurl.h>
#include <kio/ioslave_defaults.h>
#include <kmimetype.h>
#include <kmimemagic.h>
#include <kde_file.h>
#include <kremoteencoding.h>
......@@ -383,11 +382,10 @@ sftpProtocol::Status sftpProtocol::sftpGet( const KUrl& src, KIO::filesize_t off
if( mimeBuffer.size() > 1024 || offset == fileSize ) {
// determine mimetype
KMimeMagicResult* result =
KMimeMagic::self()->findBufferFileType(mimeBuffer, src.fileName());
KMimeType::Ptr mime = KMimeType::findByNameAndContent(src.fileName(), mimeBuffer);
kDebug(KIO_SFTP_DB) << "sftpGet(): mimetype is " <<
result->mimeType() << endl;
mimeType(result->mimeType());
mime->name() << endl;
mimeType(mime->name());
// Always send the total size after emitting mime-type...
totalSize(fileSize);
......
......@@ -109,7 +109,7 @@ void SMBSlave::get( const KUrl& kurl )
filedata.setRawData(buf,bytesread);
if (isFirstPacket)
{
KMimeType::Ptr p_mimeType = KMimeType::findByContent(filedata);
KMimeType::Ptr p_mimeType = KMimeType::findByNameAndContent(url.fileName(), filedata);
mimeType(p_mimeType->name());
isFirstPacket = false;
}
......@@ -224,7 +224,7 @@ void SMBSlave::open( const KUrl& kurl, int access )
filedata.setRawData(buffer.data(),bytesread);
if (isFirstPacket)
{
KMimeType::Ptr p_mimeType = KMimeType::findByContent(filedata);
KMimeType::Ptr p_mimeType = KMimeType::findByNameAndContent(url.fileName(), filedata);
mimeType(p_mimeType->name());
isFirstPacket = false;
}
......
......@@ -16,7 +16,7 @@
#include <ktar.h>
#include <kzip.h>
#include <kar.h>
#include <kmimemagic.h>
#include <kmimetype.h>
#include <klocale.h>
#include <kde_file.h>
#include <kio/global.h>
......@@ -457,9 +457,9 @@ void ArchiveProtocol::get( const KUrl & url )
{
// We use the magic one the first data read
// (As magic detection is about fixed positions, we can be sure that it is enough data.)
KMimeMagicResult * result = KMimeMagic::self()->findBufferFileType( buffer, path );
kDebug(7109) << "Emitting mimetype " << result->mimeType() << endl;
mimeType( result->mimeType() );
KMimeType::Ptr mime = KMimeType::findByNameAndContent( path, buffer );
kDebug(7109) << "Emitting mimetype " << mime->name() << endl;
mimeType( mime->name() );
firstRead = false;
}
data( buffer );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment