summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/newmail_notifier/localization/en_US.inc9
-rw-r--r--plugins/newmail_notifier/localization/pl_PL.inc9
-rw-r--r--plugins/newmail_notifier/mail.pngbin0 -> 1408 bytes
-rw-r--r--plugins/newmail_notifier/newmail_notifier.js60
-rw-r--r--plugins/newmail_notifier/newmail_notifier.php76
5 files changed, 116 insertions, 38 deletions
diff --git a/plugins/newmail_notifier/localization/en_US.inc b/plugins/newmail_notifier/localization/en_US.inc
index fbb5d9aae..3017c43dc 100644
--- a/plugins/newmail_notifier/localization/en_US.inc
+++ b/plugins/newmail_notifier/localization/en_US.inc
@@ -1,6 +1,13 @@
<?php
-$labels['basic'] = 'Display notifications on new message';
+$labels['basic'] = 'Display browser notifications on new message';
+$labels['desktop'] = 'Display desktop notifications on new message';
$labels['sound'] = 'Play the sound on new message';
+$labels['test'] = 'Test';
+$labels['title'] = 'New Email!';
+$labels['body'] = 'You\'ve received a new message.';
+$labels['testbody'] = 'This is a test notification.';
+$labels['desktopdisabled'] = 'Desktop notifications are disabled in your browser.';
+$labels['desktopunsupported'] = 'Your browser does not support desktop notifications.';
?>
diff --git a/plugins/newmail_notifier/localization/pl_PL.inc b/plugins/newmail_notifier/localization/pl_PL.inc
index 5fe37903b..d95e658af 100644
--- a/plugins/newmail_notifier/localization/pl_PL.inc
+++ b/plugins/newmail_notifier/localization/pl_PL.inc
@@ -1,6 +1,13 @@
<?php
-$labels['basic'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości';
+$labels['basic'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości w przeglądarce';
$labels['sound'] = 'Odtwarzaj dźwięk o nadejściu nowej wiadomości';
+$labels['desktop'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości na pulpicie';
+$labels['test'] = 'Testuj powiadomienie';
+$labels['title'] = 'Nowa wiadomość!';
+$labels['body'] = 'Nadeszła nowa wiadomość.';
+$labels['testbody'] = 'To jest testowe powiadomienie.';
+$labels['desktopdisabled'] = 'Powiadomienia na pulpicie zostały zablokowane w twojej przeglądarce.';
+$labels['desktopunsupported'] = 'Twoja przeglądarka nie obsługuje powiadomień na pulpicie.';
?>
diff --git a/plugins/newmail_notifier/mail.png b/plugins/newmail_notifier/mail.png
new file mode 100644
index 000000000..79f3a5311
--- /dev/null
+++ b/plugins/newmail_notifier/mail.png
Binary files differ
diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js
index 6afd66aee..16e3edd42 100644
--- a/plugins/newmail_notifier/newmail_notifier.js
+++ b/plugins/newmail_notifier/newmail_notifier.js
@@ -1,7 +1,7 @@
/**
* New Mail Notifier plugin script
*
- * @version 0.2
+ * @version 0.3
* @author Aleksander Machniak <alec@alec.pl>
*/
@@ -22,6 +22,8 @@ function newmail_notifier_run(prop)
newmail_notifier_basic();
if (prop.sound)
newmail_notifier_sound();
+ if (prop.desktop)
+ newmail_notifier_desktop(rcmail.gettext('body', 'newmail_notifier'));
}
// Stops notification
@@ -37,11 +39,13 @@ function newmail_notifier_stop(prop)
// Basic notification: window.focus and favicon change
function newmail_notifier_basic()
{
- window.focus();
+ var w = rcmail.is_framed() ? window.parent : window;
+
+ w.focus();
// we cannot simply change a href attribute, we must to replace the link element (at least in FF)
var link = $('<link rel="shortcut icon" href="plugins/newmail_notifier/favicon.ico"/>'),
- oldlink = $('link[rel="shortcut icon"]');
+ oldlink = $('link[rel="shortcut icon"]', w.document);
rcmail.env.favicon_href = oldlink.attr('href');
link.replaceAll(oldlink);
@@ -64,3 +68,53 @@ function newmail_notifier_sound()
window.setTimeout("$('#sound').remove()", 5000);
}
}
+
+// Desktop notification (need Chrome or Firefox with a plugin)
+function newmail_notifier_desktop(body)
+{
+ var dn = window.webkitNotifications;
+
+ if (dn && !dn.checkPermission()) {
+ if (rcmail.newmail_popup)
+ rcmail.newmail_popup.cancel();
+ var popup = window.webkitNotifications.createNotification('plugins/newmail_notifier/mail.png',
+ rcmail.gettext('title', 'newmail_notifier'), body);
+ popup.onclick = function() {
+ this.cancel();
+ }
+ popup.show();
+ setTimeout(function() { popup.cancel(); }, 10000); // close after 10 seconds
+ rcmail.newmail_popup = popup;
+ return true;
+ }
+
+ return false;
+}
+
+function newmail_notifier_test_desktop()
+{
+ var dn = window.webkitNotifications,
+ txt = rcmail.gettext('testbody', 'newmail_notifier');
+
+ if (dn) {
+ if (!dn.checkPermission())
+ newmail_notifier_desktop(txt);
+ else
+ dn.requestPermission(function() {
+ if (!newmail_notifier_desktop(txt))
+ rcmail.display_message(rcmail.gettext('desktopdisabled', 'newmail_notifier'), 'error');
+ });
+ }
+ else
+ rcmail.display_message(rcmail.gettext('desktopunsupported', 'newmail_notifier'), 'error');
+}
+
+function newmail_notifier_test_basic()
+{
+ newmail_notifier_basic();
+}
+
+function newmail_notifier_test_sound()
+{
+ newmail_notifier_sound();
+}
diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php
index a72d728dc..1f1df9e75 100644
--- a/plugins/newmail_notifier/newmail_notifier.php
+++ b/plugins/newmail_notifier/newmail_notifier.php
@@ -6,8 +6,10 @@
* Supports two methods of notification:
* 1. Basic - focus browser window and change favicon
* 2. Sound - play wav file
+ * 3. Desktop - display desktop notification (using webkitNotifications feature,
+ * supported by Chrome and Firefox with 'HTML5 Notifications' plugin)
*
- * @version 0.2
+ * @version 0.3
* @author Aleksander Machniak <alec@alec.pl>
*
*
@@ -32,6 +34,7 @@ class newmail_notifier extends rcube_plugin
public $task = 'mail|settings';
private $rc;
+ private $notified;
/**
* Plugin initialization
@@ -49,6 +52,8 @@ class newmail_notifier extends rcube_plugin
$this->add_hook('new_messages', array($this, 'notify'));
// add script when not in ajax and not in frame
if (is_a($this->rc->output, 'rcube_template') && empty($_REQUEST['_framed'])) {
+ $this->add_texts('localization/');
+ $this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.body');
$this->include_script('newmail_notifier.js');
}
}
@@ -69,27 +74,29 @@ class newmail_notifier extends rcube_plugin
// Load localization and configuration
$this->add_texts('localization/');
+ if (!empty($_REQUEST['_framed'])) {
+ $this->rc->output->add_label('newmail_notifier.title', 'newmail_notifier.testbody',
+ 'newmail_notifier.desktopunsupported', 'newmail_notifier.desktopenabled', 'newmail_notifier.desktopdisabled');
+ $this->include_script('newmail_notifier.js');
+ }
+
// Check that configuration is not disabled
- $dont_override = (array) $this->rc->config->get('dont_override', array());
- $basic_override = in_array('newmail_notifier_basic', $dont_override);
- $sound_override = in_array('newmail_notifier_sound', $dont_override);
+ $dont_override = (array) $this->rc->config->get('dont_override', array());
- if (!$basic_override) {
- $field_id = '_newmail_notifier_basic';
- $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
- $args['blocks']['new_message']['options']['newmail_notifier_basic'] = array(
- 'title' => html::label($field_id, Q($this->gettext('basic'))),
- 'content' => $input->show($this->rc->config->get('newmail_notifier_basic')),
- );
- }
+ foreach (array('basic', 'desktop', 'sound') as $type) {
+ $key = 'newmail_notifier_' . $type;
+ if (!in_array($key, $dont_override)) {
+ $field_id = '_' . $key;
+ $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
+ $content = $input->show($this->rc->config->get($key))
+ . ' ' . html::a(array('href' => '#', 'onclick' => 'newmail_notifier_test_'.$type.'()'),
+ $this->gettext('test'));
- if (!$sound_override) {
- $field_id = '_newmail_notifier_sound';
- $input = new html_checkbox(array('name' => $field_id, 'id' => $field_id, 'value' => 1));
- $args['blocks']['new_message']['options']['newmail_notifier_sound'] = array(
- 'title' => html::label($field_id, Q($this->gettext('sound'))),
- 'content' => $input->show($this->rc->config->get('newmail_notifier_sound')),
- );
+ $args['blocks']['new_message']['options'][$key] = array(
+ 'title' => html::label($field_id, Q($this->gettext($type))),
+ 'content' => $content
+ );
+ }
}
return $args;
@@ -108,17 +115,13 @@ class newmail_notifier extends rcube_plugin
$this->load_config();
// Check that configuration is not disabled
- $dont_override = (array) $this->rc->config->get('dont_override', array());
- $basic_override = in_array('newmail_notifier_basic', $dont_override);
- $sound_override = in_array('newmail_notifier_sound', $dont_override);
+ $dont_override = (array) $this->rc->config->get('dont_override', array());
- if (!$basic_override) {
- $key = 'newmail_notifier_basic';
- $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
- }
- if (!$sound_override) {
- $key = 'newmail_notifier_sound';
- $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
+ foreach (array('basic', 'desktop', 'sound') as $type) {
+ $key = 'newmail_notifier_' . $type;
+ if (!in_array($key, $dont_override)) {
+ $args['prefs'][$key] = get_input_value('_'.$key, RCUBE_INPUT_POST) ? true : false;
+ }
}
return $args;
@@ -129,15 +132,22 @@ class newmail_notifier extends rcube_plugin
*/
function notify($args)
{
+ if ($this->notified) {
+ return $args;
+ }
+
+ $this->notified = true;
+
// Load configuration
$this->load_config();
- $basic = $this->rc->config->get('newmail_notifier_basic');
- $sound = $this->rc->config->get('newmail_notifier_sound');
+ $basic = $this->rc->config->get('newmail_notifier_basic');
+ $sound = $this->rc->config->get('newmail_notifier_sound');
+ $desktop = $this->rc->config->get('newmail_notifier_desktop');
- if ($basic || $sound) {
+ if ($basic || $sound || $desktop) {
$this->rc->output->command('plugin.newmail_notifier',
- array('basic' => $basic, 'sound' => $sound));
+ array('basic' => $basic, 'sound' => $sound, 'desktop' => $desktop));
}
return $args;