From 3863a9d2c5515fe4c61c433503450531098358ec Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 31 May 2013 03:27:15 -0400
Subject: [PATCH] Added user preference to open all popups as standard windows

---
 CHANGELOG                              |    1 
 program/include/rcmail_output_html.php |    1 
 program/steps/settings/func.inc        |   50 +++++++++++++++----------
 program/localization/en_US/labels.inc  |    1 
 config/main.inc.php.dist               |    4 ++
 program/js/app.js                      |   31 +++++++++------
 program/steps/settings/save_prefs.inc  |    1 
 7 files changed, 57 insertions(+), 32 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 3574411..b8fe666 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Added user preference to open all popups as standard windows
 - Fix unintentional compose window resize (#1489114)
 - Fix performance regression in text wrapping function (#1489133)
 - Fix connection to posgtres db using unix socket (#1489132)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 4a73ff1..898d96b 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -723,6 +723,10 @@
 // skin name: folder from skins/
 $rcmail_config['skin'] = 'larry';
 
+// Enables using standard browser windows (that can be handled as tabs)
+// instead of popup windows
+$rcmail_config['standard_windows'] = false;
+
 // show up to X items in messages list view
 $rcmail_config['mail_pagesize'] = 50;
 
diff --git a/program/include/rcmail_output_html.php b/program/include/rcmail_output_html.php
index 02eef2f..aaec7f9 100644
--- a/program/include/rcmail_output_html.php
+++ b/program/include/rcmail_output_html.php
@@ -67,6 +67,7 @@
         //$this->framed = $framed;
         $this->set_env('task', $task);
         $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
+        $this->set_env('standard_windows', (bool) $this->config->get('standard_windows'));
 
         // add cookie info
         $this->set_env('cookie_domain', ini_get('session.cookie_domain'));
diff --git a/program/js/app.js b/program/js/app.js
index d5a66ab..25f7fe9 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -1629,18 +1629,25 @@
   // open popup window
   this.open_window = function(url, small, toolbar)
   {
-    var win = this.is_framed() ? parent.window : window,
-      page = $(win),
-      page_width = page.width(),
-      page_height = bw.mz ? $('body', win).height() : page.height(),
-      w = Math.min(small ? this.env.popup_width_small : this.env.popup_width, page_width),
-      h = page_height, // always use same height
-      l = (win.screenLeft || win.screenX) + 20,
-      t = (win.screenTop || win.screenY) + 20,
-      wname = 'rcmextwin' + new Date().getTime(),
-      extwin = window.open(url + (url.match(/\?/) ? '&' : '?') + '_extwin=1', wname,
-        'width='+w+',height='+h+',top='+t+',left='+l+',resizable=yes,location=no,scrollbars=yes'
-        +(toolbar ? ',toolbar=yes,menubar=yes,status=yes' : ',toolbar=no,menubar=no,status=no'));
+    var wname = 'rcmextwin' + new Date().getTime();
+
+    url += (url.match(/\?/) ? '&' : '?') + '_extwin=1';
+
+    if (this.env.standard_windows)
+      extwin = window.open(url, wname);
+    else {
+      var win = this.is_framed() ? parent.window : window,
+        page = $(win),
+        page_width = page.width(),
+        page_height = bw.mz ? $('body', win).height() : page.height(),
+        w = Math.min(small ? this.env.popup_width_small : this.env.popup_width, page_width),
+        h = page_height, // always use same height
+        l = (win.screenLeft || win.screenX) + 20,
+        t = (win.screenTop || win.screenY) + 20,
+        extwin = window.open(url, wname,
+          'width='+w+',height='+h+',top='+t+',left='+l+',resizable=yes,location=no,scrollbars=yes'
+          +(toolbar ? ',toolbar=yes,menubar=yes,status=yes' : ',toolbar=no,menubar=no,status=no'));
+    }
 
     // write loading... message to empty windows
     if (!url && extwin.document) {
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index ab57007..8a8fa2c 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -472,6 +472,7 @@
 $labels['spellcheckignorecaps'] = 'Ignore words with all letters capitalized';
 $labels['addtodict'] = 'Add to dictionary';
 $labels['mailtoprotohandler'] = 'Register protocol handler for mailto: links';
+$labels['standardwindows'] = 'Handle popups as standard windows';
 $labels['forwardmode'] = 'Messages forwarding';
 $labels['inline'] = 'inline';
 $labels['asattachment'] = 'as attachment';
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index ce86b1c..636941d 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -95,13 +95,13 @@
   if (empty($EDIT_FORM)) {
     $request_key = $action . (isset($id) ? '.'.$id : '');
     $form_start = $RCMAIL->output->request_form(array(
-	  'name'    => 'form',
-	  'method'  => 'post',
-	  'task'    => $RCMAIL->task,
-	  'action'  => $action,
-	  'request' => $request_key,
-	  'noclose' => true
-	) + $attrib);
+      'name'    => 'form',
+      'method'  => 'post',
+      'task'    => $RCMAIL->task,
+      'action'  => $action,
+      'request' => $request_key,
+      'noclose' => true
+    ) + $attrib);
 
     if (is_array($hidden)) {
       $hiddenfields = new html_hiddenfield($hidden);
@@ -152,6 +152,8 @@
 
     $blocks = array(
       'main'    => array('name' => Q(rcube_label('mainoptions'))),
+      'skin'    => array('name' => Q(rcube_label('skin'))),
+      'browser' => array('name' => Q(rcube_label('browseroptions'))),
     );
 
     // language selection
@@ -263,8 +265,6 @@
         $field_id = 'rcmfd_skin';
         $input_skin = new html_radiobutton(array('name'=>'_skin'));
 
-        $blocks['skin'] = array('name' => Q(rcube_label('skin')),);
-
         foreach($skins as $skin) {
           $thumbnail = "./skins/$skin/thumbnail.png";
           if (!is_file($thumbnail))
@@ -290,17 +290,27 @@
       }
     }
 
+    // standard_windows option decides if new windows should be
+    // opened as popups or standard windows (which can be handled by browsers as tabs)
+    if (!isset($no_override['standard_windows'])) {
+      $field_id = 'rcmfd_standard_windows';
+      $checkbox = new html_checkbox(array('name' => '_standard_windows', 'id' => $field_id, 'value' => 1));
+
+      $blocks['browser']['options']['standard_windows'] = array(
+        'title' => html::label($field_id, Q(rcube_label('standardwindows'))),
+        'content' => $checkbox->show($config['standard_windows']?1:0),
+      );
+    }
+
+
     $product_name = $RCMAIL->config->get('product_name', 'Roundcube Webmail');
     $RCMAIL->output->add_script(sprintf("%s.check_protocol_handler('%s', '#mailtoprotohandler');",
       JS_OBJECT_NAME, JQ($product_name)), 'foot');
 
-    $blocks['browser'] = array(
-      'name' => Q(rcube_label('browseroptions')),
-      'options' => array('mailtoprotohandler' => array(
-        'content' => html::a(array(
-          'href' => '#',
-          'id' => 'mailtoprotohandler'), Q(rcube_label('mailtoprotohandler'))),
-        )),
+    $blocks['browser']['options']['mailtoprotohandler'] = array(
+      'content' => html::a(array(
+        'href' => '#',
+        'id' => 'mailtoprotohandler'), Q(rcube_label('mailtoprotohandler'))),
     );
 
     break;
@@ -797,13 +807,13 @@
         $blocks['main']['options']['sent_mbox'] = array(
           'title' => Q(rcube_label('sent')),
           'content' => $select->show($config['sent_mbox'], array('name' => "_sent_mbox")),
-	);
+        );
 
       if (!isset($no_override['junk_mbox']))
         $blocks['main']['options']['junk_mbox'] = array(
           'title' => Q(rcube_label('junk')),
           'content' => $select->show($config['junk_mbox'], array('name' => "_junk_mbox")),
-	);
+        );
 
       if (!isset($no_override['trash_mbox']))
         $blocks['main']['options']['trash_mbox'] = array(
@@ -905,7 +915,7 @@
     foreach ($data['blocks'] as $block) {
       if (!empty($block['content']) || !empty($block['options'])) {
         $found = true;
-	    break;
+        break;
       }
     }
 
@@ -927,7 +937,7 @@
   $dir = opendir($path);
 
   if (!$dir)
-	return false;
+    return false;
 
   while (($file = readdir($dir)) !== false)
   {
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index 3bb82aa..d0a3bec 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -34,6 +34,7 @@
       'time_format'  => isset($_POST['_time_format']) ? get_input_value('_time_format', RCUBE_INPUT_POST) : ($CONFIG['time_format'] ? $CONFIG['time_format'] : 'H:i'),
       'prettydate'   => isset($_POST['_pretty_date']) ? TRUE : FALSE,
       'refresh_interval' => isset($_POST['_refresh_interval']) ? intval($_POST['_refresh_interval'])*60 : $CONFIG['refresh_interval'],
+      'standard_windows' => isset($_POST['_standard_windows']) ? TRUE : FALSE,
       'skin'         => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
     );
 

--
Gitblit v1.9.1