Commit 60b25057 authored by Martin Straka's avatar Martin Straka

Added contact list

parent c880fbfd
......@@ -36,6 +36,7 @@ ListView {
property bool canSelectBoxes: false // enables selecting of entries
property bool canDeselectBoxes: false // enables deselecting of entries
property bool canRemoveBoxes: false // enables removing of entries
property bool isContact: false // true enables contact grid, false search grid
/* This signal should be captured to implement model interaction. */
signal boxDetail(string boxId)
......@@ -54,6 +55,7 @@ ListView {
anchors.margins: defaultMargin
GridLayout {
id: gridSearchDatabox
visible: !isContact
columns: 2
rows: 3
rowSpacing: defaultMargin * 0.6
......@@ -95,6 +97,30 @@ ListView {
text: rDbEffectiveOvm
}
} // GridLayout
GridLayout {
id: gridContaxtDatabox
visible: isContact
columns: 1
rows: 3
rowSpacing: defaultMargin * 0.6
columnSpacing: defaultMargin * 2
anchors.verticalCenter: parent.verticalCenter
Text {
id: r1c1c
text: rDbName
color: headerColor
font.bold: true
}
Text {
id: r2c1c
text: rDbAddress
}
Text {
id: r3c1c
font.pointSize: textFontSizeSmall
text: (rDbIc == "") ? "ID: " + rDbID : "ID: " + rDbID + " IČ: " + rDbIc
}
} // GridLayout
} // Item
MouseArea {
anchors.fill: parent
......
......@@ -62,6 +62,7 @@ ApplicationWindow {
property Component pageAboutApp: PageAboutApp {}
property Component pageAccountDetail: PageAccountDetail {}
property Component pageChangePassword: PageChangePassword {}
property Component pageContactList: PageContactList {}
property Component pageDataboxDetail: PageDataboxDetail {}
property Component pageDataboxSearch: PageDataboxSearch {}
property Component pageMenuAccount: PageMenuAccount {}
......
/*
* Copyright (C) 2014-2017 CZ.NIC
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.models 1.0
/*
* Roles are defined in DataboxListModel::roleNames() and are accessed directly
* via their names.
*/
Item {
id: pageContactList
/* These properties must be set by caller. */
property var pageView
property var statusBar
property string userName
// recipBoxModel (if not null) holds recipient list of send message page
property var recipBoxModel: null
Component.onCompleted: {
var currentBoxId = accounts.boxId(userName)
messages.fillContactList(foundBoxModel, userName, currentBoxId)
proxyDataboxModel.setSourceModel(foundBoxModel)
emptyList.visible = (databoxList.count === 0)
}
DataboxListModel {
id: foundBoxModel
Component.onCompleted: {
}
}
ListSortFilterProxyModel {
id: proxyDataboxModel
Component.onCompleted: {
setFilterRoles([DataboxListModel.ROLE_DB_NAME,
DataboxListModel.ROLE_DB_ADDRESS, DataboxListModel.ROLE_DB_ID])
}
}
PageHeader {
id: headerBar
title: qsTr("Contacts") + " (" + userName + ")"
Item {
anchors.left: parent.left
width: parent.width * 0.5
height: parent.height
MouseArea {
anchors.fill: parent
onClicked: {
statusBar.visible = false
pageView.pop(StackView.Immediate)
}
}
}
TextField {
id: filterPhraseText
placeholderText: qsTr("Set filter")
width: headerBar.width * 0.3
anchors.right: parent.right
anchors.rightMargin: defaultMargin
anchors.verticalCenter: parent.verticalCenter
font.pointSize: defaultTextFont.font.pointSize
inputMethodHints: Qt.ImhNoPredictiveText
/*
* Using explicit top, left, ... padding because plain padding
* does not centre the text properly.
*/
topPadding: 8.0
bottomPadding: 8.0
leftPadding: 8.0
rightPadding: 8.0
/* TODO - remove background if used materials */
background: Rectangle {
anchors.fill: parent
color: (filterPhraseText.text.length == 0) ? datovkaPalette.alternateBase :
(databoxList.count > 0) ? "#afffaf" : "#ffafaf"
border.color: filterPhraseText.activeFocus ? "#0066ff" :
"#bdbebf"
}
onTextChanged: {
proxyDataboxModel.setFilterRegExpStr(filterPhraseText.text)
}
}
} // PageHeader
Text {
id: emptyList
visible: false
color: datovkaPalette.text
anchors.centerIn: parent
wrapMode: Text.Wrap
text: qsTr("No databox found in contacts.")
}
DataboxList {
id: databoxList
anchors.top: headerBar.bottom
anchors.bottom: parent.bottom
clip: true
spacing: 1
opacity: 1
visible: true
width: parent.width
interactive: true
model: proxyDataboxModel
canDetailBoxes: recipBoxModel == null
canSelectBoxes: recipBoxModel != null
canDeselectBoxes: recipBoxModel != null
isContact: true
onBoxSelect: {
var boxEntry = foundBoxModel.entry(boxId)
statusBar.visible = false
if (recipBoxModel != null) {
foundBoxModel.selectEntry(boxEntry.dbID, true)
recipBoxModel.addEntry(boxEntry)
}
}
onBoxDeselect: {
statusBar.visible = false
if (recipBoxModel != null) {
foundBoxModel.selectEntry(boxId, false)
recipBoxModel.removeEntry(boxId)
}
}
} // DataboxList
} // Item
......@@ -278,6 +278,20 @@ Item {
Row {
spacing: formItemVerticalSpacing * 5
anchors.horizontalCenter: parent.horizontalCenter
Button {
id: addContact
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
text: qsTr("Contacts")
onClicked: {
pageView.push(pageContactList, {
"pageView": pageView,
"statusBar": statusBar,
"userName": userName,
"recipBoxModel": recipBoxModel
}, StackView.Immediate)
}
}
Button {
id: findDS
height: inputItemHeight
......
......@@ -113,6 +113,7 @@
<file>../qml/pages/PageAccountDetail.qml</file>
<file>../qml/pages/PageAccountList.qml</file>
<file>../qml/pages/PageChangePassword.qml</file>
<file>../qml/pages/PageContactList.qml</file>
<file>../qml/pages/PageDataboxDetail.qml</file>
<file>../qml/pages/PageDataboxSearch.qml</file>
<file>../qml/pages/PageMenuAccount.qml</file>
......
......@@ -40,6 +40,11 @@ Accounts::Accounts(QObject *parent)
{
}
QString Accounts::boxId(const QString &userName)
{
return globAccountDbPtr->dbId(userName);
}
bool Accounts::boxEffectiveOVM(const QString &userName)
{
return globAccountDbPtr->boxEffectiveOVM(userName);
......
......@@ -52,6 +52,15 @@ class Accounts : public QObject {
public:
Accounts(QObject *parent = Q_NULLPTR);
/*!
* @brief Get account data box ID from database.
*
* @param[in] userName User name identifying account.
* @return Databox id string.
*/
Q_INVOKABLE
QString boxId(const QString &userName);
/*!
* @brief Check whether data box has effective OVM.
*
......
......@@ -87,6 +87,7 @@ const struct QmlTypeEntry qmlPages[] = {
{ "PageAccountDetail", 1, 0 },
{ "PageAccountList", 1, 0 },
{ "PageChangePassword", 1, 0 },
{ "PageContactList", 1, 0 },
{ "PageDataboxDetail", 1, 0 },
{ "PageDataboxSearch", 1, 0 },
{ "PageMenuAccount", 1, 0 },
......
......@@ -32,6 +32,7 @@
#include "src/messages.h"
#include "src/settings.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
#include "src/models/messagemodel.h"
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/file_db_container.h"
......@@ -70,6 +71,31 @@ enum MessageDb::MessageType enumToDbRepr(enum Messages::MessageType msgType)
}
}
void Messages::fillContactList(const QVariant &dbModelVariant,
const QString &userName, const QString &dbId)
{
qDebug("%s()", __func__);
DataboxListModel *databoxModel =
DataboxListModel::fromVariant(dbModelVariant);
if (databoxModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access databox model.");
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
}
databoxModel->clearAll();
msgDb->getContactsFromDb(databoxModel, dbId);
}
void Messages::fillMessageList(const QVariant &msgModelVariant,
const QString &userName, enum MessageType msgType)
{
......
......@@ -49,6 +49,17 @@ public:
Messages(QObject *parent = Q_NULLPTR);
/*!
* @brief Load contacts from database and fill QML listview via model.
*
* @param[in,out] dbModelVariant QVariant holding databox model to be set.
* @param[in] userName User name identifying account.
* @param[in] dbId Account databox ID.
*/
Q_INVOKABLE static
void fillContactList(const QVariant &dbModelVariant,
const QString &userName, const QString &dbId);
/*!
* @brief Load messages from database and fill QML listview via model.
*
......
......@@ -181,6 +181,34 @@ bool MessageDb::deleteMsgFromDb(qint64 msgId)
return true;
}
void MessageDb::getContactsFromDb(DataboxListModel *dbModel, const QString &dbId)
{
if (dbModel == Q_NULLPTR) {
Q_ASSERT(0);
return;
}
QSqlQuery query(m_db);
QString queryStr = "SELECT "
"dbIDRecipient, dmRecipient, dmRecipientAddress FROM messages "
"WHERE (dmRecipientAddress IS NOT NULL) "
" UNION SELECT "
"dbIDSender, dmSender, dmSenderAddress FROM messages "
"WHERE (dmSenderAddress IS NOT NULL) "
"ORDER BY dmRecipient, dmSender DESC";
if (!query.prepare(queryStr)) {
qCritical() << "Cannot prepare SQL query:" <<
query.lastError().text().toUtf8().constData();
return;
}
if (query.exec() && query.isActive()) {
dbModel->setQuery(query, dbId, false);
}
}
int MessageDb::getDbSizeInBytes(void)
{
QFileInfo fi(m_db.databaseName());
......
......@@ -31,6 +31,7 @@
#include "src/common.h"
#include "src/io/sqlite/db.h"
#include "src/messages.h"
#include "src/models/databoxmodel.h"
#include "src/qml_interaction/message_envelope.h"
class MessageListModel; /* Forward declaration. */
......@@ -96,6 +97,14 @@ public:
*/
bool deleteMsgFromDb(qint64 msgId);
/*!
* @brief Get list of databoxes from db.
*
* @param[in,out] dbModel Databox model to append databox info.
* @param[in] dbId Account databox ID.
*/
void getContactsFromDb(DataboxListModel *dbModel, const QString &dbId);
/*!
* @brief Get count of new messages.
*
......
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