cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / coresessionwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2020 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "coresessionwidget.h"
22
23 #include <QDateTime>
24
25 #include "client.h"
26 #include "util.h"
27
28 CoreSessionWidget::CoreSessionWidget(QWidget* parent)
29     : QWidget(parent)
30 {
31     ui.setupUi(this);
32     connect(ui.disconnectButton, &QPushButton::released, this, &CoreSessionWidget::onDisconnectClicked);
33 }
34
35 void CoreSessionWidget::setData(QMap<QString, QVariant> map)
36 {
37     ui.sessionGroup->setTitle(map["remoteAddress"].toString());
38     ui.labelLocation->setText(map["location"].toString());
39     ui.labelClient->setText(map["clientVersion"].toString());
40     if (map["clientVersionDate"].toString().isEmpty()) {
41         ui.labelVersionDate->setText(QString("<i>%1</i>").arg(tr("Unknown date")));
42     }
43     else {
44         ui.labelVersionDate->setText(tryFormatUnixEpoch(map["clientVersionDate"].toString(), Qt::DateFormat::DefaultLocaleShortDate));
45     }
46     ui.labelUptime->setText(map["connectedSince"].toDateTime().toLocalTime().toString(Qt::DateFormat::DefaultLocaleShortDate));
47     if (map["location"].toString().isEmpty()) {
48         ui.labelLocation->hide();
49         ui.labelLocationTitle->hide();
50     }
51     ui.labelSecure->setText(map["secure"].toBool() ? tr("Yes") : tr("No"));
52
53     auto features = Quassel::Features{map["featureList"].toStringList(), static_cast<Quassel::LegacyFeatures>(map["features"].toUInt())};
54     if (features.isEnabled(Quassel::Feature::RemoteDisconnect)) {
55         // Both client and core support it, enable the button
56         ui.disconnectButton->setEnabled(true);
57         ui.disconnectButton->setToolTip(tr("End the client's session, disconnecting it"));
58     }
59     else {
60         // For any active sessions to be displayed, the core must support this feature.  We can
61         // assume the client doesn't support being remotely disconnected.
62         //
63         // (During the development of 0.13, there was a period of time where active sessions existed
64         //  but did not provide the disconnect option.  We can overlook this.)
65
66         // Either core or client doesn't support it, disable the option
67         ui.disconnectButton->setEnabled(false);
68         // Assuming the client lacks support, set the tooltip accordingly
69         ui.disconnectButton->setToolTip(
70             QString("<p>%1</p><p><b>%2</b></p>")
71                 .arg(tr("End the client's session, disconnecting it"), tr("This client does not support being remotely disconnected")));
72     }
73
74     bool success = false;
75     _peerId = map["id"].toInt(&success);
76     if (!success)
77         _peerId = -1;
78 }
79
80 void CoreSessionWidget::onDisconnectClicked()
81 {
82     // Don't allow the End Session button to be spammed; Quassel's protocol isn't lossy and it
83     // should reach the destination eventually...
84     ui.disconnectButton->setEnabled(false);
85     ui.disconnectButton->setText(tr("Ending session..."));
86
87     emit disconnectClicked(_peerId);
88 }