diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-12-25 00:08:06 +0000 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-12-25 00:08:06 +0000 |
commit | 01e38d12ede3109687208c387b50ee6a07c3426c (patch) | |
tree | 349c8d8a82cb4fa7dc5de16c1d479af24a30e9d6 | |
parent | Merge pull request #357 from LorenDB/qkchdocs (diff) | |
download | nheko-01e38d12ede3109687208c387b50ee6a07c3426c.tar.xz |
Fix some compiler warnings
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/AvatarProvider.cpp | 2 | ||||
-rw-r--r-- | src/BlurhashProvider.cpp | 2 | ||||
-rw-r--r-- | src/Cache.cpp | 24 | ||||
-rw-r--r-- | src/CacheStructs.h | 2 | ||||
-rw-r--r-- | src/ChatPage.cpp | 2 | ||||
-rw-r--r-- | src/CommunitiesList.cpp | 4 | ||||
-rw-r--r-- | src/CommunitiesListItem.cpp | 4 | ||||
-rw-r--r-- | src/LoginPage.cpp | 4 | ||||
-rw-r--r-- | src/MainWindow.cpp | 4 | ||||
-rw-r--r-- | src/MxcImageProvider.cpp | 4 | ||||
-rw-r--r-- | src/UsersModel.h | 2 | ||||
-rw-r--r-- | src/Utils.cpp | 22 | ||||
-rw-r--r-- | src/dialogs/RoomSettings.cpp | 2 | ||||
-rw-r--r-- | src/popups/SuggestionsPopup.cpp | 10 | ||||
-rw-r--r-- | src/timeline/EventStore.h | 6 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 6 |
17 files changed, 51 insertions, 50 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 326e5794..dbb3209a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -579,6 +579,7 @@ endif() if(WIN32) add_executable (nheko WIN32 ${OS_BUNDLE} ${NHEKO_DEPS}) + target_compile_definitions(nheko PRIVATE _WIN32_WINNT=0x0601) else() add_executable (nheko ${OS_BUNDLE} ${NHEKO_DEPS}) endif() diff --git a/src/AvatarProvider.cpp b/src/AvatarProvider.cpp index b1751c33..4c3969be 100644 --- a/src/AvatarProvider.cpp +++ b/src/AvatarProvider.cpp @@ -81,7 +81,7 @@ resolve(const QString &avatarUrl, int size, QObject *receiver, AvatarCallback ca cache::saveImage(cacheKey.toStdString(), res); } - emit proxy->avatarDownloaded(QByteArray(res.data(), res.size())); + emit proxy->avatarDownloaded(QByteArray(res.data(), (int)res.size())); }); } diff --git a/src/BlurhashProvider.cpp b/src/BlurhashProvider.cpp index 08dc2d40..cc7d5a73 100644 --- a/src/BlurhashProvider.cpp +++ b/src/BlurhashProvider.cpp @@ -31,7 +31,7 @@ BlurhashResponse::run() return; } - QImage image(decoded.image.data(), decoded.width, decoded.height, QImage::Format_RGB32); + QImage image(decoded.image.data(), (int)decoded.width, (int)decoded.height, QImage::Format_RGB32); m_image = image.copy(); emit finished(); diff --git a/src/Cache.cpp b/src/Cache.cpp index 674b5793..3099b0c9 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -675,7 +675,7 @@ Cache::image(lmdb::txn &txn, const std::string &url) const if (!res) return QByteArray(); - return QByteArray(image.data(), image.size()); + return QByteArray(image.data(), (int)image.size()); } catch (const lmdb::error &e) { nhlog::db()->critical("image: {}, {}", e.what(), url); } @@ -703,7 +703,7 @@ Cache::image(const QString &url) const if (!res) return QByteArray(); - return QByteArray(image.data(), image.size()); + return QByteArray(image.data(), (int)image.size()); } catch (const lmdb::error &e) { nhlog::db()->critical("image: {} {}", e.what(), url.toStdString()); } @@ -1257,9 +1257,9 @@ Cache::saveState(const mtx::responses::Sync &res) updatedInfo.tags = tmp.tags; } catch (const json::exception &e) { nhlog::db()->warn( - "failed to parse room info: room_id ({}), {}", + "failed to parse room info: room_id ({}), {}: {}", room.first, - std::string(data.data(), data.size())); + std::string(data.data(), data.size()), e.what()); } } } @@ -1458,9 +1458,9 @@ Cache::singleRoomInfo(const std::string &room_id) return tmp; } catch (const json::exception &e) { - nhlog::db()->warn("failed to parse room info: room_id ({}), {}", + nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}", room_id, - std::string(data.data(), data.size())); + std::string(data.data(), data.size()), e.what()); } } @@ -1492,9 +1492,9 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms) room_info.emplace(QString::fromStdString(room), std::move(tmp)); } catch (const json::exception &e) { - nhlog::db()->warn("failed to parse room info: room_id ({}), {}", + nhlog::db()->warn("failed to parse room info: room_id ({}), {}: {}", room, - std::string(data.data(), data.size())); + std::string(data.data(), data.size()), e.what()); } } else { // Check if the room is an invite. @@ -1508,9 +1508,9 @@ Cache::getRoomInfo(const std::vector<std::string> &rooms) std::move(tmp)); } catch (const json::exception &e) { nhlog::db()->warn( - "failed to parse room info for invite: room_id ({}), {}", + "failed to parse room info for invite: room_id ({}), {}: {}", room, - std::string(data.data(), data.size())); + std::string(data.data(), data.size()), e.what()); } } } @@ -2044,7 +2044,7 @@ Cache::getRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb) } auto cursor = lmdb::cursor::open(txn, membersdb); - const int total = membersdb.size(txn); + const auto total = membersdb.size(txn); std::size_t ii = 0; std::string user_id; @@ -2327,7 +2327,7 @@ Cache::getRoomAvatar(const std::string &room_id) txn.commit(); - return QImage::fromData(QByteArray(response.data(), response.size())); + return QImage::fromData(QByteArray(response.data(), (int)response.size())); } std::vector<std::string> diff --git a/src/CacheStructs.h b/src/CacheStructs.h index b3d9acf1..10f8cc54 100644 --- a/src/CacheStructs.h +++ b/src/CacheStructs.h @@ -61,7 +61,7 @@ struct RoomInfo //! Whether or not the room is an invite. bool is_invite = false; //! Total number of members in the room. - int16_t member_count = 0; + size_t member_count = 0; //! Who can access to the room. mtx::events::state::JoinRule join_rule = mtx::events::state::JoinRule::Public; bool guest_access = false; diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index e3325c05..37248022 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -439,7 +439,7 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token) try { http::client()->set_user(parse<User>(userid.toStdString())); - } catch (const std::invalid_argument &e) { + } catch (const std::invalid_argument &) { nhlog::ui()->critical("bootstrapped with invalid user_id: {}", userid.toStdString()); } diff --git a/src/CommunitiesList.cpp b/src/CommunitiesList.cpp index 9af2ea9b..010200c8 100644 --- a/src/CommunitiesList.cpp +++ b/src/CommunitiesList.cpp @@ -104,7 +104,7 @@ CommunitiesList::setTagsForRoom(const QString &room_id, const std::vector<std::s } // insert or remove the room from the tag as appropriate std::string current_tag = - it->first.right(it->first.size() - strlen("tag:")).toStdString(); + it->first.right(static_cast<int>(it->first.size() - strlen("tag:"))).toStdString(); if (std::find(tags.begin(), tags.end(), current_tag) != tags.end()) { // the room has this tag it->second->addRoom(room_id); @@ -246,7 +246,7 @@ CommunitiesList::fetchCommunityAvatar(const QString &id, const QString &avatarUr cache::saveImage(opts.mxc_url, res); - auto data = QByteArray(res.data(), res.size()); + auto data = QByteArray(res.data(), (int)res.size()); QPixmap pix; pix.loadFromData(data); diff --git a/src/CommunitiesListItem.cpp b/src/CommunitiesListItem.cpp index c56c74a2..dca91441 100644 --- a/src/CommunitiesListItem.cpp +++ b/src/CommunitiesListItem.cpp @@ -117,7 +117,7 @@ CommunitiesListItem::resolveName() const if (!name_.isEmpty()) return name_; if (groupId_.startsWith("tag:")) - return groupId_.right(groupId_.size() - strlen("tag:")); + return groupId_.right(static_cast<int>(groupId_.size() - strlen("tag:"))); if (!groupId_.startsWith("+")) return QString("Group"); // Group with no name or id. @@ -132,7 +132,7 @@ CommunitiesListItem::updateTooltip() if (groupId_ == "world") setToolTip(tr("All rooms")); else if (is_tag()) { - QString tag = groupId_.right(groupId_.size() - strlen("tag:")); + QString tag = groupId_.right(static_cast<int>(groupId_.size() - strlen("tag:"))); if (tag == "m.favourite") setToolTip(tr("Favourite rooms")); else if (tag == "m.lowpriority") diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 8076d6d6..05741cca 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -225,7 +225,7 @@ LoginPage::onMatrixIdEntered() try { user = parse<User>(matrixid_input_->text().toStdString()); - } catch (const std::exception &e) { + } catch (const std::exception &) { showError(error_matrixid_label_, "You have entered an invalid Matrix ID e.g @joe:matrix.org"); return; @@ -389,7 +389,7 @@ LoginPage::onLoginButtonClicked() try { user = parse<User>(matrixid_input_->text().toStdString()); - } catch (const std::exception &e) { + } catch (const std::exception &) { showError(error_matrixid_label_, "You have entered an invalid Matrix ID e.g @joe:matrix.org"); return; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index d056aca6..570c0ab5 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -167,7 +167,7 @@ MainWindow::MainWindow(const QString profile, QWidget *parent) try { using namespace mtx::identifiers; http::client()->set_user(parse<User>(user_id.toStdString())); - } catch (const std::invalid_argument &e) { + } catch (const std::invalid_argument &) { nhlog::ui()->critical("bootstrapped with invalid user_id: {}", user_id.toStdString()); } @@ -472,7 +472,7 @@ MainWindow::openReadReceiptsDialog(const QString &event_id) try { dialog->addUsers(cache::readReceipts(event_id, room_id)); - } catch (const lmdb::error &e) { + } catch (const lmdb::error &) { nhlog::db()->warn("failed to retrieve read receipts for {} {}", event_id.toStdString(), chat_page_->currentRoom().toStdString()); diff --git a/src/MxcImageProvider.cpp b/src/MxcImageProvider.cpp index d6564277..b48fe011 100644 --- a/src/MxcImageProvider.cpp +++ b/src/MxcImageProvider.cpp @@ -48,7 +48,7 @@ MxcImageResponse::run() return; } - auto data = QByteArray(res.data(), res.size()); + auto data = QByteArray(res.data(), (int)res.size()); cache::saveImage(fileName, data); m_image = utils::readImage(&data); if (!m_image.isNull()) { @@ -92,7 +92,7 @@ MxcImageResponse::run() temp = mtx::crypto::to_string( mtx::crypto::decrypt_file(temp, m_encryptionInfo.value())); - auto data = QByteArray(temp.data(), temp.size()); + auto data = QByteArray(temp.data(), (int)temp.size()); cache::saveImage(m_id, data); m_image = utils::readImage(&data); m_image.setText("original filename", diff --git a/src/UsersModel.h b/src/UsersModel.h index c60b34b8..cd9b780c 100644 --- a/src/UsersModel.h +++ b/src/UsersModel.h @@ -17,7 +17,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override { (void)parent; - return roomMembers_.size(); + return (int)roomMembers_.size(); } QVariant data(const QModelIndex &index, int role) const override; diff --git a/src/Utils.cpp b/src/Utils.cpp index 1d8fcd9c..7228faf4 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -244,20 +244,20 @@ utils::humanReadableFileSize(uint64_t bytes) int utils::levenshtein_distance(const std::string &s1, const std::string &s2) { - const int nlen = s1.size(); - const int hlen = s2.size(); + const auto nlen = s1.size(); + const auto hlen = s2.size(); if (hlen == 0) return -1; if (nlen == 1) - return s2.find(s1); + return (int)s2.find(s1); std::vector<int> row1(hlen + 1, 0); - for (int i = 0; i < nlen; ++i) { - std::vector<int> row2(1, i + 1); + for (size_t i = 0; i < nlen; ++i) { + std::vector<int> row2(1, (int)i + 1); - for (int j = 0; j < hlen; ++j) { + for (size_t j = 0; j < hlen; ++j) { const int cost = s1[i] != s2[j]; row2.push_back( std::min(row1[j + 1] + 1, std::min(row2[j] + 1, row1[j] + cost))); @@ -381,15 +381,15 @@ utils::escapeBlacklistedHtml(const QString &rawStr) "caption", "/caption", "pre", "/pre", "span", "/span", "img", "/img"}; QByteArray data = rawStr.toUtf8(); QByteArray buffer; - const size_t length = data.size(); + const int length = data.size(); buffer.reserve(length); bool escapingTag = false; - for (size_t pos = 0; pos != length; ++pos) { + for (int pos = 0; pos != length; ++pos) { switch (data.at(pos)) { case '<': { bool oneTagMatched = false; - size_t endPos = std::min(static_cast<size_t>(data.indexOf('>', pos)), - static_cast<size_t>(data.indexOf(' ', pos))); + const int endPos = static_cast<int>(std::min(static_cast<size_t>(data.indexOf('>', pos)), + static_cast<size_t>(data.indexOf(' ', pos)))); auto mid = data.mid(pos + 1, endPos - pos - 1); for (const auto &tag : allowedTags) { @@ -543,7 +543,7 @@ utils::generateContrastingHexColor(const QString &input, const QString &backgrou // Create a color for the input auto hash = hashQString(input); // create a hue value based on the hash of the input. - auto userHue = static_cast<int>(qAbs(hash % 360)); + auto userHue = static_cast<int>(hash % 360); // start with moderate saturation and lightness values. auto sat = 220; auto lightness = 125; diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index e6c9c58c..bd3cc26f 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -493,7 +493,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this); roomNameLabel_->setFont(largeFont); - auto membersLabel = new QLabel(tr("%n member(s)", "", info_.member_count), this); + auto membersLabel = new QLabel(tr("%n member(s)", "", (int)info_.member_count), this); auto textLayout = new QVBoxLayout; textLayout->addWidget(roomNameLabel_); diff --git a/src/popups/SuggestionsPopup.cpp b/src/popups/SuggestionsPopup.cpp index 2650b5e6..42efe6ce 100644 --- a/src/popups/SuggestionsPopup.cpp +++ b/src/popups/SuggestionsPopup.cpp @@ -35,14 +35,14 @@ SuggestionsPopup::addRooms(const std::vector<RoomSearchResult> &rooms) return; } - const size_t layoutCount = layout_->count(); - const size_t roomCount = rooms.size(); + const int layoutCount = (int)layout_->count(); + const int roomCount = (int)rooms.size(); // Remove the extra widgets from the layout. if (roomCount < layoutCount) removeLayoutItemsAfter(roomCount - 1); - for (size_t i = 0; i < roomCount; ++i) { + for (int i = 0; i < roomCount; ++i) { auto item = layout_->itemAt(i); // Create a new widget if there isn't already one in that @@ -62,7 +62,7 @@ SuggestionsPopup::addRooms(const std::vector<RoomSearchResult> &rooms) resetSelection(); adjustSize(); - resize(geometry().width(), 40 * rooms.size()); + resize(geometry().width(), 40 * (int)rooms.size()); selectNextSuggestion(); } @@ -150,7 +150,7 @@ SuggestionsPopup::removeLayoutItemsAfter(size_t startingPos) size_t posToRemove = layout_->count() - 1; QLayoutItem *item; - while (startingPos <= posToRemove && (item = layout_->takeAt(posToRemove)) != nullptr) { + while (startingPos <= posToRemove && (item = layout_->takeAt((int)posToRemove)) != nullptr) { delete item->widget(); delete item; diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h index 2d5fb1be..a71e95d5 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h @@ -29,7 +29,7 @@ public: friend uint qHash(const Index &i, uint seed = 0) noexcept { QtPrivate::QHashCombine hash; - seed = hash(seed, QByteArray::fromRawData(i.room.data(), i.room.size())); + seed = hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size())); seed = hash(seed, i.idx); return seed; } @@ -46,8 +46,8 @@ public: friend uint qHash(const IdIndex &i, uint seed = 0) noexcept { QtPrivate::QHashCombine hash; - seed = hash(seed, QByteArray::fromRawData(i.room.data(), i.room.size())); - seed = hash(seed, QByteArray::fromRawData(i.id.data(), i.id.size())); + seed = hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size())); + seed = hash(seed, QByteArray::fromRawData(i.id.data(), (int)i.id.size())); return seed; } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 11fa60c0..adef886d 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -28,7 +28,7 @@ namespace std { inline uint qHash(const std::string &key, uint seed = 0) { - return qHash(QByteArray::fromRawData(key.data(), key.length()), seed); + return qHash(QByteArray::fromRawData(key.data(), (int)key.length()), seed); } } @@ -1208,7 +1208,7 @@ TimelineModel::cacheMedia(QString eventId) if (!file.open(QIODevice::WriteOnly)) return; - file.write(QByteArray(temp.data(), temp.size())); + file.write(QByteArray(temp.data(), (int)temp.size())); file.close(); } catch (const std::exception &e) { nhlog::ui()->warn("Error while saving file to: {}", e.what()); @@ -1227,7 +1227,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, QColor bg) "multiple users. Second argument is the last user of that list. (If only one user is " "typing, %1 is empty. You should still use it in your string though to silence Qt " "warnings.)", - users.size()); + (int)users.size()); if (users.empty()) { return ""; |