summary refs log tree commit diff
diff options
context:
space:
mode:
authorJedi18 <targetakhil@gmail.com>2021-02-13 19:08:52 +0530
committerJedi18 <targetakhil@gmail.com>2021-02-13 19:08:52 +0530
commitf3596aed554feb848b3f3d09239e5cacf2155024 (patch)
tree71baceb309d04d096233354764e2d1c1c2136fc4
parentadded changing of name through edit modal, removed old roomsettings (diff)
downloadnheko-f3596aed554feb848b3f3d09239e5cacf2155024.tar.xz
added room topic
-rw-r--r--resources/qml/RoomSettings.qml37
-rw-r--r--resources/qml/TopBar.qml2
-rw-r--r--src/ui/RoomSettings.cpp20
-rw-r--r--src/ui/RoomSettings.h32
4 files changed, 68 insertions, 23 deletions
diff --git a/resources/qml/RoomSettings.qml b/resources/qml/RoomSettings.qml
index eabe68f5..2f6f1866 100644
--- a/resources/qml/RoomSettings.qml
+++ b/resources/qml/RoomSettings.qml
@@ -12,8 +12,8 @@ ApplicationWindow {
 
 	x: MainWindow.x + (MainWindow.width / 2) - (width / 2)
     y: MainWindow.y + (MainWindow.height / 2) - (height / 2)
-    minimumWidth: 340
-    minimumHeight: 600
+    minimumWidth: 400
+    minimumHeight: 650
     palette: colors
     color: colors.window
     modality: Qt.WindowModal
@@ -24,9 +24,12 @@ ApplicationWindow {
     }
 
     ColumnLayout {
-        id: contentLayout
+        id: contentLayout1
 
-        anchors.fill: parent
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: parent.top
+        anchors.bottom: undefined
         anchors.margins: 10
         spacing: 10
 
@@ -101,6 +104,32 @@ ApplicationWindow {
             visible: roomSettings.canChangeNameAndTopic
             onClicked: roomSettings.openEditModal()
         }
+    }
+
+    ScrollView {
+        id: topicScroll
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: contentLayout1.bottom
+        anchors.bottom: undefined
+        anchors.margins: 10
+        height: 100
+
+        TextArea {
+            text: roomSettings.roomTopic
+            background: null
+        }
+    }
+
+    ColumnLayout {
+        id: contentLayout2
+
+        anchors.left: parent.left
+        anchors.right: parent.right
+        anchors.top: topicScroll.bottom
+        anchors.bottom: parent.bottom
+        anchors.margins: 10
+        spacing: 10
 
         MatrixText {
             text: "SETTINGS"
diff --git a/resources/qml/TopBar.qml b/resources/qml/TopBar.qml
index c64eddd4..967aa11e 100644
--- a/resources/qml/TopBar.qml
+++ b/resources/qml/TopBar.qml
@@ -15,7 +15,7 @@ Rectangle {
 
     MouseArea {
         anchors.fill: parent
-        onClicked: TimelineManager.openRoomSettings()
+        onClicked: TimelineManager.timeline.openRoomSettings()
     }
 
     GridLayout {
diff --git a/src/ui/RoomSettings.cpp b/src/ui/RoomSettings.cpp
index c7f388d4..d2b5a630 100644
--- a/src/ui/RoomSettings.cpp
+++ b/src/ui/RoomSettings.cpp
@@ -75,9 +75,10 @@ EditModal::EditModal(const QString &roomId, QWidget *parent)
 }
 
 void
-EditModal::topicEventSent()
+EditModal::topicEventSent(const QString &topic)
 {
         errorField_->hide();
+        emit topicChanged(topic);
         close();
 }
 
@@ -141,14 +142,14 @@ EditModal::applyClicked()
                 http::client()->send_state_event(
                   roomId_.toStdString(),
                   body,
-                  [proxy](const mtx::responses::EventId &, mtx::http::RequestErr err) {
+                  [proxy, newTopic](const mtx::responses::EventId &, mtx::http::RequestErr err) {
                           if (err) {
                                   emit proxy->error(
                                     QString::fromStdString(err->matrix_error.error));
                                   return;
                           }
 
-                          emit proxy->topicEventSent();
+                          emit proxy->topicEventSent(newTopic);
                   });
         }
 }
@@ -222,7 +223,13 @@ RoomSettings::RoomSettings(QString roomid, QObject *parent)
 QString
 RoomSettings::roomName() const
 {
-        return QString(info_.name.c_str());
+        return QString::fromStdString(info_.name);
+}
+
+QString
+RoomSettings::roomTopic() const
+{
+        return QString::fromStdString(info_.topic);
 }
 
 QString
@@ -382,6 +389,11 @@ RoomSettings::openEditModal()
                 info_.name = newName.toStdString();
                 emit roomNameChanged();
         });
+
+        connect(modal, &EditModal::topicChanged, this, [this](const QString &newTopic) {
+                info_.topic = newTopic.toStdString();
+                emit roomTopicChanged();
+        });
 }
 
 void
diff --git a/src/ui/RoomSettings.h b/src/ui/RoomSettings.h
index 0d0b13f6..25c6e588 100644
--- a/src/ui/RoomSettings.h
+++ b/src/ui/RoomSettings.h
@@ -20,7 +20,7 @@ class ThreadProxy : public QObject
 signals:
         void error(const QString &msg);
         void nameEventSent(const QString &);
-        void topicEventSent();
+        void topicEventSent(const QString &);
         void stopLoading();
 };
 
@@ -35,9 +35,10 @@ public:
 
 signals:
         void nameChanged(const QString &roomName);
+        void topicChanged(const QString &topic);
 
 private slots:
-        void topicEventSent();
+        void topicEventSent(const QString &topic);
         void nameEventSent(const QString &name);
         void error(const QString &msg);
 
@@ -60,25 +61,27 @@ private:
 class RoomSettings : public QObject
 {
         Q_OBJECT
-        Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
         Q_PROPERTY(QString roomId READ roomId CONSTANT)
         Q_PROPERTY(QString roomVersion READ roomVersion CONSTANT)
+        Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged)
+        Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged)
         Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY avatarUrlChanged)
         Q_PROPERTY(int memberCount READ memberCount CONSTANT)
         Q_PROPERTY(int notifications READ notifications NOTIFY notificationsChanged)
         Q_PROPERTY(int accessJoinRules READ accessJoinRules NOTIFY accessJoinRulesChanged)
         Q_PROPERTY(bool isLoading READ isLoading NOTIFY loadingChanged)
+        Q_PROPERTY(bool canChangeAvatar READ canChangeAvatar CONSTANT)
         Q_PROPERTY(bool canChangeJoinRules READ canChangeJoinRules CONSTANT)
         Q_PROPERTY(bool canChangeNameAndTopic READ canChangeNameAndTopic CONSTANT)
-        Q_PROPERTY(bool canChangeAvatar READ canChangeAvatar CONSTANT)
         Q_PROPERTY(bool isEncryptionEnabled READ isEncryptionEnabled NOTIFY encryptionChanged)
         Q_PROPERTY(bool respondsToKeyRequests READ respondsToKeyRequests NOTIFY keyRequestsChanged)
 
 public:
         RoomSettings(QString roomid, QObject *parent = nullptr);
 
-        QString roomName() const;
         QString roomId() const;
+        QString roomName() const;
+        QString roomTopic() const;
         QString roomVersion() const;
         QString roomAvatarUrl();
         int memberCount() const;
@@ -94,26 +97,27 @@ public:
         bool canChangeAvatar() const;
         bool isEncryptionEnabled() const;
 
-        Q_INVOKABLE void changeNotifications(int currentIndex);
-        Q_INVOKABLE void changeAccessRules(int index);
-        Q_INVOKABLE void changeKeyRequestsPreference(bool isOn);
         Q_INVOKABLE void enableEncryption();
         Q_INVOKABLE void updateAvatar();
         Q_INVOKABLE void openEditModal();
+        Q_INVOKABLE void changeAccessRules(int index);
+        Q_INVOKABLE void changeNotifications(int currentIndex);
+        Q_INVOKABLE void changeKeyRequestsPreference(bool isOn);
 
 signals:
+        void loadingChanged();
+        void roomNameChanged();
+        void roomTopicChanged();
+        void avatarUrlChanged();
+        void encryptionChanged();
+        void keyRequestsChanged();
         void notificationsChanged();
         void accessJoinRulesChanged();
-        void keyRequestsChanged();
-        void encryptionChanged();
-        void avatarUrlChanged();
-        void roomNameChanged();
-        void loadingChanged();
         void displayError(const QString &errorMessage);
 
 public slots:
-        void avatarChanged();
         void stopLoading();
+        void avatarChanged();
 
 private:
         void retrieveRoomInfo();