From 08ffd939a7530c44cd68b455f75175f79698073c Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Thu, 29 Dec 2011 04:35:01 -0500
Subject: [PATCH] - Add separate pagesize setting for mail messages and contacts (#1488269)

---
 program/steps/addressbook/list.inc    |   12 ++--
 CHANGELOG                             |    1 
 program/steps/addressbook/func.inc    |   12 ++-
 program/steps/addressbook/delete.inc  |   12 ++--
 config/main.inc.php.dist              |    7 +
 program/steps/settings/save_prefs.inc |   21 ++++--
 installer/rcube_install.php           |    7 +-
 installer/config.php                  |   27 +++++++-
 program/include/rcmail.php            |   12 ++-
 program/steps/settings/func.inc       |   38 ++++++++----
 program/localization/en_US/labels.inc |    1 
 program/js/app.js                     |   10 ---
 program/steps/addressbook/search.inc  |    8 +-
 13 files changed, 103 insertions(+), 65 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 9f8f6cc..09c8708 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Add separate pagesize setting for mail messages and contacts (#1488269)
 - Fix handling of INBOX's subfolders in special folders config (#1488279)
 - Add ifModule statement for setting Options -Indexes in .htaccess file (#1488274)
 - Fix crashes with eAccelerator (#1488256)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 32d8a0d..691c5be 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -654,8 +654,11 @@
 // skin name: folder from skins/
 $rcmail_config['skin'] = 'default';
 
-// show up to X items in list view
-$rcmail_config['pagesize'] = 40;
+// show up to X items in messages list view
+$rcmail_config['mail_pagesize'] = 50;
+
+// show up to X items in contacts list view
+$rcmail_config['addressbook_pagesize'] = 50;
 
 // use this timezone to display date/time
 $rcmail_config['timezone'] = 'auto';
diff --git a/installer/config.php b/installer/config.php
index dabc478..b71e3d5 100644
--- a/installer/config.php
+++ b/installer/config.php
@@ -524,15 +524,34 @@
 <p class="hint">Enter a URL relative to the document root of this Roundcube installation.</p>
 </dd>
 
-<dt class="propname">pagesize <span class="userconf">*</span></dt>
+<dt class="propname">mail_pagesize <span class="userconf">*</span></dt>
 <dd>
 <?php
 
-$input_pagesize = new html_inputfield(array('name' => '_pagesize', 'size' => 6, 'id' => "cfgpagesize"));
-echo $input_pagesize->show($RCI->getprop('pagesize'));
+$pagesize = $RCI->getprop('mail_pagesize');
+if (!$pagesize) {
+    $pagesize = $RCI->getprop('pagesize');
+}
+$input_pagesize = new html_inputfield(array('name' => '_mail_pagesize', 'size' => 6, 'id' => "cfgmailpagesize"));
+echo $input_pagesize->show($pagesize);
 
 ?>
-<div>Show up to X items in list view.</div>
+<div>Show up to X items in the mail messages list view.</div>
+</dd>
+
+<dt class="propname">addressbook_pagesize <span class="userconf">*</span></dt>
+<dd>
+<?php
+
+$pagesize = $RCI->getprop('addressbook_pagesize');
+if (!$pagesize) {
+    $pagesize = $RCI->getprop('pagesize');
+}
+$input_pagesize = new html_inputfield(array('name' => '_addressbook_pagesize', 'size' => 6, 'id' => "cfgabookpagesize"));
+echo $input_pagesize->show($pagesize);
+
+?>
+<div>Show up to X items in the contacts list view.</div>
 </dd>
 
 <dt class="propname">prefer_html <span class="userconf">*</span></dt>
diff --git a/installer/rcube_install.php b/installer/rcube_install.php
index 737972b..a3618a5 100644
--- a/installer/rcube_install.php
+++ b/installer/rcube_install.php
@@ -40,14 +40,15 @@
     'multiple_identities' => 'identities_level',
     'addrbook_show_images' => 'show_images',
     'imap_root' => 'imap_ns_personal',
+    'pagesize' => 'mail_pagesize',
   );
-  
+
   // these config options are required for a working system
   var $required_config = array(
     'db_dsnw', 'db_table_contactgroups', 'db_table_contactgroupmembers',
     'des_key', 'session_lifetime',
   );
-  
+
   /**
    * Constructor
    */
@@ -169,7 +170,7 @@
         if (count($value) <= 1)
           $value = $value[0];
       }
-      else if ($prop == 'pagesize') {
+      else if ($prop == 'mail_pagesize' || $prop == 'addressbook_pagesize') {
         $value = max(2, intval($value));
       }
       else if ($prop == 'smtp_user' && !empty($_POST['_smtp_user_u'])) {
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 59ffaea..deaaabf 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -598,23 +598,27 @@
     $this->imap->skip_deleted = $this->config->get('skip_deleted');
 
     // enable caching of imap data
-    $imap_cache = $this->config->get('imap_cache');
+    $imap_cache     = $this->config->get('imap_cache');
     $messages_cache = $this->config->get('messages_cache');
     // for backward compatybility
     if ($imap_cache === null && $messages_cache === null && $this->config->get('enable_caching')) {
         $imap_cache     = 'db';
         $messages_cache = true;
     }
+
     if ($imap_cache)
         $this->imap->set_caching($imap_cache);
     if ($messages_cache)
         $this->imap->set_messages_caching(true);
 
     // set pagesize from config
-    $this->imap->set_pagesize($this->config->get('pagesize', 50));
+    $pagesize = $this->config->get('mail_pagesize');
+    if (!$pagesize) {
+        $pagesize = $this->config->get('pagesize', 50);
+    }
+    $this->imap->set_pagesize($pagesize);
 
-    // Setting root and delimiter before establishing the connection
-    // can save time detecting them using NAMESPACE and LIST
+    // set connection options
     $options = array(
       'auth_type'   => $this->config->get('imap_auth_type', 'check'),
       'auth_cid'    => $this->config->get('imap_auth_cid'),
diff --git a/program/js/app.js b/program/js/app.js
index e9301f5..5e51cbb 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -5658,16 +5658,6 @@
     }
   };
 
-  this.toggle_prefer_html = function(checkbox)
-  {
-    $('#rcmfd_show_images').prop('disabled', !checkbox.checked).val(0);
-  };
-
-  this.toggle_preview_pane = function(checkbox)
-  {
-    $('#rcmfd_preview_pane_mark_read').prop('disabled', !checkbox.checked);
-  };
-
   // display fetched raw headers
   this.set_headers = function(content)
   {
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index f192209..3efff4a 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -412,7 +412,6 @@
 $labels['section'] = 'Section';
 $labels['maintenance'] = 'Maintenance';
 $labels['newmessage'] = 'New Message';
-$labels['listoptions'] = 'List Options';
 $labels['signatureoptions'] = 'Signature Options';
 $labels['whenreplying'] = 'When replying';
 $labels['replytopposting'] = 'start new message above original';
diff --git a/program/steps/addressbook/delete.inc b/program/steps/addressbook/delete.inc
index 222535c..30e0ca1 100644
--- a/program/steps/addressbook/delete.inc
+++ b/program/steps/addressbook/delete.inc
@@ -103,20 +103,20 @@
 
     // create resultset object
     $count  = count($records);
-    $first  = ($page-1) * $CONFIG['pagesize'];
+    $first  = ($page-1) * $PAGE_SIZE;
     $result = new rcube_result_set($count, $first);
 
     // get records from the next page to add to the list
-    $pages = ceil((count($records) + $delcnt) / $CONFIG['pagesize']);
+    $pages = ceil((count($records) + $delcnt) / $PAGE_SIZE);
     if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) {
         // sort the records
         ksort($records, SORT_LOCALE_STRING);
 
-        $first += $CONFIG['pagesize'];
+        $first += $PAGE_SIZE;
         // create resultset object
         $res = new rcube_result_set($count, $first - $delcnt);
 
-        if ($CONFIG['pagesize'] < $count) {
+        if ($PAGE_SIZE < $count) {
             $records = array_slice($records, $first - $delcnt, $delcnt);
         }
 
@@ -132,7 +132,7 @@
     $result = $CONTACTS->count();
 
     // get records from the next page to add to the list
-    $pages = ceil(($result->count + $delcnt) / $CONFIG['pagesize']);
+    $pages = ceil(($result->count + $delcnt) / $PAGE_SIZE);
     if ($_GET['_from'] != 'show' && $pages > 1 && $page < $pages) {
         $CONTACTS->set_page($page);
         $records = $CONTACTS->list_records(null, -$delcnt);
@@ -140,7 +140,7 @@
 }
 
 // update message count display
-$OUTPUT->set_env('pagecount', ceil($result->count / $CONFIG['pagesize']));
+$OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
 $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
 
 if (!empty($_SESSION['contact_undo'])) {
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index fac8987..e7d3eae 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -56,6 +56,10 @@
   // TODO: define fields for vcards like GEO, KEY
 );
 
+$PAGE_SIZE = $RCMAIL->config->get('addressbook_pagesize');
+if (!$PAGE_SIZE) {
+    $PAGE_SIZE = $RCMAIL->config->get('pagesize', 50);
+}
 
 // Addressbook UI
 if (!$RCMAIL->action && !$OUTPUT->ajax_call) {
@@ -108,7 +112,7 @@
 // instantiate a contacts object according to the given source
 function rcmail_contact_source($source=null, $init_env=false, $writable=false)
 {
-    global $RCMAIL, $OUTPUT, $CONFIG, $CONTACT_COLTYPES;
+    global $RCMAIL, $OUTPUT, $CONTACT_COLTYPES, $PAGE_SIZE;
 
     if (!strlen($source)) {
         $source = get_input_value('_source', RCUBE_INPUT_GPC);
@@ -116,7 +120,7 @@
 
     // Get object
     $CONTACTS = $RCMAIL->get_address_book($source, $writable);
-    $CONTACTS->set_pagesize($CONFIG['pagesize']);
+    $CONTACTS->set_pagesize($PAGE_SIZE);
 
     // set list properties and session vars
     if (!empty($_GET['_page']))
@@ -391,7 +395,7 @@
 
 function rcmail_get_rowcount_text($result=null)
 {
-    global $CONTACTS, $CONFIG;
+    global $CONTACTS, $PAGE_SIZE;
 
     // read nr of contacts
     if (!$result) {
@@ -405,7 +409,7 @@
             'name'  => $_SESSION['contactcountdisplay'] ? $_SESSION['contactcountdisplay'] : 'contactsfromto',
             'vars'  => array(
             'from'  => $result->first + 1,
-            'to'    => min($result->count, $result->first + $CONFIG['pagesize']),
+            'to'    => min($result->count, $result->first + $PAGE_SIZE),
             'count' => $result->count)
         ));
 
diff --git a/program/steps/addressbook/list.inc b/program/steps/addressbook/list.inc
index b4b7306..0e3afa2 100644
--- a/program/steps/addressbook/list.inc
+++ b/program/steps/addressbook/list.inc
@@ -56,13 +56,13 @@
     ksort($records, SORT_LOCALE_STRING);
 
     // create resultset object
-    $count  = count($records);
-    $first  = ($page-1) * $CONFIG['pagesize'];
+    $count    = count($records);
+    $first  = ($page-1) * $PAGE_SIZE;
     $result = new rcube_result_set($count, $first);
 
     // we need only records for current page
-    if ($CONFIG['pagesize'] < $count) {
-        $records = array_slice($records, $first, $CONFIG['pagesize']);
+    if ($PAGE_SIZE < $count) {
+        $records = array_slice($records, $first, $PAGE_SIZE);
     }
 
     $result->records = array_values($records);
@@ -73,7 +73,7 @@
 
     // get contacts for this user
     $result = $CONTACTS->list_records(array('name'));
-    
+
     if (!$result->count && $result->searchonly) {
         $OUTPUT->show_message('contactsearchonly', 'notice');
         $OUTPUT->command('command', 'advanced-search');
@@ -81,7 +81,7 @@
 }
 
 // update message count display
-$OUTPUT->set_env('pagecount', ceil($result->count / $CONFIG['pagesize']));
+$OUTPUT->set_env('pagecount', ceil($result->count / $PAGE_SIZE));
 $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
 
 // create javascript list
diff --git a/program/steps/addressbook/search.inc b/program/steps/addressbook/search.inc
index 643cc60..e4ce2d6 100644
--- a/program/steps/addressbook/search.inc
+++ b/program/steps/addressbook/search.inc
@@ -88,7 +88,7 @@
 
 function rcmail_contact_search()
 {
-    global $RCMAIL, $OUTPUT, $CONFIG, $SEARCH_MODS_DEFAULT;
+    global $RCMAIL, $OUTPUT, $SEARCH_MODS_DEFAULT, $PAGE_SIZE;
 
     $adv = isset($_POST['_adv']);
     $sid = get_input_value('_sid', RCUBE_INPUT_GET);
@@ -198,8 +198,8 @@
     $result = new rcube_result_set($count);
 
     // cut first-page records
-    if ($CONFIG['pagesize'] < $count) {
-        $records = array_slice($records, 0, $CONFIG['pagesize']);
+    if ($PAGE_SIZE < $count) {
+        $records = array_slice($records, 0, $PAGE_SIZE);
     }
 
     $result->records = array_values($records);
@@ -228,7 +228,7 @@
 
     // update message count display
     $OUTPUT->command('set_env', 'search_request', $search_request);
-    $OUTPUT->command('set_env', 'pagecount', ceil($result->count / $CONFIG['pagesize']));
+    $OUTPUT->command('set_env', 'pagecount', ceil($result->count / $PAGE_SIZE));
     $OUTPUT->command('set_rowcount', rcmail_get_rowcount_text($result));
     // Re-set current source
     $OUTPUT->command('set_env', 'search_id', $sid);
diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc
index 032bafd..91543ec 100644
--- a/program/steps/settings/func.inc
+++ b/program/steps/settings/func.inc
@@ -157,7 +157,6 @@
 
     $blocks = array(
       'main' => array('name' => Q(rcube_label('mainoptions'))),
-      'list' => array('name' => Q(rcube_label('listoptions'))),
     );
 
     // language selection
@@ -175,7 +174,7 @@
       );
     }
 
-    // show page size selection
+    // timezone selection
     if (!isset($no_override['timezone'])) {
       $field_id = 'rcmfd_timezone';
       $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id,
@@ -276,17 +275,6 @@
       );
     }
 
-    // show page size selection
-    if (!isset($no_override['pagesize'])) {
-      $field_id = 'rcmfd_pgsize';
-      $input_pagesize = new html_inputfield(array('name' => '_pagesize', 'id' => $field_id, 'size' => 5));
-
-      $blocks['list']['options']['pagesize'] = array(
-        'title' => html::label($field_id, Q(rcube_label('pagesize'))),
-        'content' => $input_pagesize->show($config['pagesize']),
-      );
-    }
-
     // show drop-down for available skins
     if (!isset($no_override['skin'])) {
       $skins = rcmail_get_skins();
@@ -375,6 +363,17 @@
       $blocks['main']['options']['autoexpand_threads'] = array(
         'title' => html::label($field_id, Q(rcube_label('autoexpand_threads'))),
         'content' => $select_autoexpand_threads->show($config['autoexpand_threads']),
+      );
+    }
+
+    // show page size selection
+    if (!isset($no_override['pagesize'])) {
+      $field_id = 'rcmfd_pagesize';
+      $input_pagesize = new html_inputfield(array('name' => '_pagesize', 'id' => $field_id, 'size' => 5));
+
+      $blocks['main']['options']['pagesize'] = array(
+        'title' => html::label($field_id, Q(rcube_label('pagesize'))),
+        'content' => $input_pagesize->show($config['pagesize']),
       );
     }
 
@@ -690,6 +689,19 @@
       );
     }
 
+    // show addressbook page size selection
+    if (!isset($no_override['addressbook_pagesize'])) {
+      $field_id = 'rcmfd_addressbook_pagesize';
+      $input_pagesize = new html_inputfield(array('name' => '_addressbook_pagesize', 'id' => $field_id, 'size' => 5));
+
+      $size = $config['addressbook_pagesize'] ? $config['addressbook_pagesize'] : $config['pagesize'];
+
+      $blocks['main']['options']['pagesize'] = array(
+        'title' => html::label($field_id, Q(rcube_label('pagesize'))),
+        'content' => $input_pagesize->show((int)$size),
+      );
+    }
+
     break;
 
     // Special IMAP folders
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index 5cb79d1..2e89ce1 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -31,13 +31,12 @@
       'language'     => isset($_POST['_language']) ? get_input_value('_language', RCUBE_INPUT_POST) : $CONFIG['language'],
       'timezone'     => isset($_POST['_timezone']) ? (is_numeric($_POST['_timezone']) ? floatval($_POST['_timezone']) : get_input_value('_timezone', RCUBE_INPUT_POST)) : $CONFIG['timezone'],
       'dst_active'   => isset($_POST['_dst_active']) ? TRUE : FALSE,
-      'pagesize'     => is_numeric($_POST['_pagesize']) ? max(2, intval($_POST['_pagesize'])) : $CONFIG['pagesize'],
       'date_format'  => isset($_POST['_date_format']) ? get_input_value('_date_format', RCUBE_INPUT_POST) : $CONFIG['date_format'],
       '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,
       'skin' 	     => isset($_POST['_skin']) ? get_input_value('_skin', RCUBE_INPUT_POST) : $CONFIG['skin'],
     );
-    
+
     // compose derived date/time format strings
     if ((isset($_POST['_date_format']) || isset($_POST['_time_format'])) && $a_user_prefs['date_format'] && $a_user_prefs['time_format']) {
       $a_user_prefs['date_short'] = 'D ' . $a_user_prefs['time_format'];
@@ -54,6 +53,7 @@
       'mdn_requests'         => isset($_POST['_mdn_requests']) ? intval($_POST['_mdn_requests']) : 0,
       'keep_alive'           => isset($_POST['_keep_alive']) ? intval($_POST['_keep_alive'])*60 : $CONFIG['keep_alive'],
       'check_all_folders'    => isset($_POST['_check_all_folders']) ? TRUE : FALSE,
+      'mail_pagesize'        => is_numeric($_POST['_mail_pagesize']) ? max(2, intval($_POST['_mail_pagesize'])) : $CONFIG['mail_pagesize'],
     );
 
   break;
@@ -93,8 +93,9 @@
 
   case 'addressbook':
     $a_user_prefs = array(
-      'default_addressbook' => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true),
-      'autocomplete_single' => isset($_POST['_autocomplete_single']) ? TRUE : FALSE,
+      'default_addressbook'  => get_input_value('_default_addressbook', RCUBE_INPUT_POST, true),
+      'autocomplete_single'  => isset($_POST['_autocomplete_single']) ? TRUE : FALSE,
+      'addressbook_pagesize' => is_numeric($_POST['_addressbook_pagesize']) ? max(2, intval($_POST['_addressbook_pagesize'])) : $CONFIG['addressbook_pagesize'],
     );
 
   break;
@@ -150,11 +151,15 @@
       $OUTPUT->command('reload', 500);
 
     // force min size
-    if ($a_user_prefs['pagesize'] < 1)
-      $a_user_prefs['pagesize'] = 10;
+    if ($a_user_prefs['mail_pagesize'] < 1)
+      $a_user_prefs['mail_pagesize'] = 10;
+    if ($a_user_prefs['addressbook_pagesize'] < 1)
+      $a_user_prefs['addressbook_pagesize'] = 10;
 
-    if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['pagesize'] > $CONFIG['max_pagesize']))
-      $a_user_prefs['pagesize'] = (int) $CONFIG['max_pagesize'];
+    if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['mail_pagesize'] > $CONFIG['max_pagesize']))
+      $a_user_prefs['mail_pagesize'] = (int) $CONFIG['max_pagesize'];
+    if (isset($CONFIG['max_pagesize']) && ($a_user_prefs['addressbook_pagesize'] > $CONFIG['max_pagesize']))
+      $a_user_prefs['addressbook_pagesize'] = (int) $CONFIG['max_pagesize'];
 
     $a_user_prefs['timezone'] = (string) $a_user_prefs['timezone'];
 

--
Gitblit v1.9.1