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 <QMessageBox>
23 #include "coreinfodlg.h"
26 #include "bufferwidget.h"
28 CoreInfoDlg::CoreInfoDlg(QWidget *parent) : QDialog(parent) {
30 CoreInfo *coreInfo = Client::coreInfo();
31 connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)), this, SLOT(coreInfoChanged(const QVariantMap &)));
33 coreInfoChanged(coreInfo->coreData());
36 ui.coreUnsupportedIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(16));
43 void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) {
44 ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString());
45 ui.labelCoreVersionDate->setText(coreInfo["quasselBuildDate"].toString()); // "BuildDate" for compatibility
46 ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt());
48 auto coreSessionSupported = false;
49 auto ids = _widgets.keys();
50 for (const auto &peerData : coreInfo["sessionConnectedClientData"].toList()) {
51 coreSessionSupported = true;
53 auto peerMap = peerData.toMap();
54 int peerId = peerMap["id"].toInt();
56 ids.removeAll(peerId);
59 CoreSessionWidget *coreSessionWidget = _widgets[peerId];
60 if (coreSessionWidget == nullptr) {
61 coreSessionWidget = new CoreSessionWidget(ui.coreSessionScrollContainer);
64 coreSessionWidget->setData(peerMap);
66 _widgets[peerId] = coreSessionWidget;
67 // Add this to the end of the session list, but before the default layout stretch item.
68 // The layout stretch item should never be removed, so count should always be >= 1.
69 ui.coreSessionContainer->insertWidget(ui.coreSessionContainer->count() - 1,
70 coreSessionWidget, 0, Qt::AlignTop);
71 connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int)));
75 for (const auto &key : ids) {
80 ui.coreSessionScrollArea->setVisible(coreSessionSupported);
82 // Hide the information bar when core sessions are supported
83 ui.coreUnsupportedWidget->setVisible(!coreSessionSupported);
87 void CoreInfoDlg::updateUptime() {
88 CoreInfo *coreInfo = Client::coreInfo();
90 QDateTime startTime = coreInfo->at("startTime").toDateTime();
92 int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC());
93 int64_t updays = uptime / 86400;
95 int64_t uphours = uptime / 3600;
97 int64_t upmins = uptime / 60;
100 QString uptimeText = tr("%n Day(s)", "", updays) +
101 tr(" %1:%2:%3 (since %4)")
102 .arg(uphours, 2, 10, QChar('0'))
103 .arg(upmins, 2, 10, QChar('0'))
104 .arg(uptime, 2, 10, QChar('0'))
105 .arg(startTime.toLocalTime().toString(Qt::TextDate));
106 ui.labelUptime->setText(uptimeText);
110 void CoreInfoDlg::disconnectClicked(int peerId) {
111 Client::kickClient(peerId);
114 void CoreInfoDlg::on_coreUnsupportedDetails_clicked()
116 QMessageBox::warning(this,
117 tr("Active sessions unsupported"),
118 QString("<p><b>%1</b></p></br><p>%2</p>"
119 ).arg(tr("Your Quassel core is too old to show active sessions"),
120 tr("You need a Quassel core v0.13.0 or newer to view and "
121 "disconnect other connected clients.")));