mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 14:43:09 +00:00
Fix panel clock from not respecting 12/24 hour settings
This commit is contained in:
parent
7f7bea091e
commit
cb72ee350d
3 changed files with 35 additions and 1 deletions
|
|
@ -205,7 +205,7 @@ Item {
|
||||||
|
|
||||||
PlasmaComponents.Label {
|
PlasmaComponents.Label {
|
||||||
id: clock
|
id: clock
|
||||||
property bool is24HourTime: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().indexOf("ap") === -1
|
property bool is24HourTime: plasmoid.nativeInterface.isSystem24HourFormat
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
text: Qt.formatTime(timeSource.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
|
text: Qt.formatTime(timeSource.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
#include <KConfigGroup>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDBusPendingReply>
|
#include <QDBusPendingReply>
|
||||||
|
|
@ -23,6 +24,8 @@
|
||||||
#include <QtConcurrent/QtConcurrent>
|
#include <QtConcurrent/QtConcurrent>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
|
#define FORMAT24H "HH:mm:ss"
|
||||||
|
|
||||||
constexpr int SCREENSHOT_DELAY = 200;
|
constexpr int SCREENSHOT_DELAY = 200;
|
||||||
|
|
||||||
/* -- Static Helpers --------------------------------------------------------------------------- */
|
/* -- Static Helpers --------------------------------------------------------------------------- */
|
||||||
|
|
@ -73,6 +76,19 @@ PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
|
||||||
//setHasConfigurationInterface(true);
|
//setHasConfigurationInterface(true);
|
||||||
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
|
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
|
||||||
m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
||||||
|
|
||||||
|
m_localeConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig);
|
||||||
|
m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig);
|
||||||
|
|
||||||
|
// watch for changes to locale config, to update 12/24 hour time
|
||||||
|
connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged,
|
||||||
|
this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
|
||||||
|
if (group.name() == "Locale") {
|
||||||
|
// we have to reparse for new changes (from system settings)
|
||||||
|
m_localeConfig->reparseConfiguration();
|
||||||
|
Q_EMIT isSystem24HourFormatChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
PhonePanel::~PhonePanel() = default;
|
PhonePanel::~PhonePanel() = default;
|
||||||
|
|
@ -183,6 +199,14 @@ void PhonePanel::takeScreenshot()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhonePanel::isSystem24HourFormat()
|
||||||
|
{
|
||||||
|
KConfigGroup localeSettings = KConfigGroup(m_localeConfig, "Locale");
|
||||||
|
|
||||||
|
QString timeFormat = localeSettings.readEntry("TimeFormat", QStringLiteral(FORMAT24H));
|
||||||
|
return timeFormat == QStringLiteral(FORMAT24H);
|
||||||
|
}
|
||||||
|
|
||||||
K_EXPORT_PLASMA_APPLET_WITH_JSON(quicksettings, PhonePanel, "metadata.json")
|
K_EXPORT_PLASMA_APPLET_WITH_JSON(quicksettings, PhonePanel, "metadata.json")
|
||||||
|
|
||||||
#include "phonepanel.moc"
|
#include "phonepanel.moc"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
#include <Plasma/Containment>
|
#include <Plasma/Containment>
|
||||||
|
|
||||||
|
#include <KSharedConfig>
|
||||||
|
#include <KConfigWatcher>
|
||||||
|
|
||||||
#include "kscreeninterface.h"
|
#include "kscreeninterface.h"
|
||||||
#include "screenshotinterface.h"
|
#include "screenshotinterface.h"
|
||||||
|
|
||||||
|
|
@ -18,6 +21,7 @@ class PhonePanel : public Plasma::Containment
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
|
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
|
||||||
Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged);
|
Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged);
|
||||||
|
Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged);
|
||||||
public:
|
public:
|
||||||
PhonePanel( QObject *parent, const QVariantList &args );
|
PhonePanel( QObject *parent, const QVariantList &args );
|
||||||
~PhonePanel() override;
|
~PhonePanel() override;
|
||||||
|
|
@ -32,13 +36,19 @@ public Q_SLOTS:
|
||||||
|
|
||||||
bool torchEnabled() const;
|
bool torchEnabled() const;
|
||||||
|
|
||||||
|
bool isSystem24HourFormat();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void autoRotateChanged(bool value);
|
void autoRotateChanged(bool value);
|
||||||
void torchChanged(bool value);
|
void torchChanged(bool value);
|
||||||
|
void isSystem24HourFormatChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_running = false;
|
bool m_running = false;
|
||||||
|
|
||||||
|
KConfigWatcher::Ptr m_localeConfigWatcher;
|
||||||
|
KSharedConfig::Ptr m_localeConfig;
|
||||||
|
|
||||||
org::kde::KScreen *m_kscreenInterface;
|
org::kde::KScreen *m_kscreenInterface;
|
||||||
org::kde::kwin::Screenshot *m_screenshotInterface;
|
org::kde::kwin::Screenshot *m_screenshotInterface;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue