Commit e7ce33d5 authored by Martin Straka's avatar Martin Straka

Send log via email

parent a172bd97
......@@ -43,7 +43,8 @@ Item {
Component.onCompleted: {
var logTxt = files.loadLogContent(logFilePath)
logContent.text = "<b>" + qsTr("Log from current run:") + "</b><br/><br/>" + logTxt
logContent.text = qsTr("Log from current run:") + "\n\n" + logTxt
actionButton.enabled = (logContent.text !== "")
logFileLocation = files.getLocFileLocation()
}
......@@ -56,7 +57,8 @@ Item {
logContent.clear()
logFilePath = pathListModel.get(pathListModel.count-1).path
var logTxt = files.loadLogContent(logFilePath)
logContent.text = "<b>" + qsTr("Log file") + ": " + getFileNameFromPath(logFilePath) + "</b><br/><br/>" + logTxt
logContent.text = qsTr("Log file") + ": " + getFileNameFromPath(logFilePath) + "\n\n" + logTxt
actionButton.enabled = (logContent.text !== "")
}
}
}
......@@ -75,9 +77,7 @@ Item {
image.sourceSize.height: imgHeightHeader
image.source: "qrc:/ui/send-msg.svg"
accessibleName: qsTr("Send log to helpdesk")
onClicked: {
files.sendLogFileViaEmail(logFilePath)
}
onClicked: files.sendLogViaEmail(logContent.text)
}
}
Flickable {
......@@ -91,11 +91,10 @@ Item {
Pane {
id: flickContent
anchors.fill: parent
TextArea {
TextEdit {
id: logContent
color: datovkaPalette.text
anchors.fill: parent
textFormat: TextEdit.RichText
readOnly: true
wrapMode: Text.WordWrap
font.pointSize: textFontSizeSmall
......@@ -104,7 +103,6 @@ Item {
ScrollIndicator.vertical: ScrollIndicator {}
} // Flickable
Rectangle {
id: attachmentArea
anchors.top: flickable.bottom
anchors.bottom: parent.bottom
anchors.right: parent.right
......
......@@ -24,6 +24,7 @@
#include <QDesktopServices>
#include <QFileInfo>
#include <QQmlEngine>
#include <QSysInfo>
#include <QTextStream>
#include "ios/src/url_opener.h"
......@@ -175,7 +176,6 @@ QString Files::loadLogContent(const QString &filePath)
const QList<quint64> keys(mLog->keys());
foreach (quint64 key, keys) {
log.append(mLog->message(key));
log.append("<br/>");
}
} else {
......@@ -191,7 +191,6 @@ QString Files::loadLogContent(const QString &filePath)
while (!in.atEnd()) {
QString line = in.readLine();
log.append(line);
log.append("<br/>");
}
file.close();
}
......@@ -292,31 +291,37 @@ void Files::openAttachmentFromPath(const QString &filePath)
#endif
}
bool Files::sendLogFileViaEmail(const QString &filePath)
void Files::sendLogViaEmail(const QString &logContent)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
Q_ASSERT(0);
logErrorNL("Cannot open file '%s'.",
filePath.toUtf8().constData());
return false;
debugFuncCall();
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Send log via email"),
tr("Do you want to send the log information to developers?"),
QString(), Dialogues::NO | Dialogues::YES, Dialogues::NO);
if (msgResponse == Dialogues::NO) {
return;
}
QString subject = "Mobile Datovka: Log File";
QString body = "Mobile Datovka";
body.append("\nVersion: " + QStringLiteral(VERSION));
body.append("\nOS: " + QSysInfo::productType() + " " + QSysInfo::productVersion());
body.append("\nArch: " + QSysInfo::currentCpuArchitecture());
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
/* TODO */
QString log(file.readAll());
QString targetPath(appEmailDirPath("Log"));
QString filePath(writeFile(targetPath, "mobile-datovka.log",
base64ToRaw(logContent.toUtf8())));
QStringList attachmentList;
attachmentList.append(filePath);
QString subject = tr("Log file");
QString body = tr("Log file");
removeDirFromDocLoc(DATOVKA_MAIL_DIR_NAME);
const QString boundary = generateBoundaryString();
QString emailMessage = createEmailMessage(body, subject, boundary);
addAttachmentToEmailMessage(emailMessage, "mdatovka.log",
log.toUtf8().toBase64(), boundary);
addAttachmentToEmailMessage(emailMessage, "mobile-datovka.log",
logContent.toUtf8().toBase64(), boundary);
finishEmailMessage(emailMessage, boundary);
sendEmail(emailMessage, attachmentList, subject, body, 0);
return true;
}
void Files::sendMsgFilesWithEmail(const QString &userName, qint64 msgId,
......
......@@ -162,10 +162,10 @@ public:
/*!
* @brief Send log via email.
*
* @param[in] filePath Log file path (empty = send memory log).
* @param[in] logContent Log content to be sent.
*/
Q_INVOKABLE static
bool sendLogFileViaEmail(const QString &filePath);
void sendLogViaEmail(const QString &logContent);
/*!
* @brief Send message attachments or complete zfo message
......
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