void DesktopFileModel::fillDataReally() { beginResetModel(); _modelData.clear(); endResetModel(); QStringList desktopPath; desktopPath << "/usr/share/applications"; desktopPath << QString("%1/.local/share/applications").arg(QDir::homePath()); foreach (const QString &path, desktopPath) { QDir desktopDir(path); foreach (const QString &desktop, desktopDir.entryList(QStringList() << "*.desktop", QDir::Files, QDir::NoSort)) { MDesktopEntry entry(QString("%1/%2").arg(path).arg(desktop)); if (entry.isValid() && entry.type() == "Application") { if (!_showHidden && (entry.icon().isEmpty() || entry.icon() == "icon-launcher-dummy" || entry.noDisplay())) { continue; } beginInsertRows(QModelIndex(), rowCount(), rowCount()); QVariantMap data; data["name"] = entry.name(); data["icon"] = getIconPath(entry.icon()); data["path"] = entry.fileName(); // qDebug() << "added:" << entry.fileName(); _modelData.append(data); endInsertRows(); } QCoreApplication::processEvents(); } }
// // Step 6 // Extract icon and create .desktop files // bool InstallWindow::Step6CreateShortcuts() { PrintStep(tr("Prepare desktop shortcut")); QDir desktopDir(DESKTOP_ENTRY_PATH), iconDir(ICONS_PATH), dbusDir(DBUS_PATH); if (!desktopDir.exists()) { if (!desktopDir.mkpath(DESKTOP_ENTRY_PATH)) return Failed(tr("Cannot create directory %1") .arg(desktopDir.path())); } if (!iconDir.exists()) { if (!iconDir.mkpath(ICONS_PATH)) return Failed(tr("Cannot create directory %1") .arg(iconDir.path())); } if (!dbusDir.exists()) { if (!dbusDir.mkpath(DBUS_PATH)) return Failed(tr("Cannot create directory %1") .arg(dbusDir.path())); } // Icon path QString fullDataDir(_game->DataPath() + "/usr/palm/applications/" + _game->JsonID() + "/"); QFile iconFile(fullDataDir + _game->JsonIcon()); QString saneName =_game->JsonTitle().toLower(); QString newName(QString(ICONS_PATH) + QString("/") + saneName + ".png"); if (iconFile.exists() && !QFile::exists(newName)) { if (!iconFile.copy(newName)) { return Failed(tr("Cannot copy icon ") + iconFile.fileName() + "to " + ICONS_PATH + "/" + saneName + ".png"); } } QString desktopEntry = "[Desktop Entry]\n" "Encoding=UTF-8\n" "Version=1.0\n" "Type=Application\n" "Name=" + _game->JsonTitle() + "\n" "Exec=" + _game->Exec() + "\n" "X-Osso-Type=application/x-executable\n" "X-Osso-Service=" + _game->DBusName() + "\n" "X-Preenv-Generated=true\n" "X-Preenv-Vendor=" + _game->JsonVendor() + "\n" "X-Maemo-Category=Games\n" "Icon=" + saneName + "\n"; QFile desktopFile(QString(DESKTOP_ENTRY_PATH) + QString("/") + saneName + ".desktop"); if (!desktopFile.open(QFile::WriteOnly | QFile::Text)) return Failed(tr("Cannot create .desktop file ") + desktopFile.fileName()); desktopFile.write(desktopEntry.toLocal8Bit()); desktopFile.close(); QString dbusEntry = "[D-BUS Service]\n" "Name=" + _game->DBusName() + "\n" "Exec=" + _game->Exec() + "\n"; QFile dbusFile(QString(DBUS_PATH) + QString("/") + saneName + ".service"); if (!dbusFile.open(QFile::WriteOnly | QFile::Text)) return Failed(tr("Cannot create DBUS .service file ") + dbusFile.fileName()); dbusFile.write(dbusEntry.toLocal8Bit()); dbusFile.close(); PrintOK(); return Step7PostInstall(); }