Initial implementation of auto-start function on Linux.

This commit is contained in:
Martin Rotter 2013-06-24 20:19:20 +02:00
parent 9e5b205caa
commit cb9f5521ed
4 changed files with 48 additions and 28 deletions

View File

@ -47,12 +47,6 @@ endif(EXISTS "${PROJECT_SOURCE_DIR}/.git")
message(STATUS "[${APP_LOW_NAME}] Revision number obtained: " ${APP_REVISION} ".")
# Configure internal C++ defines.
configure_file (
${PROJECT_SOURCE_DIR}/src/core/defs.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/core/defs.h
)
# Configure executable "properties" for Windows.
if(WIN32)
message(STATUS "[${APP_LOW_NAME}] Generating executable file properties.")
@ -69,8 +63,15 @@ if(UNIX)
${PROJECT_SOURCE_DIR}/resources/desktop/rssguard.desktop.in
${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/rssguard.desktop
)
set(DESKTOP_ENTRY ${CMAKE_INSTALL_PREFIX}/share/applications)
endif(UNIX)
# Configure internal C++ defines.
configure_file (
${PROJECT_SOURCE_DIR}/src/core/defs.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/core/defs.h
)
# Define some useful DEBUG for, ehrm, debug build.
if(CMAKE_BUILD_TYPE STREQUAL "release" OR CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RELEASE")
message(STATUS "[${APP_LOW_NAME}] A release build (non-debug) is chosen. Debugging outputs are silently ignored.")

View File

@ -25,6 +25,8 @@
#define APP_IS_RUNNING "app_is_running"
#if defined(Q_OS_LINUX)
#define APP_DESKTOP_ENTRY_PATH "@DESKTOP_ENTRY@"
#define APP_DESKTOP_ENTRY_FILE "@APP_LOW_NAME@.desktop"
#define APP_LANG_PATH APP_PREFIX + QString("/share/rssguard/l10n")
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")

View File

@ -33,27 +33,13 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
// Use proper freedesktop.org way to auto-start the application on Linux.
// INFO: http://standards.freedesktop.org/autostart-spec/latest/
#elif defined(Q_OS_LINUX)
QString xdg_config_path(qgetenv("XDG_CONFIG_HOME"));
QString desktop_file_location;
QString desktop_file_location = SystemFactory::getAutostartDesktopFileLocation();
if (!xdg_config_path.isEmpty()) {
// XDG_CONFIG_HOME variable is specified. Look for .desktop file
// in 'autostart' subdirectory.
desktop_file_location = xdg_config_path + "/autostart/rssguard.desktop";
}
else {
// Desired variable is not set, look for the default 'autostart' subdirectory.
QString home_directory(qgetenv("HOME"));
if (!home_directory.isEmpty()) {
// Home directory exists. Check if target .desktop file exists and
// return according status.
desktop_file_location = home_directory + "/.config/autostart/rssguard.desktop";
}
else {
// No correct path was found.
if (desktop_file_location.isEmpty()) {
qDebug("Searching for auto-start function status failed. HOME variable not found.");
return SystemFactory::Unavailable;
}
}
// We found correct path, now check if file exists and return correct status.
if (QFile::exists(desktop_file_location)) {
@ -69,6 +55,29 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
#endif
}
QString SystemFactory::getAutostartDesktopFileLocation() {
QString xdg_config_path(qgetenv("XDG_CONFIG_HOME"));
QString desktop_file_location;
if (!xdg_config_path.isEmpty()) {
// XDG_CONFIG_HOME variable is specified. Look for .desktop file
// in 'autostart' subdirectory.
desktop_file_location = xdg_config_path + "/autostart/" + APP_DESKTOP_ENTRY_FILE;
}
else {
// Desired variable is not set, look for the default 'autostart' subdirectory.
QString home_directory(qgetenv("HOME"));
if (!home_directory.isEmpty()) {
// Home directory exists. Check if target .desktop file exists and
// return according status.
desktop_file_location = home_directory + "/.config/autostart/" + APP_DESKTOP_ENTRY_FILE;
}
}
// No location found, return empty string.
return desktop_file_location;
}
// TODO: Finish implementation of SystemFactory auto-start methods.
bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();
@ -93,12 +102,16 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
return false;
}
#elif defined(Q_OS_LINUX)
// Note that we expect here that no other program uses
// "rssguard.desktop" desktop file.
switch (new_status) {
case SystemFactory::Enabled:
break;
QFile::link(QString(APP_DESKTOP_ENTRY_PATH) + "/" + APP_DESKTOP_ENTRY_FILE,
getAutostartDesktopFileLocation());
return true;
case SystemFactory::Disabled:
break;
QFile::remove(getAutostartDesktopFileLocation());
return true;
default:
return false;
}

View File

@ -20,6 +20,10 @@ class SystemFactory {
// Function returns false if setting of
// new status failed.
static bool setAutoStartStatus(const SystemFactory::AutoStartStatus &new_status);
// Returns standard location where auto-start .desktop files
// should be placed.
static QString getAutostartDesktopFileLocation();
};
#endif // SYSTEMFACTORY_H