Improve file attachments
-Don't show download and save in chatbar -Add a remove button -Add missing properties to model
This commit is contained in:
@@ -72,12 +72,12 @@ QQC2.Control {
|
|||||||
visible: NeoChatConfig.sendMessageWith === 1
|
visible: NeoChatConfig.sendMessageWith === 1
|
||||||
}
|
}
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 0
|
|
||||||
QQC2.ScrollView {
|
QQC2.ScrollView {
|
||||||
id: chatScrollView
|
id: chatScrollView
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.maximumHeight: Kirigami.Units.gridUnit * 8
|
Layout.maximumHeight: Kirigami.Units.gridUnit * 8
|
||||||
|
|
||||||
|
contentWidth: availableWidth
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ ColumnLayout {
|
|||||||
*/
|
*/
|
||||||
required property var fileTransferInfo
|
required property var fileTransferInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Whether the component should be editable.
|
||||||
|
*/
|
||||||
|
required property bool editable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Whether the media has been downloaded.
|
* @brief Whether the media has been downloaded.
|
||||||
*/
|
*/
|
||||||
@@ -66,6 +71,7 @@ ColumnLayout {
|
|||||||
spacing: Kirigami.Units.largeSpacing
|
spacing: Kirigami.Units.largeSpacing
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
Layout.fillWidth: true
|
||||||
spacing: Kirigami.Units.largeSpacing
|
spacing: Kirigami.Units.largeSpacing
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
@@ -137,6 +143,7 @@ ColumnLayout {
|
|||||||
|
|
||||||
QQC2.Button {
|
QQC2.Button {
|
||||||
id: openButton
|
id: openButton
|
||||||
|
visible: !root.editable
|
||||||
icon.name: "document-open"
|
icon.name: "document-open"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
root.autoOpenFile = true;
|
root.autoOpenFile = true;
|
||||||
@@ -150,6 +157,7 @@ ColumnLayout {
|
|||||||
|
|
||||||
QQC2.Button {
|
QQC2.Button {
|
||||||
id: downloadButton
|
id: downloadButton
|
||||||
|
visible: !root.editable
|
||||||
icon.name: "download"
|
icon.name: "download"
|
||||||
onClicked: root.saveFileAs()
|
onClicked: root.saveFileAs()
|
||||||
|
|
||||||
@@ -158,6 +166,18 @@ ColumnLayout {
|
|||||||
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QQC2.Button {
|
||||||
|
id: cancelButton
|
||||||
|
visible: root.editable
|
||||||
|
display: QQC2.AbstractButton.IconOnly
|
||||||
|
text: i18nc("@action:button", "Remove attachment")
|
||||||
|
icon.name: "dialog-close"
|
||||||
|
onClicked: root.Message.contentModel?.removeAttachment()
|
||||||
|
QQC2.ToolTip.text: text
|
||||||
|
QQC2.ToolTip.visible: hovered
|
||||||
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: fileDialog
|
id: fileDialog
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,10 @@ void ChatBarMessageContentModel::initializeFromCache()
|
|||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
|
if (currentCache->attachmentPath().length() > 0) {
|
||||||
|
addAttachment(QUrl(currentCache->attachmentPath()));
|
||||||
|
}
|
||||||
|
|
||||||
m_currentFocusComponent = QPersistentModelIndex(index(rowCount() - 1));
|
m_currentFocusComponent = QPersistentModelIndex(index(rowCount() - 1));
|
||||||
Q_EMIT focusRowChanged();
|
Q_EMIT focusRowChanged();
|
||||||
}
|
}
|
||||||
@@ -365,12 +369,16 @@ void ChatBarMessageContentModel::addAttachment(const QUrl &path)
|
|||||||
clearModel();
|
clearModel();
|
||||||
initializeModel(plainText);
|
initializeModel(plainText);
|
||||||
|
|
||||||
|
QFileInfo fileInfo(path.isLocalFile() ? path.toLocalFile() : path.toString());
|
||||||
|
auto mime = QMimeDatabase().mimeTypeForUrl(path);
|
||||||
auto it = insertComponent(m_components.first().type == MessageComponentType::Reply ? 1 : 0,
|
auto it = insertComponent(m_components.first().type == MessageComponentType::Reply ? 1 : 0,
|
||||||
MessageComponentType::typeForPath(path),
|
MessageComponentType::typeForPath(path),
|
||||||
{
|
{
|
||||||
{"filename"_L1, path.fileName()},
|
{"filename"_L1, path.fileName()},
|
||||||
{"source"_L1, path},
|
{"source"_L1, path},
|
||||||
{"animated"_L1, false},
|
{"animated"_L1, false},
|
||||||
|
{"mimeIcon"_L1, mime.name()},
|
||||||
|
{"size"_L1, fileInfo.size()},
|
||||||
});
|
});
|
||||||
it->display = path.fileName();
|
it->display = path.fileName();
|
||||||
Q_EMIT dataChanged(index(std::distance(m_components.begin(), it)), index(std::distance(m_components.begin(), it)), {DisplayRole});
|
Q_EMIT dataChanged(index(std::distance(m_components.begin(), it)), index(std::distance(m_components.begin(), it)), {DisplayRole});
|
||||||
@@ -662,6 +670,9 @@ std::optional<QString> ChatBarMessageContentModel::getReplyEventId()
|
|||||||
|
|
||||||
void ChatBarMessageContentModel::clearModel()
|
void ChatBarMessageContentModel::clearModel()
|
||||||
{
|
{
|
||||||
|
const auto hadAttachment =
|
||||||
|
hasComponentType({MessageComponentType::File, MessageComponentType::Audio, MessageComponentType::Image, MessageComponentType::Video});
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
for (const auto &component : m_components) {
|
for (const auto &component : m_components) {
|
||||||
if (const auto textItem = textItemForComponent(component)) {
|
if (const auto textItem = textItemForComponent(component)) {
|
||||||
@@ -671,6 +682,10 @@ void ChatBarMessageContentModel::clearModel()
|
|||||||
}
|
}
|
||||||
m_components.clear();
|
m_components.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
|
if (hadAttachment) {
|
||||||
|
Q_EMIT hasAttachmentChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_chatbarmessagecontentmodel.cpp"
|
#include "moc_chatbarmessagecontentmodel.cpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user