Fix start/stop button tooltip for system-wide systemd service

This commit is contained in:
Martchus 2020-02-02 19:51:16 +01:00
parent a9abeea8e3
commit 94753de797
6 changed files with 27 additions and 7 deletions

View File

@ -282,6 +282,9 @@ void SyncthingService::setScopeAndUnitName(SystemdScope scope, const QString &un
if (!unitName.isEmpty()) {
queryUnitFromSystemdInterface();
}
if (scopeChanged) {
emit this->scopeChanged(scope);
}
if (unitNameChanged) {
emit this->unitNameChanged(unitName);
}
@ -344,6 +347,7 @@ void SyncthingService::setScope(SystemdScope scope)
m_scope = scope;
clearSystemdInterface();
queryUnitFromSystemdInterface();
emit scopeChanged(scope);
}
/*!

View File

@ -50,7 +50,8 @@ class LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingService : public QObject {
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
Q_PROPERTY(bool enable READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool manuallyStopped READ isManuallyStopped)
Q_PROPERTY(SystemdScope scope READ scope WRITE setScope)
Q_PROPERTY(SystemdScope scope READ scope WRITE setScope NOTIFY scopeChanged)
Q_PROPERTY(bool userScope READ isUserScope NOTIFY scopeChanged)
public:
explicit SyncthingService(SystemdScope scope = SystemdScope::User, QObject *parent = nullptr);
@ -73,6 +74,7 @@ public:
SystemdScope scope() const;
void setScope(SystemdScope scope);
void setScopeAndUnitName(SystemdScope scope, const QString &unitName);
bool isUserScope() const;
static SyncthingService *mainInstance();
static void setMainInstance(SyncthingService *mainInstance);
@ -98,6 +100,7 @@ Q_SIGNALS:
void runningChanged(bool running);
void enabledChanged(bool enable);
void errorOccurred(const QString &context, const QString &name, const QString &message);
void scopeChanged(SystemdScope scope);
private Q_SLOTS:
void handleUnitAdded(const QString &unitName, const QDBusObjectPath &unitPath);
@ -250,6 +253,14 @@ inline SystemdScope SyncthingService::scope() const
return m_scope;
}
/*!
* \brief Returns whether the scope is SystemdScope::User.
*/
inline bool SyncthingService::isUserScope() const
{
return m_scope == SystemdScope::User;
}
/*!
* \brief Returns since when the unit is active.
*/

View File

@ -247,7 +247,7 @@ ColumnLayout {
target: startStopButton
visible: true
text: qsTr("Stop")
tooltip: "systemctl --user stop "
tooltip: (plasmoid.nativeInterface.service.userScope ? "systemctl --user stop " : "systemctl stop ")
+ plasmoid.nativeInterface.service.unitName
iconSource: "process-stop"
}
@ -258,7 +258,7 @@ ColumnLayout {
target: startStopButton
visible: true
text: qsTr("Start")
tooltip: "systemctl --user start "
tooltip: (plasmoid.nativeInterface.service.userScope ? "systemctl --user start " : "systemctl start ")
+ plasmoid.nativeInterface.service.unitName
iconSource: "system-run"
}

View File

@ -731,12 +731,16 @@ Settings::Systemd::ServiceStatus TrayWidget::applySystemdSettings(bool reconnect
m_startStopButtonTarget = StartStopButtonTarget::Service;
if (serviceStatus.running) {
m_ui->startStopPushButton->setText(tr("Stop"));
m_ui->startStopPushButton->setToolTip(QStringLiteral("systemctl --user stop ") + systemdSettings.syncthingUnit);
m_ui->startStopPushButton->setToolTip(
(serviceStatus.userService ? QStringLiteral("systemctl --user stop ") : QStringLiteral("systemctl stop "))
+ systemdSettings.syncthingUnit);
m_ui->startStopPushButton->setIcon(
QIcon::fromTheme(QStringLiteral("process-stop"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/process-stop.svg"))));
} else {
m_ui->startStopPushButton->setText(tr("Start"));
m_ui->startStopPushButton->setToolTip(QStringLiteral("systemctl --user start ") + systemdSettings.syncthingUnit);
m_ui->startStopPushButton->setToolTip(
(serviceStatus.userService ? QStringLiteral("systemctl --user start ") : QStringLiteral("systemctl start "))
+ systemdSettings.syncthingUnit);
m_ui->startStopPushButton->setIcon(
QIcon::fromTheme(QStringLiteral("system-run"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/system-run.svg"))));
}

View File

@ -500,7 +500,7 @@ Systemd::ServiceStatus Systemd::apply(
const auto consideredForReconnect = considerForReconnect && isRelevant && unitAvailable;
connectAccordingToSettings(
connection, currentConnectionSettings, *service, reconnectRequired, considerForReconnect, isRelevant, isRunning, consideredForReconnect);
return ServiceStatus{ isRelevant, isRunning, consideredForReconnect, showButton && isRelevant };
return ServiceStatus{ isRelevant, isRunning, consideredForReconnect, showButton && isRelevant, service->isUserScope() };
}
/*!
@ -513,7 +513,7 @@ Systemd::ServiceStatus Systemd::status(SyncthingConnection &connection) const
return ServiceStatus{};
}
const auto isRelevant = service->isSystemdAvailable() && connection.isLocal();
return ServiceStatus{ isRelevant, service->isRunning(), considerForReconnect && isRelevant, showButton && isRelevant };
return ServiceStatus{ isRelevant, service->isRunning(), considerForReconnect && isRelevant, showButton && isRelevant, service->isUserScope() };
}
#endif

View File

@ -113,6 +113,7 @@ struct SYNCTHINGWIDGETS_EXPORT Systemd {
bool running = false;
bool consideredForReconnect = false;
bool showStartStopButton = false;
bool userService = true;
};
void setupService(Data::SyncthingService &) const;
ServiceStatus apply(Data::SyncthingConnection &connection, const Data::SyncthingConnectionSettings *currentConnectionSettings,