Commit c522b0d0 authored by David Jarvie's avatar David Jarvie

Bug 373848: Don't allow 'auto-hide in system tray' on Unity desktop

There is no GUI mechanism to show hidden system tray icons in Unity,
so auto-hiding makes the KAlarm icon inaccessible.
parent b995a2f6
KAlarm Change Log
=== Version 2.11.13 (KDE Applications 17.04) --- 2 January 2017 ===
=== Version 2.11.13 (KDE Applications 17.04) --- 15 January 2017 ===
+ Report if terminal for command alarms is not configured.
+ Don't allow 'auto-hide in system tray' on Unity desktop [KDE Bug 373848]
=== Version 2.11.12 (KDE Applications 16.12.1) --- 1 January 2017 ===
+ Fix Export Alarms file save error [KDE Bug 374337]
......
/*
* functions.cpp - miscellaneous functions
* Program: kalarm
* Copyright © 2001-2014 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2017 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
......@@ -977,6 +977,25 @@ void editNewTemplate(const KAEvent* preset, QWidget* parent)
::editNewTemplate(EditAlarmDlg::Type(0), preset, parent);
}
/******************************************************************************
* Find the identity of the desktop we are running on.
*/
QString currentDesktopIdentityName()
{
return QProcessEnvironment::systemEnvironment().value(QStringLiteral("XDG_CURRENT_DESKTOP"));
}
/******************************************************************************
* Find the identity of the desktop we are running on.
*/
Desktop currentDesktopIdentity()
{
const QString desktop = currentDesktopIdentityName();
if (desktop == QStringLiteral("KDE")) return Desktop::Kde;
if (desktop == QStringLiteral("Unity")) return Desktop::Unity;
return Desktop::Other;
}
/******************************************************************************
* Check the config as to whether there is a wake-on-suspend alarm pending, and
* if so, delete it from the config if it has expired.
......
/*
* functions.h - miscellaneous functions
* Program: kalarm
* Copyright © 2004-2014 by David Jarvie <djarvie@kde.org>
* Copyright © 2007-2017 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
......@@ -83,6 +83,14 @@ struct UpdateResult
void set(UpdateStatus s, const QString& m) { status = s; message = m; }
};
/** Desktop identity, obtained from XDG_CURRENT_DESKTOP. */
enum class Desktop
{
Kde, //!< KDE (KDE 4 and Plasma both identify as "KDE")
Unity, //!< Unity
Other
};
/** Display a main window with the specified event selected */
MainWindow* displayMainWindowSelected(Akonadi::Item::Id = -1);
bool readConfigWindowSize(const char* window, QSize&, int* splitterWidth = nullptr);
......@@ -165,6 +173,8 @@ UpdateResult enableEvents(QVector<KAEvent>&, bool enable, QWidget* msgPar
QVector<KAEvent> getSortedActiveEvents(QObject* parent, AlarmListModel** model = nullptr);
void purgeArchive(int purgeDays); // must only be called from KAlarmApp::processQueue()
void displayKOrgUpdateError(QWidget* parent, UpdateError, UpdateResult korgError, int nAlarms = 0);
Desktop currentDesktopIdentity();
QString currentDesktopIdentityName();
QStringList checkRtcWakeConfig(bool checkEventExists = false);
void deleteRtcWakeConfig();
void cancelRtcWake(QWidget* msgParent, const QString& eventId = QString());
......
......@@ -174,7 +174,7 @@ KAlarmApp::KAlarmApp(int& argc, char** argv)
mKOrganizerEnabled = !QStandardPaths::findExecutable(korg).isEmpty();
if (!mKOrganizerEnabled) { qCDebug(KALARM_LOG) << "KOrganizer options disabled (KOrganizer not found)"; }
// Check if the window manager can't handle keyboard focus transfer between windows
mWindowFocusBroken = (QProcessEnvironment::systemEnvironment().value(QStringLiteral("XDG_CURRENT_DESKTOP")) == QLatin1String("Unity"));
mWindowFocusBroken = (KAlarm::currentDesktopIdentity() == KAlarm::Desktop::Unity);
if (mWindowFocusBroken) { qCDebug(KALARM_LOG) << "Window keyboard focus broken"; }
}
......
......@@ -18,7 +18,7 @@
<argument type="Bool">ShowInSystemTray</argument>
</signal>
<signal name="autoHideSystemTrayChanged">
<argument type="Int">AutoHideSystemTray</argument>
<argument type="Int">Base_AutoHideSystemTray</argument>
</signal>
<signal name="askResourceChanged">
<argument type="Bool">AskResource</argument>
......@@ -99,12 +99,17 @@
<default>true</default>
<!-- <emit signal="showInSystemTrayChanged"/>-->
</entry>
<entry name="AutoHideSystemTray" type="Int">
<entry name="Base_AutoHideSystemTray" key="AutoHideSystemTray" type="Int">
<label context="@label">Auto-hide in system tray if no alarms due within period</label>
<whatsthis context="@info:whatsthis">&lt;p>Enter -1 to auto-hide KAlarm's icon in the system tray when there are no active alarms.&lt;/p>&lt;p>To auto-hide the system tray icon when there are no alarms due within a set period of time, enter the time period in minutes.&lt;/p>&lt;p>Enter 0 to always show the system tray icon.&lt;/p></whatsthis>
<default>1440</default>
<!-- <emit signal="autoHideSystemTrayChanged"/> -->
</entry>
<entry name="NoAutoHideSystemTrayDesktops" type="StringList" hidden="true">
<label context="@label">Desktops without auto-hide in system tray</label>
<whatsthis context="@info:whatsthis">Desktops for which the auto-hide in system tray option is not available.</whatsthis>
<default>Unity</default>
</entry>
<entry name="AutoStart" key="AutoStart" type="Bool">
<label context="@label">Start at login</label>
<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>
......
......@@ -1319,6 +1319,7 @@ void MainWindow::executeDropEvent(MainWindow* win, QDropEvent* e)
dt.setTime_t(summary.date());
QString body = KAMail::getMailBody(summary.serialNumber());
alarmText.setEmail(summary.to(), summary.from(), QString(),
#error
KLocale::global()->formatDateTime(dt), summary.subject(),
body, summary.serialNumber());
}
......
/*
* prefdlg.cpp - program preferences dialog
* Program: kalarm
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2017 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
......@@ -1621,7 +1621,11 @@ QString EditPrefTab::validate()
=============================================================================*/
ViewPrefTab::ViewPrefTab(StackedScrollGroup* scrollGroup)
: PrefsTabBase(scrollGroup)
: PrefsTabBase(scrollGroup),
mShowInSystemTrayCheck(nullptr),
mShowInSystemTrayGroup(nullptr),
mAutoHideSystemTray(nullptr),
mAutoHideSystemTrayPeriod(nullptr)
{
mTabs = new QTabWidget();
topLayout()->addWidget(mTabs);
......@@ -1638,57 +1642,76 @@ ViewPrefTab::ViewPrefTab(StackedScrollGroup* scrollGroup)
topWindows->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
mTabWindows = mTabs->addTab(widget, i18nc("@title:tab", "Alarm Windows"));
// Run-in-system-tray group box
mShowInSystemTray = new QGroupBox(i18nc("@option:check", "Show in system tray"));
mShowInSystemTray->setCheckable(true);
mShowInSystemTray->setWhatsThis(
xi18nc("@info:whatsthis", "<para>Check to show <application>KAlarm</application>'s icon in the system tray."
" Showing it in the system tray provides easy access and a status indication.</para>"));
topGeneral->addWidget(mShowInSystemTray);
QGridLayout* grid = new QGridLayout(mShowInSystemTray);
grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
grid->setColumnStretch(1, 1);
grid->setColumnMinimumWidth(0, indentWidth());
mAutoHideSystemTray = new ButtonGroup(mShowInSystemTray);
connect(mAutoHideSystemTray, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotAutoHideSysTrayChanged);
QRadioButton* radio = new QRadioButton(i18nc("@option:radio Always show KAlarm icon", "Always show"), mShowInSystemTray);
mAutoHideSystemTray->addButton(radio, 0);
radio->setWhatsThis(
xi18nc("@info:whatsthis",
"Check to show <application>KAlarm</application>'s icon in the system tray "
"regardless of whether alarms are due."));
grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no active alarms"), mShowInSystemTray);
mAutoHideSystemTray->addButton(radio, 1);
radio->setWhatsThis(
xi18nc("@info:whatsthis",
"Check to automatically hide <application>KAlarm</application>'s icon in "
"the system tray if there are no active alarms. When hidden, the icon can "
"always be made visible by use of the system tray option to show hidden icons."));
grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
// Run-in-system-tray check box or group.
static const QString showInSysTrayText = i18nc("@option:check", "Show in system tray");
static const QString showInSysTrayWhatsThis = xi18nc("@info:whatsthis",
"<para>Check to show <application>KAlarm</application>'s icon in the system tray."
" Showing it in the system tray provides easy access and a status indication.</para>");
if(Preferences::noAutoHideSystemTrayDesktops().contains(KAlarm::currentDesktopIdentityName()))
{
// Run-in-system-tray check box.
// This desktop type doesn't provide GUI controls to view hidden system tray
// icons, so don't show options to hide the system tray icon.
widget = new QWidget; // this is to allow left adjustment
topGeneral->addWidget(widget);
QHBoxLayout* box = new QHBoxLayout(widget);
mShowInSystemTrayCheck = new QCheckBox(showInSysTrayText);
mShowInSystemTrayCheck->setWhatsThis(showInSysTrayWhatsThis);
box->addWidget(mShowInSystemTrayCheck);
box->setStretchFactor(new QWidget(widget), 1); // left adjust the controls
}
else
{
// Run-in-system-tray group box
mShowInSystemTrayGroup = new QGroupBox(showInSysTrayText);
mShowInSystemTrayGroup->setCheckable(true);
mShowInSystemTrayGroup->setWhatsThis(showInSysTrayWhatsThis);
topGeneral->addWidget(mShowInSystemTrayGroup);
QGridLayout* grid = new QGridLayout(mShowInSystemTrayGroup);
grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
grid->setColumnStretch(1, 1);
grid->setColumnMinimumWidth(0, indentWidth());
mAutoHideSystemTray = new ButtonGroup(mShowInSystemTrayGroup);
connect(mAutoHideSystemTray, &ButtonGroup::buttonSet, this, &ViewPrefTab::slotAutoHideSysTrayChanged);
QRadioButton* radio = new QRadioButton(i18nc("@option:radio Always show KAlarm icon", "Always show"), mShowInSystemTrayGroup);
mAutoHideSystemTray->addButton(radio, 0);
radio->setWhatsThis(
xi18nc("@info:whatsthis",
"Check to show <application>KAlarm</application>'s icon in the system tray "
"regardless of whether alarms are due."));
grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
QString text = xi18nc("@info:whatsthis",
"Check to automatically hide <application>KAlarm</application>'s icon in the "
"system tray if no alarms are due within the specified time period. When hidden, "
"the icon can always be made visible by use of the system tray option to show hidden icons.");
radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no alarm due within time period:"), mShowInSystemTray);
radio->setWhatsThis(text);
mAutoHideSystemTray->addButton(radio, 2);
grid->addWidget(radio, 2, 0, 1, 2, Qt::AlignLeft);
mAutoHideSystemTrayPeriod = new TimePeriod(true, mShowInSystemTray);
mAutoHideSystemTrayPeriod->setWhatsThis(text);
mAutoHideSystemTrayPeriod->setMaximumWidth(mAutoHideSystemTrayPeriod->sizeHint().width());
grid->addWidget(mAutoHideSystemTrayPeriod, 3, 1, 1, 1, Qt::AlignLeft);
mShowInSystemTray->setMaximumHeight(mShowInSystemTray->sizeHint().height());
radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no active alarms"), mShowInSystemTrayGroup);
mAutoHideSystemTray->addButton(radio, 1);
radio->setWhatsThis(
xi18nc("@info:whatsthis",
"Check to automatically hide <application>KAlarm</application>'s icon in "
"the system tray if there are no active alarms. When hidden, the icon can "
"always be made visible by use of the system tray option to show hidden icons."));
grid->addWidget(radio, 1, 0, 1, 2, Qt::AlignLeft);
QString text = xi18nc("@info:whatsthis",
"Check to automatically hide <application>KAlarm</application>'s icon in the "
"system tray if no alarms are due within the specified time period. When hidden, "
"the icon can always be made visible by use of the system tray option to show hidden icons.");
radio = new QRadioButton(i18nc("@option:radio", "Automatically hide if no alarm due within time period:"), mShowInSystemTrayGroup);
radio->setWhatsThis(text);
mAutoHideSystemTray->addButton(radio, 2);
grid->addWidget(radio, 2, 0, 1, 2, Qt::AlignLeft);
mAutoHideSystemTrayPeriod = new TimePeriod(true, mShowInSystemTrayGroup);
mAutoHideSystemTrayPeriod->setWhatsThis(text);
mAutoHideSystemTrayPeriod->setMaximumWidth(mAutoHideSystemTrayPeriod->sizeHint().width());
grid->addWidget(mAutoHideSystemTrayPeriod, 3, 1, 1, 1, Qt::AlignLeft);
mShowInSystemTrayGroup->setMaximumHeight(mShowInSystemTrayGroup->sizeHint().height());
}
// System tray tooltip group box
QGroupBox* group = new QGroupBox(i18nc("@title:group", "System Tray Tooltip"));
topGeneral->addWidget(group);
grid = new QGridLayout(group);
QGridLayout* grid = new QGridLayout(group);
grid->setMargin(style()->pixelMetric(QStyle::PM_DefaultChildMargin));
grid->setSpacing(style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing));
grid->setColumnStretch(2, 1);
......@@ -1797,7 +1820,7 @@ ViewPrefTab::ViewPrefTab(StackedScrollGroup* scrollGroup)
"<para>Choose how to reduce the chance of alarm messages being accidentally acknowledged:"
"<list><item>Position alarm message windows as far as possible from the current mouse cursor location, or</item>"
"<item>Position alarm message windows in the center of the screen, but disable buttons for a short time after the window is displayed.</item></list></para>");
radio = new QRadioButton(i18nc("@option:radio", "Position windows far from mouse cursor"), group);
QRadioButton* radio = new QRadioButton(i18nc("@option:radio", "Position windows far from mouse cursor"), group);
mWindowPosition->addButton(radio, 0);
radio->setWhatsThis(whatsthis);
grid->addWidget(radio, 0, 0, 1, 2, Qt::AlignLeft);
......@@ -1840,7 +1863,10 @@ void ViewPrefTab::restore(bool, bool allTabs)
{
if (allTabs || mTabs->currentIndex() == mTabGeneral)
{
mShowInSystemTray->setChecked(Preferences::showInSystemTray());
if (mShowInSystemTrayGroup)
mShowInSystemTrayGroup->setChecked(Preferences::showInSystemTray());
else
mShowInSystemTrayCheck->setChecked(Preferences::showInSystemTray());
int id;
int mins = Preferences::autoHideSystemTray();
switch (mins)
......@@ -1863,7 +1889,8 @@ void ViewPrefTab::restore(bool, bool allTabs)
break;
}
}
mAutoHideSystemTray->setButton(id);
if (mAutoHideSystemTray)
mAutoHideSystemTray->setButton(id);
setTooltip(Preferences::tooltipAlarmCount(),
Preferences::showTooltipAlarmTime(),
Preferences::showTooltipTimeToAlarm(),
......@@ -1901,10 +1928,10 @@ void ViewPrefTab::apply(bool syncToDisc)
QString text = mTooltipTimeToPrefix->text();
if (text != Preferences::tooltipTimeToPrefix())
Preferences::setTooltipTimeToPrefix(text);
b = mShowInSystemTray->isChecked();
b = mShowInSystemTrayGroup ? mShowInSystemTrayGroup->isChecked() : mShowInSystemTrayCheck->isChecked();
if (b != Preferences::showInSystemTray())
Preferences::setShowInSystemTray(b);
if (b)
if (b && mAutoHideSystemTray)
{
switch (mAutoHideSystemTray->selectedId())
{
......@@ -1988,7 +2015,8 @@ void ViewPrefTab::slotTooltipTimeToToggled(bool on)
void ViewPrefTab::slotAutoHideSysTrayChanged(QAbstractButton* button)
{
mAutoHideSystemTrayPeriod->setEnabled(mAutoHideSystemTray->id(button) == 2);
if (mAutoHideSystemTray)
mAutoHideSystemTrayPeriod->setEnabled(mAutoHideSystemTray->id(button) == 2);
}
void ViewPrefTab::slotWindowPosChanged(QAbstractButton* button)
......
/*
* prefdlg_p.h - private classes for program preferences dialog
* Program: kalarm
* Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2017 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
......@@ -259,7 +259,8 @@ class ViewPrefTab : public PrefsTabBase
QTabWidget* mTabs;
ColourButton* mDisabledColour;
ColourButton* mArchivedColour;
QGroupBox* mShowInSystemTray;
QCheckBox* mShowInSystemTrayCheck;
QGroupBox* mShowInSystemTrayGroup;
ButtonGroup* mAutoHideSystemTray;
TimePeriod* mAutoHideSystemTrayPeriod;
QCheckBox* mTooltipShowAlarms;
......
/*
* preferences.cpp - program preference settings
* Program: kalarm
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2017 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
......@@ -111,6 +111,29 @@ Preferences::Preferences()
setVersion(QStringLiteral(KALARM_VERSION));
}
/******************************************************************************
* Auto hiding of the system tray icon is only allowed on desktops which provide
* GUI controls to show hidden icons.
*/
int Preferences::autoHideSystemTray()
{
if(noAutoHideSystemTrayDesktops().contains(KAlarm::currentDesktopIdentityName()))
return 0; // never hide
return self()->mBase_AutoHideSystemTray;
}
/******************************************************************************
* Auto hiding of the system tray icon is only allowed on desktops which provide
* GUI controls to show hidden icons, so while KAlarm is running on such a
* desktop, don't allow changes to the setting.
*/
void Preferences::setAutoHideSystemTray(int timeout)
{
if(noAutoHideSystemTrayDesktops().contains(KAlarm::currentDesktopIdentityName()))
return;
self()->setBase_AutoHideSystemTray(timeout);
}
void Preferences::setAskAutoStart(bool yes)
{
KAMessageBox::saveDontShowAgainYesNo(ASK_AUTO_START, !yes);
......
/*
* preferences.h - program preference settings
* Program: kalarm
* Copyright © 2001-2016 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2017 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
......@@ -41,6 +41,8 @@ class Preferences : public PreferencesBase
static Preferences* self();
static void connect(const char* signal, const QObject* receiver, const char* member);
static int autoHideSystemTray();
static void setAutoHideSystemTray(int timeout);
static bool autoStartChangedByUser() { return mAutoStartChangedByUser; }
static void setAutoStartChangedByUser(bool c){ mAutoStartChangedByUser = c; }
......
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