File indexing completed on 2025-04-20 07:28:51
0001 /* 0002 SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef _K3B_THREAD_JOB_COMMUNICATION_EVENT_H_ 0007 #define _K3B_THREAD_JOB_COMMUNICATION_EVENT_H_ 0008 0009 #include "k3bdevicetypes.h" 0010 #include "k3bmsf.h" 0011 0012 #include <KGuiItem> 0013 #include <QEvent> 0014 #include <QString> 0015 #include <QWaitCondition> 0016 0017 namespace K3b { 0018 namespace Device { 0019 class Device; 0020 } 0021 } 0022 0023 namespace K3b { 0024 class ThreadJobCommunicationEvent : public QEvent 0025 { 0026 public: 0027 ~ThreadJobCommunicationEvent() override; 0028 0029 enum Type { 0030 WaitForMedium = QEvent::User + 50, 0031 QuestionYesNo, 0032 BlockingInfo 0033 }; 0034 0035 int type() const; 0036 0037 /** 0038 * Separate data object are used since events are deleted once delivered. 0039 * However, we need the data after the event has been delivered. 0040 */ 0041 class Data { 0042 public: 0043 Data(); 0044 0045 Device::Device* device() const; 0046 Device::MediaStates wantedMediaState() const; 0047 Device::MediaTypes wantedMediaType() const; 0048 K3b::Msf wantedMediaSize() const; 0049 QString message() const; 0050 0051 QString text() const; 0052 QString caption() const; 0053 0054 const KGuiItem& buttonYes() const; 0055 const KGuiItem& buttonNo() const; 0056 0057 int intResult() const; 0058 bool boolResult() const; 0059 0060 0061 /** 0062 * Used by the calling thread to wait for the result 0063 */ 0064 void wait(); 0065 0066 /** 0067 * Signal back to the calling thread. 0068 */ 0069 void done( int result ); 0070 0071 private: 0072 Device::Device* m_device; 0073 Device::MediaStates m_wantedMediaState; 0074 Device::MediaTypes m_wantedMediaType; 0075 Msf m_wantedMediaSize; 0076 QString m_text; 0077 QString m_caption; 0078 KGuiItem m_buttonYes; 0079 KGuiItem m_buttonNo; 0080 0081 QWaitCondition m_threader; 0082 int m_result; 0083 0084 friend class ThreadJobCommunicationEvent; 0085 }; 0086 0087 Data* data() const { return m_data; } 0088 0089 static ThreadJobCommunicationEvent* waitForMedium( Device::Device* device, 0090 Device::MediaStates mediaState, 0091 Device::MediaTypes mediaType, 0092 const K3b::Msf& minMediaSize, 0093 const QString& message ); 0094 static ThreadJobCommunicationEvent* questionYesNo( const QString& text, 0095 const QString& caption, 0096 const KGuiItem& buttonYes, 0097 const KGuiItem& buttonNo ); 0098 static ThreadJobCommunicationEvent* blockingInformation( const QString& text, 0099 const QString& caption ); 0100 0101 private: 0102 explicit ThreadJobCommunicationEvent( int type ); 0103 0104 int m_type; 0105 Data* m_data; 0106 }; 0107 } 0108 0109 #endif