From 2de06b972751dae2086805530d405f02995a3638 Mon Sep 17 00:00:00 2001 From: Andrew Nelless Date: Wed, 26 Oct 2016 20:14:02 +0100 Subject: [PATCH] #5707 Add support for upgrade notifications --- src/gui/src/CoreInterface.cpp | 6 ++++++ src/gui/src/CoreInterface.h | 1 + src/gui/src/LicenseManager.cpp | 5 +++++ src/gui/src/LicenseManager.h | 1 + src/lib/synergy/ArgParser.cpp | 4 ++++ src/lib/synergy/ToolApp.cpp | 31 ++++++++++++++++++++++++++++--- src/lib/synergy/ToolApp.h | 1 + src/lib/synergy/ToolArgs.cpp | 3 ++- src/lib/synergy/ToolArgs.h | 1 + 9 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index f7e987d7..8b3a1ae3 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -62,6 +62,12 @@ QString CoreInterface::getSerialKeyFilePath() return filename; } +QString CoreInterface::notifyUpgrade (QString const& version, + QString const& serialKey) { + QStringList args("--notify-upgrade"); + QString input(version + ":" + serialKey); + return run(args, input); +} QString CoreInterface::notifyActivation(const QString& identity) { diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index c8a291e2..3576f02a 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -29,5 +29,6 @@ public: QString getArch(); QString getSerialKeyFilePath(); QString notifyActivation(const QString& identity); + QString notifyUpgrade (QString const& version, QString const& serialKey); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/LicenseManager.cpp b/src/gui/src/LicenseManager.cpp index aa623c88..15f79933 100644 --- a/src/gui/src/LicenseManager.cpp +++ b/src/gui/src/LicenseManager.cpp @@ -71,6 +71,11 @@ LicenseManager::setSerialKey(QString serialKeyString, bool acceptExpired) return ret; } +void +LicenseManager::notifyUpdate(QString version) { + +} + Edition LicenseManager::activeEdition() const { diff --git a/src/gui/src/LicenseManager.h b/src/gui/src/LicenseManager.h index 3d1d03b8..4d235369 100644 --- a/src/gui/src/LicenseManager.h +++ b/src/gui/src/LicenseManager.h @@ -36,6 +36,7 @@ public: QString activeEditionName() const; SerialKey serialKey() const; void skipActivation(); + void notifyUpdate(QString version); static QString getEditionName(Edition edition, bool trial = false); private: diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index 1af32843..828e4c06 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -208,6 +208,10 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv) args.m_notifyActivation = true; return true; } + else if (isArg(i, argc, argv, NULL, "--notify-upgrade", 0)) { + args.m_notifyUpgrade = true; + return true; + } else { return false; } diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index bf3dfdce..434ae684 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -1,11 +1,11 @@ /* * synergy -- mouse and keyboard sharing utility * Copyright (C) 2014-2016 Symless Ltd. - * + * * This package is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * found in the file LICENSE that should have accompanied this file. - * + * * This package is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -80,6 +80,9 @@ ToolApp::run(int argc, char** argv) else if (m_args.m_getArch) { std::cout << ARCH->getPlatformName() << std::endl; } + else if (m_args.m_notifyUpgrade) { + notifyUpgrade(); + } else if (m_args.m_notifyActivation) { notifyActivation(); } @@ -134,7 +137,29 @@ ToolApp::loginAuth() } } -void +void +ToolApp::notifyUpgrade() +{ + String data; + std::cin >> data; + + std::vector parts = synergy::string::splitString(data, ':'); + size_t count = parts.size(); + + if (count == 2) { + std::stringstream ss; + ss << JSON_URL << "notify/upgraded/"; + ss << "?version=" << parts[0]; + ss << "&serial=" << parts[1]; + + std::cout << ARCH->internet().get(ss.str()) << std::endl; + } + else { + throw XSynergy("Invalid upgrade data."); + } +} + +void ToolApp::notifyActivation() { String info; diff --git a/src/lib/synergy/ToolApp.h b/src/lib/synergy/ToolApp.h index 39c87ca7..0f918827 100644 --- a/src/lib/synergy/ToolApp.h +++ b/src/lib/synergy/ToolApp.h @@ -30,6 +30,7 @@ public: private: void loginAuth(); void notifyActivation(); + void notifyUpgrade(); private: ToolArgs m_args; diff --git a/src/lib/synergy/ToolArgs.cpp b/src/lib/synergy/ToolArgs.cpp index 5f67c666..4884696f 100644 --- a/src/lib/synergy/ToolArgs.cpp +++ b/src/lib/synergy/ToolArgs.cpp @@ -23,6 +23,7 @@ ToolArgs::ToolArgs() : m_getInstalledDir(false), m_getProfileDir(false), m_getArch(false), - m_notifyActivation(false) + m_notifyActivation(false), + m_notifyUpgrade(false) { } diff --git a/src/lib/synergy/ToolArgs.h b/src/lib/synergy/ToolArgs.h index 5febab9e..4a620a9b 100644 --- a/src/lib/synergy/ToolArgs.h +++ b/src/lib/synergy/ToolArgs.h @@ -30,4 +30,5 @@ public: bool m_getProfileDir; bool m_getArch; bool m_notifyActivation; + bool m_notifyUpgrade; };