Move showOwnDeviceId() to widgets
So Plasmoid can use it as well
This commit is contained in:
parent
e797d8e76c
commit
856a899c4b
|
@ -2,6 +2,7 @@
|
|||
#include "./trayicon.h"
|
||||
#include "./traymenu.h"
|
||||
|
||||
#include "../../widgets/misc/otherdialogs.h"
|
||||
#include "../../widgets/misc/textviewdialog.h"
|
||||
#include "../../widgets/settings/settingsdialog.h"
|
||||
#include "../../widgets/webview/webviewdialog.h"
|
||||
|
@ -219,36 +220,8 @@ void TrayWidget::showWebUi()
|
|||
|
||||
void TrayWidget::showOwnDeviceId()
|
||||
{
|
||||
auto *dlg = new QWidget(this, Qt::Window);
|
||||
dlg->setWindowTitle(tr("Own device ID") + QStringLiteral(" - " APP_NAME));
|
||||
dlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->setBackgroundRole(QPalette::Background);
|
||||
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);
|
||||
textLabel->setText(m_connection.myId().isEmpty() ? tr("device ID is unknown") : m_connection.myId());
|
||||
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);
|
||||
copyPushButton->setText(tr("Copy to clipboard"));
|
||||
connect(
|
||||
copyPushButton, &QPushButton::clicked, bind(&QClipboard::setText, QGuiApplication::clipboard(), m_connection.myId(), QClipboard::Clipboard));
|
||||
layout->addWidget(copyPushButton);
|
||||
connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
||||
m_connection.requestQrCode(m_connection.myId(), [pixmapLabel](const QByteArray &data) {
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(data);
|
||||
pixmapLabel->setPixmap(pixmap);
|
||||
})));
|
||||
dlg->setLayout(layout);
|
||||
auto *const dlg = ownDeviceIdDialog(m_connection);
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
centerWidget(dlg);
|
||||
showDialog(dlg);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ set(WIDGETS_HEADER_FILES
|
|||
misc/statusinfo.h
|
||||
misc/dbusstatusnotifier.h
|
||||
misc/internalerror.h
|
||||
misc/otherdialogs.h
|
||||
)
|
||||
set(WIDGETS_SRC_FILES
|
||||
settings/settings.cpp
|
||||
|
@ -31,6 +32,7 @@ set(WIDGETS_SRC_FILES
|
|||
misc/errorviewdialog.cpp
|
||||
misc/statusinfo.cpp
|
||||
misc/dbusstatusnotifier.cpp
|
||||
misc/otherdialogs.cpp
|
||||
)
|
||||
set(RES_FILES
|
||||
resources/${META_PROJECT_NAME}icons.qrc
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include "./textviewdialog.h"
|
||||
|
||||
#include "../../connector/syncthingconnection.h"
|
||||
#include "../../connector/syncthingdir.h"
|
||||
|
||||
// use meta-data of syncthingtray application here
|
||||
#include "resources/../../tray/resources/config.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFont>
|
||||
#include <QGuiApplication>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace std;
|
||||
using namespace Data;
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
QWidget *ownDeviceIdDialog(Data::SyncthingConnection &connection)
|
||||
{
|
||||
auto *dlg = new QWidget(nullptr, Qt::Window);
|
||||
dlg->setWindowTitle(QCoreApplication::translate("otherdialogs", "Own device ID") + QStringLiteral(" - " APP_NAME));
|
||||
dlg->setWindowIcon(QIcon(QStringLiteral(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
||||
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
||||
dlg->setBackgroundRole(QPalette::Background);
|
||||
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);
|
||||
textLabel->setText(connection.myId().isEmpty() ? QCoreApplication::translate("otherdialogs", "device ID is unknown") : connection.myId());
|
||||
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);
|
||||
copyPushButton->setText(QCoreApplication::translate("otherdialogs", "Copy to clipboard"));
|
||||
QObject::connect(
|
||||
copyPushButton, &QPushButton::clicked, bind(&QClipboard::setText, QGuiApplication::clipboard(), connection.myId(), QClipboard::Clipboard));
|
||||
layout->addWidget(copyPushButton);
|
||||
QObject::connect(dlg, &QWidget::destroyed, bind(static_cast<bool (*)(const QMetaObject::Connection &)>(&QObject::disconnect),
|
||||
connection.requestQrCode(connection.myId(), [pixmapLabel](const QByteArray &data) {
|
||||
QPixmap pixmap;
|
||||
pixmap.loadFromData(data);
|
||||
pixmapLabel->setPixmap(pixmap);
|
||||
})));
|
||||
dlg->setLayout(layout);
|
||||
return dlg;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef SYNCTHINGWIDGETS_OTHERDIALOGS_H
|
||||
#define SYNCTHINGWIDGETS_OTHERDIALOGS_H
|
||||
|
||||
#include "../global.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Data {
|
||||
class SyncthingConnection;
|
||||
}
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
QWidget SYNCTHINGWIDGETS_EXPORT *ownDeviceIdDialog(Data::SyncthingConnection &connection);
|
||||
}
|
||||
|
||||
#endif // SYNCTHINGWIDGETS_OTHERDIALOGS_H
|
Loading…
Reference in New Issue