File indexing completed on 2024-04-28 07:39:23

0001 /*
0002     SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef AUDIOWIDGET_H
0007 #define AUDIOWIDGET_H
0008 
0009 #include "translateshelladapter.h"
0010 #include "ui_audiowidget.h"
0011 #include <QFutureWatcher>
0012 #include <QMediaPlayer>
0013 
0014 class KEduVocDocument;
0015 class KEduVocExpression;
0016 
0017 namespace Editor
0018 {
0019 class AudioWidget : public QWidget, public Ui::AudioWidget
0020 {
0021     Q_OBJECT
0022 public:
0023     explicit AudioWidget(QWidget *parent = nullptr);
0024     void setDocument(KEduVocDocument *doc);
0025 
0026 public Q_SLOTS:
0027     /**
0028      * Update the word
0029      * @param entry
0030      * @param translation
0031      */
0032     void setTranslation(KEduVocExpression *entry, int translation);
0033 
0034 private Q_SLOTS:
0035     void slotAudioFileChanged(const QString &url);
0036     void startPlayback();
0037     void slotPlaybackFinished(QMediaPlayer::PlaybackState state);
0038     void startRecordAudio();
0039     void downloadWebserviceAudio();
0040     void handleDownloadWebserviceFinished();
0041 
0042 private:
0043     QString defaultOutputDirectory() const;
0044 
0045     /// Column in the document - corresponds to the language (-KV_COL_TRANS)
0046     int m_currentTranslation{-1};
0047     /// Selection in the doc - if more than one row is selected behavior is different
0048     KEduVocExpression *m_entry{nullptr};
0049     QMediaPlayer m_player; ///< media object for the files
0050     TranslateShellAdapter m_translateShell;
0051     KEduVocDocument *m_doc{nullptr};
0052     QFutureWatcher<bool> m_webserviceDownloadWatcher;
0053 };
0054 
0055 }
0056 
0057 #endif