2017-08-31 02:19:30 +02:00
|
|
|
#include "./otherdialogs.h"
|
2017-08-29 23:53:44 +02:00
|
|
|
|
2021-01-25 19:48:11 +01:00
|
|
|
#include <syncthingconnector/syncthingconnection.h>
|
|
|
|
#include <syncthingconnector/syncthingdir.h>
|
2017-08-29 23:53:44 +02:00
|
|
|
|
|
|
|
// use meta-data of syncthingtray application here
|
|
|
|
#include "resources/../../tray/resources/config.h"
|
|
|
|
|
|
|
|
#include <QClipboard>
|
2017-09-05 00:25:14 +02:00
|
|
|
#include <QDialog>
|
2017-08-29 23:53:44 +02:00
|
|
|
#include <QFont>
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Data;
|
|
|
|
|
|
|
|
namespace QtGui {
|
|
|
|
|
2017-09-05 00:25:14 +02:00
|
|
|
QDialog *ownDeviceIdDialog(Data::SyncthingConnection &connection)
|
2017-08-29 23:53:44 +02:00
|
|
|
{
|
2017-09-05 00:25:14 +02:00
|
|
|
auto *dlg = new QDialog(nullptr, Qt::Window);
|
2017-08-30 00:12:46 +02:00
|
|
|
dlg->setWindowTitle(QCoreApplication::translate("QtGui::OtherDialogs", "Own device ID") + QStringLiteral(" - " APP_NAME));
|
2017-08-29 23:53:44 +02:00
|
|
|
dlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
2019-06-25 13:49:53 +02:00
|
|
|
dlg->setBackgroundRole(QPalette::Window);
|
2017-08-29 23:53:44 +02:00
|
|
|
auto *layout = new QVBoxLayout(dlg);
|
|
|
|
layout->setAlignment(Qt::AlignCenter);
|
|
|
|
auto *pixmapLabel = new QLabel(dlg);
|
|
|
|
pixmapLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
layout->addWidget(pixmapLabel);
|
|
|
|
auto *textLabel = new QLabel(dlg);
|
2017-08-30 00:12:46 +02:00
|
|
|
textLabel->setText(connection.myId().isEmpty() ? QCoreApplication::translate("QtGui::OtherDialogs", "device ID is unknown") : connection.myId());
|
2017-08-29 23:53:44 +02:00
|
|
|
QFont defaultFont = textLabel->font();
|
|
|
|
defaultFont.setBold(true);
|
|
|
|
defaultFont.setPointSize(defaultFont.pointSize() + 2);
|
|
|
|
textLabel->setFont(defaultFont);
|
|
|
|
textLabel->setAlignment(Qt::AlignCenter);
|
|
|
|
layout->addWidget(textLabel);
|
|
|
|
auto *copyPushButton = new QPushButton(dlg);
|
2017-08-30 00:12:46 +02:00
|
|
|
copyPushButton->setText(QCoreApplication::translate("QtGui::OtherDialogs", "Copy to clipboard"));
|
2017-08-29 23:53:44 +02:00
|
|
|
QObject::connect(
|
|
|
|
copyPushButton, &QPushButton::clicked, bind(&QClipboard::setText, QGuiApplication::clipboard(), connection.myId(), QClipboard::Clipboard));
|
|
|
|
layout->addWidget(copyPushButton);
|
2018-10-20 22:08:25 +02:00
|
|
|
connection.requestQrCode(connection.myId());
|
|
|
|
QObject::connect(dlg, &QObject::destroyed,
|
2017-09-17 21:48:15 +02:00
|
|
|
bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
2018-10-20 22:08:25 +02:00
|
|
|
QObject::connect(&connection, &SyncthingConnection::qrCodeAvailable,
|
|
|
|
[pixmapLabel, devId = connection.myId()](const QString &text, const QByteArray &data) {
|
|
|
|
if (text != devId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPixmap pixmap;
|
|
|
|
pixmap.loadFromData(data);
|
|
|
|
pixmapLabel->setPixmap(pixmap);
|
|
|
|
})));
|
2017-08-29 23:53:44 +02:00
|
|
|
dlg->setLayout(layout);
|
|
|
|
return dlg;
|
|
|
|
}
|
2017-09-17 21:48:15 +02:00
|
|
|
} // namespace QtGui
|