2015-11-04 09:38:07 +01:00
|
|
|
// This file is part of RSS Guard.
|
|
|
|
//
|
2017-03-25 10:11:18 +01:00
|
|
|
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
2015-11-04 09:38:07 +01:00
|
|
|
//
|
|
|
|
// RSS Guard is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// RSS Guard is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-11-04 06:56:26 +01:00
|
|
|
#include "core/message.h"
|
|
|
|
|
2015-12-11 13:04:37 +01:00
|
|
|
#include "miscellaneous/textfactory.h"
|
|
|
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
2015-11-04 06:56:26 +01:00
|
|
|
|
|
|
|
Enclosure::Enclosure(const QString &url, const QString &mime) : m_url(url), m_mimeType(mime) {
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Enclosure> Enclosures::decodeEnclosuresFromString(const QString &enclosures_data) {
|
|
|
|
QList<Enclosure> enclosures;
|
|
|
|
|
|
|
|
foreach (const QString &single_enclosure, enclosures_data.split(ENCLOSURES_OUTER_SEPARATOR, QString::SkipEmptyParts)) {
|
|
|
|
Enclosure enclosure;
|
|
|
|
|
|
|
|
if (single_enclosure.contains(ECNLOSURES_INNER_SEPARATOR)) {
|
|
|
|
QStringList mime_url = single_enclosure.split(ECNLOSURES_INNER_SEPARATOR);
|
|
|
|
|
|
|
|
enclosure.m_mimeType = QByteArray::fromBase64(mime_url.at(0).toLocal8Bit());
|
|
|
|
enclosure.m_url = QByteArray::fromBase64(mime_url.at(1).toLocal8Bit());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
enclosure.m_url = QByteArray::fromBase64(single_enclosure.toLocal8Bit());
|
|
|
|
}
|
|
|
|
|
|
|
|
enclosures.append(enclosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
return enclosures;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Enclosures::encodeEnclosuresToString(const QList<Enclosure> &enclosures) {
|
|
|
|
QStringList enclosures_str;
|
|
|
|
|
|
|
|
foreach (const Enclosure &enclosure, enclosures) {
|
|
|
|
if (enclosure.m_mimeType.isEmpty()) {
|
|
|
|
enclosures_str.append(enclosure.m_url.toLocal8Bit().toBase64());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
enclosures_str.append(QString(enclosure.m_mimeType.toLocal8Bit().toBase64()) +
|
|
|
|
ECNLOSURES_INNER_SEPARATOR +
|
|
|
|
enclosure.m_url.toLocal8Bit().toBase64());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return enclosures_str.join(QString(ENCLOSURES_OUTER_SEPARATOR));
|
|
|
|
}
|
|
|
|
|
|
|
|
Message::Message() {
|
2017-04-23 20:52:31 +02:00
|
|
|
m_title = m_url = m_author = m_contents = m_feedId = m_customId = m_customHash = QSL("");
|
2015-11-04 06:56:26 +01:00
|
|
|
m_enclosures = QList<Enclosure>();
|
2015-12-10 11:30:10 +01:00
|
|
|
m_accountId = m_id = 0;
|
2015-12-08 19:19:35 +01:00
|
|
|
m_isRead = m_isImportant = false;
|
2015-11-04 06:56:26 +01:00
|
|
|
}
|
2015-12-11 13:04:37 +01:00
|
|
|
|
|
|
|
Message Message::fromSqlRecord(const QSqlRecord &record, bool *result) {
|
2016-02-26 09:15:57 +01:00
|
|
|
if (record.count() != MSG_DB_CUSTOM_HASH_INDEX + 1) {
|
2016-06-20 07:58:29 +02:00
|
|
|
if (result != nullptr) {
|
2015-12-11 13:04:37 +01:00
|
|
|
*result = false;
|
|
|
|
return Message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Message message;
|
|
|
|
|
|
|
|
message.m_id = record.value(MSG_DB_ID_INDEX).toInt();
|
|
|
|
message.m_isRead = record.value(MSG_DB_READ_INDEX).toBool();
|
|
|
|
message.m_isImportant = record.value(MSG_DB_IMPORTANT_INDEX).toBool();
|
2017-05-04 14:38:07 +02:00
|
|
|
message.m_feedId = record.value(MSG_DB_FEED_CUSTOM_ID_INDEX).toString();
|
2015-12-11 13:04:37 +01:00
|
|
|
message.m_title = record.value(MSG_DB_TITLE_INDEX).toString();
|
|
|
|
message.m_url = record.value(MSG_DB_URL_INDEX).toString();
|
|
|
|
message.m_author = record.value(MSG_DB_AUTHOR_INDEX).toString();
|
|
|
|
message.m_created = TextFactory::parseDateTime(record.value(MSG_DB_DCREATED_INDEX).value<qint64>());
|
|
|
|
message.m_contents = record.value(MSG_DB_CONTENTS_INDEX).toString();
|
|
|
|
message.m_enclosures = Enclosures::decodeEnclosuresFromString(record.value(MSG_DB_ENCLOSURES_INDEX).toString());
|
|
|
|
message.m_accountId = record.value(MSG_DB_ACCOUNT_ID_INDEX).toInt();
|
|
|
|
message.m_customId = record.value(MSG_DB_CUSTOM_ID_INDEX).toString();
|
2016-02-26 09:15:57 +01:00
|
|
|
message.m_customHash = record.value(MSG_DB_CUSTOM_HASH_INDEX).toString();
|
2015-12-11 13:04:37 +01:00
|
|
|
|
2016-06-20 07:58:29 +02:00
|
|
|
if (result != nullptr) {
|
2015-12-11 13:04:37 +01:00
|
|
|
*result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
2017-04-28 08:41:38 +02:00
|
|
|
|
|
|
|
uint qHash(Message key, uint seed) {
|
|
|
|
Q_UNUSED(seed)
|
|
|
|
return (key.m_accountId * 10000) + key.m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint qHash(const Message &key) {
|
|
|
|
return (key.m_accountId * 10000) + key.m_id;
|
|
|
|
}
|