diff --git a/src/gui/res/PluginWizardPageBase.ui b/src/gui/res/PluginWizardPageBase.ui
index 1b8f5c23..dfb7a978 100644
--- a/src/gui/res/PluginWizardPageBase.ui
+++ b/src/gui/res/PluginWizardPageBase.ui
@@ -48,7 +48,7 @@
-
- TextLabel
+
@@ -96,9 +96,9 @@
-
-
+
- Finalizing, please wait.
+ Please wait...
diff --git a/src/gui/src/PluginWizardPage.cpp b/src/gui/src/PluginWizardPage.cpp
index 7e29f638..e9037887 100644
--- a/src/gui/src/PluginWizardPage.cpp
+++ b/src/gui/src/PluginWizardPage.cpp
@@ -1,11 +1,15 @@
#include "PluginWizardPage.h"
#include "ui_PluginWizardPageBase.h"
+#include "WebClient.h"
+
#include
+#include
PluginWizardPage::PluginWizardPage(QWidget *parent) :
QWizardPage(parent),
- m_Finished(false)
+ m_Finished(false),
+ m_pWebClient(NULL)
{
setupUi(this);
@@ -16,6 +20,9 @@ PluginWizardPage::PluginWizardPage(QWidget *parent) :
PluginWizardPage::~PluginWizardPage()
{
+ if (m_pWebClient != NULL) {
+ delete m_pWebClient;
+ }
}
void PluginWizardPage::changeEvent(QEvent *e)
@@ -30,6 +37,26 @@ void PluginWizardPage::changeEvent(QEvent *e)
}
}
+void PluginWizardPage::queryPluginDone()
+{
+ QStringList plguinList = m_pWebClient->getPluginList();
+ if (plguinList.isEmpty()) {
+ if (!m_pWebClient->getLastError().isEmpty()) {
+ updateStatus(m_pWebClient->getLastError());
+ m_Finished = true;
+ emit completeChanged();
+ }
+ }
+ else {
+ updateStatus(plguinList.at(0));
+ }
+}
+
+void PluginWizardPage::updateStatus(QString info)
+{
+ m_pLabelStatus->setText(info);
+}
+
bool PluginWizardPage::isComplete() const
{
return m_Finished;
@@ -38,6 +65,34 @@ bool PluginWizardPage::isComplete() const
void PluginWizardPage::initializePage()
{
QWizardPage::initializePage();
- m_Finished = true;
- emit completeChanged();
+ if (m_pWebClient == NULL) {
+ if (m_Email.isEmpty() ||
+ m_Password.isEmpty()) {
+ updateStatus("No plugin available.");
+ //TODO: stop spinning icon
+ m_Finished = true;
+ emit completeChanged();
+
+ return;
+ }
+
+ m_pWebClient = new WebClient();
+ m_pWebClient->setEmail(m_Email);
+ m_pWebClient->setPassword(m_Password);
+
+ QThread* thread = new QThread;
+ connect(m_pWebClient,
+ SIGNAL(queryPluginDone()),
+ this,
+ SLOT(queryPluginDone()));
+
+ connect(m_pWebClient, SIGNAL(queryPluginDone()), thread, SLOT(quit()));
+ connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+
+ m_pWebClient->moveToThread(thread);
+ thread->start();
+
+ updateStatus("Querying plugin list...");
+ QMetaObject::invokeMethod(m_pWebClient, "queryPluginList", Qt::QueuedConnection);
+ }
}
diff --git a/src/gui/src/PluginWizardPage.h b/src/gui/src/PluginWizardPage.h
index 72adb013..ed7163bf 100644
--- a/src/gui/src/PluginWizardPage.h
+++ b/src/gui/src/PluginWizardPage.h
@@ -4,6 +4,8 @@
#include "ui_PluginWizardPageBase.h"
#include
+class WebClient;
+
class PluginWizardPage : public QWizardPage, public Ui::PluginWizardPage {
Q_OBJECT
@@ -13,6 +15,8 @@ public:
~PluginWizardPage();
void setFinished(bool b) { m_Finished = b; }
+ void setEmail(QString e) { m_Email = e; }
+ void setPassword(QString p) { m_Password = p; }
bool isComplete() const;
void initializePage();
@@ -20,7 +24,16 @@ public:
protected:
void changeEvent(QEvent *e);
+protected slots:
+ void queryPluginDone();
+
+private:
+ void updateStatus(QString info);
+
private:
bool m_Finished;
+ WebClient* m_pWebClient;
+ QString m_Email;
+ QString m_Password;
};
#endif // PLUGINWIZARDPAGE_H
diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp
index d3bcdd33..2834a6c5 100644
--- a/src/gui/src/SetupWizard.cpp
+++ b/src/gui/src/SetupWizard.cpp
@@ -21,7 +21,6 @@
#include "EditionType.h"
#include "QSynergyApplication.h"
#include "QUtility.h"
-#include "PluginWizardPage.h"
#include
@@ -94,6 +93,8 @@ bool SetupWizard::validateCurrentPage()
return false;
}
else {
+ m_pPluginPage->setEmail(m_pLineEditEmail->text());
+ m_pPluginPage->setPassword(m_pLineEditPassword->text());
return true;
}
}
diff --git a/src/gui/src/SetupWizard.h b/src/gui/src/SetupWizard.h
index 5f00dd4f..7d974006 100644
--- a/src/gui/src/SetupWizard.h
+++ b/src/gui/src/SetupWizard.h
@@ -19,12 +19,12 @@
#include "ui_SetupWizardBase.h"
#include "SynergyLocale.h"
+#include "PluginWizardPage.h"
#include
#include
class MainWindow;
-class QMessageBox;
class SetupWizard : public QWizard, public Ui::SetupWizardBase
{
@@ -44,7 +44,7 @@ private:
bool m_StartMain;
SynergyLocale m_Locale;
int m_Edition;
- QWizardPage* m_pPluginPage;
+ PluginWizardPage* m_pPluginPage;
private slots:
void on_m_pRadioButtonActivate_toggled(bool checked);
diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp
index 75170532..252ab052 100644
--- a/src/gui/src/WebClient.cpp
+++ b/src/gui/src/WebClient.cpp
@@ -34,14 +34,15 @@ int WebClient::getEdition(
QString responseJson;
int edition = Unknown;
try {
- responseJson = request(email, password);
+ QStringList args("--login-auth");
+ responseJson = request(email, password, args);
}
catch (std::exception& e)
{
message.critical(
w, "Error",
- tr("Sorry, an error occured while trying to sign in. "
- "Please contact the help desk, and provide the "
+ tr("An error occured while trying to sign in. "
+ "Please contact the helpdesk, and provide the "
"following details.\n\n%1").arg(e.what()));
return edition;
}
@@ -50,7 +51,7 @@ int WebClient::getEdition(
if (resultRegex.exactMatch(responseJson)) {
QString boolString = resultRegex.cap(1);
if (boolString == "true") {
- QRegExp editionRegex(".*\"edition\".*:.*\"(.+)\",.*");
+ QRegExp editionRegex(".*\"edition\".*:.*\"([^\"]+)\".*");
if (editionRegex.exactMatch(responseJson)) {
QString e = editionRegex.cap(1);
edition = e.toInt();
@@ -67,7 +68,7 @@ int WebClient::getEdition(
}
}
else {
- QRegExp errorRegex(".*\"error\".*:.*\"(.+)\".*");
+ QRegExp errorRegex(".*\"error\".*:.*\"([^\"]+)\".*");
if (errorRegex.exactMatch(responseJson)) {
// replace "\n" with real new lines.
@@ -88,10 +89,67 @@ int WebClient::getEdition(
return edition;
}
-QString WebClient::request(const QString& email, const QString& password)
+void WebClient::queryPluginList()
+{
+ QString responseJson;
+ try {
+ QStringList args("--get-plugin-list");
+ responseJson = request(m_Email, m_Password, args);
+ }
+ catch (std::exception& e)
+ {
+ m_Error = tr("An error occured while trying to query the "
+ "plugin list. Please contact the help desk, and provide "
+ "the following details.\n\n%1").arg(e.what());
+ emit queryPluginDone();
+ return;
+ }
+
+ QRegExp resultRegex(".*\"result\".*:.*(true|false).*");
+ if (resultRegex.exactMatch(responseJson)) {
+ QString boolString = resultRegex.cap(1);
+ if (boolString == "true") {
+ QRegExp editionRegex(".*\"plugins\".*:.*\"([^\"]+)\".*");
+ if (editionRegex.exactMatch(responseJson)) {
+ QString e = editionRegex.cap(1);
+ m_PluginList = e.split(",");
+ m_Error.clear();
+ emit queryPluginDone();
+ return;
+ }
+ }
+ else if (boolString == "false") {
+ m_Error = tr("Get plugin list failed, invalid user email "
+ "or password.");
+ emit queryPluginDone();
+ return;
+ }
+ }
+ else {
+ QRegExp errorRegex(".*\"error\".*:.*\"([^\"]+)\".*");
+ if (errorRegex.exactMatch(responseJson)) {
+
+ // replace "\n" with real new lines.
+ QString error = errorRegex.cap(1).replace("\\n", "\n");
+ m_Error = tr("Get plugin list failed, an error occurred."
+ "\n\n%1").arg(error);
+ emit queryPluginDone();
+ return;
+ }
+ }
+
+ m_Error = tr("Get plugin list failed, an error occurred.\n\n"
+ "Server response:\n\n%1").arg(responseJson);
+ emit queryPluginDone();
+ return;
+}
+
+QString WebClient::request(
+ const QString& email,
+ const QString& password,
+ QStringList& args)
{
QString program(QCoreApplication::applicationDirPath() + "/syntool");
- QStringList args("--login-auth");
QProcess process;
process.setReadChannel(QProcess::StandardOutput);
diff --git a/src/gui/src/WebClient.h b/src/gui/src/WebClient.h
index 8c319962..d806d9f8 100644
--- a/src/gui/src/WebClient.h
+++ b/src/gui/src/WebClient.h
@@ -19,10 +19,12 @@
#define WEBCLIENT_H
#include
+#include
#include
class QMessageBox;
class QWidget;
+class QStringList;
class WebClient : public QObject
{
@@ -33,9 +35,27 @@ public:
const QString& password,
QMessageBox& message,
QWidget* w);
+ void setEmail(QString& e) { m_Email = e; }
+ void setPassword(QString& p) { m_Password = p; }
+ QStringList& getPluginList() { return m_PluginList; }
+ QString& getLastError() { return m_Error; }
+
+public slots:
+ void queryPluginList();
+
+signals:
+ void queryPluginDone();
private:
- QString request(const QString& email, const QString& password);
+ QString request(const QString& email,
+ const QString& password,
+ QStringList& args);
+
+private:
+ QString m_Email;
+ QString m_Password;
+ QStringList m_PluginList;
+ QString m_Error;
};
#endif // WEBCLIENT_H
diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp
index 3793551e..d20772dd 100644
--- a/src/lib/synergy/ArgParser.cpp
+++ b/src/lib/synergy/ArgParser.cpp
@@ -169,6 +169,10 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
args.m_loginAuthenticate = true;
return true;
}
+ if (isArg(i, argc, argv, NULL, "--get-plugin-list", 0)) {
+ args.m_getPluginList = true;
+ return true;
+ }
else {
return false;
}
diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp
index fda799ce..02d35b71 100644
--- a/src/lib/synergy/ToolApp.cpp
+++ b/src/lib/synergy/ToolApp.cpp
@@ -29,7 +29,7 @@
#include "platform/MSWindowsSession.h"
#endif
-#define PREMIUM_AUTH_URL "https://synergy-project.org/premium/json/auth/"
+#define JSON_URL "https://synergy-project.org/premium/json/"
enum {
kErrorOk,
@@ -70,6 +70,9 @@ ToolApp::run(int argc, char** argv)
else if (m_args.m_loginAuthenticate) {
loginAuth();
}
+ else if (m_args.m_getPluginList) {
+ getPluginList();
+ }
else {
throw XSynergy("Nothing to do");
}
@@ -102,7 +105,25 @@ ToolApp::loginAuth()
String password = credentials.substr(separator + 1, credentials.length());
std::stringstream ss;
- ss << PREMIUM_AUTH_URL;
+ ss << JSON_URL << "auth/";
+ ss << "?email=" << ARCH->internet().urlEncode(email);
+ ss << "&password=" << password;
+
+ std::cout << ARCH->internet().get(ss.str()) << std::endl;
+}
+
+void
+ToolApp::getPluginList()
+{
+ String credentials;
+ std::cin >> credentials;
+
+ size_t separator = credentials.find(':');
+ String email = credentials.substr(0, separator);
+ String password = credentials.substr(separator + 1, credentials.length());
+
+ std::stringstream ss;
+ ss << JSON_URL << "plugins/";
ss << "?email=" << ARCH->internet().urlEncode(email);
ss << "&password=" << password;
diff --git a/src/lib/synergy/ToolApp.h b/src/lib/synergy/ToolApp.h
index 5c66fcb4..b9dd44c0 100644
--- a/src/lib/synergy/ToolApp.h
+++ b/src/lib/synergy/ToolApp.h
@@ -29,6 +29,7 @@ public:
private:
void loginAuth();
+ void getPluginList();
private:
ToolArgs m_args;
diff --git a/src/lib/synergy/ToolArgs.cpp b/src/lib/synergy/ToolArgs.cpp
index 15cf1364..5b46e3b9 100644
--- a/src/lib/synergy/ToolArgs.cpp
+++ b/src/lib/synergy/ToolArgs.cpp
@@ -18,6 +18,8 @@
#include "synergy/ToolArgs.h"
ToolArgs::ToolArgs() :
- m_printActiveDesktopName(false)
+ m_printActiveDesktopName(false),
+ m_loginAuthenticate(false),
+ m_getPluginList(false)
{
}
diff --git a/src/lib/synergy/ToolArgs.h b/src/lib/synergy/ToolArgs.h
index 9d5a0b57..bef5d64e 100644
--- a/src/lib/synergy/ToolArgs.h
+++ b/src/lib/synergy/ToolArgs.h
@@ -26,4 +26,5 @@ public:
public:
bool m_printActiveDesktopName;
bool m_loginAuthenticate;
+ bool m_getPluginList;
};