diff options
| -rw-r--r-- | plugins/newmail_notifier/config.inc.php.dist | 9 | ||||
| -rw-r--r-- | plugins/newmail_notifier/favicon.ico | bin | 0 -> 1734 bytes | |||
| -rw-r--r-- | plugins/newmail_notifier/localization/en_US.inc | 6 | ||||
| -rw-r--r-- | plugins/newmail_notifier/localization/pl_PL.inc | 6 | ||||
| -rw-r--r-- | plugins/newmail_notifier/newmail_notifier.js | 64 | ||||
| -rw-r--r-- | plugins/newmail_notifier/newmail_notifier.php | 145 | ||||
| -rw-r--r-- | plugins/newmail_notifier/sound.wav | bin | 0 -> 10444 bytes | |||
| -rw-r--r-- | roundcubemail/CHANGELOG | 1 | ||||
| -rw-r--r-- | roundcubemail/config/main.inc.php.dist | 3 | ||||
| -rw-r--r-- | roundcubemail/program/js/app.js | 10 | ||||
| -rw-r--r-- | roundcubemail/program/steps/mail/check_recent.inc | 2 | ||||
| -rw-r--r-- | roundcubemail/program/steps/settings/func.inc | 10 | ||||
| -rw-r--r-- | roundcubemail/program/steps/settings/save_prefs.inc | 1 |
13 files changed, 231 insertions, 26 deletions
diff --git a/plugins/newmail_notifier/config.inc.php.dist b/plugins/newmail_notifier/config.inc.php.dist new file mode 100644 index 000000000..21b3d96c2 --- /dev/null +++ b/plugins/newmail_notifier/config.inc.php.dist @@ -0,0 +1,9 @@ +<?php + +// Enables basic notification +$rcmail_config['newmail_notifier_basic'] = false; + +// Enables sound notification +$rcmail_config['newmail_notifier_sound'] = false; + +?> diff --git a/plugins/newmail_notifier/favicon.ico b/plugins/newmail_notifier/favicon.ico Binary files differnew file mode 100644 index 000000000..86e10c1c7 --- /dev/null +++ b/plugins/newmail_notifier/favicon.ico diff --git a/plugins/newmail_notifier/localization/en_US.inc b/plugins/newmail_notifier/localization/en_US.inc new file mode 100644 index 000000000..fbb5d9aae --- /dev/null +++ b/plugins/newmail_notifier/localization/en_US.inc @@ -0,0 +1,6 @@ +<?php + +$labels['basic'] = 'Display notifications on new message'; +$labels['sound'] = 'Play the sound on new message'; + +?> diff --git a/plugins/newmail_notifier/localization/pl_PL.inc b/plugins/newmail_notifier/localization/pl_PL.inc new file mode 100644 index 000000000..5fe37903b --- /dev/null +++ b/plugins/newmail_notifier/localization/pl_PL.inc @@ -0,0 +1,6 @@ +<?php + +$labels['basic'] = 'Wyświetlaj powiadomienia o nadejściu nowej wiadomości'; +$labels['sound'] = 'Odtwarzaj dźwięk o nadejściu nowej wiadomości'; + +?> diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js new file mode 100644 index 000000000..6e1ae9fbb --- /dev/null +++ b/plugins/newmail_notifier/newmail_notifier.js @@ -0,0 +1,64 @@ +/** + * New Mail Notifier plugin script + * + * @version 0.1 + * @author Aleksander Machniak <alec@alec.pl> + */ + +if (window.rcmail && rcmail.env.task == 'mail') { + rcmail.addEventListener('plugin.newmail_notifier', newmail_notifier_run); + rcmail.addEventListener('actionbefore', newmail_notifier_stop); + rcmail.addEventListener('init', function() { + // bind to messages list select event, so favicon will be reverted on message preview too + if (rcmail.message_list) + rcmail.message_list.addEventListener('select', newmail_notifier_stop); + }); +} + +// Executes notification methods +function newmail_notifier_run(prop) +{ + if (prop.basic) + newmail_notifier_basic(); + if (prop.sound) + newmail_notifier_sound(); +} + +// Stops notification +function newmail_notifier_stop(prop) +{ + // revert original favicon + if (rcmail.env.favicon_href && (!prop || prop.action != 'check-recent')) { + $('<link rel="shortcut icon" href="'+rcmail.env.favicon_href+'"/>').replaceAll('link[rel="shortcut icon"]'); + rcmail.env.favicon_href = null; + } +} + +// Basic notification: window.focus and favicon change +function newmail_notifier_basic() +{ + window.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"]'); + + rcmail.env.favicon_href = oldlink.attr('href'); + link.replaceAll(oldlink); +} + +// Sound notification +function newmail_notifier_sound() +{ + // HTML5 + try { + var elem = $('<audio src="success.wav" />'); + elem.get(0).play(); + } + // old method + catch (e) { + var elem = $('<embed id="sound" src="success.wav" hidden=true autostart=true loop=false />'); + elem.appendTo($('body')); + window.setTimeout("$('#sound').remove()", 5000); + } +} diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php new file mode 100644 index 000000000..28542f0a4 --- /dev/null +++ b/plugins/newmail_notifier/newmail_notifier.php @@ -0,0 +1,145 @@ +<?php + +/** + * New Mail Notifier plugin + * + * Supports two methods of notification: + * 1. Basic - focus browser window and change favicon + * 2. Sound - play wav file + * + * @version 0.1 + * @author Aleksander Machniak <alec@alec.pl> + * + * + * Copyright (C) 2011, Kolab Systems AG + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +class newmail_notifier extends rcube_plugin +{ + public $task = 'mail|settings'; + + private $rc; + + /** + * Plugin initialization + */ + function init() + { + $this->rc = rcmail::get_instance(); + + // Preferences hooks + if ($this->rc->task == 'settings') { + $this->add_hook('preferences_list', array($this, 'prefs_list')); + $this->add_hook('preferences_save', array($this, 'prefs_save')); + } + else { // if ($this->rc->task == 'mail') { + $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->include_script('newmail_notifier.js'); + } + } + } + + /** + * Handler for user preferences form (preferences_list hook) + */ + function prefs_list($args) + { + // Load configuration + $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); + + if($args['section'] != 'mailbox') { + return $args; + } + + // Load localization and configuration + $this->add_texts('localization/'); + + 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')), + ); + } + + 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')), + ); + } + + return $args; + } + + /** + * Handler for user preferences save (preferences_save hook) + */ + function prefs_save($args) + { + // Load configuration + $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); + + if($args['section'] != 'mailbox') { + return $args; + } + + 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; + } + + return $args; + } + + /** + * Handler for new message action (new_messages hook) + */ + function notify($args) + { + // Load configuration + $this->load_config(); + + $basic = $this->rc->config->get('newmail_notifier_basic'); + $sound = $this->rc->config->get('newmail_notifier_sound'); + + if ($basic || $sound) { + $this->rc->output->command('plugin.newmail_notifier', + array('basic' => $basic, 'sound' => $sound)); + } + + return $args; + } +} diff --git a/plugins/newmail_notifier/sound.wav b/plugins/newmail_notifier/sound.wav Binary files differnew file mode 100644 index 000000000..72d3dd857 --- /dev/null +++ b/plugins/newmail_notifier/sound.wav diff --git a/roundcubemail/CHANGELOG b/roundcubemail/CHANGELOG index e3afea7e8..39d586733 100644 --- a/roundcubemail/CHANGELOG +++ b/roundcubemail/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG Roundcube Webmail =========================== +- Removed option focus_on_new_message, added newmail_notifier plugin - Added general rcube_cache class with Memcache and APC support - Improved caching performance by skipping writes of unchanged data - Option enable_caching replaced by imap_cache and messages_cache options diff --git a/roundcubemail/config/main.inc.php.dist b/roundcubemail/config/main.inc.php.dist index f63a18129..29af28457 100644 --- a/roundcubemail/config/main.inc.php.dist +++ b/roundcubemail/config/main.inc.php.dist @@ -607,9 +607,6 @@ $rcmail_config['preview_pane'] = false; // Set to -1 if messages in preview pane should not be marked as read $rcmail_config['preview_pane_mark_read'] = 0; -// focus new window if new message arrives -$rcmail_config['focus_on_new_message'] = true; - // Clear Trash on logout $rcmail_config['logout_purge'] = false; diff --git a/roundcubemail/program/js/app.js b/roundcubemail/program/js/app.js index fa643c2b0..a114c80d6 100644 --- a/roundcubemail/program/js/app.js +++ b/roundcubemail/program/js/app.js @@ -5017,16 +5017,6 @@ function rcube_webmail() } }; - // notifies that a new message(s) has hit the mailbox - this.new_message_focus = function() - { - // focus main window - if (this.env.framed && window.parent) - window.parent.focus(); - else - window.focus(); - }; - this.toggle_prefer_html = function(checkbox) { var elem; diff --git a/roundcubemail/program/steps/mail/check_recent.inc b/roundcubemail/program/steps/mail/check_recent.inc index c636e459b..469fa482c 100644 --- a/roundcubemail/program/steps/mail/check_recent.inc +++ b/roundcubemail/program/steps/mail/check_recent.inc @@ -71,8 +71,6 @@ foreach ($a_mailboxes as $mbox_name) { $OUTPUT->set_env('current_page', $all_count ? $IMAP->list_page : 1); if ($status & 1) { - if ($RCMAIL->config->get('focus_on_new_message', true)) - $OUTPUT->command('new_message_focus'); // trigger plugin hook $RCMAIL->plugins->exec_hook('new_messages', array('mailbox' => $mbox_name)); } diff --git a/roundcubemail/program/steps/settings/func.inc b/roundcubemail/program/steps/settings/func.inc index 6d3919faa..b204d9bc9 100644 --- a/roundcubemail/program/steps/settings/func.inc +++ b/roundcubemail/program/steps/settings/func.inc @@ -349,16 +349,6 @@ function rcmail_user_prefs($current=null) ); } - if (!isset($no_override['focus_on_new_message'])) { - $field_id = 'rcmfd_focus_on_new_message'; - $input_focus_on_new_message = new html_checkbox(array('name' => '_focus_on_new_message', 'id' => $field_id, 'value' => 1)); - - $blocks['new_message']['options']['focus_on_new_message'] = array( - 'title' => html::label($field_id, Q(rcube_label('focusonnewmessage'))), - 'content' => $input_focus_on_new_message->show($config['focus_on_new_message']?1:0), - ); - } - if (!isset($no_override['keep_alive'])) { $field_id = 'rcmfd_keep_alive'; $select_keep_alive = new html_select(array('name' => '_keep_alive', 'id' => $field_id)); diff --git a/roundcubemail/program/steps/settings/save_prefs.inc b/roundcubemail/program/steps/settings/save_prefs.inc index 92e2d8b9d..42ad0b952 100644 --- a/roundcubemail/program/steps/settings/save_prefs.inc +++ b/roundcubemail/program/steps/settings/save_prefs.inc @@ -39,7 +39,6 @@ switch ($CURR_SECTION) break; case 'mailbox': $a_user_prefs = array( - 'focus_on_new_message' => isset($_POST['_focus_on_new_message']) ? TRUE : FALSE, 'preview_pane' => isset($_POST['_preview_pane']) ? TRUE : FALSE, 'preview_pane_mark_read' => isset($_POST['_preview_pane_mark_read']) ? intval($_POST['_preview_pane_mark_read']) : $CONFIG['preview_pane_mark_read'], 'autoexpand_threads' => isset($_POST['_autoexpand_threads']) ? intval($_POST['_autoexpand_threads']) : 0, |
