set device type
This commit is contained in:
@@ -141,6 +141,25 @@ void AppController::setQuickSave(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
QString AppController::deviceType() const
|
||||
{
|
||||
return LocalSend::deviceTypeToString(m_settings->deviceType());
|
||||
}
|
||||
|
||||
void AppController::setDeviceType(const QString& type)
|
||||
{
|
||||
LocalSend::DeviceType newType = LocalSend::deviceTypeFromString(type);
|
||||
if (m_settings->deviceType() != newType) {
|
||||
m_settings->setDeviceType(newType);
|
||||
emit deviceTypeChanged();
|
||||
|
||||
LocalSend::InfoDto info = buildInfoDto();
|
||||
m_server->setLocalInfo(info, m_security->fingerprint());
|
||||
m_discovery->setLocalInfo(info, m_security->fingerprint(), m_settings->port(),
|
||||
m_settings->https() ? LocalSend::ProtocolType::Https : LocalSend::ProtocolType::Http);
|
||||
}
|
||||
}
|
||||
|
||||
QVariantList AppController::devices() const
|
||||
{
|
||||
QVariantList result;
|
||||
|
||||
@@ -33,6 +33,7 @@ class AppController : public QObject
|
||||
Q_PROPERTY(int currentReceiveFileIndex READ currentReceiveFileIndex NOTIFY receiveProgressChanged)
|
||||
Q_PROPERTY(int totalReceiveFiles READ totalReceiveFiles NOTIFY receivingChanged)
|
||||
Q_PROPERTY(QString currentReceiveSenderAlias READ currentReceiveSenderAlias NOTIFY receivingChanged)
|
||||
Q_PROPERTY(QString deviceType READ deviceType WRITE setDeviceType NOTIFY deviceTypeChanged)
|
||||
|
||||
public:
|
||||
explicit AppController(QObject* parent = nullptr);
|
||||
@@ -72,6 +73,9 @@ public:
|
||||
int totalReceiveFiles() const;
|
||||
QString currentReceiveSenderAlias() const;
|
||||
|
||||
QString deviceType() const;
|
||||
void setDeviceType(const QString& type);
|
||||
|
||||
Q_INVOKABLE void startDiscovery();
|
||||
Q_INVOKABLE void stopDiscovery();
|
||||
Q_INVOKABLE void refreshDevices();
|
||||
@@ -110,6 +114,7 @@ signals:
|
||||
void receivePinChanged();
|
||||
void receivingChanged();
|
||||
void receiveProgressChanged();
|
||||
void deviceTypeChanged();
|
||||
|
||||
private slots:
|
||||
void onDeviceDiscovered(const LocalSend::Device& device);
|
||||
|
||||
@@ -15,6 +15,17 @@ ApplicationWindow {
|
||||
property string currentSenderAlias: ""
|
||||
property string currentSenderIp: ""
|
||||
|
||||
function getDeviceTypeIcon(deviceType) {
|
||||
switch (deviceType) {
|
||||
case "mobile": return "\u{1F4F1}"
|
||||
case "desktop": return "\u{1F4BB}"
|
||||
case "web": return "\u{1F310}"
|
||||
case "headless": return "\u{1F5A5}"
|
||||
case "server": return "\u{1F4E1}"
|
||||
default: return "\u{1F4BB}"
|
||||
}
|
||||
}
|
||||
|
||||
DropArea {
|
||||
id: dropArea
|
||||
anchors.fill: parent
|
||||
@@ -587,6 +598,13 @@ ApplicationWindow {
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 12
|
||||
|
||||
Label {
|
||||
text: getDeviceTypeIcon(modelData.deviceType)
|
||||
font.pixelSize: 32
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
Layout.fillWidth: true
|
||||
@@ -728,6 +746,33 @@ ApplicationWindow {
|
||||
onClicked: appController.receivePin = ""
|
||||
}
|
||||
}
|
||||
|
||||
Label { text: qsTr("Device Type:") }
|
||||
ComboBox {
|
||||
id: deviceTypeCombo
|
||||
Layout.fillWidth: true
|
||||
model: [
|
||||
{ text: qsTr("Mobile"), value: "mobile" },
|
||||
{ text: qsTr("Desktop"), value: "desktop" },
|
||||
{ text: qsTr("Web"), value: "web" },
|
||||
{ text: qsTr("Headless"), value: "headless" },
|
||||
{ text: qsTr("Server"), value: "server" }
|
||||
]
|
||||
textRole: "text"
|
||||
Component.onCompleted: {
|
||||
for (var i = 0; i < model.length; i++) {
|
||||
if (model[i].value === appController.deviceType) {
|
||||
currentIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
onCurrentIndexChanged: {
|
||||
if (currentIndex >= 0 && currentIndex < model.length) {
|
||||
appController.deviceType = model[currentIndex].value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FolderDialog {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "LocalSendCore/Settings.h"
|
||||
#include "LocalSendCore/Constants.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QSysInfo>
|
||||
|
||||
namespace LocalSend {
|
||||
|
||||
@@ -11,6 +12,18 @@ Settings::Settings(QObject* parent)
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
DeviceType detectDeviceType() {
|
||||
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
|
||||
return DeviceType::Mobile;
|
||||
#elif defined(Q_OS_LINUX) || defined(Q_OS_MACOS) || defined(Q_OS_WINDOWS)
|
||||
return DeviceType::Desktop;
|
||||
#else
|
||||
return DeviceType::Headless;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QString Settings::alias() const
|
||||
{
|
||||
return m_settings.value(QStringLiteral("alias"),
|
||||
@@ -108,8 +121,11 @@ void Settings::setDeviceModel(const QString& model)
|
||||
|
||||
DeviceType Settings::deviceType() const
|
||||
{
|
||||
return deviceTypeFromString(m_settings.value(QStringLiteral("deviceType"),
|
||||
QStringLiteral("desktop")).toString());
|
||||
QVariant stored = m_settings.value(QStringLiteral("deviceType"));
|
||||
if (stored.isValid()) {
|
||||
return deviceTypeFromString(stored.toString());
|
||||
}
|
||||
return detectDeviceType();
|
||||
}
|
||||
|
||||
void Settings::setDeviceType(DeviceType type)
|
||||
|
||||
Reference in New Issue
Block a user