Commit 87420b14 authored by Volker Krause's avatar Volker Krause

Port from KMimeType to QMimeType.

parent cbdc21e5
......@@ -48,6 +48,7 @@
#include <KEncodingFileDialog>
#include <KLocalizedString>
#include <KMessageBox>
#include <KMimeType>
#include <KMimeTypeTrader>
#include <QPushButton>
#include <KRun>
......
......@@ -57,13 +57,12 @@
#include <KLocalizedString>
#include <kmessagebox.h>
#include <kio/netaccess.h>
#include <QTemporaryFile>
#include <KFileDialog>
#include <ktoolinvocation.h>
#include <QAction>
#include <QIcon>
#include <KFileDialog>
#include <QTemporaryFile>
#include <QFileDialog>
#include <QTextCodec>
#include <QWidget>
......@@ -71,6 +70,7 @@
#include <QDBusConnectionInterface>
#include <QActionGroup>
#include <QPointer>
#include <QMimeDatabase>
using namespace MessageViewer;
......@@ -108,9 +108,10 @@ QString Util::fileNameForMimetype(const QString &mimeType, int iconSize,
} else if (mimeType == QLatin1String("application/x-vnd.kolab.note")) {
tMimeType = QStringLiteral("application/x-vnd.akonadi.note");
}
KMimeType::Ptr mime = KMimeType::mimeType(tMimeType, KMimeType::ResolveAliases);
if (mime) {
fileName = mime->iconName();
QMimeDatabase mimeDb;
auto mime = mimeDb.mimeTypeForName(tMimeType);
if (mime.isValid()) {
fileName = mime.iconName();
} else {
fileName = QStringLiteral("unknown");
if (!tMimeType.isEmpty()) {
......@@ -127,7 +128,7 @@ QString Util::fileNameForMimetype(const QString &mimeType, int iconSize,
fileName = fallbackFileName2;
}
if (!fileName.isEmpty()) {
fileName = KMimeType::findByPath(QLatin1String("/tmp/") + fileName, 0, true)->iconName();
fileName = mimeDb.mimeTypeForFile(QLatin1String("/tmp/") + fileName).iconName();
}
}
......@@ -550,14 +551,17 @@ QAction *Util::createAppAction(const KService::Ptr &service, bool singleOffer, Q
return act;
}
KMimeType::Ptr Util::mimetype(const QString &name)
QMimeType Util::mimetype(const QString &name)
{
QMimeDatabase db;
// consider the filename if mimetype cannot be found by content-type
KMimeType::Ptr mimeType = KMimeType::findByPath(name, 0, true /* no disk access */);
if (mimeType->name() == QLatin1String("application/octet-stream")) {
// consider the attachment's contents if neither the Content-Type header
// nor the filename give us a clue
mimeType = KMimeType::findByFileContent(name);
auto mimeTypes = db.mimeTypesForFileName(name);
foreach (const auto &mt, mimeTypes) {
if (mt.name() != QLatin1String("application/octet-stream"))
return mt;
}
return mimeType;
// consider the attachment's contents if neither the Content-Type header
// nor the filename give us a clue
return db.mimeTypeForFile(name);
}
......@@ -40,7 +40,6 @@
#include "messageviewer_export.h"
#include "kmime/kmime_content.h"
#include <KMimeType>
#include <QString>
#include <KService>
#include <AkonadiCore/Item>
......@@ -49,6 +48,7 @@ class QUrl;
class QWidget;
class QActionGroup;
class QAction;
class QMimeType;
namespace KMime
{
......@@ -128,9 +128,9 @@ void speakSelectedText(const QString &text);
MESSAGEVIEWER_EXPORT QAction *createAppAction(const KService::Ptr &service, bool singleOffer, QActionGroup *actionGroup, QObject *parent);
/**
* Search mimetype from filename when mimetype is empty or application/octet-stream
**/
MESSAGEVIEWER_EXPORT KMimeType::Ptr mimetype(const QString &name);
* Search mimetype from filename when mimetype is empty or application/octet-stream
**/
MESSAGEVIEWER_EXPORT QMimeType mimetype(const QString &name);
}
}
......
......@@ -25,11 +25,12 @@
#include <kmime/kmime_content.h>
#include <KMime/Message>
#include <QIcon>
#include <KLocalizedString>
#include <KMimeType>
#include <KFormat>
#include <QIcon>
#include <QMimeDatabase>
using namespace MessageViewer;
class Q_DECL_HIDDEN MimeTreeModel::Private
......@@ -70,11 +71,11 @@ public:
{
if (content->contentType(false)) {
const QString contentMimeType = QString::fromLatin1(content->contentType()->mimeType());
KMimeType::Ptr mimeType = KMimeType::mimeType(contentMimeType);
if (!mimeType) {
auto mimeType = m_mimeDb.mimeTypeForName(contentMimeType);
if (!mimeType.isValid()) {
return contentMimeType;
}
return mimeType->comment();
return mimeType.comment();
} else {
return QString();
}
......@@ -91,24 +92,25 @@ public:
QIcon iconForContent(KMime::Content *content)
{
if (content->contentType(false)) {
KMimeType::Ptr mimeType = KMimeType::mimeType(QString::fromLatin1(content->contentType()->mimeType()));
if (!mimeType || mimeType->name() == QLatin1String("application/octet-stream")) {
auto mimeType = m_mimeDb.mimeTypeForName(QString::fromLatin1(content->contentType()->mimeType()));
if (!mimeType.isValid() || mimeType.name() == QLatin1String("application/octet-stream")) {
const QString name = descriptionForContent(content);
mimeType = MessageViewer::Util::mimetype(name);
}
if (!mimeType || mimeType->iconName().isEmpty()) {
if (!mimeType.isValid() || mimeType.iconName().isEmpty()) {
return QIcon();
}
if (mimeType->name().startsWith(QStringLiteral("multipart/"))) {
if (mimeType.name().startsWith(QStringLiteral("multipart/"))) {
return QIcon::fromTheme(QStringLiteral("folder"));
}
return QIcon::fromTheme(mimeType->iconName());
return QIcon::fromTheme(mimeType.iconName());
} else {
return QIcon();
}
}
KMime::Content *root;
QMimeDatabase m_mimeDb;
};
MimeTreeModel::MimeTreeModel(QObject *parent) :
......
......@@ -498,7 +498,7 @@ QString NodeHelper::iconName(KMime::Content *node, int size)
QByteArray mimeType = node->contentType()->mimeType();
if (mimeType.isNull() || mimeType == "application/octet-stream") {
const QString mime = Util::mimetype(node->contentDisposition()->filename())->name();
const QString mime = Util::mimetype(node->contentDisposition()->filename()).name();
mimeType = mime.toLatin1();
}
mimeType = mimeType.toLower();
......
......@@ -52,27 +52,26 @@
#include <kmime/kmime_content.h>
#include <KEmailAddress>
#include <QMenu>
#include <KMimeType>
#include <KRun>
#include <KUrl>
#include <QIcon>
#include <KLocalizedString>
#include <kmessagebox.h>
#include <QMenu>
#include <QIcon>
#include <QApplication>
#include <QClipboard>
#include <QProcess>
#include <QFile>
#include <QMimeData>
#include <QDrag>
#include <QMimeDatabase>
#include <QStandardPaths>
#include <algorithm>
#include <ui/messagebox.h>
#include <KLocalizedString>
#include <kmessagebox.h>
#include <QStandardPaths>
using std::for_each;
using std::remove;
......@@ -1027,11 +1026,12 @@ bool KRunURLHandler::handleClick(const KUrl &url, ViewerPrivate *w) const
KPIM::BroadcastStatus::instance()->setTransientStatusMsg(i18n("Opening URL..."));
QTimer::singleShot(2000, KPIM::BroadcastStatus::instance(), SLOT(reset()));
KMimeType::Ptr mime = KMimeType::findByUrl(url);
if (mime->name() == QLatin1String("application/x-desktop") ||
mime->name() == QLatin1String("application/x-executable") ||
mime->name() == QLatin1String("application/x-ms-dos-executable") ||
mime->name() == QLatin1String("application/x-shellscript")) {
QMimeDatabase mimeDb;
auto mime = mimeDb.mimeTypeForUrl(url);
if (mime.name() == QLatin1String("application/x-desktop") ||
mime.name() == QLatin1String("application/x-executable") ||
mime.name() == QLatin1String("application/x-ms-dos-executable") ||
mime.name() == QLatin1String("application/x-shellscript")) {
if (KMessageBox::warningYesNo(0, xi18nc("@info", "Do you really want to execute <filename>%1</filename>?",
url.pathOrUrl()), QString(), KGuiItem(i18n("Execute")), KStandardGuiItem::cancel()) != KMessageBox::Yes) {
return true;
......
......@@ -61,7 +61,6 @@
#include <QWebFrame>
#include <QMenu>
#include <KMessageBox>
#include <KMimeType>
#include <KMimeTypeChooser>
#include <KMimeTypeTrader>
#include <KRun>
......@@ -102,6 +101,7 @@
#include <QPrinter>
#include <QPrintDialog>
#include <QHeaderView>
#include <QMimeDatabase>
//libkdepim
#include "libkdepim/misc/broadcaststatus.h"
......@@ -365,9 +365,9 @@ void ViewerPrivate::openAttachment(KMime::Content *node, const QString &name)
}
// determine the MIME type of the attachment
// prefer the value of the Content-Type header
KMimeType::Ptr mimetype = KMimeType::mimeType(QString::fromLatin1(node->contentType()->mimeType().toLower()),
KMimeType::ResolveAliases);
if (!mimetype.isNull() && mimetype->is(KContacts::Addressee::mimeType())) {
QMimeDatabase mimeDb;
auto mimetype = mimeDb.mimeTypeForName(QString::fromLatin1(node->contentType()->mimeType().toLower()));
if (mimetype.isValid() && mimetype.inherits(KContacts::Addressee::mimeType())) {
showVCard(node);
return;
}
......@@ -381,16 +381,16 @@ void ViewerPrivate::openAttachment(KMime::Content *node, const QString &name)
return;
}
if (mimetype.isNull() || mimetype->name() == QLatin1String("application/octet-stream")) {
if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
mimetype = Util::mimetype(name);
}
KService::Ptr offer =
KMimeTypeTrader::self()->preferredService(mimetype->name(), QStringLiteral("Application"));
KMimeTypeTrader::self()->preferredService(mimetype.name(), QStringLiteral("Application"));
const QString filenameText = NodeHelper::fileName(node);
AttachmentDialog dialog(mMainWindow, filenameText, offer ? offer->name() : QString(),
QString::fromLatin1("askSave_") + mimetype->name());
QString::fromLatin1("askSave_") + mimetype.name());
const int choice = dialog.exec();
if (choice == AttachmentDialog::Save) {
......@@ -616,9 +616,10 @@ void ViewerPrivate::showAttachmentPopup(KMime::Content *node, const QString &nam
createOpenWithMenu(menu, contentTypeStr, true);
}
KMimeType::Ptr mimetype = KMimeType::mimeType(contentTypeStr, KMimeType::ResolveAliases);
if (!mimetype.isNull()) {
const QStringList parentMimeType = mimetype->allParentMimeTypes();
QMimeDatabase mimeDb;
auto mimetype = mimeDb.mimeTypeForName(contentTypeStr);
if (mimetype.isValid()) {
const QStringList parentMimeType = mimetype.parentMimeTypes();
if ((contentTypeStr == QLatin1String("text/plain")) ||
(contentTypeStr == QLatin1String("image/png")) ||
(contentTypeStr == QLatin1String("image/jpeg")) ||
......@@ -715,20 +716,20 @@ KService::Ptr ViewerPrivate::getServiceOffer(KMime::Content *content)
const QString contentTypeStr = QLatin1String(content->contentType()->mimeType());
// determine the MIME type of the attachment
KMimeType::Ptr mimetype;
// prefer the value of the Content-Type header
mimetype = KMimeType::mimeType(contentTypeStr, KMimeType::ResolveAliases);
QMimeDatabase mimeDb;
auto mimetype = mimeDb.mimeTypeForName(contentTypeStr);
if (!mimetype.isNull() && mimetype->is(KContacts::Addressee::mimeType())) {
if (mimetype.isValid() && mimetype.inherits(KContacts::Addressee::mimeType())) {
attachmentView(content);
return KService::Ptr(0);
}
if (mimetype.isNull() || mimetype->name() == QLatin1String("application/octet-stream")) {
if (!mimetype.isValid() || mimetype.name() == QLatin1String("application/octet-stream")) {
/*TODO(Andris) port when on-demand loading is done && msgPart.isComplete() */
mimetype = MessageViewer::Util::mimetype(fileName);
}
return KMimeTypeTrader::self()->preferredService(mimetype->name(), QStringLiteral("Application"));
return KMimeTypeTrader::self()->preferredService(mimetype.name(), QStringLiteral("Application"));
}
KMime::Content::List ViewerPrivate::selectedContents()
......
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