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"
24 #include "bufferwidget.h"
26 CoreInfoDlg::CoreInfoDlg(QWidget *parent) : QDialog(parent) {
28 CoreInfo *coreInfo = Client::coreInfo();
29 connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)), this, SLOT(coreInfoChanged(const QVariantMap &)));
31 coreInfoChanged(coreInfo->coreData());
38 void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) {
39 ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString());
40 ui.labelCoreVersionDate->setText(coreInfo["quasselBuildDate"].toString()); // "BuildDate" for compatibility
41 ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt());
43 auto coreSessionSupported = false;
44 auto ids = _widgets.keys();
45 for (const auto &peerData : coreInfo["sessionConnectedClientData"].toList()) {
46 coreSessionSupported = true;
48 auto peerMap = peerData.toMap();
49 int peerId = peerMap["id"].toInt();
51 ids.removeAll(peerId);
54 CoreSessionWidget *coreSessionWidget = _widgets[peerId];
55 if (coreSessionWidget == nullptr) {
56 coreSessionWidget = new CoreSessionWidget(ui.coreSessionScrollContainer);
59 coreSessionWidget->setData(peerMap);
61 _widgets[peerId] = coreSessionWidget;
62 ui.coreSessionContainer->addWidget(coreSessionWidget);
63 connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int)));
67 for (const auto &key : ids) {
72 ui.coreSessionScrollArea->setVisible(coreSessionSupported);
73 ui.coreSessionContainer->addStretch(1);
77 void CoreInfoDlg::updateUptime() {
78 CoreInfo *coreInfo = Client::coreInfo();
80 QDateTime startTime = coreInfo->at("startTime").toDateTime();
82 int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC());
83 int64_t updays = uptime / 86400;
85 int64_t uphours = uptime / 3600;
87 int64_t upmins = uptime / 60;
90 QString uptimeText = tr("%n Day(s)", "", updays) +
91 tr(" %1:%2:%3 (since %4)")
92 .arg(uphours, 2, 10, QChar('0'))
93 .arg(upmins, 2, 10, QChar('0'))
94 .arg(uptime, 2, 10, QChar('0'))
95 .arg(startTime.toLocalTime().toString(Qt::TextDate));
96 ui.labelUptime->setText(uptimeText);
100 void CoreInfoDlg::disconnectClicked(int peerId) {
101 Client::kickClient(peerId);