Commit 1e2a7b3f authored by Karel Slaný's avatar Karel Slaný

Passing model with Messages::fillMessageList().

parent ca866946
......@@ -47,7 +47,7 @@ Component {
property int msgType
Component.onCompleted: {
messages.fillMessageList(userName, msgType)
messages.fillMessageList(messageListModel, userName, msgType)
if (messageList.count == 0) {
emptyList.visible = true
/* Don't use visible property as it hides the element. */
......
......@@ -85,23 +85,32 @@ enum MessageDb::MessageType enumToDbRepr(enum Messages::MessageType msgType)
/*
* Slot: Fill message list in QML.
*/
void Messages::fillMessageList(const QString &userName,
enum MessageType msgType)
void Messages::fillMessageList(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType)
/* ========================================================================= */
{
qDebug("%s()", __func__);
MessageDb *msgDb = NULL;
msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access message model.");
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == NULL) {
qDebug() << "ERROR: Message database cannot open!";
if (msgDb == Q_NULLPTR) {
qCritical() << "Cannot open message database.";
return;
}
globMessagesModel.clearAll();
messageModel->clearAll();
/* Translate into database enum type. */
msgDb->getMessageListDataFromDb(userName, enumToDbRepr(msgType));
msgDb->getMessageListDataFromDb(messageModel, userName,
enumToDbRepr(msgType));
}
......
......@@ -52,11 +52,14 @@ public:
/*!
* @brief Load messages from database and fill QML listview via model.
*
* @param[in,out] msgModelVariant QVariant holding message model
* to be set.
* @param[in] userName User name identifying account.
* @param[in] msgType Message orientation.
*/
Q_INVOKABLE void fillMessageList(const QString &userName,
enum MessageType msgType);
Q_INVOKABLE static
void fillMessageList(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType);
/*!
* @brief Returns HTML-formatted string containing message description.
......@@ -113,7 +116,7 @@ public:
* @param[in] msgTypes Sought message types.
* @return Number of messages in the search result.
*/
Q_INVOKABLE
Q_INVOKABLE static
int searchMsg(const QVariant &msgModelVariant, const QString &phrase,
MessageTypes msgTypes);
......
......@@ -570,9 +570,14 @@ short MessageDb::getMessageStatusFromDb(qint64 msgId, bool &hasFiles) const
return ret;
}
void MessageDb::getMessageListDataFromDb(const QString &userName,
enum MessageType messageType)
void MessageDb::getMessageListDataFromDb(MessageListModel *msgModel,
const QString &userName, enum MessageType messageType)
{
if (msgModel == Q_NULLPTR) {
Q_ASSERT(0);
return;
}
QSqlQuery query(m_db);
QString queryStr = "SELECT dmID, dmSender, dmRecipient, "
......@@ -587,7 +592,7 @@ void MessageDb::getMessageListDataFromDb(const QString &userName,
query.bindValue(":_dmMessageType", messageType);
if (query.exec() && query.isActive()) {
globMessagesModel.setQuery(userName, query, false);
msgModel->setQuery(userName, query, false);
}
}
......
......@@ -123,12 +123,12 @@ public:
/*!
* @brief Get list of messages from db - for QML.
*
* @param[in,out] msgModel Model to append data to.
* @param[in] userName Account user name.
* @param[in] messageType Received or sent.
* @return messageListModel for QML.
*/
void getMessageListDataFromDb(const QString &userName,
enum MessageType messageType);
void getMessageListDataFromDb(MessageListModel *msgModel,
const QString &userName, enum MessageType messageType);
/*!
* @brief Check if message exists in the database.
......
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