2013-10-02 21:06:33 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@owncloud.com>
|
|
|
|
* Copyright (C) by Daniel Molkentin <danimo@owncloud.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
2014-08-16 05:11:19 +04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#endif
|
|
|
|
|
2013-10-02 21:06:33 +04:00
|
|
|
static void setupFavLink_private(const QString &folder) {
|
|
|
|
// Nautilus: add to ~/.gtk-bookmarks
|
|
|
|
QFile gtkBookmarks(QDir::homePath()+QLatin1String("/.gtk-bookmarks"));
|
|
|
|
QByteArray folderUrl = "file://" + folder.toUtf8();
|
|
|
|
if (gtkBookmarks.open(QFile::ReadWrite)) {
|
|
|
|
QByteArray places = gtkBookmarks.readAll();
|
|
|
|
if (!places.contains(folderUrl)) {
|
|
|
|
places += folderUrl;
|
|
|
|
gtkBookmarks.reset();
|
|
|
|
gtkBookmarks.write(places + '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-31 05:10:44 +04:00
|
|
|
// returns the autostart directory the linux way
|
|
|
|
// and respects the XDG_CONFIG_HOME env variable
|
|
|
|
QString getUserAutostartDir_private()
|
|
|
|
{
|
2014-08-16 05:11:19 +04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
|
|
|
QString config = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
|
|
|
|
#else
|
2014-04-23 20:59:40 +04:00
|
|
|
QString config = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
|
2013-12-31 05:10:44 +04:00
|
|
|
|
|
|
|
if (config.isEmpty()) {
|
|
|
|
config = QDir::homePath()+QLatin1String("/.config");
|
|
|
|
}
|
2014-08-16 05:11:19 +04:00
|
|
|
#endif
|
2013-12-31 05:10:44 +04:00
|
|
|
config += QLatin1String("/autostart/");
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2013-10-02 21:06:33 +04:00
|
|
|
bool hasLaunchOnStartup_private(const QString &appName)
|
|
|
|
{
|
2013-12-31 05:10:44 +04:00
|
|
|
QString desktopFileLocation = getUserAutostartDir_private()+appName+QLatin1String(".desktop");
|
2013-10-02 21:06:33 +04:00
|
|
|
return QFile::exists(desktopFileLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLaunchOnStartup_private(const QString &appName, const QString& guiName, bool enable)
|
|
|
|
{
|
2013-12-31 05:10:44 +04:00
|
|
|
QString userAutoStartPath = getUserAutostartDir_private();
|
2013-10-02 21:06:33 +04:00
|
|
|
QString desktopFileLocation = userAutoStartPath+appName+QLatin1String(".desktop");
|
|
|
|
if (enable) {
|
2014-05-19 14:41:15 +04:00
|
|
|
if (!QDir().exists(userAutoStartPath) && !QDir().mkpath(userAutoStartPath)) {
|
2013-10-02 21:06:33 +04:00
|
|
|
qDebug() << "Could not create autostart directory";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QFile iniFile(desktopFileLocation);
|
|
|
|
if (!iniFile.open(QIODevice::WriteOnly)) {
|
|
|
|
qDebug() << "Could not write auto start entry" << desktopFileLocation;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTextStream ts(&iniFile);
|
|
|
|
ts.setCodec("UTF-8");
|
|
|
|
ts << QLatin1String("[Desktop Entry]") << endl
|
|
|
|
<< QLatin1String("Name=") << guiName << endl
|
|
|
|
<< QLatin1String("GenericName=") << QLatin1String("File Synchronizer") << endl
|
|
|
|
<< QLatin1String("Exec=") << QCoreApplication::applicationFilePath() << endl
|
|
|
|
<< QLatin1String("Terminal=") << "false" << endl
|
2014-04-07 17:14:58 +04:00
|
|
|
<< QLatin1String("Icon=") << appName.toLower() << endl // always use lowercase for icons
|
2013-10-02 21:06:33 +04:00
|
|
|
<< QLatin1String("Categories=") << QLatin1String("Network") << endl
|
|
|
|
<< QLatin1String("Type=") << QLatin1String("Application") << endl
|
|
|
|
<< QLatin1String("StartupNotify=") << "false" << endl
|
|
|
|
<< QLatin1String("X-GNOME-Autostart-enabled=") << "true" << endl
|
|
|
|
;
|
|
|
|
} else {
|
|
|
|
if (!QFile::remove(desktopFileLocation)) {
|
|
|
|
qDebug() << "Could not remove autostart desktop file";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 23:52:41 +04:00
|
|
|
|
|
|
|
static inline bool hasDarkSystray_private()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|