summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-24 11:36:58 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-24 11:36:58 (GMT)
commit1723bdd827fb48caf61f6e95b3abe258bad8158b (patch)
tree1a8c6e883aef02e80ab806a4cf9716301c6ea8e4
parent0544b566ea62c09860099c4e51a22893fbf961ea (diff)
Use path and not data for icons. It's more easy to create autotest
-rw-r--r--messageviewer/src/messagepartthemes/default/autotests/quotehtmltest.cpp29
-rw-r--r--messageviewer/src/messagepartthemes/default/defaultrenderer.cpp18
-rw-r--r--messageviewer/src/utils/iconnamecache.cpp26
-rw-r--r--messageviewer/src/utils/iconnamecache.h3
-rw-r--r--messageviewer/src/viewer/viewer_p.cpp19
-rw-r--r--messageviewer/src/viewer/viewer_p.h1
6 files changed, 47 insertions, 49 deletions
diff --git a/messageviewer/src/messagepartthemes/default/autotests/quotehtmltest.cpp b/messageviewer/src/messagepartthemes/default/autotests/quotehtmltest.cpp
index 5cce1d7..969aa22 100644
--- a/messageviewer/src/messagepartthemes/default/autotests/quotehtmltest.cpp
+++ b/messageviewer/src/messagepartthemes/default/autotests/quotehtmltest.cpp
@@ -33,22 +33,11 @@ using namespace MessageViewer;
QTEST_GUILESS_MAIN(QuoteHtmlTest)
-static QString iconToDataUrl(const QString &iconPath)
-{
- QFile f(iconPath);
- if (!f.open(QIODevice::ReadOnly)) {
- return QString();
- }
-
- const QByteArray ba = f.readAll();
- return QStringLiteral("data:image/png;base64,%1").arg(QLatin1String(ba.toBase64().constData()));
-}
-
void QuoteHtmlTest::initTestCase()
{
MessageViewer::Test::setupEnv();
- mCollapseIcon = iconToDataUrl(MessageViewer::IconNameCache::instance()->iconPath(QStringLiteral("quotecollapse"), 0));
- mExpandIcon = iconToDataUrl(MessageViewer::IconNameCache::instance()->iconPath(QStringLiteral("quoteexpand"), 0));
+ mCollapseIcon = MessageViewer::IconNameCache::instance()->iconPathFromLocal(QStringLiteral("quotecollapse.png"));
+ mExpandIcon = MessageViewer::IconNameCache::instance()->iconPathFromLocal(QStringLiteral("quoteexpand.png"));
}
void QuoteHtmlTest::testQuoteHtml_data()
@@ -91,16 +80,20 @@ void QuoteHtmlTest::testQuoteHtml_data()
"<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">new quote1</font></div></div></blockquote><div class=\"noquote\"><div dir=\"ltr\">new text</div></div>").arg(mCollapseIcon)
<< true << 3;
- //TODO fix me quotelevel
QTest::newRow("bug-369072-expand-quotelevel2") << QStringLiteral("test\n>quote1\n>>quote2\n>>>quote3\n>>new quote2\n>new quote1\nnew text") <<
- QStringLiteral("<div class=\"noquote\"><div dir=\"ltr\">test</div>"
- "</div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?0 \"><img src=\"%1\"/></a></div>"
+ QStringLiteral("<div class=\"noquote\"><div dir=\"ltr\">test</div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?0 \"><img src=\"%1\"/></a></div>"
"<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">quote1</font></div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?1 \"><img src=\"%1\"/></a></div>"
- "<div class=\"quotelevel2\"><div dir=\"ltr\"><span class=\"quotemarks\">>></span><font color=\"#007000\">quote2</font></div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?-1 \"><img src=\"%1\"/></a></div><br/></div></blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?1 \"><img src=\"%1\"/></a></div>"
+ "<div class=\"quotelevel2\"><div dir=\"ltr\"><span class=\"quotemarks\">>></span><font color=\"#007000\">quote2</font></div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?-1 \"><img src=\"%2\"/></a></div><br/></div></blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?1 \"><img src=\"%1\"/></a></div>"
"<div class=\"quotelevel2\"><div dir=\"ltr\"><span class=\"quotemarks\">>></span><font color=\"#007000\">new quote2</font></div></div></blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?0 \"><img src=\"%1\"/></a></div>"
- "<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">new quote1</font></div></div></blockquote><div class=\"noquote\"><div dir=\"ltr\">new text</div></div>").arg(mCollapseIcon)
+ "<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">new quote1</font></div></div></blockquote><div class=\"noquote\"><div dir=\"ltr\">new text</div></div>").arg(mCollapseIcon).arg(mExpandIcon)
<< true << 2;
+ QTest::newRow("bug-369072-expand-quotelevel1") << QStringLiteral("test\n>quote1\n>>quote2\n>>>quote3\n>>new quote2\n>new quote1\nnew text") <<
+ QStringLiteral("<div class=\"noquote\"><div dir=\"ltr\">test</div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?0 \"><img src=\"%1\"/></a></div>"
+ "<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">quote1</font></div></div><blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?-1 \"><img src=\"%2\"/></a></div><br/>"
+ "</div><blockquote></blockquote></blockquote><div class=\"quotelevelmark\" ><a href=\"kmail:levelquote?0 \"><img src=\"%1\"/></a></div>"
+ "<div class=\"quotelevel1\"><div dir=\"ltr\"><span class=\"quotemarks\">></span><font color=\"#008000\">new quote1</font></div></div></blockquote><div class=\"noquote\"><div dir=\"ltr\">new text</div></div>").arg(mCollapseIcon).arg(mExpandIcon)
+ << true << 1;
}
diff --git a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
index 7f5d4fa..f7c9059 100644
--- a/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
+++ b/messageviewer/src/messagepartthemes/default/defaultrenderer.cpp
@@ -64,17 +64,6 @@ using namespace MessageViewer;
Q_DECLARE_METATYPE(GpgME::DecryptionResult::Recipient)
Q_DECLARE_METATYPE(const QGpgME::Protocol *)
-static QString iconToDataUrl(const QString &iconPath)
-{
- QFile f(iconPath);
- if (!f.open(QIODevice::ReadOnly)) {
- return QString();
- }
-
- const QByteArray ba = f.readAll();
- return QStringLiteral("data:image/png;base64,%1").arg(QLatin1String(ba.toBase64().constData()));
-}
-
/** Check if the newline at position @p newLinePos in string @p s
seems to separate two paragraphs (important for correct BiDi
behavior, but is heuristic because paragraphs are not
@@ -702,10 +691,10 @@ public:
if (source()->showExpandQuotesMark()) {
// Cache Icons
if (mCollapseIcon.isEmpty()) {
- mCollapseIcon = iconToDataUrl(IconNameCache::instance()->iconPath(QStringLiteral("quotecollapse"), 0));
+ mCollapseIcon = IconNameCache::instance()->iconPathFromLocal(QStringLiteral("quotecollapse.png"));
}
if (mExpandIcon.isEmpty()) {
- mExpandIcon = iconToDataUrl(IconNameCache::instance()->iconPath(QStringLiteral("quoteexpand"), 0));
+ mExpandIcon = IconNameCache::instance()->iconPathFromLocal(QStringLiteral("quoteexpand.png"));
}
}
@@ -763,7 +752,7 @@ public:
}
//Close blockquote
if (previousQuoteDepth > actQuoteLevel) {
- htmlStr += cssHelper()->addEndBlockQuote((previousQuoteDepth - actQuoteLevel));
+ htmlStr += cssHelper()->addEndBlockQuote(previousQuoteDepth - actQuoteLevel);
}
/* start new quotelevel */
@@ -800,7 +789,6 @@ public:
htmlStr += deepQuoteFontTag[actQuoteLevel % 3];
}
}
-
} else {
// Add blockquote
if (previousQuoteDepth < actQuoteLevel) {
diff --git a/messageviewer/src/utils/iconnamecache.cpp b/messageviewer/src/utils/iconnamecache.cpp
index 42149b7..9ccdf8b 100644
--- a/messageviewer/src/utils/iconnamecache.cpp
+++ b/messageviewer/src/utils/iconnamecache.cpp
@@ -20,6 +20,7 @@
#include "iconnamecache.h"
#include <KIconLoader>
+#include <QStandardPaths>
using namespace MessageViewer;
@@ -53,4 +54,27 @@ QString IconNameCache::iconPath(const QString &name, int size) const
const QString fileName = KIconLoader::global()->iconPath(name, size);
mCachedEntries.insert(entry, fileName);
return fileName;
-} \ No newline at end of file
+}
+
+QString IconNameCache::iconPathFromLocal(const QString &name) const
+{
+ Entry entry;
+ entry.fileName = name;
+ entry.size = 0;
+
+ if (mCachedEntries.contains(entry)) {
+ return mCachedEntries.value(entry);
+ }
+
+ const QString fileName = picsPath() + name;
+ mCachedEntries.insert(entry, fileName);
+ return fileName;
+}
+
+QString IconNameCache::picsPath() const
+{
+ if (mPicsPath.isEmpty()) {
+ mPicsPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libmessageviewer/pics/"), QStandardPaths::LocateDirectory);
+ }
+ return mPicsPath;
+}
diff --git a/messageviewer/src/utils/iconnamecache.h b/messageviewer/src/utils/iconnamecache.h
index 10c9ae6..4861f44 100644
--- a/messageviewer/src/utils/iconnamecache.h
+++ b/messageviewer/src/utils/iconnamecache.h
@@ -39,8 +39,10 @@ public:
static IconNameCache *instance();
QString iconPath(const QString &name, int size) const;
+ QString iconPathFromLocal(const QString &name) const;
private:
+ QString picsPath() const;
class Entry
{
@@ -52,6 +54,7 @@ private:
};
mutable QMap<Entry, QString> mCachedEntries;
+ mutable QString mPicsPath;
};
}
diff --git a/messageviewer/src/viewer/viewer_p.cpp b/messageviewer/src/viewer/viewer_p.cpp
index c57c12b..4213a75 100644
--- a/messageviewer/src/viewer/viewer_p.cpp
+++ b/messageviewer/src/viewer/viewer_p.cpp
@@ -27,6 +27,7 @@
#include "viewer/objecttreeemptysource.h"
#include "viewer/objecttreeviewersource.h"
#include "messagedisplayformatattribute.h"
+#include "utils/iconnamecache.h"
#include "scamdetection/scamdetectionwarningwidget.h"
#include "scamdetection/scamattribute.h"
#include "viewer/mimeparttree/mimeparttreeview.h"
@@ -2320,14 +2321,6 @@ void ViewerPrivate::slotSetEncoding()
}
}
-QString ViewerPrivate::picsPath()
-{
- if (mPicsPath.isEmpty()) {
- mPicsPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libmessageviewer/pics/"), QStandardPaths::LocateDirectory);
- }
- return mPicsPath;
-}
-
HeaderStylePlugin *ViewerPrivate::headerStylePlugin() const
{
return mHeaderStylePlugin;
@@ -2342,7 +2335,6 @@ QString ViewerPrivate::attachmentInjectionHtml()
return QString();
}
- QString imgpath(picsPath());
const QString urlHandleShow = QStringLiteral("kmail:showAttachmentQuicklist");
const QString imgSrcShow = QStringLiteral("quicklistClosed.png");
const QString urlHandleHide = QStringLiteral("kmail:hideAttachmentQuicklist");
@@ -2360,10 +2352,10 @@ QString ViewerPrivate::attachmentInjectionHtml()
const QString visibility = QStringLiteral("style=\"display:none;\"");
link += QStringLiteral("<div style=\"text-align: %1;\">").arg(textAlign) +
QStringLiteral("<a id=\"kmailshowattachment\" href=\"%1\" %2>").arg(urlHandleShow).arg(mShowAttachmentQuicklist ? QString() : visibility) +
- QStringLiteral("<img src=\"%1\">").arg(QUrl::fromLocalFile(imgpath + imgSrcShow).url()) +
+ QStringLiteral("<img src=\"%1\">").arg(QUrl::fromLocalFile(MessageViewer::IconNameCache::instance()->iconPathFromLocal(imgSrcShow)).url()) +
QStringLiteral("</a>") +
QStringLiteral("<a id=\"kmailhideattachment\" href=\"%1\" %2>").arg(urlHandleHide).arg(mShowAttachmentQuicklist ? visibility : QString()) +
- QStringLiteral("<img src=\"%1\">").arg(QUrl::fromLocalFile(imgpath + imgSrcHide).url()) +
+ QStringLiteral("<img src=\"%1\">").arg(QUrl::fromLocalFile(MessageViewer::IconNameCache::instance()->iconPathFromLocal(imgSrcHide)).url()) +
QStringLiteral("</a>") +
QStringLiteral("</div>");
@@ -2824,7 +2816,6 @@ void ViewerPrivate::toggleFullAddressList()
QString ViewerPrivate::recipientsQuickListLinkHtml(const QString &field)
{
- const QString imgpath(picsPath());
const QString urlHandleShow = QLatin1String("kmail:hideFull") + field + QLatin1String("AddressList");
const QString imgSrcShow = QStringLiteral("quicklistOpened.png");
const QString urlHandleHide = QLatin1String("kmail:showFull") + field + QLatin1String("AddressList");
@@ -2833,10 +2824,10 @@ QString ViewerPrivate::recipientsQuickListLinkHtml(const QString &field)
return QStringLiteral("<span style=\"text-align: right;\">") +
QStringLiteral("<a id=\"kmail%2show\" href=\"%1\">").arg(urlHandleShow).arg(field) +
- QStringLiteral("<img src=\"%1\" alt=\"%2\" />").arg(QUrl::fromLocalFile(imgpath + imgSrcShow).url(), /*altTextShow*/QString()) +
+ QStringLiteral("<img src=\"%1\" alt=\"%2\" />").arg(QUrl::fromLocalFile(MessageViewer::IconNameCache::instance()->iconPathFromLocal(imgSrcShow)).url(), /*altTextShow*/QString()) +
QStringLiteral("</a>") +
QStringLiteral("<a id=\"kmail%2hide\" href=\"%1\" %3>").arg(urlHandleHide).arg(field).arg(visibility) +
- QStringLiteral("<img src=\"%1\" alt=\"%2\" />").arg(QUrl::fromLocalFile(imgpath + imgSrcHide).url(), /*altTextHide*/QString()) +
+ QStringLiteral("<img src=\"%1\" alt=\"%2\" />").arg(QUrl::fromLocalFile(MessageViewer::IconNameCache::instance()->iconPathFromLocal(imgSrcHide)).url(), /*altTextHide*/QString()) +
QStringLiteral("</a>") +
QStringLiteral("</span>");
}
diff --git a/messageviewer/src/viewer/viewer_p.h b/messageviewer/src/viewer/viewer_p.h
index 822335c..29b3eb2 100644
--- a/messageviewer/src/viewer/viewer_p.h
+++ b/messageviewer/src/viewer/viewer_p.h
@@ -585,7 +585,6 @@ private:
void addHelpTextAction(QAction *act, const QString &text);
void readGravatarConfig();
- QString picsPath();
public:
MimeTreeParser::NodeHelper *mNodeHelper;
bool mHtmlMailGlobalSetting;