Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libcommhistory] Add a recipient event model to fetch events from uns…
…aved numbers. Contributes to TJC#143264
- Loading branch information
Showing
12 changed files
with
486 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/****************************************************************************** | ||
** | ||
** This file is part of libcommhistory. | ||
** | ||
** Copyright (C) 2020 D. Caliste. | ||
** Contact: Damien Caliste <dcaliste@free.fr> | ||
** | ||
** This library is free software; you can redistribute it and/or modify it | ||
** under the terms of the GNU Lesser General Public License version 2.1 as | ||
** published by the Free Software Foundation. | ||
** | ||
** This library 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 Lesser General Public | ||
** License for more details. | ||
** | ||
** You should have received a copy of the GNU Lesser General Public License | ||
** along with this library; if not, write to the Free Software Foundation, Inc., | ||
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
** | ||
******************************************************************************/ | ||
|
||
#include "recipienteventmodel.h" | ||
|
||
#include "databaseio_p.h" | ||
#include "eventmodel_p.h" | ||
#include "recipienteventmodel_p.h" | ||
|
||
#include <QSqlQuery> | ||
|
||
namespace CommHistory { | ||
|
||
RecipientEventModelPrivate::RecipientEventModelPrivate(RecipientEventModel *model) | ||
: EventModelPrivate(model) | ||
{ | ||
} | ||
|
||
bool RecipientEventModelPrivate::acceptsEvent(const Event &event) const | ||
{ | ||
return m_recipients.intersects(event.recipients()); | ||
} | ||
|
||
void RecipientEventModelPrivate::fetchEvents() | ||
{ | ||
if (!m_recipients.isEmpty()) { | ||
// Get the events that match these addresses | ||
QStringList clauses; | ||
QVariantList values; | ||
for (RecipientList::const_iterator it = m_recipients.constBegin(); | ||
it != m_recipients.constEnd(); ++it) { | ||
if (it->localUid().isEmpty()) { | ||
clauses.append(QString("(remoteUid LIKE ? AND localUid LIKE '%1%%')").arg(RING_ACCOUNT)); | ||
values.append(QString("%%%1%%").arg(minimizePhoneNumber(it->remoteUid()))); | ||
} else { | ||
clauses.append("(remoteUid = ? AND localUid = ?)"); | ||
values.append(it->remoteUid()); | ||
values.append(it->localUid()); | ||
} | ||
} | ||
|
||
QString where("WHERE ( "); | ||
where.append(clauses.join(" OR ")); | ||
where.append(" ) ORDER BY Events.endTime DESC, Events.id DESC"); | ||
|
||
QSqlQuery query = prepareQuery(DatabaseIOPrivate::eventQueryBase() + where); | ||
|
||
foreach (const QVariant &value, values) | ||
query.addBindValue(value); | ||
|
||
executeQuery(query); | ||
} else { | ||
modelUpdatedSlot(true); | ||
} | ||
} | ||
|
||
RecipientEventModel::RecipientEventModel(QObject *parent) | ||
: EventModel(*new RecipientEventModelPrivate(this), parent) | ||
{ | ||
setResolveContacts(ResolveImmediately); | ||
} | ||
|
||
RecipientEventModel::RecipientEventModel(RecipientEventModelPrivate &dd, QObject *parent) | ||
: EventModel(dd, parent) | ||
{ | ||
setResolveContacts(ResolveImmediately); | ||
} | ||
|
||
RecipientEventModel::~RecipientEventModel() | ||
{ | ||
} | ||
|
||
bool RecipientEventModel::getEvents(const RecipientList &recipients) | ||
{ | ||
Q_D(RecipientEventModel); | ||
|
||
beginResetModel(); | ||
d->clearEvents(); | ||
d->isReady = false; | ||
endResetModel(); | ||
|
||
d->m_recipients = recipients; | ||
d->fetchEvents(); | ||
return true; | ||
} | ||
|
||
bool RecipientEventModel::getEvents(const Recipient &recipient) | ||
{ | ||
return getEvents(RecipientList() << recipient); | ||
} | ||
|
||
} // namespace CommHistory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/****************************************************************************** | ||
** | ||
** This file is part of libcommhistory. | ||
** | ||
** Copyright (C) 2020 D. Caliste | ||
** Contact: Damien Caliste <dcaliste@free.fr> | ||
** | ||
** This library is free software; you can redistribute it and/or modify it | ||
** under the terms of the GNU Lesser General Public License version 2.1 as | ||
** published by the Free Software Foundation. | ||
** | ||
** This library 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 Lesser General Public | ||
** License for more details. | ||
** | ||
** You should have received a copy of the GNU Lesser General Public License | ||
** along with this library; if not, write to the Free Software Foundation, Inc., | ||
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
** | ||
******************************************************************************/ | ||
|
||
#ifndef COMMHISTORY_RECIPIENT_EVENT_MODEL_H | ||
#define COMMHISTORY_RECIPIENT_EVENT_MODEL_H | ||
|
||
#include "libcommhistoryexport.h" | ||
#include "eventmodel.h" | ||
|
||
namespace CommHistory { | ||
|
||
class RecipientEventModelPrivate; | ||
|
||
/*! | ||
* \class RecipientEventModel | ||
* \brief Model representing events from one or several local / remote uids. | ||
*/ | ||
class LIBCOMMHISTORY_EXPORT RecipientEventModel : public EventModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
/*! | ||
* Model constructor. | ||
* | ||
* \param parent Parent object. | ||
*/ | ||
RecipientEventModel(QObject *parent = 0); | ||
|
||
/*! | ||
* Destructor. | ||
*/ | ||
~RecipientEventModel(); | ||
|
||
/*! | ||
* Populate model with events matching the recipient list. | ||
* It's not necessary that the recipients are contact resolved. | ||
* | ||
* \param recipients, local / remote uid pairs to be fetched. | ||
* | ||
* \return true if successful, otherwise false | ||
*/ | ||
bool getEvents(const RecipientList &recipients); | ||
/*! | ||
* Populate model with events matching the given recipient. | ||
* It's not necessary that the recipient is contact resolved. | ||
* | ||
* \param recipient, local / remote uid pairs to be fetched. | ||
* | ||
* \return true if successful, otherwise false | ||
*/ | ||
bool getEvents(const Recipient &recipient); | ||
|
||
protected: | ||
RecipientEventModel(RecipientEventModelPrivate &dd, QObject *parent = 0); | ||
|
||
private: | ||
Q_DECLARE_PRIVATE(RecipientEventModel) | ||
}; | ||
|
||
} // namespace CommHistory | ||
|
||
#endif // COMMHISTORY_RECIPIENT_EVENT_MODEL_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/****************************************************************************** | ||
** | ||
** This file is part of libcommhistory. | ||
** | ||
** Copyright (C) 2020 D. Caliste. | ||
** Contact: Damien Caliste <dcaliste@free.fr> | ||
** | ||
** This library is free software; you can redistribute it and/or modify it | ||
** under the terms of the GNU Lesser General Public License version 2.1 as | ||
** published by the Free Software Foundation. | ||
** | ||
** This library 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 Lesser General Public | ||
** License for more details. | ||
** | ||
** You should have received a copy of the GNU Lesser General Public License | ||
** along with this library; if not, write to the Free Software Foundation, Inc., | ||
** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
** | ||
******************************************************************************/ | ||
|
||
#ifndef COMMHISTORY_RECIPIENT_EVENT_MODEL_P_H | ||
#define COMMHISTORY_RECIPIENT_EVENT_MODEL_P_H | ||
|
||
#include "recipienteventmodel.h" | ||
#include "eventmodel_p.h" | ||
|
||
namespace CommHistory { | ||
|
||
class LIBCOMMHISTORY_EXPORT RecipientEventModelPrivate : public EventModelPrivate | ||
{ | ||
Q_OBJECT | ||
|
||
Q_DECLARE_PUBLIC(RecipientEventModel) | ||
|
||
public: | ||
RecipientEventModelPrivate(RecipientEventModel *model = 0); | ||
|
||
virtual bool acceptsEvent(const Event &event) const; | ||
void fetchEvents(); | ||
|
||
RecipientList m_recipients; | ||
}; | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.