Hell with date/times.
This commit is contained in:
parent
c753939fd7
commit
943d89c8e8
@ -96,8 +96,7 @@ FeedsModelStandardCategory *FeedsModelStandardCategory::loadFromRecord(const QSq
|
|||||||
category->setId(record.value(CAT_DB_ID_INDEX).toInt());
|
category->setId(record.value(CAT_DB_ID_INDEX).toInt());
|
||||||
category->setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
category->setTitle(record.value(CAT_DB_TITLE_INDEX).toString());
|
||||||
category->setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
|
category->setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString());
|
||||||
category->setCreationDate(QDateTime::fromString(record.value(CAT_DB_DCREATED_INDEX).toString(),
|
category->setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
|
||||||
Qt::ISODate));
|
|
||||||
category->setIcon(IconFactory::fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray()));
|
category->setIcon(IconFactory::fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray()));
|
||||||
|
|
||||||
return category;
|
return category;
|
||||||
|
@ -32,8 +32,7 @@ FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord
|
|||||||
feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
|
feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
|
||||||
feed->setId(record.value(FDS_DB_ID_INDEX).toInt());
|
feed->setId(record.value(FDS_DB_ID_INDEX).toInt());
|
||||||
feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString());
|
feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString());
|
||||||
feed->setCreationDate(QDateTime::fromString(record.value(FDS_DB_DCREATED_INDEX).toString(),
|
feed->setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value<qint64>()).toLocalTime());
|
||||||
Qt::ISODate));
|
|
||||||
feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
|
feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
|
||||||
feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString());
|
feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString());
|
||||||
feed->setUrl(record.value(FDS_DB_URL_INDEX).toString());
|
feed->setUrl(record.value(FDS_DB_URL_INDEX).toString());
|
||||||
@ -206,7 +205,7 @@ void FeedsModelStandardFeed::update() {
|
|||||||
|
|
||||||
void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||||
int feed_id = id(), message_id;
|
int feed_id = id(), message_id;
|
||||||
QDateTime message_creation_date;
|
qint64 message_creation_date;
|
||||||
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelStandardFeed");
|
QSqlDatabase database = DatabaseFactory::getInstance()->addConnection("FeedsModelStandardFeed");
|
||||||
|
|
||||||
// Prepare queries.
|
// Prepare queries.
|
||||||
@ -252,7 +251,7 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
|||||||
if (query_select.next()) {
|
if (query_select.next()) {
|
||||||
// Message with this title & url probably exists in current feed.
|
// Message with this title & url probably exists in current feed.
|
||||||
message_id = query_select.value(0).toInt();
|
message_id = query_select.value(0).toInt();
|
||||||
message_creation_date = TextFactory::parseDateTime(query_select.value(2).toString());
|
message_creation_date = query_select.value(2).value<qint64>();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message_id = -1;
|
message_id = -1;
|
||||||
@ -266,15 +265,15 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
|||||||
query_insert.bindValue(":title", message.m_title);
|
query_insert.bindValue(":title", message.m_title);
|
||||||
query_insert.bindValue(":url", message.m_url);
|
query_insert.bindValue(":url", message.m_url);
|
||||||
query_insert.bindValue(":author", message.m_author);
|
query_insert.bindValue(":author", message.m_author);
|
||||||
query_insert.bindValue(":date_created", message.m_created.toString(Qt::ISODate));
|
query_insert.bindValue(":date_created", message.m_created.toMSecsSinceEpoch());
|
||||||
query_insert.bindValue(":contents", message.m_contents);
|
query_insert.bindValue(":contents", message.m_contents);
|
||||||
|
|
||||||
query_insert.exec();
|
query_insert.exec();
|
||||||
query_insert.finish();
|
query_insert.finish();
|
||||||
}
|
}
|
||||||
else if (message.m_createdFromFeed &&
|
else if (message.m_createdFromFeed &&
|
||||||
message_creation_date.isValid() &&
|
message_creation_date != 0 &&
|
||||||
message_creation_date > message.m_created) {
|
message_creation_date > message.m_created.toMSecsSinceEpoch()) {
|
||||||
qDebug("Message '%s' (id %d) was updated in the feed, updating too.",
|
qDebug("Message '%s' (id %d) was updated in the feed, updating too.",
|
||||||
qPrintable(message.m_title),
|
qPrintable(message.m_title),
|
||||||
message_id);
|
message_id);
|
||||||
@ -288,7 +287,7 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
|||||||
query_update.bindValue(":title", message.m_title);
|
query_update.bindValue(":title", message.m_title);
|
||||||
query_update.bindValue(":url", message.m_url);
|
query_update.bindValue(":url", message.m_url);
|
||||||
query_update.bindValue(":author", message.m_author);
|
query_update.bindValue(":author", message.m_author);
|
||||||
query_update.bindValue(":date_created", message.m_created.toString(Qt::ISODate));
|
query_update.bindValue(":date_created", message.m_created.toMSecsSinceEpoch());
|
||||||
query_update.bindValue(":contents", message.m_contents);
|
query_update.bindValue(":contents", message.m_contents);
|
||||||
query_update.bindValue(":id", message_id);
|
query_update.bindValue(":id", message_id);
|
||||||
|
|
||||||
|
@ -141,11 +141,8 @@ QVariant MessagesModel::data(const QModelIndex &index, int role) const {
|
|||||||
int index_column = index.column();
|
int index_column = index.column();
|
||||||
|
|
||||||
if (index_column == MSG_DB_DCREATED_INDEX) {
|
if (index_column == MSG_DB_DCREATED_INDEX) {
|
||||||
// This column contains QDateTime properly stored in ISO format.
|
return TextFactory::parseDateTime(QSqlTableModel::data(index,
|
||||||
// So that QDateTime::fromString(...) is okay here.
|
role).value<qint64>()).toLocalTime().toString(Qt::DefaultLocaleShortDate);
|
||||||
return QDateTime::fromString(QSqlTableModel::data(index,
|
|
||||||
role).toString(),
|
|
||||||
Qt::ISODate).toLocalTime().toString(Qt::DefaultLocaleShortDate);
|
|
||||||
}
|
}
|
||||||
else if (index_column == MSG_DB_AUTHOR_INDEX) {
|
else if (index_column == MSG_DB_AUTHOR_INDEX) {
|
||||||
QString author_name = QSqlTableModel::data(index, role).toString();
|
QString author_name = QSqlTableModel::data(index, role).toString();
|
||||||
|
@ -40,6 +40,20 @@ QDateTime TextFactory::parseDateTime(const QString &date_time) {
|
|||||||
return QDateTime();
|
return QDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDateTime TextFactory::parseDateTime(qint64 milis_from_epoch) {
|
||||||
|
QDateTime converted = QDateTime::fromMSecsSinceEpoch(milis_from_epoch);
|
||||||
|
|
||||||
|
// TODO: tadle funkce nahore fromMSec.. by mela vracet cas v UTC
|
||||||
|
// tedy timespec Qt::UTC, ale na windows vraci local time.
|
||||||
|
// overit co to vraci na linuxu a podle toho
|
||||||
|
// prenastavit zobrazovani datumu v messagesmodelu::data (delani
|
||||||
|
// nebo nedelani konverze .toLocalTime().
|
||||||
|
// mozna taky toString() udela konverzi za me.
|
||||||
|
// vsude je pouzito prozatim toLocalTime()
|
||||||
|
//converted.setTimeSpec(Qt::UTC);
|
||||||
|
return converted;
|
||||||
|
}
|
||||||
|
|
||||||
QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
QString TextFactory::shorten(const QString &input, int text_length_limit) {
|
||||||
if (input.size() > text_length_limit) {
|
if (input.size() > text_length_limit) {
|
||||||
return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH, '.');
|
return input.left(text_length_limit - ELLIPSIS_LENGTH) + QString(ELLIPSIS_LENGTH, '.');
|
||||||
|
@ -14,8 +14,14 @@ class TextFactory {
|
|||||||
public:
|
public:
|
||||||
// Tries to parse input textual date/time representation.
|
// Tries to parse input textual date/time representation.
|
||||||
// Returns invalid date/time if processing fails.
|
// Returns invalid date/time if processing fails.
|
||||||
|
// NOTE: This method tries to always return time in UTC+00:00.
|
||||||
static QDateTime parseDateTime(const QString &date_time);
|
static QDateTime parseDateTime(const QString &date_time);
|
||||||
|
|
||||||
|
// Converts 1970-epoch miliseconds to date/time.
|
||||||
|
// NOTE: This method returns date/time in UTC+00:00.
|
||||||
|
// NOTE: On Windows UTC is known to be broken.
|
||||||
|
static QDateTime parseDateTime(qint64 milis_from_epoch);
|
||||||
|
|
||||||
// Strips "<....>" (HTML, XML) tags from given text.
|
// Strips "<....>" (HTML, XML) tags from given text.
|
||||||
static QString stripTags(QString text);
|
static QString stripTags(QString text);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user