/**
  * Definir tous les parametres d'une configuration.
  * @param string $path Le chemin vers le fichier de configuration.
  * @param array $data Un tableau contenant les nouveaux parametres.
  */
 protected function setConfig($path, array $data)
 {
     $config = new Config($this->webos);
     $config->load($path);
     foreach ($config->getConfig() as $index => $value) {
         if (!array_key_exists($index, $data)) {
             $config->remove($index);
         }
     }
     foreach ($data as $index => $value) {
         $config->set($index, $value);
     }
     $config->save();
 }
 /**
  * Recuperer tous les raccourcis.
  */
 protected function get()
 {
     if ($this->webos->getUser()->isConnected()) {
         $path = '~/.config/prefered-openers.xml';
         $config = new Config($this->webos);
         if (!$this->webos->managers()->get('File')->exists($path)) {
             $file = $this->webos->managers()->get('File')->createFile($path);
             $file->setContents($config->saveXML());
         }
         $config->load($path);
         $preferedOpeners = $config->getConfig();
     } else {
         $preferedOpeners = array();
     }
     //On recupere la liste des raccourcis
     $applications = $this->webos->managers()->get('File')->get('/usr/share/applications/')->contents();
     //On initialise la liste
     $list = array('applications' => array(), 'categories' => array());
     //On recupere les infos pour chaque raccourci
     foreach ($applications as $shortcut) {
         if ($shortcut->isDir()) {
             continue;
         }
         if ($shortcut->extension() != 'xml') {
             continue;
         }
         $xml = new \DOMDocument();
         $xml->loadXML($shortcut->contents());
         $attributes = $xml->getElementsByTagName('attribute');
         $attributesList = array();
         foreach ($attributes as $attribute) {
             $attributesList[$attribute->getAttribute('name')] = $attribute->getAttribute('value');
         }
         $attributesList['prefered_open'] = '';
         if (array_key_exists($shortcut->filename(), $preferedOpeners)) {
             $opens = $preferedOpeners[$shortcut->filename()];
             $attributesList['prefered_open'] = $opens;
             if (array_key_exists('open', $attributesList)) {
                 $attributesList['open'] .= ',' . $opens;
             } else {
                 $attributesList['open'] = $opens;
             }
         }
         if (array_key_exists('visible', $attributesList) && (int) $attributesList['visible'] == 0) {
             continue;
         }
         $list['applications'][$shortcut->filename()] = $attributesList;
     }
     $favoritesConfig = $this->_getFavoritesConfig();
     foreach ($favoritesConfig->getConfig() as $app => $value) {
         if ((int) $value > 0 && array_key_exists($app, $list['applications'])) {
             $list['applications'][$app]['favorite'] = (int) $value;
         }
     }
     //On trie le tableau
     uasort($list['applications'], function ($a, $b) {
         $specialChars = array('Š' => 'S', 'š' => 's', 'Ð' => 'Dj', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y', 'ƒ' => 'f');
         $aTitle = strtr($a['title'], $specialChars);
         $bTitle = strtr($b['title'], $specialChars);
         return strcmp($aTitle, $bTitle);
     });
     //On recupere la liste des categories
     $categories = $this->webos->managers()->get('File')->get('/usr/share/categories/')->contents();
     //On recupere les infos pour cahque categorie
     foreach ($categories as $shortcut) {
         if ($shortcut->isDir()) {
             continue;
         }
         if ($shortcut->extension() != 'xml') {
             continue;
         }
         $xml = new \DOMDocument();
         $xml->loadXML($shortcut->contents());
         $attributes = $xml->getElementsByTagName('attribute');
         $attributesList = array();
         foreach ($attributes as $attribute) {
             $attributesList[$attribute->getAttribute('name')] = $attribute->getAttribute('value');
         }
         if (array_key_exists('visible', $attributesList) && (int) $attributesList['visible'] == 0) {
             continue;
         }
         $list['categories'][] = $attributesList;
     }
     $this->webos->getHTTPResponse()->setData($list);
 }