Commit 1723bdd8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use path and not data for icons. It's more easy to create autotest

parent 0544b566
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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;
}
......@@ -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;
};
}
......
......@@ -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>");
}
......
......@@ -585,7 +585,6 @@ private:
void addHelpTextAction(QAction *act, const QString &text);
void readGravatarConfig();
QString picsPath();
public:
MimeTreeParser::NodeHelper *mNodeHelper;
bool mHtmlMailGlobalSetting;
......
Supports Markdown
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