From 8260b104e56fd959806e2df2fcdca9ffb60a9821 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Wed, 22 Nov 2023 15:36:05 +0100 Subject: [PATCH] Linux : Generate linphone.desktop file to ~/.local/share/applications from menu. --- linphone-app/assets/languages/cs.ts | 10 +++++ linphone-app/assets/languages/da.ts | 10 +++++ linphone-app/assets/languages/de.ts | 10 +++++ linphone-app/assets/languages/en.ts | 10 +++++ linphone-app/assets/languages/es.ts | 10 +++++ linphone-app/assets/languages/fr_FR.ts | 10 +++++ linphone-app/assets/languages/hu.ts | 10 +++++ linphone-app/assets/languages/it.ts | 10 +++++ linphone-app/assets/languages/ja.ts | 10 +++++ linphone-app/assets/languages/lt.ts | 10 +++++ linphone-app/assets/languages/pt_BR.ts | 10 +++++ linphone-app/assets/languages/ru.ts | 10 +++++ linphone-app/assets/languages/sv.ts | 10 +++++ linphone-app/assets/languages/tr.ts | 10 +++++ linphone-app/assets/languages/uk.ts | 10 +++++ linphone-app/assets/languages/zh_CN.ts | 10 +++++ linphone-app/src/app/App.cpp | 45 ++++++++++++++----- linphone-app/src/app/App.hpp | 5 +++ .../ui/views/App/Main/MainWindowMenuBar.qml | 7 +++ .../views/App/Main/MainWindowTopMenuBar.qml | 7 ++- 20 files changed, 212 insertions(+), 12 deletions(-) diff --git a/linphone-app/assets/languages/cs.ts b/linphone-app/assets/languages/cs.ts index 424d13501..9a91858c3 100644 --- a/linphone-app/assets/languages/cs.ts +++ b/linphone-app/assets/languages/cs.ts @@ -2056,6 +2056,11 @@ Klikněte zde: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Nahrávky + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2081,6 +2086,11 @@ Klikněte zde: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Nahrávky + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/da.ts b/linphone-app/assets/languages/da.ts index 5ec4d08ae..328c06d37 100644 --- a/linphone-app/assets/languages/da.ts +++ b/linphone-app/assets/languages/da.ts @@ -2044,6 +2044,11 @@ Klik her: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Klik her: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/de.ts b/linphone-app/assets/languages/de.ts index 9b51c35b7..7415d1d42 100644 --- a/linphone-app/assets/languages/de.ts +++ b/linphone-app/assets/languages/de.ts @@ -2044,6 +2044,11 @@ Klicken Sie hier: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Aufzeichnungen + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Klicken Sie hier: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Aufzeichnungen + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/en.ts b/linphone-app/assets/languages/en.ts index 123d79b63..6f99490d6 100644 --- a/linphone-app/assets/languages/en.ts +++ b/linphone-app/assets/languages/en.ts @@ -2044,6 +2044,11 @@ Click here: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Recordings + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + Export %1.desktop file to applications + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Click here: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Recordings + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + Export %1.desktop file to applications + ManageAccounts diff --git a/linphone-app/assets/languages/es.ts b/linphone-app/assets/languages/es.ts index adc609ff5..c5de931b6 100644 --- a/linphone-app/assets/languages/es.ts +++ b/linphone-app/assets/languages/es.ts @@ -2044,6 +2044,11 @@ Haga clic aquí: <a href="%1">%1 </a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Haga clic aquí: <a href="%1">%1 </a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/fr_FR.ts b/linphone-app/assets/languages/fr_FR.ts index 2879dbe3e..504cdbae0 100644 --- a/linphone-app/assets/languages/fr_FR.ts +++ b/linphone-app/assets/languages/fr_FR.ts @@ -2044,6 +2044,11 @@ Cliquez ici : <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Enregistrements + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Cliquez ici : <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. Enregistrements + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/hu.ts b/linphone-app/assets/languages/hu.ts index 21679dc56..d220cb88c 100644 --- a/linphone-app/assets/languages/hu.ts +++ b/linphone-app/assets/languages/hu.ts @@ -2033,6 +2033,11 @@ Kattintson ide: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2058,6 +2063,11 @@ Kattintson ide: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/it.ts b/linphone-app/assets/languages/it.ts index d2ed74cc4..7f26b25c9 100644 --- a/linphone-app/assets/languages/it.ts +++ b/linphone-app/assets/languages/it.ts @@ -2044,6 +2044,11 @@ Clicca: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Clicca: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/ja.ts b/linphone-app/assets/languages/ja.ts index 95ca61732..1b16a0e64 100644 --- a/linphone-app/assets/languages/ja.ts +++ b/linphone-app/assets/languages/ja.ts @@ -2033,6 +2033,11 @@ 'Recordings' : Label for the recordings menu. 録音 + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2058,6 +2063,11 @@ 'Recordings' : Label for the recordings menu. 録音 + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/lt.ts b/linphone-app/assets/languages/lt.ts index 02e996761..7e768d0a2 100644 --- a/linphone-app/assets/languages/lt.ts +++ b/linphone-app/assets/languages/lt.ts @@ -2055,6 +2055,11 @@ Spustelėkite čia: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2080,6 +2085,11 @@ Spustelėkite čia: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/pt_BR.ts b/linphone-app/assets/languages/pt_BR.ts index 0d285739a..b07f3139d 100644 --- a/linphone-app/assets/languages/pt_BR.ts +++ b/linphone-app/assets/languages/pt_BR.ts @@ -2044,6 +2044,11 @@ Clique aqui: <a href="%1">%1 </a> 'Recordings' : Label for the recordings menu. Gravações + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Clique aqui: <a href="%1">%1 </a> 'Recordings' : Label for the recordings menu. Gravações + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/ru.ts b/linphone-app/assets/languages/ru.ts index 128692583..f21fbc900 100644 --- a/linphone-app/assets/languages/ru.ts +++ b/linphone-app/assets/languages/ru.ts @@ -2055,6 +2055,11 @@ 'Recordings' : Label for the recordings menu. Записи + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2080,6 +2085,11 @@ 'Recordings' : Label for the recordings menu. Записи + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/sv.ts b/linphone-app/assets/languages/sv.ts index 4d740b855..befde22b4 100644 --- a/linphone-app/assets/languages/sv.ts +++ b/linphone-app/assets/languages/sv.ts @@ -2044,6 +2044,11 @@ Klicka här: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2069,6 +2074,11 @@ Klicka här: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/tr.ts b/linphone-app/assets/languages/tr.ts index 144eada19..a34e88dec 100644 --- a/linphone-app/assets/languages/tr.ts +++ b/linphone-app/assets/languages/tr.ts @@ -2033,6 +2033,11 @@ Buraya tıklayın: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2058,6 +2063,11 @@ Buraya tıklayın: <a href="%1">%1</a> 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/uk.ts b/linphone-app/assets/languages/uk.ts index 96f0e2482..48e7b91a1 100644 --- a/linphone-app/assets/languages/uk.ts +++ b/linphone-app/assets/languages/uk.ts @@ -2055,6 +2055,11 @@ 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2080,6 +2085,11 @@ 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/assets/languages/zh_CN.ts b/linphone-app/assets/languages/zh_CN.ts index 63f1332ea..cb50a0553 100644 --- a/linphone-app/assets/languages/zh_CN.ts +++ b/linphone-app/assets/languages/zh_CN.ts @@ -2033,6 +2033,11 @@ 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + MainWindowTopMenuBar @@ -2058,6 +2063,11 @@ 'Recordings' : Label for the recordings menu. + + exportDesktopFile + 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + + ManageAccounts diff --git a/linphone-app/src/app/App.cpp b/linphone-app/src/app/App.cpp index e85c834bc..8c9bdf1f8 100644 --- a/linphone-app/src/app/App.cpp +++ b/linphone-app/src/app/App.cpp @@ -73,6 +73,7 @@ using namespace std; namespace { #ifdef Q_OS_LINUX const QString AutoStartDirectory(QDir::homePath().append(QStringLiteral("/.config/autostart/"))); +const QString ApplicationsDirectory(QDir::homePath().append(QStringLiteral("/.local/share/applications/"))); #elif defined(Q_OS_MACOS) const QString OsascriptExecutable(QStringLiteral("osascript")); #else @@ -464,6 +465,7 @@ void App::initContentApp () { mEngine->addImageProvider(ThumbnailProvider::ProviderId, new ThumbnailProvider()); mEngine->rootContext()->setContextProperty("applicationName", APPLICATION_NAME); + mEngine->rootContext()->setContextProperty("executableName", EXECUTABLE_NAME); #ifdef APPLICATION_URL mEngine->rootContext()->setContextProperty("applicationUrl", APPLICATION_URL); @@ -997,23 +999,37 @@ void App::setAutoStart (bool enabled) { } const QString confPath(AutoStartDirectory + EXECUTABLE_NAME ".desktop"); + if(generateDesktopFile(confPath, !enabled)) { + mAutoStart = enabled; + emit autoStartChanged(enabled); + } +} +void App::exportDesktopFile(){ + QDir dir(ApplicationsDirectory); + if (!dir.exists() && !dir.mkpath(ApplicationsDirectory)) { + qWarning() << QStringLiteral("Unable to build applications dir path: `%1`.").arg(ApplicationsDirectory); + return; + } + + const QString confPath(ApplicationsDirectory + EXECUTABLE_NAME ".desktop"); + if(generateDesktopFile(confPath, true)) + generateDesktopFile(confPath, false); +} +bool App::generateDesktopFile(const QString& confPath, bool remove){ qInfo() << QStringLiteral("Updating `%1`...").arg(confPath); QFile file(confPath); - if (!enabled) { + if (remove) { if (file.exists() && !file.remove()) { qWarning() << QLatin1String("Unable to remove autostart file: `" EXECUTABLE_NAME ".desktop`."); - return; + return false; } - - mAutoStart = enabled; - emit autoStartChanged(enabled); - return; + return true; } if (!file.open(QFile::WriteOnly)) { qWarning() << "Unable to open autostart file: `" EXECUTABLE_NAME ".desktop`."; - return; + return false; } const QString binPath(applicationFilePath()); @@ -1044,11 +1060,10 @@ void App::setAutoStart (bool enabled) { "Exec=" + exec + " --iconified\n" "Terminal=false\n" "Categories=Network;Telephony;\n" - "MimeType=x-scheme-handler/sip-" EXECUTABLE_NAME ";x-scheme-handler/sip;x-scheme-handler/sips-" EXECUTABLE_NAME ";x-scheme-handler/sips;x-scheme-handler/tel;x-scheme-handler/callto;\n" + "MimeType=x-scheme-handler/sip-" EXECUTABLE_NAME ";x-scheme-handler/sip;x-scheme-handler/sips-" EXECUTABLE_NAME ";x-scheme-handler/sips;x-scheme-handler/tel;x-scheme-handler/callto;x-scheme-handler/" EXECUTABLE_NAME "-config;\n" + "X-PulseAudio-Properties=media.role=phone\n" ); - - mAutoStart = enabled; - emit autoStartChanged(enabled); + return true; } #elif defined(Q_OS_MACOS) @@ -1208,3 +1223,11 @@ bool App::isPdfAvailable(){ return false; #endif } + +bool App::isLinux(){ +#ifdef Q_OS_LINUX + return true; +#else + return false; +#endif +} diff --git a/linphone-app/src/app/App.hpp b/linphone-app/src/app/App.hpp index 2fc5b36a6..352c158f2 100644 --- a/linphone-app/src/app/App.hpp +++ b/linphone-app/src/app/App.hpp @@ -127,6 +127,11 @@ public: // Check module availability when no dependencies are needed (else use SettingsModel) Q_INVOKABLE static bool isPdfAvailable(); + Q_INVOKABLE static bool isLinux(); +#ifdef Q_OS_LINUX + Q_INVOKABLE void exportDesktopFile(); + bool generateDesktopFile(const QString& confPath, bool remove); +#endif public slots: void stateChanged(Qt::ApplicationState); diff --git a/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml b/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml index b6220b88f..49fd53797 100644 --- a/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml +++ b/linphone-app/ui/views/App/Main/MainWindowMenuBar.qml @@ -89,6 +89,13 @@ Item { onTriggered: App.checkForUpdates(true) } + MenuItem{ + visible: App.isLinux() + //: 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + text: qsTr('exportDesktopFile').arg(executableName) + onTriggered: App.exportDesktopFile() + } + MenuItem { text: qsTr('about') diff --git a/linphone-app/ui/views/App/Main/MainWindowTopMenuBar.qml b/linphone-app/ui/views/App/Main/MainWindowTopMenuBar.qml index 8381b4ea7..28ff24006 100644 --- a/linphone-app/ui/views/App/Main/MainWindowTopMenuBar.qml +++ b/linphone-app/ui/views/App/Main/MainWindowTopMenuBar.qml @@ -42,7 +42,12 @@ MenuBar { role: MenuItem.ApplicationSpecificRole onTriggered: App.checkForUpdates(true) } - + MenuItem{ + visible: App.isLinux() + //: 'Export %1.desktop file to applications' : Label menu to export the %1.desktop file to the ~/.local/share/applications/ folder on Linux (%1 is the exectuable name) + text: qsTr('exportDesktopFile').arg(executableName) + onTriggered: App.exportDesktopFile() + } MenuItem { text: qsTr('about') role: MenuItem.AboutRole