[Svn] r4197 - trunk/plugins/kolab_addressbook

trac at roundcube.net trac at roundcube.net
Tue Nov 9 00:17:28 CET 2010


Author: thomasb
Date: 2010-11-08 17:17:28 -0600 (Mon, 08 Nov 2010)
New Revision: 4197

Modified:
   trunk/plugins/kolab_addressbook/kolab_addressbook.php
   trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
Log:
List all Kolab contact folders available

Modified: trunk/plugins/kolab_addressbook/kolab_addressbook.php
===================================================================
--- trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-08 13:52:39 UTC (rev 4196)
+++ trunk/plugins/kolab_addressbook/kolab_addressbook.php	2010-11-08 23:17:28 UTC (rev 4197)
@@ -16,9 +16,10 @@
  */
 class kolab_addressbook extends rcube_plugin
 {
-    private $abook_id = 'kolab';
-    private $abook;
- 
+    private $kolab;
+    private $folders;
+    private $sources;
+
     /**
      * Required startup method of a Roundcube plugin
      */
@@ -31,14 +32,6 @@
         $this->add_hook('addressbook_get', array($this, 'get_address_book'));
         $this->add_hook('imap_init', array($this, 'imap_init'));
 
-        // use this address book for autocompletion queries
-        $config = rcmail::get_instance()->config;
-        $sources = (array) $config->get('autocomplete_addressbooks', array('sql'));
-        if (!in_array($this->abook_id, $sources)) {
-            $sources[] = $this->abook_id;
-            $config->set('autocomplete_addressbooks', $sources);
-        }
-        
         // extend include path to load bundled Horde classes
         $include_path = $this->home . '/lib' . PATH_SEPARATOR . ini_get('include_path');
         set_include_path($include_path);
@@ -55,16 +48,37 @@
      */
     public function address_sources($p)
     {
-        // get single instance (for now)
-        $abook = rcube_kolab_contacts::singleton();
-        
-        // maybe here we'll add more than one item
-        $p['sources'][$this->abook_id] = array(
-            'id' => $this->abook_id,
-            'name' => 'Kolab',
-            'readonly' => $abook->readonly,
-            'groups' => $abook->groups,
-        );
+        // setup Kolab backend
+        rcube_kolab::setup();
+
+        // get all folders that have "contact" type
+        $this->kolab = Kolab_List::singleton();
+        $this->folders = $this->kolab->getByType('contact');
+
+        if (PEAR::isError($this->folders)) {
+            raise_error(array(
+              'code' => 600, 'type' => 'php',
+              'file' => __FILE__, 'line' => __LINE__,
+              'message' => "Failed to list contact folders from Kolab server:" . $this->folders->getMessage()),
+            true, false);
+        }
+        else {
+            foreach ($this->folders as $c_folder) {
+                // create instance of rcube_contacts
+                $abook_id = strtolower(asciiwords(strtr($c_folder->name, '/', '-')));
+                $abook = new rcube_kolab_contacts($c_folder->name);
+                $this->sources[$abook_id] = $abook;
+                
+                // register this address source
+                $p['sources'][$abook_id] = array(
+                    'id' => $abook_id,
+                    'name' => $c_folder->name,
+                    'readonly' => $abook->readonly,
+                    'groups' => $abook->groups,
+                );
+            }
+        }
+
         return $p;
     }
  
@@ -74,8 +88,8 @@
      */
     public function get_address_book($p)
     {
-        if ($p['id'] === $this->abook_id) {
-            $p['instance'] = rcube_kolab_contacts::singleton();
+        if ($this->sources[$p['id']]) {
+            $p['instance'] = $this->sources[$p['id']];
         }
         
         return $p;

Modified: trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php
===================================================================
--- trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	2010-11-08 13:52:39 UTC (rev 4196)
+++ trunk/plugins/kolab_addressbook/rcube_kolab_contacts.php	2010-11-08 23:17:28 UTC (rev 4197)
@@ -28,25 +28,14 @@
     private $filter;
     private $result;
     private $imap_folder = 'INBOX/Contacts';
-    
-    
-    /**
-     * Singleton getter
-     */
-    public static function singleton()
-    {
-        if (!self::$instance)
-            self::$instance = new rcube_kolab_contacts;
-        return self::$instance;
-    }
 
 
-    public function __construct()
+    public function __construct($imap_folder = null)
     {
-        // setup Kolab backend
-        rcube_kolab::setup();
+        if ($imap_folder)
+            $this->imap_folder = $imap_folder;
         
-        // fetch objects from Cotnacts folder
+        // fetch objects from Contacts folder
         $this->_kolab = Kolab_List::singleton();
         $this->_folder = $this->_kolab->getFolder($this->imap_folder);
         $this->_storage = $this->_folder->getData();

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list