From 32da441fc0a7e18075d146a0367dc35634dac71e Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Tue, 27 Oct 2015 15:45:39 -0700 Subject: [PATCH 01/40] Simplify OS info on Unix #4933 --- src/lib/arch/unix/ArchSystemUnix.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/arch/unix/ArchSystemUnix.cpp b/src/lib/arch/unix/ArchSystemUnix.cpp index 112e15cb..07cbf6c4 100644 --- a/src/lib/arch/unix/ArchSystemUnix.cpp +++ b/src/lib/arch/unix/ArchSystemUnix.cpp @@ -44,8 +44,6 @@ ArchSystemUnix::getOSName() const msg += info.sysname; msg += " "; msg += info.release; - msg += " "; - msg += info.version; return msg; } #endif From 4d20a3ce912604fbd223e2733c6155bc697f530e Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Tue, 27 Oct 2015 15:50:34 -0700 Subject: [PATCH 02/40] Add OS and arch in auth request #4933 --- src/lib/synergy/ToolApp.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 5f01cb81..f6cd2ef5 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -157,6 +157,8 @@ ToolApp::loginAuth() ss << JSON_URL << "auth/"; ss << "?email=" << ARCH->internet().urlEncode(email); ss << "&password=" << password; + ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); + ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); std::cout << ARCH->internet().get(ss.str()) << std::endl; } From a4c799c285b8d945feaf5cfaee40e2b907b943d4 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Tue, 27 Oct 2015 16:31:09 -0700 Subject: [PATCH 03/40] Notify activation when skipping or using serial #4932 --- src/gui/src/CoreInterface.cpp | 6 ++++++ src/gui/src/CoreInterface.h | 1 + src/gui/src/SetupWizard.cpp | 11 +++++++++++ src/gui/src/WebClient.cpp | 2 +- src/lib/synergy/ArgParser.cpp | 4 ++++ src/lib/synergy/ToolApp.cpp | 34 ++++++++++++++++++++++++++++++---- src/lib/synergy/ToolApp.h | 1 + src/lib/synergy/ToolArgs.cpp | 1 + src/lib/synergy/ToolArgs.h | 1 + 9 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 9bc8d132..1a917382 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -71,6 +71,12 @@ QString CoreInterface::checkSubscription() return run(args); } +QString CoreInterface::notifyActivation(const QString& input) +{ + QStringList args("--notify-activation"); + return run(args, input); +} + QString CoreInterface::run(const QStringList& args, const QString& input) { QString program( diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index dc2f9fb6..4949bddc 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -31,5 +31,6 @@ public: QString getSubscriptionFilename(); QString activateSerial(const QString& serial); QString checkSubscription(); + QString notifyActivation(const QString& input); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index cc8fd9ca..bbe14328 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -216,6 +216,17 @@ void SetupWizard::accept() if (m_pRadioButtonSubscription->isChecked()) { appConfig.setSerialKey(m_pLineEditSerialKey->text()); + + QString info("serial:" + hash(getFirstMacAddress()) + "\n"); + CoreInterface coreInterface; + coreInterface.notifyActivation(info); + } + + if (m_pRadioButtonSkip->isChecked()) + { + QString info("skip:" + hash(getFirstMacAddress()) + "\n"); + CoreInterface coreInterface; + coreInterface.notifyActivation(info); } m_MainWindow.setEdition(m_Edition); diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp index 6de6d9ca..c231c970 100644 --- a/src/gui/src/WebClient.cpp +++ b/src/gui/src/WebClient.cpp @@ -94,6 +94,6 @@ QString WebClient::request( { QStringList args("--login-auth"); // hash password in case it contains interesting chars. - QString credentials(email + ":" + hash(password) + "\n"); + QString credentials(email + ":" + hash(password) + ":" + hash(getFirstMacAddress()) + "\n"); return m_CoreInterface.run(args, credentials); } diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index 92185b26..ba0a103c 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -211,6 +211,10 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv) args.m_checkSubscription = true; return true; } + else if (isArg(i, argc, argv, NULL, "--notify-activation", 0)) { + args.m_notifyActivation = true; + return true; + } else { return false; } diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index f6cd2ef5..436db09d 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -117,6 +117,9 @@ ToolApp::run(int argc, char** argv) return kExitSubscription; } } + else if (m_args.m_notifyActivation) { + notifyActivation(); + } else { throw XSynergy("Nothing to do"); } @@ -149,14 +152,17 @@ ToolApp::loginAuth() String credentials; std::cin >> credentials; - size_t separator = credentials.find(':'); - String email = credentials.substr(0, separator); - String password = credentials.substr(separator + 1, credentials.length()); + size_t separator1 = credentials.find(':'); + size_t separator2 = credentials.find(':', separator1 + 1); + String email = credentials.substr(0, separator1); + String password = credentials.substr(separator1 + 1, separator2 - separator1 - 1); + String macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1); std::stringstream ss; ss << JSON_URL << "auth/"; ss << "?email=" << ARCH->internet().urlEncode(email); ss << "&password=" << password; + ss << "&mac=" << macHash; ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); @@ -179,4 +185,24 @@ ToolApp::getPluginList() ss << "&password=" << password; std::cout << ARCH->internet().get(ss.str()) << std::endl; -} \ No newline at end of file +} + +void +ToolApp::notifyActivation() +{ + String info; + std::cin >> info; + + size_t separator = info.find(':'); + String action = info.substr(0, separator); + String macHash = info.substr(separator + 1, info.length()); + + std::stringstream ss; + ss << JSON_URL << "notify/"; + ss << "?action=" << action; + ss << "&mac=" << macHash; + ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); + ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); + + std::cout << ARCH->internet().get(ss.str()) << std::endl; +} diff --git a/src/lib/synergy/ToolApp.h b/src/lib/synergy/ToolApp.h index 08947c6e..7f0b6ea7 100644 --- a/src/lib/synergy/ToolApp.h +++ b/src/lib/synergy/ToolApp.h @@ -30,6 +30,7 @@ public: private: void loginAuth(); void getPluginList(); + void notifyActivation(); private: ToolArgs m_args; diff --git a/src/lib/synergy/ToolArgs.cpp b/src/lib/synergy/ToolArgs.cpp index 0fd68a92..23439317 100644 --- a/src/lib/synergy/ToolArgs.cpp +++ b/src/lib/synergy/ToolArgs.cpp @@ -27,6 +27,7 @@ ToolArgs::ToolArgs() : m_getArch(false), m_getSubscriptionFilename(false), m_checkSubscription(false), + m_notifyActivation(false), m_subscriptionSerial() { } diff --git a/src/lib/synergy/ToolArgs.h b/src/lib/synergy/ToolArgs.h index ffbf932e..fb0b3e78 100644 --- a/src/lib/synergy/ToolArgs.h +++ b/src/lib/synergy/ToolArgs.h @@ -33,5 +33,6 @@ public: bool m_getArch; bool m_getSubscriptionFilename; bool m_checkSubscription; + bool m_notifyActivation; String m_subscriptionSerial; }; From d4d5d83bb6166504dbd0d06c57b8e5b78771433a Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 28 Oct 2015 14:09:04 -0700 Subject: [PATCH 04/40] Check OS info from GUI #4933 --- src/gui/src/CommandProcess.cpp | 37 ++++++++++++++++++++++++++++++---- src/gui/src/CommandProcess.h | 5 +++-- src/gui/src/PluginManager.cpp | 1 - src/gui/src/QUtility.cpp | 19 +++++++++++++++++ src/gui/src/QUtility.h | 1 + 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/gui/src/CommandProcess.cpp b/src/gui/src/CommandProcess.cpp index 763a7058..ce239129 100644 --- a/src/gui/src/CommandProcess.cpp +++ b/src/gui/src/CommandProcess.cpp @@ -18,17 +18,46 @@ #include "CommandProcess.h" #include +#include -CommandProcess::CommandProcess(QString cmd, QStringList arguments) : +CommandProcess::CommandProcess(QString cmd, QStringList arguments, QString input) : m_Command(cmd), - m_Arguments(arguments) + m_Arguments(arguments), + m_Input(input) { } -void CommandProcess::run() +QString CommandProcess::run() { QProcess process; + process.setReadChannel(QProcess::StandardOutput); process.start(m_Command, m_Arguments); - process.waitForFinished(); + bool success = process.waitForFinished(); + + QString output, error; + if (success) + { + if (!m_Input.isEmpty()) { + process.write(m_Input.toStdString().c_str()); + } + + if (process.waitForFinished()) { + output = process.readAllStandardOutput().trimmed(); + error = process.readAllStandardError().trimmed(); + } + } + + int code = process.exitCode(); + if (!error.isEmpty() || !success || code != 0) + { + throw std::runtime_error( + QString("Code: %1\nError: %2") + .arg(process.exitCode()) + .arg(error.isEmpty() ? "Unknown" : error) + .toStdString()); + } + emit finished(); + + return output; } diff --git a/src/gui/src/CommandProcess.h b/src/gui/src/CommandProcess.h index 62e89bfb..508552da 100644 --- a/src/gui/src/CommandProcess.h +++ b/src/gui/src/CommandProcess.h @@ -25,17 +25,18 @@ class CommandProcess : public QObject Q_OBJECT public: - CommandProcess(QString cmd, QStringList arguments); + CommandProcess(QString cmd, QStringList arguments, QString input = ""); signals: void finished(); public slots: - void run(); + QString run(); private: QString m_Command; QStringList m_Arguments; + QString m_Input; }; #endif // COMMANDTHREAD_H diff --git a/src/gui/src/PluginManager.cpp b/src/gui/src/PluginManager.cpp index a39fef0b..f4d16ff0 100644 --- a/src/gui/src/PluginManager.cpp +++ b/src/gui/src/PluginManager.cpp @@ -18,7 +18,6 @@ #include "PluginManager.h" #include "CoreInterface.h" -#include "CommandProcess.h" #include "DataDownloader.h" #include "QUtility.h" #include "ProcessorArch.h" diff --git a/src/gui/src/QUtility.cpp b/src/gui/src/QUtility.cpp index 14d1d1e1..8be55c18 100644 --- a/src/gui/src/QUtility.cpp +++ b/src/gui/src/QUtility.cpp @@ -18,6 +18,7 @@ #include "QUtility.h" #include "ProcessorArch.h" +#include "CommandProcess" #if defined(Q_OS_LINUX) #include @@ -90,3 +91,21 @@ qProcessorArch getProcessorArch() return kProcessorArchUnknown; } + +QString getOSInformation() +{ + QString output; + +#if defined(Q_OS_LINUX) + CommandProcess cp("/bin/cat", "/etc/os-release"); + QString output = cp.run(); + + QRegExp resultRegex(".*PRETTY_NAME=\".*\".*"); + if (resultRegex.exactMatch(output)) { + QString OSInfo = resultRegex.cap(1); + output = OSInfo; + } +#endif + + return output; +} diff --git a/src/gui/src/QUtility.h b/src/gui/src/QUtility.h index 89861dda..01a42c03 100644 --- a/src/gui/src/QUtility.h +++ b/src/gui/src/QUtility.h @@ -28,3 +28,4 @@ void setIndexFromItemData(QComboBox* comboBox, const QVariant& itemData); QString hash(const QString& string); QString getFirstMacAddress(); qProcessorArch getProcessorArch(); +QString getOSInformation(); From 2535f3466c87b06a740e27e547cbdb639e721d84 Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Wed, 28 Oct 2015 17:15:16 -0700 Subject: [PATCH 05/40] Check OS info from GUI #4933 --- src/gui/src/CommandProcess.cpp | 2 +- src/gui/src/QUtility.cpp | 14 ++++++++------ src/gui/src/WebClient.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gui/src/CommandProcess.cpp b/src/gui/src/CommandProcess.cpp index ce239129..e1b4a7e4 100644 --- a/src/gui/src/CommandProcess.cpp +++ b/src/gui/src/CommandProcess.cpp @@ -32,7 +32,7 @@ QString CommandProcess::run() QProcess process; process.setReadChannel(QProcess::StandardOutput); process.start(m_Command, m_Arguments); - bool success = process.waitForFinished(); + bool success = process.waitForStarted(); QString output, error; if (success) diff --git a/src/gui/src/QUtility.cpp b/src/gui/src/QUtility.cpp index 8be55c18..dcc8f5eb 100644 --- a/src/gui/src/QUtility.cpp +++ b/src/gui/src/QUtility.cpp @@ -18,7 +18,7 @@ #include "QUtility.h" #include "ProcessorArch.h" -#include "CommandProcess" +#include "CommandProcess.h" #if defined(Q_OS_LINUX) #include @@ -94,18 +94,20 @@ qProcessorArch getProcessorArch() QString getOSInformation() { - QString output; + QString result; #if defined(Q_OS_LINUX) - CommandProcess cp("/bin/cat", "/etc/os-release"); + QStringList arguments; + arguments.append("/etc/os-release"); + CommandProcess cp("/bin/cat", arguments); QString output = cp.run(); - QRegExp resultRegex(".*PRETTY_NAME=\".*\".*"); + QRegExp resultRegex(".*PRETTY_NAME=\"([^\"]+)\".*"); if (resultRegex.exactMatch(output)) { QString OSInfo = resultRegex.cap(1); - output = OSInfo; + result = OSInfo; } #endif - return output; + return result; } diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp index c231c970..9362c008 100644 --- a/src/gui/src/WebClient.cpp +++ b/src/gui/src/WebClient.cpp @@ -94,6 +94,12 @@ QString WebClient::request( { QStringList args("--login-auth"); // hash password in case it contains interesting chars. - QString credentials(email + ":" + hash(password) + ":" + hash(getFirstMacAddress()) + "\n"); + QString credentials(email + ":" + hash(password) + ":" + hash(getFirstMacAddress())); + QString os= getOSInformation(); + if (!os.isEmpty()) { + credentials.append(":").append(os); + } + credentials.append("\n"); + return m_CoreInterface.run(args, credentials); } From 582629e968a0f558474464c03a5d63a36438cd5f Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 28 Oct 2015 17:29:42 -0700 Subject: [PATCH 06/40] Use the passed in OS info if specified #4933 --- src/lib/synergy/ToolApp.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 436db09d..4b41b0d8 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -154,16 +154,26 @@ ToolApp::loginAuth() size_t separator1 = credentials.find(':'); size_t separator2 = credentials.find(':', separator1 + 1); + size_t separator3 = credentials.find(':', separator2 + 1); String email = credentials.substr(0, separator1); String password = credentials.substr(separator1 + 1, separator2 - separator1 - 1); - String macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1); + String macHash; + String os; + if (separator3 != String::npos) { + macHash = credentials.substr(separator2 + 1, separator3 - separator2 - 1); + os = credentials.substr(separator3 + 1, credentials.length() - separator3 - 1); + } + else { + macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1); + os = ARCH->getOSName(); + } std::stringstream ss; ss << JSON_URL << "auth/"; ss << "?email=" << ARCH->internet().urlEncode(email); ss << "&password=" << password; ss << "&mac=" << macHash; - ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); + ss << "&os=" << ARCH->internet().urlEncode(os); ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); std::cout << ARCH->internet().get(ss.str()) << std::endl; From 27f83e1801e322f6aab4829812ea22a396b762a0 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 11:42:16 -0700 Subject: [PATCH 07/40] Refactor duplicated code #4933 --- src/gui/src/CoreInterface.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 1a917382..4705b8cc 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -17,6 +17,8 @@ #include "CoreInterface.h" +#include "CommandProcess.h" + #include #include #include @@ -83,33 +85,7 @@ QString CoreInterface::run(const QStringList& args, const QString& input) QCoreApplication::applicationDirPath() + "/" + kCoreBinary); - QProcess process; - process.setReadChannel(QProcess::StandardOutput); - process.start(program, args); - bool success = process.waitForStarted(); + CommandProcess commandProcess(program, args, input); + return commandProcess.run(); - QString output, error; - if (success) - { - if (!input.isEmpty()) { - process.write(input.toStdString().c_str()); - } - - if (process.waitForFinished()) { - output = process.readAllStandardOutput().trimmed(); - error = process.readAllStandardError().trimmed(); - } - } - - int code = process.exitCode(); - if (!error.isEmpty() || !success || code != 0) - { - throw std::runtime_error( - QString("Code: %1\nError: %2") - .arg(process.exitCode()) - .arg(error.isEmpty() ? "Unknown" : error) - .toStdString()); - } - - return output; } From 72397137c0d5cd6d9799debffccd3dcf41f8194a Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 12:52:55 -0700 Subject: [PATCH 08/40] Add split string function #4933 --- src/lib/base/String.cpp | 20 ++++++++++++++++++++ src/lib/base/String.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 99a2bb43..cbaae56b 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -224,6 +224,26 @@ stringToSizeType(String string) return value; } +std::vector +splitString(String string, const char c) +{ + std::vector results; + + size_t head = 0; + size_t separator = string.find(c); + while (separator != String::npos) { + results.push_back(string.substr(head, separator - head)); + head = separator + 1; + separator = string.find(c, head); + } + + if (head < string.size()) { + results.push_back(string.substr(head, string.size() - head)); + } + + return results; +} + // // CaselessCmp // diff --git a/src/lib/base/String.h b/src/lib/base/String.h index de34ad0a..df4307a6 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -22,6 +22,7 @@ #include "common/stdstring.h" #include +#include // use standard C++ string class for our string class typedef std::string String; @@ -100,6 +101,12 @@ Convert an a \c string to an size type */ size_t stringToSizeType(String string); +//! Split a string into substrings +/*! +Split a \c string that separated by a \c c into substrings +*/ +std::vector splitString(String string, const char c); + //! Case-insensitive comparisons /*! This class provides case-insensitve comparison functions. From 1b73b8875b89caa08fa607642c3bc19f8cb9091a Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 12:53:15 -0700 Subject: [PATCH 09/40] Add unit tests for split string function #4933 --- src/test/unittests/base/StringTests.cpp | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 6381cac5..8c76b578 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -100,3 +100,37 @@ TEST(StringTests, stringToUint) EXPECT_EQ(123, value); } + +TEST(StringTests, splitString1) +{ + String string = "stub1:stub2:stub3"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(3, results.size()); + EXPECT_EQ("stub1", results[0]); + EXPECT_EQ("stub2", results[1]); + EXPECT_EQ("stub3", results[2]); +} + +TEST(StringTests, splitString2) +{ + String string = "stub1:stub2:"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(2, results.size()); + EXPECT_EQ("stub1", results[0]); + EXPECT_EQ("stub2", results[1]); +} + +TEST(StringTests, splitString3) +{ + String string = "stub1"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(1, results.size()); + EXPECT_EQ("stub1", results[0]); +} + From d429988e739442261639f22dee77efdad1baae46 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 13:00:03 -0700 Subject: [PATCH 10/40] Add more unit tests for split string function #4933 --- src/lib/base/String.cpp | 4 ++- src/test/unittests/base/StringTests.cpp | 42 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index cbaae56b..689295b6 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -232,7 +232,9 @@ splitString(String string, const char c) size_t head = 0; size_t separator = string.find(c); while (separator != String::npos) { - results.push_back(string.substr(head, separator - head)); + if (head!=separator) { + results.push_back(string.substr(head, separator - head)); + } head = separator + 1; separator = string.find(c, head); } diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 8c76b578..29606417 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -101,7 +101,7 @@ TEST(StringTests, stringToUint) EXPECT_EQ(123, value); } -TEST(StringTests, splitString1) +TEST(StringTests, splitString_twoSeparator_returnThreeParts) { String string = "stub1:stub2:stub3"; @@ -113,7 +113,28 @@ TEST(StringTests, splitString1) EXPECT_EQ("stub3", results[2]); } -TEST(StringTests, splitString2) +TEST(StringTests, splitString_oneSeparator_returnTwoParts) +{ + String string = "stub1:stub2"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(2, results.size()); + EXPECT_EQ("stub1", results[0]); + EXPECT_EQ("stub2", results[1]); +} + +TEST(StringTests, splitString_noSeparator_returnOriginalString) +{ + String string = "stub1"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(1, results.size()); + EXPECT_EQ("stub1", results[0]); +} + +TEST(StringTests, splitString_tailSeparator_returnTwoParts) { String string = "stub1:stub2:"; @@ -124,13 +145,24 @@ TEST(StringTests, splitString2) EXPECT_EQ("stub2", results[1]); } -TEST(StringTests, splitString3) +TEST(StringTests, splitString_headSeparator_returnTwoParts) { - String string = "stub1"; + String string = ":stub1:stub2"; std::vector results = string::splitString(string, ':'); - EXPECT_EQ(1, results.size()); + EXPECT_EQ(2, results.size()); EXPECT_EQ("stub1", results[0]); + EXPECT_EQ("stub2", results[1]); } +TEST(StringTests, splitString_headAndTailSeparators_returnTwoParts) +{ + String string = ":stub1:stub2:"; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(2, results.size()); + EXPECT_EQ("stub1", results[0]); + EXPECT_EQ("stub2", results[1]); +} From c148fbb7f4ea94200bdc07c48d0256c3a13c6bf5 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 13:08:00 -0700 Subject: [PATCH 11/40] Fix unit tests name convention #4933 --- src/test/unittests/base/StringTests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 29606417..55acb914 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -21,7 +21,7 @@ using namespace synergy; -TEST(StringTests, format) +TEST(StringTests, format_formatWithArguments_formatedString) { const char* format = "%%%{1}=%{2}"; const char* arg1 = "answer"; @@ -32,7 +32,7 @@ TEST(StringTests, format) EXPECT_EQ("%answer=42", result); } -TEST(StringTests, findReplaceAll) +TEST(StringTests, findReplaceAll_inputString_replacedString) { String subject = "foobar"; String find = "bar"; @@ -43,7 +43,7 @@ TEST(StringTests, findReplaceAll) EXPECT_EQ("foobaz", subject); } -TEST(StringTests, sprintf) +TEST(StringTests, sprintf_formatWithArgument_formatedString) { const char* format = "%s=%d"; const char* arg1 = "answer"; @@ -54,7 +54,7 @@ TEST(StringTests, sprintf) EXPECT_EQ("answer=42", result); } -TEST(StringTests, toHex) +TEST(StringTests, toHex_plaintext_hexString) { String subject = "foobar"; int width = 2; @@ -64,7 +64,7 @@ TEST(StringTests, toHex) EXPECT_EQ("666f6f626172", subject); } -TEST(StringTests, uppercase) +TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput) { String subject = "12foo3BaR"; @@ -73,7 +73,7 @@ TEST(StringTests, uppercase) EXPECT_EQ("12FOO3BAR", subject); } -TEST(StringTests, removeChar) +TEST(StringTests, removeChar_inputString_removeAllSpecifiedCharactors) { String subject = "foobar"; const char c = 'o'; @@ -83,7 +83,7 @@ TEST(StringTests, removeChar) EXPECT_EQ("fbar", subject); } -TEST(StringTests, intToString) +TEST(StringTests, intToString_inputInt_outputString) { size_t value = 123; @@ -92,7 +92,7 @@ TEST(StringTests, intToString) EXPECT_EQ("123", number); } -TEST(StringTests, stringToUint) +TEST(StringTests, stringToUint_inputString_outputInt) { String number = "123"; From 942dcabdcd028f2cf18102dccfe7e90dcf352fba Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 15:11:09 -0700 Subject: [PATCH 12/40] Add split empty string unit test #4933 --- src/test/unittests/base/StringTests.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 55acb914..f34e917a 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -134,6 +134,15 @@ TEST(StringTests, splitString_noSeparator_returnOriginalString) EXPECT_EQ("stub1", results[0]); } +TEST(StringTests, splitString_emptyString_returnEmptyVector) +{ + String string; + + std::vector results = string::splitString(string, ':'); + + EXPECT_EQ(0, results.size()); +} + TEST(StringTests, splitString_tailSeparator_returnTwoParts) { String string = "stub1:stub2:"; From b4563a42c49a70973e76ccb25315220445165398 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 15:47:10 -0700 Subject: [PATCH 13/40] Use string split function in syntool #4933 --- src/lib/synergy/ToolApp.cpp | 83 +++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 32 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 4b41b0d8..7b5a5715 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -152,31 +152,35 @@ ToolApp::loginAuth() String credentials; std::cin >> credentials; - size_t separator1 = credentials.find(':'); - size_t separator2 = credentials.find(':', separator1 + 1); - size_t separator3 = credentials.find(':', separator2 + 1); - String email = credentials.substr(0, separator1); - String password = credentials.substr(separator1 + 1, separator2 - separator1 - 1); - String macHash; - String os; - if (separator3 != String::npos) { - macHash = credentials.substr(separator2 + 1, separator3 - separator2 - 1); - os = credentials.substr(separator3 + 1, credentials.length() - separator3 - 1); + std::vector parts = synergy::string::splitString(credentials, ':'); + int count = parts.size(); + + if (count == 3 || count == 4) { + String email = parts[0]; + String password = parts[1]; + String macHash = parts[2]; + String os; + + if (count == 4) { + os = parts[3]; + } + else { + os = ARCH->getOSName(); + } + + std::stringstream ss; + ss << JSON_URL << "auth/"; + ss << "?email=" << ARCH->internet().urlEncode(email); + ss << "&password=" << password; + ss << "&mac=" << macHash; + ss << "&os=" << ARCH->internet().urlEncode(os); + ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); + + std::cout << ARCH->internet().get(ss.str()) << std::endl; } else { - macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1); - os = ARCH->getOSName(); + throw XSynergy("Invalid credentials."); } - - std::stringstream ss; - ss << JSON_URL << "auth/"; - ss << "?email=" << ARCH->internet().urlEncode(email); - ss << "&password=" << password; - ss << "&mac=" << macHash; - ss << "&os=" << ARCH->internet().urlEncode(os); - ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); - - std::cout << ARCH->internet().get(ss.str()) << std::endl; } void @@ -203,16 +207,31 @@ ToolApp::notifyActivation() String info; std::cin >> info; - size_t separator = info.find(':'); - String action = info.substr(0, separator); - String macHash = info.substr(separator + 1, info.length()); + std::vector parts = synergy::string::splitString(info, ':'); + int count = parts.size(); - std::stringstream ss; - ss << JSON_URL << "notify/"; - ss << "?action=" << action; - ss << "&mac=" << macHash; - ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); - ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); + if (count == 2 || count == 3) { + String action = parts[0]; + String macHash = parts[1]; + String os; - std::cout << ARCH->internet().get(ss.str()) << std::endl; + if (count == 3) { + os = parts[2]; + } + else { + os = ARCH->getOSName(); + } + + std::stringstream ss; + ss << JSON_URL << "notify/"; + ss << "?action=" << action; + ss << "&mac=" << macHash; + ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); + ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); + + std::cout << ARCH->internet().get(ss.str()) << std::endl; + } + else { + throw XSynergy("Invalid credentials."); + } } From f03b453c6f9167dc51e7a24aa8485b35a0354b43 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 15:55:55 -0700 Subject: [PATCH 14/40] Pass Linux OS info during notification #4932 --- src/gui/src/CoreInterface.cpp | 11 ++++++++++- src/gui/src/CoreInterface.h | 2 +- src/gui/src/SetupWizard.cpp | 6 ++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 4705b8cc..9d24a3df 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -18,6 +18,7 @@ #include "CoreInterface.h" #include "CommandProcess.h" +#include "QUtility.h" #include #include @@ -73,9 +74,17 @@ QString CoreInterface::checkSubscription() return run(args); } -QString CoreInterface::notifyActivation(const QString& input) +QString CoreInterface::notifyActivation(const QString& action) { QStringList args("--notify-activation"); + + QString input(action + ":" + hash(getFirstMacAddress())); + QString os= getOSInformation(); + if (!os.isEmpty()) { + input.append(":").append(os); + } + input.append("\n"); + return run(args, input); } diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index 4949bddc..004a3928 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -31,6 +31,6 @@ public: QString getSubscriptionFilename(); QString activateSerial(const QString& serial); QString checkSubscription(); - QString notifyActivation(const QString& input); + QString notifyActivation(const QString& action); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index bbe14328..c45f30a0 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -217,16 +217,14 @@ void SetupWizard::accept() { appConfig.setSerialKey(m_pLineEditSerialKey->text()); - QString info("serial:" + hash(getFirstMacAddress()) + "\n"); CoreInterface coreInterface; - coreInterface.notifyActivation(info); + coreInterface.notifyActivation("serial"); } if (m_pRadioButtonSkip->isChecked()) { - QString info("skip:" + hash(getFirstMacAddress()) + "\n"); CoreInterface coreInterface; - coreInterface.notifyActivation(info); + coreInterface.notifyActivation("skip"); } m_MainWindow.setEdition(m_Edition); From 0a1c4395357e6afe9751541f093ea68a4a6991f5 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 16:50:23 -0700 Subject: [PATCH 15/40] Only send notify request on wizard finish #4932 --- src/gui/src/CoreInterface.cpp | 4 ++-- src/gui/src/CoreInterface.h | 2 +- src/gui/src/SetupWizard.cpp | 11 +++++++++-- src/gui/src/WebClient.cpp | 7 +------ src/lib/synergy/ToolApp.cpp | 24 +++++++----------------- 5 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 9d24a3df..12703ae7 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -74,11 +74,11 @@ QString CoreInterface::checkSubscription() return run(args); } -QString CoreInterface::notifyActivation(const QString& action) +QString CoreInterface::notifyActivation(const QString& identity) { QStringList args("--notify-activation"); - QString input(action + ":" + hash(getFirstMacAddress())); + QString input(identity + ":" + hash(getFirstMacAddress())); QString os= getOSInformation(); if (!os.isEmpty()) { input.append(":").append(os); diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index 004a3928..f65348af 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -31,6 +31,6 @@ public: QString getSubscriptionFilename(); QString activateSerial(const QString& serial); QString checkSubscription(); - QString notifyActivation(const QString& action); + QString notifyActivation(const QString& identity); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index c45f30a0..ecacab65 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -211,6 +211,9 @@ void SetupWizard::accept() QString hashResult = hash(hashSrc); appConfig.setUserToken(hashResult); appConfig.setEdition(m_Edition); + + CoreInterface coreInterface; + coreInterface.notifyActivation("login:" + m_pLineEditEmail->text()); } if (m_pRadioButtonSubscription->isChecked()) @@ -218,13 +221,13 @@ void SetupWizard::accept() appConfig.setSerialKey(m_pLineEditSerialKey->text()); CoreInterface coreInterface; - coreInterface.notifyActivation("serial"); + coreInterface.notifyActivation("serial:" + m_pLineEditSerialKey->text()); } if (m_pRadioButtonSkip->isChecked()) { CoreInterface coreInterface; - coreInterface.notifyActivation("skip"); + coreInterface.notifyActivation("skip:unknown"); } m_MainWindow.setEdition(m_Edition); @@ -251,6 +254,10 @@ void SetupWizard::reject() m_MainWindow.open(); } + // treat cancel as skip + CoreInterface coreInterface; + coreInterface.notifyActivation("skip:unknown"); + QWizard::reject(); } diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp index 9362c008..451bf47f 100644 --- a/src/gui/src/WebClient.cpp +++ b/src/gui/src/WebClient.cpp @@ -94,12 +94,7 @@ QString WebClient::request( { QStringList args("--login-auth"); // hash password in case it contains interesting chars. - QString credentials(email + ":" + hash(password) + ":" + hash(getFirstMacAddress())); - QString os= getOSInformation(); - if (!os.isEmpty()) { - credentials.append(":").append(os); - } - credentials.append("\n"); + QString credentials(email + ":" + hash(password) + "\n"); return m_CoreInterface.run(args, credentials); } diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 7b5a5715..0b4978b7 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -155,26 +155,14 @@ ToolApp::loginAuth() std::vector parts = synergy::string::splitString(credentials, ':'); int count = parts.size(); - if (count == 3 || count == 4) { + if (count == 2 ) { String email = parts[0]; String password = parts[1]; - String macHash = parts[2]; - String os; - - if (count == 4) { - os = parts[3]; - } - else { - os = ARCH->getOSName(); - } std::stringstream ss; ss << JSON_URL << "auth/"; ss << "?email=" << ARCH->internet().urlEncode(email); ss << "&password=" << password; - ss << "&mac=" << macHash; - ss << "&os=" << ARCH->internet().urlEncode(os); - ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); std::cout << ARCH->internet().get(ss.str()) << std::endl; } @@ -210,13 +198,14 @@ ToolApp::notifyActivation() std::vector parts = synergy::string::splitString(info, ':'); int count = parts.size(); - if (count == 2 || count == 3) { + if (count == 3 || count == 4) { String action = parts[0]; - String macHash = parts[1]; + String identity = parts[1]; + String macHash = parts[2]; String os; - if (count == 3) { - os = parts[2]; + if (count == 4) { + os = parts[3]; } else { os = ARCH->getOSName(); @@ -225,6 +214,7 @@ ToolApp::notifyActivation() std::stringstream ss; ss << JSON_URL << "notify/"; ss << "?action=" << action; + ss << "&identity=" << identity; ss << "&mac=" << macHash; ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); From 068b3b98ed68a6e2bdda4dc681d4ce99a40b53de Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 11:25:16 -0700 Subject: [PATCH 16/40] Fix compile warnning #4933 --- src/lib/synergy/ToolApp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 0b4978b7..6a156b26 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -153,7 +153,7 @@ ToolApp::loginAuth() std::cin >> credentials; std::vector parts = synergy::string::splitString(credentials, ':'); - int count = parts.size(); + size_t count = parts.size(); if (count == 2 ) { String email = parts[0]; @@ -196,7 +196,7 @@ ToolApp::notifyActivation() std::cin >> info; std::vector parts = synergy::string::splitString(info, ':'); - int count = parts.size(); + size_t count = parts.size(); if (count == 3 || count == 4) { String action = parts[0]; From 73ac3df22d9799ac8ddcbea79c24aa456d57a56c Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 11:41:51 -0700 Subject: [PATCH 17/40] Limit expired time to trial version #4716 --- src/lib/synergy/SubscriptionManager.cpp | 6 +++-- src/lib/synergy/SubscriptionManager.h | 5 ++-- .../unittests/synergy/SubscriptionTests.cpp | 25 +++++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/lib/synergy/SubscriptionManager.cpp b/src/lib/synergy/SubscriptionManager.cpp index 2b51e17d..ecc272c3 100644 --- a/src/lib/synergy/SubscriptionManager.cpp +++ b/src/lib/synergy/SubscriptionManager.cpp @@ -150,12 +150,14 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& sscanf(parts.at(5).c_str(), "%d", &key.m_expireTime); // TODO: use Arch time - if (time(0) > key.m_expireTime) { + if (time(0) > key.m_expireTime && + key.m_type == "trial") { throw XSubscription(synergy::string::sprintf( "%s subscription has expired", key.m_type.c_str())); } - else if (time(0) > key.m_warnTime) { + else if (time(0) > key.m_warnTime && + key.m_type == "trial") { LOG((CLOG_WARN "%s subscription will expire soon", key.m_type.c_str())); } diff --git a/src/lib/synergy/SubscriptionManager.h b/src/lib/synergy/SubscriptionManager.h index 1f08006b..2817f768 100644 --- a/src/lib/synergy/SubscriptionManager.h +++ b/src/lib/synergy/SubscriptionManager.h @@ -41,8 +41,9 @@ private: FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText); FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException); - FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException); - FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey); private: String decode(const String& input); diff --git a/src/test/unittests/synergy/SubscriptionTests.cpp b/src/test/unittests/synergy/SubscriptionTests.cpp index 3e2c9dc9..368542ae 100644 --- a/src/test/unittests/synergy/SubscriptionTests.cpp +++ b/src/test/unittests/synergy/SubscriptionTests.cpp @@ -54,21 +54,22 @@ TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException) EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); } -TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException) +TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey) { + // valid until 2 March 2049 SubscriptionManager subscriptionManager; - String painText("{v1;trial;Bob;1;1498297600;1498384000}"); + String painText("{v1;trial;Bob;1;2147483647;2147483647}"); SubscriptionKey key; subscriptionManager.parsePlainSerial(painText, key); EXPECT_EQ("trial", key.m_type); EXPECT_EQ("Bob", key.m_name); EXPECT_EQ(1, key.m_userLimit); - EXPECT_EQ(1498297600, key.m_warnTime); - EXPECT_EQ(1498384000, key.m_expireTime); + EXPECT_EQ(2147483647, key.m_warnTime); + EXPECT_EQ(2147483647, key.m_expireTime); } -TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException) +TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException) { SubscriptionManager subscriptionManager; String painText("{v1;trial;Bob;1;1398297600;1398384000}"); @@ -76,3 +77,17 @@ TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException) EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription); } + +TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey) +{ + SubscriptionManager subscriptionManager; + String painText("{v1;basic;Bob;1;1398297600;1398384000}"); + SubscriptionKey key; + subscriptionManager.parsePlainSerial(painText, key); + + EXPECT_EQ("basic", key.m_type); + EXPECT_EQ("Bob", key.m_name); + EXPECT_EQ(1, key.m_userLimit); + EXPECT_EQ(1398297600, key.m_warnTime); + EXPECT_EQ(1398384000, key.m_expireTime); +} From bdc02677ec776ceb28802a522ac9378d48510e85 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 11:57:12 -0700 Subject: [PATCH 18/40] Add trial edition type #4716 --- src/gui/src/EditionType.h | 1 + src/gui/src/MainWindow.cpp | 3 +++ src/gui/src/PluginWizardPage.cpp | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/src/EditionType.h b/src/gui/src/EditionType.h index ec465a6c..2229cd23 100644 --- a/src/gui/src/EditionType.h +++ b/src/gui/src/EditionType.h @@ -21,6 +21,7 @@ enum qEditionType { Basic, Pro, + Trial, Unknown }; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 99cd9336..572695bc 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -992,6 +992,9 @@ void MainWindow::setEdition(int type) else if (type == Pro) { title = "Synergy Pro"; } + else if (type == Trial) { + title = "Synergy Trial"; + } else { title = "Synergy (UNREGISTERED)"; } diff --git a/src/gui/src/PluginWizardPage.cpp b/src/gui/src/PluginWizardPage.cpp index ecbc26e4..ace607da 100644 --- a/src/gui/src/PluginWizardPage.cpp +++ b/src/gui/src/PluginWizardPage.cpp @@ -64,8 +64,7 @@ void PluginWizardPage::initializePage() { QWizardPage::initializePage(); - if (m_Edition == Unknown || - m_Edition == Basic) { + if (m_Edition != Pro) { updateStatus(tr("Setup complete.")); showFinished(); return; From 382607129c439b8a16a6f6558a2e97de54057383 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 12:43:28 -0700 Subject: [PATCH 19/40] Make notify failure silent #4932 --- src/lib/synergy/ToolApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 6a156b26..a8f61714 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -222,6 +222,6 @@ ToolApp::notifyActivation() std::cout << ARCH->internet().get(ss.str()) << std::endl; } else { - throw XSynergy("Invalid credentials."); + LOG((CLOG_WARN "notify activation failed")); } } From 10e3917b617c690e4c7f0bd293a420f3ed23c466 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 13:42:05 -0700 Subject: [PATCH 20/40] Change notify failure log level #4932 --- src/lib/synergy/ToolApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index a8f61714..b4e19a84 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -222,6 +222,6 @@ ToolApp::notifyActivation() std::cout << ARCH->internet().get(ss.str()) << std::endl; } else { - LOG((CLOG_WARN "notify activation failed")); + LOG((CLOG_DEBUG "notify activation failed")); } } From 4c1b6f3f2340cb03ecf581605ec1c8b1d81659fd Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 30 Oct 2015 13:49:18 -0700 Subject: [PATCH 21/40] Use test website #4932 --- src/lib/synergy/ToolApp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index b4e19a84..74d1cacf 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -30,7 +30,7 @@ #include "platform/MSWindowsSession.h" #endif -#define JSON_URL "https://synergy-project.org/premium/json/" +#define JSON_URL "https://test.synergy-project.org/premium/json/" enum { kErrorOk, From 9eec29927833aee4d5436912e94655a053610c83 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 12 Nov 2015 09:50:30 -0800 Subject: [PATCH 22/40] Check user type from serial key #4715 --- src/gui/src/SubscriptionManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index a0c10916..0173248a 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -88,9 +88,15 @@ bool SubscriptionManager::checkSubscriptionExist() int SubscriptionManager::getEditionType(QString& string) { - if (string.contains("full subscription valid")) { + if (string.contains("pro subscription valid")) { return Pro; } + else if (string.contains("basic subscription valid")) { + return Basic; + } + else if (string.contains("trial subscription valid")) { + return Trial; + } return Unknown; } From 55df81b1a66804b87fb392a9d258f7d81e94eab0 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 12 Nov 2015 10:08:35 -0800 Subject: [PATCH 23/40] Add company and email into serial key #4715 --- src/lib/synergy/SubscriptionKey.h | 2 ++ src/lib/synergy/SubscriptionManager.cpp | 10 ++++++---- src/lib/synergy/SubscriptionManager.h | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/synergy/SubscriptionKey.h b/src/lib/synergy/SubscriptionKey.h index 0d65a17c..28744fed 100644 --- a/src/lib/synergy/SubscriptionKey.h +++ b/src/lib/synergy/SubscriptionKey.h @@ -22,6 +22,8 @@ struct SubscriptionKey { String m_name; String m_type; + String m_email; + String m_company; int m_userLimit; int m_warnTime; int m_expireTime; diff --git a/src/lib/synergy/SubscriptionManager.cpp b/src/lib/synergy/SubscriptionManager.cpp index ecc272c3..a657a21e 100644 --- a/src/lib/synergy/SubscriptionManager.cpp +++ b/src/lib/synergy/SubscriptionManager.cpp @@ -140,14 +140,16 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& pos += 1; } - // e.g.: {v1;trial;Bob;1;1398297600;1398384000} - if ((parts.size() == 6) + // e.g.: {v1;trial;Bob;1;email;company name;1398297600;1398384000} + if ((parts.size() == 8) && (parts.at(0).find("v1") != String::npos)) { key.m_type = parts.at(1); key.m_name = parts.at(2); sscanf(parts.at(3).c_str(), "%d", &key.m_userLimit); - sscanf(parts.at(4).c_str(), "%d", &key.m_warnTime); - sscanf(parts.at(5).c_str(), "%d", &key.m_expireTime); + key.m_email = parts.at(4); + key.m_company = parts.at(5); + sscanf(parts.at(6).c_str(), "%d", &key.m_warnTime); + sscanf(parts.at(7).c_str(), "%d", &key.m_expireTime); // TODO: use Arch time if (time(0) > key.m_expireTime && diff --git a/src/lib/synergy/SubscriptionManager.h b/src/lib/synergy/SubscriptionManager.h index 2817f768..fb52701b 100644 --- a/src/lib/synergy/SubscriptionManager.h +++ b/src/lib/synergy/SubscriptionManager.h @@ -37,13 +37,14 @@ public: private: FRIEND_TEST(SubscriptionTests, decode_invalidLength_throwException); - FRIEND_TEST(SubscriptionTests, decode_unrecognizedDigit_throwException); FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText); + FRIEND_TEST(SubscriptionTests, decode_unrecognizedDigit_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey); FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException); FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey); + FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerialWithoutCompany_validSubscriptionKey); private: String decode(const String& input); From 8c4ccdf1487c1ea3b4a29fb680890c2c9c5d088f Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 12 Nov 2015 10:08:55 -0800 Subject: [PATCH 24/40] Unit test for new fields in serial key #4715 --- .../unittests/synergy/SubscriptionTests.cpp | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/test/unittests/synergy/SubscriptionTests.cpp b/src/test/unittests/synergy/SubscriptionTests.cpp index 368542ae..eeda3e7b 100644 --- a/src/test/unittests/synergy/SubscriptionTests.cpp +++ b/src/test/unittests/synergy/SubscriptionTests.cpp @@ -58,13 +58,32 @@ TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey) { // valid until 2 March 2049 SubscriptionManager subscriptionManager; - String painText("{v1;trial;Bob;1;2147483647;2147483647}"); + String painText("{v1;trial;Bob;1;a@a.a;mock company;2147483647;2147483647}"); SubscriptionKey key; subscriptionManager.parsePlainSerial(painText, key); EXPECT_EQ("trial", key.m_type); EXPECT_EQ("Bob", key.m_name); EXPECT_EQ(1, key.m_userLimit); + EXPECT_EQ("a@a.a", key.m_email); + EXPECT_EQ("mock company", key.m_company); + EXPECT_EQ(2147483647, key.m_warnTime); + EXPECT_EQ(2147483647, key.m_expireTime); +} + +TEST(SubscriptionTests, parsePlainSerial_validSerialWithoutCompany_validSubscriptionKey) +{ + // valid until 2 March 2049 + SubscriptionManager subscriptionManager; + String painText("{v1;trial;Bob;1;a@a.a;;2147483647;2147483647}"); + SubscriptionKey key; + subscriptionManager.parsePlainSerial(painText, key); + + EXPECT_EQ("trial", key.m_type); + EXPECT_EQ("Bob", key.m_name); + EXPECT_EQ(1, key.m_userLimit); + EXPECT_EQ("a@a.a", key.m_email); + EXPECT_EQ("", key.m_company); EXPECT_EQ(2147483647, key.m_warnTime); EXPECT_EQ(2147483647, key.m_expireTime); } @@ -81,13 +100,15 @@ TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException) TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey) { SubscriptionManager subscriptionManager; - String painText("{v1;basic;Bob;1;1398297600;1398384000}"); + String painText("{v1;basic;Bob;1;a@a.a;mock company;1398297600;1398384000}"); SubscriptionKey key; subscriptionManager.parsePlainSerial(painText, key); EXPECT_EQ("basic", key.m_type); EXPECT_EQ("Bob", key.m_name); EXPECT_EQ(1, key.m_userLimit); + EXPECT_EQ("a@a.a", key.m_email); + EXPECT_EQ("mock company", key.m_company); EXPECT_EQ(1398297600, key.m_warnTime); EXPECT_EQ(1398384000, key.m_expireTime); } From 4b7796d215f98a1a937e291a3946519fd2705a9d Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 12 Nov 2015 12:05:26 -0800 Subject: [PATCH 25/40] Catch exception from notification request #4932 --- src/lib/synergy/ToolApp.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 74d1cacf..0549c396 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -30,7 +30,7 @@ #include "platform/MSWindowsSession.h" #endif -#define JSON_URL "https://test.synergy-project.org/premium/json/" +#define JSON_URL "http://test.synergy-project.org/premium/json/" enum { kErrorOk, @@ -219,9 +219,17 @@ ToolApp::notifyActivation() ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); - std::cout << ARCH->internet().get(ss.str()) << std::endl; + try { + std::cout << ARCH->internet().get(ss.str()) << std::endl; + } + catch (std::exception& e) { + LOG((CLOG_CRIT "An error occurred during notification: %s\n", e.what())); + } + catch (...) { + LOG((CLOG_CRIT "An unknown error occurred during notification.\n")); + } } else { - LOG((CLOG_DEBUG "notify activation failed")); + LOG((CLOG_DEBUG "notification failed")); } } From ad16599fa59e01bbcf8496bd9c02d4bf62307c5f Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 12 Nov 2015 12:05:37 -0800 Subject: [PATCH 26/40] Fix code style --- src/gui/src/CoreInterface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 12703ae7..13560c1b 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -96,5 +96,4 @@ QString CoreInterface::run(const QStringList& args, const QString& input) CommandProcess commandProcess(program, args, input); return commandProcess.run(); - } From 2fd0d5c68f70ede82f11b7084de143ce70a73422 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Fri, 13 Nov 2015 11:04:23 -0800 Subject: [PATCH 27/40] Modify regex to recognize edition from jason #4933 --- src/gui/src/WebClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp index 451bf47f..cd07b882 100644 --- a/src/gui/src/WebClient.cpp +++ b/src/gui/src/WebClient.cpp @@ -50,7 +50,7 @@ int WebClient::getEdition( if (resultRegex.exactMatch(responseJson)) { QString boolString = resultRegex.cap(1); if (boolString == "true") { - QRegExp editionRegex(".*\"edition\".*:.*\"([^\"]+)\".*"); + QRegExp editionRegex(".*\"edition\":(0|1|2|3).*"); if (editionRegex.exactMatch(responseJson)) { QString e = editionRegex.cap(1); edition = e.toInt(); From 97809f9040b28351190f7278f251672470d25b7f Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Mon, 16 Nov 2015 09:24:49 -0800 Subject: [PATCH 28/40] Revert "Modify regex to recognize edition from jason #4933" This reverts commit 2fd0d5c68f70ede82f11b7084de143ce70a73422. --- src/gui/src/WebClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp index cd07b882..451bf47f 100644 --- a/src/gui/src/WebClient.cpp +++ b/src/gui/src/WebClient.cpp @@ -50,7 +50,7 @@ int WebClient::getEdition( if (resultRegex.exactMatch(responseJson)) { QString boolString = resultRegex.cap(1); if (boolString == "true") { - QRegExp editionRegex(".*\"edition\":(0|1|2|3).*"); + QRegExp editionRegex(".*\"edition\".*:.*\"([^\"]+)\".*"); if (editionRegex.exactMatch(responseJson)) { QString e = editionRegex.cap(1); edition = e.toInt(); From 18d23d6f89652b8f8a82478cb57d82f20691a3a1 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Tue, 17 Nov 2015 10:41:24 -0800 Subject: [PATCH 29/40] Rephrase using serial recommendation #5020 --- src/gui/src/SetupWizard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index ecacab65..ae41c89b 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -103,7 +103,7 @@ bool SetupWizard::validateCurrentPage() QMessageBox::StandardButton reply = QMessageBox::information( this, tr("Setup Synergy"), - tr("Would you like to use serial key to activate?"), + tr("Would you like to use your serial key instead?"), QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { From f8e9047c36e5db0ebd42445248e86ca3c61cb72e Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Tue, 17 Nov 2015 14:17:00 -0800 Subject: [PATCH 30/40] Rephrase and refactor serial warning message #4716 --- src/gui/src/MainWindow.cpp | 15 ++--- src/gui/src/SetupWizard.cpp | 12 +--- src/gui/src/SubscriptionManager.cpp | 86 +++++++++++++++++-------- src/gui/src/SubscriptionManager.h | 13 ++-- src/lib/synergy/SubscriptionManager.cpp | 24 +++---- 5 files changed, 89 insertions(+), 61 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 572695bc..2576c0e0 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -698,22 +698,19 @@ QString MainWindow::appPath(const QString& name) bool MainWindow::serverArgs(QStringList& args, QString& app) { - SubscriptionManager subscriptionManager; + int edition; + SubscriptionManager subscriptionManager(this, edition); if (subscriptionManager.checkSubscriptionExist()) { - int edition; - int state = subscriptionManager.checkSubscription(edition); - - if (state == kInvalid) { + if (!subscriptionManager.checkSubscription()) { return false; } - else if (state == kExpired) { - QMessageBox::warning(this, tr("Subscription is expired"), - tr("Your subscription is expired. Please purchase.")); - return false; + else { + setEdition(edition); } } + app = appPath(appConfig().synergysName()); if (!QFile::exists(app)) diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index ae41c89b..e97030d8 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -127,15 +127,9 @@ bool SetupWizard::validateCurrentPage() } else { // create subscription file in profile directory - SubscriptionManager subscriptionManager; - bool r = subscriptionManager.activateSerial(m_pLineEditSerialKey->text(), m_Edition); - if (!r) { - message.setText(tr("An error occurred while trying to activate using a serial key. " - "Please contact the helpdesk, and provide the " - "following details.\n\n%1").arg(subscriptionManager.getLastError())); - message.exec(); - - return r; + SubscriptionManager subscriptionManager(this, m_Edition); + if (!subscriptionManager.activateSerial(m_pLineEditSerialKey->text())) { + return false; } m_pPluginPage->setEdition(m_Edition); diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 0173248a..b9b0f5ff 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -24,13 +24,16 @@ #include #include -SubscriptionManager::SubscriptionManager() +SubscriptionManager::SubscriptionManager(QWidget* parent, int& edition) : + m_pParent(parent), + m_Edition(edition) { + } -bool SubscriptionManager::activateSerial(const QString& serial, int& edition) +bool SubscriptionManager::activateSerial(const QString& serial) { - edition = Unknown; + m_Edition = Unknown; CoreInterface coreInterface; QString output; @@ -41,17 +44,18 @@ bool SubscriptionManager::activateSerial(const QString& serial, int& edition) catch (std::exception& e) { m_ErrorMessage = e.what(); + checkError(m_ErrorMessage); return false; } - edition = getEditionType(output); + checkOutput(output); return true; } -int SubscriptionManager::checkSubscription(int& edition) +bool SubscriptionManager::checkSubscription() { - edition = Unknown; + m_Edition = Unknown; CoreInterface coreInterface; QString output; try @@ -61,21 +65,13 @@ int SubscriptionManager::checkSubscription(int& edition) catch (std::exception& e) { m_ErrorMessage = e.what(); - - if (m_ErrorMessage.contains("subscription has expired")) { - return kExpired; - } - - return kInvalid; + checkError(m_ErrorMessage); + return false; } - if (output.contains("subscription will expire soon")) { - return kExpiredSoon; - } + checkOutput(output); - edition = getEditionType(output); - - return kValid; + return true; } bool SubscriptionManager::checkSubscriptionExist() @@ -86,17 +82,51 @@ bool SubscriptionManager::checkSubscriptionExist() return QFile::exists(subscriptionFilename); } -int SubscriptionManager::getEditionType(QString& string) +void SubscriptionManager::checkError(QString& error) { - if (string.contains("pro subscription valid")) { - return Pro; + if (error.contains("trial has expired")) { + QMessageBox::warning(m_pParent, tr("Subscription warning"), + tr("Your trial has expired. Click here to purchase")); } - else if (string.contains("basic subscription valid")) { - return Basic; + else { + QMessageBox::warning(m_pParent, tr("Subscription error"), + tr("An error occurred while trying to activate using a serial key. " + "Please contact the helpdesk, and provide the " + "following details.\n\n%1").arg(error)); + } +} + +void SubscriptionManager::checkOutput(QString& output) +{ + getEditionType(output); + checkExpiring(output); +} + +void SubscriptionManager::getEditionType(QString& output) +{ + if (output.contains("pro subscription valid")) { + m_Edition = Pro; + } + else if (output.contains("basic subscription valid")) { + m_Edition = Basic; + } + else if (output.contains("trial subscription valid")) { + m_Edition = Trial; + } +} + +void SubscriptionManager::checkExpiring(QString& output) +{ + if (output.contains("trial will end in")) { + QRegExp dayLeftRegex(".*trial will end in ([0-9]+) day.*"); + if (dayLeftRegex.exactMatch(output)) { + QString dayLeft = dayLeftRegex.cap(1); + + // TODO: warn user once a day + QMessageBox::warning(m_pParent, tr("Subscription warning"), + tr("Your trial will end in %1 %2. Click here to purchase") + .arg(dayLeft) + .arg(dayLeft == "1" ? "day" : "days")); + } } - else if (string.contains("trial subscription valid")) { - return Trial; - } - - return Unknown; } diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index 1af14ad6..bc272ef4 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -22,16 +22,21 @@ class SubscriptionManager : public QWidget { public: - SubscriptionManager(); + SubscriptionManager(QWidget* parent, int& edition); - bool activateSerial(const QString& serial, int& edition); - int checkSubscription(int& edition); + bool activateSerial(const QString& serial); + bool checkSubscription(); bool checkSubscriptionExist(); QString getLastError(){ return m_ErrorMessage; } private: - int getEditionType(QString& string); + void checkError(QString& error); + void checkOutput(QString& output); + void getEditionType(QString& output); + void checkExpiring(QString& output); private: QString m_ErrorMessage; + QWidget* m_pParent; + int& m_Edition; }; diff --git a/src/lib/synergy/SubscriptionManager.cpp b/src/lib/synergy/SubscriptionManager.cpp index a657a21e..78207dc2 100644 --- a/src/lib/synergy/SubscriptionManager.cpp +++ b/src/lib/synergy/SubscriptionManager.cpp @@ -151,17 +151,19 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& sscanf(parts.at(6).c_str(), "%d", &key.m_warnTime); sscanf(parts.at(7).c_str(), "%d", &key.m_expireTime); - // TODO: use Arch time - if (time(0) > key.m_expireTime && - key.m_type == "trial") { - throw XSubscription(synergy::string::sprintf( - "%s subscription has expired", - key.m_type.c_str())); - } - else if (time(0) > key.m_warnTime && - key.m_type == "trial") { - LOG((CLOG_WARN "%s subscription will expire soon", - key.m_type.c_str())); + // only limit to trial version + if (key.m_type == "trial") { + if (time(0) > key.m_expireTime) { + throw XSubscription("trial has expired"); + } + else if (time(0) > key.m_warnTime) { + int secLeft = key.m_expireTime - static_cast(time(0)); + const int spd = 60 * 60 * 24; + int dayLeft = secLeft / spd + 1; + LOG((CLOG_NOTE "trial will end in %d %s", + dayLeft, + dayLeft == 1 ? "day" : "days")); + } } const char* userText = (key.m_userLimit == 1) ? "user" : "users"; From 7ecc0457e042f2ce4c36f40a389994578411e32c Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Tue, 17 Nov 2015 14:51:04 -0800 Subject: [PATCH 31/40] Show subscription warning once a day #4716 --- src/gui/gui.pro | 3 +-- src/gui/src/AppConfig.cpp | 5 ++++- src/gui/src/AppConfig.h | 3 +++ src/gui/src/MainWindow.cpp | 3 +-- src/gui/src/SetupWizard.cpp | 3 +-- src/gui/src/SubscriptionManager.cpp | 27 +++++++++++++++++++++++---- src/gui/src/SubscriptionManager.h | 6 +++++- src/gui/src/SubscriptionState.h | 28 ---------------------------- 8 files changed, 38 insertions(+), 40 deletions(-) delete mode 100644 src/gui/src/SubscriptionState.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 5ada72ff..6f5232af 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -109,8 +109,7 @@ HEADERS += src/MainWindow.h \ src/Plugin.h \ src/WebClient.h \ ../lib/common/PluginVersion.h \ - src/SubscriptionManager.h \ - src/SubscriptionState.h + src/SubscriptionManager.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 6bbf7323..76e2234b 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -58,7 +58,8 @@ AppConfig::AppConfig(QSettings* settings) : m_ElevateMode(false), m_AutoConfigPrompted(false), m_CryptoEnabled(false), - m_AutoHide(false) + m_AutoHide(false), + m_LastExpiringWarningTime(0) { Q_ASSERT(m_pSettings); @@ -133,6 +134,7 @@ void AppConfig::loadSettings() m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool(); m_AutoHide = settings().value("autoHide", false).toBool(); m_Serialkey = settings().value("serialKey", "").toString(); + m_LastExpiringWarningTime = settings().value("lastExpiringWarningTime", 0).toInt(); } void AppConfig::saveSettings() @@ -155,6 +157,7 @@ void AppConfig::saveSettings() settings().setValue("cryptoEnabled", m_CryptoEnabled); settings().setValue("autoHide", m_AutoHide); settings().setValue("serialKey", m_Serialkey); + settings().setValue("lastExpiringWarningTime", m_LastExpiringWarningTime); } void AppConfig::setAutoConfig(bool autoConfig) diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 80de53f6..6a7c1905 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -80,6 +80,8 @@ class AppConfig QString userToken() { return m_UserToken; } void setSerialKey(QString serial) { m_Serialkey = serial; } QString serialKey() { return m_Serialkey; } + int lastExpiringWarningTime() const { return m_LastExpiringWarningTime; } + void setLastExpiringWarningTime(int t) { m_LastExpiringWarningTime = t; } QString synergysName() const { return m_SynergysName; } QString synergycName() const { return m_SynergycName; } @@ -132,6 +134,7 @@ class AppConfig bool m_CryptoEnabled; bool m_AutoHide; QString m_Serialkey; + int m_LastExpiringWarningTime; static const char m_SynergysName[]; static const char m_SynergycName[]; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 2576c0e0..2f3ec96f 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -32,7 +32,6 @@ #include "DataDownloader.h" #include "CommandProcess.h" #include "SubscriptionManager.h" -#include "SubscriptionState.h" #include "EditionType.h" #include "QUtility.h" #include "ProcessorArch.h" @@ -699,7 +698,7 @@ QString MainWindow::appPath(const QString& name) bool MainWindow::serverArgs(QStringList& args, QString& app) { int edition; - SubscriptionManager subscriptionManager(this, edition); + SubscriptionManager subscriptionManager(this, appConfig(), edition); if (subscriptionManager.checkSubscriptionExist()) { if (!subscriptionManager.checkSubscription()) { diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index e97030d8..13078220 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -20,7 +20,6 @@ #include "WebClient.h" #include "SubscriptionManager.h" #include "EditionType.h" -#include "SubscriptionState.h" #include "QSynergyApplication.h" #include "QUtility.h" @@ -127,7 +126,7 @@ bool SetupWizard::validateCurrentPage() } else { // create subscription file in profile directory - SubscriptionManager subscriptionManager(this, m_Edition); + SubscriptionManager subscriptionManager(this, m_MainWindow.appConfig(), m_Edition); if (!subscriptionManager.activateSerial(m_pLineEditSerialKey->text())) { return false; } diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index b9b0f5ff..6820472e 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -17,15 +17,19 @@ #include "SubscriptionManager.h" + #include "CoreInterface.h" #include "EditionType.h" -#include "SubscriptionState.h" +#include "AppConfig.h" #include #include +#include +#include -SubscriptionManager::SubscriptionManager(QWidget* parent, int& edition) : +SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition) : m_pParent(parent), + m_AppConfig(appConfig), m_Edition(edition) { @@ -117,12 +121,11 @@ void SubscriptionManager::getEditionType(QString& output) void SubscriptionManager::checkExpiring(QString& output) { - if (output.contains("trial will end in")) { + if (output.contains("trial will end in") && shouldWarnExpiring()) { QRegExp dayLeftRegex(".*trial will end in ([0-9]+) day.*"); if (dayLeftRegex.exactMatch(output)) { QString dayLeft = dayLeftRegex.cap(1); - // TODO: warn user once a day QMessageBox::warning(m_pParent, tr("Subscription warning"), tr("Your trial will end in %1 %2. Click here to purchase") .arg(dayLeft) @@ -130,3 +133,19 @@ void SubscriptionManager::checkExpiring(QString& output) } } } + +bool SubscriptionManager::shouldWarnExpiring() +{ + // warn users about expiring subscription once a day + int lastExpiringWarningTime = m_AppConfig.lastExpiringWarningTime(); + QDateTime currentDateTime = QDateTime::currentDateTime(); + int currentTime = currentDateTime.toTime_t(); + const int secondPerDay = 60 * 60 * 24; + bool result = false; + if ((currentTime - lastExpiringWarningTime) > secondPerDay) { + result = true; + m_AppConfig.setLastExpiringWarningTime(currentTime); + } + + return result; +} diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index bc272ef4..54e7da34 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -19,10 +19,12 @@ #include +class AppConfig; + class SubscriptionManager : public QWidget { public: - SubscriptionManager(QWidget* parent, int& edition); + SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition); bool activateSerial(const QString& serial); bool checkSubscription(); @@ -34,9 +36,11 @@ private: void checkOutput(QString& output); void getEditionType(QString& output); void checkExpiring(QString& output); + bool shouldWarnExpiring(); private: QString m_ErrorMessage; QWidget* m_pParent; + AppConfig& m_AppConfig; int& m_Edition; }; diff --git a/src/gui/src/SubscriptionState.h b/src/gui/src/SubscriptionState.h deleted file mode 100644 index e52a6df5..00000000 --- a/src/gui/src/SubscriptionState.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2015 Synergy Seamless Inc. - * - * 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 - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SUBSCRIPTIONSTATE_H -#define SUBSCRIPTIONSTATE_H - -enum qSubscriptionState { - kValid, - kInvalid, - kExpiredSoon, - kExpired -}; - -#endif // SUBSCRIPTIONSTATE_H From 5f73d339aae6c3663b2ca1a922ba880364994fc2 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Tue, 17 Nov 2015 15:20:22 -0800 Subject: [PATCH 32/40] Refactor purchase url #4716 --- src/gui/src/SubscriptionManager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 6820472e..9794c3e1 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -27,6 +27,8 @@ #include #include +static const char purchaseURL[] = "https://synergy-project.org/account/"; + SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, int& edition) : m_pParent(parent), m_AppConfig(appConfig), @@ -90,7 +92,7 @@ void SubscriptionManager::checkError(QString& error) { if (error.contains("trial has expired")) { QMessageBox::warning(m_pParent, tr("Subscription warning"), - tr("Your trial has expired. Click here to purchase")); + tr("Your trial has expired. Click here to purchase").arg(purchaseURL)); } else { QMessageBox::warning(m_pParent, tr("Subscription error"), @@ -127,9 +129,10 @@ void SubscriptionManager::checkExpiring(QString& output) QString dayLeft = dayLeftRegex.cap(1); QMessageBox::warning(m_pParent, tr("Subscription warning"), - tr("Your trial will end in %1 %2. Click here to purchase") + tr("Your trial will end in %1 %2. Click here to purchase") .arg(dayLeft) - .arg(dayLeft == "1" ? "day" : "days")); + .arg(dayLeft == "1" ? "day" : "days") + .arg(purchaseURL)); } } } From 4698394e21f1b0113be13224314a03cd8a8dd8f0 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 11:51:45 -0800 Subject: [PATCH 33/40] URL encode identity and MAC address --- src/lib/synergy/ToolApp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 0549c396..fb2ca7cc 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -214,8 +214,8 @@ ToolApp::notifyActivation() std::stringstream ss; ss << JSON_URL << "notify/"; ss << "?action=" << action; - ss << "&identity=" << identity; - ss << "&mac=" << macHash; + ss << "&identity=" << ARCH->internet().urlEncode(identity); + ss << "&mac=" << ARCH->internet().urlEncode(macHash); ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); From 20d4d4764811b07a7eaeb20614a2c4d8ce77b308 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 15:03:06 -0800 Subject: [PATCH 34/40] Save edition type to settings after wizard finish #4715 --- src/gui/src/AppConfig.h | 3 ++- src/gui/src/SetupWizard.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 6a7c1905..398082f2 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -97,6 +97,8 @@ class AppConfig void setAutoHide(bool b) { m_AutoHide = b; } bool getAutoHide() { return m_AutoHide; } + void saveSettings(); + protected: QSettings& settings() { return *m_pSettings; } void setScreenName(const QString& s) { m_ScreenName = s; } @@ -111,7 +113,6 @@ class AppConfig void setElevateMode(bool b) { m_ElevateMode = b; } void loadSettings(); - void saveSettings(); private: QSettings* m_pSettings; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index 13078220..e2f4abcc 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -223,9 +223,11 @@ void SetupWizard::accept() coreInterface.notifyActivation("skip:unknown"); } + appConfig.setEdition(m_Edition); m_MainWindow.setEdition(m_Edition); m_MainWindow.updateLocalFingerprint(); + appConfig.saveSettings(); settings.sync(); QWizard::accept(); From b1c5a83bfb62b5495615e3b79d714a434687a422 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 15:05:05 -0800 Subject: [PATCH 35/40] Uthe edition value in app config as default #4715 --- src/gui/src/MainWindow.cpp | 18 ++---------------- src/gui/src/MainWindow.h | 1 - 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 2f3ec96f..2417c7a4 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -134,7 +134,7 @@ MainWindow::MainWindow(QSettings& settings, AppConfig& appConfig) : m_pComboServerList->hide(); - updateEdition(); + setEdition(m_AppConfig.edition()); m_pLabelPadlock->hide(); @@ -939,7 +939,7 @@ void MainWindow::changeEvent(QEvent* event) retranslateUi(this); retranslateMenuBar(); - updateEdition(); + setEdition(m_AppConfig.edition()); break; } @@ -1285,20 +1285,6 @@ void MainWindow::promptAutoConfig() m_AppConfig.setAutoConfigPrompted(true); } -void MainWindow::updateEdition() -{ - QString mac = getFirstMacAddress(); - QString hashSrc = m_AppConfig.activateEmail() + mac; - QString hashResult = hash(hashSrc); - - if (hashResult == m_AppConfig.userToken()) { - setEdition(m_AppConfig.edition()); - } - else { - setEdition(Unknown); - } -} - void MainWindow::on_m_pComboServerList_currentIndexChanged(QString ) { if (m_pComboServerList->count() != 0) { diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index c159747a..9c7aeebc 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -172,7 +172,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase bool isBonjourRunning(); void downloadBonjour(); void promptAutoConfig(); - void updateEdition(); QString getProfileRootForArg(); void checkConnected(const QString& line); void checkFingerprint(const QString& line); From 0e58bfc5fe2454c2540b15b7598725eddff1ac40 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 15:09:09 -0800 Subject: [PATCH 36/40] Remove user token #4715 --- src/gui/src/AppConfig.cpp | 2 -- src/gui/src/AppConfig.h | 3 --- src/gui/src/SetupWizard.cpp | 5 ----- 3 files changed, 10 deletions(-) diff --git a/src/gui/src/AppConfig.cpp b/src/gui/src/AppConfig.cpp index 76e2234b..69142d1d 100644 --- a/src/gui/src/AppConfig.cpp +++ b/src/gui/src/AppConfig.cpp @@ -130,7 +130,6 @@ void AppConfig::loadSettings() m_AutoConfigPrompted = settings().value("autoConfigPrompted", false).toBool(); m_Edition = settings().value("edition", Unknown).toInt(); m_ActivateEmail = settings().value("activateEmail", "").toString(); - m_UserToken = settings().value("userToken", "").toString(); m_CryptoEnabled = settings().value("cryptoEnabled", false).toBool(); m_AutoHide = settings().value("autoHide", false).toBool(); m_Serialkey = settings().value("serialKey", "").toString(); @@ -153,7 +152,6 @@ void AppConfig::saveSettings() settings().setValue("autoConfigPrompted", m_AutoConfigPrompted); settings().setValue("edition", m_Edition); settings().setValue("activateEmail", m_ActivateEmail); - settings().setValue("userToken", m_UserToken); settings().setValue("cryptoEnabled", m_CryptoEnabled); settings().setValue("autoHide", m_AutoHide); settings().setValue("serialKey", m_Serialkey); diff --git a/src/gui/src/AppConfig.h b/src/gui/src/AppConfig.h index 398082f2..684c0015 100644 --- a/src/gui/src/AppConfig.h +++ b/src/gui/src/AppConfig.h @@ -76,8 +76,6 @@ class AppConfig int edition() { return m_Edition; } void setActivateEmail(QString e) { m_ActivateEmail = e; } QString activateEmail() { return m_ActivateEmail; } - void setUserToken(QString t) { m_UserToken = t; } - QString userToken() { return m_UserToken; } void setSerialKey(QString serial) { m_Serialkey = serial; } QString serialKey() { return m_Serialkey; } int lastExpiringWarningTime() const { return m_LastExpiringWarningTime; } @@ -131,7 +129,6 @@ class AppConfig bool m_AutoConfigPrompted; int m_Edition; QString m_ActivateEmail; - QString m_UserToken; bool m_CryptoEnabled; bool m_AutoHide; QString m_Serialkey; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index e2f4abcc..e239b015 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -199,11 +199,6 @@ void SetupWizard::accept() if (m_pRadioButtonActivate->isChecked()) { appConfig.setActivateEmail(m_pLineEditEmail->text()); - QString mac = getFirstMacAddress(); - QString hashSrc = m_pLineEditEmail->text() + mac; - QString hashResult = hash(hashSrc); - appConfig.setUserToken(hashResult); - appConfig.setEdition(m_Edition); CoreInterface coreInterface; coreInterface.notifyActivation("login:" + m_pLineEditEmail->text()); From cab8a992334c390b7d421a4b20ad514ee01b3b81 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 16:03:32 -0800 Subject: [PATCH 37/40] Persist Profile folder #4715 --- src/gui/src/SubscriptionManager.cpp | 15 ++++++++++++++- src/gui/src/SubscriptionManager.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 9794c3e1..6606cdf4 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -23,6 +23,7 @@ #include "AppConfig.h" #include +#include #include #include #include @@ -34,12 +35,12 @@ SubscriptionManager::SubscriptionManager(QWidget* parent, AppConfig& appConfig, m_AppConfig(appConfig), m_Edition(edition) { - } bool SubscriptionManager::activateSerial(const QString& serial) { m_Edition = Unknown; + persistDirectory(); CoreInterface coreInterface; QString output; @@ -62,6 +63,7 @@ bool SubscriptionManager::activateSerial(const QString& serial) bool SubscriptionManager::checkSubscription() { m_Edition = Unknown; + persistDirectory(); CoreInterface coreInterface; QString output; try @@ -152,3 +154,14 @@ bool SubscriptionManager::shouldWarnExpiring() return result; } + +void SubscriptionManager::persistDirectory() +{ + CoreInterface coreInterface; + QString profileDir = coreInterface.getProfileDir(); + + QDir dir(profileDir); + if (!dir.exists()) { + dir.mkpath("."); + } +} diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index 54e7da34..646ff81a 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -37,6 +37,7 @@ private: void getEditionType(QString& output); void checkExpiring(QString& output); bool shouldWarnExpiring(); + void persistDirectory(); private: QString m_ErrorMessage; From 4b2fc8c4c968cd3dbf615e89175013d591101978 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 18 Nov 2015 16:05:08 -0800 Subject: [PATCH 38/40] Refactor function name #4715 --- src/gui/src/MainWindow.cpp | 2 +- src/gui/src/SubscriptionManager.cpp | 2 +- src/gui/src/SubscriptionManager.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 2417c7a4..e24c8ac1 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -699,7 +699,7 @@ bool MainWindow::serverArgs(QStringList& args, QString& app) { int edition; SubscriptionManager subscriptionManager(this, appConfig(), edition); - if (subscriptionManager.checkSubscriptionExist()) + if (subscriptionManager.fileExists()) { if (!subscriptionManager.checkSubscription()) { return false; diff --git a/src/gui/src/SubscriptionManager.cpp b/src/gui/src/SubscriptionManager.cpp index 6606cdf4..f3f55611 100644 --- a/src/gui/src/SubscriptionManager.cpp +++ b/src/gui/src/SubscriptionManager.cpp @@ -82,7 +82,7 @@ bool SubscriptionManager::checkSubscription() return true; } -bool SubscriptionManager::checkSubscriptionExist() +bool SubscriptionManager::fileExists() { CoreInterface coreInterface; QString subscriptionFilename = coreInterface.getSubscriptionFilename(); diff --git a/src/gui/src/SubscriptionManager.h b/src/gui/src/SubscriptionManager.h index 646ff81a..59497352 100644 --- a/src/gui/src/SubscriptionManager.h +++ b/src/gui/src/SubscriptionManager.h @@ -28,7 +28,7 @@ public: bool activateSerial(const QString& serial); bool checkSubscription(); - bool checkSubscriptionExist(); + bool fileExists(); QString getLastError(){ return m_ErrorMessage; } private: From e1e38bd3a20a2a3b947bbcb73a331e5ab68ae4e8 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 19 Nov 2015 10:01:50 -0800 Subject: [PATCH 39/40] Compress network error during notification #4932 --- src/lib/synergy/ToolApp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index fb2ca7cc..048e51dd 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -223,13 +223,13 @@ ToolApp::notifyActivation() std::cout << ARCH->internet().get(ss.str()) << std::endl; } catch (std::exception& e) { - LOG((CLOG_CRIT "An error occurred during notification: %s\n", e.what())); + LOG((CLOG_NOTE "An error occurred during notification: %s\n", e.what())); } catch (...) { - LOG((CLOG_CRIT "An unknown error occurred during notification.\n")); + LOG((CLOG_NOTE "An unknown error occurred during notification.\n")); } } else { - LOG((CLOG_DEBUG "notification failed")); + LOG((CLOG_NOTE "notification failed")); } } From 4be852c2f2752035325e18e207ca1651b029c867 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 19 Nov 2015 10:48:11 -0800 Subject: [PATCH 40/40] Move notify into thread #4932 --- src/gui/gui.pro | 6 +++-- src/gui/src/ActivationNotifier.cpp | 36 ++++++++++++++++++++++++++ src/gui/src/ActivationNotifier.h | 41 ++++++++++++++++++++++++++++++ src/gui/src/SetupWizard.cpp | 25 +++++++++++++----- src/gui/src/SetupWizard.h | 1 + 5 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 src/gui/src/ActivationNotifier.cpp create mode 100644 src/gui/src/ActivationNotifier.h diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 6f5232af..73368b84 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -62,7 +62,8 @@ SOURCES += src/main.cpp \ src/Plugin.cpp \ src/WebClient.cpp \ ../lib/common/PluginVersion.cpp \ - src/SubscriptionManager.cpp + src/SubscriptionManager.cpp \ + src/ActivationNotifier.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -109,7 +110,8 @@ HEADERS += src/MainWindow.h \ src/Plugin.h \ src/WebClient.h \ ../lib/common/PluginVersion.h \ - src/SubscriptionManager.h + src/SubscriptionManager.h \ + src/ActivationNotifier.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/src/ActivationNotifier.cpp b/src/gui/src/ActivationNotifier.cpp new file mode 100644 index 00000000..7efe4e82 --- /dev/null +++ b/src/gui/src/ActivationNotifier.cpp @@ -0,0 +1,36 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Seamless Inc. + * + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ActivationNotifier.h" + +#include "CoreInterface.h" + +ActivationNotifier::ActivationNotifier(QObject *parent) : + QObject(parent) +{ +} + +void ActivationNotifier::setIdentity(QString identity) +{ + m_Identity = identity; +} + +void ActivationNotifier::notify() +{ + CoreInterface coreInterface; + coreInterface.notifyActivation(m_Identity); +} diff --git a/src/gui/src/ActivationNotifier.h b/src/gui/src/ActivationNotifier.h new file mode 100644 index 00000000..d245cd27 --- /dev/null +++ b/src/gui/src/ActivationNotifier.h @@ -0,0 +1,41 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Seamless Inc. + * + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ACTIVATIONNOTIFIER_H +#define ACTIVATIONNOTIFIER_H + +#include + +class ActivationNotifier : public QObject +{ +Q_OBJECT +public: + explicit ActivationNotifier(QObject *parent = 0); + + void setIdentity(QString identity); + +public slots: + void notify(); + +signals: + void finished(); + +private: + QString m_Identity; +}; + +#endif // ACTIVATIONNOTIFIER_H diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index e239b015..a3a081fc 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -18,6 +18,7 @@ #include "SetupWizard.h" #include "MainWindow.h" #include "WebClient.h" +#include "ActivationNotifier.h" #include "SubscriptionManager.h" #include "EditionType.h" #include "QSynergyApplication.h" @@ -200,22 +201,19 @@ void SetupWizard::accept() if (m_pRadioButtonActivate->isChecked()) { appConfig.setActivateEmail(m_pLineEditEmail->text()); - CoreInterface coreInterface; - coreInterface.notifyActivation("login:" + m_pLineEditEmail->text()); + notifyActivation("login:" + m_pLineEditEmail->text()); } if (m_pRadioButtonSubscription->isChecked()) { appConfig.setSerialKey(m_pLineEditSerialKey->text()); - CoreInterface coreInterface; - coreInterface.notifyActivation("serial:" + m_pLineEditSerialKey->text()); + notifyActivation("serial:" + m_pLineEditSerialKey->text()); } if (m_pRadioButtonSkip->isChecked()) { - CoreInterface coreInterface; - coreInterface.notifyActivation("skip:unknown"); + notifyActivation("skip:unknown"); } appConfig.setEdition(m_Edition); @@ -251,6 +249,21 @@ void SetupWizard::reject() QWizard::reject(); } +void SetupWizard::notifyActivation(QString identity) +{ + ActivationNotifier* notifier = new ActivationNotifier(); + notifier->setIdentity(identity); + QThread* thread = new QThread; + connect(notifier, SIGNAL(finished()), thread, SLOT(quit())); + connect(notifier, SIGNAL(finished()), notifier, SLOT(deleteLater())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + notifier->moveToThread(thread); + thread->start(); + + QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection); +} + void SetupWizard::on_m_pComboLanguage_currentIndexChanged(int index) { QString ietfCode = m_pComboLanguage->itemData(index).toString(); diff --git a/src/gui/src/SetupWizard.h b/src/gui/src/SetupWizard.h index 253ac97f..328de0ee 100644 --- a/src/gui/src/SetupWizard.h +++ b/src/gui/src/SetupWizard.h @@ -43,6 +43,7 @@ protected: void changeEvent(QEvent* event); void accept(); void reject(); + void notifyActivation(QString identity); private: MainWindow& m_MainWindow;