From fe279556894a5c68bf2a92871e66552e8b3fea53 Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 17 Nov 2019 13:24:12 +0300 Subject: [PATCH] uploading multiple messages fix, some warnings fix --- core/account.cpp | 10 +++------- core/archive.cpp | 24 ++++++++++-------------- core/networkaccess.cpp | 12 ++++++------ core/rosteritem.cpp | 13 +++++++------ core/squawk.cpp | 2 +- ui/models/contact.cpp | 2 +- ui/models/room.cpp | 2 +- ui/models/roster.cpp | 2 +- ui/utils/messageline.cpp | 2 +- ui/widgets/conversation.cpp | 2 ++ ui/widgets/vcard/emailsmodel.cpp | 10 +++++----- ui/widgets/vcard/emailsmodel.h | 8 ++++---- ui/widgets/vcard/phonesmodel.cpp | 10 +++++----- ui/widgets/vcard/phonesmodel.h | 8 ++++---- 14 files changed, 51 insertions(+), 56 deletions(-) diff --git a/core/account.cpp b/core/account.cpp index 492ebdc..6fb26a0 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -1103,6 +1103,8 @@ void Core::Account::onClientError(QXmppClient::Error err) case QXmppClient::KeepAliveError: errorText = "Client keep alive error"; break; + case QXmppClient::NoError: + break; //not exactly sure what to do here } qDebug() << errorType << errorText; @@ -1565,11 +1567,7 @@ void Core::Account::uploadVCard(const Shared::VCard& card) initializeQXmppVCard(iq, card); bool avatarChanged = false; - if (card.getAvatarType() == Shared::Avatar::empty) { - if (avatarType.size() > 0) { - avatarChanged = true; - } - } else { + if (card.getAvatarType() != Shared::Avatar::empty) { QString newPath = card.getAvatarPath(); QString oldPath = getAvatarPath(); QByteArray data; @@ -1584,7 +1582,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card) 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(); } @@ -1598,7 +1595,6 @@ void Core::Account::uploadVCard(const Shared::VCard& card) 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(); } diff --git a/core/archive.cpp b/core/archive.cpp index 5900df2..9b7c9eb 100644 --- a/core/archive.cpp +++ b/core/archive.cpp @@ -74,18 +74,18 @@ void Core::Archive::open(const QString& account) mdb_txn_begin(environment, NULL, 0, &txn); try { fromTheBeginning = getStatBoolValue("beginning", txn); - } catch (NotFound e) { + } catch (const NotFound& e) { fromTheBeginning = false; } try { hasAvatar = getStatBoolValue("hasAvatar", txn); - } catch (NotFound e) { + } catch (const NotFound& e) { hasAvatar = false; } if (hasAvatar) { try { avatarAutoGenerated = getStatBoolValue("avatarAutoGenerated", txn); - } catch (NotFound e) { + } catch (const NotFound& e) { avatarAutoGenerated = false; } @@ -346,8 +346,7 @@ long unsigned int Core::Archive::size() const throw Closed("size", jid.toStdString()); } MDB_txn *txn; - int rc; - rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); + mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); MDB_stat stat; mdb_stat(txn, order, &stat); mdb_txn_abort(txn); @@ -473,13 +472,12 @@ void Core::Archive::printOrder() { qDebug() << "Printing order"; MDB_txn *txn; - int rc; - rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); + mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); MDB_cursor* cursor; - rc = mdb_cursor_open(txn, order, &cursor); + mdb_cursor_open(txn, order, &cursor); MDB_val lmdbKey, lmdbData; - rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); + mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); do { std::string sId((char*)lmdbData.mv_data, lmdbData.mv_size); @@ -493,13 +491,12 @@ void Core::Archive::printOrder() void Core::Archive::printKeys() { MDB_txn *txn; - int rc; - rc = mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); + mdb_txn_begin(environment, NULL, MDB_RDONLY, &txn); MDB_cursor* cursor; - rc = mdb_cursor_open(txn, main, &cursor); + mdb_cursor_open(txn, main, &cursor); MDB_val lmdbKey, lmdbData; - rc = mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); + mdb_cursor_get(cursor, &lmdbKey, &lmdbData, MDB_FIRST); do { 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) { - MDB_cursor* cursor; MDB_val lmdbKey, lmdbData; lmdbKey.mv_size = id.size(); lmdbKey.mv_data = (char*)id.c_str(); diff --git a/core/networkaccess.cpp b/core/networkaccess.cpp index 2973a6c..a27ab8f 100644 --- a/core/networkaccess.cpp +++ b/core/networkaccess.cpp @@ -53,9 +53,9 @@ void Core::NetworkAccess::fileLocalPathRequest(const QString& messageId, const Q files.removeRecord(url); emit fileLocalPathResponse(messageId, ""); } - } catch (Archive::NotFound e) { + } catch (const Archive::NotFound& e) { emit fileLocalPathResponse(messageId, ""); - } catch (Archive::Unknown e) { + } catch (const Archive::Unknown& e) { qDebug() << "Error requesting file path:" << e.what(); emit fileLocalPathResponse(messageId, ""); } @@ -82,9 +82,9 @@ void Core::NetworkAccess::downladFileRequest(const QString& messageId, const QSt files.removeRecord(url); startDownload(messageId, url); } - } catch (Archive::NotFound e) { + } catch (const Archive::NotFound& e) { startDownload(messageId, url); - } catch (Archive::Unknown e) { + } catch (const Archive::Unknown& e) { qDebug() << "Error requesting file path:" << 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); } } - } catch (Archive::NotFound e) { + } catch (const Archive::NotFound& e) { startUpload(messageId, url, path); - } catch (Archive::Unknown e) { + } catch (const Archive::Unknown& e) { qDebug() << "Error requesting file path on upload:" << e.what(); emit uploadFileError(messageId, QString("Database error: ") + e.what()); } diff --git a/core/rosteritem.cpp b/core/rosteritem.cpp index f144901..ccc3072 100644 --- a/core/rosteritem.cpp +++ b/core/rosteritem.cpp @@ -141,11 +141,11 @@ void Core::RosterItem::performRequest(int count, const QString& before) std::list arc = archive->getBefore(requestedCount - responseCache.size(), lBefore); responseCache.insert(responseCache.begin(), arc.begin(), arc.end()); found = true; - } catch (Archive::NotFound e) { + } catch (const Archive::NotFound& e) { requestCache.emplace_back(requestedCount, before); requestedCount = -1; emit needHistory(archive->oldestId(), ""); - } catch (Archive::Empty e) { + } catch (const Archive::Empty& e) { requestCache.emplace_back(requestedCount, before); requestedCount = -1; emit needHistory(archive->oldestId(), ""); @@ -171,9 +171,9 @@ void Core::RosterItem::performRequest(int count, const QString& before) try { std::list arc = archive->getBefore(requestedCount - responseCache.size(), before); 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"); - } catch (Archive::Empty e) { + } catch (const Archive::Empty& e) { qDebug("requesting id hasn't been found in archive, skipping"); } nextRequest(); @@ -254,6 +254,7 @@ void Core::RosterItem::flushMessagesToArchive(bool finished, const QString& firs case empty: wasEmpty = true; archiveState = end; + [[fallthrough]]; case end: added += archive->addElements(appendCache); appendCache.clear(); @@ -274,9 +275,9 @@ void Core::RosterItem::flushMessagesToArchive(bool finished, const QString& firs std::list arc = archive->getBefore(requestedCount - responseCache.size(), before); responseCache.insert(responseCache.begin(), arc.begin(), arc.end()); 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()) { diff --git a/core/squawk.cpp b/core/squawk.cpp index 7ca41e3..3ccb224 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -51,7 +51,7 @@ void Core::Squawk::stop() QSettings settings; settings.beginGroup("core"); settings.beginWriteArray("accounts"); - for (int i = 0; i < accounts.size(); ++i) { + for (std::deque::size_type i = 0; i < accounts.size(); ++i) { settings.setArrayIndex(i); Account* acc = accounts[i]; settings.setValue("name", acc->getName()); diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index eee6b4e..cde8941 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -322,7 +322,7 @@ void Models::Contact::getMessages(Models::Contact::Messages& container) const void Models::Contact::toOfflineState() { emit childIsAboutToBeRemoved(this, 0, childItems.size()); - for (int i = 0; i < childItems.size(); ++i) { + for (std::deque::size_type i = 0; i < childItems.size(); ++i) { Item* item = childItems[i]; disconnect(item, &Item::childChanged, this, &Contact::refresh); Item::_removeChild(i); diff --git a/ui/models/room.cpp b/ui/models/room.cpp index 204b2b5..a251f4d 100644 --- a/ui/models/room.cpp +++ b/ui/models/room.cpp @@ -236,7 +236,7 @@ void Models::Room::getMessages(Models::Room::Messages& container) const void Models::Room::toOfflineState() { emit childIsAboutToBeRemoved(this, 0, childItems.size()); - for (int i = 0; i < childItems.size(); ++i) { + for (std::deque::size_type i = 0; i < childItems.size(); ++i) { Item* item = childItems[i]; Item::_removeChild(i); item->deleteLater(); diff --git a/ui/models/roster.cpp b/ui/models/roster.cpp index e124db7..2f226f2 100644 --- a/ui/models/roster.cpp +++ b/ui/models/roster.cpp @@ -518,7 +518,7 @@ void Models::Roster::removeGroup(const QString& account, const QString& name) if (toInsert.size() > 0) { Account* acc = accounts.find("account")->second; - for (int i = 0; i < toInsert.size(); ++i) { + for (std::deque::size_type i = 0; i < toInsert.size(); ++i) { Contact* cont = toInsert[i]; acc->appendChild(cont); //TODO optimisation } diff --git a/ui/utils/messageline.cpp b/ui/utils/messageline.cpp index befef70..6f2cb8d 100644 --- a/ui/utils/messageline.cpp +++ b/ui/utils/messageline.cpp @@ -111,7 +111,7 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg, bool forc } } messageIndex.insert(std::make_pair(id, message)); - int index = std::distance(messageOrder.begin(), result.first); //need to make with binary indexed tree + unsigned long index = std::distance(messageOrder.begin(), result.first); //need to make with binary indexed tree Position res = invalid; if (index == 0) { res = beggining; diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index 07a160f..d9e1039 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -24,6 +24,7 @@ #include #include #include +#include Conversation::Conversation(bool muc, const QString& mJid, const QString mRes, const QString pJid, const QString pRes, const QString& acc, QWidget* parent): QWidget(parent), @@ -205,6 +206,7 @@ void Conversation::onEnterPressed() msg.generateRandomId(); msg.setCurrentTime(); line->appendMessageWithUpload(msg, badge->id); + usleep(1000); //this is required for the messages not to have equal time when appending into messageline } clearAttachedFiles(); } diff --git a/ui/widgets/vcard/emailsmodel.cpp b/ui/widgets/vcard/emailsmodel.cpp index 4044322..9723672 100644 --- a/ui/widgets/vcard/emailsmodel.cpp +++ b/ui/widgets/vcard/emailsmodel.cpp @@ -145,7 +145,7 @@ QModelIndex UI::VCard::EMailsModel::addNewEmptyLine() 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()) { 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()) { - int maxCount = deque.size() - index; + quint32 maxCount = deque.size() - index; if (count > maxCount) { count = maxCount; } @@ -194,12 +194,12 @@ void UI::VCard::EMailsModel::setEmails(const std::deque& e } } -void UI::VCard::EMailsModel::revertPreferred(int row) +void UI::VCard::EMailsModel::revertPreferred(quint32 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; } diff --git a/ui/widgets/vcard/emailsmodel.h b/ui/widgets/vcard/emailsmodel.h index 358536f..3ee3a02 100644 --- a/ui/widgets/vcard/emailsmodel.h +++ b/ui/widgets/vcard/emailsmodel.h @@ -40,16 +40,16 @@ public: QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) 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& emails); void getEmails(std::deque& emails) const; - QString getEmail(int row) const; + QString getEmail(quint32 row) const; public slots: QModelIndex addNewEmptyLine(); - void revertPreferred(int row); + void revertPreferred(quint32 row); private: bool edit; diff --git a/ui/widgets/vcard/phonesmodel.cpp b/ui/widgets/vcard/phonesmodel.cpp index df9cad6..ee0ff75 100644 --- a/ui/widgets/vcard/phonesmodel.cpp +++ b/ui/widgets/vcard/phonesmodel.cpp @@ -129,7 +129,7 @@ void UI::VCard::PhonesModel::getPhones(std::deque& phones) } } -bool UI::VCard::PhonesModel::isPreferred(int row) const +bool UI::VCard::PhonesModel::isPreferred(quint32 row) const { if (row < deque.size()) { 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()) { - int maxCount = deque.size() - index; + quint32 maxCount = deque.size() - index; if (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)); } @@ -216,7 +216,7 @@ void UI::VCard::PhonesModel::setPhones(const std::deque& p } } -QString UI::VCard::PhonesModel::getPhone(int row) const +QString UI::VCard::PhonesModel::getPhone(quint32 row) const { return deque[row].number; } diff --git a/ui/widgets/vcard/phonesmodel.h b/ui/widgets/vcard/phonesmodel.h index bf847d2..f799f82 100644 --- a/ui/widgets/vcard/phonesmodel.h +++ b/ui/widgets/vcard/phonesmodel.h @@ -41,16 +41,16 @@ public: int rowCount(const QModelIndex& parent) const override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) 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& phones); void getPhones(std::deque& phones) const; - QString getPhone(int row) const; + QString getPhone(quint32 row) const; public slots: QModelIndex addNewEmptyLine(); - void revertPreferred(int row); + void revertPreferred(quint32 row); private: bool edit;