Commit 4e8a829d authored by David Jarvie's avatar David Jarvie

Prevent autostarting on non-KDE desktops if start-at-login is disabled

parent 4d25621b
KAlarm Change Log
=== Version 2.11.5 --- 13 April 2016 ===
=== Version 2.11.6 --- 20 April 2016 ===
- Prevent KAlarm autostarting on non-KDE desktops if start-at-login is disabled.
=== Version 2.11.5 (KDE Applications 16.04.0) --- 13 April 2016 ===
- Fix alarm times out by an hour in daylight savings time (needs kcalcore 16.04) [KDE Bug 336738]
- Don't show spurious extra calendar after adding new calendar [KDE Bug 361543]
- Fix crash when adding new calendar [KDE Bugs 361539, 361717]
......
......@@ -24,7 +24,7 @@
#undef QT3_SUPPORT
#define VERSION_SUFFIX "-5ak"
#define KALARM_VERSION "2.11.5" VERSION_SUFFIX
#define KALARM_VERSION "2.11.6" VERSION_SUFFIX
#define KALARM_NAME "KAlarm"
#define KALARM_DBUS_SERVICE "org.kde.kalarm" // D-Bus service name of KAlarm application
......
......@@ -110,7 +110,7 @@
<whatsthis context="@info:whatsthis">&lt;p>Automatically start KAlarm whenever you start KDE.&lt;/p>&lt;p>This option should always be checked unless you intend to discontinue use of KAlarm.&lt;/p></whatsthis>
<default>false</default>
</entry>
<entry name="NoAutoStart" key="NoAutoStart" type="Bool" hidden="true">
<entry name="Base_NoAutoStart" key="NoAutoStart" type="Bool" hidden="true">
<label context="@label">Suppress autostart at login</label>
<default>false</default>
</entry>
......
/*
* preferences.cpp - program preference settings
* Program: kalarm
* Copyright © 2001-2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -37,6 +37,8 @@
#include <ksystemtimezone.h>
#include "kalarm_debug.h"
#include <QStandardPaths>
#include <time.h>
#include <unistd.h>
......@@ -49,6 +51,8 @@ static const char* GENERAL_SECTION = "General";
// Config file entry name for temporary use
static const char* TEMP = "Temp";
static const QString AUTOSTART_FILE(QStringLiteral("kalarm.autostart.desktop"));
// Values for EmailFrom entry
static const QString FROM_SYS_SETTINGS(QStringLiteral("@SystemSettings"));
static const QString FROM_KMAIL(QStringLiteral("@KMail"));
......@@ -112,6 +116,109 @@ void Preferences::setAskAutoStart(bool yes)
KAMessageBox::saveDontShowAgainYesNo(ASK_AUTO_START, !yes);
}
/******************************************************************************
* Set the NoAutoStart condition.
* On KDE desktops, the "X-KDE-autostart-condition" entry in
* kalarm.autostart.desktop references this to determine whether to autostart KAlarm.
* On non-KDE desktops, the "X-KDE-autostart-condition" entry in
* kalarm.autostart.desktop doesn't have any effect, so that KAlarm will be
* autostarted even if it is set not to autostart. Adding a "Hidden" entry to a
* user-modifiable copy of the file fixes this.
*/
void Preferences::setNoAutoStart(bool yes)
{
// Find the existing kalarm.autostart.desktop file, and whether it's writable.
bool existsRW = false;
QString autostartFile;
const QStringList autostartDirs = QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation);
Q_FOREACH(const QString& dir, autostartDirs)
{
const QString file = dir + QStringLiteral("/autostart/") + AUTOSTART_FILE;
if (QFile::exists(file))
{
QFileInfo info(file);
if (info.isReadable())
{
autostartFile = file;
existsRW = info.isWritable();
break;
}
}
}
// If the existing file isn't writable, create a writable file and get its path.
if (!existsRW)
{
autostartFile = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/autostart/") + AUTOSTART_FILE;
if (QFile::exists(autostartFile))
{
QFileInfo info(autostartFile);
if (!info.isReadable() || !info.isWritable())
{
qCWarning(KALARM_LOG) << "Autostart file is not read/write:" << autostartFile;
return;
}
}
}
// Read the writable file and remove any "Hidden=" entries
QFile file(autostartFile);
if (file.open(QIODevice::ReadWrite))
{
bool update = false;
QStringList lines;
QTextStream stream(&file);
stream.setCodec("UTF-8");
stream.setAutoDetectUnicode(true);
if (existsRW)
{
lines = stream.readAll().split(QLatin1Char('\n'));
for (int i = 0; i < lines.size(); ++i)
{
const QString line = lines[i].trimmed();
if (line.isEmpty())
{
lines.removeAt(i);
--i;
}
else if (line.startsWith(QStringLiteral("Hidden=")))
{
lines.removeAt(i);
update = true;
--i;
}
}
}
if (yes)
{
// If a local kalarm.autostart.desktop file exists, add a "Hidden"
// entry to prevent autostart from happening. Otherwise, create a file
// with only a "Hidden" entry.
lines += QStringLiteral("Hidden=true");
update = true;
}
else
{
// Remove any local kalarm.autostart.desktop "Hidden" entry, and if
// that was the only entry in the file, remove the file.
if (lines.isEmpty())
{
// The file only contains a "Hidden=" entry.
if (file.remove())
update = false;
}
}
if (update)
{
// Write the updated file
file.resize(0);
stream << lines.join(QLatin1Char('\n')) << "\n";
}
}
self()->setBase_NoAutoStart(yes);
}
/******************************************************************************
* Get the user's time zone, or if none has been chosen, the system time zone.
* The system time zone is cached, and the cached value will be returned unless
......
/*
* preferences.h - program preference settings
* Program: kalarm
* Copyright © 2001-2010 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
*
* 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
......@@ -48,6 +48,8 @@ class Preferences : public PreferencesBase
static QString previousVersion() { return mPreviousVersion; }
static Backend previousBackend() { return mPreviousBackend; }
static void setAskAutoStart(bool yes);
static bool noAutoStart() { return self()->base_NoAutoStart(); }
static void setNoAutoStart(bool yes);
static KTimeZone timeZone(bool reload = false);
static void setTimeZone(const KTimeZone&);
static const KHolidays::HolidayRegion& holidays();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment