[network/ruqola] src/widgets/room: Fix duplicate code

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 4f362589260bb10850c4b647f1d9dcc1a92b987e by Laurent Montel.
Committed on 16/07/2026 at 22:26.
Pushed by mlaurent into branch 'master'.

Fix duplicate code

M  +10   -12   src/widgets/room/pendingattachmentclickablewidget.cpp
M  +2    -0    src/widgets/room/pendingattachmentclickablewidget.h

https://invent.kde.org/network/ruqola/-/commit/4f362589260bb10850c4b647f1d9dcc1a92b987e

diff --git a/src/widgets/room/pendingattachmentclickablewidget.cpp b/src/widgets/room/pendingattachmentclickablewidget.cpp
index 9d6f135268..6f8170fbb0 100644
--- a/src/widgets/room/pendingattachmentclickablewidget.cpp
+++ b/src/widgets/room/pendingattachmentclickablewidget.cpp
@@ -71,29 +71,27 @@ void PendingAttachmentClickableWidget::setPendingAttachmentInfo(const AccountRoo
     mPendingAttachmentInfo = pendingAttachment;
     const QMimeDatabase db;
     const QFileInfo info(mPendingAttachmentInfo.fileUrl.toLocalFile());
-    const QMimeType mimeType = db.mimeTypeForFile(info);
-    const QString mimeTypeIconName = mimeType.iconName();
-    const QString mimeTypeIconPath = KIconLoader::global()->iconPath(mimeTypeIconName, KIconLoader::Small);
-    mIconLabel->setPixmap(QPixmap(mimeTypeIconPath));
-    const QString elided = mNameLabel->fontMetrics().elidedText(mPendingAttachmentInfo.fileName, Qt::ElideMiddle, 120);
-    mNameLabel->setText(elided);
-    mNameLabel->setToolTip(mPendingAttachmentInfo.fileUrl.toString());
-    mSizeLabel->setText(KFormat().formatByteSize(info.size()));
+    updateInfo(info);
 }
 
 void PendingAttachmentClickableWidget::setUrl(const QUrl &url)
 {
-    const QMimeDatabase db;
     const QFileInfo info(url.toLocalFile());
-    const QMimeType mimeType = db.mimeTypeForFile(info);
-    const QString mimeTypeIconName = mimeType.iconName();
     mPendingAttachmentInfo.fileUrl = url;
     mPendingAttachmentInfo.fileName = info.fileName();
+    updateInfo(info);
+}
+
+void PendingAttachmentClickableWidget::updateInfo(const QFileInfo &info)
+{
+    const QMimeDatabase db;
+    const QMimeType mimeType = db.mimeTypeForFile(info);
+    const QString mimeTypeIconName = mimeType.iconName();
     const QString mimeTypeIconPath = KIconLoader::global()->iconPath(mimeTypeIconName, KIconLoader::MainToolbar);
     mIconLabel->setPixmap(QPixmap(mimeTypeIconPath));
     const QString elided = mNameLabel->fontMetrics().elidedText(mPendingAttachmentInfo.fileName, Qt::ElideMiddle, 120);
     mNameLabel->setText(elided);
-    mNameLabel->setToolTip(url.toString());
+    mNameLabel->setToolTip(mPendingAttachmentInfo.fileUrl.toString());
     mSizeLabel->setText(KFormat().formatByteSize(info.size()));
 }
 
diff --git a/src/widgets/room/pendingattachmentclickablewidget.h b/src/widgets/room/pendingattachmentclickablewidget.h
index 4ca48c946c..4e3cf112fd 100644
--- a/src/widgets/room/pendingattachmentclickablewidget.h
+++ b/src/widgets/room/pendingattachmentclickablewidget.h
@@ -10,6 +10,7 @@
 #include <QUrl>
 #include <QWidget>
 class QLabel;
+class QFileInfo;
 class LIBRUQOLAWIDGETS_TESTS_EXPORT PendingAttachmentClickableWidget : public QWidget
 {
     Q_OBJECT
@@ -28,6 +29,7 @@ private:
     LIBRUQOLAWIDGETS_NO_EXPORT void setPendingAttachmentInfo(const AccountRoomSettings::PendingAttachmentInfo &pendingAttachment);
     LIBRUQOLAWIDGETS_NO_EXPORT void setUrl(const QUrl &url);
     AccountRoomSettings::PendingAttachmentInfo mPendingAttachmentInfo;
+    LIBRUQOLAWIDGETS_NO_EXPORT void updateInfo(const QFileInfo &info);
     QLabel *const mIconLabel;
     QLabel *const mNameLabel;
     QLabel *const mSizeLabel;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.