Skip to content

Commit

Permalink
Allow build with qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Oct 14, 2023
1 parent 8483917 commit 596f2b6
Show file tree
Hide file tree
Showing 41 changed files with 504 additions and 57 deletions.
2 changes: 1 addition & 1 deletion common-vars.pri
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#------------------------------------------------------------------------------
# Project name (used e.g. in include file and doc install path).
#------------------------------------------------------------------------------
PROJECT_NAME = libcommhistory-qt5
PROJECT_NAME = libcommhistory-qt$${QT_MAJOR_VERSION}

#------------------------------------------------------------------------------
# Project version
Expand Down
4 changes: 2 additions & 2 deletions declarative/declarative.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ CONFIG += qt plugin hide_symbols
QT += qml contacts dbus
QT -= gui

LIBS += -L../src ../src/libcommhistory-qt5.so
PKGCONFIG += qtcontacts-sqlite-qt5-extensions contactcache-qt5
LIBS += -L../src ../src/libcommhistory-qt$${QT_MAJOR_VERSION}.so
PKGCONFIG += qtcontacts-sqlite-qt$${QT_MAJOR_VERSION}-extensions contactcache-qt$${QT_MAJOR_VERSION}

target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
INSTALLS += target
Expand Down
1 change: 0 additions & 1 deletion declarative/src/mmshelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "mmsconstants.h"
#include "singleeventmodel.h"
#include <QtDBus>
#include <QTextCodec>
#include <QTemporaryDir>
#include <QMimeDatabase>
#include <QDebug>
Expand Down
5 changes: 5 additions & 0 deletions declarative/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ void CommHistoryPlugin::registerTypes(const char *uri)
qmlRegisterType<DraftEvent>(uri, 1, 0, "DraftEvent");
qmlRegisterType<MmsHelper>(uri, 1, 0, "MmsHelper");

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
qmlRegisterAnonymousType<CommHistory::GroupObject>(uri, 0);
qmlRegisterAnonymousType<CommHistory::ContactGroup>(uri, 0);
#else
qmlRegisterType<CommHistory::GroupObject>();
qmlRegisterType<CommHistory::ContactGroup>();
#endif
}
4 changes: 4 additions & 0 deletions src/callmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,11 @@ void CallModel::setFilterType(CallEvent::CallType type)
void CallModel::setFilterReferenceTime(const QDateTime &referenceTime)
{
Q_D(CallModel);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->referenceTime = referenceTime.isNull() ? 0 : referenceTime.toSecsSinceEpoch();
#else
d->referenceTime = referenceTime.isNull() ? 0 : referenceTime.toTime_t();
#endif
}

void CallModel::setFilterAccount(const QString &localUid)
Expand Down
12 changes: 12 additions & 0 deletions src/commhistory-qt6.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/$$PKGCONFIG_LIB/
includedir=${prefix}/include/commhistory-qt6/

Name: libcommhistory-qt6
Description: Messaging/Call-History Library
Version: $$PROJECT_VERSION
Libs: -L${libdir} -lcommhistory-qt6
Libs.private: -L/usr/lib
Cflags: -I${includedir}
Requires: contactcache-qt6 qtcontacts-sqlite-qt6-extensions
12 changes: 12 additions & 0 deletions src/contactgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,21 @@ QStringList ContactGroup::displayNames() const
QDateTime ContactGroup::startTime() const
{
Q_D(const ContactGroup);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
return QDateTime::fromSecsSinceEpoch(d->startTimeT);
#else
return QDateTime::fromTime_t(d->startTimeT);
#endif
}

QDateTime ContactGroup::endTime() const
{
Q_D(const ContactGroup);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
return QDateTime::fromSecsSinceEpoch(d->endTimeT);
#else
return QDateTime::fromTime_t(d->endTimeT);
#endif
}

int ContactGroup::unreadMessages() const
Expand Down Expand Up @@ -360,7 +368,11 @@ bool ContactGroup::lastEventIsDraft() const
QDateTime ContactGroup::lastModified() const
{
Q_D(const ContactGroup);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
return QDateTime::fromSecsSinceEpoch(d->lastModifiedT);
#else
return QDateTime::fromTime_t(d->lastModifiedT);
#endif
}

QString ContactGroup::subscriberIdentity() const
Expand Down
5 changes: 4 additions & 1 deletion src/conversationmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ bool ConversationModel::getEvents(int groupId)
bool ConversationModel::getEvents(QList<int> groupIds)
{
Q_D(ConversationModel);

#if (QT_VERSION > QT_VERSION_CHECK(5, 15, 0))
d->filterGroupIds = QSet<int>(groupIds.begin(), groupIds.end());
#else
d->filterGroupIds = QSet<int>::fromList(groupIds);
#endif
d->allGroups = false;

beginResetModel();
Expand Down
4 changes: 2 additions & 2 deletions src/databaseio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ bool DatabaseIO::modifyEvent(Event &event)
if (part.id() >= 0) {
if (!idList.isEmpty())
idList.append(',');
idList.append(QString::number(part.id()));
idList.append(QString::number(part.id()).toUtf8());
}
}

Expand Down Expand Up @@ -1059,7 +1059,7 @@ bool DatabaseIO::getGroups(const QString &localUid, const QString &remoteUid, QL
if (!remoteUid.isEmpty())
q += "Groups.remoteUids = :remoteUid ";
}
q += "GROUP BY Groups.id " + queryOrder;
q += QString("GROUP BY Groups.id " + queryOrder).toUtf8();

QSqlQuery query = CommHistoryDatabase::prepare(q.data(), d->connection());
if (!localUid.isEmpty())
Expand Down
8 changes: 8 additions & 0 deletions src/draftsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ QList<int> DraftsModel::filterGroups() const
void DraftsModel::setFilterGroups(const QList<int> &list)
{
Q_D(DraftsModel);
#if QT_VERSION > QT_VERSION_CHECK(5, 15, 0)
QSet<int> groupIds = QSet<int>(list.begin(), list.end());
#else
QSet<int> groupIds = list.toSet();
#endif
if (groupIds == d->filterGroups)
return;

Expand Down Expand Up @@ -89,7 +93,11 @@ bool DraftsModel::getEvents()

// As in ConversationModel, a UNION ALL is used to get better
// optimization out of sqlite
#if QT_VERSION > QT_VERSION_CHECK(5, 15, 0)
QList<int> groups = QList<int>(d->filterGroups.begin(), d->filterGroups.end());
#else
QList<int> groups = d->filterGroups.toList();
#endif
int unionCount = 0;
QString q;
do {
Expand Down
69 changes: 69 additions & 0 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,13 @@ QDataStream &operator>>(QDataStream &stream, CommHistory::Event &event)

event.setId(p.id);
event.setType(static_cast<Event::EventType>(type));
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
event.setStartTimeT(p.startTime.toSecsSinceEpoch());
event.setEndTimeT(p.endTime.toSecsSinceEpoch());
#else
event.setStartTimeT(p.startTime.toTime_t());
event.setEndTimeT(p.endTime.toTime_t());
#endif
event.setDirection(static_cast<Event::EventDirection>(direction));
event.setIsDraft(isDraft);
event.setIsRead(isRead);
Expand All @@ -285,7 +290,11 @@ QDataStream &operator>>(QDataStream &stream, CommHistory::Event &event)
event.setGroupId(p.groupId);
event.setMessageToken(p.messageToken);
event.setMmsId(p.mmsId);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
event.setLastModifiedT(p.lastModified.toSecsSinceEpoch());
#else
event.setLastModifiedT(p.lastModified.toTime_t());
#endif
event.setFromVCard(p.fromVCardFileName, p.fromVCardLabel);
event.setReportDelivery(reportDelivery);
event.setValidityPeriod(p.validityPeriod);
Expand Down Expand Up @@ -485,15 +494,23 @@ Event::EventCategory Event::category() const
QDateTime Event::startTime() const
{
if (d->startTime.isNull() && d->startTimeT != 0) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->startTime = QDateTime::fromSecsSinceEpoch(d->startTimeT);
#else
d->startTime = QDateTime::fromTime_t(d->startTimeT);
#endif
}
return d->startTime;
}

QDateTime Event::endTime() const
{
if (d->endTime.isNull() && d->endTimeT != 0) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->endTime = QDateTime::fromSecsSinceEpoch(d->endTimeT);
#else
d->endTime = QDateTime::fromTime_t(d->endTimeT);
#endif
}
return d->endTime;
}
Expand Down Expand Up @@ -620,7 +637,11 @@ QString Event::mmsId() const
QDateTime Event::lastModified() const
{
if (d->lastModified.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->lastModified = QDateTime::fromSecsSinceEpoch(d->lastModifiedT);
#else
d->lastModified = QDateTime::fromTime_t(d->lastModifiedT);
#endif
}
return d->lastModified;
}
Expand All @@ -637,17 +658,29 @@ QList<MessagePart> Event::messageParts() const

QStringList Event::toList() const
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return d->headers.value(MMS_TO_HEADER).split("\x1e", Qt::SkipEmptyParts);
#else
return d->headers.value(MMS_TO_HEADER).split("\x1e", QString::SkipEmptyParts);
#endif
}

QStringList Event::ccList() const
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return d->headers.value(MMS_CC_HEADER).split("\x1e", Qt::SkipEmptyParts);
#else
return d->headers.value(MMS_CC_HEADER).split("\x1e", QString::SkipEmptyParts);
#endif
}

QStringList Event::bccList() const
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return d->headers.value(MMS_BCC_HEADER).split("\x1e", Qt::SkipEmptyParts);
#else
return d->headers.value(MMS_BCC_HEADER).split("\x1e", QString::SkipEmptyParts);
#endif
}

Event::EventReadStatus Event::readStatus() const
Expand Down Expand Up @@ -755,21 +788,37 @@ void Event::setType(Event::EventType type)
void Event::setStartTime(const QDateTime &startTime)
{
if (d->startTime.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->startTimeT = startTime.toUTC().toSecsSinceEpoch();
#else
d->startTimeT = startTime.toUTC().toTime_t();
#endif
} else {
d->startTime = startTime.toUTC();
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->startTimeT = d->startTime.toSecsSinceEpoch();
#else
d->startTimeT = d->startTime.toTime_t();
#endif
}
d->propertyChanged(Event::StartTime);
}

void Event::setEndTime(const QDateTime &endTime)
{
if (d->endTime.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->endTimeT = endTime.toUTC().toSecsSinceEpoch();
#else
d->endTimeT = endTime.toUTC().toTime_t();
#endif
} else {
d->endTime = endTime.toUTC();
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->endTimeT = d->endTime.toSecsSinceEpoch();
#else
d->endTimeT = d->endTime.toTime_t();
#endif
}
d->propertyChanged(Event::EndTime);
}
Expand Down Expand Up @@ -876,10 +925,18 @@ void Event::setMmsId(const QString &mmsId)
void Event::setLastModified(const QDateTime &modified)
{
if (d->lastModified.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->lastModifiedT = modified.toUTC().toSecsSinceEpoch();
#else
d->lastModifiedT = modified.toUTC().toTime_t();
#endif
} else {
d->lastModified = modified.toUTC();
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->lastModifiedT = d->lastModified.toSecsSinceEpoch();
#else
d->lastModifiedT = d->lastModified.toTime_t();
#endif
}
d->propertyChanged(Event::LastModified);
}
Expand Down Expand Up @@ -1035,7 +1092,11 @@ void Event::setStartTimeT(quint32 startTime)
{
d->startTimeT = startTime;
if (!d->startTime.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->startTime = QDateTime::fromMSecsSinceEpoch(d->startTimeT);
#else
d->startTime = QDateTime::fromTime_t(d->startTimeT);
#endif
}
d->propertyChanged(Event::StartTime);
}
Expand All @@ -1044,7 +1105,11 @@ void Event::setEndTimeT(quint32 endTime)
{
d->endTimeT = endTime;
if (!d->endTime.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->endTime = QDateTime::fromMSecsSinceEpoch(d->endTimeT);
#else
d->endTime = QDateTime::fromTime_t(d->endTimeT);
#endif
}
d->propertyChanged(Event::EndTime);
}
Expand All @@ -1053,7 +1118,11 @@ void Event::setLastModifiedT(quint32 modified)
{
d->lastModifiedT = modified;
if (!d->lastModified.isNull()) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
d->lastModified = QDateTime::fromMSecsSinceEpoch(d->lastModifiedT);
#else
d->lastModified = QDateTime::fromTime_t(d->lastModifiedT);
#endif
}
d->propertyChanged(Event::LastModified);
}
Expand Down
5 changes: 4 additions & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,11 @@ class LIBCOMMHISTORY_EXPORT Event
* \param another event
*/
void copyValidProperties(const Event &other);

#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
static quint32 currentTime_t() { return QDateTime::currentDateTimeUtc().toSecsSinceEpoch(); }
#else
static quint32 currentTime_t() { return QDateTime::currentDateTimeUtc().toTime_t(); }
#endif

private:
QSharedDataPointer<EventPrivate> d;
Expand Down
8 changes: 8 additions & 0 deletions src/eventmodel_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,21 @@ void EventModelPrivate::recipientsUpdated(const QSet<Recipient> &recipients, boo

void EventModelPrivate::slotContactInfoChanged(const RecipientList &recipients)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
#else
QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
#endif
recipientsUpdated(changed);
}

void EventModelPrivate::slotContactChanged(const RecipientList &recipients)
{
#if QT_VERSION > QT_VERSION_CHECK(5, 15, 0)
QSet<Recipient> changed = QSet<Recipient>(recipients.recipients().begin(), recipients.recipients().end());
#else
QSet<Recipient> changed = QSet<Recipient>::fromList(recipients.recipients());
#endif
recipientsUpdated(changed, true);
}

Expand Down
1 change: 1 addition & 0 deletions src/eventmodel_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "eventmodel.h"
#include "event.h"
#include "group.h"
#include "eventtreeitem.h"
#include "databaseio.h"
#include "libcommhistoryexport.h"
Expand Down
Loading

0 comments on commit 596f2b6

Please sign in to comment.