Commit 8914a2f5 authored by Martin Straka's avatar Martin Straka

Added message forwarding

parent 27fb11ac
......@@ -86,6 +86,12 @@ Component {
image: "qrc:/ui/reply.svg"
showNext: false
}
ListElement {
index: 5
name: qsTr("Forward")
image: "qrc:/ui/forward.svg"
showNext: false
}
ListElement {
index: 1
name: qsTr("Send attachments by email")
......@@ -184,7 +190,16 @@ Component {
"action": "reply"
}, StackView.Immediate)
}
}
} else if (index == 5) {
pageView.replace(pageSendMessage, {
"pageView": pageView,
"statusBar": statusBar,
"userName": userName,
"msgId": msgId,
"msgType": msgType,
"action": "forward"
}, StackView.Immediate)
}
}
}
}
......
......@@ -59,27 +59,41 @@ Item {
: "~" + (fileSize) + " B"
}
/* Add file from path to listview */
function addFileToAttachmentList(filePath, fileDbId, fileName, fileSize, fileIcon, isZfo) {
sendMsgAttachmentModel.append({"fileDbId": fileDbId, "name": fileName,
"path": filePath, "img": fileIcon, "size": fileSize, "zfo": isZfo});
/* Set mandate fields in QML */
function setMandate(msgEnvelope) {
dmLegalTitleLaw.text = msgEnvelope.dmLegalTitleLaw
dmLegalTitleYear.text = msgEnvelope.dmLegalTitleYear
dmLegalTitleSect.text = msgEnvelope.dmLegalTitleSect
dmLegalTitlePar.text = msgEnvelope.dmLegalTitlePar
dmLegalTitlePoint.text = msgEnvelope.dmLegalTitlePoint
}
/* Set reply message data and add recipient to model */
function setReplyData(userName, msgId) {
headerBar.title = qsTr("Reply message %1").arg(msgId) + " (" + userName + ")"
// get some message envelope data and add recipient to recipient model
var msgEnvelope = messages.getReplyMsgDataAndSetRecipient(userName, msgId, recipBoxModel)
var msgEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, recipBoxModel)
dmAnnotation.text = "Re: " + msgEnvelope.dmAnnotation
// swap sender ref and ident data to recipient (reply)
dmSenderRefNumber.text = msgEnvelope.dmRecipientRefNumber
dmSenderIdent.text = msgEnvelope.dmRecipientIdent
dmRecipientRefNumber.text = msgEnvelope.dmSenderRefNumber
dmRecipientIdent.text = msgEnvelope.dmSenderIdent
dmLegalTitleLaw.text = msgEnvelope.dmLegalTitleLaw
dmLegalTitleYear.text = msgEnvelope.dmLegalTitleYear
dmLegalTitleSect.text = msgEnvelope.dmLegalTitleSect
dmLegalTitlePar.text = msgEnvelope.dmLegalTitlePar
dmLegalTitlePoint.text = msgEnvelope.dmLegalTitlePoint
setMandate(msgEnvelope)
}
/* Set forward message data and files to attachment model*/
function setForwardData(userName, msgId) {
headerBar.title = qsTr("Forward message %1").arg(msgId) + " (" + userName + ")"
// get some message envelope data, recipient model must be null (no recipient)
var msgEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, null)
dmAnnotation.text = "Fwd: " + msgEnvelope.dmAnnotation
dmSenderRefNumber.text = msgEnvelope.dmSenderRefNumber
dmSenderIdent.text = msgEnvelope.dmSenderIdent
dmRecipientRefNumber.text = msgEnvelope.dmRecipientRefNumber
dmRecipientIdent.text = msgEnvelope.dmRecipientIdent
setMandate(msgEnvelope)
sendMsgAttachmentModel.setFromDb(userName, msgId)
}
Component.onCompleted: {
......@@ -87,6 +101,8 @@ Item {
headerBar.title = qsTr("Create message") + " (" + userName + ")"
} else if (action === "reply") {
setReplyData(userName, msgId)
} else if (action === "forward") {
setForwardData(userName, msgId)
}
actionButton.enabled = false
var boxEffectiveOVM = accounts.boxEffectiveOVM(userName)
......@@ -101,16 +117,16 @@ Item {
if (path != "") {
var isInFiletList = false
for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
if (sendMsgAttachmentModel.get(i).path === path) {
if (sendMsgAttachmentModel.filePathFromRow(i) === path) {
isInFiletList = true
break
}
}
if (!isInFiletList) {
var fileName = getFileNameFromPath(path)
addFileToAttachmentList(path, noFileId, fileName,
sendMsgAttachmentModel.appendFileFromPath(noFileId, fileName, path,
getFileSizeString(files.getAttachmentSizeInBytes(path)),
files.getAttachmentFileIcon(fileName), false)
files.getAttachmentFileIcon(fileName))
}
}
}
......@@ -124,7 +140,7 @@ Item {
}
/* Holds send message attachment list model */
ListModel {
FileListModel {
id: sendMsgAttachmentModel
Component.onCompleted: {
}
......@@ -179,11 +195,8 @@ Item {
Connections {
target: isds
onRunSendMessageSig: {
for (var j = 0; j < sendMsgAttachmentModel.rowCount(); j++) {
filePaths.push(sendMsgAttachmentModel.get(j).path)
}
isds.sendMessage(userName, dmAnnotation.text.toString(),
recipBoxModel, filePaths,
recipBoxModel, sendMsgAttachmentModel,
dmLegalTitleLaw.text.toString(), dmLegalTitleYear.text.toString(),
dmLegalTitleSect.text.toString(), dmLegalTitlePar.text.toString(),
dmLegalTitlePoint.text.toString(), dmToHands.text.toString(),
......@@ -372,16 +385,27 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
var filePath = sendMsgAttachmentModel.get(index).path
if (files.isZfoFile(getFileNameFromPath(filePath))) {
pageView.push(pageMessageDetail, {
// fileId is set and is valid, use files from database
if (rFileId != noFileId) {
if (files.isZfoFile(rFileName)) {
pageView.push(pageMessageDetail, {
"pageView": pageView,
"statusBar": statusBar,
"fromLocalDb": false,
"rawZfoContent": files.rawFileContent(filePath)
})
"rawZfoContent": files.getAttachmentDb(userName, msgId, rFileId)})
} else {
files.openAttachmentFromDb(userName, msgId, rFileId)
}
} else {
files.openAttachmentFromPath(filePath)
if (files.isZfoFile(getFileNameFromPath(rFilePath))) {
pageView.push(pageMessageDetail, {
"pageView": pageView,
"statusBar": statusBar,
"fromLocalDb": false,
"rawZfoContent": files.rawFileContent(rFilePath)})
} else {
files.openAttachmentFromPath(rFilePath)
}
}
}
}
......@@ -390,7 +414,7 @@ Item {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
sourceSize.height: listItemHeight * 0.8
source: img
source: rFileIcon
}
Item {
anchors.left: imageAttachment.right
......@@ -402,17 +426,17 @@ Item {
anchors.verticalCenter: parent.verticalCenter
spacing: defaultMargin
Text {
text: name
text: rFileName
color: datovkaPalette.text
font.bold: true
}
Text {
text: path
text: (rFilePath != "") ? rFilePath : qsTr("Local database")
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
}
Text {
text: size
text: rFileSize
color: datovkaPalette.mid
font.pointSize: textFontSizeSmall
}
......@@ -441,7 +465,7 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
sendMsgAttachmentModel.remove(index)
sendMsgAttachmentModel.removeItem(index)
}
}
} // Rectangle
......
......@@ -148,7 +148,7 @@ void setZfoFilesToModel(FileListModel &model,
foreach (const AttachmentData &file, fileList) {
model.appendFileEntry(FileListModel::Entry(-1, file.dmFileDescr(),
file._dmFileSize(), file._icon(), file.dmEncodedContent()));
file._dmFileSize(), file._icon(), file.dmEncodedContent(), QString()));
}
}
......
......@@ -144,7 +144,7 @@ QString Messages::getMessageDetail(const QString &userName,
return msgDb->getMessageDetailDataFromDb(msgId);
}
MsgEnvelope *Messages::getReplyMsgDataAndSetRecipient(
MsgEnvelope *Messages::getMsgEnvelopeDataAndSetRecipient(
const QString &userName, qint64 msgId, const QVariant &dbModelVariant)
{
qDebug("%s()", __func__);
......
......@@ -97,7 +97,7 @@ public:
* @return Pointer to message envelope data object.
*/
Q_INVOKABLE
MsgEnvelope *getReplyMsgDataAndSetRecipient(const QString &userName,
MsgEnvelope *getMsgEnvelopeDataAndSetRecipient(const QString &userName,
qint64 msgId, const QVariant &dbModelVariant);
/*!
......
......@@ -32,17 +32,20 @@ FileListModel::Entry::Entry(const Entry &fme)
m_dmFileDescr(fme.m_dmFileDescr),
m_dmFileSize(fme.m_dmFileSize),
m_icon(fme.m_icon),
m_fileContent(fme.m_fileContent)
m_fileContent(fme.m_fileContent),
m_filePath(fme.m_filePath)
{
}
FileListModel::Entry::Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon, const QString &fileContent)
const QString &dmFileSize, const QString &icon, const QString &fileContent,
const QString &filePath)
: m_fileId(fileId),
m_dmFileDescr(dmFileDescr),
m_dmFileSize(dmFileSize),
m_icon(icon),
m_fileContent(fileContent)
m_fileContent(fileContent),
m_filePath(filePath)
{
}
......@@ -91,6 +94,16 @@ void FileListModel::Entry::setFileContent(const QString &fileContent)
m_fileContent = fileContent;
}
QString FileListModel::Entry::filePath(void) const
{
return m_filePath;
}
void FileListModel::Entry::setFilePath(const QString &filePath)
{
m_filePath = filePath;
}
void FileListModel::declareQML(void)
{
qmlRegisterType<FileListModel>("cz.nic.mobileDatovka.models", 1, 0, "FileListModel");
......@@ -123,6 +136,7 @@ QHash<int, QByteArray> FileListModel::roleNames(void) const
roles[ROLE_FILE_SIZE] = "rFileSize";
roles[ROLE_FILE_ICON] = "rFileIcon";
roles[ROLE_FILE_DATA] = "rFileContent";
roles[ROLE_FILE_PATH] = "rFilePath";
}
return roles;
}
......@@ -151,6 +165,9 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
case ROLE_FILE_DATA:
return file.fileContent();
break;
case ROLE_FILE_PATH:
return file.filePath();
break;
default:
/* Do nothing. */
break;
......@@ -159,6 +176,26 @@ QVariant FileListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
QList<FileListModel::Entry> FileListModel::allEntries(void) const
{
QList<FileListModel::Entry> entries;
foreach (const FileListModel::Entry &file, m_files) {
entries.append(file);
}
return entries;
}
QString FileListModel::filePathFromRow(int row)
{
if ((row < 0) || (row >= m_files.size())) {
return QString();
}
return m_files[row].filePath();
}
Qt::ItemFlags FileListModel::flags(const QModelIndex &index) const
{
return QAbstractListModel::flags(index);
......@@ -178,7 +215,7 @@ void FileListModel::setQuery(QSqlQuery &query)
while (query.isActive() && query.isValid()) {
m_files.append(Entry(query.value(0).toInt(),
query.value(1).toString(), query.value(2).toString(),
query.value(3).toString(), QString()));
query.value(3).toString(), QString(), QString()));
query.next();
}
......@@ -189,9 +226,17 @@ void FileListModel::setQuery(QSqlQuery &query)
void FileListModel::appendFileEntry(const Entry &entry)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_files.append(entry);
endInsertRows();
}
void FileListModel::appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, const QString &fileSize, const QString &fileIcon)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_files.append(FileListModel::Entry(fileId, fileName, fileSize,
fileIcon, QString(), filePath));
endInsertRows();
}
......@@ -221,3 +266,14 @@ bool FileListModel::setFromDb(const QString &userName, const QString &msgIdStr)
return Files::setAttachmentModel(*this, userName, msgId);
}
void FileListModel::removeItem(int row)
{
if ((row < 0) || (row >= m_files.size())) {
return;
}
beginRemoveRows(QModelIndex(), row, row);
m_files.removeAt(row);
endRemoveRows();
}
......@@ -36,7 +36,7 @@ public:
Entry(const Entry &fme);
Entry(const int fileId, const QString &dmFileDescr,
const QString &dmFileSize, const QString &icon,
const QString &fileContent);
const QString &fileContent, const QString &filePath);
int fileId(void) const;
QString dmFileDescr(void) const;
......@@ -47,6 +47,8 @@ public:
void setIcon(const QString &icon);
QString fileContent(void) const;
void setFileContent(const QString &fileContent);
QString filePath(void) const;
void setFilePath(const QString &filePath);
private:
int m_fileId; /*!< File database file identifier. */
......@@ -54,6 +56,7 @@ public:
QString m_dmFileSize; /*!< File size. */
QString m_icon; /*!< File icon? */
QString m_fileContent; /*!< File content */
QString m_filePath; /*!< File path */
};
/*!
......@@ -64,7 +67,8 @@ public:
ROLE_FILE_NAME,
ROLE_FILE_SIZE,
ROLE_FILE_ICON,
ROLE_FILE_DATA
ROLE_FILE_DATA,
ROLE_FILE_PATH
};
/* Don't forget to declare various properties to the QML system. */
......@@ -117,6 +121,22 @@ public:
virtual
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
/*!
* @brief Return list of all entries.
*
* @return List of all entries.
*/
QList<FileListModel::Entry> allEntries(void) const;
/*!
* @brief Return file path from attachment model.
*
* @param[in] row Row specifying the item.
* @return File path string.
*/
Q_INVOKABLE
QString filePathFromRow(int row);
/*!
* @brief Returns item flags for given index.
*
......@@ -140,6 +160,20 @@ public:
*/
void appendFileEntry(const Entry &entry);
/*!
* @brief Appends file from path to model.
*
* @param[in] fileId File id.
* @param[in] fileName File name.
* @param[in] filePath File path.
* @param[in] fileSize File size.
* @param[in] fileIcon File icon.
*/
Q_INVOKABLE
void appendFileFromPath(int fileId, const QString &fileName,
const QString &filePath, const QString &fileSize,
const QString &fileIcon);
/*!
* @brief Clears the model.
*/
......@@ -173,6 +207,14 @@ public:
Q_INVOKABLE
bool setFromDb(const QString &userName, const QString &msgIdStr);
/*!
* @brief Remove file from attachment model.
*
* @param[in] row Row specifying the item.
*/
Q_INVOKABLE
void removeItem(int row);
private:
QList<Entry> m_files; /*!< List of attachment entries. */
};
......
......@@ -436,7 +436,7 @@ void IsdsWrapper::inputDialogReturnPassword(const QString &isdsAction,
void IsdsWrapper::sendMessage(const QString &userName,
const QString &dmAnnotation, const QVariant &dbModelVariant,
const QStringList &filePaths,
const QVariant &attachmentModelVariant,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
const QString &dmLegalTitleSect, const QString &dmLegalTitlePar,
const QString &dmLegalTitlePoint, const QString &dmToHands,
......@@ -466,6 +466,14 @@ void IsdsWrapper::sendMessage(const QString &userName,
return;
}
FileListModel *attachModel =
FileListModel::fromVariant(attachmentModelVariant);
if (attachModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access attachment model.");
return;
}
MsgEnvelope msg;
/* Fill message envelope */
msg.setDmAnnotation(dmAnnotation);
......@@ -483,18 +491,37 @@ void IsdsWrapper::sendMessage(const QString &userName,
msg.setDmPersonalDelivery(dmPersonalDelivery);
int totalAttachmentSizeKBs = 0;
FileDb *fDb = NULL;
fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == NULL) {
qDebug() << "ERROR: File database cannot open!" << userName;
return;
}
QList<AttachmentData> attachList;
/* Load file contents from storage (path) to file structure */
foreach (const QString &file, filePaths) {
/* Load file contents from storage or database to file structure */
foreach (const FileListModel::Entry &file, attachModel->allEntries()) {
AttachmentData attach;
QFileInfo fi(file);
attach.setDmFileDescr(fi.fileName());
totalAttachmentSizeKBs += fi.size() / 1024;
QFile fin(file);
if (!fin.open(QIODevice::ReadOnly)) {
continue;
attach.setDmFileDescr(file.dmFileDescr());
if (file.fileId() >= 0) {
// load file content from database
FileDb::FileData fileData = fDb->getFileContentFromDb(file.fileId());
attach.setDmEncodedContent(fileData.content);
totalAttachmentSizeKBs += fileData.content.length() / 1024;
} else {
// load file content from storage (path)
QFileInfo fi(file.filePath());
totalAttachmentSizeKBs += fi.size() / 1024;
QFile fin(file.filePath());
if (!fin.open(QIODevice::ReadOnly)) {
continue;
}
attach.setDmEncodedContent(fin.readAll().toBase64());
}
attach.setDmEncodedContent(fin.readAll().toBase64());
attach._setDmFileSize(getApproximatelyAttachmentFileSizeFromBase64(attach.dmEncodedContent().length()));
attach._setIcon(getAttachmentFileIconFromFileExtension(attach.dmFileDescr()));
attachList.append(attach);
......
......@@ -193,7 +193,7 @@ public:
Q_INVOKABLE
void sendMessage(const QString &userName,
const QString &dmAnnotation, const QVariant &dbModelVariant,
const QStringList &filePaths,
const QVariant &attachmentModelVariant,
const QString &dmLegalTitleLaw, const QString &dmLegalTitleYear,
const QString &dmLegalTitleSect, const QString &dmLegalTitlePar,
const QString &dmLegalTitlePoint, const QString &dmToHands,
......
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