Refactored "syntool" usage into CoreInterface #4168
This commit is contained in:
parent
595e403c87
commit
40d304dc24
|
@ -55,7 +55,7 @@ SOURCES += src/main.cpp \
|
||||||
src/WebClient.cpp \
|
src/WebClient.cpp \
|
||||||
src/PluginWizardPage.cpp \
|
src/PluginWizardPage.cpp \
|
||||||
src/PluginManager.cpp \
|
src/PluginManager.cpp \
|
||||||
src/DirectoryManager.cpp
|
src/CoreInterface.cpp
|
||||||
HEADERS += src/MainWindow.h \
|
HEADERS += src/MainWindow.h \
|
||||||
src/AboutDialog.h \
|
src/AboutDialog.h \
|
||||||
src/ServerConfig.h \
|
src/ServerConfig.h \
|
||||||
|
@ -97,7 +97,7 @@ HEADERS += src/MainWindow.h \
|
||||||
src/PluginWizardPage.h \
|
src/PluginWizardPage.h \
|
||||||
src/ProcessorArch.h \
|
src/ProcessorArch.h \
|
||||||
src/PluginManager.h \
|
src/PluginManager.h \
|
||||||
src/DirectoryManager.h
|
src/CoreInterface.h
|
||||||
RESOURCES += res/Synergy.qrc
|
RESOURCES += res/Synergy.qrc
|
||||||
RC_FILE = res/win/Synergy.rc
|
RC_FILE = res/win/Synergy.rc
|
||||||
macx {
|
macx {
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2015 Synergy Si Ltd.
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file COPYING 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CoreInterface.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
static const char kCoreBinary[] = "syntool";
|
||||||
|
|
||||||
|
CoreInterface::CoreInterface()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CoreInterface::getPluginDir()
|
||||||
|
{
|
||||||
|
QStringList args("--get-plugin-dir");
|
||||||
|
return run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CoreInterface::getProfileDir()
|
||||||
|
{
|
||||||
|
QStringList args("--get-profile-dir");
|
||||||
|
return run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CoreInterface::getArch()
|
||||||
|
{
|
||||||
|
QStringList args("--get-arch");
|
||||||
|
return run(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CoreInterface::run(const QStringList& args, const QString& input)
|
||||||
|
{
|
||||||
|
QString program(
|
||||||
|
QCoreApplication::applicationDirPath()
|
||||||
|
+ "/" + kCoreBinary);
|
||||||
|
|
||||||
|
QProcess process;
|
||||||
|
process.setReadChannel(QProcess::StandardOutput);
|
||||||
|
process.start(program, args);
|
||||||
|
bool success = process.waitForStarted();
|
||||||
|
|
||||||
|
QString output, error;
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
if (!input.isEmpty()) {
|
||||||
|
process.write(input.toStdString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.waitForFinished()) {
|
||||||
|
output = process.readAllStandardOutput();
|
||||||
|
error = process.readAllStandardError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.trimmed();
|
||||||
|
error = error.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;
|
||||||
|
}
|
|
@ -1,36 +1,31 @@
|
||||||
/*
|
/*
|
||||||
* synergy -- mouse and keyboard sharing utility
|
* synergy -- mouse and keyboard sharing utility
|
||||||
* Copyright (C) 2015 Synergy Si Ltd.
|
* Copyright (C) 2015 Synergy Si Ltd.
|
||||||
*
|
*
|
||||||
* This package is free software; you can redistribute it and/or
|
* This package is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
* found in the file COPYING that should have accompanied this file.
|
* found in the file COPYING that should have accompanied this file.
|
||||||
*
|
*
|
||||||
* This package is distributed in the hope that it will be useful,
|
* This package is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DIRECTORYMANAGER_H
|
#pragma once
|
||||||
#define DIRECTORYMANAGER_H
|
|
||||||
|
#include <QString>
|
||||||
#include <QString>
|
|
||||||
#include <QStringList>
|
class CoreInterface
|
||||||
|
{
|
||||||
class DirectoryManager
|
public:
|
||||||
{
|
CoreInterface();
|
||||||
public:
|
|
||||||
DirectoryManager();
|
QString getPluginDir();
|
||||||
|
QString getProfileDir();
|
||||||
static QString getPluginDir();
|
QString getArch();
|
||||||
static QString getProfileDir();
|
QString run(const QStringList& args, const QString& input = "");
|
||||||
|
};
|
||||||
private:
|
|
||||||
static QString getDirViaSyntool(QStringList& args);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DIRECTORYMANAGER_H
|
|
|
@ -1,81 +0,0 @@
|
||||||
/*
|
|
||||||
* synergy -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2015 Synergy Si Ltd.
|
|
||||||
*
|
|
||||||
* This package is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* found in the file COPYING 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "DirectoryManager.h"
|
|
||||||
|
|
||||||
#include <QCoreApplication>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
static const char kGetPluginDirArg[] = "--get-plugin-dir";
|
|
||||||
static const char kGetProfileDirArg[] = "--get-profile-dir";
|
|
||||||
|
|
||||||
DirectoryManager::DirectoryManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DirectoryManager::getPluginDir()
|
|
||||||
{
|
|
||||||
QStringList args(kGetPluginDirArg);
|
|
||||||
return getDirViaSyntool(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DirectoryManager::getProfileDir()
|
|
||||||
{
|
|
||||||
QStringList args(kGetProfileDirArg);
|
|
||||||
return getDirViaSyntool(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DirectoryManager::getDirViaSyntool(QStringList& args)
|
|
||||||
{
|
|
||||||
QString program(QCoreApplication::applicationDirPath() + "/syntool");
|
|
||||||
|
|
||||||
QProcess process;
|
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(program, args);
|
|
||||||
bool success = process.waitForStarted();
|
|
||||||
|
|
||||||
QString out, error;
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
if (process.waitForFinished()) {
|
|
||||||
out = process.readAllStandardOutput();
|
|
||||||
error = process.readAllStandardError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out = out.trimmed();
|
|
||||||
error = error.trimmed();
|
|
||||||
|
|
||||||
if (out.isEmpty() ||
|
|
||||||
!error.isEmpty() ||
|
|
||||||
!success ||
|
|
||||||
process.exitCode() != 0)
|
|
||||||
{
|
|
||||||
QMessageBox::critical(
|
|
||||||
NULL, QObject::tr("Synergy"),
|
|
||||||
QObject::tr("An error occured while calling syntool "
|
|
||||||
"with the first arg %1. Code: %2\nError: %3")
|
|
||||||
.arg(args.at(0))
|
|
||||||
.arg(process.exitCode())
|
|
||||||
.arg(error.isEmpty() ? "Unknown" : error));
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
|
@ -63,7 +63,7 @@ void PluginWizardPage::changeEvent(QEvent *e)
|
||||||
|
|
||||||
void PluginWizardPage::showError(QString error)
|
void PluginWizardPage::showError(QString error)
|
||||||
{
|
{
|
||||||
updateStatus(error);
|
updateStatus(tr("Error: %1").arg(error));
|
||||||
showFinished();
|
showFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "SettingsDialog.h"
|
#include "SettingsDialog.h"
|
||||||
|
|
||||||
#include "DirectoryManager.h"
|
#include "CoreInterface.h"
|
||||||
#include "SynergyLocale.h"
|
#include "SynergyLocale.h"
|
||||||
#include "QSynergyApplication.h"
|
#include "QSynergyApplication.h"
|
||||||
#include "QUtility.h"
|
#include "QUtility.h"
|
||||||
|
@ -57,7 +57,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
|
||||||
m_pCheckBoxElevateMode->hide();
|
m_pCheckBoxElevateMode->hide();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QString pluginDir = DirectoryManager::getPluginDir();
|
QString pluginDir = m_CoreInterface.getPluginDir();
|
||||||
QDir dir(pluginDir);
|
QDir dir(pluginDir);
|
||||||
int fileNum = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count();
|
int fileNum = dir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count();
|
||||||
if (fileNum == 0) {
|
if (fileNum == 0) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "ui_SettingsDialogBase.h"
|
#include "ui_SettingsDialogBase.h"
|
||||||
#include "SynergyLocale.h"
|
#include "SynergyLocale.h"
|
||||||
|
#include "CoreInterface.h"
|
||||||
|
|
||||||
class AppConfig;
|
class AppConfig;
|
||||||
|
|
||||||
|
@ -44,6 +45,7 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
|
||||||
private:
|
private:
|
||||||
AppConfig& m_AppConfig;
|
AppConfig& m_AppConfig;
|
||||||
SynergyLocale m_Locale;
|
SynergyLocale m_Locale;
|
||||||
|
CoreInterface m_CoreInterface;
|
||||||
bool m_SuppressElevateWarning;
|
bool m_SuppressElevateWarning;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -140,44 +140,11 @@ void WebClient::queryPluginList()
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WebClient::request(
|
QString WebClient::request(
|
||||||
const QString& email,
|
const QString& email,
|
||||||
const QString& password,
|
const QString& password,
|
||||||
QStringList& args)
|
QStringList& args)
|
||||||
{
|
{
|
||||||
QString program(QCoreApplication::applicationDirPath() + "/syntool");
|
// hash password in case it contains interesting chars.
|
||||||
|
QString credentials(email + ":" + hash(password) + "\n");
|
||||||
QProcess process;
|
return m_CoreInterface.run(args, credentials);
|
||||||
process.setReadChannel(QProcess::StandardOutput);
|
|
||||||
process.start(program, args);
|
|
||||||
bool success = process.waitForStarted();
|
|
||||||
|
|
||||||
QString out, error;
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
// hash password in case it contains interesting chars.
|
|
||||||
QString credentials(email + ":" + hash(password) + "\n");
|
|
||||||
process.write(credentials.toStdString().c_str());
|
|
||||||
|
|
||||||
if (process.waitForFinished()) {
|
|
||||||
out = process.readAllStandardOutput();
|
|
||||||
error = process.readAllStandardError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out = out.trimmed();
|
|
||||||
error = error.trimmed();
|
|
||||||
|
|
||||||
if (out.isEmpty() ||
|
|
||||||
!error.isEmpty() ||
|
|
||||||
!success ||
|
|
||||||
process.exitCode() != 0)
|
|
||||||
{
|
|
||||||
throw std::runtime_error(
|
|
||||||
QString("Code: %1\nError: %2")
|
|
||||||
.arg(process.exitCode())
|
|
||||||
.arg(error.isEmpty() ? "Unknown" : error)
|
|
||||||
.toStdString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "CoreInterface.h"
|
||||||
|
|
||||||
class QMessageBox;
|
class QMessageBox;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
|
@ -55,6 +57,7 @@ private:
|
||||||
QString m_Email;
|
QString m_Email;
|
||||||
QString m_Password;
|
QString m_Password;
|
||||||
QStringList m_PluginList;
|
QStringList m_PluginList;
|
||||||
|
CoreInterface m_CoreInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WEBCLIENT_H
|
#endif // WEBCLIENT_H
|
||||||
|
|
Loading…
Reference in New Issue