/
alexashkin
/
telegraph
Обзор
Документация
Войти
/
alexashkin
/
telegraph
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/device/osservice.cpp
98 строк
3 KB
mbarashkov
Методы для open with перенесены в OSService
21 фев 2025, 17:49
21 фев 2025, 17:49
3cbea5e
Код
Авторство
О чём код?
#include "osservice.h" #include <QFile> #include <QProcess> #include <QStandardPaths> #include <QTextStream> #include <QDir> OSService::OSService(QObject *parent) : QObject(parent) { } void OSService::initializeOpenWith() { const QString applicationsLocation(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)); const QString openUrlFilePath(applicationsLocation + "/open-url.desktop"); const QString sailfishBrowserFilePath(applicationsLocation + "/sailfish-browser.desktop"); if (QFile::exists(sailfishBrowserFilePath)) { QFile::remove(sailfishBrowserFilePath); QProcess::startDetached("update-desktop-database " + applicationsLocation); } if (QFile::exists(openUrlFilePath)) { QFile::remove(openUrlFilePath); QProcess::startDetached("update-desktop-database " + applicationsLocation); } const QString desktopFilePath(applicationsLocation + "/telegraf-open-url.desktop"); QFile desktopFile(desktopFilePath); if (desktopFile.exists()) { desktopFile.remove(); QProcess::startDetached("update-desktop-database " + applicationsLocation); } if (desktopFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream fileOut(&desktopFile); fileOut.setCodec("UTF-8"); fileOut << QString("[Desktop Entry]").toUtf8() << "\n"; fileOut << QString("Type=Application").toUtf8() << "\n"; fileOut << QString("Name=Telegraf").toUtf8() << "\n"; fileOut << QString("Icon=ru.telegrafaurora.telegraf").toUtf8() << "\n"; fileOut << QString("NotShowIn=X-MeeGo;").toUtf8() << "\n"; fileOut << QString("MimeType=x-url-handler/t.me;x-scheme-handler/tg;").toUtf8() << "\n"; fileOut << QString("X-Maemo-Service=ru.telegrafaurora.telegraf").toUtf8() << "\n"; fileOut << QString("X-Maemo-Object-Path=/ru/telegrafaurora/telegraf").toUtf8() << "\n"; fileOut << QString("X-Maemo-Method=ru.telegrafaurora.telegraf.openUrl").toUtf8() << "\n"; fileOut << QString("Hidden=true;").toUtf8() << "\n"; fileOut.flush(); desktopFile.close(); QProcess::startDetached("update-desktop-database " + applicationsLocation); } QString dbusPathName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/dbus-1/services"; QDir dbusPath(dbusPathName); if (!dbusPath.exists()) { dbusPath.mkpath(dbusPathName); } QString dbusServiceFileName = dbusPathName + "/ru.telegrafaurora.telegraf.service"; QFile dbusServiceFile(dbusServiceFileName); if (dbusServiceFile.exists()) { dbusServiceFile.remove(); } if (dbusServiceFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream fileOut(&dbusServiceFile); fileOut.setCodec("UTF-8"); fileOut << QString("[D-BUS Service]").toUtf8() << "\n"; fileOut << QString("Name=ru.telegrafaurora.telegraf").toUtf8() << "\n"; fileOut << QString("Exec=sailjail -- /usr/bin/ru.telegrafaurora.telegraf").toUtf8() << "\n"; fileOut.flush(); dbusServiceFile.close(); } } void OSService::removeOpenWith() { QFile::remove(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/telegraf-open-url.desktop"); QProcess::startDetached("update-desktop-database " + QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation)); }