Commit f19faa83 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

run git clang-format

parent 5581cc97
......@@ -6,9 +6,9 @@
#include "noteutils.h"
#include <QTest>
#include <QHash>
#include <QDebug>
#include <QHash>
#include <QTest>
#include <QDateTime>
#include <kmime/kmime_message.h>
......@@ -31,13 +31,14 @@ private Q_SLOTS:
note.setLastModifiedDate(QDateTime(QDate(2012, 3, 3), QTime(4, 4, 4), Qt::UTC));
Attachment a("testfile2", QStringLiteral("mimetype/mime3"));
a.setLabel(QStringLiteral("label"));
note.attachments() << Attachment(QUrl(QStringLiteral("file://url/to/file")), QStringLiteral("mimetype/mime")) << Attachment("testfile", QStringLiteral("mimetype/mime2")) << a;
note.attachments() << Attachment(QUrl(QStringLiteral("file://url/to/file")), QStringLiteral("mimetype/mime"))
<< Attachment("testfile", QStringLiteral("mimetype/mime2")) << a;
note.custom().insert(QStringLiteral("key1"), QStringLiteral("value1"));
note.custom().insert(QStringLiteral("key2"), QStringLiteral("value2"));
note.custom().insert(QStringLiteral("key3"), QStringLiteral("value3"));
KMime::MessagePtr msg = note.message();
// qWarning() << msg->encodedContent();
// qWarning() << msg->encodedContent();
NoteMessageWrapper result(msg);
......@@ -52,7 +53,7 @@ private Q_SLOTS:
QCOMPARE(result.custom(), note.custom());
QCOMPARE(result.attachments(), note.attachments());
// qWarning() << result.message()->encodedContent();
// qWarning() << result.message()->encodedContent();
}
void createIfEmpty()
......@@ -66,7 +67,8 @@ private Q_SLOTS:
void testNormalTextWithoutAttachments()
{
NoteMessageWrapper note;
QString text(QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
QString text(
QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
<html> \
<head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
<body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
......@@ -83,7 +85,8 @@ private Q_SLOTS:
void testRichTextWithoutAttachments()
{
NoteMessageWrapper note;
QString text(QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
QString text(
QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
<html> \
<head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
<body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
......@@ -100,7 +103,8 @@ private Q_SLOTS:
void testRichTextWithAttachments()
{
NoteMessageWrapper note;
QString text(QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
QString text(
QStringLiteral("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\"> \
<html> \
<head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head> \
<body style=\"font-family:'Sans Serif'; font-size:9pt;\"> <p>sdfg</p></body> \
......@@ -118,7 +122,6 @@ private Q_SLOTS:
QCOMPARE(result.textFormat(), Qt::RichText);
QCOMPARE(result.attachments(), note.attachments());
}
};
QTEST_MAIN(NotesTest)
......
......@@ -6,10 +6,10 @@
#include "noteutils.h"
#include "akonadi_notes_debug.h"
#include <KLocalizedString>
#include <QDateTime>
#include <kmime/kmime_message.h>
#include "akonadi_notes_debug.h"
#include <QRegularExpression>
#include <QString>
......@@ -20,7 +20,6 @@ namespace Akonadi
{
namespace NoteUtils
{
#define X_NOTES_UID_HEADER "X-Akonotes-UID"
#define X_NOTES_LASTMODIFIED_HEADER "X-Akonotes-LastModified"
#define X_NOTES_CLASSIFICATION_HEADER "X-Akonotes-Classification"
......@@ -69,7 +68,6 @@ public:
Attachment::Attachment()
: d_ptr(new Attachment::AttachmentPrivate(QUrl(), QString()))
{
}
Attachment::Attachment(const QUrl &url, const QString &mimetype)
......@@ -96,17 +94,11 @@ bool Attachment::operator==(const Attachment &a) const
{
Q_D(const Attachment);
if (d->mUrl.isEmpty()) {
return d->mUrl == a.d_func()->mUrl &&
d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded &&
d->mMimetype == a.d_func()->mMimetype &&
d->mContentID == a.d_func()->mContentID &&
d->mLabel == a.d_func()->mLabel;
return d->mUrl == a.d_func()->mUrl && d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded && d->mMimetype == a.d_func()->mMimetype
&& d->mContentID == a.d_func()->mContentID && d->mLabel == a.d_func()->mLabel;
}
return d->mData == a.d_func()->mData &&
d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded &&
d->mMimetype == a.d_func()->mMimetype &&
d->mContentID == a.d_func()->mContentID &&
d->mLabel == a.d_func()->mLabel;
return d->mData == a.d_func()->mData && d->mDataBase64Encoded == a.d_func()->mDataBase64Encoded && d->mMimetype == a.d_func()->mMimetype
&& d->mContentID == a.d_func()->mContentID && d->mLabel == a.d_func()->mLabel;
}
void Attachment::operator=(const Attachment &a)
......@@ -194,7 +186,7 @@ public:
QString from;
QDateTime creationDate;
QDateTime lastModifiedDate;
QMap< QString, QString > custom;
QMap<QString, QString> custom;
QVector<Attachment> attachments;
Classification classification = Public;
Qt::TextFormat textFormat = Qt::PlainText;
......@@ -207,7 +199,7 @@ void NoteMessageWrapper::NoteMessageWrapperPrivate::readMimeMessage(const KMime:
return;
}
title = msg->subject(true)->asUnicodeString();
text = msg->mainBodyPart()->decodedText(true); //remove trailing whitespace, so we get rid of " " in empty notes
text = msg->mainBodyPart()->decodedText(true); // remove trailing whitespace, so we get rid of " " in empty notes
if (msg->from(false)) {
from = msg->from(false)->asUnicodeString();
}
......@@ -282,8 +274,8 @@ KMime::Content *NoteMessageWrapper::NoteMessageWrapperPrivate::createCustomPart(
QDomDocument document = createXMLDocument();
QDomElement element = document.createElement(QStringLiteral("custom"));
element.setAttribute(QStringLiteral("version"), QStringLiteral("1.0"));
QMap <QString, QString >::const_iterator end = custom.end();
for (QMap <QString, QString >::const_iterator it = custom.begin(); it != end; ++it) {
QMap<QString, QString>::const_iterator end = custom.end();
for (QMap<QString, QString>::const_iterator it = custom.begin(); it != end; ++it) {
QDomElement e = element.ownerDocument().createElement(it.key());
QDomText t = element.ownerDocument().createTextNode(it.value());
e.appendChild(t);
......@@ -302,8 +294,7 @@ void NoteMessageWrapper::NoteMessageWrapperPrivate::parseCustomPart(KMime::Conte
}
QDomElement top = document.documentElement();
if (top.tagName() != QLatin1String("custom")) {
qWarning("XML error: Top tag was %s instead of the expected custom",
top.tagName().toLatin1().data());
qWarning("XML error: Top tag was %s instead of the expected custom", top.tagName().toLatin1().data());
return;
}
......@@ -369,12 +360,12 @@ void NoteMessageWrapper::NoteMessageWrapperPrivate::parseAttachmentPart(KMime::C
}
NoteMessageWrapper::NoteMessageWrapper()
: d_ptr(new NoteMessageWrapperPrivate())
: d_ptr(new NoteMessageWrapperPrivate())
{
}
NoteMessageWrapper::NoteMessageWrapper(const KMime::MessagePtr &msg)
: d_ptr(new NoteMessageWrapperPrivate(msg))
: d_ptr(new NoteMessageWrapperPrivate(msg))
{
}
......@@ -436,7 +427,7 @@ KMime::MessagePtr NoteMessageWrapper::message() const
classification = CLASSIFICATION_CONFIDENTIAL;
break;
default:
//do nothing
// do nothing
break;
}
header = new KMime::Headers::Generic(X_NOTES_CLASSIFICATION_HEADER);
......@@ -557,7 +548,7 @@ QString NoteMessageWrapper::toPlainText() const
return d->text;
}
//From cleanHtml in kdepimlibs/kcalutils/incidenceformatter.cpp
// From cleanHtml in kdepimlibs/kcalutils/incidenceformatter.cpp
const QRegularExpression rx(QStringLiteral("<body[^>]*>(.*)</body>"), QRegularExpression::CaseInsensitiveOption);
QString body = rx.match(d->text).captured(1);
......@@ -570,7 +561,7 @@ QVector<Attachment> &NoteMessageWrapper::attachments()
return d->attachments;
}
QMap< QString, QString > &NoteMessageWrapper::custom()
QMap<QString, QString> &NoteMessageWrapper::custom()
{
Q_D(NoteMessageWrapper);
return d->custom;
......@@ -586,5 +577,5 @@ QString noteMimeType()
return QStringLiteral("text/x-vnd.akonadi.note");
}
} //End Namespace
} //End Namespace
} // End Namespace
} // End Namespace
......@@ -9,12 +9,12 @@
#include "akonadi-notes_export.h"
#include <QUrl>
#include <QMap>
#include <QUrl>
class QDateTime;
class QString;
template <typename T> class QSharedPointer;
template<typename T> class QSharedPointer;
namespace KMime
{
......@@ -25,23 +25,22 @@ namespace Akonadi
{
namespace NoteUtils
{
/**
* @return mimetype for notes
* @since 4.8
*/
* @return mimetype for notes
* @since 4.8
*/
AKONADI_NOTES_EXPORT QString noteMimeType();
/**
* @return icon for notes
* @since 4.8
*/
* @return icon for notes
* @since 4.8
*/
AKONADI_NOTES_EXPORT QString noteIconName();
/**
* An attachment for a note
* @since 4.9
*/
* An attachment for a note
* @since 4.9
*/
class AKONADI_NOTES_EXPORT Attachment
{
public:
......@@ -86,7 +85,7 @@ public:
*/
QString contentID() const;
/**
/**
* Set this to true if inline data provided via ctor
* is alredy base64 encoded. Default value is false.
*
......@@ -101,7 +100,7 @@ public:
*/
bool dataBase64Encoded() const;
/**
/**
* Returns the mimetype
*/
QString mimetype() const;
......@@ -115,6 +114,7 @@ public:
* Returns the label of the attachment
*/
QString label() const;
private:
//@cond PRIVATE
class AttachmentPrivate;
......@@ -124,43 +124,43 @@ private:
};
/**
* A convenience wrapper around KMime::MessagePtr for notes
*
* This is the format used by the Akonotes Resource
*
* A note has the following properties:
* uid: globally unique identifier (generated if empty)
* creationDate: timestamp when the note was created (generated if empty)
* lastModified: lastModified (generated if empty)
* classification: one of private, confidential, public. This is only meant as an indication to the user.
* title: title of the note
* text: textual content
* from: author (generated if empty)
* attachments: inline or url only
* custom: key value pair for custom values
*
* Reading a note from an Akonotes akonadi item:
* @code
* if ( item.hasPayload<KMime::MessagePtr>() ) {
* NoteUtils::NoteMessageWrapper note(item.payload<KMime::MessagePtr>());
* qCDebug(AKONADINOTES_LOG) << note.text();
* textIsRich = messageWrapper.textFormat() == Qt::RichText;
* }
* @endcode
*
* Setting the note as payload of an akonadi Item
* @code
* item.setMimeType(NoteUtils::noteMimeType());
* NoteUtils::NoteMessageWrapper note;
* note.setTitle( "title" );
* note.setText( "text" );
* note.setFrom( QString::fromLatin1( "MyApplication@kde4" ) );
* item.setPayload( note.message() );
* @endcode
*
* @author Christian Mollekopf <chrigi_1@fastmail.fm>
* @since 4.8
*/
* A convenience wrapper around KMime::MessagePtr for notes
*
* This is the format used by the Akonotes Resource
*
* A note has the following properties:
* uid: globally unique identifier (generated if empty)
* creationDate: timestamp when the note was created (generated if empty)
* lastModified: lastModified (generated if empty)
* classification: one of private, confidential, public. This is only meant as an indication to the user.
* title: title of the note
* text: textual content
* from: author (generated if empty)
* attachments: inline or url only
* custom: key value pair for custom values
*
* Reading a note from an Akonotes akonadi item:
* @code
* if ( item.hasPayload<KMime::MessagePtr>() ) {
* NoteUtils::NoteMessageWrapper note(item.payload<KMime::MessagePtr>());
* qCDebug(AKONADINOTES_LOG) << note.text();
* textIsRich = messageWrapper.textFormat() == Qt::RichText;
* }
* @endcode
*
* Setting the note as payload of an akonadi Item
* @code
* item.setMimeType(NoteUtils::noteMimeType());
* NoteUtils::NoteMessageWrapper note;
* note.setTitle( "title" );
* note.setText( "text" );
* note.setFrom( QString::fromLatin1( "MyApplication@kde4" ) );
* item.setPayload( note.message() );
* @endcode
*
* @author Christian Mollekopf <chrigi_1@fastmail.fm>
* @since 4.8
*/
class AKONADI_NOTES_EXPORT NoteMessageWrapper
{
public:
......@@ -169,112 +169,108 @@ public:
~NoteMessageWrapper();
/**
* Set the uid of the note
* @param uid should be globally unique
*/
* Set the uid of the note
* @param uid should be globally unique
*/
void setUid(const QString &uid);
/**
* Returns the uid of the note
*/
* Returns the uid of the note
*/
QString uid() const;
enum Classification {
Public,
Private,
Confidential
};
enum Classification { Public, Private, Confidential };
/**
* Set the classification of the note
*/
* Set the classification of the note
*/
void setClassification(Classification);
/**
* Returns the classification of the note
*/
* Returns the classification of the note
*/
Classification classification() const;
/**
* Set the title of the note
*/
* Set the title of the note
*/
void setTitle(const QString &title);
/**
* Returns the title of the note
*/
* Returns the title of the note
*/
QString title() const;
/**
* Set the text of the note
*
* @param format only Qt::PlainText and Qt::RichText is supported
*/
* Set the text of the note
*
* @param format only Qt::PlainText and Qt::RichText is supported
*/
void setText(const QString &text, Qt::TextFormat format = Qt::PlainText);
/**
* Returns the text of the note
*/
* Returns the text of the note
*/
QString text() const;
/**
* @return Qt::PlainText or Qt::RichText
*/
* @return Qt::PlainText or Qt::RichText
*/
Qt::TextFormat textFormat() const;
/**
* @return plaintext version of the text (if richtext)
*/
* @return plaintext version of the text (if richtext)
*/
QString toPlainText() const;
/**
* Set the creation date of the note (stored in the mime header)
*/
* Set the creation date of the note (stored in the mime header)
*/
void setCreationDate(const QDateTime &creationDate);
/**
* Returns the creation date of the note
*/
* Returns the creation date of the note
*/
QDateTime creationDate() const;
/**
* Set the lastModified-date of the note
*/
* Set the lastModified-date of the note
*/
void setLastModifiedDate(const QDateTime &lastModifiedDate);
/**
* Returns the lastModified-date of the note
*/
* Returns the lastModified-date of the note
*/
QDateTime lastModifiedDate() const;
/**
* Set the origin (creator) of the note (stored in the mime header)
* This is usually the application creating the note.
* @param from must be an address in the style of foo@kde.org.
*/
* Set the origin (creator) of the note (stored in the mime header)
* This is usually the application creating the note.
* @param from must be an address in the style of foo@kde.org.
*/
void setFrom(const QString &from);
/**
* Returns the origin (creator) of the note
*/
* Returns the origin (creator) of the note
*/
QString from() const;
/**
* Returns a reference to the list of attachments of the note
*/
* Returns a reference to the list of attachments of the note
*/
QVector<Attachment> &attachments();
/**
* Returns a reference to the custom-value map
* @return key-value map containing all custom values
*/
* Returns a reference to the custom-value map
* @return key-value map containing all custom values
*/
QMap<QString, QString> &custom();
/**
* Assemble a KMime message with the given values
*
* The message can then i.e. be stored inside an akonadi item
*/
* Assemble a KMime message with the given values
*
* The message can then i.e. be stored inside an akonadi item
*/
KMime::MessagePtr message() const;
private:
......
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