Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@
"shadow": "Shadow",
"show-caps-lock": "Caps Lock Warning",
"show-device": "Show Device",
"show-events": "Show Events",
"show-forecast": "Show Forecast",
"show-keyboard-layout": "Keyboard Layout",
"show-label": "Show Label",
Expand All @@ -522,6 +523,7 @@
"show-vpn-label": "Show VPN Label",
"show-weather": "Weather",
"show-when-idle": "Show When Idle",
"show-week-numbers": "Show Week Numbers",
"stat": "Stat",
"stat-cpu-temp": "CPU Temp",
"stat-cpu-usage": "CPU Usage",
Expand Down Expand Up @@ -561,6 +563,7 @@
"types": {
"audio-visualizer": "Audio Visualizer",
"button": "Button",
"calendar": "Calendar",
"clock": "Clock",
"fancy-audio-visualizer": "Fancy Audio Visualizer",
"label": "Label",
Expand Down
3 changes: 3 additions & 0 deletions assets/translations/uk-UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,13 @@
"secondary-color": "Другорядний колір",
"sensitivity": "Чутливість",
"shadow": "Тінь",
"show-events": "Показувати події",
"show-forecast": "Показати прогноз погоди",
"show-keyboard-layout": "Розкладка клавіатури",
"show-label": "Показати мітку",
"show-login-button": "Кнопка підтвердження входу",
"show-when-idle": "Показувати, коли неактивний",
"show-week-numbers": "Показувати номери тижнів",
"stat": "Стан",
"stat-cpu-temp": "Температура CPU",
"stat-cpu-usage": "Використання CPU",
Expand Down Expand Up @@ -536,6 +538,7 @@
"types": {
"audio-visualizer": "Аудіовізуалізатор",
"button": "Кнопка",
"calendar": "Календар",
"clock": "Годинник",
"fancy-audio-visualizer": "Ефектний аудіовізуалізатор",
"label": "Мітка",
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ _noctalia_sources = files(
'src/shell/lockscreen/lockscreen_widgets_host.cpp',
'src/shell/desktop/widgets/desktop_audio_visualizer_widget.cpp',
'src/shell/desktop/widgets/desktop_button_widget.cpp',
'src/shell/desktop/widgets/desktop_calendar_widget.cpp',
'src/shell/desktop/widgets/desktop_clock_widget.cpp',
'src/shell/desktop/widgets/desktop_fancy_audio_visualizer_widget.cpp',
'src/shell/desktop/widgets/desktop_label_widget.cpp',
Expand Down
1 change: 1 addition & 0 deletions src/app/application_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ void Application::initWidgetControllersAndCallbacks() {
.configService = &m_configService,
};
const DesktopWidgetRuntimeServices desktopWidgetRuntime{
.calendar = &m_calendarService,
.pipewire = m_pipewireService.get(),
.pipewireSpectrum = m_pipewireSpectrum.get(),
.weather = &m_weatherService,
Expand Down
19 changes: 15 additions & 4 deletions src/calendar/calendar_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,25 @@ void CalendarService::retryCredentialMigration() {
});
}

void CalendarService::addChangeCallback(ChangeCallback callback) {
if (callback) {
m_callbacks.push_back(std::move(callback));
CalendarService::ChangeCallbackId CalendarService::addChangeCallback(ChangeCallback callback) {
if (!callback) {
return 0;
}
const ChangeCallbackId id = m_nextCallbackId++;
m_callbacks.emplace_back(id, std::move(callback));
return id;
}

void CalendarService::removeChangeCallback(ChangeCallbackId callbackId) {
if (callbackId == 0) {
return;
}
std::erase_if(m_callbacks, [callbackId](const auto& entry) { return entry.first == callbackId; });
}

void CalendarService::notifyChanged() {
for (auto& callback : m_callbacks) {
for (auto& [id, callback] : m_callbacks) {
(void)id;
if (callback) {
callback();
}
Expand Down
7 changes: 5 additions & 2 deletions src/calendar/calendar_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace security {
class CalendarService {
public:
using ChangeCallback = std::function<void()>;
using ChangeCallbackId = std::uint64_t;
enum class ConnectState : std::uint8_t { Idle, Pending, Success, Failed };
enum class CachePersistenceState : std::uint8_t {
Opening,
Expand Down Expand Up @@ -63,7 +64,8 @@ class CalendarService {
);

void initialize();
void addChangeCallback(ChangeCallback callback);
[[nodiscard]] ChangeCallbackId addChangeCallback(ChangeCallback callback);
void removeChangeCallback(ChangeCallbackId callbackId);
void setCredentialChangeCallback(ChangeCallback callback) { m_credentialChangeCallback = std::move(callback); }

[[nodiscard]] int pollTimeoutMs() const;
Expand Down Expand Up @@ -141,7 +143,8 @@ class CalendarService {
HttpClient& m_httpClient;
NotificationManager* m_notifications = nullptr;
CalendarConfig m_activeConfig;
std::vector<ChangeCallback> m_callbacks;
std::vector<std::pair<ChangeCallbackId, ChangeCallback>> m_callbacks;
ChangeCallbackId m_nextCallbackId = 1;
ChangeCallback m_credentialChangeCallback;

calendar::GoogleOAuthBroker m_oauth;
Expand Down
2 changes: 1 addition & 1 deletion src/shell/control_center/tabs/calendar_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ std::unique_ptr<Flex> CalendarTab::create() {

if (m_calendar != nullptr && !m_changeCallbackRegistered) {
m_changeCallbackRegistered = true;
m_calendar->addChangeCallback([this]() {
(void)m_calendar->addChangeCallback([this]() {
m_eventsDirty = true;
PanelManager::instance().refresh();
});
Expand Down
20 changes: 17 additions & 3 deletions src/shell/desktop/desktop_widget_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "scripting/plugin_runtime_context.h"
#include "shell/desktop/widgets/desktop_audio_visualizer_widget.h"
#include "shell/desktop/widgets/desktop_button_widget.h"
#include "shell/desktop/widgets/desktop_calendar_widget.h"
#include "shell/desktop/widgets/desktop_clock_widget.h"
#include "shell/desktop/widgets/desktop_fancy_audio_visualizer_widget.h"
#include "shell/desktop/widgets/desktop_label_widget.h"
Expand Down Expand Up @@ -182,13 +183,26 @@ namespace {
} // namespace

DesktopWidgetFactory::DesktopWidgetFactory(DesktopWidgetRuntimeServices services)
: m_pipewire(services.pipewire), m_pipewireSpectrum(services.pipewireSpectrum), m_weather(services.weather),
m_mpris(services.mpris), m_httpClient(services.httpClient), m_sysmon(services.sysmon),
m_scriptDeps(services.scriptDeps) {}
: m_calendar(services.calendar), m_pipewire(services.pipewire), m_pipewireSpectrum(services.pipewireSpectrum),
m_weather(services.weather), m_mpris(services.mpris), m_httpClient(services.httpClient),
m_sysmon(services.sysmon), m_scriptDeps(services.scriptDeps) {}

std::unique_ptr<DesktopWidget> DesktopWidgetFactory::create(
const std::string& type, const std::unordered_map<std::string, WidgetSettingValue>& settings, float contentScale
) const {
if (type == "calendar") {
auto widget = std::make_unique<DesktopCalendarWidget>(
m_scriptDeps.configService, m_calendar,
DesktopCalendarWidget::Options{
.showEvents = getBoolSetting(settings, "show_events", true),
.showWeekNumbers = getBoolSetting(settings, "show_week_numbers", false),
}
);
applyCommonSettings(*widget, settings);
widget->setContentScale(contentScale);
return widget;
}

if (type == "clock") {
const std::string styleSetting = getStringSetting(settings, "clock_style", "digital");
const DesktopClockWidget::Style style =
Expand Down
2 changes: 2 additions & 0 deletions src/shell/desktop/desktop_widget_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <unordered_map>

class HttpClient;
class CalendarService;
class MprisService;
class SystemMonitorService;
class PipeWireService;
Expand All @@ -24,6 +25,7 @@ class DesktopWidgetFactory {
) const;

private:
CalendarService* m_calendar = nullptr;
PipeWireService* m_pipewire = nullptr;
PipeWireSpectrum* m_pipewireSpectrum = nullptr;
const WeatherService* m_weather = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions src/shell/desktop/desktop_widget_services.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

class ClipboardService;
class CalendarService;
class ConfigService;
class FileWatcher;
class HttpClient;
Expand All @@ -27,6 +28,7 @@ struct DesktopWidgetScriptDeps {
};

struct DesktopWidgetRuntimeServices {
CalendarService* calendar = nullptr;
PipeWireService* pipewire = nullptr;
PipeWireSpectrum* pipewireSpectrum = nullptr;
const WeatherService* weather = nullptr;
Expand Down
7 changes: 6 additions & 1 deletion src/shell/desktop/desktop_widget_settings_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace desktop_settings {
const std::vector<DesktopWidgetTypeSpec> kDesktopWidgetTypeSpecs = {
{.type = "audio_visualizer", .labelKey = "desktop-widgets.editor.types.audio-visualizer"},
{.type = "button", .labelKey = "desktop-widgets.editor.types.button"},
{.type = "calendar", .labelKey = "desktop-widgets.editor.types.calendar"},
{.type = "clock", .labelKey = "desktop-widgets.editor.types.clock"},
{.type = "fancy_audio_visualizer", .labelKey = "desktop-widgets.editor.types.fancy-audio-visualizer"},
{.type = "label", .labelKey = "desktop-widgets.editor.types.label"},
Expand Down Expand Up @@ -240,7 +241,11 @@ namespace desktop_settings {
std::vector<WidgetSettingSpec> specs;
auto add = [&](WidgetSettingSpec spec) { specs.push_back(std::move(spec)); };

if (type == "clock") {
if (type == "calendar") {
add(boolSpec("show_events", true));
add(boolSpec("show_week_numbers", false));
add(fontFamilySpec());
} else if (type == "clock") {
const WidgetSettingVisibility digitalOnly{{"clock_style", {"digital"}}};
const WidgetSettingVisibility analogOnly{{"clock_style", {"analog"}}};
add(segmentedSpec(
Expand Down
Loading