Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove users to invite from list #908

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions client/roomdialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,15 @@ class InviteeList : public QListWidget
{
if (event->key() == Qt::Key_Delete)
delete takeItem(currentRow());
else
QListWidget::keyPressEvent(event);
}
void mousePressEvent(QMouseEvent* event) override
{
if (event->button() == Qt::MiddleButton)
delete takeItem(currentRow());
else
QListWidget::mousePressEvent(event);
}
};

Expand All @@ -351,9 +355,11 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,
, accountChooser(new AccountSelector(accounts))
, version(nullptr) // Will be initialized below
, nextInvitee(new NextInvitee)
, inviteButton(
, addToInviteesButton(
new QPushButton(tr("Add", "Add a user to the list of invitees")))
, invitees(new QListWidget)
, removeFromInviteesButton(
new QPushButton(tr("Remove", "Remove a user from the list of invitees")))
, invitees(new InviteeList)
{
Q_ASSERT(!accounts->empty());

Expand All @@ -377,9 +383,11 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,
this, &CreateRoomDialog::updatePushButtons);
// connect(nextInvitee, &NextInvitee::editTextChanged,
// this, &CreateRoomDialog::updateUserList);
inviteButton->setFocusPolicy(Qt::NoFocus);
inviteButton->setDisabled(true);
connect(inviteButton, &QPushButton::clicked, [this] {

// Add button initialization
addToInviteesButton->setFocusPolicy(Qt::NoFocus);
addToInviteesButton->setDisabled(true);
connect(addToInviteesButton, &QPushButton::clicked, [this] {
auto userName = nextInvitee->currentText();
if (userName.indexOf('@') == -1)
{
Expand All @@ -393,6 +401,18 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,
invitees->addItem(item);
nextInvitee->clear();
});

// Remove button initialization
removeFromInviteesButton->setFocusPolicy(Qt::NoFocus);
removeFromInviteesButton->setDisabled(true);
connect(removeFromInviteesButton, &QPushButton::clicked, [this] {
if (invitees->currentItem() == nullptr)
return;
delete invitees->takeItem(invitees->currentRow());
});
connect(invitees, &InviteeList::currentItemChanged, this,
&CreateRoomDialog::updatePushButtons);

invitees->setSizeAdjustPolicy(
QAbstractScrollArea::AdjustToContentsOnFirstShow);
invitees->setUniformItemSizes(true);
Expand All @@ -402,7 +422,8 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,

auto* inviteLayout = new QHBoxLayout;
inviteLayout->addWidget(nextInvitee);
inviteLayout->addWidget(inviteButton);
inviteLayout->addWidget(addToInviteesButton);
inviteLayout->addWidget(removeFromInviteesButton);

mainFormLayout->addRow(tr("Invite user(s)"), inviteLayout);
mainFormLayout->addRow("", invitees);
Expand All @@ -417,9 +438,10 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,

void CreateRoomDialog::updatePushButtons()
{
inviteButton->setEnabled(!nextInvitee->currentText().isEmpty());
if (inviteButton->isEnabled() && nextInvitee->hasFocus())
inviteButton->setDefault(true);
addToInviteesButton->setEnabled(!nextInvitee->currentText().isEmpty());
removeFromInviteesButton->setEnabled(invitees->currentItem() != nullptr);
if (addToInviteesButton->isEnabled() && nextInvitee->hasFocus())
addToInviteesButton->setDefault(true);
else
buttonBox()->button(QDialogButtonBox::Ok)->setDefault(true);
}
Expand Down
3 changes: 2 additions & 1 deletion client/roomdialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class CreateRoomDialog : public RoomDialogBase
AccountSelector* accountChooser;
QComboBox* version;
QComboBox* nextInvitee;
QPushButton* inviteButton;
QPushButton* addToInviteesButton;
QPushButton* removeFromInviteesButton;
QListWidget* invitees;

QHash<Connection*, QStandardItemModel*> userLists;
Expand Down
16 changes: 11 additions & 5 deletions client/translations/quaternion_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,34 @@
<context>
<name>CreateRoomDialog</name>
<message>
<location filename="../roomdialogs.cpp" line="349"/>
<location filename="../roomdialogs.cpp" line="353"/>
<source>Create room</source>
<translation>Create room</translation>
</message>
<message>
<location filename="../roomdialogs.cpp" line="355"/>
<location filename="../roomdialogs.cpp" line="359"/>
<source>Add</source>
<comment>Add a user to the list of invitees</comment>
<translation>Add</translation>
</message>
<message>
<location filename="../roomdialogs.cpp" line="366"/>
<location filename="../roomdialogs.cpp" line="361"/>
<source>Remove</source>
<comment>Remove a user from the list of invitees</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../roomdialogs.cpp" line="372"/>
<source>Please fill the fields as desired. None are mandatory</source>
<translation>Please fill the fields as desired. None are mandatory</translation>
</message>
<message>
<location filename="../roomdialogs.cpp" line="407"/>
<location filename="../roomdialogs.cpp" line="427"/>
<source>Invite user(s)</source>
<translation>Invite user(s)</translation>
</message>
<message>
<location filename="../roomdialogs.cpp" line="410"/>
<location filename="../roomdialogs.cpp" line="430"/>
<source>Creating the room, please wait</source>
<translation>Creating the room, please wait</translation>
</message>
Expand Down