Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make traffic stats accurate #246

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ 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)

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})
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions includes/qst/apihandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
#include <tuple>
#include "utilities.hpp"

#ifdef HAVE_JSONCPP
#include <sstream>
#include <json/reader.h>
#endif

#define kInternalChangedFilesCache 5

namespace
Expand Down Expand Up @@ -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<QString>(reply);
QJsonDocument replyDoc = QJsonDocument::fromJson(m_DownloadedData.toUtf8());
QJsonObject replyData = replyDoc.object();
QJsonObject connectionArray = replyData["total"].toObject();
double inBytes = static_cast<double>(connectionArray.find("inBytesTotal").value().toDouble());
double outBytes = static_cast<double>(connectionArray.find("outBytesTotal").value().toDouble());
#endif
curInBytes = (std::max)(0.0, ((inBytes - std::get<0>(oldTraffic)) / (timeDelta.count() * 1e-3)))
+ (std::numeric_limits<double>::min)();
curOutBytes = (std::max)(0.0, ((outBytes - std::get<1>(oldTraffic)) / (timeDelta.count()* 1e-3)))
Expand Down