Commit aa7fdeb3 authored by Michal Humpula's avatar Michal Humpula

migrate from KMimeType

REVIEW: 114494
parent 5b45801f
......@@ -45,7 +45,6 @@
#include <KShortcutsDialog>
#include <KLocale>
#include <KMessageBox>
#include <KMimeType>
#include <KOpenWithDialog>
#include <KMenu>
#include <KConfig>
......@@ -70,6 +69,7 @@
#include <QDropEvent>
#include <QList>
#include <QDesktopWidget>
#include <QMimeDatabase>
#include <kio/job.h>
#include <KIO/ListJob>
......@@ -746,11 +746,12 @@ void KateMainWindow::mSlotFixOpenWithMenu()
menu->clear();
// get a list of appropriate services.
KMimeType::Ptr mime = KMimeType::mimeType(activeView->document()->mimeType());
//kDebug(13001) << "mime type: " << mime->name();
QMimeDatabase db;
QMimeType mime = db.mimeTypeForName( activeView->document()->mimeType() );
//kDebug(13001) << "mime type: " << mime.name();
QAction *a = 0;
KService::List offers = KMimeTypeTrader::self()->query(mime->name(), "Application");
KService::List offers = KMimeTypeTrader::self()->query(mime.name(), "Application");
// add all default open-with-actions except "Kate"
for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
......
......@@ -29,7 +29,6 @@
#include <KLocale>
#include <KMimeTypeTrader>
#include <KMimeType>
#include <KOpenWithDialog>
#include <KRun>
#include <KMessageBox>
......@@ -41,6 +40,7 @@
#include <kdebug.h>
#include <qapplication.h>
#include <QClipboard>
#include <QMimeDatabase>
//END Includes
......@@ -228,11 +228,12 @@ void KateFileTree::slotFixOpenWithMenu()
if (!doc) return;
// get a list of appropriate services.
KMimeType::Ptr mime = KMimeType::mimeType(doc->mimeType());
//kDebug(13001) << "mime type: " << mime->name();
QMimeDatabase db;
QMimeType mime = db.mimeTypeForName( doc->mimeType() );
//kDebug(13001) << "mime type: " << mime.name();
QAction *a = 0;
KService::List offers = KMimeTypeTrader::self()->query(mime->name(), "Application");
KService::List offers = KMimeTypeTrader::self()->query(mime.name(), "Application");
// for each one, insert a menu item...
for(KService::List::Iterator it = offers.begin(); it != offers.end(); ++it)
{
......
......@@ -21,7 +21,8 @@
#include <QDir>
#include <QFileInfo>
#include <QList>
#include <KMimeType>
#include <QMimeDatabase>
#include <KColorScheme>
#include <KColorUtils>
#include <klocale.h>
......@@ -1269,7 +1270,7 @@ void KateFileTreeModel::setupIcon(ProxyItem *item)
}
else {
KUrl url = item->path();
icon_name = KMimeType::findByUrl(url, 0, true, true)->iconName();
icon_name = QMimeDatabase().mimeTypeForFile(url.path(), QMimeDatabase::MatchExtension).iconName();
}
if(item->flag(ProxyItem::ModifiedExternally) || item->flag(ProxyItem::DeletedExternally)) {
......
......@@ -24,10 +24,10 @@
#include <QtCore/QString>
#include <QtCore/QFile>
#include <QtCore/QCryptographicHash>
#include <QMimeDatabase>
// on the fly compression
#include <kfilterdev.h>
#include <kmimetype.h>
namespace Kate {
......@@ -66,10 +66,8 @@ class TextLoader
{
// try to get mimetype for on the fly decompression, don't rely on filename!
QFile testMime (filename);
if (testMime.open (QIODevice::ReadOnly))
m_mimeType = KMimeType::findByContent (&testMime)->name ();
else
m_mimeType = KMimeType::findByPath (filename, 0, false)->name ();
m_mimeType = QMimeDatabase().mimeTypeForFileNameAndData( filename, &testMime ).name();
// construct filter device
//KCompressionDevice::CompressionType compressionType = KFilterDev::compressionTypeForMimeType(m_mimeType);
......
......@@ -1885,19 +1885,17 @@ bool KateDocument::print ()
//BEGIN KTextEditor::DocumentInfoInterface (### unfinished)
QString KateDocument::mimeType()
{
KMimeType::Ptr result = KMimeType::defaultMimeTypePtr();
QMimeType mt;
// if the document has a URL, try KMimeType::findByURL
if ( ! this->url().isEmpty() )
result = KMimeType::findByUrl( this->url() );
else if ( this->url().isEmpty() || ! this->url().isLocalFile() )
result = mimeTypeForContent();
if ( !this->url().isEmpty() )
mt = QMimeDatabase().mimeTypeForUrl( this->url() );
else
mt = mimeTypeForContent();
return result->name();
return mt.name();
}
KMimeType::Ptr KateDocument::mimeTypeForContent()
QMimeType KateDocument::mimeTypeForContent()
{
QByteArray buf (1024,'\0');
uint bufpos = 0;
......@@ -1920,9 +1918,8 @@ KMimeType::Ptr KateDocument::mimeTypeForContent()
}
buf.resize( bufpos );
int accuracy = 0;
KMimeType::Ptr mt = KMimeType::findByContent(buf, &accuracy);
return mt ? mt : KMimeType::defaultMimeTypePtr();
QMimeDatabase db;
return db.mimeTypeForData(buf);
}
//END KTextEditor::DocumentInfoInterface
......
......@@ -28,9 +28,9 @@
#include <QtCore/QDate>
#include <QtGui/QClipboard>
#include <QtCore/QStack>
#include <QtCore/QMimeType>
#include <kjob.h>
#include <kmimetype.h>
#include <ktexteditor/document.h>
#include <ktexteditor/sessionconfiginterface.h>
......@@ -512,19 +512,18 @@ class KATEPART_TESTS_EXPORT KateDocument : public KTextEditor::Document,
/**
* @return the name of the mimetype for the document.
*
* This method is using KMimeType::findByUrl, and if the pointer
* is then still the default MimeType for a nonlocal or unsaved file,
* uses mimeTypeForContent().
* This method is using QMimeTypeDatabase::mimeTypeForUrl and if that
* fails then calls mimeTypeForContent
*/
virtual QString mimeType();
/**
* @return a pointer to the KMimeType for this document, found by analyzing the
* @return QMimeType for this document, found by analyzing the
* actual content.
*
* Note that this method is *not* part of the DocumentInfoInterface.
*/
KMimeType::Ptr mimeTypeForContent();
QMimeType mimeTypeForContent();
//
// KTextEditor::VariableInterface
......
......@@ -32,7 +32,6 @@
#include "ui_filetypeconfigwidget.h"
#include <kconfig.h>
#include <kmimetype.h>
#include <kmimetypechooser.h>
#include <kdebug.h>
#include <kiconloader.h>
......@@ -49,6 +48,8 @@
#include <QtWidgets/QLayout>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QToolButton>
#include <QtCore/QMimeDatabase>
#include <kvbox.h>
#define KATE_FT_HOWMANY 1024
......@@ -239,21 +240,19 @@ QString KateModeManager::fileType (KateDocument *doc, const QString &fileToReadF
}
// Try content-based mimetype
KMimeType::Ptr mt;
if (!fileToReadFrom.isEmpty()) {
int accuracy = 0;
mt = KMimeType::findByFileContent(fileToReadFrom, &accuracy);
if (!mt)
mt = KMimeType::defaultMimeTypePtr();
} else {
QMimeType mt;
QMimeDatabase db;
if ( !fileToReadFrom.isEmpty() )
mt = db.mimeTypeForFile( fileToReadFrom );
else
mt = doc->mimeTypeForContent();
}
QList<KateFileType*> types;
foreach (KateFileType *type, m_types)
{
if (type->mimetypes.indexOf (mt->name()) > -1)
if (type->mimetypes.indexOf (mt.name()) > -1)
types.append (type);
}
......
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