Commit ed751ba8 authored by David Jarvie's avatar David Jarvie

Fix Stop Play button being left enabled after alarm window is closed

When a display alarm was playing an audio file and it was closed,
the Stop Play button in the system tray menu was left enabled.
parent 8451e2c9
......@@ -2,6 +2,7 @@ KAlarm Change Log
=== Version 2.10.3 --- 15 June 2013 ===
- Fix sound repetition pause not working in audio alarms [KDE Bug 319261]
- Fix Stop Play button being left enabled after closing alarm window.
=== Version 2.10.2 --- 4 May 2013 ===
- [Akonadi] Fix infinite loop on shutdown if display alarms are active [KDE Bug 317806]
......
......@@ -115,6 +115,7 @@ class KAlarmApp : public KUniqueApplication
void purgeNewArchivedDefault(const Akonadi::Collection&);
void atLoginEventAdded(const KAEvent&);
#endif
void notifyAudioStopped() { notifyAudioPlaying(false); }
void stopAudio();
void spreadWindows(bool);
void emailSent(KAMail::JobData&, const QStringList& errmsgs, bool copyerr = false);
......
......@@ -170,7 +170,7 @@ QMap<QString, unsigned> MessageWin::mErrorMessages;
// sound files simultaneously would result in a cacophony, and besides
// that, Phonon currently crashes...
QPointer<AudioThread> MessageWin::mAudioThread;
MessageWin* MessageWin::mAudioOwner = 0;
MessageWin* AudioThread::mAudioOwner = 0;
/******************************************************************************
* Construct the message window for the specified alarm.
......@@ -415,7 +415,7 @@ MessageWin::MessageWin()
MessageWin::~MessageWin()
{
kDebug() << mEventId;
if (mAudioOwner == this && mAudioThread)
if (AudioThread::mAudioOwner == this && !mAudioThread.isNull())
mAudioThread->quit();
mErrorMessages.remove(mEventId);
mWindowList.removeAll(this);
......@@ -1498,7 +1498,6 @@ void MessageWin::startAudio()
{
kDebug() << QThread::currentThread();
mAudioThread = new AudioThread(this, mAudioFile, mVolume, mFadeVolume, mFadeSeconds, mAudioRepeatPause);
mAudioOwner = this;
connect(mAudioThread, SIGNAL(readyToPlay()), SLOT(playReady()));
connect(mAudioThread, SIGNAL(finished()), SLOT(playFinished()));
if (mSilenceButton)
......@@ -1563,14 +1562,27 @@ void MessageWin::playFinished()
}
}
delete mAudioThread.data();
// Notify after deleting mAudioThread, so that isAudioPlaying() will
// return the correct value.
theApp()->notifyAudioPlaying(false);
mAudioOwner = 0;
if (mAlwaysHide)
close();
}
/******************************************************************************
* Constructor for audio thread.
*/
AudioThread::AudioThread(MessageWin* parent, const QString& audioFile, float volume, float fadeVolume, int fadeSeconds, int repeatPause)
: QThread(parent),
mFile(audioFile),
mVolume(volume),
mFadeVolume(fadeVolume),
mFadeSeconds(fadeSeconds),
mRepeatPause(repeatPause),
mAudioObject(0)
{
if (mAudioOwner)
kError() << "mAudioOwner already set";
mAudioOwner = parent;
}
/******************************************************************************
* Destructor for audio thread. Waits for thread completion and tidies up.
* Note that this destructor is executed in the parent thread.
......@@ -1581,6 +1593,11 @@ AudioThread::~AudioThread()
stop(true); // stop playing and tidy up (timeout 3 seconds)
delete mAudioObject;
mAudioObject = 0;
if (mAudioOwner == parent())
mAudioOwner = 0;
// Notify after deleting mAudioThread, so that isAudioPlaying() will
// return the correct value.
QTimer::singleShot(0, theApp(), SLOT(notifyAudioStopped()));
}
/******************************************************************************
......
/*
* messagewin.h - displays an alarm message
* Program: kalarm
* Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
* Copyright © 2001-2013 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
......@@ -160,8 +160,7 @@ class MessageWin : public MainWindowBase
static QMap<QString, unsigned> mErrorMessages; // error messages currently displayed, by event ID
#endif
// Sound file playing
static QPointer<AudioThread> mAudioThread; // thread to play audio file
static MessageWin* mAudioOwner; // window which owns mAudioThread
static QPointer<AudioThread> mAudioThread; // thread to play audio file
// Properties needed by readProperties()
QString mMessage;
QFont mFont;
......
/*
* messagewin_p.h - private declarations for MessageWin
* Program: kalarm
* Copyright © 2009,2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2009-2013 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
......@@ -26,25 +26,21 @@
#include <QThread>
#include <QMutex>
class MessageWin;
namespace Phonon { class MediaObject; }
class AudioThread : public QThread
{
Q_OBJECT
public:
AudioThread(QObject* parent, const QString& audioFile, float volume, float fadeVolume, int fadeSeconds, int repeatPause)
: QThread(parent),
mFile(audioFile),
mVolume(volume),
mFadeVolume(fadeVolume),
mFadeSeconds(fadeSeconds),
mRepeatPause(repeatPause),
mAudioObject(0)
{}
AudioThread(MessageWin* parent, const QString& audioFile, float volume, float fadeVolume, int fadeSeconds, int repeatPause);
~AudioThread();
void stop(bool wait = false);
QString error() const;
static MessageWin* mAudioOwner; // window which owns the unique AudioThread
signals:
void readyToPlay();
......
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