File indexing completed on 2024-09-22 04:50:00

0001 /*
0002  * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  *
0006  */
0007 
0008 #include "filteractionplaysound.h"
0009 
0010 #include "filter/dialog/filteractionmissingsoundurldialog.h"
0011 
0012 #include <phonon/mediaobject.h>
0013 
0014 #include <KLocalizedString>
0015 
0016 #include <QFile>
0017 #include <QPointer>
0018 
0019 using namespace MailCommon;
0020 
0021 FilterActionPlaySound::FilterActionPlaySound()
0022     : FilterActionWithTest(QStringLiteral("play sound"), i18n("Play Sound"))
0023 {
0024 }
0025 
0026 FilterActionPlaySound::~FilterActionPlaySound()
0027 {
0028     delete mPlayer;
0029 }
0030 
0031 FilterAction *FilterActionPlaySound::newAction()
0032 {
0033     return new FilterActionPlaySound();
0034 }
0035 
0036 bool FilterActionPlaySound::isEmpty() const
0037 {
0038     return mParameter.isEmpty();
0039 }
0040 
0041 FilterAction::ReturnCode FilterActionPlaySound::process(ItemContext &, bool) const
0042 {
0043     if (isEmpty()) {
0044         return ErrorButGoOn;
0045     }
0046     if (!mPlayer) {
0047         mPlayer = Phonon::createPlayer(Phonon::NotificationCategory);
0048     }
0049 
0050     mPlayer->setCurrentSource(mParameter);
0051     mPlayer->play();
0052     return GoOn;
0053 }
0054 
0055 SearchRule::RequiredPart FilterActionPlaySound::requiredPart() const
0056 {
0057     return SearchRule::Envelope;
0058 }
0059 
0060 bool FilterActionPlaySound::argsFromStringInteractive(const QString &argsStr, const QString &filterName)
0061 {
0062     bool needUpdate = false;
0063     argsFromString(argsStr);
0064     if (!QFile(mParameter).exists()) {
0065         QPointer<MailCommon::FilterActionMissingSoundUrlDialog> dlg = new MailCommon::FilterActionMissingSoundUrlDialog(filterName, argsStr);
0066         if (dlg->exec()) {
0067             mParameter = dlg->soundUrl();
0068             needUpdate = true;
0069         }
0070         delete dlg;
0071     }
0072     return needUpdate;
0073 }
0074 
0075 QString FilterActionPlaySound::informationAboutNotValidAction() const
0076 {
0077     return i18n("Sound file was not defined.");
0078 }
0079 
0080 #include "moc_filteractionplaysound.cpp"