X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoreinfodlg.cpp;h=2f8736c1ec064a9725980aa55c5c373bbbcf75ff;hp=29e60485eb741bff40fa00128ff1e0da4fb4e42e;hb=924ed0da8578d43bf21c9155b9bf439108e74988;hpb=52df0969e22249e6758714eec9e5afd7d4fe9b83 diff --git a/src/qtui/coreinfodlg.cpp b/src/qtui/coreinfodlg.cpp index 29e60485..2f8736c1 100644 --- a/src/qtui/coreinfodlg.cpp +++ b/src/qtui/coreinfodlg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,26 +15,90 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "coreinfodlg.h" #include "client.h" -#include "signalproxy.h" - -CoreInfoDlg::CoreInfoDlg(QWidget *parent) - : QDialog(parent), - _coreInfo(this) -{ - ui.setupUi(this); - connect(&_coreInfo, SIGNAL(initDone()), this, SLOT(coreInfoAvailable())); - Client::signalProxy()->synchronize(&_coreInfo); +#include "bufferwidget.h" + +CoreInfoDlg::CoreInfoDlg(QWidget *parent) : QDialog(parent) { + ui.setupUi(this); + CoreInfo *coreInfo = Client::coreInfo(); + connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)), this, SLOT(coreInfoChanged(const QVariantMap &))); + + coreInfoChanged(coreInfo->coreData()); + + updateUptime(); + startTimer(1000); +} + + +void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) { + ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString()); + ui.labelCoreVersionDate->setText(coreInfo["quasselBuildDate"].toString()); // "BuildDate" for compatibility + ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt()); + + auto coreSessionSupported = false; + auto ids = _widgets.keys(); + for (const auto &peerData : coreInfo["sessionConnectedClientData"].toList()) { + coreSessionSupported = true; + + auto peerMap = peerData.toMap(); + int peerId = peerMap["id"].toInt(); + + ids.removeAll(peerId); + + bool isNew = false; + CoreSessionWidget *coreSessionWidget = _widgets[peerId]; + if (coreSessionWidget == nullptr) { + coreSessionWidget = new CoreSessionWidget(ui.coreSessionScrollContainer); + isNew = true; + } + coreSessionWidget->setData(peerMap); + if (isNew) { + _widgets[peerId] = coreSessionWidget; + // Add this to the end of the session list, but before the default layout stretch item. + // The layout stretch item should never be removed, so count should always be >= 1. + ui.coreSessionContainer->insertWidget(ui.coreSessionContainer->count() - 1, + coreSessionWidget, 0, Qt::AlignTop); + connect(coreSessionWidget, SIGNAL(disconnectClicked(int)), this, SLOT(disconnectClicked(int))); + } + } + + for (const auto &key : ids) { + delete _widgets[key]; + _widgets.remove(key); + } + + ui.coreSessionScrollArea->setVisible(coreSessionSupported); +} + + +void CoreInfoDlg::updateUptime() { + CoreInfo *coreInfo = Client::coreInfo(); + if (coreInfo) { + QDateTime startTime = coreInfo->at("startTime").toDateTime(); + + int64_t uptime = startTime.secsTo(QDateTime::currentDateTime().toUTC()); + int64_t updays = uptime / 86400; + uptime %= 86400; + int64_t uphours = uptime / 3600; + uptime %= 3600; + int64_t upmins = uptime / 60; + uptime %= 60; + + QString uptimeText = tr("%n Day(s)", "", updays) + + tr(" %1:%2:%3 (since %4)") + .arg(uphours, 2, 10, QChar('0')) + .arg(upmins, 2, 10, QChar('0')) + .arg(uptime, 2, 10, QChar('0')) + .arg(startTime.toLocalTime().toString(Qt::TextDate)); + ui.labelUptime->setText(uptimeText); + } } -void CoreInfoDlg::coreInfoAvailable() { - ui.labelCoreVersion->setText(_coreInfo["quasselVersion"].toString()); - ui.labelUptime->setText(_coreInfo["startTime"].toString()); - ui.labelClientCount->setNum(_coreInfo["sessionConnectedClients"].toInt()); - // data["quasselBuildDate"] = Global::quasselBuildDate; +void CoreInfoDlg::disconnectClicked(int peerId) { + Client::kickClient(peerId); }