Skip to content

Commit 20ded9c

Browse files
Use cpp macros for OS_TYPE
1 parent 434dd2f commit 20ded9c

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/gui/programupdater.cpp

+29-12
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929

3030
#include "programupdater.h"
3131

32+
#include <QtCore/qconfig.h>
3233
#include <QtSystemDetection>
3334
#include <QDebug>
3435
#include <QDesktopServices>
3536
#include <QRegularExpression>
3637
#include <QXmlStreamReader>
3738

39+
#include <libtorrent/version.hpp>
40+
3841
#include "base/global.h"
3942
#include "base/net/downloadmanager.h"
4043
#include "base/preferences.h"
@@ -97,23 +100,37 @@ void ProgramUpdater::rssDownloadFinished(const Net::DownloadResult &result)
97100
: QString {};
98101
};
99102

100-
#ifdef QBT_USES_LIBTORRENT2
101-
102103
#ifdef Q_OS_MACOS
103-
const QString OS_TYPE = u"Mac OS X (lt20)"_s;
104+
#define BASE_OS "Mac OS X"
104105
#elif defined(Q_OS_WIN)
105-
const QString OS_TYPE = u"Windows x64 (lt20)"_s;
106-
#endif // Q_OS_MACOS
106+
#define BASE_OS "Windows x64"
107+
#endif
107108

108-
#else // QBT_USES_LIBTORRENT2
109+
#define STRINGIFY(s) #s
109110

110-
#ifdef Q_OS_MACOS
111-
const QString OS_TYPE = u"Mac OS X"_s;
112-
#elif defined(Q_OS_WIN)
113-
const QString OS_TYPE = u"Windows x64"_s;
114-
#endif // Q_OS_MACOS
111+
#if (QT_VERSION_MAJOR == 6) && (LIBTORRENT_VERSION_MAJOR == 1)
112+
#define _TYPE() BASE_OS
113+
#define TYPE _TYPE()
114+
115+
#elif (QT_VERSION_MAJOR == 6) && (LIBTORRENT_VERSION_MAJOR > 1)
116+
#define _TYPE(lt_major, lt_minor) BASE_OS " (lt" STRINGIFY(lt_major) STRINGIFY(lt_minor) ")"
117+
#define TYPE _TYPE(LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR)
118+
119+
#elif (QT_VERSION_MAJOR > 6)
120+
#define _TYPE(qt_major, lt_major, lt_minor) BASE_OS " (qt" STRINGIFY(qt_major) " lt" STRINGIFY(lt_major) STRINGIFY(lt_minor) ")"
121+
#define TYPE _TYPE(QT_VERSION_MAJOR, LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR)
122+
123+
#else
124+
#error "OS_TYPE is undefined for the current Qt/libtorrent combination"
125+
#endif
126+
127+
const QString OS_TYPE = QStringLiteral(TYPE);
128+
129+
#undef TYPE
130+
#undef _TYPE
131+
#undef STRINGIFY
132+
#undef BASE_OS
115133

116-
#endif // QBT_USES_LIBTORRENT2
117134

118135
bool inItem = false;
119136
QString version;

0 commit comments

Comments
 (0)