fix: recent FTBFS in msvc (#2907)

* fix: recent FTBFS in msvc

It's happening a line in qt/WatchDir.cc where an enum named `ERROR` is
declared, so it's probably conflicting with a new `ERROR` name in some
header file. Rename ours and make at an `enum class` for good measure.

* build: fix cmake msvc warning

D9025 : overriding /W3 with /W4
This commit is contained in:
Charles Kerr 2022-04-12 01:56:09 -05:00 committed by GitHub
parent 7c76d40a4d
commit 8c51c48472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR) cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW)
endif()
# The value of this variable should be set prior to the first project() command invocation. # The value of this variable should be set prior to the first project() command invocation.
# See: https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html # See: https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_DEPLOYMENT_TARGET.html
if(CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "") if(CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "")

View File

@ -30,27 +30,27 @@ WatchDir::WatchDir(TorrentModel const& model)
**** ****
***/ ***/
int WatchDir::metainfoTest(QString const& filename) const WatchDir::AddResult WatchDir::metainfoTest(QString const& filename) const
{ {
auto metainfo = tr_torrent_metainfo(); auto metainfo = tr_torrent_metainfo();
if (!metainfo.parseTorrentFile(filename.toUtf8().constData())) if (!metainfo.parseTorrentFile(filename.toUtf8().constData()))
{ {
return ERROR; return AddResult::Error;
} }
if (model_.hasTorrent(TorrentHash{ metainfo.infoHash() })) if (model_.hasTorrent(TorrentHash{ metainfo.infoHash() }))
{ {
return DUPLICATE; return AddResult::Duplicate;
} }
return OK; return AddResult::Success;
} }
void WatchDir::onTimeout() void WatchDir::onTimeout()
{ {
auto* t = qobject_cast<QTimer*>(sender()); auto* t = qobject_cast<QTimer*>(sender());
if (auto const filename = t->objectName(); metainfoTest(filename) == OK) if (auto const filename = t->objectName(); metainfoTest(filename) == AddResult::Success)
{ {
emit torrentFileAdded(filename); emit torrentFileAdded(filename);
} }
@ -98,14 +98,14 @@ void WatchDir::watcherActivated(QString const& path)
switch (metainfoTest(filename)) switch (metainfoTest(filename))
{ {
case OK: case AddResult::Success:
emit torrentFileAdded(filename); emit torrentFileAdded(filename);
break; break;
case DUPLICATE: case AddResult::Duplicate:
break; break;
case ERROR: case AddResult::Error:
{ {
// give the torrent a few seconds to finish downloading // give the torrent a few seconds to finish downloading
auto* t = new QTimer(this); auto* t = new QTimer(this);

View File

@ -36,14 +36,14 @@ private slots:
void rescanAllWatchedDirectories(); void rescanAllWatchedDirectories();
private: private:
enum enum class AddResult
{ {
OK, Success,
DUPLICATE, Duplicate,
ERROR Error
}; };
int metainfoTest(QString const& filename) const; AddResult metainfoTest(QString const& filename) const;
TorrentModel const& model_; TorrentModel const& model_;