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 // Add this to the end of the session list, but before the default layout stretch item.
63 // The layout stretch item should never be removed, so count should always be >= 1.
64 ui.coreSessionContainer->insertWidget(ui.coreSessionContainer->count() - 1,
65 coreSessionWidget, 0, Qt::AlignTop);
66 connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int)));
70 for (const auto &key : ids) {
75 ui.coreSessionScrollArea->setVisible(coreSessionSupported);
79 void CoreInfoDlg::updateUptime() {
80 CoreInfo *coreInfo = Client::coreInfo();
82 QDateTime startTime = coreInfo->at("startTime").toDateTime();
84 int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC());
85 int64_t updays = uptime / 86400;
87 int64_t uphours = uptime / 3600;
89 int64_t upmins = uptime / 60;
92 QString uptimeText = tr("%n Day(s)", "", updays) +
93 tr(" %1:%2:%3 (since %4)")
94 .arg(uphours, 2, 10, QChar('0'))
95 .arg(upmins, 2, 10, QChar('0'))
96 .arg(uptime, 2, 10, QChar('0'))
97 .arg(startTime.toLocalTime().toString(Qt::TextDate));
98 ui.labelUptime->setText(uptimeText);
102 void CoreInfoDlg::disconnectClicked(int peerId) {
103 Client::kickClient(peerId);