Skip to content

Commit

Permalink
Message forwarding: introduce roster's contact pick mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jul 10, 2024
1 parent 898efbd commit cc3d12b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/contactlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ void ContactListView::activate(const QModelIndex &index) { itemActivated(index);

void ContactListView::itemActivated(const QModelIndex &index)
{
model()->setData(index, QVariant(true), ContactListModel::ActivateRole);
if (activateAction == Activate) {
model()->setData(index, QVariant(true), ContactListModel::ActivateRole);
} else {
emit contactSelected(
model()->data(index, ContactListModel::ContactListItemRole).value<ContactListItem *>()->contact());
}
}

static QAbstractItemModel *realModel(QAbstractItemModel *model)
Expand Down
6 changes: 6 additions & 0 deletions src/contactlistview.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ class ContactListItemMenu;
class ContactListModel;
class QLineEdit;
class QWidget;
class PsiContact;

class ContactListView : public HoverableTreeView {
Q_OBJECT

public:
enum ActivateAction { Activate, SignalSelected };

ContactListView(QWidget *parent = nullptr);

ContactListModel *realModel() const;
Expand All @@ -47,6 +50,7 @@ class ContactListView : public HoverableTreeView {
void activate(const QModelIndex &index);
void toggleExpandedState(const QModelIndex &index);
void ensureVisible(const QModelIndex &index);
void setActivateAction(ActivateAction action) { activateAction = action; }

// reimplemented
void setModel(QAbstractItemModel *model) override;
Expand All @@ -58,6 +62,7 @@ public slots:
void realExpanded(const QModelIndex &);
void realCollapsed(const QModelIndex &);
void modelItemsUpdated();
void contactSelected(PsiContact *);

protected:
// reimplemented
Expand Down Expand Up @@ -98,6 +103,7 @@ protected slots:
private:
QPointer<ContactListItemMenu> contextMenu_;
bool contextMenuActive_;
ActivateAction activateAction = Activate;
};

#endif // CONTACTLISTVIEW_H
4 changes: 3 additions & 1 deletion src/psicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,9 @@ void PsiCon::invokeForwardMessage(const Jid &from, const QString &text)

auto roster = new PsiRosterWidget(d->mainwin);
roster->setContactList(d->contactList);
roster->setFilterModeEnabled(true);
roster->setPickContactMode(true);
connect(roster, &PsiRosterWidget::contactPick, this,
[](PsiContact *c) { qDebug("TODO forwarding to: %s", qPrintable(c->jid().full())); });

auto btn = new QPushButton(tr("Forward"));
connect(btn, &QPushButton::clicked, dlg, [this, roster](bool) { qDebug("TODO: implement forwarding"); });
Expand Down
36 changes: 30 additions & 6 deletions src/psirosterwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void PsiRosterWidget::setContactList(PsiContactList *contactList)
contactListModel_->invalidateLayout();
contactListModel_->setAccountsEnabled(true);
contactListModel_->setGroupsEnabled(PsiOptions::instance()->getOption(enableGroupsOptionPath).toBool());
// connect
#ifdef MODELTEST
new ModelTest(contactListModel_, this);
#endif
Expand Down Expand Up @@ -249,9 +250,19 @@ void PsiRosterWidget::filterEditTextChanged(const QString &text)
#endif
}

void PsiRosterWidget::quitFilteringMode() { setFilterModeEnabled(false); }
void PsiRosterWidget::quitFilteringMode()
{
if (!pickContactMode_) {
setFilterModeEnabled(false);
}
}

void PsiRosterWidget::updateFilterMode() { setFilterModeEnabled(!filterEdit_->text().isEmpty()); }
void PsiRosterWidget::updateFilterMode()
{
if (!pickContactMode_) {
setFilterModeEnabled(!filterEdit_->text().isEmpty());
}
}

void PsiRosterWidget::setFilterModeEnabled(bool enabled)
{
Expand Down Expand Up @@ -297,9 +308,18 @@ void PsiRosterWidget::setFilterModeEnabled(bool enabled)
delete selection;
}

void PsiRosterWidget::setPickContactMode(bool value)
{
pickContactMode_ = value;
if (value) {
setFilterModeEnabled(true);
}
contactListPageView_->setActivateAction(value ? ContactListView::SignalSelected : ContactListView::Activate);
}

void PsiRosterWidget::clearFilterEdit()
{
if (filterEdit_->text().isEmpty())
if (filterEdit_->text().isEmpty() && !pickContactMode_)
setFilterModeEnabled(false);
else
filterEdit_->setText("");
Expand Down Expand Up @@ -332,19 +352,23 @@ bool PsiRosterWidget::eventFilter(QObject *obj, QEvent *e)
filterEdit_->setText(text);
return true;
}
} else if (ke->key() == Qt::Key_F3) {
} else if (ke->key() == Qt::Key_F3 && !pickContactMode_) {
setFilterModeEnabled(!(filterEdit_->isVisible() && filterEdit_->text().isEmpty()));
filterEdit_->setText("");
return true;
}

if (obj == filterEdit_ || obj == filterPageView_ || obj == filterPage_) {
if (ke->key() == Qt::Key_Escape) {
setFilterModeEnabled(false);
if (pickContactMode_) {
deleteLater();
} else {
setFilterModeEnabled(false);
}
return true;
}

if (ke->key() == Qt::Key_Backspace && filterEdit_->text().isEmpty()) {
if (ke->key() == Qt::Key_Backspace && filterEdit_->text().isEmpty() && !pickContactMode_) {
setFilterModeEnabled(false);
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/psirosterwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ContactListDragModel;
class PsiContactList;
class PsiContactListView;
class PsiFilteredContactListView;
class PsiContact;
class QLineEdit;
class QMimeData;
class QSortFilterProxyModel;
Expand All @@ -40,6 +41,10 @@ class PsiRosterWidget : public QWidget {

void setContactList(PsiContactList *contactList);

void setPickContactMode(bool);
signals:
void contactPick(PsiContact *);

public slots:
void filterEditTextChanged(const QString &);
void quitFilteringMode();
Expand Down Expand Up @@ -69,6 +74,7 @@ private slots:

ContactListDragModel *contactListModel_;
QSortFilterProxyModel *filterModel_;
bool pickContactMode_ = false;
};

#endif // PSIROSTERWIDGET_H
4 changes: 2 additions & 2 deletions themes/chatview/psi/bubble/Dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ blockquote>div {
}

.reactions_selector {
background-color: #111;
background-color: #033;
}

.context_menu {
background-color: black;
background-color: #033;
}

.context_menu>div+div {
Expand Down
2 changes: 1 addition & 1 deletion themes/chatview/psi/bubble/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@

.context_menu>div {
box-sizing: border-box;
padding: .3rem .5rem;
padding: .3rem 1rem;
}

.context_menu>div+div {
Expand Down

0 comments on commit cc3d12b

Please sign in to comment.