Add menu to modify the name & topic of the room

fixes #235
This commit is contained in:
Konstantinos Sideris 2018-05-16 20:40:42 +03:00
parent fab413327c
commit 340c9ab9de
8 changed files with 341 additions and 78 deletions

View file

@ -9,91 +9,95 @@
namespace conf {
// Global settings.
static constexpr int fontSize = 14;
static constexpr int textInputFontSize = 14;
static constexpr int emojiSize = 14;
static constexpr int headerFontSize = 21;
static constexpr int typingNotificationFontSize = 11;
constexpr int fontSize = 14;
constexpr int textInputFontSize = 14;
constexpr int emojiSize = 14;
constexpr int headerFontSize = 21;
constexpr int typingNotificationFontSize = 11;
namespace popup {
static constexpr int font = fontSize;
static constexpr int avatar = 28;
constexpr int font = fontSize;
constexpr int avatar = 28;
}
namespace modals {
constexpr int errorFont = conf::fontSize - 2;
}
namespace receipts {
static constexpr int font = 12;
constexpr int font = 12;
}
namespace dialogs {
static constexpr int labelSize = 15;
constexpr int labelSize = 15;
}
namespace strings {
static const QString url_html = "<a href=\"\\1\">\\1</a>";
static const QRegExp url_regex(
const QString url_html = "<a href=\"\\1\">\\1</a>";
const QRegExp url_regex(
"((www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]\\)\\:])");
}
// Window geometry.
namespace window {
static constexpr int height = 600;
static constexpr int width = 1066;
constexpr int height = 600;
constexpr int width = 1066;
static constexpr int minHeight = height;
static constexpr int minWidth = 950;
constexpr int minHeight = height;
constexpr int minWidth = 950;
} // namespace window
namespace textInput {
static constexpr int height = 50;
constexpr int height = 50;
}
namespace sidebarActions {
static constexpr int height = textInput::height;
static constexpr int iconSize = 28;
constexpr int height = textInput::height;
constexpr int iconSize = 28;
}
// Button settings.
namespace btn {
static constexpr int fontSize = 20;
static constexpr int cornerRadius = 3;
constexpr int fontSize = 20;
constexpr int cornerRadius = 3;
} // namespace btn
// RoomList specific.
namespace roomlist {
namespace fonts {
static constexpr int heading = 13;
static constexpr int timestamp = heading;
static constexpr int badge = 10;
static constexpr int bubble = 20;
static constexpr int communityBubble = bubble - 4;
constexpr int heading = 13;
constexpr int timestamp = heading;
constexpr int badge = 10;
constexpr int bubble = 20;
constexpr int communityBubble = bubble - 4;
} // namespace fonts
} // namespace roomlist
namespace userInfoWidget {
namespace fonts {
static constexpr int displayName = 16;
static constexpr int userid = 14;
constexpr int displayName = 16;
constexpr int userid = 14;
} // namespace fonts
} // namespace userInfoWidget
namespace topRoomBar {
namespace fonts {
static constexpr int roomName = 15;
static constexpr int roomDescription = 14;
constexpr int roomName = 15;
constexpr int roomDescription = 14;
} // namespace fonts
} // namespace topRoomBar
namespace timeline {
static constexpr int msgAvatarTopMargin = 15;
static constexpr int msgTopMargin = 2;
static constexpr int msgLeftMargin = 14;
static constexpr int avatarSize = 36;
static constexpr int headerSpacing = 3;
static constexpr int headerLeftMargin = 15;
constexpr int msgAvatarTopMargin = 15;
constexpr int msgTopMargin = 2;
constexpr int msgLeftMargin = 14;
constexpr int avatarSize = 36;
constexpr int headerSpacing = 3;
constexpr int headerLeftMargin = 15;
namespace fonts {
static constexpr int timestamp = 13;
static constexpr int dateSeparator = conf::fontSize;
constexpr int timestamp = 13;
constexpr int dateSeparator = conf::fontSize;
} // namespace fonts
} // namespace timeline

View file

@ -18,10 +18,13 @@
#pragma once
#include <QFileInfo>
#include <QJsonDocument>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <mtx.hpp>
#include <mtx/errors.hpp>
class DownloadMediaProxy : public QObject
{
@ -33,6 +36,15 @@ signals:
void avatarDownloaded(const QImage &img);
};
class StateEventProxy : public QObject
{
Q_OBJECT
signals:
void stateEventSent();
void stateEventError(const QString &msg);
};
Q_DECLARE_METATYPE(mtx::responses::Sync)
/*
@ -48,6 +60,10 @@ public:
// Client API.
void initialSync() noexcept;
void sync() noexcept;
template<class EventBody, mtx::events::EventType EventT>
std::shared_ptr<StateEventProxy> sendStateEvent(const EventBody &body,
const QString &roomId,
const QString &stateKey = "");
void sendRoomMessage(mtx::events::MessageType ty,
int txnId,
const QString &roomid,
@ -221,3 +237,50 @@ init();
MatrixClient *
client();
}
template<class EventBody, mtx::events::EventType EventT>
std::shared_ptr<StateEventProxy>
MatrixClient::sendStateEvent(const EventBody &body, const QString &roomId, const QString &stateKey)
{
QUrl endpoint(server_);
endpoint.setPath(clientApiUrl_ + QString("/rooms/%1/state/%2/%3")
.arg(roomId)
.arg(QString::fromStdString(to_string(EventT)))
.arg(stateKey));
QNetworkRequest request(QString(endpoint.toEncoded()));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
setupAuth(request);
auto proxy = std::shared_ptr<StateEventProxy>(new StateEventProxy,
[](auto proxy) { proxy->deleteLater(); });
auto serializedBody = nlohmann::json(body).dump();
auto reply = put(request, QByteArray(serializedBody.data(), serializedBody.size()));
connect(reply, &QNetworkReply::finished, this, [reply, proxy]() {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
auto data = reply->readAll();
if (status == 0 || status >= 400) {
try {
mtx::errors::Error res = nlohmann::json::parse(data);
emit proxy->stateEventError(QString::fromStdString(res.error));
} catch (const std::exception &e) {
emit proxy->stateEventError(QString::fromStdString(e.what()));
}
return;
}
try {
mtx::responses::EventId res = nlohmann::json::parse(data);
emit proxy->stateEventSent();
} catch (const std::exception &e) {
emit proxy->stateEventError(QString::fromStdString(e.what()));
}
});
return proxy;
}

View file

@ -12,10 +12,38 @@ class QPixmap;
class QLayout;
class QLabel;
class QComboBox;
class TextField;
class QLabel;
template<class T>
class QSharedPointer;
class EditModal : public QWidget
{
Q_OBJECT
public:
EditModal(const QString &roomId, QWidget *parent = nullptr);
void setFields(const QString &roomName, const QString &roomTopic);
signals:
void nameChanged(const QString &roomName);
private:
QString roomId_;
QString initialName_;
QString initialTopic_;
QLabel *errorField_;
TextField *nameInput_;
TextField *topicInput_;
FlatButton *applyBtn_;
FlatButton *cancelBtn_;
};
class TopSection : public QWidget
{
Q_OBJECT
@ -25,6 +53,7 @@ class TopSection : public QWidget
public:
TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr);
QSize sizeHint() const override;
void setRoomName(const QString &name);
QColor textColor() const { return textColor_; }
void setTextColor(QColor &color) { textColor_ = color; }
@ -56,7 +85,7 @@ protected:
void paintEvent(QPaintEvent *event) override;
private slots:
void save_and_close();
void saveSettings();
private:
static constexpr int AvatarSize = 64;
@ -67,10 +96,14 @@ private:
FlatButton *saveBtn_;
FlatButton *cancelBtn_;
FlatButton *editFieldsBtn_;
RoomInfo info_;
QString room_id_;
QImage avatarImg_;
TopSection *topSection_;
QComboBox *accessCombo;
};