1
0
forked from blue/squawk

Renaming contacts in roster, set 2 reconnects by default

This commit is contained in:
Blue 2019-10-01 11:47:40 +03:00
parent 415d56ba69
commit 475a12c28e
7 changed files with 52 additions and 2 deletions

View File

@ -1200,3 +1200,14 @@ void Core::Account::removeContactFromGroupRequest(const QString& jid, const QStr
} }
} }
} }
void Core::Account::renameContactRequest(const QString& jid, const QString& newName)
{
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
if (itr == contacts.end()) {
qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping";
} else {
QXmppRosterManager& rm = client.rosterManager();
rm.renameItem(jid, newName);
}
}

View File

@ -72,6 +72,7 @@ public:
void addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups); void addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups);
void addContactToGroupRequest(const QString& jid, const QString& groupName); void addContactToGroupRequest(const QString& jid, const QString& groupName);
void removeContactFromGroupRequest(const QString& jid, const QString& groupName); void removeContactFromGroupRequest(const QString& jid, const QString& groupName);
void renameContactRequest(const QString& jid, const QString& newName);
void setRoomJoined(const QString& jid, bool joined); void setRoomJoined(const QString& jid, bool joined);
void setRoomAutoJoin(const QString& jid, bool joined); void setRoomAutoJoin(const QString& jid, bool joined);

View File

@ -101,8 +101,12 @@ void Core::Squawk::newAccountRequest(const QMap<QString, QVariant>& map)
void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource) void Core::Squawk::addAccount(const QString& login, const QString& server, const QString& password, const QString& name, const QString& resource)
{ {
QSettings settings;
unsigned int reconnects = settings.value("reconnects", 2).toUInt();
Account* acc = new Account(login, server, password, name); Account* acc = new Account(login, server, password, name);
acc->setResource(resource); acc->setResource(resource);
acc->setReconnectTimes(reconnects);
accounts.push_back(acc); accounts.push_back(acc);
amap.insert(std::make_pair(name, acc)); amap.insert(std::make_pair(name, acc));
@ -518,3 +522,13 @@ void Core::Squawk::removeContactFromGroupRequest(const QString& account, const Q
} }
itr->second->removeContactFromGroupRequest(jid, groupName); itr->second->removeContactFromGroupRequest(jid, groupName);
} }
void Core::Squawk::renameContactRequest(const QString& account, const QString& jid, const QString& newName)
{
AccountsMap::const_iterator itr = amap.find(account);
if (itr == amap.end()) {
qDebug() << "An attempt to rename contact" << jid << "of existing account" << account << ", skipping";
return;
}
itr->second->renameContactRequest(jid, newName);
}

View File

@ -82,6 +82,7 @@ public slots:
void addContactToGroupRequest(const QString& account, const QString& jid, const QString& groupName); void addContactToGroupRequest(const QString& account, const QString& jid, const QString& groupName);
void removeContactFromGroupRequest(const QString& account, const QString& jid, const QString& groupName); void removeContactFromGroupRequest(const QString& account, const QString& jid, const QString& groupName);
void removeContactRequest(const QString& account, const QString& jid); void removeContactRequest(const QString& account, const QString& jid);
void renameContactRequest(const QString& account, const QString& jid, const QString& newName);
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups); void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
void setRoomJoined(const QString& account, const QString& jid, bool joined); void setRoomJoined(const QString& account, const QString& jid, bool joined);
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined); void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);

View File

@ -91,6 +91,7 @@ int main(int argc, char *argv[])
QObject::connect(&w, SIGNAL(downloadFileRequest(const QString&, const QString&)), squawk, SLOT(downloadFileRequest(const QString&, const QString&))); QObject::connect(&w, SIGNAL(downloadFileRequest(const QString&, const QString&)), squawk, SLOT(downloadFileRequest(const QString&, const QString&)));
QObject::connect(&w, &Squawk::addContactToGroupRequest, squawk, &Core::Squawk::addContactToGroupRequest); QObject::connect(&w, &Squawk::addContactToGroupRequest, squawk, &Core::Squawk::addContactToGroupRequest);
QObject::connect(&w, &Squawk::removeContactFromGroupRequest, squawk, &Core::Squawk::removeContactFromGroupRequest); QObject::connect(&w, &Squawk::removeContactFromGroupRequest, squawk, &Core::Squawk::removeContactFromGroupRequest);
QObject::connect(&w, &Squawk::renameContactRequest, squawk, &Core::Squawk::renameContactRequest);
QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&))); QObject::connect(squawk, SIGNAL(newAccount(const QMap<QString, QVariant>&)), &w, SLOT(newAccount(const QMap<QString, QVariant>&)));
QObject::connect(squawk, SIGNAL(addContact(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)), QObject::connect(squawk, SIGNAL(addContact(const QString&, const QString&, const QString&, const QMap<QString, QVariant>&)),

View File

@ -578,10 +578,31 @@ void Squawk::onRosterContextMenu(const QPoint& point)
}); });
} }
} }
QMenu* groupsMenu = contextMenu->addMenu(Shared::icon("group"), "Groups");
QString accName = cnt->getAccountName(); QString accName = cnt->getAccountName();
QString cntJID = cnt->getJid(); QString cntJID = cnt->getJid();
QString cntName = cnt->getName();
QAction* rename = contextMenu->addAction(Shared::icon("edit-rename"), "Rename");
rename->setEnabled(active);
connect(rename, &QAction::triggered, [this, cntName, accName, cntJID]() {
QInputDialog* dialog = new QInputDialog(this);
connect(dialog, &QDialog::accepted, [this, dialog, cntName, accName, cntJID]() {
QString newName = dialog->textValue();
if (newName != cntName) {
emit renameContactRequest(accName, cntJID, newName);
}
dialog->deleteLater();
});
connect(dialog, &QDialog::rejected, dialog, &QObject::deleteLater);
dialog->setInputMode(QInputDialog::TextInput);
dialog->setLabelText("Input new name for " + cntJID + " \nor leave it empty for the contact \nto be displayed as " + cntJID);
dialog->setWindowTitle("Renaming " + cntJID);
dialog->setTextValue(cntName);
dialog->exec();
});
QMenu* groupsMenu = contextMenu->addMenu(Shared::icon("group"), "Groups");
std::deque<QString> groupList = rosterModel.groupList(accName); std::deque<QString> groupList = rosterModel.groupList(accName);
for (QString groupName : groupList) { for (QString groupName : groupList) {
QAction* gr = groupsMenu->addAction(groupName); QAction* gr = groupsMenu->addAction(groupName);

View File

@ -64,6 +64,7 @@ signals:
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups); void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
void addContactToGroupRequest(const QString& account, const QString& jid, const QString& groupName); void addContactToGroupRequest(const QString& account, const QString& jid, const QString& groupName);
void removeContactFromGroupRequest(const QString& account, const QString& jid, const QString& groupName); void removeContactFromGroupRequest(const QString& account, const QString& jid, const QString& groupName);
void renameContactRequest(const QString& account, const QString& jid, const QString& newName);
void setRoomJoined(const QString& account, const QString& jid, bool joined); void setRoomJoined(const QString& account, const QString& jid, bool joined);
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined); void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);
void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin); void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin);