- Replace unknown file image by empty extension

- Display generic image file on image extension (if file doesn't exists)
- Fix file checking with empty path (avoid spamming errors logs)
- Image file checking based on extension if it doesn't exists.
- Fix empty texts space in messages.
This commit is contained in:
Julien Wadel 2023-05-04 15:19:39 +02:00
parent bdeff220cc
commit 48c6c5a355
11 changed files with 85 additions and 105 deletions

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -86,7 +86,7 @@
<file>assets/images/file_custom.svg</file>
<file>assets/images/file_sign.svg</file>
<file>assets/images/file_extension_custom.svg</file>
<file>assets/images/file_unknown_custom.svg</file>
<file>assets/images/file_image_custom.svg</file>
<file>assets/images/filter_custom.svg</file>
<file>assets/images/filter_params_custom.svg</file>
<file>assets/images/folder_custom.svg</file>

View file

@ -622,6 +622,7 @@ bool Utils::isMe(const std::shared_ptr<const linphone::Address>& address){
}
bool Utils::isAnimatedImage(const QString& path){
if(path.isEmpty()) return false;
QFileInfo info(path);
if( !info.exists())
return false;
@ -630,27 +631,32 @@ bool Utils::isAnimatedImage(const QString& path){
}
bool Utils::isImage(const QString& path){
if(path.isEmpty()) return false;
QFileInfo info(path);
if( !info.exists())
return false;
if( !info.exists()){
return QMimeDatabase().mimeTypeForFile(info, QMimeDatabase::MatchExtension).name().contains("image");
}
QImageReader reader(path);
return reader.imageCount() == 1;
}
bool Utils::isVideo(const QString& path){
if(path.isEmpty()) return false;
return QMimeDatabase().mimeTypeForFile(path).name().contains("video");
}
bool Utils::isPdf(const QString& path){
if(path.isEmpty()) return false;
return QMimeDatabase().mimeTypeForFile(path).name().contains("application/pdf");
}
bool Utils::isSupportedForDisplay(const QString& path){
if(path.isEmpty()) return false;
return !QMimeDatabase().mimeTypeForFile(path).name().contains("application");// "for pdf : "application/pdf". Note : Make an exception when supported.
}
bool Utils::canHaveThumbnail(const QString& path){
if(path.isEmpty()) return false;
return isImage(path) || isAnimatedImage(path) || isPdf(path) || isVideo(path);
}
@ -732,6 +738,7 @@ QString Utils::encodeEmojiToQmlRichFormat(const QString &body){
}
bool Utils::isOnlyEmojis(const QString& text){
if(text.isEmpty()) return false;
QVector<uint> utf32_string = text.toUcs4();
for (auto &code : utf32_string)
if( !Utils::codepointIsEmoji(code))
@ -794,8 +801,11 @@ QString Utils::encodeTextToQmlRichFormat(const QString& text, const QVariantMap&
}
if(images != "")
images = "<div>" + images +"</div>";
return images + "<p style=\"white-space:pre-wrap;\">" + encodeEmojiToQmlRichFormat(formattedText.join("")) + "</p>";
QString encodeEmojis = encodeEmojiToQmlRichFormat(formattedText.join(""));
if( encodeEmojis.isEmpty() && images.isEmpty())
return "";
else
return images + "<p style=\"white-space:pre-wrap;\">" + encodeEmojiToQmlRichFormat(formattedText.join("")) + "</p>";
}
QString Utils::getFileContent(const QString& filePath){

View file

@ -316,7 +316,7 @@ DialogPlus{
Icon{
id: fileIcon
anchors.centerIn: parent
icon: FileViewDialogStyle.extension.unknownIcon
icon: FileViewDialogStyle.extension.icon
iconSize: FileViewDialogStyle.extension.iconSize
}
}

View file

@ -103,7 +103,7 @@ QtObject {
property var foregroundDisabledColor : ColorsList.addImageColor(sectionName+'_'+name+'_fg_d', icon, 's_d_b_fg')
}
property QtObject extension: QtObject {
property string unknownIcon: 'file_unknown_custom'
property string icon: 'file_extension_custom'
property int iconSize: 60
}
}

View file

@ -23,17 +23,16 @@ TextEdit {
property ContentModel contentModel
property string lastTextSelected : ''
property font customFont : SettingsModel.textMessageFont
property int fitHeight: contentHeight
property int fitHeight: visible ? contentHeight : 0
property int fitWidth: implicitWidth
signal rightClicked()
property int removeWarningFromBindingLoop : implicitWidth // Just a dummy variable to remove meaningless binding loop on implicitWidth
height: fitHeight
width: parent && parent.width || 1
visible: contentModel
visible: contentModel && contentModel.text != ''
clip: false
textMargin: 0
readOnly: true

View file

@ -12,10 +12,8 @@ import Utils 1.0
Item {
id: mainItem
implicitHeight: message.height
//width: parent.width
Layout.fillWidth: true
//onWidthChanged: console.log(width)
property alias isHovering: message.isHovering
property alias isTopGrouped: message.isTopGrouped
@ -29,19 +27,11 @@ Item {
signal conferenceIcsCopied()
signal addContactClicked(string contactAddress)
signal viewContactClicked(string contactAddress)
implicitHeight: message.height
RowLayout{
/*
anchors {
left: parent.left
//leftMargin: ChatStyle.entry.metaWidth
right: parent.right
}
*/
//width: parent.width
anchors.fill: parent
//onWidthChanged: console.log(width)
spacing: 0
//spacing: ChatStyle.entry.message.extraContent.spacing
Message {
id: message
@ -53,97 +43,78 @@ Item {
onConferenceIcsCopied: mainItem.conferenceIcsCopied()
onAddContactClicked: mainItem.addContactClicked(contactAddress)
onViewContactClicked: mainItem.viewContactClicked(contactAddress)
/*
anchors {
left: parent.left
leftMargin: ChatStyle.entry.metaWidth
right: parent.right
}*/
backgroundColorModel: ChatStyle.entry.message.outgoing.backgroundColor
Layout.fillWidth: true
//Layout.fillHeight: true
Layout.leftMargin: 10
//onImplicitHeightChanged: Layout.preferredHeight= implicitHeight
Layout.minimumHeight: implicitHeight // Avoid bug where UI is not computed by Qt
Layout.preferredHeight: implicitHeight
//Layout.preferredWidth: parent.width
//width: parent.width
//Layout.minimumHeight: implicitHeight // Avoid bug where UI is not computed by Qt
//Layout.preferredHeight: implicitHeight
// Not a style. Workaround to avoid a 0 width.
// Arbitrary value.
Layout.minimumWidth: 1
//onWidthChanged: console.log(width)
}
/*
RowLayout {
anchors.fill: parent
anchors.leftMargin: ChatStyle.entry.message.extraContent.leftMargin
spacing: ChatStyle.entry.message.extraContent.spacing
*/
Component {
id: iconComponent
Item{
Icon {
id: iconId
readonly property var isError: Utils.includes([
LinphoneEnums.ChatMessageStateFileTransferError,
LinphoneEnums.ChatMessageStateNotDelivered,
], $chatEntry.state)
readonly property bool isUploaded: $chatEntry.state == LinphoneEnums.ChatMessageStateDelivered
readonly property bool isDelivered: $chatEntry.state == LinphoneEnums.ChatMessageStateDeliveredToUser
readonly property bool isRead: $chatEntry.state == LinphoneEnums.ChatMessageStateDisplayed
icon: iconId.isError
? 'chat_error'
: (iconId.isRead ? 'chat_read' : (iconId.isDelivered ? 'chat_delivered' : '' ) )
iconSize: ChatStyle.entry.message.outgoing.sendIconSize
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
id:retryAction
anchors.fill: parent
visible: iconId.isError || $chatEntry.state == LinphoneEnums.ChatMessageStateIdle
onClicked: $chatEntry.resendMessage()
}
TooltipArea {
id:tooltip
visible: text != ''
text: iconId.isError
? qsTr('messageError')
: (iconId.isRead ? qsTr('messageRead') : (iconId.isDelivered ? qsTr('messageDelivered') : ''))
hoveringCursor : retryAction.visible?Qt.PointingHandCursor:Qt.ArrowCursor
}
Component {
id: iconComponent
Item{
Icon {
id: iconId
readonly property var isError: Utils.includes([
LinphoneEnums.ChatMessageStateFileTransferError,
LinphoneEnums.ChatMessageStateNotDelivered,
], $chatEntry.state)
readonly property bool isUploaded: $chatEntry.state == LinphoneEnums.ChatMessageStateDelivered
readonly property bool isDelivered: $chatEntry.state == LinphoneEnums.ChatMessageStateDeliveredToUser
readonly property bool isRead: $chatEntry.state == LinphoneEnums.ChatMessageStateDisplayed
icon: iconId.isError
? 'chat_error'
: (iconId.isRead ? 'chat_read' : (iconId.isDelivered ? 'chat_delivered' : '' ) )
iconSize: ChatStyle.entry.message.outgoing.sendIconSize
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
id:retryAction
anchors.fill: parent
visible: iconId.isError || $chatEntry.state == LinphoneEnums.ChatMessageStateIdle
onClicked: $chatEntry.resendMessage()
}
TooltipArea {
id:tooltip
visible: text != ''
text: iconId.isError
? qsTr('messageError')
: (iconId.isRead ? qsTr('messageRead') : (iconId.isDelivered ? qsTr('messageDelivered') : ''))
hoveringCursor : retryAction.visible?Qt.PointingHandCursor:Qt.ArrowCursor
}
}
}
}
Component {
id: indicator
Component {
id: indicator
Item {
BusyIndicator {
anchors.centerIn: parent
height: ChatStyle.entry.message.outgoing.busyIndicatorSize
width: ChatStyle.entry.message.outgoing.busyIndicatorSize
}
Item {
BusyIndicator {
anchors.centerIn: parent
height: ChatStyle.entry.message.outgoing.busyIndicatorSize
width: ChatStyle.entry.message.outgoing.busyIndicatorSize
}
}
}
Loader {
Layout.preferredWidth: ChatStyle.entry.message.outgoing.areaSize
Layout.fillHeight: true
Loader {
//height: ChatStyle.entry.lineHeight
//anchors.bottom: parent.bottom
//Layout.alignment: Qt.AlignBottom | Qt.AlignHCenter
Layout.preferredWidth: ChatStyle.entry.message.outgoing.areaSize
Layout.fillHeight: true
//Layout.rightMargin: 10
sourceComponent: $chatEntry.state == LinphoneEnums.ChatMessageStateInProgress || $chatEntry.state == LinphoneEnums.ChatMessageStateFileTransferInProgress
? indicator
: iconComponent
}
//}
sourceComponent: $chatEntry.state == LinphoneEnums.ChatMessageStateInProgress || $chatEntry.state == LinphoneEnums.ChatMessageStateFileTransferInProgress
? indicator
: iconComponent
}
}
/*
Rectangle{

View file

@ -155,8 +155,9 @@ Item {
spacing: FileViewStyle.spacing
Icon{
id: fileIcon
property bool isImage: UtilsCpp.isImage(mainItem.name)
Layout.alignment: Qt.AlignCenter
icon: extensionText.text != '' ? FileViewStyle.extension.icon : FileViewStyle.extension.unknownIcon
icon: fileIcon.isImage ? FileViewStyle.extension.imageIcon : FileViewStyle.extension.icon
iconSize: FileViewStyle.extension.iconSize
Layout.fillHeight: true
Layout.fillWidth: true
@ -173,7 +174,7 @@ Item {
font.bold: true
font.pointSize: extensionMetrics.font.pointSize
clip: true
text: (mainItem.contentModel?Utils.getExtension(mainItem.name).toUpperCase():'')
text: (!fileIcon.isImage && mainItem.contentModel?Utils.getExtension(mainItem.name).toUpperCase():'')
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
TextMetrics{

View file

@ -220,7 +220,6 @@ QtObject {
property QtObject extension: QtObject {
property string icon: 'file_extension_custom'
property string unknownIcon: 'file_unknown_custom'
property int iconSize: 60
property int internalSize: 37
property int radius: 0

View file

@ -46,8 +46,8 @@ QtObject {
}
property QtObject extension: QtObject {
property string icon: 'file_extension_custom'
property string unknownIcon: 'file_unknown_custom'
property string icon: 'file_extension_custom'
property string imageIcon: 'file_image_custom'
property int iconSize: 60
property int internalSize: 37
property int radius: 0

View file

@ -57,7 +57,7 @@ QtObject {
property QtObject openImage: QtObject {
property int iconSize: buttons.size/2
property string name : 'openImage'
property string icon : 'file_unknown_custom'
property string icon : 'file_image_custom'
property color backgroundNormalColor : ColorsList.addImageColor(sectionName+'_'+name+'_bg_n', icon, 'ma_n_b_inv_bg').color
property color backgroundHoveredColor : ColorsList.addImageColor(sectionName+'_'+name+'_bg_h', icon, 'ma_h_b_inv_bg').color
property color backgroundPressedColor : ColorsList.addImageColor(sectionName+'_'+name+'_bg_p', icon, 'ma_p_b_inv_bg').color