-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add per-device KeeShare sync mode #13089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
8e561a9
da85170
15246fa
870bd4a
737af87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ | |
| #include "gui/DatabaseIcons.h" | ||
| #include "keeshare/ShareObserver.h" | ||
|
|
||
| #include <QRegularExpression> | ||
| #include <QSysInfo> | ||
|
|
||
| namespace | ||
| { | ||
| static const QString KeeShare_Reference("KeeShare/Reference"); | ||
|
|
@@ -51,6 +54,39 @@ void KeeShare::init(QObject* parent) | |
| m_instance = new KeeShare(parent); | ||
| } | ||
|
|
||
| QString KeeShare::deviceId() | ||
| { | ||
| auto id = config()->get(Config::KeeShare_DeviceId).toString(); | ||
| if (id.isEmpty()) { | ||
| // Generate fallback from machine unique ID, truncated to 7 chars | ||
| auto machineId = QSysInfo::machineUniqueId(); | ||
| if (!machineId.isEmpty()) { | ||
| // machineUniqueId() on Linux returns a hex string directly from /etc/machine-id | ||
| id = QString::fromLatin1(machineId).left(7).toUpper(); | ||
| } else { | ||
| // Last resort: use hostname | ||
| id = QSysInfo::machineHostName(); | ||
| } | ||
| setDeviceId(id); | ||
| // Re-read the sanitized value | ||
| id = config()->get(Config::KeeShare_DeviceId).toString(); | ||
| } | ||
| return id; | ||
| } | ||
|
|
||
| void KeeShare::setDeviceId(const QString& id) | ||
| { | ||
| // All sanitization consolidated here: strip non-alphanumeric, enforce max | ||
| // length, and fall back to DEFAULT if empty | ||
| QString sanitized = id; | ||
| sanitized.remove(QRegularExpression("[^A-Za-z0-9]")); | ||
| sanitized.truncate(32); | ||
| if (sanitized.isEmpty()) { | ||
| sanitized = QStringLiteral("DEFAULT"); | ||
| } | ||
| config()->set(Config::KeeShare_DeviceId, sanitized); | ||
| } | ||
|
Comment on lines
+77
to
+88
|
||
|
|
||
| KeeShareSettings::Own KeeShare::own() | ||
| { | ||
| // Read existing own certificate or generate a new one if none available | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| #include "gui/MessageBox.h" | ||
| #include "keeshare/KeeShare.h" | ||
|
|
||
| #include <QRegularExpressionValidator> | ||
| #include <QStandardItemModel> | ||
| #include <QStandardPaths> | ||
| #include <QTextStream> | ||
|
|
@@ -33,6 +34,9 @@ SettingsWidgetKeeShare::SettingsWidgetKeeShare(QWidget* parent) | |
| { | ||
| m_ui->setupUi(this); | ||
|
|
||
| m_ui->deviceIdEdit->setValidator( | ||
| new QRegularExpressionValidator(QRegularExpression("[A-Za-z0-9]{0,32}"), this)); | ||
|
|
||
| connect(m_ui->ownCertificateSignerEdit, SIGNAL(textChanged(QString)), SLOT(setVerificationExporter(QString))); | ||
| connect(m_ui->generateOwnCerticateButton, SIGNAL(clicked(bool)), SLOT(generateCertificate())); | ||
| } | ||
|
|
@@ -47,6 +51,8 @@ void SettingsWidgetKeeShare::loadSettings() | |
| m_ui->enableExportCheckBox->setChecked(active.out); | ||
| m_ui->enableImportCheckBox->setChecked(active.in); | ||
|
|
||
| m_ui->deviceIdEdit->setText(KeeShare::deviceId()); | ||
|
|
||
| m_own = KeeShare::own(); | ||
| updateOwnCertificate(); | ||
| } | ||
|
|
@@ -68,6 +74,14 @@ void SettingsWidgetKeeShare::saveSettings() | |
| KeeShare::setOwn(m_own); | ||
| KeeShare::setActive(active); | ||
|
|
||
| auto deviceId = m_ui->deviceIdEdit->text().trimmed(); | ||
| if (!deviceId.isEmpty()) { | ||
| KeeShare::setDeviceId(deviceId); | ||
| } else { | ||
| // Clear stored ID so it will be auto-detected next time | ||
| config()->set(Config::KeeShare_DeviceId, QString()); | ||
| } | ||
|
Comment on lines
+77
to
+83
|
||
|
|
||
| config()->set(Config::KeeShare_QuietSuccess, m_ui->quietSuccessCheckBox->isChecked()); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,48 @@ | |
| </layout> | ||
| </widget> | ||
| </item> | ||
| <item> | ||
| <widget class="QGroupBox" name="deviceIdentityGroupBox"> | ||
| <property name="title"> | ||
| <string>Device Identity</string> | ||
| </property> | ||
| <layout class="QGridLayout" name="gridLayout_3"> | ||
| <item row="0" column="0"> | ||
| <widget class="QLabel" name="deviceIdLabel"> | ||
| <property name="text"> | ||
| <string>Device ID:</string> | ||
| </property> | ||
| </widget> | ||
| </item> | ||
| <item row="0" column="1"> | ||
| <widget class="QLineEdit" name="deviceIdEdit"> | ||
| <property name="accessibleName"> | ||
| <string>Device ID field</string> | ||
| </property> | ||
| <property name="toolTip"> | ||
| <string>Unique identifier for this device in per-device sync mode (alphanumeric only)</string> | ||
| </property> | ||
| <property name="placeholderText"> | ||
| <string>Auto-detected from system</string> | ||
| </property> | ||
| </widget> | ||
|
Comment on lines
+85
to
+95
|
||
| </item> | ||
| <item row="0" column="2"> | ||
| <spacer name="deviceIdSpacer"> | ||
| <property name="orientation"> | ||
| <enum>Qt::Horizontal</enum> | ||
| </property> | ||
| <property name="sizeHint" stdset="0"> | ||
| <size> | ||
| <width>40</width> | ||
| <height>20</height> | ||
| </size> | ||
| </property> | ||
| </spacer> | ||
| </item> | ||
| </layout> | ||
| </widget> | ||
| </item> | ||
| <item> | ||
| <widget class="QGroupBox" name="ownCertificateGroupBox"> | ||
| <property name="title"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.