From 9474b65e1b3c0ce155a8d5957f9bed6ed1c756fb Mon Sep 17 00:00:00 2001 From: Reza Mousavi Date: Mon, 1 Apr 2024 08:08:13 +0330 Subject: [PATCH 1/2] add persian weekdays feature --- .../calendar.js | 21 ++++++++++++++----- .../dateMenu.js | 4 ++-- .../extension.js | 7 ++++++- .../prefs.js | 20 ++++++++++++++++-- ...ell.extensions.PersianCalendar.gschema.xml | 6 +++++- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/persian-calendar@iamrezamousavi.gmail.com/calendar.js b/persian-calendar@iamrezamousavi.gmail.com/calendar.js index 54df415..51bfbfd 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/calendar.js +++ b/persian-calendar@iamrezamousavi.gmail.com/calendar.js @@ -37,7 +37,7 @@ function _isWorkDay(date) { return !days.includes(date.getDay().toString()); } -function _getCalendarDayAbbreviation(dayNumber) { +function _getCalendarDayAbbreviation(dayNumber, isPersian) { let abbreviations = [ /* Translators: Calendar grid abbreviation for Sunday. * @@ -57,18 +57,29 @@ function _getCalendarDayAbbreviation(dayNumber) { NC_('grid friday', 'F'), /* Translators: Calendar grid abbreviation for Saturday */ NC_('grid saturday', 'S'), + + 'ی', + 'د', + 'س', + 'چ', + 'پ', + 'ج', + 'ش', ]; - return Shell.util_translate_time_string(abbreviations[dayNumber]); + return isPersian ? abbreviations[dayNumber + 7] : Shell.util_translate_time_string(abbreviations[dayNumber]); } export const Calendar = GObject.registerClass({ Signals: {'selected-date-changed': {param_types: [GLib.DateTime.$gtype]}}, }, class Calendar extends St.Widget { - _init() { + _init(settings) { // this._weekStart = Shell.util_get_week_start(); this._weekStart = 6; - this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.calendar'}); + this.settings = settings; + this.usePersianWeekday = this.settings.get_boolean('calendar-weekday-persian-number'); + + this._settings = new Gio.Settings({schema_id: 'org.gnome.desktop.calendar'}); this._settings.connect(`changed::${SHOW_WEEKDATE_KEY}`, this._onSettingsChange.bind(this)); this._useWeekdate = this._settings.get_boolean(SHOW_WEEKDATE_KEY); @@ -178,7 +189,7 @@ export const Calendar = GObject.registerClass({ for (let i = 0; i < 7; i++) { // Could use iter.toLocaleFormat('%a') but that normally gives three characters // and we want, ideally, a single character for e.g. S M T W T F S - let customDayAbbrev = _getCalendarDayAbbreviation(iter.getDay()); + let customDayAbbrev = _getCalendarDayAbbreviation(iter.getDay(), this.usePersianWeekday); let label = new St.Label({ style_class: 'calendar-day-heading', text: customDayAbbrev, diff --git a/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js b/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js index a20cddc..37f5d96 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js +++ b/persian-calendar@iamrezamousavi.gmail.com/dateMenu.js @@ -274,7 +274,7 @@ class DateMenuButton extends PanelMenu.Button { hbox = new St.BoxLayout({name: 'calendarArea'}); bin.add_child(hbox); - this._calendar = new Calendar(); + this._calendar = new Calendar(settings); this._calendar.connect('selected-date-changed', (_calendar, datetime) => { let date = _gDateTimeToDate(datetime); this._eventsItem.setDate(date); @@ -346,7 +346,7 @@ class DateMenuButton extends PanelMenu.Button { _updateCalendarDisplay() { let displayFormat = this.settings.get_string('panel-format'); - let usePersianDigit = this.settings.get_boolean('number-to-persian'); + let usePersianDigit = this.settings.get_boolean('top-panel-persian-number'); let date = new PersianDate(); this._calendarDisplay.set_text( usePersianDigit diff --git a/persian-calendar@iamrezamousavi.gmail.com/extension.js b/persian-calendar@iamrezamousavi.gmail.com/extension.js index b837c1e..99bf01d 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/extension.js +++ b/persian-calendar@iamrezamousavi.gmail.com/extension.js @@ -57,7 +57,12 @@ export default class PersianCalendar extends Extension { this.enable(); }); - this.settings.connect('changed::number-to-persian', () => { + this.settings.connect('changed::top-panel-persian-number', () => { + this.disable(); + this.enable(); + }); + + this.settings.connect('changed::calendar-weekday-persian-number', () => { this.disable(); this.enable(); }); diff --git a/persian-calendar@iamrezamousavi.gmail.com/prefs.js b/persian-calendar@iamrezamousavi.gmail.com/prefs.js index f1045ae..2971618 100644 --- a/persian-calendar@iamrezamousavi.gmail.com/prefs.js +++ b/persian-calendar@iamrezamousavi.gmail.com/prefs.js @@ -74,11 +74,11 @@ export default class PersianCalendarPreferences extends ExtensionPreferences { group.add(toPersianRow); const toPersian = new Gtk.Switch({ - active: settings.get_boolean('number-to-persian'), + active: settings.get_boolean('top-panel-persian-number'), valign: Gtk.Align.CENTER, }); settings.bind( - 'number-to-persian', + 'top-panel-persian-number', toPersian, 'active', Gio.SettingsBindFlags.DEFAULT @@ -86,6 +86,22 @@ export default class PersianCalendarPreferences extends ExtensionPreferences { toPersianRow.add_suffix(toPersian); toPersianRow.activatable_widget = toPersian; + const persianWeekdayRow = new Adw.ActionRow({title: 'Use Persian Weekday'}); + group.add(persianWeekdayRow); + + const persianWeekday = new Gtk.Switch({ + active: settings.get_boolean('calendar-weekday-persian-number'), + valign: Gtk.Align.CENTER, + }); + settings.bind( + 'calendar-weekday-persian-number', + persianWeekday, + 'active', + Gio.SettingsBindFlags.DEFAULT + ); + persianWeekdayRow.add_suffix(persianWeekday); + persianWeekdayRow.activatable_widget = persianWeekday; + // 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 b659746..cee7a80 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 @@ -16,10 +16,14 @@ "d mmmm yyyy" Panel date format - + true Use persian digit in top panel + + true + Use persian digit in calendar weekday + true Show Gregorian Events From 27969b82809652a11bb67c23308b8465e8a2697a Mon Sep 17 00:00:00 2001 From: Reza Mousavi Date: Mon, 1 Apr 2024 08:21:24 +0330 Subject: [PATCH 2/2] 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