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
588 changes: 588 additions & 0 deletions PersianCalendar@oxygenws.com/PrayTimes.js

Large diffs are not rendered by default.

64 changes: 63 additions & 1 deletion PersianCalendar@oxygenws.com/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const convenience = extension.imports.convenience;

const PersianDate = extension.imports.PersianDate;
const HijriDate = extension.imports.HijriDate;
const PrayTimes = extension.imports.PrayTimes.prayTimes;
const player = extension.imports.sound.player;

const str = extension.imports.strFunctions;
const Events = extension.imports.Events;
Expand Down Expand Up @@ -45,7 +47,7 @@ Calendar.prototype = {
});

this.actor.connect('scroll-event', Lang.bind(this, this._onScroll));

PrayTimes.setMethod('Tehran');
this._buildHeader();
},

Expand Down Expand Up @@ -421,6 +423,57 @@ Calendar.prototype = {
}));
}

if(Schema.get_boolean('praytime-visible'))
{
let _prayBox_v = new St.BoxLayout({style_class: 'button pcalendar-praytimes-container', vertical: true, x_expand: true});

let _prayTimes = PrayTimes.getTimes(g_selectedDate, [Schema.get_double('praytime-lat') , Schema.get_double('praytime-lng')], Schema.get_double('praytime-timezone'));

let i=0;
let _prayColumnBox = new St.BoxLayout({style_class: 'pcalendar-praytimes-box', x_expand: true});
for(let key in _prayTimes)
{

_prayColumnBox.add(new St.Label({
text: str.format(_prayTimes[key]),
style_class: 'pcalendar-praytimes-item pcalendar-praytimes-time',
x_expand: true,
}));


_prayColumnBox.add(new St.Label({
text: PrayTimes.persianMap[key],
style_class: 'pcalendar-praytimes-item pcalendar-praytimes-key',
x_expand: true,
}));

if( ++i % 2 === 0)
{
_prayBox_v.add(_prayColumnBox);
_prayColumnBox = new St.BoxLayout({style_class: 'pcalendar-praytimes-box', x_expand: true});
}

}

this.actor.layout_manager.attach(_prayBox_v, 0, ++row, 7, i-1);
row+=i;
if(player.isPlaying())
{
let btn = new St.Button({label: 'توقف پخش اذان', style_class : 'button pcalendar-praytimes-azan'});
btn.connect('clicked',Lang.bind(btn, function(){
player.pause();
}));
this.actor.layout_manager.attach(btn, 0, ++row, 7, 1);
}


// let _label = new St.Label();
// _label.set_text(_textBuilder.join('\n'));
// _prayBox_h.add(_label, {expand: true, x_fill: true, x_align: St.Align.MIDDLE});
// {"imsak":"04:43","fajr":"04:53","sunrise":"06:16","dhuhr":"12:14","asr":"15:37","sunset":"18:11","maghrib":"18:29","isha":"19:16","midnight":"23:32"}
}


// add event box for selected date
events = ev.getEvents(g_selectedDate);

Expand All @@ -437,5 +490,14 @@ Calendar.prototype = {
bottomLabel.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
_eventBox.add(bottomLabel, {expand: true, x_fill: true, y_fill: true, x_align: St.Align.MIDDLE});
}
},

checkPrayTime: function(){
let now = new Date();
if(now.getSeconds() >= 3 || !Schema.get_boolean('praytime-play')) return;
let _prayTimes = PrayTimes.getTimes(now, [Schema.get_double('praytime-lat') , Schema.get_double('praytime-lng')], Schema.get_double('praytime-timezone'));
now = now.getHours() + ':' + now.getMinutes();
if([_prayTimes.fajr,_prayTimes.dhuhr,_prayTimes.maghrib].includes(now))
player.setVolume(1);
}
};
12 changes: 12 additions & 0 deletions PersianCalendar@oxygenws.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ const PersianCalendar = new Lang.Class({
that._calendar.setDate(now);
}
}));

this._prayerTimeLoop();
},

_updateDate: function (skip_notification, force) {
Expand Down Expand Up @@ -277,6 +279,15 @@ const PersianCalendar = new Lang.Class({
return true;
},

_prayerTimeLoop: function(){
if (this._prayerTimeout) {
MainLoop.source_remove(this._prayerTimeout);
this._prayerTimeout = null;
}
this._prayerTimeout = MainLoop.timeout_add(60000 - (new Date().getSeconds() * 1000), Lang.bind(this,this._prayerTimeLoop));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove this in the "disable" function.
And I would suggest adding it to the "enable" function.

Another suggestion is to ignore adding timeout when the feature is disabled.

this._calendar.checkPrayTime();
},

_generateConverterPart: function () {
// Add date conversion button
let converterMenu = new PopupMenu.PopupSubMenuMenuItem('تبدیل تاریخ');
Expand Down Expand Up @@ -533,6 +544,7 @@ function enable() {
_indicator._updateDate(!Schema.get_boolean('startup-notification'));
_timer = MainLoop.timeout_add(3000, Lang.bind(_indicator, _indicator._updateDate));


// install fonts
let path = extension.dir.get_path();
GLib.spawn_sync(
Expand Down
46 changes: 46 additions & 0 deletions PersianCalendar@oxygenws.com/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ const App = new Lang.Class({
this.vbox2.add(item);
Schema.bind('event-world', item, 'active', Gio.SettingsBindFlags.DEFAULT);

//PrayTimes
this.vbox2.add(new Gtk.Label({
label: _('PrayTime:\n<span size="x-small">("PrayTime" based on geographical location)</span>'),
use_markup: true
}));
item = new Gtk.CheckButton({label: _('Show Pray Time')});
this.vbox2.add(item);
Schema.bind('praytime-visible', item, 'active', Gio.SettingsBindFlags.DEFAULT);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please disable this and Azaan options, by default.


item = new Gtk.CheckButton({label: _('Play Azaan')});
this.vbox2.add(item);
Schema.bind('praytime-play', item, 'active', Gio.SettingsBindFlags.DEFAULT);


let _item = this.createTextEntry('praytime-lat', 'Latitude: ');
this.vbox2.add(_item.hbox);
if(_item.comment) this.vbox2.add(_item.comment);

_item = this.createTextEntry('praytime-lng', 'Longitude: ');
this.vbox2.add(_item.hbox);
if(_item.comment) this.vbox2.add(_item.comment);

_item = this.createTextEntry('praytime-timezone', 'Timezone: ');
this.vbox2.add(_item.hbox);
if(_item.comment) this.vbox2.add(_item.comment);


// COLOR
this.vbox3.add(new Gtk.Label({label: _('Widget Properties:')}));

Expand Down Expand Up @@ -194,6 +221,25 @@ const App = new Lang.Class({

this.main_hbox.show_all();
},
createTextEntry: function(value, labelText, commentText){
let label = new Gtk.Label({label: labelText});
let format = new Gtk.Entry();
let hbox = new Gtk.HBox();
hbox.add(label);
hbox.add(format);
let comment = null;
if(commentText)
comment = new Gtk.Label({
label: _(commentText),
use_markup: true
});
format.set_text(Schema.get_double(value).toString());
format.connect('changed', function (innerFormat) {
Schema.set_string(value, innerFormat.text);
});

return {hbox:hbox,comment:comment};
},

_scaleRound: function (value) {
// Based on gtk/gtkcoloreditor.c
Expand Down
Binary file modified PersianCalendar@oxygenws.com/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@
<summary>Display official international events</summary>
<description>Display official international events.</description>
</key>
<key name="praytime-visible" type="b">
<default>true</default>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.
Please disable this and Azaan options, by default.

<summary>Display PrayTime</summary>
<description>Display Pray time based on location</description>
</key>
<key name="praytime-play" type="b">
<default>true</default>
<summary>Play Call to prayer song (Azaan)</summary>
<description>Play Azan</description>
</key>
<key name="praytime-lat" type="d">
<default>35.689202</default>
<summary>Latitude</summary>
<description>your location latitude</description>
</key>
<key name="praytime-lng" type="d">
<default>51.388973</default>
<summary>Latitude</summary>
<description>your location latitude</description>
</key>
<key name="praytime-timezone" type="d">
<default>3.5</default>
<summary>Timezone</summary>
<description>Your timezone based on GMT</description>
</key>
<key name="widget-format" type="s">
<default>'%d'</default>
<summary>Widget date format</summary>
Expand Down
89 changes: 89 additions & 0 deletions PersianCalendar@oxygenws.com/sound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* sound.js
*
* Copyright (C) 2017 Felipe Borges <felipeborges@gnome.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


const Gst = imports.gi.Gst;
const GstAudio = imports.gi.GstAudio;

const DEFAULT_VOLUME = 1;
Gst.init(null);
const SoundPlayer = class SoundPlayer {
constructor(sound) {
this.playbin = Gst.ElementFactory.make("playbin", sound.name);
this.playbin.set_property("uri", this.getUri(sound));
this.sink = Gst.ElementFactory.make("pulsesink", "sink");
this.playbin.set_property("audio-sink", this.sink);

this.prerolled = false;
let bus = this.playbin.get_bus();
bus.add_signal_watch();
bus.connect("message", (bus, msg) => {
if (msg != null) this._onMessageReceived(msg);
});
}

isPlaying() {
let [rv, state, pstate] = this.playbin.get_state(Gst.State.NULL);
return state === Gst.State.PLAYING;
}


play() {
this.playbin.set_state(Gst.State.PLAYING);

}

pause() {
this.playbin.set_state(Gst.State.NULL);
this.prerolled = false;
}

setVolume(value) {
this.playbin.set_volume(GstAudio.StreamVolumeFormat.LINEAR, value);
if (value == 0) {
this.playbin.set_state(Gst.State.NULL);
} else if (!this.isPlaying()) {
this.play();
}
}

_onMessageReceived(message) {
if (message.type == Gst.MessageType.SEGMENT_DONE) {
this.playbin.seek_simple(Gst.Format.TIME, Gst.SeekFlags.SEGMENT, 0);
}
if (message.type == Gst.MessageType.ASYNC_DONE) {
if (!this.prerolled) {
this.playbin.seek_simple(
Gst.Format.TIME,
Gst.SeekFlags.FLUSH | Gst.SeekFlags.SEGMENT,
0
);
this.prerolled = true;
}
}

return true;
}

getUri(sound) {
/* All URIs are relative to $HOME. */
return Gst.filename_to_uri(sound.uri);
}
};

var player = new SoundPlayer({name:"test",uri:".local/share/gnome-shell/extensions/PersianCalendar@oxygenws.com/sounds/azan.mp3"});
Binary file added PersianCalendar@oxygenws.com/sounds/azan.mp3
Binary file not shown.
25 changes: 25 additions & 0 deletions PersianCalendar@oxygenws.com/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,28 @@
margin-left: 5px;
margin-right: 5px;
}

.pcalendar-praytimes-container {
direction: rtl;
text-align: center;
}
.pcalendar-praytimes-box {
margin: 5px 0;

}
.pcalendar-praytimes-item{
margin: 0 5px;
}
.pcalendar-praytimes-key{
text-align: right;
width:70px;
}
.pcalendar-praytimes-time{
text-align: left;
width:40px;

}

.pcalendar-praytimes-azan{
background-color: #ff1648;
}