2025-02-09 16:16:15 +00:00
|
|
|
/*
|
|
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "FingerprintDialog.h"
|
|
|
|
|
|
2025-02-12 23:05:18 +00:00
|
|
|
#include "widgets/FingerprintPreview.h"
|
2025-02-09 16:16:15 +00:00
|
|
|
|
|
|
|
|
#include <QFont>
|
2025-02-12 23:05:18 +00:00
|
|
|
#include <QLabel>
|
2025-02-09 16:16:15 +00:00
|
|
|
#include <QPushButton>
|
2025-02-12 23:05:18 +00:00
|
|
|
#include <QVBoxLayout>
|
2025-02-09 16:16:15 +00:00
|
|
|
|
2025-08-24 04:33:06 +00:00
|
|
|
FingerprintDialog::FingerprintDialog(
|
|
|
|
|
QWidget *parent, const Fingerprint &localFingerprint, FingerprintDialogMode mode,
|
|
|
|
|
const Fingerprint &remoteFingerprint
|
|
|
|
|
)
|
2025-02-09 16:16:15 +00:00
|
|
|
: QDialog(parent),
|
2025-02-12 23:05:18 +00:00
|
|
|
m_lblHeader{new QLabel(this)},
|
|
|
|
|
m_lblFooter{new QLabel(this)},
|
2025-08-24 04:33:06 +00:00
|
|
|
m_buttonBox{new QDialogButtonBox(QDialogButtonBox::Help, this)}
|
2025-02-09 16:16:15 +00:00
|
|
|
{
|
2025-02-12 23:05:18 +00:00
|
|
|
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2025-08-24 04:33:06 +00:00
|
|
|
m_lblHeader->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2025-02-09 16:16:15 +00:00
|
|
|
|
2025-08-24 04:33:06 +00:00
|
|
|
const bool localMode = mode == FingerprintDialogMode::Local;
|
|
|
|
|
const bool isServer = mode == FingerprintDialogMode::Server;
|
2025-02-12 23:05:18 +00:00
|
|
|
|
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
|
layout->addWidget(m_lblHeader);
|
|
|
|
|
layout->addSpacerItem(new QSpacerItem(0, 10, QSizePolicy::Fixed, QSizePolicy::Fixed));
|
2025-08-24 04:33:06 +00:00
|
|
|
layout->addLayout(
|
|
|
|
|
localMode ? makeLocalLayout(localFingerprint) : makeCompareLayout(localFingerprint, isServer, remoteFingerprint)
|
|
|
|
|
);
|
2025-02-12 23:05:18 +00:00
|
|
|
layout->addWidget(m_lblFooter);
|
|
|
|
|
layout->addWidget(m_buttonBox);
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
|
2025-08-24 04:33:06 +00:00
|
|
|
if (localMode) {
|
2025-02-12 23:05:18 +00:00
|
|
|
setWindowTitle(tr("Local Fingerprints"));
|
2025-08-24 04:33:06 +00:00
|
|
|
setWindowIcon(QIcon::fromTheme("fingerprint"));
|
|
|
|
|
|
|
|
|
|
m_lblHeader->setText(tr("Local computer's fingerprint"));
|
|
|
|
|
|
|
|
|
|
m_buttonBox->addButton(QDialogButtonBox::Ok);
|
2025-02-12 23:05:18 +00:00
|
|
|
connect(m_buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept);
|
2025-08-24 04:33:06 +00:00
|
|
|
|
2024-11-29 13:19:41 +00:00
|
|
|
} else {
|
2025-08-24 04:33:06 +00:00
|
|
|
setWindowIcon(QIcon::fromTheme("question"));
|
|
|
|
|
m_lblHeader->setAlignment(Qt::AlignHCenter);
|
|
|
|
|
m_lblFooter->setAlignment(Qt::AlignHCenter);
|
|
|
|
|
|
2025-03-11 00:21:57 +00:00
|
|
|
auto body =
|
|
|
|
|
tr("Compare the fingerprints in this dialog to those on the %1.\n"
|
|
|
|
|
"Only connect if they match!");
|
2024-11-29 13:19:41 +00:00
|
|
|
|
2025-08-24 04:33:06 +00:00
|
|
|
if (isServer) {
|
|
|
|
|
setWindowTitle(tr("New client connecting"));
|
|
|
|
|
m_lblHeader->setText(body.arg(tr("client")));
|
2025-10-27 06:07:41 +00:00
|
|
|
m_lblFooter->setText(tr("\nTrust client and allow connection?\n"));
|
2024-11-29 13:19:41 +00:00
|
|
|
} else {
|
2025-08-24 04:33:06 +00:00
|
|
|
setWindowTitle(tr("Connecting to a new server"));
|
|
|
|
|
m_lblHeader->setText(body.arg(tr("server")));
|
2025-10-27 06:07:41 +00:00
|
|
|
m_lblFooter->setText(tr("\nDo you want to connect to the server?\n"));
|
2024-11-29 13:19:41 +00:00
|
|
|
}
|
2025-02-09 16:16:15 +00:00
|
|
|
|
2025-08-24 04:33:06 +00:00
|
|
|
m_buttonBox->addButton(QDialogButtonBox::Yes);
|
|
|
|
|
m_buttonBox->addButton(QDialogButtonBox::No);
|
2025-02-12 23:05:18 +00:00
|
|
|
m_buttonBox->button(QDialogButtonBox::No)->setFocus();
|
|
|
|
|
connect(m_buttonBox->button(QDialogButtonBox::No), &QPushButton::clicked, this, &QDialog::reject);
|
|
|
|
|
connect(m_buttonBox->button(QDialogButtonBox::Yes), &QPushButton::clicked, this, &QDialog::accept);
|
2025-02-09 16:16:15 +00:00
|
|
|
}
|
2025-08-24 04:33:06 +00:00
|
|
|
|
|
|
|
|
updateModeButton(false);
|
|
|
|
|
m_buttonBox->button(QDialogButtonBox::Help)->setCheckable(true);
|
|
|
|
|
m_buttonBox->button(QDialogButtonBox::Help)->setIcon(QIcon());
|
|
|
|
|
connect(
|
|
|
|
|
m_buttonBox->button(QDialogButtonBox::Help), &QPushButton::toggled, this, &FingerprintDialog::togglePreviewMode
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-09 16:16:15 +00:00
|
|
|
adjustSize();
|
2025-02-12 23:05:18 +00:00
|
|
|
setFixedSize(size());
|
2025-02-09 16:16:15 +00:00
|
|
|
}
|
2025-08-24 04:33:06 +00:00
|
|
|
|
|
|
|
|
QLayout *FingerprintDialog::makeLocalLayout(const Fingerprint &localFingerprint)
|
|
|
|
|
{
|
|
|
|
|
m_localPreview = new FingerprintPreview(this, localFingerprint);
|
|
|
|
|
|
|
|
|
|
auto layout = new QVBoxLayout();
|
|
|
|
|
layout->addWidget(m_localPreview, 0, Qt::AlignTop | Qt::AlignHCenter);
|
|
|
|
|
return layout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLayout *FingerprintDialog::makeCompareLayout(
|
|
|
|
|
const Fingerprint &localFingerprint, bool isServer, const Fingerprint &remoteFingerprint
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
const auto serverText = tr("Server Fingerprint");
|
|
|
|
|
const auto clientText = tr("Client Fingerprint");
|
|
|
|
|
|
|
|
|
|
m_localPreview = new FingerprintPreview(this, localFingerprint, isServer ? serverText : clientText, false);
|
|
|
|
|
m_remotePreview = new FingerprintPreview(this, remoteFingerprint, isServer ? clientText : serverText, false);
|
|
|
|
|
|
|
|
|
|
auto fpLayout = new QHBoxLayout();
|
|
|
|
|
fpLayout->setAlignment(Qt::AlignTop);
|
|
|
|
|
if (isServer) {
|
|
|
|
|
fpLayout->addWidget(m_localPreview, 0, Qt::AlignHCenter);
|
|
|
|
|
fpLayout->addWidget(m_remotePreview, 0, Qt::AlignHCenter);
|
|
|
|
|
} else {
|
|
|
|
|
fpLayout->addWidget(m_remotePreview, 0, Qt::AlignHCenter);
|
|
|
|
|
fpLayout->addWidget(m_localPreview, 0, Qt::AlignHCenter);
|
|
|
|
|
}
|
|
|
|
|
return fpLayout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FingerprintDialog::togglePreviewMode(bool hashMode)
|
|
|
|
|
{
|
|
|
|
|
m_localPreview->toggleMode(hashMode);
|
|
|
|
|
if (m_remotePreview)
|
|
|
|
|
m_remotePreview->toggleMode(hashMode);
|
|
|
|
|
updateModeButton(hashMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FingerprintDialog::updateModeButton(bool hashMode) const
|
|
|
|
|
{
|
2025-10-18 05:39:59 +00:00
|
|
|
const auto text = hashMode ? tr("Show image") : tr("Show hash");
|
|
|
|
|
const auto toolTip = hashMode ? tr("Display the fingerprint as an image") : tr("Display the fingerprint as a hash");
|
2025-08-24 04:33:06 +00:00
|
|
|
m_buttonBox->button(QDialogButtonBox::Help)->setText(text);
|
|
|
|
|
m_buttonBox->button(QDialogButtonBox::Help)->setToolTip(toolTip);
|
|
|
|
|
}
|