From 12d9898b5d0bcc227bbfddbc2da5fc9ee8dd85c9 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 26 Aug 2015 20:44:42 +0300 Subject: [PATCH 1/3] Enable c++11 support. --- macxconf.pri | 4 +++- os2conf.pri | 3 +++ src/src.pro | 4 ++++ unixconf.pri | 3 +++ winconf-mingw.pri | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/macxconf.pri b/macxconf.pri index a51b34405..554fdf38a 100644 --- a/macxconf.pri +++ b/macxconf.pri @@ -10,7 +10,9 @@ exists($$OUT_PWD/../conf.pri) { } LIBS += -framework Carbon -framework IOKit -CONFIG += c++11 + +# C++11 support +lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11 QT_LANG_PATH = ../dist/qt-translations DIST_PATH = ../dist/mac diff --git a/os2conf.pri b/os2conf.pri index c27a9e77e..469a5a3e9 100644 --- a/os2conf.pri +++ b/os2conf.pri @@ -1,3 +1,6 @@ +# C++11 support +lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11 + exists(conf.pri) { # to the conf.pri goes all system dependent stuff include(conf.pri) diff --git a/src/src.pro b/src/src.pro index 333160ad9..be82b41a7 100644 --- a/src/src.pro +++ b/src/src.pro @@ -2,6 +2,10 @@ TEMPLATE = app CONFIG += qt thread silent +# C++11 support +CONFIG += c++11 +DEFINES += BOOST_NO_CXX11_RVALUE_REFERENCES + # Windows specific configuration win32: include(../winconf.pri) diff --git a/unixconf.pri b/unixconf.pri index 2738b5952..f26fba4f7 100644 --- a/unixconf.pri +++ b/unixconf.pri @@ -9,6 +9,9 @@ exists($$OUT_PWD/../conf.pri) { include(conf.pri) } +# C++11 support +lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++0x + # COMPILATION SPECIFIC !nogui:dbus { QT += dbus diff --git a/winconf-mingw.pri b/winconf-mingw.pri index 450700049..0283d23e6 100644 --- a/winconf-mingw.pri +++ b/winconf-mingw.pri @@ -1,3 +1,6 @@ +# C++11 support +lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=gnu++11 + strace_win{ contains(QMAKE_HOST.arch, x86) { # i686 arch requires frame pointer preservation From b519700e3391795c401ec67d690f548bc898222e Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 26 Aug 2015 20:45:31 +0300 Subject: [PATCH 2/3] Use c++11 enum classes instead of macros. --- src/core/net/private/geoipdatabase.cpp | 5 ++--- src/core/preferences.cpp | 4 ++-- src/core/types.h | 31 +++++++------------------- src/gui/options_imp.cpp | 4 ++-- src/webui/prefjson.cpp | 4 ++-- 5 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/core/net/private/geoipdatabase.cpp b/src/core/net/private/geoipdatabase.cpp index c3207eb88..7987b280d 100644 --- a/src/core/net/private/geoipdatabase.cpp +++ b/src/core/net/private/geoipdatabase.cpp @@ -63,7 +63,7 @@ namespace const quint32 __ENDIAN_TEST__ = 0x00000001; const bool __IS_LITTLE_ENDIAN__ = (reinterpret_cast(&__ENDIAN_TEST__)[0] == 0x01); - BEGIN_SCOPED_ENUM(DataType) + enum class DataType { Unknown = 0, Pointer = 1, @@ -81,8 +81,7 @@ namespace EndMarker = 13, Boolean = 14, Float = 15 - } - END_SCOPED_ENUM + }; struct DataFieldDescriptor { diff --git a/src/core/preferences.cpp b/src/core/preferences.cpp index 1e02aa5a8..f22ea2ae1 100644 --- a/src/core/preferences.cpp +++ b/src/core/preferences.cpp @@ -974,12 +974,12 @@ void Preferences::setGlobalMaxRatio(qreal ratio) MaxRatioAction Preferences::getMaxRatioAction() const { - return value("Preferences/Bittorrent/MaxRatioAction", MaxRatioAction::Pause).toInt(); + return value("Preferences/Bittorrent/MaxRatioAction", QVariant::fromValue(MaxRatioAction::Pause)).value(); } void Preferences::setMaxRatioAction(MaxRatioAction act) { - setValue("Preferences/Bittorrent/MaxRatioAction", act); + setValue("Preferences/Bittorrent/MaxRatioAction", QVariant::fromValue(act)); } // IP Filter diff --git a/src/core/types.h b/src/core/types.h index 4415191ff..92a24d0cf 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -31,43 +31,28 @@ #include -#define BEGIN_SCOPED_ENUM(name) class name\ -{\ - int m_val;\ -\ -public:\ - name() {}\ - name(int val) : m_val(val) {}\ - operator int() const { return m_val; }\ - operator QVariant() const { return m_val; }\ -\ - enum - -#define END_SCOPED_ENUM ; }; - const qlonglong MAX_ETA = 8640000; -BEGIN_SCOPED_ENUM(MaxRatioAction) +enum class MaxRatioAction { Pause, Remove -} -END_SCOPED_ENUM +}; + +Q_DECLARE_METATYPE(MaxRatioAction) -BEGIN_SCOPED_ENUM(TorrentExportFolder) +enum class TorrentExportFolder { Regular, Finished -} -END_SCOPED_ENUM +}; -BEGIN_SCOPED_ENUM(ShutdownAction) +enum class ShutdownAction { None, Shutdown, Suspend, Hibernate -} -END_SCOPED_ENUM +}; #endif // TYPES_H diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index baabdc8fe..beda4e089 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -469,7 +469,7 @@ void options_imp::saveOptions() pref->setEncryptionSetting(getEncryptionSetting()); pref->enableAnonymousMode(checkAnonymousMode->isChecked()); pref->setGlobalMaxRatio(getMaxRatio()); - pref->setMaxRatioAction(comboRatioLimitAct->currentIndex()); + pref->setMaxRatioAction(static_cast(comboRatioLimitAct->currentIndex())); // End Bittorrent preferences // Misc preferences // * IPFilter @@ -804,7 +804,7 @@ void options_imp::loadOptions() spinMaxRatio->setEnabled(false); comboRatioLimitAct->setEnabled(false); } - comboRatioLimitAct->setCurrentIndex(pref->getMaxRatioAction()); + comboRatioLimitAct->setCurrentIndex(static_cast(pref->getMaxRatioAction())); // End Bittorrent preferences // Web UI preferences diff --git a/src/webui/prefjson.cpp b/src/webui/prefjson.cpp index bf206df39..f08385463 100644 --- a/src/webui/prefjson.cpp +++ b/src/webui/prefjson.cpp @@ -141,7 +141,7 @@ QByteArray prefjson::getPreferences() // Share Ratio Limiting data["max_ratio_enabled"] = (pref->getGlobalMaxRatio() >= 0.); data["max_ratio"] = pref->getGlobalMaxRatio(); - data["max_ratio_act"] = pref->getMaxRatioAction(); + data["max_ratio_act"] = QVariant::fromValue(pref->getMaxRatioAction()); // Web UI // Language @@ -337,7 +337,7 @@ void prefjson::setPreferences(const QString& json) else pref->setGlobalMaxRatio(-1); if (m.contains("max_ratio_act")) - pref->setMaxRatioAction(m["max_ratio_act"].toInt()); + pref->setMaxRatioAction(m["max_ratio_act"].value()); // Web UI // Language From 2a411987dbf872f8f5ece8efa7ac6c0866ab837f Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sun, 20 Sep 2015 15:45:40 +0300 Subject: [PATCH 3/3] Bump minimum supported version of gcc to 4.8. --- .travis.yml | 11 +++++++++-- unixconf.pri | 10 +++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67f378b18..d318598d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,14 +43,19 @@ addons: branch_pattern: $coverity_branch notification_email: sledgehammer999@qbittorrent.org apt: + sources: + # sources list: https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json + - ubuntu-toolchain-r-test + - boost-latest packages: # packages list: https://github.com/travis-ci/apt-package-whitelist/blob/master/ubuntu-precise - autoconf - automake - colormake + - g++-4.8 - libssl-dev - - libboost-dev - - libboost-system-dev + - libboost1.55-dev + - libboost-system1.55-dev - libqt4-dev # Uncomment when Travis upgraded "Ubuntu 12.04 LTS" to a newer version whose repo will have a more up-to-date libtorrent package #- libtorrent-rasterbar6 @@ -60,6 +65,7 @@ before_install: - if [ "$TRAVIS_BRANCH" = "$coverity_branch" ] && ! [ "$TRAVIS_OS_NAME" = "linux" -a "$lt_branch" = "RC_1_0" -a "$gui" = true ]; then exit ; fi - shopt -s expand_aliases + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then export CC=gcc-4.8 CXX=g++-4.8 ; fi - if [ "$TRAVIS_BRANCH" != "$coverity_branch" -a "$TRAVIS_OS_NAME" = "linux" ]; then dpkg-query -L ccache && export PATH="/usr/lib/ccache/:$PATH" ; fi - alias make="colormake -j3" # Using nprocs/2 sometimes may fail (gcc is killed by system) @@ -90,6 +96,7 @@ install: script: - if [ "$TRAVIS_BRANCH" = "$coverity_branch" ]; then exit ; fi # Skip usual build when running coverity scan - ./bootstrap.sh && ./configure $qbtconf + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then echo QMAKE_CC=$CC >> conf.pri && echo QMAKE_CXX=$CXX >> conf.pri ; fi - make && make install after_success: diff --git a/unixconf.pri b/unixconf.pri index f26fba4f7..cc59b43dd 100644 --- a/unixconf.pri +++ b/unixconf.pri @@ -10,17 +10,13 @@ exists($$OUT_PWD/../conf.pri) { } # C++11 support -lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++0x +lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11 # COMPILATION SPECIFIC -!nogui:dbus { - QT += dbus -} +!nogui:dbus: QT += dbus QMAKE_CXXFLAGS += -Wformat -Wformat-security -!haiku { - QMAKE_LFLAGS_APP += -rdynamic -} +!haiku: QMAKE_LFLAGS_APP += -rdynamic # Man page nogui {