some more with contect menu

This commit is contained in:
Blue 2019-06-14 19:36:04 +03:00
parent ee59d92cdc
commit f0f26ae1a1
6 changed files with 48 additions and 8 deletions

View File

@ -747,7 +747,7 @@ void Core::Account::subscribeToContact(const QString& jid, const QString& reason
QXmppRosterManager& rm = client.rosterManager(); QXmppRosterManager& rm = client.rosterManager();
rm.subscribe(jid, reason); rm.subscribe(jid, reason);
} else { } else {
qDebug() << "An attempt to subscribe an account " << name << " to jid " << jid << " but the account is not in the connected state, skipping"; qDebug() << "An attempt to subscribe account " << name << " to contact " << jid << " but the account is not in the connected state, skipping";
} }
} }
@ -757,7 +757,27 @@ void Core::Account::unsubscribeFromContact(const QString& jid, const QString& re
QXmppRosterManager& rm = client.rosterManager(); QXmppRosterManager& rm = client.rosterManager();
rm.unsubscribe(jid, reason); rm.unsubscribe(jid, reason);
} else { } else {
qDebug() << "An attempt to unsubscribe an account " << name << " from jid " << jid << " but the account is not in the connected state, skipping"; qDebug() << "An attempt to unsubscribe account " << name << " from contact " << jid << " but the account is not in the connected state, skipping";
} }
} }
void Core::Account::removeContactRequest(const QString& jid)
{
if (state == Shared::connected) {
QXmppRosterManager& rm = client.rosterManager();
rm.removeItem(jid);
} else {
qDebug() << "An attempt to remove contact " << jid << " from account " << name << " but the account is not in the connected state, skipping";
}
}
void Core::Account::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups)
{
if (state == Shared::connected) {
QXmppRosterManager& rm = client.rosterManager();
rm.addItem(jid, name, groups);
} else {
qDebug() << "An attempt to add contact " << jid << " to account " << name << " but the account is not in the connected state, skipping";
}
}

View File

@ -46,6 +46,8 @@ public:
void setReconnectTimes(unsigned int times); void setReconnectTimes(unsigned int times);
void subscribeToContact(const QString& jid, const QString& reason); void subscribeToContact(const QString& jid, const QString& reason);
void unsubscribeFromContact(const QString& jid, const QString& reason); void unsubscribeFromContact(const QString& jid, const QString& reason);
void removeContactRequest(const QString& jid);
void addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups);
signals: signals:
void connectionStateChanged(int); void connectionStateChanged(int);

View File

@ -354,3 +354,14 @@ void Core::Squawk::unsubscribeContact(const QString& account, const QString& jid
itr->second->unsubscribeFromContact(jid, reason); itr->second->unsubscribeFromContact(jid, reason);
} }
void Core::Squawk::removeContactRequest(const QString& account, const QString& jid)
{
AccountsMap::const_iterator itr = amap.find(account);
if (itr == amap.end()) {
qDebug("An attempt to remove contact from non existing account, skipping");
return;
}
itr->second->removeContactRequest(jid);
}

View File

@ -51,6 +51,7 @@ public slots:
void requestArchive(const QString& account, const QString& jid, int count, const QString& before); void requestArchive(const QString& account, const QString& jid, int count, const QString& before);
void subscribeContact(const QString& account, const QString& jid, const QString& reason); void subscribeContact(const QString& account, const QString& jid, const QString& reason);
void unsubscribeContact(const QString& account, const QString& jid, const QString& reason); void unsubscribeContact(const QString& account, const QString& jid, const QString& reason);
void removeContactRequest(const QString& account, const QString& jid);
private: private:
typedef std::deque<Account*> Accounts; typedef std::deque<Account*> Accounts;

View File

@ -313,8 +313,8 @@ void Squawk::onRosterContextMenu(const QPoint& point)
Models::Contact* cnt = static_cast<Models::Contact*>(item); Models::Contact* cnt = static_cast<Models::Contact*>(item);
hasMenu = true; hasMenu = true;
QAction* remove = contextMenu->addAction(QIcon::fromTheme("mail-message"), "Open dialog"); QAction* dialog = contextMenu->addAction(QIcon::fromTheme("mail-message"), "Open dialog");
connect(remove, &QAction::triggered, [this, index]() { connect(dialog, &QAction::triggered, [this, index]() {
onRosterItemDoubleClicked(index); onRosterItemDoubleClicked(index);
}); });
@ -322,8 +322,8 @@ void Squawk::onRosterContextMenu(const QPoint& point)
switch (state) { switch (state) {
case Shared::both: case Shared::both:
case Shared::to: { case Shared::to: {
QAction* remove = contextMenu->addAction(QIcon::fromTheme("news-unsubscribe"), "Unsubscribe"); QAction* unsub = contextMenu->addAction(QIcon::fromTheme("news-unsubscribe"), "Unsubscribe");
connect(remove, &QAction::triggered, [this, cnt]() { connect(unsub, &QAction::triggered, [this, cnt]() {
emit unsubscribeContact(cnt->getAccountName(), cnt->getJid(), ""); emit unsubscribeContact(cnt->getAccountName(), cnt->getJid(), "");
}); });
} }
@ -331,13 +331,18 @@ void Squawk::onRosterContextMenu(const QPoint& point)
case Shared::from: case Shared::from:
case Shared::unknown: case Shared::unknown:
case Shared::none: { case Shared::none: {
QAction* remove = contextMenu->addAction(QIcon::fromTheme("news-subscribe"), "Subscribe"); QAction* sub = contextMenu->addAction(QIcon::fromTheme("news-subscribe"), "Subscribe");
connect(remove, &QAction::triggered, [this, cnt]() { connect(sub, &QAction::triggered, [this, cnt]() {
emit subscribeContact(cnt->getAccountName(), cnt->getJid(), ""); emit subscribeContact(cnt->getAccountName(), cnt->getJid(), "");
}); });
} }
} }
QAction* remove = contextMenu->addAction(QIcon::fromTheme("edit-delete"), "Remove");
connect(remove, &QAction::triggered, [this, cnt]() {
emit removeContactRequest(cnt->getAccountName(), cnt->getJid());
});
} }
break; break;
default: default:

View File

@ -37,6 +37,7 @@ signals:
void requestArchive(const QString& account, const QString& jid, int count, const QString& before); void requestArchive(const QString& account, const QString& jid, int count, const QString& before);
void subscribeContact(const QString& account, const QString& jid, const QString& reason); void subscribeContact(const QString& account, const QString& jid, const QString& reason);
void unsubscribeContact(const QString& account, const QString& jid, const QString& reason); void unsubscribeContact(const QString& account, const QString& jid, const QString& reason);
void removeContactRequest(const QString& account, const QString& jid);
public slots: public slots:
void newAccount(const QMap<QString, QVariant>& account); void newAccount(const QMap<QString, QVariant>& account);