From 80c2ed6dc93c527df0d05ec3b7d02838d4bbd908 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Mon, 30 Oct 2017 04:00:55 +0200 Subject: [PATCH 1/6] Initial implementation of Communities (groups) feature --- CMakeLists.txt | 6 + include/ChatPage.h | 10 ++ include/CommunitiesList.h | 44 ++++++++ include/CommunitiesListItem.h | 83 ++++++++++++++ include/Community.h | 63 +++++++++++ include/MatrixClient.h | 8 ++ include/RoomInfoListItem.h | 1 + include/RoomList.h | 6 + include/ui/Theme.h | 1 + resources/icons/ui/world.png | Bin 0 -> 2863 bytes resources/icons/ui/world.svg | 98 +++++++++++++++++ resources/res.qrc | 11 +- src/ChatPage.cc | 53 +++++++++ src/CommunitiesList.cc | 143 ++++++++++++++++++++++++ src/CommunitiesListItem.cc | 200 ++++++++++++++++++++++++++++++++++ src/Community.cc | 45 ++++++++ src/MatrixClient.cc | 143 ++++++++++++++++++++++++ src/RoomInfoListItem.cc | 5 +- src/RoomList.cc | 52 ++++++++- 19 files changed, 964 insertions(+), 8 deletions(-) create mode 100644 include/CommunitiesList.h create mode 100644 include/CommunitiesListItem.h create mode 100644 include/Community.h create mode 100644 resources/icons/ui/world.png create mode 100644 resources/icons/ui/world.svg create mode 100644 src/CommunitiesList.cc create mode 100644 src/CommunitiesListItem.cc create mode 100644 src/Community.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index c15093ad..f34d2ce6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,9 @@ set(SRC_FILES src/AvatarProvider.cc src/Cache.cc src/ChatPage.cc + src/CommunitiesListItem.cc + src/CommunitiesList.cc + src/Community.cc src/Deserializable.cc src/EmojiCategory.cc src/EmojiItemDelegate.cc @@ -221,6 +224,9 @@ include_directories(${LMDB_INCLUDE_DIR}) qt5_wrap_cpp(MOC_HEADERS include/AvatarProvider.h include/ChatPage.h + include/CommunitiesListItem.h + include/CommunitiesList.h + include/Community.h include/EmojiCategory.h include/EmojiItemDelegate.h include/EmojiPanel.h diff --git a/include/ChatPage.h b/include/ChatPage.h index 416f7870..567ef551 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -72,6 +72,7 @@ private slots: void showUnreadMessageNotification(int count); void updateTopBarAvatar(const QString &roomid, const QPixmap &img); void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name); + void updateOwnCommunitiesInfo(const QList &own_communities); void setOwnAvatar(const QPixmap &img); void initialSyncCompleted(const SyncResponse &response); void syncCompleted(const SyncResponse &response); @@ -108,6 +109,8 @@ private: Splitter *splitter; QWidget *sideBar_; + QWidget *communitiesSideBar_; + QVBoxLayout *communitiesSideBarLayout_; QVBoxLayout *sideBarLayout_; QVBoxLayout *sideBarTopLayout_; QVBoxLayout *sideBarMainLayout_; @@ -119,7 +122,9 @@ private: QHBoxLayout *topBarLayout_; QVBoxLayout *mainContentLayout_; + CommunitiesList *communitiesList_; RoomList *room_list_; + TimelineViewManager *view_manager_; SideBarActions *sidebarActions_; @@ -132,13 +137,18 @@ private: QTimer *consensusTimer_; QString current_room_; + QString current_community_; + QMap room_avatars_; + QMap community_avatars_; UserInfoWidget *user_info_widget_; QMap state_manager_; QMap> settingsManager_; + QMap> communityManager_; + // Keeps track of the users currently typing on each room. QMap> typingUsers_; diff --git a/include/CommunitiesList.h b/include/CommunitiesList.h new file mode 100644 index 00000000..ffa3cfcf --- /dev/null +++ b/include/CommunitiesList.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include + +#include "MatrixClient.h" +#include "CommunitiesListItem.h" +#include "Community.h" +#include "ui/Theme.h" + +class CommunitiesList : public QWidget +{ + Q_OBJECT + +public: + CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); + ~CommunitiesList(); + + void setCommunities(const QMap> &communities); + void clear(); + + void addCommunity(QSharedPointer community, + const QString &community_id); + void removeCommunity(const QString &community_id); +signals: + void communityChanged(const QString &community_id); + +public slots: + void updateCommunityAvatar(const QString &community_id, + const QPixmap &img); + void highlightSelectedCommunity(const QString &community_id); + +private: + QVBoxLayout *topLayout_; + QVBoxLayout *contentsLayout_; + QWidget *scrollAreaContents_; + QScrollArea *scrollArea_; + + QMap> communities_; + + QSharedPointer client_; +}; diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h new file mode 100644 index 00000000..52b3e849 --- /dev/null +++ b/include/CommunitiesListItem.h @@ -0,0 +1,83 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "ui/Theme.h" +#include "Menu.h" +#include "Community.h" + +class CommunitiesListItem : public QWidget +{ + Q_OBJECT + +public: + CommunitiesListItem(QSharedPointer community, + QString community_id, + QWidget *parent = nullptr); + + ~CommunitiesListItem(); + + void setCommunity(QSharedPointer community); + + inline bool isPressed() const; + inline void setAvatar(const QImage &avatar_image); + +signals: + void clicked(const QString &community_id); + +public slots: + void setPressedState(bool state); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; + +private: + const int IconSize = 55; + + QSharedPointer community_; + QString communityId_; + QString communityName_; + QString communityShortDescription; + + QPixmap communityAvatar_; + + Menu *menu_; + bool isPressed_ = false; +}; + +inline bool +CommunitiesListItem::isPressed() const +{ + return isPressed_; +} + +inline void +CommunitiesListItem::setAvatar(const QImage &avatar_image) +{ + communityAvatar_ = QPixmap::fromImage( + avatar_image.scaled(IconSize, + IconSize, + Qt::IgnoreAspectRatio, + Qt::SmoothTransformation)); + update(); +} + +class WorldCommunityListItem : public CommunitiesListItem +{ + Q_OBJECT +public: + WorldCommunityListItem(QWidget *parent = nullptr); + ~WorldCommunityListItem(); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; +private: + const int IconSize = 55; +}; diff --git a/include/Community.h b/include/Community.h new file mode 100644 index 00000000..2dccbbc8 --- /dev/null +++ b/include/Community.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include +#include +#include + +class Community : public QObject +{ + Q_OBJECT + +public: + void parseProfile(const QJsonObject &profile); + void parseRooms(const QJsonObject &rooms); + + inline QUrl getAvatar() const; + inline QString getName() const; + inline QString getShortDescription() const; + inline QString getLongDescription() const; + inline const QList getRoomList() const; + +signals: + void roomsChanged(QList &rooms); + +private: + QUrl avatar_; + QString name_; + QString short_description_; + QString long_description_; + + QList rooms_; +}; + +inline QUrl +Community::getAvatar() const +{ + return avatar_; +} + +inline QString +Community::getName() const +{ + return name_; +} + +inline QString +Community::getShortDescription() const +{ + return short_description_; +} + +inline QString +Community::getLongDescription() const +{ + return long_description_; +} + + +inline const QList +Community::getRoomList() const +{ + return rooms_; +} diff --git a/include/MatrixClient.h b/include/MatrixClient.h index ef9e82e6..a10b1f7b 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -50,6 +50,9 @@ public: void versions() noexcept; void fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url); void fetchUserAvatar(const QString &userId, const QUrl &avatarUrl); + void fetchCommunityAvatar(const QString &communityId, const QUrl &avatarUrl); + void fetchCommunityProfile(const QString &communityId); + void fetchCommunityRooms(const QString &communityId); void fetchOwnAvatar(const QUrl &avatar_url); void downloadImage(const QString &event_id, const QUrl &url); void messages(const QString &room_id, const QString &from_token, int limit = 30) noexcept; @@ -65,6 +68,7 @@ public: public slots: void getOwnProfile() noexcept; + void getOwnCommunities() noexcept; void logout() noexcept; void setServer(const QString &server) @@ -90,11 +94,15 @@ signals: void roomAvatarRetrieved(const QString &roomid, const QPixmap &img); void userAvatarRetrieved(const QString &userId, const QImage &img); + void communityAvatarRetrieved(const QString &communityId, const QPixmap &img); + void communityProfileRetrieved(const QString &communityId, const QJsonObject &profile); + void communityRoomsRetrieved(const QString &communityId, const QJsonObject &rooms); void ownAvatarRetrieved(const QPixmap &img); void imageDownloaded(const QString &event_id, const QPixmap &img); // Returned profile data for the user's account. void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name); + void getOwnCommunitiesResponse(const QList &own_communities); void initialSyncCompleted(const SyncResponse &response); void initialSyncFailed(const QString &msg); void syncCompleted(const SyncResponse &response); diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index a137b37f..63a73a04 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -57,6 +57,7 @@ public: void setAvatar(const QImage &avatar_image); void setDescriptionMessage(const DescInfo &info); + inline QString roomId(); signals: void clicked(const QString &room_id); diff --git a/include/RoomList.h b/include/RoomList.h index df668ac6..9e58b64b 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -52,6 +52,8 @@ public: const RoomState &state, const QString &room_id); void removeRoom(const QString &room_id, bool reset); + void setFilterRooms(bool filterRooms); + void setRoomFilter(QList room_ids); signals: void roomChanged(const QString &room_id); @@ -83,6 +85,10 @@ private: QSharedPointer leaveRoomDialog_; QMap> rooms_; + QString selectedRoom_; + + bool filterRooms_ = false; + QList roomFilter_ = QList(); //which rooms to include in the room list QSharedPointer client_; }; diff --git a/include/ui/Theme.h b/include/ui/Theme.h index c6c39553..4d482fe3 100644 --- a/include/ui/Theme.h +++ b/include/ui/Theme.h @@ -15,6 +15,7 @@ enum class AvatarType namespace sidebar { static const int SmallSize = 60; static const int NormalSize = 300; +static const int CommunitiesSidebarSize = 64; } // Default font size. const int FontSize = 16; diff --git a/resources/icons/ui/world.png b/resources/icons/ui/world.png new file mode 100644 index 0000000000000000000000000000000000000000..d687d1413cc1c6345e6f8e9831541b90520eed14 GIT binary patch literal 2863 zcmai0`8yN}7anBBIz~kpOBq74jmxF3W$asIEwY3mqr}+8Waq{(vV>6*6ER#{$(o6& zQH^y-#y*tg5+m8O&FB6F-+A8myw5p5oFC3}o^wvxbz5^mJ_$Ym03c{-Vd8M23ICA? zc;c!0-n}PsD$K~ziRZ*(c#yc0m^Z}2H4Fey@cNG&QYmi(PmYKgZ;xX-l2W~ z3v!*E_^dH8}Lnv$ek@006!kOA~}sR1xcWbcUy?2qoUSV9jmc0nLAz5TrCM z!Q1@$`gxx6sxK}pxwkppe7_FzA=r<<20Hu_dX%QPEq+FxGs#4-Ih}}4=rJm{r+^ro z9(e@)%KPo@th&`+gMp)lXOo({8oR$(yRrWk*i7^>qZj+8ey{0;E%phBrFj2;XjwWo zi6}l91z0D_Q+$YLbf7wdPk8(I>Q+F&ggJ^erTF|2R}@g}vh&L6suu9zDR<5qpbIy< zq}YCuouH6lo}hYLLA}_%B1iLIjuwC(jj9CS26zEP^Bpu{kDV#TXW4@uRs1(y!{s04 zy5h-%>g`!-74)WKz$5-r#=Qh?iuSCB^zIIT&PnHZN8u%^?M>e6QZK@b;e+{lta`z- zjugD~u7vO(T(`1Q7dQFejh6M5L=hq+#{_IP6^F0uK=<^zB|1lQIzN<6;iVeD7r!oG z4BO4yKFKjS>LJsEz7%?*a`vy7y`Ncrie7It_l2p!(bpsM?x!YJ!}Dear+6|>Pg6Qi z4G7h-E9VNUHJ8>AseOX)XVd`FxFPhZu_uVslzIPBXoSHTp%)*@dLqnei#&yy$G``Q z;nNSg*709{_lj=?D0U#ijgKMdIok@Zqlm*M$*tcNvY3oqbKW-z?LOf%gk=4Qew9{e zFhtx3buV)2&1KMY!c}DaC-e~z>G|F{t5$c(sbDIheF)4E{HPT}3Z-l6{@D4`G!E0X z-7CyB=v;D5_lL{58fwrw%QWUlb-*b8D7f3cvo`(Eel`OaEjm~HOw5%06bO%jzCT*0 zr?`WuMS1#V01;4b% z-xhfNK}Z&c(?=E)g;48fG7tPup|sa0W@j`Lu!hhOE5!bN5c5{{s#5orEiWoy!)^OW z>)Q5L{6X#L^)TS{(xY{KA~!1IRt~W*(4etqd7P;F)6l*5#?`uLSw}nrQauQrjr+X4 znYaQeSRFbaOpmAQ90QGQO;5q>v;8L{rqEX{0t3PwbC#A=2wyfEh# z_#9D4u>CZ%1nQTCpc^v*-p#NzhFlRK@nY@l z8d?;ufW5CqwSiE{>Tb70jGju(TFKW#dE2adjm+bixrV47T;Z!wv{;%SPg#@mg}f0C zw;`{)Sy4U1`trsU4m&Jr3`G8CzWs`yq>wVUKsMLop`#1vW=eRHdWRJ8TK6QqE2PfC zEU_Rz<{C*ZK#C|5g(s1nPU;X8v9P@?0FyW`wUf7yyfc1f+L4iKLE;-;R#Fr3ivZNZ z^=K2(GL7I_U+cZn{PN|zzc0v*$@TfzVXG?rK{PmWI4;N>PP4|l5Q0H~cPc-A2!>QV z-i-lb!}7^&|Lg(+TM=7mYdI9dUtXhp`L62i=Ep4%*Tj`%QTapLE`#g9i7sb_jX{?d;$y}Eg=z%QaN0wWP?dE2}^Y73mxT#U+qAp0ID(Z-Ib!L3xyC7_5U5u74b zh)t&P;@ky(rvme_+&ZS|M+XTRr=z#vb^f6LaEyv`)W$Og`;!~{1d33RgDGZ4)PV1 z&5y={o}^r^+`2#?*O6&#h*2nWA*SZ$`wS9BIEszpP4~?@=JmvLMQbn5bStXZ#NlEv zI%o$MkeKYuAn7lXZ!9fL+hGMTofmF~cv@_zvi~m}xe(+AzJz7v&AAt5>bF-dpEZXz zz))f{7FAzQrmNA{H&q~t8t&fr@f|GN= zjrk0&V7lpWfV=f%EE5^;GQV1GdoCpd231ONwcURRQ7emw#TvaCF3s04+<(%AAKKL* zbD^po6r<5g&vCulQ&ap?}X5U6m%45 zL@cRqsDp&55dc@Y2MKA@W~%mERpjw6>$>LeVqC07&UzFbPC$(bHVWPsHz1Kpq5tGZ z%60~*tRZ}r_BYnO6v&+wZKvM}d*uHF=nKSvTwSDElB2YS72$F0NaCBtZ(Ol{n>vDx z!LzWq`O-~*UbN83nTfN6OdEeAd^ z(=(#iAs00oQ?wr=xH3>RrkfBp2fE+tF!dvRn z6WAUll=JgLx~@f^S8LHN*xGW}yQkYc&JFt{__L6B1)({n)j-qcl9uj|$l9`u7Tr28 z#1=NSgl6CJ)<=2GEKEvbBtu~P!|1_1{RN||W;>Am-Ds}0*T*^wDfOdrlep%>pWo+4 z4_G}B$+Q8YD^_pAlDC)bx%76NGOh9UzjG>xm`H|sgl+w~NbJ1^9?xyTc-b8e(!rTF z-50+r#7UcII~Jx$DxEowmQKvKQx5gw>v2!-h`2X4+pZ7NlX$FUQquWnX2xp_F&_9S zO+Q#Y6E6wx6go`Wqm~JIGvfRgUwnqhUBlc_JYWhe=vy7;V9bmPgR+%k?1{WUN+L{P+icVNq77Mg+~P26njm-Kw~|3rL8?*^gyKi7S8d pQG@gEnIqSj>H^gNj|w0gB-5zz_FM5~jg#jVU}3>rmUHSk3 literal 0 HcmV?d00001 diff --git a/resources/icons/ui/world.svg b/resources/icons/ui/world.svg new file mode 100644 index 00000000..c3acf162 --- /dev/null +++ b/resources/icons/ui/world.svg @@ -0,0 +1,98 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/resources/res.qrc b/resources/res.qrc index 55962275..a3ba1b98 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -24,6 +24,7 @@ icons/ui/angle-pointing-to-left@2x.png icons/ui/angle-arrow-down.png icons/ui/angle-arrow-down@2x.png + icons/ui/world.png icons/emoji-categories/people.png icons/emoji-categories/people@2x.png @@ -40,9 +41,7 @@ icons/emoji-categories/symbols.png icons/emoji-categories/symbols@2x.png icons/emoji-categories/flags.png - icons/emoji-categories/flags@2x.png - nheko.png @@ -62,13 +61,19 @@ nheko-32.png nheko-16.png - fonts/OpenSans/OpenSans-Regular.ttf fonts/OpenSans/OpenSans-Italic.ttf fonts/OpenSans/OpenSans-Bold.ttf fonts/OpenSans/OpenSans-Semibold.ttf +<<<<<<< HEAD +======= + fonts/OpenSans/OpenSans-SemiboldItalic.ttf + fonts/OpenSans/OpenSans-ExtraBold.ttf + fonts/OpenSans/OpenSans-ExtraBoldItalic.ttf +>>>>>>> 4e60338... Initial implementation of Communities (groups) feature fonts/EmojiOne/emojione-android.ttf + diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 5fefd767..12e9b82a 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -55,6 +55,17 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) topLayout_->setSpacing(0); topLayout_->setMargin(0); + communitiesSideBar_ = new QWidget(this); + communitiesSideBar_->setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + communitiesSideBarLayout_ = new QVBoxLayout(communitiesSideBar_); + communitiesSideBarLayout_->setSpacing(0); + communitiesSideBarLayout_->setMargin(0); + + communitiesList_ = new CommunitiesList(client, this); + communitiesSideBarLayout_->addWidget(communitiesList_); + //communitiesSideBarLayout_->addStretch(1); + topLayout_->addWidget(communitiesSideBar_); + auto splitter = new Splitter(this); splitter->setHandleWidth(0); @@ -241,6 +252,26 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) SIGNAL(getOwnProfileResponse(const QUrl &, const QString &)), this, SLOT(updateOwnProfileInfo(const QUrl &, const QString &))); + connect(client_.data(), + SIGNAL(getOwnCommunitiesResponse(QList)), + this, + SLOT(updateOwnCommunitiesInfo(QList))); + connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, + [=](QString communityId, QJsonObject profile) { + communityManager_[communityId]->parseProfile(profile); + }); + connect(client_.data(), &MatrixClient::communityRoomsRetrieved, this, + [=](QString communityId, QJsonObject rooms) { + communityManager_[communityId]->parseRooms(rooms); + + if (communityId == current_community_) { + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); + } + } + }); connect(client_.data(), SIGNAL(ownAvatarRetrieved(const QPixmap &)), this, @@ -270,6 +301,15 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) } }); + connect(communitiesList_, &CommunitiesList::communityChanged, this, [=](const QString &communityId) { + current_community_ = communityId; + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); + } + }); + AvatarProvider::init(client); } @@ -323,6 +363,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) client_->setServer(homeserver); client_->setAccessToken(token); client_->getOwnProfile(); + client_->getOwnCommunities(); cache_ = QSharedPointer(new Cache(userid)); @@ -445,6 +486,18 @@ ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_na client_->fetchOwnAvatar(avatar_url); } +void +ChatPage::updateOwnCommunitiesInfo(const QList &own_communities) +{ + for (int i = 0; i < own_communities.size(); i++) { + QSharedPointer community = QSharedPointer(new Community()); + + communityManager_[own_communities[i]] = community; + } + + communitiesList_->setCommunities(communityManager_); +} + void ChatPage::changeTopRoomInfo(const QString &room_id) { diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc new file mode 100644 index 00000000..739ad4d6 --- /dev/null +++ b/src/CommunitiesList.cc @@ -0,0 +1,143 @@ +#include "CommunitiesList.h" + +#include + +CommunitiesList::CommunitiesList(QSharedPointer client, QWidget *parent) + : QWidget(parent) + , client_(client) +{ + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(1); + setSizePolicy(sizePolicy); + + setStyleSheet("border-style: none;"); + + topLayout_ = new QVBoxLayout(this); + topLayout_->setSpacing(0); + topLayout_->setMargin(0); + + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + + scrollArea_ = new QScrollArea(this); + scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + scrollArea_->setWidgetResizable(true); + scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); + + scrollAreaContents_ = new QWidget(); + + contentsLayout_ = new QVBoxLayout(scrollAreaContents_); + contentsLayout_->setSpacing(0); + contentsLayout_->setMargin(0); + + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + contentsLayout_->addWidget(world_list_item); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, &WorldCommunityListItem::clicked, + this, &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->addStretch(1); + + scrollArea_->setWidget(scrollAreaContents_); + topLayout_->addWidget(scrollArea_); + + connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, + [=](QString communityId, QJsonObject profile) { + client_->fetchCommunityAvatar(communityId, QUrl(profile["avatar_url"].toString())); + }); + connect(client_.data(), + SIGNAL(communityAvatarRetrieved(const QString &, const QPixmap &)), + this, + SLOT(updateCommunityAvatar(const QString &,const QPixmap &))); +} + +CommunitiesList::~CommunitiesList() {} + +void +CommunitiesList::setCommunities(const QMap> &communities) +{ + communities_.clear(); + + //TODO: still not sure how to handle the "world" special-case + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, &WorldCommunityListItem::clicked, + this, &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->insertWidget(0, world_list_item); + + for (auto it = communities.constBegin(); it != communities.constEnd(); it++) { + const auto community_id = it.key(); + const auto community = it.value(); + + addCommunity(community, community_id); + + client_->fetchCommunityProfile(community_id); + client_->fetchCommunityRooms(community_id); + } + + world_list_item->setPressedState(true); + emit communityChanged("world"); +} + +void +CommunitiesList::clear() +{ + communities_.clear(); +} + +void +CommunitiesList::addCommunity(QSharedPointer community, const QString &community_id) +{ + CommunitiesListItem *list_item = new CommunitiesListItem(community, + community_id, + scrollArea_); + + communities_.insert(community_id, QSharedPointer(list_item)); + + client_->fetchCommunityAvatar(community_id, community->getAvatar()); + + contentsLayout_->insertWidget(contentsLayout_->count()-1, list_item); + + connect(list_item, &CommunitiesListItem::clicked, + this, &CommunitiesList::highlightSelectedCommunity); +} + +void +CommunitiesList::removeCommunity(const QString &community_id) +{ + communities_.remove(community_id); +} + +void +CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img) +{ + if (!communities_.contains(community_id)) { + qWarning() << "Avatar update on nonexistent community" << community_id; + return; + } + + communities_.value(community_id)->setAvatar(img.toImage()); + +} + +void +CommunitiesList::highlightSelectedCommunity(const QString &community_id) +{ + emit communityChanged(community_id); + + if (!communities_.contains(community_id)) { + qDebug() << "CommunitiesList: clicked unknown community"; + return; + } + + for (auto it = communities_.constBegin(); it != communities_.constEnd(); it++) { + if (it.key() != community_id) { + it.value()->setPressedState(false); + } else { + it.value()->setPressedState(true); + scrollArea_->ensureWidgetVisible( + qobject_cast(it.value().data())); + } + } +} diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc new file mode 100644 index 00000000..1a2c1d7c --- /dev/null +++ b/src/CommunitiesListItem.cc @@ -0,0 +1,200 @@ +#include "CommunitiesListItem.h" + +CommunitiesListItem::CommunitiesListItem(QSharedPointer community, + QString community_id, + QWidget *parent) + : QWidget(parent) + , community_(community) + , communityId_(community_id) +{ + //menu_ = new Menu(this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFixedHeight(ui::sidebar::CommunitiesSidebarSize); + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); +} + +CommunitiesListItem::~CommunitiesListItem() {} + +void +CommunitiesListItem::setCommunity(QSharedPointer community) +{ + community_ = community; +} + +void +CommunitiesListItem::setPressedState(bool state) +{ + if (isPressed_ != state) { + isPressed_ = state; + update(); + } +} + +void +CommunitiesListItem::mousePressEvent(QMouseEvent *event) { + if (event->buttons() == Qt::RightButton) { + QWidget::mousePressEvent(event); + return; + } + + emit clicked(communityId_); + + setPressedState(true); +} + +void +CommunitiesListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + + QPainter p(this); + p.setRenderHint(QPainter::TextAntialiasing); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.setRenderHint(QPainter::Antialiasing); + + if (isPressed_) + p.fillRect(rect(), QColor("#38A3D8")); + else if (underMouse()) + p.fillRect(rect(), QColor(200, 200, 200, 128)); + else + p.fillRect(rect(), QColor("#FFF")); + + QFont font; + font.setPixelSize(conf::fontSize); + + p.setPen(QColor("#333")); + + QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + + font.setBold(false); + p.setPen(Qt::NoPen); + + // We using the first letter of room's name. + if (communityAvatar_.isNull()) { + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor("#eee"); + + p.setPen(Qt::NoPen); + p.setBrush(brush); + + p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2); + + font.setPixelSize(conf::roomlist::fonts::bubble); + p.setFont(font); + p.setPen(QColor("#000")); + p.setBrush(Qt::NoBrush); + p.drawText( + avatarRegion.translated(0, -1), Qt::AlignCenter, QChar(community_->getName()[0])); + } else { + p.save(); + + QPainterPath path; + path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + p.setClipPath(path); + + p.drawPixmap(avatarRegion, communityAvatar_); + p.restore(); + } + + //TODO: Discord-style community ping counts? + /*if (unreadMsgCount_ > 0) { + QColor textColor("white"); + QColor backgroundColor("#38A3D8"); + + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor(backgroundColor); + + if (isPressed_) + brush.setColor(textColor); + + QFont unreadCountFont; + unreadCountFont.setPixelSize(conf::roomlist::fonts::badge); + unreadCountFont.setBold(true); + + p.setBrush(brush); + p.setPen(Qt::NoPen); + p.setFont(unreadCountFont); + + int diameter = 20; + + QRectF r( + width() - diameter - 5, height() - diameter - 5, diameter, diameter); + + p.setPen(Qt::NoPen); + p.drawEllipse(r); + + p.setPen(QPen(textColor)); + + if (isPressed_) + p.setPen(QPen(backgroundColor)); + + p.setBrush(Qt::NoBrush); + p.drawText( + r.translated(0, -0.5), Qt::AlignCenter, QString::number(unreadMsgCount_)); + }*/ +} + +void +CommunitiesListItem::contextMenuEvent(QContextMenuEvent *event) +{ + Q_UNUSED(event); + + //menu_->popup(event->globalPos()); +} + +WorldCommunityListItem::WorldCommunityListItem(QWidget *parent) + : CommunitiesListItem(QSharedPointer(), "", parent) +{ +} + +WorldCommunityListItem::~WorldCommunityListItem() {} + +void +WorldCommunityListItem::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() == Qt::RightButton) { + QWidget::mousePressEvent(event); + return; + } + + emit CommunitiesListItem::clicked("world"); + + setPressedState(true); +} + +void +WorldCommunityListItem::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + static QPixmap worldIcon(":/icons/icons/world.png"); + + QPainter p(this); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.setRenderHint(QPainter::Antialiasing); + + if (isPressed()) + p.fillRect(rect(), QColor("#38A3D8")); + else if (underMouse()) + p.fillRect(rect(), QColor(200, 200, 200, 128)); + else + p.fillRect(rect(), QColor("#FFF")); + + QBrush brush; + brush.setStyle(Qt::SolidPattern); + brush.setColor("#FFFFFF"); + + p.setPen(Qt::NoPen); + p.setBrush(brush); + + QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2); + QPainterPath path; + path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + p.setClipPath(path); + + p.drawPixmap(avatarRegion, worldIcon); +} diff --git a/src/Community.cc b/src/Community.cc new file mode 100644 index 00000000..79b4b45b --- /dev/null +++ b/src/Community.cc @@ -0,0 +1,45 @@ +#include "include/Community.h" + +#include +#include + +void +Community::parseProfile(const QJsonObject &profile) +{ + if (profile["name"].type() == QJsonValue::Type::String) { + name_ = profile["name"].toString(); + } else { + name_ = "Unnamed Community"; //TODO: what is correct here? + } + + if (profile["avatar_url"].type() == QJsonValue::Type::String) { + avatar_ = QUrl(profile["avatar_url"].toString()); + } else { + avatar_ = QUrl(); + } + + if (profile["short_description"].type() == QJsonValue::Type::String) { + short_description_ = profile["short_description"].toString(); + } else { + short_description_ = ""; + } + + if (profile["long_description"].type() == QJsonValue::Type::String) { + long_description_ = profile["long_description"].toString(); + } else { + long_description_ = ""; + } + +} + +void +Community::parseRooms(const QJsonObject &rooms) +{ + rooms_.clear(); + + for (auto i = 0; ideleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto data = reply->readAll(); + auto json = QJsonDocument::fromJson(data); + try { + QList response; + for (auto it = json["groups"].toArray().constBegin(); it != json["groups"].toArray().constEnd(); it++) { + response.append(it->toString()); + } + emit getOwnCommunitiesResponse(response); + } catch (DeserializationException &e) { + qWarning() << "Own communities:" << e.what(); + } + }); +} + void MatrixClient::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url) { @@ -509,6 +546,112 @@ MatrixClient::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url) }); } +void +MatrixClient::fetchCommunityAvatar(const QString &communityid, const QUrl &avatar_url) +{ + QList url_parts = avatar_url.toString().split("mxc://"); + + if (url_parts.size() != 2) { + qDebug() << "Invalid format for community avatar " << avatar_url.toString(); + return; + } + + QUrlQuery query; + query.addQueryItem("width", "512"); + query.addQueryItem("height", "512"); + query.addQueryItem("method", "crop"); + + QString media_url = + QString("%1/_matrix/media/r0/thumbnail/%2").arg(getHomeServer().toString(), url_parts[1]); + + QUrl endpoint(media_url); + endpoint.setQuery(query); + + QNetworkRequest avatar_request(endpoint); + + QNetworkReply *reply = get(avatar_request); + connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status == 0 || status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto img = reply->readAll(); + + if (img.size() == 0) + return; + + QPixmap pixmap; + pixmap.loadFromData(img); + + emit communityAvatarRetrieved(communityId, pixmap); + }); +} + +void +MatrixClient::fetchCommunityProfile(const QString &communityId) +{ + QUrlQuery query; + query.addQueryItem("access_token", token_); + + QUrl endpoint(server_); + endpoint.setPath(clientApiUrl_ + "/groups/" + communityId + "/profile"); + endpoint.setQuery(query); + + QNetworkRequest request(QString(endpoint.toEncoded())); + + QNetworkReply *reply = get(request); + connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto data = reply->readAll(); + const auto json = QJsonDocument::fromJson(data).object(); + + emit communityProfileRetrieved(communityId, json); + }); +} + +void +MatrixClient::fetchCommunityRooms(const QString &communityId) +{ + QUrlQuery query; + query.addQueryItem("access_token", token_); + + QUrl endpoint(server_); + endpoint.setPath(clientApiUrl_ + "/groups/" + communityId + "/rooms"); + endpoint.setQuery(query); + + QNetworkRequest request(QString(endpoint.toEncoded())); + + QNetworkReply *reply = get(request); + connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { + reply->deleteLater(); + + int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + + if (status >= 400) { + qWarning() << reply->errorString(); + return; + } + + auto data = reply->readAll(); + const auto json = QJsonDocument::fromJson(data).object(); + + emit communityRoomsRetrieved(communityId, json); + }); +} + void MatrixClient::fetchUserAvatar(const QString &userId, const QUrl &avatarUrl) { diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc index 857189b5..7692dce6 100644 --- a/src/RoomInfoListItem.cc +++ b/src/RoomInfoListItem.cc @@ -262,10 +262,7 @@ RoomInfoListItem::clearUnreadMessageCount() void RoomInfoListItem::setPressedState(bool state) { - if (!isPressed_ && state) { - isPressed_ = state; - update(); - } else if (isPressed_ && !state) { + if (isPressed_ != state) { isPressed_ = state; update(); } diff --git a/src/RoomList.cc b/src/RoomList.cc index c89e4e6e..2ddc1322 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -49,7 +49,7 @@ RoomList::RoomList(QSharedPointer client, QWidget *parent) scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); scrollArea_->setWidgetResizable(true); - scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); + scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); scrollAreaContents_ = new QWidget(); @@ -89,6 +89,8 @@ RoomList::addRoom(const QSharedPointer &settings, client_->fetchRoomAvatar(room_id, state.getAvatar()); contentsLayout_->insertWidget(0, room_item); + + setFilterRooms(filterRooms_); } void @@ -164,6 +166,8 @@ RoomList::setInitialRooms(const QMap> &set if (rooms_.isEmpty()) return; + setFilterRooms(filterRooms_); + auto first_room = rooms_.first(); first_room->setPressedState(true); @@ -241,6 +245,8 @@ RoomList::highlightSelectedRoom(const QString &room_id) qobject_cast(it.value().data())); } } + + selectedRoom_ = room_id; } void @@ -284,3 +290,47 @@ RoomList::closeLeaveRoomDialog(bool leaving, const QString &room_id) client_->leaveRoom(room_id); } } + +void +RoomList::setFilterRooms(bool filterRooms) +{ + filterRooms_ = filterRooms; + + for (int i=0; icount(); i++) { + + //If roomFilter_ contains the room for the current RoomInfoListItem, + //show the list item, otherwise hide it + RoomInfoListItem *listitem = (RoomInfoListItem *) contentsLayout_->itemAt(i)->widget(); + + if (listitem != nullptr) { + if (!filterRooms) { + contentsLayout_->itemAt(i)->widget()->show(); + } else if (roomFilter_.contains(listitem->roomId())) { + contentsLayout_->itemAt(i)->widget()->show(); + } else { + contentsLayout_->itemAt(i)->widget()->hide(); + } + } + } + + if (!roomFilter_.contains(selectedRoom_)) { + RoomInfoListItem *firstVisibleRoom = nullptr; + for (int i=0; icount(); i++) { + QWidget *item = contentsLayout_->itemAt(i)->widget(); + if (item != nullptr && item->isVisible()) { + firstVisibleRoom = (RoomInfoListItem *) item; + break; + } + } + if (firstVisibleRoom != nullptr) { + highlightSelectedRoom(firstVisibleRoom->roomId()); + } + } +} + +void +RoomList::setRoomFilter(QList room_ids) +{ + roomFilter_ = room_ids; + setFilterRooms(true); +} From 4040fd3901ebb9ca36a6893121051a7dc0990973 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Mon, 30 Oct 2017 12:18:15 +0200 Subject: [PATCH 2/6] Try harder to scroll the RoomList to the active room (still doesn't work) --- src/RoomList.cc | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/RoomList.cc b/src/RoomList.cc index 2ddc1322..0aafd331 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -313,18 +313,21 @@ RoomList::setFilterRooms(bool filterRooms) } } - if (!roomFilter_.contains(selectedRoom_)) { - RoomInfoListItem *firstVisibleRoom = nullptr; - for (int i=0; icount(); i++) { - QWidget *item = contentsLayout_->itemAt(i)->widget(); - if (item != nullptr && item->isVisible()) { - firstVisibleRoom = (RoomInfoListItem *) item; - break; + if (filterRooms_ && !roomFilter_.contains(selectedRoom_)) { + RoomInfoListItem *firstVisibleRoom = nullptr; + for (int i = 0; i < contentsLayout_->count(); i++) { + QWidget *item = contentsLayout_->itemAt(i)->widget(); + if (item != nullptr && item->isVisible()) { + firstVisibleRoom = (RoomInfoListItem *)item; + break; + } } - } - if (firstVisibleRoom != nullptr) { - highlightSelectedRoom(firstVisibleRoom->roomId()); - } + if (firstVisibleRoom != nullptr) { + highlightSelectedRoom(firstVisibleRoom->roomId()); + } + } else { + scrollArea_->ensureWidgetVisible( + qobject_cast(rooms_.value(selectedRoom_).data())); } } From 0f76f0115ef2820dbad754138fb55c237db0619b Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 31 Oct 2017 07:26:41 +0200 Subject: [PATCH 3/6] lint --- include/CommunitiesList.h | 38 ++++---- include/CommunitiesListItem.h | 76 ++++++++------- include/Community.h | 7 +- include/RoomList.h | 4 +- include/ui/Theme.h | 4 +- src/ChatPage.cc | 63 +++++++------ src/CommunitiesList.cc | 173 ++++++++++++++++++---------------- src/CommunitiesListItem.cc | 43 ++++----- src/Community.cc | 53 +++++------ src/MatrixClient.cc | 22 +++-- src/RoomList.cc | 26 ++--- 11 files changed, 261 insertions(+), 248 deletions(-) diff --git a/include/CommunitiesList.h b/include/CommunitiesList.h index ffa3cfcf..53715363 100644 --- a/include/CommunitiesList.h +++ b/include/CommunitiesList.h @@ -1,44 +1,42 @@ #pragma once -#include #include #include #include +#include -#include "MatrixClient.h" #include "CommunitiesListItem.h" #include "Community.h" +#include "MatrixClient.h" #include "ui/Theme.h" class CommunitiesList : public QWidget { - Q_OBJECT + Q_OBJECT public: - CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); - ~CommunitiesList(); + CommunitiesList(QSharedPointer client, QWidget *parent = nullptr); + ~CommunitiesList(); - void setCommunities(const QMap> &communities); - void clear(); + void setCommunities(const QMap> &communities); + void clear(); - void addCommunity(QSharedPointer community, - const QString &community_id); - void removeCommunity(const QString &community_id); + void addCommunity(QSharedPointer community, const QString &community_id); + void removeCommunity(const QString &community_id); signals: - void communityChanged(const QString &community_id); + void communityChanged(const QString &community_id); public slots: - void updateCommunityAvatar(const QString &community_id, - const QPixmap &img); - void highlightSelectedCommunity(const QString &community_id); + void updateCommunityAvatar(const QString &community_id, const QPixmap &img); + void highlightSelectedCommunity(const QString &community_id); private: - QVBoxLayout *topLayout_; - QVBoxLayout *contentsLayout_; - QWidget *scrollAreaContents_; - QScrollArea *scrollArea_; + QVBoxLayout *topLayout_; + QVBoxLayout *contentsLayout_; + QWidget *scrollAreaContents_; + QScrollArea *scrollArea_; - QMap> communities_; + QMap> communities_; - QSharedPointer client_; + QSharedPointer client_; }; diff --git a/include/CommunitiesListItem.h b/include/CommunitiesListItem.h index 52b3e849..5df67268 100644 --- a/include/CommunitiesListItem.h +++ b/include/CommunitiesListItem.h @@ -1,83 +1,81 @@ #pragma once -#include -#include +#include #include #include -#include +#include +#include -#include "ui/Theme.h" -#include "Menu.h" #include "Community.h" +#include "Menu.h" +#include "ui/Theme.h" class CommunitiesListItem : public QWidget { - Q_OBJECT + Q_OBJECT public: - CommunitiesListItem(QSharedPointer community, - QString community_id, - QWidget *parent = nullptr); + CommunitiesListItem(QSharedPointer community, + QString community_id, + QWidget *parent = nullptr); - ~CommunitiesListItem(); + ~CommunitiesListItem(); - void setCommunity(QSharedPointer community); + void setCommunity(QSharedPointer community); - inline bool isPressed() const; - inline void setAvatar(const QImage &avatar_image); + inline bool isPressed() const; + inline void setAvatar(const QImage &avatar_image); signals: - void clicked(const QString &community_id); + void clicked(const QString &community_id); public slots: - void setPressedState(bool state); + void setPressedState(bool state); protected: - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; - void contextMenuEvent(QContextMenuEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; private: - const int IconSize = 55; + const int IconSize = 55; - QSharedPointer community_; - QString communityId_; - QString communityName_; - QString communityShortDescription; + QSharedPointer community_; + QString communityId_; + QString communityName_; + QString communityShortDescription; - QPixmap communityAvatar_; + QPixmap communityAvatar_; - Menu *menu_; - bool isPressed_ = false; + Menu *menu_; + bool isPressed_ = false; }; inline bool CommunitiesListItem::isPressed() const { - return isPressed_; + return isPressed_; } inline void CommunitiesListItem::setAvatar(const QImage &avatar_image) { - communityAvatar_ = QPixmap::fromImage( - avatar_image.scaled(IconSize, - IconSize, - Qt::IgnoreAspectRatio, - Qt::SmoothTransformation)); - update(); + communityAvatar_ = QPixmap::fromImage( + avatar_image.scaled(IconSize, IconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + update(); } class WorldCommunityListItem : public CommunitiesListItem { - Q_OBJECT + Q_OBJECT public: - WorldCommunityListItem(QWidget *parent = nullptr); - ~WorldCommunityListItem(); + WorldCommunityListItem(QWidget *parent = nullptr); + ~WorldCommunityListItem(); protected: - void mousePressEvent(QMouseEvent *event) override; - void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + private: - const int IconSize = 55; + const int IconSize = 55; }; diff --git a/include/Community.h b/include/Community.h index 2dccbbc8..0d70dee1 100644 --- a/include/Community.h +++ b/include/Community.h @@ -1,13 +1,13 @@ #pragma once -#include #include -#include +#include #include +#include class Community : public QObject { - Q_OBJECT + Q_OBJECT public: void parseProfile(const QJsonObject &profile); @@ -55,7 +55,6 @@ Community::getLongDescription() const return long_description_; } - inline const QList Community::getRoomList() const { diff --git a/include/RoomList.h b/include/RoomList.h index 9e58b64b..b44e99d6 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -87,8 +87,8 @@ private: QMap> rooms_; QString selectedRoom_; - bool filterRooms_ = false; - QList roomFilter_ = QList(); //which rooms to include in the room list + bool filterRooms_ = false; + QList roomFilter_ = QList(); // which rooms to include in the room list QSharedPointer client_; }; diff --git a/include/ui/Theme.h b/include/ui/Theme.h index 4d482fe3..c2e4ab59 100644 --- a/include/ui/Theme.h +++ b/include/ui/Theme.h @@ -13,8 +13,8 @@ enum class AvatarType }; namespace sidebar { -static const int SmallSize = 60; -static const int NormalSize = 300; +static const int SmallSize = 60; +static const int NormalSize = 300; static const int CommunitiesSidebarSize = 64; } // Default font size. diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 12e9b82a..8cd7007d 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -63,7 +63,7 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) communitiesList_ = new CommunitiesList(client, this); communitiesSideBarLayout_->addWidget(communitiesList_); - //communitiesSideBarLayout_->addStretch(1); + // communitiesSideBarLayout_->addStretch(1); topLayout_->addWidget(communitiesSideBar_); auto splitter = new Splitter(this); @@ -256,22 +256,27 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) SIGNAL(getOwnCommunitiesResponse(QList)), this, SLOT(updateOwnCommunitiesInfo(QList))); - connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, + connect(client_.data(), + &MatrixClient::communityProfileRetrieved, + this, [=](QString communityId, QJsonObject profile) { - communityManager_[communityId]->parseProfile(profile); - }); - connect(client_.data(), &MatrixClient::communityRoomsRetrieved, this, + communityManager_[communityId]->parseProfile(profile); + }); + connect(client_.data(), + &MatrixClient::communityRoomsRetrieved, + this, [=](QString communityId, QJsonObject rooms) { - communityManager_[communityId]->parseRooms(rooms); + communityManager_[communityId]->parseRooms(rooms); - if (communityId == current_community_) { - if (communityId == "world") { - room_list_->setFilterRooms(false); - } else { - room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); - } - } - }); + if (communityId == current_community_) { + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter( + communityManager_[communityId]->getRoomList()); + } + } + }); connect(client_.data(), SIGNAL(ownAvatarRetrieved(const QPixmap &)), this, @@ -301,14 +306,18 @@ ChatPage::ChatPage(QSharedPointer client, QWidget *parent) } }); - connect(communitiesList_, &CommunitiesList::communityChanged, this, [=](const QString &communityId) { - current_community_ = communityId; - if (communityId == "world") { - room_list_->setFilterRooms(false); - } else { - room_list_->setRoomFilter(communityManager_[communityId]->getRoomList()); - } - }); + connect(communitiesList_, + &CommunitiesList::communityChanged, + this, + [=](const QString &communityId) { + current_community_ = communityId; + if (communityId == "world") { + room_list_->setFilterRooms(false); + } else { + room_list_->setRoomFilter( + communityManager_[communityId]->getRoomList()); + } + }); AvatarProvider::init(client); } @@ -489,13 +498,13 @@ ChatPage::updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_na void ChatPage::updateOwnCommunitiesInfo(const QList &own_communities) { - for (int i = 0; i < own_communities.size(); i++) { - QSharedPointer community = QSharedPointer(new Community()); + for (int i = 0; i < own_communities.size(); i++) { + QSharedPointer community = QSharedPointer(new Community()); - communityManager_[own_communities[i]] = community; - } + communityManager_[own_communities[i]] = community; + } - communitiesList_->setCommunities(communityManager_); + communitiesList_->setCommunities(communityManager_); } void diff --git a/src/CommunitiesList.cc b/src/CommunitiesList.cc index 739ad4d6..c40155e5 100644 --- a/src/CommunitiesList.cc +++ b/src/CommunitiesList.cc @@ -3,53 +3,58 @@ #include CommunitiesList::CommunitiesList(QSharedPointer client, QWidget *parent) - : QWidget(parent) - , client_(client) + : QWidget(parent) + , client_(client) { - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(1); - setSizePolicy(sizePolicy); + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(1); + setSizePolicy(sizePolicy); - setStyleSheet("border-style: none;"); + setStyleSheet("border-style: none;"); - topLayout_ = new QVBoxLayout(this); - topLayout_->setSpacing(0); - topLayout_->setMargin(0); + topLayout_ = new QVBoxLayout(this); + topLayout_->setSpacing(0); + topLayout_->setMargin(0); - setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); - scrollArea_ = new QScrollArea(this); - scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - scrollArea_->setWidgetResizable(true); - scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); + scrollArea_ = new QScrollArea(this); + scrollArea_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scrollArea_->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); + scrollArea_->setWidgetResizable(true); + scrollArea_->setAlignment(Qt::AlignLeading | Qt::AlignTop | Qt::AlignVCenter); - scrollAreaContents_ = new QWidget(); + scrollAreaContents_ = new QWidget(); - contentsLayout_ = new QVBoxLayout(scrollAreaContents_); - contentsLayout_->setSpacing(0); - contentsLayout_->setMargin(0); + contentsLayout_ = new QVBoxLayout(scrollAreaContents_); + contentsLayout_->setSpacing(0); + contentsLayout_->setMargin(0); - WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); - contentsLayout_->addWidget(world_list_item); - communities_.insert("world", QSharedPointer(world_list_item)); - connect(world_list_item, &WorldCommunityListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); - contentsLayout_->addStretch(1); + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + contentsLayout_->addWidget(world_list_item); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, + &WorldCommunityListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->addStretch(1); - scrollArea_->setWidget(scrollAreaContents_); - topLayout_->addWidget(scrollArea_); + scrollArea_->setWidget(scrollAreaContents_); + topLayout_->addWidget(scrollArea_); - connect(client_.data(), &MatrixClient::communityProfileRetrieved, this, - [=](QString communityId, QJsonObject profile) { - client_->fetchCommunityAvatar(communityId, QUrl(profile["avatar_url"].toString())); - }); - connect(client_.data(), - SIGNAL(communityAvatarRetrieved(const QString &, const QPixmap &)), - this, - SLOT(updateCommunityAvatar(const QString &,const QPixmap &))); + connect(client_.data(), + &MatrixClient::communityProfileRetrieved, + this, + [=](QString communityId, QJsonObject profile) { + client_->fetchCommunityAvatar(communityId, + QUrl(profile["avatar_url"].toString())); + }); + connect(client_.data(), + SIGNAL(communityAvatarRetrieved(const QString &, const QPixmap &)), + this, + SLOT(updateCommunityAvatar(const QString &, const QPixmap &))); } CommunitiesList::~CommunitiesList() {} @@ -57,87 +62,89 @@ CommunitiesList::~CommunitiesList() {} void CommunitiesList::setCommunities(const QMap> &communities) { - communities_.clear(); + communities_.clear(); - //TODO: still not sure how to handle the "world" special-case - WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); - communities_.insert("world", QSharedPointer(world_list_item)); - connect(world_list_item, &WorldCommunityListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); - contentsLayout_->insertWidget(0, world_list_item); + // TODO: still not sure how to handle the "world" special-case + WorldCommunityListItem *world_list_item = new WorldCommunityListItem(); + communities_.insert("world", QSharedPointer(world_list_item)); + connect(world_list_item, + &WorldCommunityListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); + contentsLayout_->insertWidget(0, world_list_item); - for (auto it = communities.constBegin(); it != communities.constEnd(); it++) { - const auto community_id = it.key(); - const auto community = it.value(); + for (auto it = communities.constBegin(); it != communities.constEnd(); it++) { + const auto community_id = it.key(); + const auto community = it.value(); - addCommunity(community, community_id); + addCommunity(community, community_id); - client_->fetchCommunityProfile(community_id); - client_->fetchCommunityRooms(community_id); - } + client_->fetchCommunityProfile(community_id); + client_->fetchCommunityRooms(community_id); + } - world_list_item->setPressedState(true); - emit communityChanged("world"); + world_list_item->setPressedState(true); + emit communityChanged("world"); } void CommunitiesList::clear() { - communities_.clear(); + communities_.clear(); } void CommunitiesList::addCommunity(QSharedPointer community, const QString &community_id) { - CommunitiesListItem *list_item = new CommunitiesListItem(community, - community_id, - scrollArea_); + CommunitiesListItem *list_item = + new CommunitiesListItem(community, community_id, scrollArea_); - communities_.insert(community_id, QSharedPointer(list_item)); + communities_.insert(community_id, QSharedPointer(list_item)); - client_->fetchCommunityAvatar(community_id, community->getAvatar()); + client_->fetchCommunityAvatar(community_id, community->getAvatar()); - contentsLayout_->insertWidget(contentsLayout_->count()-1, list_item); + contentsLayout_->insertWidget(contentsLayout_->count() - 1, list_item); - connect(list_item, &CommunitiesListItem::clicked, - this, &CommunitiesList::highlightSelectedCommunity); + connect(list_item, + &CommunitiesListItem::clicked, + this, + &CommunitiesList::highlightSelectedCommunity); } void CommunitiesList::removeCommunity(const QString &community_id) { - communities_.remove(community_id); + communities_.remove(community_id); } void CommunitiesList::updateCommunityAvatar(const QString &community_id, const QPixmap &img) { - if (!communities_.contains(community_id)) { - qWarning() << "Avatar update on nonexistent community" << community_id; - return; - } - - communities_.value(community_id)->setAvatar(img.toImage()); + if (!communities_.contains(community_id)) { + qWarning() << "Avatar update on nonexistent community" << community_id; + return; + } + communities_.value(community_id)->setAvatar(img.toImage()); } void CommunitiesList::highlightSelectedCommunity(const QString &community_id) { - emit communityChanged(community_id); + emit communityChanged(community_id); - if (!communities_.contains(community_id)) { - qDebug() << "CommunitiesList: clicked unknown community"; - return; - } - - for (auto it = communities_.constBegin(); it != communities_.constEnd(); it++) { - if (it.key() != community_id) { - it.value()->setPressedState(false); - } else { - it.value()->setPressedState(true); - scrollArea_->ensureWidgetVisible( - qobject_cast(it.value().data())); + if (!communities_.contains(community_id)) { + qDebug() << "CommunitiesList: clicked unknown community"; + return; + } + + for (auto it = communities_.constBegin(); it != communities_.constEnd(); it++) { + if (it.key() != community_id) { + it.value()->setPressedState(false); + } else { + it.value()->setPressedState(true); + scrollArea_->ensureWidgetVisible( + qobject_cast(it.value().data())); + } } - } } diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc index 1a2c1d7c..5f4253f6 100644 --- a/src/CommunitiesListItem.cc +++ b/src/CommunitiesListItem.cc @@ -3,14 +3,14 @@ CommunitiesListItem::CommunitiesListItem(QSharedPointer community, QString community_id, QWidget *parent) - : QWidget(parent) - , community_(community) - , communityId_(community_id) + : QWidget(parent) + , community_(community) + , communityId_(community_id) { - //menu_ = new Menu(this); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - setFixedHeight(ui::sidebar::CommunitiesSidebarSize); - setFixedWidth(ui::sidebar::CommunitiesSidebarSize); + // menu_ = new Menu(this); + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setFixedHeight(ui::sidebar::CommunitiesSidebarSize); + setFixedWidth(ui::sidebar::CommunitiesSidebarSize); } CommunitiesListItem::~CommunitiesListItem() {} @@ -18,20 +18,21 @@ CommunitiesListItem::~CommunitiesListItem() {} void CommunitiesListItem::setCommunity(QSharedPointer community) { - community_ = community; + community_ = community; } void CommunitiesListItem::setPressedState(bool state) { - if (isPressed_ != state) { - isPressed_ = state; - update(); - } + if (isPressed_ != state) { + isPressed_ = state; + update(); + } } void -CommunitiesListItem::mousePressEvent(QMouseEvent *event) { +CommunitiesListItem::mousePressEvent(QMouseEvent *event) +{ if (event->buttons() == Qt::RightButton) { QWidget::mousePressEvent(event); return; @@ -47,7 +48,6 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) { Q_UNUSED(event); - QPainter p(this); p.setRenderHint(QPainter::TextAntialiasing); p.setRenderHint(QPainter::SmoothPixmapTransform); @@ -65,7 +65,7 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) p.setPen(QColor("#333")); - QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); font.setBold(false); p.setPen(Qt::NoPen); @@ -91,14 +91,15 @@ CommunitiesListItem::paintEvent(QPaintEvent *event) p.save(); QPainterPath path; - path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + path.addEllipse( + (width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.setClipPath(path); p.drawPixmap(avatarRegion, communityAvatar_); p.restore(); } - //TODO: Discord-style community ping counts? + // TODO: Discord-style community ping counts? /*if (unreadMsgCount_ > 0) { QColor textColor("white"); QColor backgroundColor("#38A3D8"); @@ -142,11 +143,11 @@ CommunitiesListItem::contextMenuEvent(QContextMenuEvent *event) { Q_UNUSED(event); - //menu_->popup(event->globalPos()); + // menu_->popup(event->globalPos()); } WorldCommunityListItem::WorldCommunityListItem(QWidget *parent) - : CommunitiesListItem(QSharedPointer(), "", parent) + : CommunitiesListItem(QSharedPointer(), "", parent) { } @@ -190,10 +191,10 @@ WorldCommunityListItem::paintEvent(QPaintEvent *event) p.setPen(Qt::NoPen); p.setBrush(brush); - QRect avatarRegion((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + QRect avatarRegion((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.drawEllipse(avatarRegion.center(), IconSize / 2, IconSize / 2); QPainterPath path; - path.addEllipse((width()-IconSize)/2, (height()-IconSize)/2, IconSize, IconSize); + path.addEllipse((width() - IconSize) / 2, (height() - IconSize) / 2, IconSize, IconSize); p.setClipPath(path); p.drawPixmap(avatarRegion, worldIcon); diff --git a/src/Community.cc b/src/Community.cc index 79b4b45b..df425e88 100644 --- a/src/Community.cc +++ b/src/Community.cc @@ -1,45 +1,44 @@ #include "include/Community.h" -#include #include +#include void Community::parseProfile(const QJsonObject &profile) { - if (profile["name"].type() == QJsonValue::Type::String) { - name_ = profile["name"].toString(); - } else { - name_ = "Unnamed Community"; //TODO: what is correct here? - } + if (profile["name"].type() == QJsonValue::Type::String) { + name_ = profile["name"].toString(); + } else { + name_ = "Unnamed Community"; // TODO: what is correct here? + } - if (profile["avatar_url"].type() == QJsonValue::Type::String) { - avatar_ = QUrl(profile["avatar_url"].toString()); - } else { - avatar_ = QUrl(); - } + if (profile["avatar_url"].type() == QJsonValue::Type::String) { + avatar_ = QUrl(profile["avatar_url"].toString()); + } else { + avatar_ = QUrl(); + } - if (profile["short_description"].type() == QJsonValue::Type::String) { - short_description_ = profile["short_description"].toString(); - } else { - short_description_ = ""; - } - - if (profile["long_description"].type() == QJsonValue::Type::String) { - long_description_ = profile["long_description"].toString(); - } else { - long_description_ = ""; - } + if (profile["short_description"].type() == QJsonValue::Type::String) { + short_description_ = profile["short_description"].toString(); + } else { + short_description_ = ""; + } + if (profile["long_description"].type() == QJsonValue::Type::String) { + long_description_ = profile["long_description"].toString(); + } else { + long_description_ = ""; + } } void Community::parseRooms(const QJsonObject &rooms) { - rooms_.clear(); + rooms_.clear(); - for (auto i = 0; ireadAll(); auto json = QJsonDocument::fromJson(data); try { - QList response; - for (auto it = json["groups"].toArray().constBegin(); it != json["groups"].toArray().constEnd(); it++) { - response.append(it->toString()); - } - emit getOwnCommunitiesResponse(response); + QList response; + for (auto it = json["groups"].toArray().constBegin(); + it != json["groups"].toArray().constEnd(); + it++) { + response.append(it->toString()); + } + emit getOwnCommunitiesResponse(response); } catch (DeserializationException &e) { - qWarning() << "Own communities:" << e.what(); + qWarning() << "Own communities:" << e.what(); } }); } @@ -606,7 +608,7 @@ MatrixClient::fetchCommunityProfile(const QString &communityId) QNetworkReply *reply = get(request); connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { - reply->deleteLater(); + reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -615,7 +617,7 @@ MatrixClient::fetchCommunityProfile(const QString &communityId) return; } - auto data = reply->readAll(); + auto data = reply->readAll(); const auto json = QJsonDocument::fromJson(data).object(); emit communityProfileRetrieved(communityId, json); @@ -636,7 +638,7 @@ MatrixClient::fetchCommunityRooms(const QString &communityId) QNetworkReply *reply = get(request); connect(reply, &QNetworkReply::finished, this, [this, reply, communityId]() { - reply->deleteLater(); + reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -645,7 +647,7 @@ MatrixClient::fetchCommunityRooms(const QString &communityId) return; } - auto data = reply->readAll(); + auto data = reply->readAll(); const auto json = QJsonDocument::fromJson(data).object(); emit communityRoomsRetrieved(communityId, json); diff --git a/src/RoomList.cc b/src/RoomList.cc index 0aafd331..de853377 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -296,21 +296,21 @@ RoomList::setFilterRooms(bool filterRooms) { filterRooms_ = filterRooms; - for (int i=0; icount(); i++) { + for (int i = 0; i < contentsLayout_->count(); i++) { + // If roomFilter_ contains the room for the current RoomInfoListItem, + // show the list item, otherwise hide it + RoomInfoListItem *listitem = + (RoomInfoListItem *)contentsLayout_->itemAt(i)->widget(); - //If roomFilter_ contains the room for the current RoomInfoListItem, - //show the list item, otherwise hide it - RoomInfoListItem *listitem = (RoomInfoListItem *) contentsLayout_->itemAt(i)->widget(); - - if (listitem != nullptr) { - if (!filterRooms) { - contentsLayout_->itemAt(i)->widget()->show(); - } else if (roomFilter_.contains(listitem->roomId())) { - contentsLayout_->itemAt(i)->widget()->show(); - } else { - contentsLayout_->itemAt(i)->widget()->hide(); + if (listitem != nullptr) { + if (!filterRooms) { + contentsLayout_->itemAt(i)->widget()->show(); + } else if (roomFilter_.contains(listitem->roomId())) { + contentsLayout_->itemAt(i)->widget()->show(); + } else { + contentsLayout_->itemAt(i)->widget()->hide(); + } } - } } if (filterRooms_ && !roomFilter_.contains(selectedRoom_)) { From 7f0ad89bca6b368367357587bde995bc5eec4b50 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 31 Oct 2017 07:47:19 +0200 Subject: [PATCH 4/6] Fix merge errors --- include/ChatPage.h | 2 ++ include/RoomInfoListItem.h | 8 ++++---- resources/res.qrc | 7 ------- src/CommunitiesListItem.cc | 2 +- src/MatrixClient.cc | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/ChatPage.h b/include/ChatPage.h index 567ef551..773e3bc5 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -26,6 +26,8 @@ #include "MemberEventContent.h" #include "MessageEvent.h" #include "StateEvent.h" +#include "CommunitiesList.h" +#include "Community.h" class Cache; class MatrixClient; diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index 63a73a04..992a3b5b 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -51,13 +51,13 @@ public: void clearUnreadMessageCount(); void setState(const RoomState &state); - bool isPressed() const { return isPressed_; }; - RoomState state() const { return state_; }; - int unreadMessageCount() const { return unreadMsgCount_; }; + bool isPressed() const { return isPressed_; } + RoomState state() const { return state_; } + int unreadMessageCount() const { return unreadMsgCount_; } void setAvatar(const QImage &avatar_image); void setDescriptionMessage(const DescInfo &info); - inline QString roomId(); + QString roomId() { return roomId_; } signals: void clicked(const QString &room_id); diff --git a/resources/res.qrc b/resources/res.qrc index a3ba1b98..5d87f9ed 100644 --- a/resources/res.qrc +++ b/resources/res.qrc @@ -66,13 +66,6 @@ fonts/OpenSans/OpenSans-Italic.ttf fonts/OpenSans/OpenSans-Bold.ttf fonts/OpenSans/OpenSans-Semibold.ttf -<<<<<<< HEAD - -======= - fonts/OpenSans/OpenSans-SemiboldItalic.ttf - fonts/OpenSans/OpenSans-ExtraBold.ttf - fonts/OpenSans/OpenSans-ExtraBoldItalic.ttf ->>>>>>> 4e60338... Initial implementation of Communities (groups) feature fonts/EmojiOne/emojione-android.ttf diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc index 5f4253f6..6bb13014 100644 --- a/src/CommunitiesListItem.cc +++ b/src/CommunitiesListItem.cc @@ -171,7 +171,7 @@ WorldCommunityListItem::paintEvent(QPaintEvent *event) { Q_UNUSED(event); - static QPixmap worldIcon(":/icons/icons/world.png"); + static QPixmap worldIcon(":/icons/icons/ui/world.png"); QPainter p(this); p.setRenderHint(QPainter::SmoothPixmapTransform); diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 8778c6c7..e0282e6a 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -487,7 +487,7 @@ MatrixClient::getOwnCommunities() noexcept } auto data = reply->readAll(); - auto json = QJsonDocument::fromJson(data); + auto json = QJsonDocument::fromJson(data).object(); try { QList response; for (auto it = json["groups"].toArray().constBegin(); @@ -549,7 +549,7 @@ MatrixClient::fetchRoomAvatar(const QString &roomid, const QUrl &avatar_url) } void -MatrixClient::fetchCommunityAvatar(const QString &communityid, const QUrl &avatar_url) +MatrixClient::fetchCommunityAvatar(const QString &communityId, const QUrl &avatar_url) { QList url_parts = avatar_url.toString().split("mxc://"); From dc6aeccad3a54955ce421054150d48aa2964ccd5 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Tue, 31 Oct 2017 08:00:35 +0200 Subject: [PATCH 5/6] fix linting errors --- include/ChatPage.h | 4 ++-- src/CommunitiesListItem.cc | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/ChatPage.h b/include/ChatPage.h index 773e3bc5..5077d867 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -23,11 +23,11 @@ #include #include +#include "CommunitiesList.h" +#include "Community.h" #include "MemberEventContent.h" #include "MessageEvent.h" #include "StateEvent.h" -#include "CommunitiesList.h" -#include "Community.h" class Cache; class MatrixClient; diff --git a/src/CommunitiesListItem.cc b/src/CommunitiesListItem.cc index 6bb13014..5a94f768 100644 --- a/src/CommunitiesListItem.cc +++ b/src/CommunitiesListItem.cc @@ -148,8 +148,7 @@ CommunitiesListItem::contextMenuEvent(QContextMenuEvent *event) WorldCommunityListItem::WorldCommunityListItem(QWidget *parent) : CommunitiesListItem(QSharedPointer(), "", parent) -{ -} +{} WorldCommunityListItem::~WorldCommunityListItem() {} From 2f6df70a8b557d67fe2c38c858232fed9e3e3dd0 Mon Sep 17 00:00:00 2001 From: Max Sandholm Date: Thu, 2 Nov 2017 16:18:27 +0200 Subject: [PATCH 6/6] Fix the segfault when iterating over the JSON array in getOwnCommunities --- src/MatrixClient.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index e0282e6a..88563ec8 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -490,8 +490,9 @@ MatrixClient::getOwnCommunities() noexcept auto json = QJsonDocument::fromJson(data).object(); try { QList response; - for (auto it = json["groups"].toArray().constBegin(); - it != json["groups"].toArray().constEnd(); + auto array = json["groups"].toArray(); + for (auto it = array.constBegin(); + it != array.constEnd(); it++) { response.append(it->toString()); }