public function insertApp(AppLauncher $app)
 {
     $launcherPath = self::APPS_DIR . '/' . $app['name'] . '.xml';
     $xml = new TranslatedDOMDocument('1.0');
     $root = $xml->createElement('shortcut');
     $xml->appendChild($root);
     $appData = $app->toArray();
     foreach ($appData as $name => $value) {
         $attrEl = $xml->createElement('attribute');
         $root->appendChild($attrEl);
         $nameAttr = $xml->createAttribute('name');
         $nameAttr->appendChild($xml->createTextNode($name));
         $attrEl->appendChild($nameAttr);
         $valueAttr = $xml->createAttribute('value');
         $valueAttr->appendChild($xml->createTextNode($value));
         $attrEl->appendChild($valueAttr);
     }
     $this->dao->write($launcherPath, $xml->saveXML());
 }
 /**
  * Retrieve all shortcuts.
  */
 protected function executeGet()
 {
     $configManager = $this->managers()->getManagerOf('config');
     $fileManager = $this->managers()->getManagerOf('file');
     $translationManager = $this->managers()->getManagerOf('translation');
     if ($this->app->user()->isLogged()) {
         $config = $configManager->open('~/.config/prefered-openers.json');
         $preferedOpeners = $config->read();
     } else {
         $preferedOpeners = array();
     }
     //Retrieve shortcut files list
     $shortcuts = $fileManager->readDir('/usr/share/applications/');
     //Initialize shortcuts list
     $list = array('applications' => array(), 'categories' => array());
     $lang = $translationManager->language();
     //On recupere les infos pour chaque raccourci
     foreach ($shortcuts as $shortcutPath) {
         if ($fileManager->isDir($shortcutPath)) {
             continue;
         }
         if ($fileManager->pathinfo($shortcutPath, PATHINFO_EXTENSION) != 'xml') {
             continue;
         }
         $filename = $fileManager->pathinfo($shortcutPath, PATHINFO_FILENAME);
         $xml = new TranslatedDOMDocument();
         $xml->loadXML($fileManager->read($shortcutPath));
         $attributes = $xml->getTranslatedElementsByTagName('attribute', $lang, 'name');
         $attributesList = array();
         foreach ($attributes as $attribute) {
             $attributesList[$attribute->getAttribute('name')] = $attribute->getAttribute('value');
         }
         $attributesList['prefered_open'] = '';
         if (array_key_exists($filename, $preferedOpeners)) {
             $opens = $preferedOpeners[$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'][$filename] = $attributesList;
     }
     $favoritesConfig = $this->_getFavoritesConfig();
     foreach ($favoritesConfig->read() 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);
     });
     //Retrieve categories list
     $categories = $fileManager->readDir('/usr/share/categories/');
     foreach ($categories as $shortcutPath) {
         if ($fileManager->isDir($shortcutPath)) {
             continue;
         }
         if ($fileManager->pathinfo($shortcutPath, PATHINFO_EXTENSION) != 'xml') {
             continue;
         }
         $xml = new TranslatedDOMDocument();
         $xml->loadXML($fileManager->read($shortcutPath));
         $attributes = $xml->getTranslatedElementsByTagName('attribute', $lang, 'name');
         $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;
     }
     return $list;
 }