Skip to content

Commit

Permalink
Interim support of room tags
Browse files Browse the repository at this point in the history
Closes #322. Full support includes room ordering within a tag, which implies organising rooms under tags in the UI (the scope of #323).
  • Loading branch information
KitsuneRal committed Mar 5, 2018
1 parent 7f0d418 commit f439cb0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
35 changes: 34 additions & 1 deletion client/roomdialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,43 @@ RoomDialogBase::RoomDialogBase(const QString& title,
RoomSettingsDialog::RoomSettingsDialog(QuaternionRoom* room, QWidget* parent)
: RoomDialogBase(tr("Room settings: %1").arg(room->displayName()),
tr("Update room"), room, parent)
, tagsList(new QListWidget)
{
Q_ASSERT(room != nullptr);
connect(room, &QuaternionRoom::avatarChanged, this, [this, room] {
if (!userChangedAvatar)
avatar->setPixmap(QPixmap::fromImage(room->avatar(64)));
});
avatar->setPixmap(QPixmap::fromImage(room->avatar(64)));
// TODO: Make same for other fields
tagsList->setSizeAdjustPolicy(
QAbstractScrollArea::AdjustToContentsOnFirstShow);
tagsList->setUniformItemSizes(true);
tagsList->setSelectionMode(QAbstractItemView::ExtendedSelection);

formLayout->addRow(tr("Tags"), tagsList);
}

void RoomSettingsDialog::load()
{
roomName->setText(room->name());
alias->setText(room->canonicalAlias());
topic->setPlainText(room->topic());

tagsList->clear();
auto roomTags = room->tagNames();
for (const auto& tag: room->connection()->tagNames())
{
auto tagDisplayName =
tag == QMatrixClient::FavouriteTag ? tr("Favourite") :
tag == QMatrixClient::LowPriorityTag ? tr("Low priority") :
tag;
auto* item = new QListWidgetItem(tagDisplayName, tagsList);
item->setData(Qt::UserRole, tag);
item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
item->setCheckState(
roomTags.contains(tag) ? Qt::Checked : Qt::Unchecked);
tagsList->addItem(item);
}
}

void RoomSettingsDialog::apply()
Expand All @@ -133,6 +155,17 @@ void RoomSettingsDialog::apply()
room->setCanonicalAlias(alias->text());
if (topic->toPlainText() != room->topic())
room->setTopic(topic->toPlainText());
auto tags = room->tags();
for (int i = 0; i < tagsList->count(); ++i)
{
const auto* item = tagsList->item(i);
const auto tagName = item->data(Qt::UserRole).toString();
if (item->checkState() == Qt::Checked)
tags[tagName]; // Just ensure the tag is there, no overwriting
else
tags.remove(tagName);
}
room->setTags(tags);
accept();
}

Expand Down
1 change: 1 addition & 0 deletions client/roomdialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class RoomSettingsDialog : public RoomDialogBase
void apply() override;

private:
QListWidget* tagsList;
bool userChangedAvatar = false;
};

Expand Down
33 changes: 31 additions & 2 deletions client/roomlistdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QtCore/QSettings>
#include <QtWidgets/QMenu>
#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QInputDialog>

#include "models/roomlistmodel.h"
#include "quaternionroom.h"
Expand Down Expand Up @@ -104,6 +105,10 @@ RoomListDock::RoomListDock(QWidget* parent)
connect(markAsReadAction, &QAction::triggered, this, &RoomListDock::menuMarkReadSelected);
contextMenu->addAction(markAsReadAction);
contextMenu->addSeparator();
addTagsAction = new QAction(tr("Add tags..."), this);
connect(addTagsAction, &QAction::triggered, this, &RoomListDock::addTagsSelected);
contextMenu->addAction(addTagsAction);
contextMenu->addSeparator();
joinAction = new QAction(tr("Join room"), this);
connect(joinAction, &QAction::triggered, this, &RoomListDock::menuJoinSelected);
contextMenu->addAction(joinAction);
Expand Down Expand Up @@ -138,13 +143,15 @@ void RoomListDock::showContextMenu(const QPoint& pos)
auto room = model->roomAt(proxyModel->mapToSource(index));

using QMatrixClient::JoinState;
joinAction->setEnabled(room->joinState() != JoinState::Join);
bool joined = room->joinState() == JoinState::Join;
markAsReadAction->setEnabled(joined);
addTagsAction->setEnabled(joined);
joinAction->setEnabled(!joined);
leaveAction->setText(room->joinState() == JoinState::Invite ?
tr("Reject invitation") : tr("Leave room"));
leaveAction->setEnabled(room->joinState() != JoinState::Leave);
forgetAction->setText(room->joinState() == JoinState::Invite ?
tr("Forget invitation") : tr("Forget room"));
markAsReadAction->setEnabled(room->joinState() == JoinState::Join);

contextMenu->popup(mapToGlobal(pos));
}
Expand Down Expand Up @@ -183,6 +190,28 @@ void RoomListDock::menuMarkReadSelected()
room->markAllMessagesAsRead();
}

void RoomListDock::addTagsSelected()
{
if (auto room = getSelectedRoom())
{
auto tagsInput = QInputDialog::getMultiLineText(this,
tr("Enter new tags for the room"),
tr("Enter tags to add to this room, one tag per line"));
if (tagsInput.isEmpty())
return;

auto tags = room->tags();
for (const auto& tag: tagsInput.split('\n'))
{
// No overwriting, just ensure the tag exists
tags[tag == tr("Favourite") ? QMatrixClient::FavouriteTag :
tag == tr("Low priority") ? QMatrixClient::LowPriorityTag :
tag];
}
room->setTags(tags);
}
}

void RoomListDock::refreshTitle()
{
setWindowTitle(tr("Rooms (%1)").arg(model->rowCount(QModelIndex())));
Expand Down
2 changes: 2 additions & 0 deletions client/roomlistdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RoomListDock : public QDockWidget
void rowSelected(const QModelIndex& index);
void showContextMenu(const QPoint& pos);
void menuMarkReadSelected();
void addTagsSelected();
void menuJoinSelected();
void menuLeaveSelected();
void menuForgetSelected();
Expand All @@ -57,6 +58,7 @@ class RoomListDock : public QDockWidget
QSortFilterProxyModel* proxyModel;
QMenu* contextMenu;
QAction* markAsReadAction;
QAction* addTagsAction;
QAction* joinAction;
QAction* leaveAction;
QAction* forgetAction;
Expand Down
2 changes: 1 addition & 1 deletion lib
Submodule lib updated from 164938 to 1c5b7f

0 comments on commit f439cb0

Please sign in to comment.