X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoresessionwidget.cpp;h=c0fb8c890c96193f5eabe6e13590744ba4b98312;hp=2cce145916aa6429207a8bbec4d5003fcaba6123;hb=HEAD;hpb=9ef86f499753853c3751aee7da54d186837a5161 diff --git a/src/qtui/coresessionwidget.cpp b/src/qtui/coresessionwidget.cpp index 2cce1459..a4c54654 100644 --- a/src/qtui/coresessionwidget.cpp +++ b/src/qtui/coresessionwidget.cpp @@ -1,33 +1,88 @@ +/*************************************************************************** + * Copyright (C) 2005-2022 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + #include "coresessionwidget.h" -#include -#include -#include -#include -#include -#include +#include + +#include "client.h" +#include "util.h" -CoreSessionWidget::CoreSessionWidget(QWidget *parent) +CoreSessionWidget::CoreSessionWidget(QWidget* parent) : QWidget(parent) { ui.setupUi(this); - layout()->setContentsMargins(0, 0, 0, 0); - layout()->setSpacing(0); + connect(ui.disconnectButton, &QPushButton::released, this, &CoreSessionWidget::onDisconnectClicked); } void CoreSessionWidget::setData(QMap map) { - QLabel *iconSecure = ui.iconSecure; - QPushButton *disconnectButton = ui.disconnectButton; - - ui.labelRemoteAddress->setText(map["remoteAddress"].toString()); + ui.sessionGroup->setTitle(map["remoteAddress"].toString()); ui.labelLocation->setText(map["location"].toString()); ui.labelClient->setText(map["clientVersion"].toString()); - ui.labelVersionDate->setText(map["clientVersionDate"].toString()); - ui.labelUptime - ->setText(map["connectedSince"].toDateTime().toLocalTime().toString(Qt::DateFormat::SystemLocaleShortDate)); + if (map["clientVersionDate"].toString().isEmpty()) { + ui.labelVersionDate->setText(QString("%1").arg(tr("Unknown date"))); + } + else { + ui.labelVersionDate->setText(tryFormatUnixEpoch(map["clientVersionDate"].toString(), Qt::DateFormat::DefaultLocaleShortDate)); + } + ui.labelUptime->setText(map["connectedSince"].toDateTime().toLocalTime().toString(Qt::DateFormat::DefaultLocaleShortDate)); if (map["location"].toString().isEmpty()) { ui.labelLocation->hide(); ui.labelLocationTitle->hide(); } + ui.labelSecure->setText(map["secure"].toBool() ? tr("Yes") : tr("No")); + + auto features = Quassel::Features{map["featureList"].toStringList(), static_cast(map["features"].toUInt())}; + if (features.isEnabled(Quassel::Feature::RemoteDisconnect)) { + // Both client and core support it, enable the button + ui.disconnectButton->setEnabled(true); + ui.disconnectButton->setToolTip(tr("End the client's session, disconnecting it")); + } + else { + // For any active sessions to be displayed, the core must support this feature. We can + // assume the client doesn't support being remotely disconnected. + // + // (During the development of 0.13, there was a period of time where active sessions existed + // but did not provide the disconnect option. We can overlook this.) + + // Either core or client doesn't support it, disable the option + ui.disconnectButton->setEnabled(false); + // Assuming the client lacks support, set the tooltip accordingly + ui.disconnectButton->setToolTip( + QString("

%1

%2

") + .arg(tr("End the client's session, disconnecting it"), tr("This client does not support being remotely disconnected"))); + } + + bool success = false; + _peerId = map["id"].toInt(&success); + if (!success) + _peerId = -1; +} + +void CoreSessionWidget::onDisconnectClicked() +{ + // Don't allow the End Session button to be spammed; Quassel's protocol isn't lossy and it + // should reach the destination eventually... + ui.disconnectButton->setEnabled(false); + ui.disconnectButton->setText(tr("Ending session...")); + + emit disconnectClicked(_peerId); }