Mailcommon

filteractionplaysound.cpp
1/*
2 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 */
7
8#include "filteractionplaysound.h"
9
10#include "filter/dialog/filteractionmissingsoundurldialog.h"
11
12#include <phonon/mediaobject.h>
13
14#include <KLocalizedString>
15
16#include <QFile>
17#include <QPointer>
18
19using namespace MailCommon;
20
21FilterActionPlaySound::FilterActionPlaySound()
22 : FilterActionWithTest(QStringLiteral("play sound"), i18n("Play Sound"))
23{
24}
25
26FilterActionPlaySound::~FilterActionPlaySound()
27{
28 delete mPlayer;
29}
30
31FilterAction *FilterActionPlaySound::newAction()
32{
33 return new FilterActionPlaySound();
34}
35
36bool FilterActionPlaySound::isEmpty() const
37{
38 return mParameter.isEmpty();
39}
40
41FilterAction::ReturnCode FilterActionPlaySound::process(ItemContext &, bool) const
42{
43 if (isEmpty()) {
44 return ErrorButGoOn;
45 }
46 if (!mPlayer) {
47 mPlayer = Phonon::createPlayer(Phonon::NotificationCategory);
48 }
49
50 mPlayer->setCurrentSource(mParameter);
51 mPlayer->play();
52 return GoOn;
53}
54
55SearchRule::RequiredPart FilterActionPlaySound::requiredPart() const
56{
58}
59
60bool FilterActionPlaySound::argsFromStringInteractive(const QString &argsStr, const QString &filterName)
61{
62 bool needUpdate = false;
63 argsFromString(argsStr);
64 if (!QFile(mParameter).exists()) {
65 QPointer<MailCommon::FilterActionMissingSoundUrlDialog> dlg = new MailCommon::FilterActionMissingSoundUrlDialog(filterName, argsStr);
66 if (dlg->exec()) {
67 mParameter = dlg->soundUrl();
68 needUpdate = true;
69 }
70 delete dlg;
71 }
72 return needUpdate;
73}
74
75QString FilterActionPlaySound::informationAboutNotValidAction() const
76{
77 return i18n("Sound file was not defined.");
78}
79
80#include "moc_filteractionplaysound.cpp"
Abstract base class for mail filter actions.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
A helper class for the filtering process.
Definition itemcontext.h:27
RequiredPart
Possible required parts.
Definition searchrule.h:68
void setCurrentSource(const MediaSource &source)
QString i18n(const char *text, const TYPE &arg...)
The filter dialog.
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.