diff --git a/.travis.yml b/.travis.yml index e0d4e9d..09924f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,9 @@ before_install: - | if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update && + brew upgrade cmake && brew install qt5 && + brew install jsoncpp && chmod -R 755 /usr/local/opt/qt5/* fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fa05ea..83d9643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ if (NOT Qt5_FOUND) ) endif () +find_package(PkgConfig) +pkg_check_modules(JSONCPP jsoncpp) + # Fill the template with information gathered from CMake. configure_file(includes/config.template.h config.h @ONLY) @@ -29,6 +32,10 @@ add_definitions(-DGLEW_STATIC) # The Qt5Widgets_INCLUDES also includes the include directories for # dependencies QtCore and QtGui include_directories(${Qt5Widgets_INCLUDES}) +if (${JSONCPP_FOUND}) + add_definitions(-DHAVE_JSONCPP) + include_directories(${JSONCPP_INCLUDE_DIRS}) +endif () # We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5. add_definitions(${Qt5Widgets_DEFINITIONS}) @@ -136,6 +143,10 @@ else() target_link_libraries(QSyncthingTray Qt5::Widgets Qt5::Network Qt5::WebEngineWidgets) endif() +if (${JSONCPP_FOUND}) + target_link_libraries(QSyncthingTray ${JSONCPP_LINK_LIBRARIES}) +endif () + # Temporary solution/hack to generate package. # Proper way will come after cmake cleanup. diff --git a/includes/qst/apihandler.hpp b/includes/qst/apihandler.hpp index 0a12ee4..fb5eea5 100644 --- a/includes/qst/apihandler.hpp +++ b/includes/qst/apihandler.hpp @@ -33,6 +33,11 @@ #include #include "utilities.hpp" +#ifdef HAVE_JSONCPP +#include +#include +#endif + #define kInternalChangedFilesCache 5 namespace @@ -99,12 +104,21 @@ namespace api } else { +#ifdef HAVE_JSONCPP + std::stringstream downloadedDataStream(reply.toStdString()); + Json::Value replyData; + Json::parseFromStream(Json::CharReaderBuilder(), downloadedDataStream, &replyData, nullptr); + Json::Value connectionArray = replyData["total"]; + uint64_t inBytes = connectionArray["inBytesTotal"].asUInt64(); + uint64_t outBytes = connectionArray["outBytesTotal"].asUInt64(); +#else QString m_DownloadedData = static_cast(reply); QJsonDocument replyDoc = QJsonDocument::fromJson(m_DownloadedData.toUtf8()); QJsonObject replyData = replyDoc.object(); QJsonObject connectionArray = replyData["total"].toObject(); double inBytes = static_cast(connectionArray.find("inBytesTotal").value().toDouble()); double outBytes = static_cast(connectionArray.find("outBytesTotal").value().toDouble()); +#endif curInBytes = (std::max)(0.0, ((inBytes - std::get<0>(oldTraffic)) / (timeDelta.count() * 1e-3))) + (std::numeric_limits::min)(); curOutBytes = (std::max)(0.0, ((outBytes - std::get<1>(oldTraffic)) / (timeDelta.count()* 1e-3)))