Commit 79949843 authored by Laurent Montel's avatar Laurent Montel 😁

Coding style

parent c21489ac
......@@ -24,29 +24,29 @@
MailSourceViewTextBrowserWidgetTest::MailSourceViewTextBrowserWidgetTest(QObject *parent)
: QObject(parent)
{
}
MailSourceViewTextBrowserWidgetTest::~MailSourceViewTextBrowserWidgetTest()
{
}
void MailSourceViewTextBrowserWidgetTest::shouldHaveDefaultValue()
{
MessageViewer::MailSourceViewTextBrowserWidget widget(QStringLiteral("Email"));
MessageViewer::MailSourceViewTextBrowser *textbrowser = widget.findChild<MessageViewer::MailSourceViewTextBrowser *>(QStringLiteral("textbrowser"));
MessageViewer::MailSourceViewTextBrowser *textbrowser
= widget.findChild<MessageViewer::MailSourceViewTextBrowser *>(QStringLiteral("textbrowser"));
QVERIFY(textbrowser);
QVERIFY(!textbrowser->isHidden());
MessageViewer::FindBarSourceView *findbar = widget.findChild<MessageViewer::FindBarSourceView *>(QStringLiteral("findbar"));
MessageViewer::FindBarSourceView *findbar
= widget.findChild<MessageViewer::FindBarSourceView *>(QStringLiteral("findbar"));
QVERIFY(findbar);
QVERIFY(findbar->isHidden());
KPIMTextEdit::TextToSpeechWidget *texttospeechwidget = widget.findChild<KPIMTextEdit::TextToSpeechWidget *>(QStringLiteral("texttospeech"));
KPIMTextEdit::TextToSpeechWidget *texttospeechwidget
= widget.findChild<KPIMTextEdit::TextToSpeechWidget *>(QStringLiteral("texttospeech"));
QVERIFY(texttospeechwidget);
QVERIFY(texttospeechwidget->isHidden());
}
QTEST_MAIN(MailSourceViewTextBrowserWidgetTest)
......@@ -31,4 +31,3 @@ private Q_SLOTS:
};
#endif // MAILSOURCEVIEWTEXTBROWSERWIDGETTEST_H
......@@ -25,12 +25,10 @@
MessageDisplayFormatAttributeTest::MessageDisplayFormatAttributeTest(QObject *parent)
: QObject(parent)
{
}
MessageDisplayFormatAttributeTest::~MessageDisplayFormatAttributeTest()
{
}
void MessageDisplayFormatAttributeTest::shouldHaveDefaultValue()
......@@ -61,7 +59,6 @@ void MessageDisplayFormatAttributeTest::shouldChangeMessageFormat()
format = MessageViewer::Viewer::UseGlobalSetting;
attr.setMessageFormat(format);
QCOMPARE(attr.messageFormat(), format);
}
void MessageDisplayFormatAttributeTest::shouldDeserializeValue()
......
......@@ -28,7 +28,7 @@
void MessageViewer::Test::setupEnv()
{
setenv("LC_ALL", "C", 1);
setenv("KDEHOME", QFile::encodeName(QDir::homePath() + QString::fromLatin1("/.qttest")).constData(), 1);
setenv("KDEHOME", QFile::encodeName(QDir::homePath() + QString::fromLatin1(
"/.qttest")).constData(), 1);
QStandardPaths::setTestModeEnabled(true);
}
......@@ -25,21 +25,15 @@
#include <viewer/objecttreeemptysource.h>
#include <viewer/attachmentstrategy.h>
namespace MessageViewer
{
namespace Test
{
namespace MessageViewer {
namespace Test {
/**
* setup a environment variables for tests:
* * set LC_ALL to C
* * set KDEHOME
*/
void setupEnv();
}
}
#endif
......@@ -31,7 +31,6 @@ ViewerGrantleeThemeSupportTest::ViewerGrantleeThemeSupportTest(QObject *parent)
ViewerGrantleeThemeSupportTest::~ViewerGrantleeThemeSupportTest()
{
}
void ViewerGrantleeThemeSupportTest::initTestCase()
......@@ -46,7 +45,8 @@ void ViewerGrantleeThemeSupportTest::initTestCase()
void ViewerGrantleeThemeSupportTest::shouldUpdateThemeMenu()
{
MessageViewer::Viewer *viewer = new MessageViewer::Viewer(nullptr, nullptr, new KActionCollection(this));
MessageViewer::Viewer *viewer = new MessageViewer::Viewer(nullptr, nullptr, new KActionCollection(
this));
viewer->show();
QTest::qWaitForWindowExposed(viewer);
}
......
......@@ -27,7 +27,8 @@ ViewerTest::ViewerTest()
void ViewerTest::shouldHaveDefaultValuesOnCreation()
{
MessageViewer::Viewer *viewer = new MessageViewer::Viewer(nullptr, nullptr, new KActionCollection(this));
MessageViewer::Viewer *viewer = new MessageViewer::Viewer(nullptr, nullptr, new KActionCollection(
this));
viewer->show();
QTest::qWaitForWindowExposed(viewer);
......@@ -42,11 +43,13 @@ void ViewerTest::shouldHaveDefaultValuesOnCreation()
QWidget *colorBar = viewer->findChild<QWidget *>(QStringLiteral("mColorBar"));
QVERIFY(colorBar);
QWidget *scandetectionWidget = viewer->findChild<QWidget *>(QStringLiteral("scandetectionwarning"));
QWidget *scandetectionWidget
= viewer->findChild<QWidget *>(QStringLiteral("scandetectionwarning"));
QVERIFY(scandetectionWidget);
QCOMPARE(scandetectionWidget->isVisible(), false);
QWidget *openattachementfolderwidget = viewer->findChild<QWidget *>(QStringLiteral("openattachementfolderwidget"));
QWidget *openattachementfolderwidget
= viewer->findChild<QWidget *>(QStringLiteral("openattachementfolderwidget"));
QVERIFY(openattachementfolderwidget);
QCOMPARE(openattachementfolderwidget->isVisible(), false);
......@@ -70,29 +73,29 @@ void ViewerTest::shouldHaveDefaultValuesOnCreation()
delete viewer;
}
static const char s_mail1[] =
"From: Konqui <konqui@kde.org>\n"
"To: Friends <friends@kde.org>\n"
"Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
"Subject: Sample message\n"
"MIME-Version: 1.0\n"
"Content-type: text/plain; charset=us-ascii\n"
"\n"
"\n"
"This is a test message.\n"
"\n";
static const char s_mail2[] =
"From: David Faure <dfaure@example.com>\n"
"To: Friends <friends@example.com>\n"
"Date: Sun, 31 Aug 2016 23:56:48 +0200 (CEST)\n"
"Subject: Second mail\n"
"MIME-Version: 1.0\n"
"Content-type: text/plain; charset=\"us-ascii\"\n"
"\n"
"\n"
"This is the second message.\n"
"\n";
static const char s_mail1[]
= "From: Konqui <konqui@kde.org>\n"
"To: Friends <friends@kde.org>\n"
"Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)\n"
"Subject: Sample message\n"
"MIME-Version: 1.0\n"
"Content-type: text/plain; charset=us-ascii\n"
"\n"
"\n"
"This is a test message.\n"
"\n";
static const char s_mail2[]
= "From: David Faure <dfaure@example.com>\n"
"To: Friends <friends@example.com>\n"
"Date: Sun, 31 Aug 2016 23:56:48 +0200 (CEST)\n"
"Subject: Second mail\n"
"MIME-Version: 1.0\n"
"Content-type: text/plain; charset=\"us-ascii\"\n"
"\n"
"\n"
"This is the second message.\n"
"\n";
KMime::Message::Ptr createMsg(const char *data)
{
......
......@@ -23,12 +23,10 @@
ZoomActionMenuTest::ZoomActionMenuTest(QObject *parent)
: QObject(parent)
{
}
ZoomActionMenuTest::~ZoomActionMenuTest()
{
}
void ZoomActionMenuTest::shouldHaveDefaultValue()
......
......@@ -79,13 +79,13 @@ void AntiSpamConfig::readConfig()
for (unsigned int i = 1; i <= totalTools; ++i) {
KConfigGroup tool(&config, QStringLiteral("Spamtool #%1").arg(i));
if (tool.hasKey("ScoreHeader")) {
const QString name = tool.readEntry("ScoreName");
const QByteArray header = tool.readEntry("ScoreHeader").toLatin1();
const QByteArray cheader = tool.readEntry("ConfidenceHeader").toLatin1();
const QByteArray type = tool.readEntry("ScoreType").toLatin1();
const QString score = tool.readEntryUntranslated("ScoreValueRegexp");
const QString threshold = tool.readEntryUntranslated("ScoreThresholdRegexp");
const QString confidence = tool.readEntryUntranslated("ScoreConfidenceRegexp");
const QString name = tool.readEntry("ScoreName");
const QByteArray header = tool.readEntry("ScoreHeader").toLatin1();
const QByteArray cheader = tool.readEntry("ConfidenceHeader").toLatin1();
const QByteArray type = tool.readEntry("ScoreType").toLatin1();
const QString score = tool.readEntryUntranslated("ScoreValueRegexp");
const QString threshold = tool.readEntryUntranslated("ScoreThresholdRegexp");
const QString confidence = tool.readEntryUntranslated("ScoreConfidenceRegexp");
SpamAgentTypes typeE = SpamAgentNone;
if (qstricmp(type.data(), "bool") == 0) {
typeE = SpamAgentBool;
......
......@@ -40,9 +40,7 @@
class QString;
namespace MessageViewer
{
namespace MessageViewer {
/// Valid types of SpamAgent
enum SpamAgentTypes {
SpamAgentNone, //!< Invalid SpamAgent, skip this agent
......@@ -55,36 +53,53 @@ enum SpamAgentTypes {
class SpamAgent
{
public:
SpamAgent() : mType(SpamAgentNone) {}
SpamAgent(const QString &name, SpamAgentTypes type, const QByteArray &field, const QByteArray &cfield,
const QRegExp &score, const QRegExp &threshold, const QRegExp &confidence)
: mName(name), mType(type), mField(field), mConfidenceField(cfield),
mScore(score), mThreshold(threshold), mConfidence(confidence) {}
SpamAgent() : mType(SpamAgentNone)
{
}
SpamAgent(const QString &name, SpamAgentTypes type, const QByteArray &field,
const QByteArray &cfield, const QRegExp &score, const QRegExp &threshold,
const QRegExp &confidence)
: mName(name)
, mType(type)
, mField(field)
, mConfidenceField(cfield)
, mScore(score)
, mThreshold(threshold)
, mConfidence(confidence)
{
}
QString name() const
{
return mName;
}
SpamAgentTypes scoreType() const
{
return mType;
}
QByteArray header() const
{
return mField;
}
QByteArray confidenceHeader() const
{
return mConfidenceField;
}
QRegExp scorePattern() const
{
return mScore;
}
QRegExp thresholdPattern() const
{
return mThreshold;
}
QRegExp confidencePattern() const
{
return mConfidence;
......@@ -141,7 +156,6 @@ private:
void readConfig();
};
}
#endif // __MESSAGEVIEWER_ANTISPAMCONFIG_H__
......@@ -170,7 +170,7 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
KMime::Headers::Base *cHeader = message->headerByType(confidenceHeaderName.constData());
if (cHeader) {
mCField = cHeader->asUnicodeString();
if (! mCField.isEmpty()) {
if (!mCField.isEmpty()) {
// Can we extract the confidence?
QRegExp cScorePattern = (*it).confidencePattern();
if (cScorePattern.indexIn(mCField) != -1) {
......@@ -179,7 +179,8 @@ SpamScores SpamHeaderAnalyzer::getSpamScores(KMime::Message *message)
confidence = confidenceString.toFloat(&confidenceValid);
if (!confidenceValid) {
spamError = couldNotConvertConfidenceToFloat;
qCDebug(MESSAGEVIEWER_LOG) << "Unable to convert confidence to float:" << confidenceString;
qCDebug(MESSAGEVIEWER_LOG) << "Unable to convert confidence to float:"
<< confidenceString;
}
}
}
......
......@@ -39,9 +39,7 @@
#include <QString>
#include <QVector>
namespace MessageViewer
{
namespace MessageViewer {
enum SpamError {
noError,
uninitializedStructUsed,
......@@ -72,40 +70,48 @@ class SpamScore
public:
SpamScore()
: mError(noError), mScore(-2.0), mConfidence(-2.0)
: mError(noError)
, mScore(-2.0)
, mConfidence(-2.0)
{
}
SpamScore(const QString &agent, SpamError error, float score, float confidence,
const QString &header, const QString &cheader)
: mAgent(agent),
mError(error),
mScore(score),
mConfidence(confidence),
mHeader(header),
mConfidenceHeader(cheader)
: mAgent(agent)
, mError(error)
, mScore(score)
, mConfidence(confidence)
, mHeader(header)
, mConfidenceHeader(cheader)
{
}
QString agent() const
{
return mAgent;
}
float score() const
{
return mScore;
}
float confidence() const
{
return mConfidence;
}
SpamError error() const
{
return mError;
}
QString spamHeader() const
{
return mHeader;
}
QString confidenceHeader() const
{
return mConfidenceHeader;
......@@ -135,7 +141,6 @@ public:
*/
static SpamScores getSpamScores(KMime::Message *message);
};
}
#endif // __SPAMHEADERANALYZER_H__
......@@ -24,7 +24,8 @@
using namespace MessageViewer;
FindBarSourceView::FindBarSourceView(QPlainTextEdit *view, QWidget *parent)
: WebEngineViewer::FindBarBase(parent), mView(view)
: WebEngineViewer::FindBarBase(parent)
, mView(view)
{
}
......@@ -80,4 +81,3 @@ void FindBarSourceView::updateSensitivity(bool)
const bool found = mView->find(mLastSearchStr, searchOptions);
setFoundMatch(found);
}
......@@ -23,8 +23,7 @@
class QPlainTextEdit;
namespace MessageViewer
{
namespace MessageViewer {
class FindBarSourceView : public WebEngineViewer::FindBarBase
{
Q_OBJECT
......@@ -38,6 +37,7 @@ private:
{
Q_UNUSED(parent);
}
void clearSelections() override;
void searchText(bool backward, bool isAutoSearch) override;
void updateHighLight(bool) override;
......@@ -49,4 +49,3 @@ private:
}
#endif /* FINDBARSOURCEVIEW_H */
......@@ -29,17 +29,20 @@
using namespace MessageViewer;
ContactDisplayMessageMemento::ContactDisplayMessageMemento(const QString &emailAddress)
: QObject(nullptr),
mForceDisplayTo(Viewer::UseGlobalSetting),
mEmailAddress(emailAddress),
mFinished(false),
mMailAllowToRemoteContent(false),
mSearchJob(nullptr)
: QObject(nullptr)
, mForceDisplayTo(Viewer::UseGlobalSetting)
, mEmailAddress(emailAddress)
, mFinished(false)
, mMailAllowToRemoteContent(false)
, mSearchJob(nullptr)
{
if (!emailAddress.isEmpty()) {
mSearchJob = new Akonadi::ContactSearchJob();
mSearchJob->setQuery(Akonadi::ContactSearchJob::Email, emailAddress.toLower(), Akonadi::ContactSearchJob::ExactMatch);
connect(mSearchJob.data(), &Akonadi::ContactSearchJob::result, this, &ContactDisplayMessageMemento::slotSearchJobFinished);
mSearchJob->setQuery(Akonadi::ContactSearchJob::Email,
emailAddress.toLower(), Akonadi::ContactSearchJob::ExactMatch);
connect(
mSearchJob.data(), &Akonadi::ContactSearchJob::result, this,
&ContactDisplayMessageMemento::slotSearchJobFinished);
} else {
mFinished = true;
}
......@@ -48,7 +51,9 @@ ContactDisplayMessageMemento::ContactDisplayMessageMemento(const QString &emailA
ContactDisplayMessageMemento::~ContactDisplayMessageMemento()
{
if (mSearchJob) {
disconnect(mSearchJob.data(), &Akonadi::ContactSearchJob::result, this, &ContactDisplayMessageMemento::slotSearchJobFinished);
disconnect(
mSearchJob.data(), &Akonadi::ContactSearchJob::result, this,
&ContactDisplayMessageMemento::slotSearchJobFinished);
mSearchJob->kill();
}
}
......@@ -89,7 +94,7 @@ void ContactDisplayMessageMemento::slotSearchJobFinished(KJob *job)
QByteArray imageData;
KIO::TransferJob *job = KIO::get(url, KIO::NoReload);
QObject::connect(job, &KIO::TransferJob::data,
[&imageData](KIO::Job *, const QByteArray & data) {
[&imageData](KIO::Job *, const QByteArray &data) {
imageData.append(data);
});
if (job->exec()) {
......@@ -111,12 +116,14 @@ void ContactDisplayMessageMemento::slotSearchJobFinished(KJob *job)
if (Gravatar::GravatarSettings::self()->gravatarSupportEnabled()) {
Gravatar::GravatarResolvUrlJob *job = new Gravatar::GravatarResolvUrlJob(this);
job->setEmail(mEmailAddress);
job->setUseDefaultPixmap(Gravatar::GravatarSettings::self()->gravatarUseDefaultImage());
job->setUseDefaultPixmap(
Gravatar::GravatarSettings::self()->gravatarUseDefaultImage());
job->setUseLibravatar(Gravatar::GravatarSettings::self()->libravatarSupportEnabled());
job->setFallbackGravatar(Gravatar::GravatarSettings::self()->fallbackToGravatar());
job->setUseHttps(true);
if (job->canStart()) {
connect(job, &Gravatar::GravatarResolvUrlJob::finished, this, &ContactDisplayMessageMemento::slotGravatarResolvUrlFinished);
connect(job, &Gravatar::GravatarResolvUrlJob::finished, this,
&ContactDisplayMessageMemento::slotGravatarResolvUrlFinished);
job->start();
} else {
job->deleteLater();
......@@ -134,7 +141,8 @@ bool ContactDisplayMessageMemento::finished() const
void ContactDisplayMessageMemento::detach()
{
disconnect(this, SIGNAL(update(MimeTreeParser::UpdateMode)), nullptr, nullptr);