[network/ruqola] src/widgets/room: Add "add topic" feature

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a174ffd8a46cf524ea35811c7f568d89d2ca7ae0 by Laurent Montel.
Committed on 27/07/2026 at 18:33.
Pushed by mlaurent into branch 'master'.

Add "add topic" feature

M  +15   -3    src/widgets/room/roomheaderlabel.cpp
M  +6    -0    src/widgets/room/roomheaderlabel.h
M  +8    -0    src/widgets/room/roomheaderwidget.cpp
M  +1    -0    src/widgets/room/roomheaderwidget.h

https://invent.kde.org/network/ruqola/-/commit/a174ffd8a46cf524ea35811c7f568d89d2ca7ae0

diff --git a/src/widgets/room/roomheaderlabel.cpp b/src/widgets/room/roomheaderlabel.cpp
index 785dd61b89..abeb4a36ff 100644
--- a/src/widgets/room/roomheaderlabel.cpp
+++ b/src/widgets/room/roomheaderlabel.cpp
@@ -20,7 +20,7 @@ RoomHeaderLabel::RoomHeaderLabel(QWidget *parent)
     setVisible(false);
     connect(this, &QLabel::linkActivated, this, &RoomHeaderLabel::slotMoreInfo);
     connect(this, &QLabel::linkHovered, this, [this](const QString &url) {
-        if (url != "showlesstext"_L1 && url != "showmoretext"_L1) {
+        if (url != "showlesstext"_L1 && url != "showmoretext"_L1 && url != "add_topic"_L1) {
             setToolTip(url);
         }
     });
@@ -28,6 +28,12 @@ RoomHeaderLabel::RoomHeaderLabel(QWidget *parent)
 
 RoomHeaderLabel::~RoomHeaderLabel() = default;
 
+void RoomHeaderLabel::setIsOwner(bool isOwner)
+{
+    mIsOwner = isOwner;
+    updateHeaderText();
+}
+
 void RoomHeaderLabel::resizeEvent(QResizeEvent *ev)
 {
     QLabel::resizeEvent(ev);
@@ -59,6 +65,8 @@ void RoomHeaderLabel::slotMoreInfo(const QString &content)
     } else if (content == "showlesstext"_L1) {
         mExpandTopic = false;
         updateSqueezedText();
+    } else if (content == "add_topic"_L1) {
+        Q_EMIT configureTopic();
     } else {
         RuqolaUtils::self()->openUrl(QUrl(content));
     }
@@ -79,7 +87,7 @@ QString RoomHeaderLabel::rPixelSqueeze(const QString &text, int maxPixels) const
 
                 // On some MacOS system, maxWidth may return 0
                 if (em == 0) {
-                    for (QChar c : text) {
+                    for (const QChar c : text) {
                         em = qMax(em, fontMetrics().horizontalAdvance(c));
                     }
                 }
@@ -137,7 +145,11 @@ void RoomHeaderLabel::setRoomTopic(const QString &topic)
 void RoomHeaderLabel::updateHeaderText()
 {
     mFullText.clear();
-    if (!mTopic.isEmpty()) {
+    if (mTopic.isEmpty()) {
+        if (mIsOwner) {
+            mFullText = u"<a href=\"add_topic\">%1</a>"_s.arg(i18n("Add Topic"));
+        }
+    } else {
         mFullText = mTopic;
     }
     if (!mAnnouncement.isEmpty()) {
diff --git a/src/widgets/room/roomheaderlabel.h b/src/widgets/room/roomheaderlabel.h
index 05620fde66..53a8849633 100644
--- a/src/widgets/room/roomheaderlabel.h
+++ b/src/widgets/room/roomheaderlabel.h
@@ -19,9 +19,14 @@ public:
 
     [[nodiscard]] const QString &fullText() const;
 
+    void setIsOwner(bool isOwner);
+
 protected:
     void resizeEvent(QResizeEvent *ev) override;
 
+Q_SIGNALS:
+    void configureTopic();
+
 private:
     LIBRUQOLAWIDGETS_NO_EXPORT void slotMoreInfo(const QString &content);
     LIBRUQOLAWIDGETS_NO_EXPORT void updateSqueezedText();
@@ -32,4 +37,5 @@ private:
     QString mTopic;
     QString mAnnouncement;
     bool mExpandTopic = false;
+    bool mIsOwner = false;
 };
diff --git a/src/widgets/room/roomheaderwidget.cpp b/src/widgets/room/roomheaderwidget.cpp
index 03c93214bd..00aed262d0 100644
--- a/src/widgets/room/roomheaderwidget.cpp
+++ b/src/widgets/room/roomheaderwidget.cpp
@@ -245,6 +245,7 @@ RoomHeaderWidget::RoomHeaderWidget(QWidget *parent)
     connect(mTeamName, &TeamNameLabel::openTeam, this, &RoomHeaderWidget::openTeam);
 
     connect(mActionButtonsGenerator, &ActionButtonsGenerator::uiInteractionRequested, this, &RoomHeaderWidget::uiInteractionRequested);
+    connect(mRoomHeaderLabel, &RoomHeaderLabel::configureTopic, this, &RoomHeaderWidget::slotConfigureTopic);
 }
 
 RoomHeaderWidget::~RoomHeaderWidget()
@@ -324,6 +325,8 @@ void RoomHeaderWidget::setRoom(Room *room)
     } else {
         mRoomIcon->setPixmap({});
     }
+    const bool owner = mRoom->hasPermission(u"set-owner"_s);
+    mRoomHeaderLabel->setIsOwner(owner);
 }
 
 void RoomHeaderWidget::setCurrentRocketChatAccount(RocketChatAccount *account)
@@ -403,4 +406,9 @@ void RoomHeaderWidget::slotDisabledEncryption()
     }
 }
 
+void RoomHeaderWidget::slotConfigureTopic()
+{
+    Q_EMIT channelInfoRequested();
+}
+
 #include "moc_roomheaderwidget.cpp"
diff --git a/src/widgets/room/roomheaderwidget.h b/src/widgets/room/roomheaderwidget.h
index 29fe2a9b84..2f0dfa5b46 100644
--- a/src/widgets/room/roomheaderwidget.h
+++ b/src/widgets/room/roomheaderwidget.h
@@ -77,6 +77,7 @@ Q_SIGNALS:
     void uiInteractionRequested(const QJsonObject &obj);
 
 private:
+    LIBRUQOLAWIDGETS_NO_EXPORT void slotConfigureTopic();
     LIBRUQOLAWIDGETS_NO_EXPORT void slotDisabledEncryption();
     LIBRUQOLAWIDGETS_NO_EXPORT void slotActionButtonChanged();
     LIBRUQOLAWIDGETS_NO_EXPORT void slotOfflineModeChanged();
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.