From de64f8e332507744be3d010ab88db8b775fd5b46 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 29 Jul 2023 12:12:30 +0300 Subject: [PATCH] libs: drop the automatic update feature of Plasma::Calendar only Plasma::ClockApplet uses the Plasma::Calendar class and it disables automatic updates (because the date comes from data engine). also due to 7819796c556a94ad57ef9a126cab072e247658bd the date is updated once a second which was updating the currently selected date thus interfering with date selection every second so the check that was removed in d7d63a156bc0b49bbc27b80b5e38ced429470127 had to be brought back Signed-off-by: Ivailo Monev --- libs/plasmaclock/calendar.cpp | 29 ++++------------------------- libs/plasmaclock/calendar.h | 1 - libs/plasmaclock/clockapplet.cpp | 13 +++++-------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/libs/plasmaclock/calendar.cpp b/libs/plasmaclock/calendar.cpp index d8f8d015..bfdf6555 100644 --- a/libs/plasmaclock/calendar.cpp +++ b/libs/plasmaclock/calendar.cpp @@ -70,8 +70,7 @@ class CalendarPrivate : q(calendar), calendarWidget(nullptr), layout(nullptr), - currentDate(QDate::currentDate()), - automaticUpdates(true) + currentDate(QDate::currentDate()) { } @@ -83,7 +82,6 @@ class CalendarPrivate Plasma::CalendarWidget *calendarWidget; QGraphicsLinearLayout *layout; QDate currentDate; - bool automaticUpdates; }; Calendar::Calendar(const QDate &date, QGraphicsWidget *parent) @@ -122,30 +120,12 @@ void CalendarPrivate::init(const QDate &initialDate) updateSize(); } -void Calendar::showEvent(QShowEvent * event) -{ - if (d->automaticUpdates) { - d->currentDate = QDate::currentDate(); - } - QGraphicsWidget::showEvent(event); -} - void Calendar::focusInEvent(QFocusEvent* event) { Q_UNUSED(event); d->calendarWidget->setFocus(); } -void Calendar::setAutomaticUpdateEnabled(bool automatic) -{ - d->automaticUpdates = automatic; -} - -bool Calendar::isAutomaticUpdateEnabled() const -{ - return d->automaticUpdates; -} - void Calendar::setDate(const QDate &toDate) { // New date must be valid one @@ -156,10 +136,9 @@ void Calendar::setDate(const QDate &toDate) return; } - // NOTE: this method is called by Plasma::ClockApplet::popupEvent() on show so updating as if - // show event ocurred - if (d->automaticUpdates) { - d->currentDate = QDate::currentDate(); + // If new date is the same as old date don't actually need to do anything + if (toDate == d->currentDate) { + return; } d->calendarWidget->setSelectedDate(toDate); diff --git a/libs/plasmaclock/calendar.h b/libs/plasmaclock/calendar.h index ae096dfe..3c3ec8b1 100644 --- a/libs/plasmaclock/calendar.h +++ b/libs/plasmaclock/calendar.h @@ -57,7 +57,6 @@ Q_SIGNALS: void dateChanged(const QDate &newDate); protected: - void showEvent(QShowEvent * event); void focusInEvent(QFocusEvent* event); private Q_SLOTS: diff --git a/libs/plasmaclock/clockapplet.cpp b/libs/plasmaclock/clockapplet.cpp index 780026d0..b99788d5 100644 --- a/libs/plasmaclock/clockapplet.cpp +++ b/libs/plasmaclock/clockapplet.cpp @@ -124,7 +124,6 @@ public: if (q->config().readEntry("ShowCalendarPopup", true)) { if (!calendarWidget) { calendarWidget = new Plasma::Calendar(); - calendarWidget->setAutomaticUpdateEnabled(false); calendarWidget->setFlag(QGraphicsItem::ItemIsFocusable); } } else { @@ -257,12 +256,7 @@ void ClockApplet::updateClockApplet() void ClockApplet::updateClockApplet(const Plasma::DataEngine::Data &data) { if (d->calendarWidget) { - bool updateSelectedDate = (d->calendarWidget->currentDate() == d->calendarWidget->date()); - d->calendarWidget->setCurrentDate(data["Date"].toDate()); - - if (updateSelectedDate){ - d->calendarWidget->setDate(d->calendarWidget->currentDate()); - } + d->calendarWidget->setDate(data["Date"].toDate()); } d->lastTimeSeen = data["Time"].toTime(); @@ -506,7 +500,10 @@ void ClockApplet::popupEvent(bool show) { if (show && d->calendarWidget) { Plasma::DataEngine::Data data = dataEngine("time")->query(currentTimezone()); - d->calendarWidget->setDate(data["Date"].toDate()); + const QDate date = data["Date"].toDate(); + d->calendarWidget->setCurrentDate(date.addDays(-1)); + d->calendarWidget->setDate(date); + d->calendarWidget->setCurrentDate(date); } }