+ 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);
+
+ // Hide the information bar when core sessions are supported or when disconnected
+ ui.coreUnsupportedWidget->setVisible(
+ !(coreSessionSupported || Client::isConnected() == false));
+
+ // Update uptime for immediate display, don't wait for the timer
+ updateUptime();
+}
+
+
+void CoreInfoDlg::updateUptime() {
+ CoreInfo *coreInfo = Client::coreInfo();
+
+ if (!Client::isConnected()) {
+ // Not connected, don't bother trying to calculate the uptime
+ ui.labelUptime->setText(tr("Not available"));
+ } else if (coreInfo->coreData().isEmpty()) {
+ // Core info is entirely empty despite being connected. Something's probably wrong.
+ ui.labelUptime->setText(tr("Unknown"));
+ } else {
+ // Connected, format the uptime for display
+ 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::disconnectClicked(int peerId) {
+ Client::kickClient(peerId);
+}
+
+void CoreInfoDlg::on_coreUnsupportedDetails_clicked()
+{
+ QMessageBox::warning(this,
+ tr("Active sessions unsupported"),
+ QString("<p><b>%1</b></p></br><p>%2</p>"
+ ).arg(tr("Your Quassel core is too old to show active sessions"),
+ tr("You need a Quassel core v0.13.0 or newer to view and "
+ "disconnect other connected clients.")));