diff --git a/matrix/controller.h b/matrix/controller.h index 5c0e7f3..d6e6389 100644 --- a/matrix/controller.h +++ b/matrix/controller.h @@ -19,61 +19,61 @@ class Controller : public QObject Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged) Q_PROPERTY(QByteArray token READ getToken WRITE setToken NOTIFY tokenChanged) -public: - explicit Controller(QObject *parent = nullptr); - ~Controller(); + public: + explicit Controller(QObject *parent = nullptr); + ~Controller(); - // All the Q_INVOKABLEs. - Q_INVOKABLE void login(QString, QString, QString); - Q_INVOKABLE void logout(); + // All the Q_INVOKABLEs. + Q_INVOKABLE void login(QString, QString, QString); + Q_INVOKABLE void logout(); - // All the non-Q_INVOKABLE functions. + // All the non-Q_INVOKABLE functions. - // All the Q_PROPERTYs. - QMatrixClient::Connection* m_connection; - QMatrixClient::Connection* getConnection() { return m_connection; } - void setConnection(QMatrixClient::Connection* conn); + // All the Q_PROPERTYs. + QMatrixClient::Connection* m_connection; + QMatrixClient::Connection* getConnection() { return m_connection; } + void setConnection(QMatrixClient::Connection* conn); - bool isLogin = false; - bool getIsLogin() { return isLogin; } - void setIsLogin(bool n) { - if(n != isLogin) { - isLogin = n; - emit isLoginChanged(); + bool isLogin = false; + bool getIsLogin() { return isLogin; } + void setIsLogin(bool n) { + if(n != isLogin) { + isLogin = n; + emit isLoginChanged(); + } } - } - QString userID; - QString getUserID() { return userID; } - void setUserID(QString n) { - if(n != userID) { - userID = n; - emit userIDChanged(); + QString userID; + QString getUserID() { return userID; } + void setUserID(QString n) { + if(n != userID) { + userID = n; + emit userIDChanged(); + } } - } - QByteArray token; - QByteArray getToken() { return token; } - void setToken(QByteArray n) { - if(n != token) { - token = n; - emit tokenChanged(); + QByteArray token; + QByteArray getToken() { return token; } + void setToken(QByteArray n) { + if(n != token) { + token = n; + emit tokenChanged(); + } } - } -private: - void connected(); - void resync(); - void reconnect(); + private: + void connected(); + void resync(); + void reconnect(); -signals: - void connectionChanged(); - void isLoginChanged(); - void userIDChanged(); - void tokenChanged(); - void homeServerChanged(); + signals: + void connectionChanged(); + void isLoginChanged(); + void userIDChanged(); + void tokenChanged(); + void homeServerChanged(); -public slots: + public slots: }; #endif // CONTROLLER_H diff --git a/matrix/imageprovider.cpp b/matrix/imageprovider.cpp index ee0b9c8..09a02bd 100644 --- a/matrix/imageprovider.cpp +++ b/matrix/imageprovider.cpp @@ -57,7 +57,7 @@ QImage ImageProvider::requestImage(const QString& id, condition.wait(&m_lock); } - if( pSize != nullptr ) + if(pSize != nullptr) *pSize = result.size(); return result; diff --git a/matrix/matriqueroom.cpp b/matrix/matriqueroom.cpp index d68c258..168f798 100644 --- a/matrix/matriqueroom.cpp +++ b/matrix/matriqueroom.cpp @@ -9,8 +9,8 @@ MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId, JoinState joinState) : Room(connection, roomId, joinState) { - connect( this, &MatriqueRoom::notificationCountChanged, this, &MatriqueRoom::countChanged ); - connect( this, &MatriqueRoom::highlightCountChanged, this, &MatriqueRoom::countChanged ); + connect(this, &MatriqueRoom::notificationCountChanged, this, &MatriqueRoom::countChanged); + connect(this, &MatriqueRoom::highlightCountChanged, this, &MatriqueRoom::countChanged); } const QString& MatriqueRoom::cachedInput() const @@ -58,7 +58,7 @@ void MatriqueRoom::saveViewport(int topIndex, int bottomIndex) void MatriqueRoom::countChanged() { - if( displayed() && !hasUnreadMessages() ) + if(displayed() && !hasUnreadMessages()) { resetNotificationCount(); resetHighlightCount(); diff --git a/matrix/messageeventmodel.cpp b/matrix/messageeventmodel.cpp index 62eeafb..48294e2 100644 --- a/matrix/messageeventmodel.cpp +++ b/matrix/messageeventmodel.cpp @@ -43,14 +43,14 @@ void MessageEventModel::changeRoom(MatriqueRoom* room) return; beginResetModel(); - if( m_currentRoom ) + if(m_currentRoom) { - m_currentRoom->disconnect( this ); + m_currentRoom->disconnect(this); qDebug() << "Disconnected from" << m_currentRoom->id(); } m_currentRoom = room; - if( room ) + if(room) { using namespace QMatrixClient; connect(m_currentRoom, &Room::aboutToAddNewMessages, this, @@ -156,14 +156,14 @@ QString MessageEventModel::makeDateString(MatriqueRoom::rev_iter_t baseIt) const int MessageEventModel::rowCount(const QModelIndex& parent) const { - if( !m_currentRoom || parent.isValid() ) + if(!m_currentRoom || parent.isValid()) return 0; return m_currentRoom->timelineSize(); } QVariant MessageEventModel::data(const QModelIndex& index, int role) const { - if( !m_currentRoom || + if(!m_currentRoom || index.row() < 0 || index.row() >= m_currentRoom->timelineSize()) return QVariant(); @@ -173,7 +173,7 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const QString senderName = m_currentRoom->roomMembername(event->senderId()); using namespace QMatrixClient; - if( role == Qt::DisplayRole ) + if(role == Qt::DisplayRole) { if (event->isRedacted()) { @@ -185,7 +185,7 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const .arg(event->redactedBecause()->reason()); } - if( event->type() == EventType::RoomMessage ) + if(event->type() == EventType::RoomMessage) { using namespace MessageEventContent; @@ -202,13 +202,13 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const } return m_currentRoom->prettyPrint(e->plainBody()); } - if( event->type() == EventType::RoomMember ) + if(event->type() == EventType::RoomMember) { auto* e = static_cast(event); // FIXME: Rewind to the name that was at the time of this event QString subjectName = m_currentRoom->roomMembername(e->userId()); // The below code assumes senderName output in AuthorRole - switch( e->membership() ) + switch(e->membership()) { case MembershipType::Invite: if (e->repeatsState()) @@ -269,43 +269,43 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const // return tr("made something unknown"); } } - if( event->type() == EventType::RoomAliases ) + if(event->type() == EventType::RoomAliases) { auto* e = static_cast(event); return tr("set aliases to: %1").arg(e->aliases().join(", ")); } - if( event->type() == EventType::RoomCanonicalAlias ) + if(event->type() == EventType::RoomCanonicalAlias) { auto* e = static_cast(event); return tr("set the room main alias to: %1").arg(e->alias()); } - if( event->type() == EventType::RoomName ) + if(event->type() == EventType::RoomName) { auto* e = static_cast(event); return tr("set the room name to: %1").arg(e->name()); } - if( event->type() == EventType::RoomTopic ) + if(event->type() == EventType::RoomTopic) { auto* e = static_cast(event); return tr("set the topic to: %1").arg(e->topic()); } - if( event->type() == EventType::RoomAvatar ) + if(event->type() == EventType::RoomAvatar) { return tr("changed the room avatar"); } - if( event->type() == EventType::RoomEncryption ) + if(event->type() == EventType::RoomEncryption) { return tr("activated End-to-End Encryption"); } return tr("Unknown Event"); } - if( role == Qt::ToolTipRole ) + if(role == Qt::ToolTipRole) { return event->originalJson(); } - if( role == EventTypeRole ) + if(role == EventTypeRole) { if (event->isStateEvent()) return "state"; @@ -332,20 +332,20 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const return "other"; } - if( role == TimeRole ) + if(role == TimeRole) return makeMessageTimestamp(eventIt); - if( role == SectionRole ) + if(role == SectionRole) return makeDateString(eventIt); // FIXME: move date rendering to QML - if( role == AboveSectionRole ) // FIXME: shouldn't be here, because #312 + if(role == AboveSectionRole) // FIXME: shouldn't be here, because #312 { auto aboveEventIt = eventIt + 1; if (aboveEventIt != m_currentRoom->timelineEdge()) return makeDateString(aboveEventIt); } - if( role == AuthorRole ) + if(role == AuthorRole) { auto userId = event->senderId(); // FIXME: This will go away after senderName is generated correctly @@ -383,7 +383,7 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const .arg(event->redactedBecause()->reason()); } - if( event->type() == EventType::RoomMessage ) + if(event->type() == EventType::RoomMessage) { using namespace MessageEventContent; @@ -401,13 +401,13 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const } } - if( role == HighlightRole ) + if(role == HighlightRole) return m_currentRoom->isEventHighlighted(event); - if( role == ReadMarkerRole ) + if(role == ReadMarkerRole) return event->id() == lastReadEventId; - if( role == SpecialMarksRole ) + if(role == SpecialMarksRole) { if (event->isStateEvent() && static_cast(event)->repeatsState()) @@ -415,10 +415,10 @@ QVariant MessageEventModel::data(const QModelIndex& index, int role) const return event->isRedacted() ? "redacted" : ""; } - if( role == EventIdRole ) + if(role == EventIdRole) return event->id(); - if( role == LongOperationRole ) + if(role == LongOperationRole) { if (event->type() == EventType::RoomMessage && static_cast(event)->hasFileContent()) diff --git a/matrix/messageeventmodel.h b/matrix/messageeventmodel.h index 07b1da3..c30acf5 100644 --- a/matrix/messageeventmodel.h +++ b/matrix/messageeventmodel.h @@ -7,13 +7,14 @@ class MessageEventModel: public QAbstractListModel { - Q_OBJECT - // The below property is marked constant because it only changes - // when the whole model is reset (so anything that depends on the model - // has to be re-calculated anyway). - // XXX: A better way would be to make [Room::]Timeline a list model - // itself, leaving only representation of the model to a client. - Q_PROPERTY(MatriqueRoom* room MEMBER m_currentRoom CONSTANT) + Q_OBJECT + // The below property is marked constant because it only changes + // when the whole model is reset (so anything that depends on the model + // has to be re-calculated anyway). + // XXX: A better way would be to make [Room::]Timeline a list model + // itself, leaving only representation of the model to a client. + Q_PROPERTY(MatriqueRoom* room MEMBER m_currentRoom CONSTANT) + public: enum EventRoles { EventTypeRole = Qt::UserRole + 1, diff --git a/matrix/roomlistmodel.h b/matrix/roomlistmodel.h index ec8cb3b..96b74c9 100644 --- a/matrix/roomlistmodel.h +++ b/matrix/roomlistmodel.h @@ -18,37 +18,37 @@ class RoomListModel : public QAbstractListModel Q_PROPERTY(QMatrixClient::Connection *connection READ getConnection WRITE setConnection NOTIFY connectionChanged) -public: - explicit RoomListModel(); - ~RoomListModel(); + public: + explicit RoomListModel(); + ~RoomListModel(); - enum RoomModelRoles { - NameRole, ValueRole, AvatarRole - }; + enum RoomModelRoles { + NameRole, ValueRole, AvatarRole + }; - QMatrixClient::Connection* m_connection; - QMatrixClient::Connection* getConnection() { return m_connection; } - void setConnection(QMatrixClient::Connection* conn); + QMatrixClient::Connection* m_connection; + QMatrixClient::Connection* getConnection() { return m_connection; } + void setConnection(QMatrixClient::Connection* conn); - QHash roleNames() const; + QHash roleNames() const; - Q_INVOKABLE QMatrixClient::Room* roomAt(int row); + Q_INVOKABLE QMatrixClient::Room* roomAt(int row); - QVariant data(const QModelIndex& index, int role) const override; - Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override; + QVariant data(const QModelIndex& index, int role) const override; + Q_INVOKABLE int rowCount(const QModelIndex& parent=QModelIndex()) const override; -signals: - void connectionChanged(); + signals: + void connectionChanged(); -public slots: + public slots: -private slots: - void namesChanged(QMatrixClient::Room* room); - void unreadMessagesChanged(QMatrixClient::Room* room); - void addRoom(QMatrixClient::Room* room); + private slots: + void namesChanged(QMatrixClient::Room* room); + void unreadMessagesChanged(QMatrixClient::Room* room); + void addRoom(QMatrixClient::Room* room); -private: - QList m_rooms; + private: + QList m_rooms; }; #endif // ROOMLISTMODEL_H