From 27969b82809652a11bb67c23308b8465e8a2697a Mon Sep 17 00:00:00 2001 From: Reza Mousavi Date: Mon, 1 Apr 2024 08:21:24 +0330 Subject: [PATCH] add calendar persian day number feature --- .../calendar.js | 6 +++++- .../extension.js | 5 +++++ .../prefs.js | 16 ++++++++++++++++ ....shell.extensions.PersianCalendar.gschema.xml | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/persian-calendar@iamrezamousavi.gmail.com/calendar.js b/persian-calendar@iamrezamousavi.gmail.com/calendar.js index 51bfbfd..3c3cc52 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/calendar.js +++ b/persian-calendar@iamrezamousavi.gmail.com/calendar.js @@ -13,6 +13,7 @@ import {gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js' import {PersianDate} from './persianDate.js'; import {EventSource} from './eventSource.js'; import {getDayAccessibleName} from './utils/dateformat.js'; +import {toPersianDigit} from './utils/numbers.js'; const SHOW_WEEKDATE_KEY = 'show-weekdate'; @@ -78,6 +79,7 @@ export const Calendar = GObject.registerClass({ this.settings = settings; this.usePersianWeekday = this.settings.get_boolean('calendar-weekday-persian-number'); + this.usePersianDay = this.settings.get_boolean('calendar-day-persian-number'); this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.calendar'}); this._settings.connect(`changed::${SHOW_WEEKDATE_KEY}`, this._onSettingsChange.bind(this)); @@ -327,7 +329,9 @@ export const Calendar = GObject.registerClass({ while (row < nRows) { let button = new St.Button({ // xgettext:no-javascript-format - label: iter.getPersianDate().toString().replace(/\d/g, x => _(x)), + label: this.usePersianDay + ? toPersianDigit(iter.getPersianDate()) + : iter.getPersianDate().toString().replace(/\d/g, x => _(x)), can_focus: true, }); let rtl = button.get_text_direction() === Clutter.TextDirection.RTL; diff --git a/persian-calendar@iamrezamousavi.gmail.com/extension.js b/persian-calendar@iamrezamousavi.gmail.com/extension.js index 99bf01d..46ceec6 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/extension.js +++ b/persian-calendar@iamrezamousavi.gmail.com/extension.js @@ -67,6 +67,11 @@ export default class PersianCalendar extends Extension { this.enable(); }); + this.settings.connect('changed::calendar-day-persian-number', () => { + this.disable(); + this.enable(); + }); + this.settings.connect('changed::gregorian-events-active', () => { this.disable(); this.enable(); diff --git a/persian-calendar@iamrezamousavi.gmail.com/prefs.js b/persian-calendar@iamrezamousavi.gmail.com/prefs.js index 2971618..9befb1a 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/prefs.js +++ b/persian-calendar@iamrezamousavi.gmail.com/prefs.js @@ -102,6 +102,22 @@ export default class PersianCalendarPreferences extends ExtensionPreferences { persianWeekdayRow.add_suffix(persianWeekday); persianWeekdayRow.activatable_widget = persianWeekday; + const persianCalDayRow = new Adw.ActionRow({title: 'Use Persian Number in Calendar'}); + group.add(persianCalDayRow); + + const persianCalDay = new Gtk.Switch({ + active: settings.get_boolean('calendar-day-persian-number'), + valign: Gtk.Align.CENTER, + }); + settings.bind( + 'calendar-day-persian-number', + persianCalDay, + 'active', + Gio.SettingsBindFlags.DEFAULT + ); + persianCalDayRow.add_suffix(persianCalDay); + persianCalDayRow.activatable_widget = persianCalDay; + // Event Switchs const gregorianEventsRow = new Adw.ActionRow({title: 'Show Gregorian Events'}); group.add(gregorianEventsRow); diff --git a/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml b/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml index cee7a80..f250242 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml +++ b/persian-calendar@iamrezamousavi.gmail.com/schemas/org.gnome.shell.extensions.PersianCalendar.gschema.xml @@ -24,6 +24,10 @@ true Use persian digit in calendar weekday + + true + Use persian digit in calendar day + true Show Gregorian Events