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) {
31 CoreInfo *coreInfo = Client::coreInfo();
32 connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)), this, SLOT(coreInfoChanged(const QVariantMap &)));
34 coreInfoChanged(coreInfo->coreData());
37 ui.coreUnsupportedIcon->setPixmap(icon::get("dialog-warning").pixmap(16));
44 void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) {
45 ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString());
46 ui.labelCoreVersionDate->setText(coreInfo["quasselBuildDate"].toString()); // "BuildDate" for compatibility
47 ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt());
49 auto coreSessionSupported = false;
50 auto ids = _widgets.keys();
51 for (const auto &peerData : coreInfo["sessionConnectedClientData"].toList()) {
52 coreSessionSupported = true;
54 auto peerMap = peerData.toMap();
55 int peerId = peerMap["id"].toInt();
57 ids.removeAll(peerId);
60 CoreSessionWidget *coreSessionWidget = _widgets[peerId];
61 if (coreSessionWidget == nullptr) {
62 coreSessionWidget = new CoreSessionWidget(ui.coreSessionScrollContainer);
65 coreSessionWidget->setData(peerMap);
67 _widgets[peerId] = coreSessionWidget;
68 // Add this to the end of the session list, but before the default layout stretch item.
69 // The layout stretch item should never be removed, so count should always be >= 1.
70 ui.coreSessionContainer->insertWidget(ui.coreSessionContainer->count() - 1,
71 coreSessionWidget, 0, Qt::AlignTop);
72 connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int)));
76 for (const auto &key : ids) {
81 ui.coreSessionScrollArea->setVisible(coreSessionSupported);
83 // Hide the information bar when core sessions are supported
84 ui.coreUnsupportedWidget->setVisible(!coreSessionSupported);
88 void CoreInfoDlg::updateUptime() {
89 CoreInfo *coreInfo = Client::coreInfo();
91 QDateTime startTime = coreInfo->at("startTime").toDateTime();
93 int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC());
94 int64_t updays = uptime / 86400;
96 int64_t uphours = uptime / 3600;
98 int64_t upmins = uptime / 60;
101 QString uptimeText = tr("%n Day(s)", "", updays) +
102 tr(" %1:%2:%3 (since %4)")
103 .arg(uphours, 2, 10, QChar('0'))
104 .arg(upmins, 2, 10, QChar('0'))
105 .arg(uptime, 2, 10, QChar('0'))
106 .arg(startTime.toLocalTime().toString(Qt::TextDate));
107 ui.labelUptime->setText(uptimeText);
111 void CoreInfoDlg::disconnectClicked(int peerId) {
112 Client::kickClient(peerId);
115 void CoreInfoDlg::on_coreUnsupportedDetails_clicked()
117 QMessageBox::warning(this,
118 tr("Active sessions unsupported"),
119 QString("<p><b>%1</b></p></br><p>%2</p>"
120 ).arg(tr("Your Quassel core is too old to show active sessions"),
121 tr("You need a Quassel core v0.13.0 or newer to view and "
122 "disconnect other connected clients.")));