Skip to content

Commit

Permalink
Merge #908(dymoksc): Remove users to invite from list
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Feb 10, 2025
2 parents 3d945ad + fb2256a commit 213c27f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
39 changes: 30 additions & 9 deletions client/roomdialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,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 @@ -342,9 +346,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 @@ -366,9 +372,10 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,
nextInvitee->setCompleter(completer);
connect(nextInvitee, &NextInvitee::currentTextChanged,
this, &CreateRoomDialog::updatePushButtons);
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 @@ -379,6 +386,18 @@ CreateRoomDialog::CreateRoomDialog(Quotient::AccountRegistry* accounts,
invitees->addItem(userName);
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 @@ -388,7 +407,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 @@ -403,9 +423,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
6 changes: 6 additions & 0 deletions client/translations/quaternion_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@
<comment>Add a user to the list of invitees</comment>
<translation>Add</translation>
</message>
<message>
<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="357"/>
<source>Please fill the fields as desired. None are mandatory</source>
Expand Down

0 comments on commit 213c27f

Please sign in to comment.