summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-31 19:42:07 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-05-31 19:42:07 +0300
commitaf80c251d75e5e8bf7e8c6f870f8c8b069a822e1 (patch)
tree71f63d4d3c74555a66f27a347016d30e82aa3e66 /src
parentAdd menu to toggle notifications (diff)
downloadnheko-af80c251d75e5e8bf7e8c6f870f8c8b069a822e1.tar.xz
Add context menu on RoomList items
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cc2
-rw-r--r--src/RoomInfoListItem.cc37
-rw-r--r--src/RoomList.cc11
-rw-r--r--src/TopRoomBar.cc16
4 files changed, 51 insertions, 15 deletions
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 2b92ac7d..0b09693b 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -303,7 +303,7 @@ void ChatPage::initialSyncCompleted(const SyncResponse &response)
 	}
 
 	view_manager_->initialize(response.rooms());
-	room_list_->setInitialRooms(state_manager_);
+	room_list_->setInitialRooms(settingsManager_, state_manager_);
 
 	sync_timer_->start(sync_interval_);
 }
diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc
index 7753536e..3d4c5355 100644
--- a/src/RoomInfoListItem.cc
+++ b/src/RoomInfoListItem.cc
@@ -24,10 +24,14 @@
 #include "RoomState.h"
 #include "Theme.h"
 
-RoomInfoListItem::RoomInfoListItem(RoomState state, QString room_id, QWidget *parent)
+RoomInfoListItem::RoomInfoListItem(QSharedPointer<RoomSettings> settings,
+				   RoomState state,
+				   QString room_id,
+				   QWidget *parent)
     : QWidget(parent)
     , state_(state)
     , roomId_(room_id)
+    , roomSettings_{settings}
     , isPressed_(false)
     , maxHeight_(IconSize + 2 * Padding)
     , unreadMsgCount_(0)
@@ -44,6 +48,24 @@ RoomInfoListItem::RoomInfoListItem(RoomState state, QString room_id, QWidget *pa
 	ripple_overlay_ = new RippleOverlay(this);
 	ripple_overlay_->setClipPath(path);
 	ripple_overlay_->setClipping(true);
+
+	menu_ = new Menu(this);
+
+	toggleNotifications_ = new QAction(notificationText(), this);
+
+	connect(toggleNotifications_, &QAction::triggered, this, [=]() {
+		roomSettings_->toggleNotifications();
+	});
+
+	menu_->addAction(toggleNotifications_);
+}
+
+QString RoomInfoListItem::notificationText()
+{
+	if (roomSettings_.isNull() || roomSettings_->isNotificationsEnabled())
+		return QString(tr("Disable notifications"));
+
+	return tr("Enable notifications");
 }
 
 void RoomInfoListItem::paintEvent(QPaintEvent *event)
@@ -193,8 +215,21 @@ void RoomInfoListItem::setState(const RoomState &new_state)
 	repaint();
 }
 
+void RoomInfoListItem::contextMenuEvent(QContextMenuEvent *event)
+{
+	Q_UNUSED(event);
+
+	toggleNotifications_->setText(notificationText());
+	menu_->popup(event->globalPos());
+}
+
 void RoomInfoListItem::mousePressEvent(QMouseEvent *event)
 {
+	if (event->buttons() == Qt::RightButton) {
+		QWidget::mousePressEvent(event);
+		return;
+	}
+
 	emit clicked(roomId_);
 
 	setPressedState(true);
diff --git a/src/RoomList.cc b/src/RoomList.cc
index 6d0e185b..55c71b19 100644
--- a/src/RoomList.cc
+++ b/src/RoomList.cc
@@ -92,10 +92,17 @@ void RoomList::calculateUnreadMessageCount()
 	emit totalUnreadMessageCountUpdated(total_unread_msgs);
 }
 
-void RoomList::setInitialRooms(const QMap<QString, RoomState> &states)
+void RoomList::setInitialRooms(const QMap<QString, QSharedPointer<RoomSettings>> &settings,
+			       const QMap<QString, RoomState> &states)
 {
 	rooms_.clear();
 
+	if (settings.size() != states.size()) {
+		qWarning() << "Initializing room list";
+		qWarning() << "Different number of room states and room settings";
+		return;
+	}
+
 	for (auto it = states.constBegin(); it != states.constEnd(); it++) {
 		auto room_id = it.key();
 		auto state = it.value();
@@ -103,7 +110,7 @@ void RoomList::setInitialRooms(const QMap<QString, RoomState> &states)
 		if (!state.getAvatar().toString().isEmpty())
 			client_->fetchRoomAvatar(room_id, state.getAvatar());
 
-		RoomInfoListItem *room_item = new RoomInfoListItem(state, room_id, scrollArea_);
+		RoomInfoListItem *room_item = new RoomInfoListItem(settings[room_id], state, room_id, scrollArea_);
 		connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom);
 
 		rooms_.insert(room_id, QSharedPointer<RoomInfoListItem>(room_item));
diff --git a/src/TopRoomBar.cc b/src/TopRoomBar.cc
index ce0693f2..2f04129e 100644
--- a/src/TopRoomBar.cc
+++ b/src/TopRoomBar.cc
@@ -71,17 +71,16 @@ TopRoomBar::TopRoomBar(QWidget *parent)
 	toggleNotifications_ = new QAction(tr("Disable notifications"), this);
 	connect(toggleNotifications_, &QAction::triggered, this, [=]() {
 		roomSettings_->toggleNotifications();
-
-		if (roomSettings_->isNotificationsEnabled())
-			toggleNotifications_->setText("Disable notifications");
-		else
-			toggleNotifications_->setText("Enable notifications");
-
 	});
 
 	menu_->addAction(toggleNotifications_);
 
 	connect(settingsBtn_, &QPushButton::clicked, this, [=]() {
+		if (roomSettings_->isNotificationsEnabled())
+			toggleNotifications_->setText(tr("Disable notifications"));
+		else
+			toggleNotifications_->setText(tr("Enable notifications"));
+
 		auto pos = mapToGlobal(settingsBtn_->pos());
 		menu_->popup(QPoint(pos.x() + buttonSize_ - menu_->sizeHint().width(),
 				    pos.y() + buttonSize_));
@@ -121,11 +120,6 @@ void TopRoomBar::paintEvent(QPaintEvent *event)
 void TopRoomBar::setRoomSettings(QSharedPointer<RoomSettings> settings)
 {
 	roomSettings_ = settings;
-
-	if (roomSettings_->isNotificationsEnabled())
-		toggleNotifications_->setText("Disable notifications");
-	else
-		toggleNotifications_->setText("Enable notifications");
 }
 
 TopRoomBar::~TopRoomBar()