refactor: adjust interface

This commit is contained in:
Barry 2022-05-24 11:02:32 +08:00
commit f40e97be2c
4 changed files with 9 additions and 22 deletions

View file

@ -63,24 +63,9 @@ bool DeviceManage::connectDevice(qsc::DeviceParams params)
return false; return false;
} }
m_devices[params.serial] = device; m_devices[params.serial] = device;
if (!m_script.isEmpty()) {
device->updateScript(m_script);
}
return true; return true;
} }
void DeviceManage::updateScript(QString script)
{
m_script = script;
QMapIterator<QString, QPointer<IDevice>> i(m_devices);
while (i.hasNext()) {
i.next();
if (i.value()) {
i.value()->updateScript(script);
}
}
}
bool DeviceManage::disconnectDevice(const QString &serial) bool DeviceManage::disconnectDevice(const QString &serial)
{ {
bool ret = false; bool ret = false;

View file

@ -21,8 +21,6 @@ public:
bool disconnectDevice(const QString &serial) override; bool disconnectDevice(const QString &serial) override;
void disconnectAllDevice() override; void disconnectAllDevice() override;
void updateScript(QString script) override;
protected slots: protected slots:
void onDeviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size); void onDeviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);
void onDeviceDisconnected(QString serial); void onDeviceDisconnected(QString serial);

View file

@ -77,13 +77,10 @@ class IDeviceManage : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static IDeviceManage& getInstance(); static IDeviceManage& getInstance();
virtual QPointer<IDevice> getDevice(const QString& serial) = 0;
virtual bool connectDevice(DeviceParams params) = 0; virtual bool connectDevice(DeviceParams params) = 0;
virtual bool disconnectDevice(const QString &serial) = 0; virtual bool disconnectDevice(const QString &serial) = 0;
virtual void disconnectAllDevice() = 0; virtual void disconnectAllDevice() = 0;
virtual QPointer<IDevice> getDevice(const QString& serial) = 0;
virtual void updateScript(QString script) = 0;
signals: signals:
void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size); void deviceConnected(bool success, const QString& serial, const QString& deviceName, const QSize& size);

View file

@ -283,6 +283,7 @@ void Dialog::on_startServerBtn_clicked()
params.recordFileFormat = ui->formatBox->currentText().trimmed(); params.recordFileFormat = ui->formatBox->currentText().trimmed();
params.serverLocalPath = getServerPath(); params.serverLocalPath = getServerPath();
params.serverRemotePath = Config::getInstance().getServerPath(); params.serverRemotePath = Config::getInstance().getServerPath();
params.gameScript = getGameScript(ui->gameBox->currentText());
qsc::IDeviceManage::getInstance().connectDevice(params); qsc::IDeviceManage::getInstance().connectDevice(params);
} }
@ -517,7 +518,13 @@ void Dialog::on_refreshGameScriptBtn_clicked()
void Dialog::on_applyScriptBtn_clicked() void Dialog::on_applyScriptBtn_clicked()
{ {
qsc::IDeviceManage::getInstance().updateScript(getGameScript(ui->gameBox->currentText())); auto curSerial = ui->serialBox->currentText().trimmed();
auto device = qsc::IDeviceManage::getInstance().getDevice(curSerial);
if (!device) {
return;
}
device->updateScript(getGameScript(ui->gameBox->currentText()));
} }
void Dialog::on_recordScreenCheck_clicked(bool checked) void Dialog::on_recordScreenCheck_clicked(bool checked)