Mailcommon

filteractionplaysound.cpp
1 /*
2  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <[email protected]>
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 
19 using namespace MailCommon;
20 
21 FilterActionPlaySound::FilterActionPlaySound()
22  : FilterActionWithTest(QStringLiteral("play sound"), i18n("Play Sound"))
23 {
24 }
25 
26 FilterActionPlaySound::~FilterActionPlaySound()
27 {
28  delete mPlayer;
29 }
30 
31 FilterAction *FilterActionPlaySound::newAction()
32 {
33  return new FilterActionPlaySound();
34 }
35 
36 bool FilterActionPlaySound::isEmpty() const
37 {
38  return mParameter.isEmpty();
39 }
40 
41 FilterAction::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 
55 SearchRule::RequiredPart FilterActionPlaySound::requiredPart() const
56 {
57  return SearchRule::Envelope;
58 }
59 
60 bool 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 
75 QString FilterActionPlaySound::informationAboutNotValidAction() const
76 {
77  return i18n("Sound file was not defined.");
78 }
Abstract base class for mail filter actions.
Definition: filteraction.h:38
QString i18n(const char *text, const TYPE &arg...)
RequiredPart
Possible required parts.
Definition: searchrule.h:68
A helper class for the filtering process.
Definition: itemcontext.h:26
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:45
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Oct 1 2022 04:00:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.