mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-04-17 20:08:28 +00:00
feat(App): supports autostart on GNU/Linux
This commit is contained in:
parent
da77d41e7e
commit
d073177da0
13 changed files with 150 additions and 0 deletions
|
|
@ -1599,6 +1599,10 @@ Server URL ist nicht konfiguriert.</translation>
|
|||
<source>dataTitle</source>
|
||||
<translation>UI-Daten</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1604,6 +1604,10 @@ your friend's SIP address or username.</translation>
|
|||
<source>dataTitle</source>
|
||||
<translation>UI Data</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation>Autostart app</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1602,6 +1602,10 @@ Cliquez ici : <a href="%1">%1</a>
|
|||
<source>dataTitle</source>
|
||||
<translation>Données</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation>Démarrer auto. l'app</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1599,6 +1599,10 @@
|
|||
<source>dataTitle</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1604,6 +1604,10 @@ Tiesiog, įveskite savo draugo SIP adresą ar naudotojo vardą.</translation>
|
|||
<source>dataTitle</source>
|
||||
<translation>Naudotojo sąsajos duomenys</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1604,6 +1604,10 @@ o endereço SIP ou nome de usuário do seu amigo.</translation>
|
|||
<source>dataTitle</source>
|
||||
<translation>Dados UI</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1602,6 +1602,10 @@
|
|||
<source>dataTitle</source>
|
||||
<translation>Данные пользовательского интерфейса</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1602,6 +1602,10 @@ Klicka här: <a href="%1">%1</a>
|
|||
<source>dataTitle</source>
|
||||
<translation>Användargränssnitt data</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -1604,6 +1604,10 @@ arkadaşınızın SIP adresini veya kullanıcı adını girin.</translation>
|
|||
<source>dataTitle</source>
|
||||
<translation>Kullanıcı Arayüzü Verisi</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>autoStartLabel</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SettingsVideo</name>
|
||||
|
|
|
|||
|
|
@ -70,8 +70,32 @@ namespace {
|
|||
constexpr char AboutPath[] = "qrc:/ui/views/App/Main/Dialogs/About.qml";
|
||||
|
||||
constexpr char AssistantViewName[] = "Assistant";
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
static QString AutoStartDirectory(
|
||||
QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).at(0) + QLatin1String("/autostart/")
|
||||
);
|
||||
#endif // ifdef Q_OS_LINUX
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
static inline bool autoStartEnabled () {
|
||||
return QDir(AutoStartDirectory).exists() && QFile(AutoStartDirectory + EXECUTABLE_NAME ".desktop").exists();
|
||||
}
|
||||
#elif defined(Q_OS_MACOS)
|
||||
static inline bool autoStartEnabled () {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
static inline bool autoStartEnabled () {
|
||||
return false;
|
||||
}
|
||||
#endif // ifdef Q_OS_LINUX
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static inline bool installLocale (App &app, QTranslator &translator, const QLocale &locale) {
|
||||
return translator.load(locale, LanguagePath) && app.installTranslator(&translator);
|
||||
}
|
||||
|
|
@ -125,6 +149,8 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U
|
|||
if (mParser->isSet("version"))
|
||||
mParser->showVersion();
|
||||
|
||||
mAutoStart = autoStartEnabled();
|
||||
|
||||
qInfo() << QStringLiteral("Starting " APPLICATION_NAME " (bin: " EXECUTABLE_NAME ")");
|
||||
qInfo() << QStringLiteral("Use locale: %1").arg(mLocale);
|
||||
}
|
||||
|
|
@ -578,6 +604,71 @@ QString App::getLocale () const {
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
||||
void App::setAutoStart (bool enabled) {
|
||||
if (enabled == mAutoStart)
|
||||
return;
|
||||
|
||||
QDir dir(AutoStartDirectory);
|
||||
if (!dir.exists() && !dir.mkpath(AutoStartDirectory)) {
|
||||
qWarning() << QStringLiteral("Unable to build autostart dir path: `%1`.").arg(AutoStartDirectory);
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(AutoStartDirectory + EXECUTABLE_NAME ".desktop");
|
||||
|
||||
if (!enabled) {
|
||||
if (file.exists() && !file.remove()) {
|
||||
qWarning() << QLatin1String("Unable to remove autostart file: `" EXECUTABLE_NAME ".desktop`.");
|
||||
return;
|
||||
}
|
||||
|
||||
mAutoStart = enabled;
|
||||
emit autoStartChanged(enabled);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
qWarning() << "Unable to open autostart file: `" EXECUTABLE_NAME ".desktop`.";
|
||||
return;
|
||||
}
|
||||
|
||||
QString fileContent(
|
||||
"[Desktop Entry]\n"
|
||||
"Name=" APPLICATION_NAME "\n"
|
||||
"GenericName=SIP Phone\n"
|
||||
"Comment=" APPLICATION_DESCRIPTION "\n"
|
||||
"Type=Application\n"
|
||||
"Exec=" + applicationFilePath() + "\n"
|
||||
"Icon=\n"
|
||||
"Terminal=false\n"
|
||||
"Categories=Network;Telephony;\n"
|
||||
"MimeType=x-scheme-handler/sip-linphone;x-scheme-handler/sip;x-scheme-handler/sips-linphone;x-scheme-handler/sips;\n"
|
||||
);
|
||||
QTextStream out(&file);
|
||||
out << fileContent;
|
||||
|
||||
mAutoStart = enabled;
|
||||
emit autoStartChanged(enabled);
|
||||
}
|
||||
|
||||
#elif defined(Q_OS_MACOS)
|
||||
|
||||
void App::setAutoStart (bool enabled) {
|
||||
Q_UNUSED(enabled);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void App::setAutoStart (bool enabled) {
|
||||
Q_UNUSED(enabled);
|
||||
}
|
||||
|
||||
#endif // ifdef Q_OS_LINUX
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void App::openAppAfterInit (bool mustBeIconified) {
|
||||
qInfo() << QStringLiteral("Open " APPLICATION_NAME " app.");
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ class App : public SingleApplication {
|
|||
Q_PROPERTY(QVariantList availableLocales READ getAvailableLocales CONSTANT);
|
||||
Q_PROPERTY(QString qtVersion READ getQtVersion CONSTANT);
|
||||
|
||||
Q_PROPERTY(bool autoStart READ getAutoStart WRITE setAutoStart NOTIFY autoStartChanged);
|
||||
|
||||
public:
|
||||
App (int &argc, char *argv[]);
|
||||
~App ();
|
||||
|
|
@ -100,6 +102,8 @@ public:
|
|||
signals:
|
||||
void configLocaleChanged (const QString &locale);
|
||||
|
||||
void autoStartChanged (bool enabled);
|
||||
|
||||
private:
|
||||
void createParser ();
|
||||
|
||||
|
|
@ -122,6 +126,12 @@ private:
|
|||
return mAvailableLocales;
|
||||
}
|
||||
|
||||
bool getAutoStart () const {
|
||||
return mAutoStart;
|
||||
}
|
||||
|
||||
void setAutoStart (bool enabled);
|
||||
|
||||
void openAppAfterInit (bool mustBeIconified = false);
|
||||
|
||||
static void checkForUpdate ();
|
||||
|
|
@ -133,6 +143,8 @@ private:
|
|||
QVariantList mAvailableLocales;
|
||||
QString mLocale;
|
||||
|
||||
bool mAutoStart = false;
|
||||
|
||||
QCommandLineParser *mParser = nullptr;
|
||||
|
||||
QQmlApplicationEngine *mEngine = nullptr;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#cmakedefine APPLICATION_NAME "${APPLICATION_NAME}"
|
||||
#cmakedefine APPLICATION_DESCRIPTION "${APPLICATION_DESCRIPTION}"
|
||||
#cmakedefine ENABLE_UPDATE_CHECK 1
|
||||
#cmakedefine EXECUTABLE_NAME "${EXECUTABLE_NAME}"
|
||||
#cmakedefine MSPLUGINS_DIR "${MSPLUGINS_DIR}"
|
||||
|
|
|
|||
|
|
@ -146,6 +146,16 @@ TabContainer {
|
|||
onClicked: SettingsModel.exitOnClose = !checked
|
||||
}
|
||||
}
|
||||
|
||||
FormGroup {
|
||||
label: qsTr('autoStartLabel')
|
||||
|
||||
Switch {
|
||||
checked: App.autoStart
|
||||
|
||||
onClicked: App.autoStart = !checked
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue