forked from blue/squawk
basic avatar/vcard changes uploads and roster reaction
This commit is contained in:
parent
652381b067
commit
36c71968bc
@ -103,15 +103,15 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||||||
if (!avatar->exists()) {
|
if (!avatar->exists()) {
|
||||||
delete avatar;
|
delete avatar;
|
||||||
avatar = new QFile(path + "/avatar.jpg");
|
avatar = new QFile(path + "/avatar.jpg");
|
||||||
QString type = "jpg";
|
type = "jpg";
|
||||||
if (!avatar->exists()) {
|
if (!avatar->exists()) {
|
||||||
delete avatar;
|
delete avatar;
|
||||||
avatar = new QFile(path + "/avatar.jpeg");
|
avatar = new QFile(path + "/avatar.jpeg");
|
||||||
QString type = "jpeg";
|
type = "jpeg";
|
||||||
if (!avatar->exists()) {
|
if (!avatar->exists()) {
|
||||||
delete avatar;
|
delete avatar;
|
||||||
avatar = new QFile(path + "/avatar.gif");
|
avatar = new QFile(path + "/avatar.gif");
|
||||||
QString type = "gif";
|
type = "gif";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1337,7 +1337,6 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card)
|
|||||||
if (confItr == conferences.end()) {
|
if (confItr == conferences.end()) {
|
||||||
if (jid == getLogin() + "@" + getServer()) {
|
if (jid == getLogin() + "@" + getServer()) {
|
||||||
onOwnVCardReceived(card);
|
onOwnVCardReceived(card);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "received vCard" << jid << "doesn't belong to any of known contacts or conferences, skipping";
|
qDebug() << "received vCard" << jid << "doesn't belong to any of known contacts or conferences, skipping";
|
||||||
}
|
}
|
||||||
@ -1375,13 +1374,18 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card)
|
|||||||
vCard.setAvatarType(Shared::Avatar::empty);
|
vCard.setAvatarType(Shared::Avatar::empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<QString, QVariant> cd = {
|
||||||
|
{"avatarState", static_cast<quint8>(vCard.getAvatarType())},
|
||||||
|
{"avatarPath", vCard.getAvatarPath()}
|
||||||
|
};
|
||||||
|
emit changeContact(jid, cd);
|
||||||
emit receivedVCard(jid, vCard);
|
emit receivedVCard(jid, vCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
||||||
{
|
{
|
||||||
QByteArray ava = card.photo();
|
QByteArray ava = card.photo();
|
||||||
bool changed = false;
|
bool avaChanged = false;
|
||||||
QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + name + "/";
|
QString path = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + name + "/";
|
||||||
if (ava.size() > 0) {
|
if (ava.size() > 0) {
|
||||||
QCryptographicHash sha1(QCryptographicHash::Sha1);
|
QCryptographicHash sha1(QCryptographicHash::Sha1);
|
||||||
@ -1407,7 +1411,7 @@ void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
|||||||
newAvatar.close();
|
newAvatar.close();
|
||||||
avatarHash = newHash;
|
avatarHash = newHash;
|
||||||
avatarType = newType.preferredSuffix();
|
avatarType = newType.preferredSuffix();
|
||||||
changed = true;
|
avaChanged = true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Received new avatar for account" << name << "but can't save it";
|
qDebug() << "Received new avatar for account" << name << "but can't save it";
|
||||||
if (oldToRemove) {
|
if (oldToRemove) {
|
||||||
@ -1425,7 +1429,7 @@ void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
|||||||
newAvatar.close();
|
newAvatar.close();
|
||||||
avatarHash = newHash;
|
avatarHash = newHash;
|
||||||
avatarType = newType.preferredSuffix();
|
avatarType = newType.preferredSuffix();
|
||||||
changed = true;
|
avaChanged = true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Received new avatar for account" << name << "but can't save it";
|
qDebug() << "Received new avatar for account" << name << "but can't save it";
|
||||||
}
|
}
|
||||||
@ -1436,12 +1440,14 @@ void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
|||||||
if (!oldAvatar.remove()) {
|
if (!oldAvatar.remove()) {
|
||||||
qDebug() << "Received vCard for account" << name << "without avatar, but can't get rid of the file, doing nothing";
|
qDebug() << "Received vCard for account" << name << "without avatar, but can't get rid of the file, doing nothing";
|
||||||
} else {
|
} else {
|
||||||
changed = true;
|
avatarType = "";
|
||||||
|
avatarHash = "";
|
||||||
|
avaChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) {
|
if (avaChanged) {
|
||||||
QMap<QString, QVariant> change;
|
QMap<QString, QVariant> change;
|
||||||
if (avatarType.size() > 0) {
|
if (avatarType.size() > 0) {
|
||||||
presence.setPhotoHash(avatarHash.toUtf8());
|
presence.setPhotoHash(avatarHash.toUtf8());
|
||||||
@ -1453,6 +1459,7 @@ void Core::Account::onOwnVCardReceived(const QXmppVCardIq& card)
|
|||||||
change.insert("avatarPath", "");
|
change.insert("avatarPath", "");
|
||||||
}
|
}
|
||||||
client.setClientPresence(presence);
|
client.setClientPresence(presence);
|
||||||
|
emit changed(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
ownVCardRequestInProgress = false;
|
ownVCardRequestInProgress = false;
|
||||||
@ -1504,3 +1511,66 @@ void Core::Account::requestVCard(const QString& jid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::Account::uploadVCard(const Shared::VCard& card)
|
||||||
|
{
|
||||||
|
QXmppVCardIq iq;
|
||||||
|
iq.setFirstName(card.getFirstName());
|
||||||
|
iq.setMiddleName(card.getMiddleName());
|
||||||
|
iq.setLastName(card.getLastName());
|
||||||
|
iq.setNickName(card.getNickName());
|
||||||
|
iq.setBirthday(card.getBirthday());
|
||||||
|
iq.setDescription(card.getDescription());
|
||||||
|
|
||||||
|
bool avatarChanged = false;
|
||||||
|
if (card.getAvatarType() == Shared::Avatar::empty) {
|
||||||
|
if (avatarType.size() > 0) {
|
||||||
|
avatarChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QString newPath = card.getAvatarPath();
|
||||||
|
QString oldPath = getAvatarPath();
|
||||||
|
QByteArray data;
|
||||||
|
QString type;
|
||||||
|
if (newPath != oldPath) {
|
||||||
|
QFile avatar(newPath);
|
||||||
|
if (!avatar.open(QFile::ReadOnly)) {
|
||||||
|
qDebug() << "An attempt to upload new vCard to account" << name
|
||||||
|
<< "but it wasn't possible to read file" << newPath
|
||||||
|
<< "which was supposed to be new avatar, uploading old avatar";
|
||||||
|
if (avatarType.size() > 0) {
|
||||||
|
QFile oA(oldPath);
|
||||||
|
if (!oA.open(QFile::ReadOnly)) {
|
||||||
|
qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar";
|
||||||
|
avatarChanged = true;
|
||||||
|
} else {
|
||||||
|
data = oA.readAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data = avatar.readAll();
|
||||||
|
avatarChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (avatarType.size() > 0) {
|
||||||
|
QFile oA(oldPath);
|
||||||
|
if (!oA.open(QFile::ReadOnly)) {
|
||||||
|
qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar";
|
||||||
|
avatarChanged = true;
|
||||||
|
} else {
|
||||||
|
data = oA.readAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.size() > 0) {
|
||||||
|
QMimeDatabase db;
|
||||||
|
type = db.mimeTypeForData(data).name();
|
||||||
|
iq.setPhoto(data);
|
||||||
|
iq.setPhotoType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
client.vCardManager().setClientVCard(iq);
|
||||||
|
onOwnVCardReceived(iq);
|
||||||
|
}
|
||||||
|
@ -88,6 +88,7 @@ public:
|
|||||||
void removeRoomRequest(const QString& jid);
|
void removeRoomRequest(const QString& jid);
|
||||||
void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin);
|
void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin);
|
||||||
void requestVCard(const QString& jid);
|
void requestVCard(const QString& jid);
|
||||||
|
void uploadVCard(const Shared::VCard& card);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(const QMap<QString, QVariant>& data);
|
void changed(const QMap<QString, QVariant>& data);
|
||||||
|
@ -543,3 +543,13 @@ void Core::Squawk::requestVCard(const QString& account, const QString& jid)
|
|||||||
}
|
}
|
||||||
itr->second->requestVCard(jid);
|
itr->second->requestVCard(jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::Squawk::uploadVCard(const QString& account, const Shared::VCard& card)
|
||||||
|
{
|
||||||
|
AccountsMap::const_iterator itr = amap.find(account);
|
||||||
|
if (itr == amap.end()) {
|
||||||
|
qDebug() << "An attempt to upload vcard to non existing account" << account << ", skipping";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
itr->second->uploadVCard(card);
|
||||||
|
}
|
||||||
|
@ -93,6 +93,7 @@ public slots:
|
|||||||
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
void fileLocalPathRequest(const QString& messageId, const QString& url);
|
||||||
void downloadFileRequest(const QString& messageId, const QString& url);
|
void downloadFileRequest(const QString& messageId, const QString& url);
|
||||||
void requestVCard(const QString& account, const QString& jid);
|
void requestVCard(const QString& account, const QString& jid);
|
||||||
|
void uploadVCard(const QString& account, const Shared::VCard& card);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::deque<Account*> Accounts;
|
typedef std::deque<Account*> Accounts;
|
||||||
|
1
global.h
1
global.h
@ -437,6 +437,7 @@ static const std::map<QString, std::pair<QString, QString>> icons = {
|
|||||||
{"view-refresh", {"view-refresh", "view-refresh"}},
|
{"view-refresh", {"view-refresh", "view-refresh"}},
|
||||||
{"send", {"document-send", "send"}},
|
{"send", {"document-send", "send"}},
|
||||||
{"clean", {"edit-clear-all", "clean"}},
|
{"clean", {"edit-clear-all", "clean"}},
|
||||||
|
{"user", {"user", "user"}},
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
1
main.cpp
1
main.cpp
@ -106,6 +106,7 @@ int main(int argc, char *argv[])
|
|||||||
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(&w, &Squawk::renameContactRequest, squawk, &Core::Squawk::renameContactRequest);
|
||||||
QObject::connect(&w, &Squawk::requestVCard, squawk, &Core::Squawk::requestVCard);
|
QObject::connect(&w, &Squawk::requestVCard, squawk, &Core::Squawk::requestVCard);
|
||||||
|
QObject::connect(&w, &Squawk::uploadVCard, squawk, &Core::Squawk::uploadVCard);
|
||||||
|
|
||||||
QObject::connect(squawk, &Core::Squawk::newAccount, &w, &Squawk::newAccount);
|
QObject::connect(squawk, &Core::Squawk::newAccount, &w, &Squawk::newAccount);
|
||||||
QObject::connect(squawk, &Core::Squawk::addContact, &w, &Squawk::addContact);
|
QObject::connect(squawk, &Core::Squawk::addContact, &w, &Squawk::addContact);
|
||||||
|
@ -98,6 +98,7 @@ QVariant Models::Roster::data (const QModelIndex& index, int role) const
|
|||||||
result = acc->getStatusIcon(false);
|
result = acc->getStatusIcon(false);
|
||||||
} else if (col == 1) {
|
} else if (col == 1) {
|
||||||
QString path = acc->getAvatarPath();
|
QString path = acc->getAvatarPath();
|
||||||
|
|
||||||
if (path.size() > 0) {
|
if (path.size() > 0) {
|
||||||
result = QIcon(path);
|
result = QIcon(path);
|
||||||
}
|
}
|
||||||
@ -641,7 +642,8 @@ void Models::Roster::removeContact(const QString& account, const QString& jid, c
|
|||||||
void Models::Roster::onChildChanged(Models::Item* item, int row, int col)
|
void Models::Roster::onChildChanged(Models::Item* item, int row, int col)
|
||||||
{
|
{
|
||||||
QModelIndex index = createIndex(row, 0, item);
|
QModelIndex index = createIndex(row, 0, item);
|
||||||
emit dataChanged(index, index);
|
QModelIndex index2 = createIndex(row, 1, item);
|
||||||
|
emit dataChanged(index, index2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Models::Roster::onChildIsAboutToBeInserted(Models::Item* parent, int first, int last)
|
void Models::Roster::onChildIsAboutToBeInserted(Models::Item* parent, int first, int last)
|
||||||
|
@ -66,7 +66,7 @@ VCard::VCard(const QString& jid, bool edit, QWidget* parent):
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted);
|
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &VCard::onButtonBoxAccepted);
|
||||||
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, m_ui->buttonBox, &QDialogButtonBox::deleteLater);
|
connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &VCard::close);
|
||||||
|
|
||||||
avatarButtonMargins = m_ui->avatarButton->size();
|
avatarButtonMargins = m_ui->avatarButton->size();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user