1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #include "coreinfodlg.h"
23 #include <QMessageBox>
25 #include "bufferwidget.h"
29 CoreInfoDlg::CoreInfoDlg(QWidget *parent) : QDialog(parent) {
32 // Listen for resynchronization events (pre-0.13 cores only)
33 connect(Client::instance(), SIGNAL(coreInfoResynchronized()),
34 this, SLOT(coreInfoResynchronized()));
36 // Update legacy core info for Quassel cores earlier than 0.13. This does nothing on modern
38 Client::refreshLegacyCoreInfo();
40 // Display existing core info, set up signal handlers
41 coreInfoResynchronized();
44 ui.coreUnsupportedIcon->setPixmap(icon::get("dialog-warning").pixmap(16));
51 void CoreInfoDlg::coreInfoResynchronized() {
52 // CoreInfo object has been recreated, or this is the first time the dialog's been shown
54 CoreInfo *coreInfo = Client::coreInfo();
55 // Listen for changes to core information
56 connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)),
57 this, SLOT(coreInfoChanged(const QVariantMap &)));
59 // Update with any known core information set before connecting the signal. This is needed for
60 // both modern (0.13+) and legacy cores.
61 coreInfoChanged(coreInfo->coreData());
65 void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) {
66 if(coreInfo.isEmpty()) {
67 // We're missing data for some reason
68 if (Client::isConnected()) {
69 // Core info is entirely empty despite being connected. Something's probably wrong.
70 ui.labelCoreVersion->setText(tr("Unknown"));
71 ui.labelCoreVersionDate->setText(tr("Unknown"));
73 // We're disconnected. Mark as such.
74 ui.labelCoreVersion->setText(tr("Disconnected from core"));
75 ui.labelCoreVersionDate->setText(tr("Not available"));
77 ui.labelClientCount->setNum(0);
78 // Don't return, allow the code below to remove any existing session widgets
80 ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString());
81 // "BuildDate" for compatibility
82 ui.labelCoreVersionDate->setText(coreInfo["quasselBuildDate"].toString());
83 ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt());
86 auto coreSessionSupported = false;
87 auto ids = _widgets.keys();
88 for (const auto &peerData : coreInfo["sessionConnectedClientData"].toList()) {
89 coreSessionSupported = true;
91 auto peerMap = peerData.toMap();
92 int peerId = peerMap["id"].toInt();
94 ids.removeAll(peerId);
97 CoreSessionWidget *coreSessionWidget = _widgets[peerId];
98 if (coreSessionWidget == nullptr) {
99 coreSessionWidget = new CoreSessionWidget(ui.coreSessionScrollContainer);
102 coreSessionWidget->setData(peerMap);
104 _widgets[peerId] = coreSessionWidget;
105 // Add this to the end of the session list, but before the default layout stretch item.
106 // The layout stretch item should never be removed, so count should always be >= 1.
107 ui.coreSessionContainer->insertWidget(ui.coreSessionContainer->count() - 1,
108 coreSessionWidget, 0, Qt::AlignTop);
109 connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int)));
113 for (const auto &key : ids) {
114 delete _widgets[key];
115 _widgets.remove(key);
118 ui.coreSessionScrollArea->setVisible(coreSessionSupported);
120 // Hide the information bar when core sessions are supported or when disconnected
121 ui.coreUnsupportedWidget->setVisible(
122 !(coreSessionSupported || Client::isConnected() == false));
124 // Update uptime for immediate display, don't wait for the timer
129 void CoreInfoDlg::updateUptime() {
130 CoreInfo *coreInfo = Client::coreInfo();
132 if (!Client::isConnected()) {
133 // Not connected, don't bother trying to calculate the uptime
134 ui.labelUptime->setText(tr("Not available"));
135 } else if (coreInfo->coreData().isEmpty()) {
136 // Core info is entirely empty despite being connected. Something's probably wrong.
137 ui.labelUptime->setText(tr("Unknown"));
139 // Connected, format the uptime for display
140 QDateTime startTime = coreInfo->at("startTime").toDateTime();
142 int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC());
143 int64_t updays = uptime / 86400;
145 int64_t uphours = uptime / 3600;
147 int64_t upmins = uptime / 60;
150 QString uptimeText = tr("%n Day(s)", "", updays) +
151 tr(" %1:%2:%3 (since %4)")
152 .arg(uphours, 2, 10, QChar('0'))
153 .arg(upmins, 2, 10, QChar('0'))
154 .arg(uptime, 2, 10, QChar('0'))
155 .arg(startTime.toLocalTime().toString(Qt::TextDate));
156 ui.labelUptime->setText(uptimeText);
160 void CoreInfoDlg::disconnectClicked(int peerId) {
161 Client::kickClient(peerId);
164 void CoreInfoDlg::on_coreUnsupportedDetails_clicked()
166 QMessageBox::warning(this,
167 tr("Active sessions unsupported"),
168 QString("<p><b>%1</b></p></br><p>%2</p>"
169 ).arg(tr("Your Quassel core is too old to show active sessions"),
170 tr("You need a Quassel core v0.13.0 or newer to view and "
171 "disconnect other connected clients.")));