Skip to content

Commit

Permalink
add calendar persian day number feature
Browse files Browse the repository at this point in the history
  • Loading branch information
IamRezaMousavi committed Apr 1, 2024
1 parent 9474b65 commit 27969b8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion [email protected]/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<default>true</default>
<summary>Use persian digit in calendar weekday</summary>
</key>
<key name="calendar-day-persian-number" type="b">
<default>true</default>
<summary>Use persian digit in calendar day</summary>
</key>
<key name="gregorian-events-active" type="b">
<default>true</default>
<summary>Show Gregorian Events</summary>
Expand Down

0 comments on commit 27969b8

Please sign in to comment.