1
0
forked from blue/squawk

uploading multiple messages fix, some warnings fix

This commit is contained in:
Blue 2019-11-17 13:24:12 +03:00
parent 0c33d81c59
commit fe27955689
14 changed files with 51 additions and 56 deletions

View File

@ -1103,6 +1103,8 @@ void Core::Account::onClientError(QXmppClient::Error err)
case QXmppClient::KeepAliveError: case QXmppClient::KeepAliveError:
errorText = "Client keep alive error"; errorText = "Client keep alive error";
break; break;
case QXmppClient::NoError:
break; //not exactly sure what to do here
} }
qDebug() << errorType << errorText; qDebug() << errorType << errorText;
@ -1565,11 +1567,7 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
initializeQXmppVCard(iq, card); initializeQXmppVCard(iq, card);
bool avatarChanged = false; bool avatarChanged = false;
if (card.getAvatarType() == Shared::Avatar::empty) { if (card.getAvatarType() != Shared::Avatar::empty) {
if (avatarType.size() > 0) {
avatarChanged = true;
}
} else {
QString newPath = card.getAvatarPath(); QString newPath = card.getAvatarPath();
QString oldPath = getAvatarPath(); QString oldPath = getAvatarPath();
QByteArray data; QByteArray data;
@ -1584,7 +1582,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
QFile oA(oldPath); QFile oA(oldPath);
if (!oA.open(QFile::ReadOnly)) { if (!oA.open(QFile::ReadOnly)) {
qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar"; qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar";
avatarChanged = true;
} else { } else {
data = oA.readAll(); data = oA.readAll();
} }
@ -1598,7 +1595,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card)
QFile oA(oldPath); QFile oA(oldPath);
if (!oA.open(QFile::ReadOnly)) { if (!oA.open(QFile::ReadOnly)) {
qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar"; qDebug() << "Couldn't read old avatar of account" << name << ", uploading empty avatar";
avatarChanged = true;
} else { } else {
data = oA.readAll(); data = oA.readAll();
} }

View File

@ -74,18 +74,18 @@ void Core::Archive::open(const QString& account)
mdb_txn_begin(environment, NULL, 0, &txn); mdb_txn_begin(environment, NULL, 0, &txn);
try { try {
fromTheBeginning = getStatBoolValue("beginning", txn); fromTheBeginning = getStatBoolValue("beginning", txn);
} catch (NotFound e) { } catch (const NotFound& e) {
fromTheBeginning = false; fromTheBeginning = false;
} }
try { try {
hasAvatar = getStatBoolValue("hasAvatar", txn); hasAvatar = getStatBoolValue("hasAvatar", txn);
} catch (NotFound e) { } catch (const NotFound& e) {
hasAvatar = false; hasAvatar = false;
} }
if (hasAvatar) { if (hasAvatar) {
try { try {
avatarAutoGenerated = getStatBoolValue("avatarAutoGenerated", txn); avatarAutoGenerated = getStatBoolValue("avatarAutoGenerated", txn);
} catch (NotFound e) { } catch (const NotFound& e) {
avatarAutoGenerated = false; avatarAutoGenerated = false;
} }
@ -346,8 +346,7 @@ long unsigned int Core::Archive::size() const
throw Closed("size", jid.toStdString()); throw Closed("size", jid.toStdString());
} }
MDB_txn *txn; MDB_txn *txn;
int rc; mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
MDB_stat stat; MDB_stat stat;
mdb_stat(txn, order, &stat); mdb_stat(txn, order, &stat);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -473,13 +472,12 @@ void Core::Archive::printOrder()
{ {
qDebug() << "Printing order"; qDebug() << "Printing order";
MDB_txn *txn; MDB_txn *txn;
int rc; mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
MDB_cursor* cursor; MDB_cursor* cursor;
rc = mdb_cursor_open(txn, order, &cursor); mdb_cursor_open(txn, order, &cursor);
MDB_val lmdbKey, lmdbData; MDB_val lmdbKey, lmdbData;
rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST);
do { do {
std::string sId((char*)lmdbData.mv_data, lmdbData.mv_size); std::string sId((char*)lmdbData.mv_data, lmdbData.mv_size);
@ -493,13 +491,12 @@ void Core::Archive::printOrder()
void Core::Archive::printKeys() void Core::Archive::printKeys()
{ {
MDB_txn *txn; MDB_txn *txn;
int rc; mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn);
MDB_cursor* cursor; MDB_cursor* cursor;
rc = mdb_cursor_open(txn, main, &cursor); mdb_cursor_open(txn, main, &cursor);
MDB_val lmdbKey, lmdbData; MDB_val lmdbKey, lmdbData;
rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST);
do { do {
std::string sId((char*)lmdbKey.mv_data, lmdbKey.mv_size); std::string sId((char*)lmdbKey.mv_data, lmdbKey.mv_size);
@ -540,7 +537,6 @@ bool Core::Archive::getStatBoolValue(const std::string& id, MDB_txn* txn)
std::string Core::Archive::getStatStringValue(const std::string& id, MDB_txn* txn) std::string Core::Archive::getStatStringValue(const std::string& id, MDB_txn* txn)
{ {
MDB_cursor* cursor;
MDB_val lmdbKey, lmdbData; MDB_val lmdbKey, lmdbData;
lmdbKey.mv_size = id.size(); lmdbKey.mv_size = id.size();
lmdbKey.mv_data = (char*)id.c_str(); lmdbKey.mv_data = (char*)id.c_str();

View File

@ -53,9 +53,9 @@ void Core::NetworkAccess::fileLocalPathRequest(const QString& messageId, const Q
files.removeRecord(url); files.removeRecord(url);
emit fileLocalPathResponse(messageId, ""); emit fileLocalPathResponse(messageId, "");
} }
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
emit fileLocalPathResponse(messageId, ""); emit fileLocalPathResponse(messageId, "");
} catch (Archive::Unknown e) { } catch (const Archive::Unknown& e) {
qDebug() << "Error requesting file path:" << e.what(); qDebug() << "Error requesting file path:" << e.what();
emit fileLocalPathResponse(messageId, ""); emit fileLocalPathResponse(messageId, "");
} }
@ -82,9 +82,9 @@ void Core::NetworkAccess::downladFileRequest(const QString& messageId, const QSt
files.removeRecord(url); files.removeRecord(url);
startDownload(messageId, url); startDownload(messageId, url);
} }
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
startDownload(messageId, url); startDownload(messageId, url);
} catch (Archive::Unknown e) { } catch (const Archive::Unknown& e) {
qDebug() << "Error requesting file path:" << e.what(); qDebug() << "Error requesting file path:" << e.what();
emit downloadFileError(messageId, QString("Database error: ") + e.what()); emit downloadFileError(messageId, QString("Database error: ") + e.what());
} }
@ -454,9 +454,9 @@ void Core::NetworkAccess::uploadFileRequest(const QString& messageId, const QStr
startUpload(messageId, url, path); startUpload(messageId, url, path);
} }
} }
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
startUpload(messageId, url, path); startUpload(messageId, url, path);
} catch (Archive::Unknown e) { } catch (const Archive::Unknown& e) {
qDebug() << "Error requesting file path on upload:" << e.what(); qDebug() << "Error requesting file path on upload:" << e.what();
emit uploadFileError(messageId, QString("Database error: ") + e.what()); emit uploadFileError(messageId, QString("Database error: ") + e.what());
} }

View File

@ -141,11 +141,11 @@ void Core::RosterItem::performRequest(int count, const QString& before)
std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), lBefore); std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), lBefore);
responseCache.insert(responseCache.begin(), arc.begin(), arc.end()); responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
found = true; found = true;
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
requestCache.emplace_back(requestedCount, before); requestCache.emplace_back(requestedCount, before);
requestedCount = -1; requestedCount = -1;
emit needHistory(archive->oldestId(), ""); emit needHistory(archive->oldestId(), "");
} catch (Archive::Empty e) { } catch (const Archive::Empty& e) {
requestCache.emplace_back(requestedCount, before); requestCache.emplace_back(requestedCount, before);
requestedCount = -1; requestedCount = -1;
emit needHistory(archive->oldestId(), ""); emit needHistory(archive->oldestId(), "");
@ -171,9 +171,9 @@ void Core::RosterItem::performRequest(int count, const QString& before)
try { try {
std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), before); std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), before);
responseCache.insert(responseCache.begin(), arc.begin(), arc.end()); responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
qDebug("requesting id hasn't been found in archive, skipping"); qDebug("requesting id hasn't been found in archive, skipping");
} catch (Archive::Empty e) { } catch (const Archive::Empty& e) {
qDebug("requesting id hasn't been found in archive, skipping"); qDebug("requesting id hasn't been found in archive, skipping");
} }
nextRequest(); nextRequest();
@ -254,6 +254,7 @@ void Core::RosterItem::flushMessagesToArchive(bool finished, const QString& firs
case empty: case empty:
wasEmpty = true; wasEmpty = true;
archiveState = end; archiveState = end;
[[fallthrough]];
case end: case end:
added += archive->addElements(appendCache); added += archive->addElements(appendCache);
appendCache.clear(); appendCache.clear();
@ -274,9 +275,9 @@ void Core::RosterItem::flushMessagesToArchive(bool finished, const QString& firs
std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), before); std::list<Shared::Message> arc = archive->getBefore(requestedCount - responseCache.size(), before);
responseCache.insert(responseCache.begin(), arc.begin(), arc.end()); responseCache.insert(responseCache.begin(), arc.begin(), arc.end());
found = true; found = true;
} catch (Archive::NotFound e) { } catch (const Archive::NotFound& e) {
} catch (Archive::Empty e) { } catch (const Archive::Empty& e) {
} }
if (!found || requestedCount > responseCache.size()) { if (!found || requestedCount > responseCache.size()) {

View File

@ -51,7 +51,7 @@ void Core::Squawk::stop()
QSettings settings; QSettings settings;
settings.beginGroup("core"); settings.beginGroup("core");
settings.beginWriteArray("accounts"); settings.beginWriteArray("accounts");
for (int i = 0; i < accounts.size(); ++i) { for (std::deque<Account*>::size_type i = 0; i < accounts.size(); ++i) {
settings.setArrayIndex(i); settings.setArrayIndex(i);
Account* acc = accounts[i]; Account* acc = accounts[i];
settings.setValue("name", acc->getName()); settings.setValue("name", acc->getName());

View File

@ -322,7 +322,7 @@ void Models::Contact::getMessages(Models::Contact::Messages& container) const
void Models::Contact::toOfflineState() void Models::Contact::toOfflineState()
{ {
emit childIsAboutToBeRemoved(this, 0, childItems.size()); emit childIsAboutToBeRemoved(this, 0, childItems.size());
for (int i = 0; i < childItems.size(); ++i) { for (std::deque<Item*>::size_type i = 0; i < childItems.size(); ++i) {
Item* item = childItems[i]; Item* item = childItems[i];
disconnect(item, &Item::childChanged, this, &Contact::refresh); disconnect(item, &Item::childChanged, this, &Contact::refresh);
Item::_removeChild(i); Item::_removeChild(i);

View File

@ -236,7 +236,7 @@ void Models::Room::getMessages(Models::Room::Messages& container) const
void Models::Room::toOfflineState() void Models::Room::toOfflineState()
{ {
emit childIsAboutToBeRemoved(this, 0, childItems.size()); emit childIsAboutToBeRemoved(this, 0, childItems.size());
for (int i = 0; i < childItems.size(); ++i) { for (std::deque<Item*>::size_type i = 0; i < childItems.size(); ++i) {
Item* item = childItems[i]; Item* item = childItems[i];
Item::_removeChild(i); Item::_removeChild(i);
item->deleteLater(); item->deleteLater();

View File

@ -518,7 +518,7 @@ void Models::Roster::removeGroup(const QString& account, const QString& name)
if (toInsert.size() > 0) { if (toInsert.size() > 0) {
Account* acc = accounts.find("account")->second; Account* acc = accounts.find("account")->second;
for (int i = 0; i < toInsert.size(); ++i) { for (std::deque<Contact*>::size_type i = 0; i < toInsert.size(); ++i) {
Contact* cont = toInsert[i]; Contact* cont = toInsert[i];
acc->appendChild(cont); //TODO optimisation acc->appendChild(cont); //TODO optimisation
} }

View File

@ -111,7 +111,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc
} }
} }
messageIndex.insert(std::make_pair(id, message)); messageIndex.insert(std::make_pair(id, message));
int index = std::distance<Order::const_iterator>(messageOrder.begin(), result.first); //need to make with binary indexed tree unsigned long index = std::distance<Order::const_iterator>(messageOrder.begin(), result.first); //need to make with binary indexed tree
Position res = invalid; Position res = invalid;
if (index == 0) { if (index == 0) {
res = beggining; res = beggining;

View File

@ -24,6 +24,7 @@
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
#include <QFileDialog> #include <QFileDialog>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <unistd.h>
Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent): Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent):
QWidget(parent), QWidget(parent),
@ -205,6 +206,7 @@ void Conversation::onEnterPressed()
msg.generateRandomId(); msg.generateRandomId();
msg.setCurrentTime(); msg.setCurrentTime();
line->appendMessageWithUpload(msg, badge->id); line->appendMessageWithUpload(msg, badge->id);
usleep(1000); //this is required for the messages not to have equal time when appending into messageline
} }
clearAttachedFiles(); clearAttachedFiles();
} }

View File

@ -145,7 +145,7 @@ QModelIndex UI::VCard::EMailsModel::addNewEmptyLine()
return createIndex(deque.size() - 1, 0, &(deque.back())); return createIndex(deque.size() - 1, 0, &(deque.back()));
} }
bool UI::VCard::EMailsModel::isPreferred(int row) const bool UI::VCard::EMailsModel::isPreferred(quint32 row) const
{ {
if (row < deque.size()) { if (row < deque.size()) {
return deque[row].prefered; return deque[row].prefered;
@ -154,10 +154,10 @@ bool UI::VCard::EMailsModel::isPreferred(int row) const
} }
} }
void UI::VCard::EMailsModel::removeLines(int index, int count) void UI::VCard::EMailsModel::removeLines(quint32 index, quint32 count)
{ {
if (index < deque.size()) { if (index < deque.size()) {
int maxCount = deque.size() - index; quint32 maxCount = deque.size() - index;
if (count > maxCount) { if (count > maxCount) {
count = maxCount; count = maxCount;
} }
@ -194,12 +194,12 @@ void UI::VCard::EMailsModel::setEmails(const std::deque<Shared::VCard::Email>& e
} }
} }
void UI::VCard::EMailsModel::revertPreferred(int row) void UI::VCard::EMailsModel::revertPreferred(quint32 row)
{ {
setData(createIndex(row, 2), !isPreferred(row)); setData(createIndex(row, 2), !isPreferred(row));
} }
QString UI::VCard::EMailsModel::getEmail(int row) const QString UI::VCard::EMailsModel::getEmail(quint32 row) const
{ {
return deque[row].address; return deque[row].address;
} }

View File

@ -40,16 +40,16 @@ public:
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool isPreferred(int row) const; bool isPreferred(quint32 row) const;
void removeLines(int index, int count); void removeLines(quint32 index, quint32 count);
void setEmails(const std::deque<Shared::VCard::Email>& emails); void setEmails(const std::deque<Shared::VCard::Email>& emails);
void getEmails(std::deque<Shared::VCard::Email>& emails) const; void getEmails(std::deque<Shared::VCard::Email>& emails) const;
QString getEmail(int row) const; QString getEmail(quint32 row) const;
public slots: public slots:
QModelIndex addNewEmptyLine(); QModelIndex addNewEmptyLine();
void revertPreferred(int row); void revertPreferred(quint32 row);
private: private:
bool edit; bool edit;

View File

@ -129,7 +129,7 @@ void UI::VCard::PhonesModel::getPhones(std::deque<Shared::VCard::Phone>& phones)
} }
} }
bool UI::VCard::PhonesModel::isPreferred(int row) const bool UI::VCard::PhonesModel::isPreferred(quint32 row) const
{ {
if (row < deque.size()) { if (row < deque.size()) {
return deque[row].prefered; return deque[row].prefered;
@ -138,10 +138,10 @@ bool UI::VCard::PhonesModel::isPreferred(int row) const
} }
} }
void UI::VCard::PhonesModel::removeLines(int index, int count) void UI::VCard::PhonesModel::removeLines(quint32 index, quint32 count)
{ {
if (index < deque.size()) { if (index < deque.size()) {
int maxCount = deque.size() - index; quint32 maxCount = deque.size() - index;
if (count > maxCount) { if (count > maxCount) {
count = maxCount; count = maxCount;
} }
@ -156,7 +156,7 @@ void UI::VCard::PhonesModel::removeLines(int index, int count)
} }
} }
void UI::VCard::PhonesModel::revertPreferred(int row) void UI::VCard::PhonesModel::revertPreferred(quint32 row)
{ {
setData(createIndex(row, 3), !isPreferred(row)); setData(createIndex(row, 3), !isPreferred(row));
} }
@ -216,7 +216,7 @@ void UI::VCard::PhonesModel::setPhones(const std::deque<Shared::VCard::Phone>& p
} }
} }
QString UI::VCard::PhonesModel::getPhone(int row) const QString UI::VCard::PhonesModel::getPhone(quint32 row) const
{ {
return deque[row].number; return deque[row].number;
} }

View File

@ -41,16 +41,16 @@ public:
int rowCount(const QModelIndex& parent) const override; int rowCount(const QModelIndex& parent) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool isPreferred(int row) const; bool isPreferred(quint32 row) const;
void removeLines(int index, int count); void removeLines(quint32 index, quint32 count);
void setPhones(const std::deque<Shared::VCard::Phone>& phones); void setPhones(const std::deque<Shared::VCard::Phone>& phones);
void getPhones(std::deque<Shared::VCard::Phone>& phones) const; void getPhones(std::deque<Shared::VCard::Phone>& phones) const;
QString getPhone(int row) const; QString getPhone(quint32 row) const;
public slots: public slots:
QModelIndex addNewEmptyLine(); QModelIndex addNewEmptyLine();
void revertPreferred(int row); void revertPreferred(quint32 row);
private: private:
bool edit; bool edit;