X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoreinfodlg.cpp;h=b1759776bc6b69dd62fece41287caa015924caaa;hp=e5eb7f4c62bd8ab8ca2b211eb57025e7a602c421;hb=c013d415d0e6e85cbb8c0adba9ded53bbcf4f36c;hpb=bd5414d8bfe2be18ba051d4bbf936e9ead0cdf66 diff --git a/src/qtui/coreinfodlg.cpp b/src/qtui/coreinfodlg.cpp index e5eb7f4c..b1759776 100644 --- a/src/qtui/coreinfodlg.cpp +++ b/src/qtui/coreinfodlg.cpp @@ -20,25 +20,90 @@ #include "coreinfodlg.h" -#include "client.h" +#include + #include "bufferwidget.h" +#include "client.h" +#include "icon.h" +#include "util.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()); + // Listen for resynchronization events (pre-0.13 cores only) + connect(Client::instance(), SIGNAL(coreInfoResynchronized()), + this, SLOT(coreInfoResynchronized())); + + // Update legacy core info for Quassel cores earlier than 0.13. This does nothing on modern + // cores. + refreshLegacyCoreInfo(); + + // Display existing core info, set up signal handlers + coreInfoResynchronized(); + + // Warning icon + ui.coreUnsupportedIcon->setPixmap(icon::get("dialog-warning").pixmap(16)); updateUptime(); startTimer(1000); } +void CoreInfoDlg::refreshLegacyCoreInfo() { + if (!Client::isConnected() || Client::isCoreFeatureEnabled(Quassel::Feature::SyncedCoreInfo)) { + // If we're not connected, or the core supports SyncedCoreInfo (0.13+), bail out + return; + } + + // Request legacy (pre-0.13) CoreInfo object to be resynchronized (does nothing on modern cores) + Client::refreshLegacyCoreInfo(); + + // On legacy cores, CoreInfo data does not send signals. Periodically poll for information. + // 15 seconds seems like a reasonable trade-off as this only happens while the dialog is open. + QTimer::singleShot(15 * 1000, this, SLOT(refreshLegacyCoreInfo())); +} + + +void CoreInfoDlg::coreInfoResynchronized() { + // CoreInfo object has been recreated, or this is the first time the dialog's been shown + + CoreInfo *coreInfo = Client::coreInfo(); + // Listen for changes to core information + connect(coreInfo, SIGNAL(coreDataChanged(const QVariantMap &)), + this, SLOT(coreInfoChanged(const QVariantMap &))); + + // Update with any known core information set before connecting the signal. This is needed for + // both modern (0.13+) and legacy cores. + coreInfoChanged(coreInfo->coreData()); +} + + 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()); + if(coreInfo.isEmpty()) { + // We're missing data for some reason + if (Client::isConnected()) { + // Core info is entirely empty despite being connected. Something's probably wrong. + ui.labelCoreVersion->setText(tr("Unknown")); + ui.labelCoreVersionDate->setText(tr("Unknown")); + } else { + // We're disconnected. Mark as such. + ui.labelCoreVersion->setText(tr("Disconnected from core")); + ui.labelCoreVersionDate->setText(tr("Not available")); + } + ui.labelClientCount->setNum(0); + // Don't return, allow the code below to remove any existing session widgets + } else { + ui.labelCoreVersion->setText(coreInfo["quasselVersion"].toString()); + // "BuildDate" for compatibility + if (coreInfo["quasselBuildDate"].toString().isEmpty()) { + ui.labelCoreVersionDate->setText(QString("%1").arg(tr("Unknown date"))); + } + else { + ui.labelCoreVersionDate->setText( + tryFormatUnixEpoch(coreInfo["quasselBuildDate"].toString())); + } + ui.labelClientCount->setNum(coreInfo["sessionConnectedClients"].toInt()); + } auto coreSessionSupported = false; auto ids = _widgets.keys(); @@ -59,7 +124,10 @@ void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) { coreSessionWidget->setData(peerMap); if (isNew) { _widgets[peerId] = coreSessionWidget; - ui.coreSessionContainer->addWidget(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))); } } @@ -70,13 +138,27 @@ void CoreInfoDlg::coreInfoChanged(const QVariantMap &coreInfo) { } ui.coreSessionScrollArea->setVisible(coreSessionSupported); - ui.coreSessionContainer->addStretch(1); + + // 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 (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()); @@ -100,3 +182,13 @@ void CoreInfoDlg::updateUptime() { void CoreInfoDlg::disconnectClicked(int peerId) { Client::kickClient(peerId); } + +void CoreInfoDlg::on_coreUnsupportedDetails_clicked() +{ + QMessageBox::warning(this, + tr("Active sessions unsupported"), + QString("

%1


%2

" + ).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."))); +}