Changeset View
Changeset View
Standalone View
Standalone View
messageviewer/src/utils/messageviewerutil.cpp
Show All 32 Lines | |||||
33 | ** your version of the file, but you are not obligated to do so. If | 33 | ** your version of the file, but you are not obligated to do so. If | ||
34 | ** you do not wish to do so, delete this exception statement from | 34 | ** you do not wish to do so, delete this exception statement from | ||
35 | ** your version. | 35 | ** your version. | ||
36 | ** | 36 | ** | ||
37 | *******************************************************************************/ | 37 | *******************************************************************************/ | ||
38 | 38 | | |||
39 | #include "messageviewer/messageviewerutil.h" | 39 | #include "messageviewer/messageviewerutil.h" | ||
40 | #include "kpimtextedit/texttospeech.h" | 40 | #include "kpimtextedit/texttospeech.h" | ||
41 | #include "utils/iconnamecache.h" | | |||
42 | #include "messageviewer/nodehelper.h" | 41 | #include "messageviewer/nodehelper.h" | ||
43 | #include "messageviewer_debug.h" | 42 | #include "messageviewer_debug.h" | ||
44 | #include "MessageCore/MessageCoreSettings" | 43 | #include "MessageCore/MessageCoreSettings" | ||
45 | #include "MessageCore/NodeHelper" | 44 | #include "MessageCore/NodeHelper" | ||
46 | #include "MessageCore/StringUtil" | 45 | #include "MessageCore/StringUtil" | ||
47 | 46 | | |||
48 | #include "PimCommon/RenameFileDialog" | 47 | #include "PimCommon/RenameFileDialog" | ||
49 | 48 | | |||
Show All 17 Lines | |||||
67 | #include <QTemporaryFile> | 66 | #include <QTemporaryFile> | ||
68 | #include <QFileDialog> | 67 | #include <QFileDialog> | ||
69 | #include <QTextCodec> | 68 | #include <QTextCodec> | ||
70 | #include <QWidget> | 69 | #include <QWidget> | ||
71 | #include <QDBusInterface> | 70 | #include <QDBusInterface> | ||
72 | #include <QDBusConnectionInterface> | 71 | #include <QDBusConnectionInterface> | ||
73 | #include <QActionGroup> | 72 | #include <QActionGroup> | ||
74 | #include <QPointer> | 73 | #include <QPointer> | ||
75 | #include <QMimeDatabase> | | |||
76 | 74 | | |||
77 | using namespace MessageViewer; | 75 | using namespace MessageViewer; | ||
78 | 76 | | |||
79 | bool Util::checkOverwrite(const QUrl &url, QWidget *w) | 77 | bool Util::checkOverwrite(const QUrl &url, QWidget *w) | ||
80 | { | 78 | { | ||
81 | bool fileExists = false; | 79 | bool fileExists = false; | ||
82 | if (url.isLocalFile()) { | 80 | if (url.isLocalFile()) { | ||
83 | fileExists = QFile::exists(url.toLocalFile()); | 81 | fileExists = QFile::exists(url.toLocalFile()); | ||
Show All 10 Lines | 88 | if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( | |||
94 | i18n("Overwrite File?"), | 92 | i18n("Overwrite File?"), | ||
95 | KStandardGuiItem::overwrite())) { | 93 | KStandardGuiItem::overwrite())) { | ||
96 | return false; | 94 | return false; | ||
97 | } | 95 | } | ||
98 | } | 96 | } | ||
99 | return true; | 97 | return true; | ||
100 | } | 98 | } | ||
101 | 99 | | |||
102 | QString Util::fileNameForMimetype(const QString &mimeType, int iconSize, | | |||
103 | const QString &fallbackFileName1, | | |||
104 | const QString &fallbackFileName2) | | |||
105 | { | | |||
106 | QString fileName; | | |||
107 | QString tMimeType = mimeType; | | |||
108 | | ||||
109 | // convert non-registered types to registered types | | |||
110 | if (mimeType == QLatin1String("application/x-vnd.kolab.contact")) { | | |||
111 | tMimeType = QStringLiteral("text/x-vcard"); | | |||
112 | } else if (mimeType == QLatin1String("application/x-vnd.kolab.event")) { | | |||
113 | tMimeType = QStringLiteral("application/x-vnd.akonadi.calendar.event"); | | |||
114 | } else if (mimeType == QLatin1String("application/x-vnd.kolab.task")) { | | |||
115 | tMimeType = QStringLiteral("application/x-vnd.akonadi.calendar.todo"); | | |||
116 | } else if (mimeType == QLatin1String("application/x-vnd.kolab.journal")) { | | |||
117 | tMimeType = QStringLiteral("application/x-vnd.akonadi.calendar.journal"); | | |||
118 | } else if (mimeType == QLatin1String("application/x-vnd.kolab.note")) { | | |||
119 | tMimeType = QStringLiteral("application/x-vnd.akonadi.note"); | | |||
120 | } | | |||
121 | QMimeDatabase mimeDb; | | |||
122 | auto mime = mimeDb.mimeTypeForName(tMimeType); | | |||
123 | if (mime.isValid()) { | | |||
124 | fileName = mime.iconName(); | | |||
125 | } else { | | |||
126 | fileName = QStringLiteral("unknown"); | | |||
127 | if (!tMimeType.isEmpty()) { | | |||
128 | qCWarning(MESSAGEVIEWER_LOG) << "unknown mimetype" << tMimeType; | | |||
129 | } | | |||
130 | } | | |||
131 | //WorkAround for #199083 | | |||
132 | if (fileName == QLatin1String("text-vcard")) { | | |||
133 | fileName = QStringLiteral("text-x-vcard"); | | |||
134 | } | | |||
135 | if (fileName.isEmpty()) { | | |||
136 | fileName = fallbackFileName1; | | |||
137 | if (fileName.isEmpty()) { | | |||
138 | fileName = fallbackFileName2; | | |||
139 | } | | |||
140 | if (!fileName.isEmpty()) { | | |||
141 | fileName = mimeDb.mimeTypeForFile(QLatin1String("/tmp/") + fileName).iconName(); | | |||
142 | } | | |||
143 | } | | |||
144 | | ||||
145 | return IconNameCache::instance()->iconPath(fileName, iconSize); | | |||
146 | } | | |||
147 | | ||||
148 | #if defined Q_OS_WIN || defined Q_OS_MACX | 100 | #if defined Q_OS_WIN || defined Q_OS_MACX | ||
149 | #include <QDesktopServices> | 101 | #include <QDesktopServices> | ||
150 | #endif | 102 | #endif | ||
151 | 103 | | |||
152 | bool Util::handleUrlWithQDesktopServices(const QUrl &url) | 104 | bool Util::handleUrlWithQDesktopServices(const QUrl &url) | ||
153 | { | 105 | { | ||
154 | #if defined Q_OS_WIN || defined Q_OS_MACX | 106 | #if defined Q_OS_WIN || defined Q_OS_MACX | ||
155 | QDesktopServices::openUrl(url); | 107 | QDesktopServices::openUrl(url); | ||
▲ Show 20 Lines • Show All 367 Lines • ▼ Show 20 Line(s) | 468 | { | |||
523 | 475 | | |||
524 | QAction *act = new QAction(parent); | 476 | QAction *act = new QAction(parent); | ||
525 | act->setIcon(QIcon::fromTheme(service->icon())); | 477 | act->setIcon(QIcon::fromTheme(service->icon())); | ||
526 | act->setText(actionName); | 478 | act->setText(actionName); | ||
527 | actionGroup->addAction(act); | 479 | actionGroup->addAction(act); | ||
528 | act->setData(QVariant::fromValue(service)); | 480 | act->setData(QVariant::fromValue(service)); | ||
529 | return act; | 481 | return act; | ||
530 | } | 482 | } | ||
531 | | ||||
532 | QMimeType Util::mimetype(const QString &name) | | |||
533 | { | | |||
534 | QMimeDatabase db; | | |||
535 | // consider the filename if mimetype cannot be found by content-type | | |||
536 | auto mimeTypes = db.mimeTypesForFileName(name); | | |||
537 | foreach (const auto &mt, mimeTypes) { | | |||
538 | if (mt.name() != QLatin1String("application/octet-stream")) { | | |||
539 | return mt; | | |||
540 | } | | |||
541 | } | | |||
542 | | ||||
543 | // consider the attachment's contents if neither the Content-Type header | | |||
544 | // nor the filename give us a clue | | |||
545 | return db.mimeTypeForFile(name); | | |||
546 | } | | |||
483 | No newline at end of file |