File indexing completed on 2024-12-08 04:24:27

0001 /*
0002     SPDX-FileCopyrightText: 1998-2010 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bthreadjobcommunicationevent.h"
0007 
0008 #include <QMutex>
0009 
0010 K3b::ThreadJobCommunicationEvent::Data::Data()
0011     : m_device( 0 ),
0012       m_result( 0 )
0013 {
0014 }
0015 
0016 
0017 
0018 
0019 K3b::Device::Device* K3b::ThreadJobCommunicationEvent::Data::device() const
0020 {
0021     return m_device;
0022 }
0023 
0024 
0025 K3b::Device::MediaStates K3b::ThreadJobCommunicationEvent::Data::wantedMediaState() const
0026 {
0027     return m_wantedMediaState;
0028 }
0029 
0030 
0031 K3b::Device::MediaTypes K3b::ThreadJobCommunicationEvent::Data::wantedMediaType() const
0032 {
0033     return m_wantedMediaType;
0034 }
0035 
0036 
0037 K3b::Msf K3b::ThreadJobCommunicationEvent::Data::wantedMediaSize() const
0038 {
0039     return m_wantedMediaSize;
0040 }
0041 
0042 
0043 QString K3b::ThreadJobCommunicationEvent::Data::message() const
0044 {
0045     return m_text;
0046 }
0047 
0048 
0049 QString K3b::ThreadJobCommunicationEvent::Data::text() const
0050 {
0051     return m_text;
0052 }
0053 
0054 
0055 QString K3b::ThreadJobCommunicationEvent::Data::caption() const
0056 {
0057     return m_caption;
0058 }
0059 
0060 
0061 const KGuiItem& K3b::ThreadJobCommunicationEvent::Data::buttonYes() const
0062 {
0063     return m_buttonYes;
0064 }
0065 
0066 
0067 const KGuiItem& K3b::ThreadJobCommunicationEvent::Data::buttonNo() const
0068 {
0069     return m_buttonNo;
0070 }
0071 
0072 
0073 int K3b::ThreadJobCommunicationEvent::Data::intResult() const
0074 {
0075     return m_result;
0076 }
0077 
0078 
0079 bool K3b::ThreadJobCommunicationEvent::Data::boolResult() const
0080 {
0081     return ( m_result != 0 );
0082 }
0083 
0084 
0085 void K3b::ThreadJobCommunicationEvent::Data::wait()
0086 {
0087     QMutex mutex;
0088     mutex.lock();
0089     m_threader.wait( &mutex );
0090     mutex.unlock();
0091 }
0092 
0093 
0094 void K3b::ThreadJobCommunicationEvent::Data::done( int result )
0095 {
0096     m_result = result;
0097     m_threader.wakeAll();
0098 }
0099 
0100 
0101 K3b::ThreadJobCommunicationEvent::ThreadJobCommunicationEvent( int type )
0102     : QEvent( QEvent::User ),
0103       m_type( type ),
0104       m_data( new Data() )
0105 {
0106 }
0107 
0108 
0109 K3b::ThreadJobCommunicationEvent::~ThreadJobCommunicationEvent()
0110 {
0111     // Do NOT delete m_data here. It is needed after destruction by K3b::ThreadJob
0112 }
0113 
0114 
0115 int K3b::ThreadJobCommunicationEvent::type() const
0116 {
0117     return m_type;
0118 }
0119 
0120 
0121 K3b::ThreadJobCommunicationEvent* K3b::ThreadJobCommunicationEvent::waitForMedium( K3b::Device::Device* device,
0122                                                                                    Device::MediaStates mediaState,
0123                                                                                    Device::MediaTypes mediaType,
0124                                                                                    const K3b::Msf& minMediaSize,
0125                                                                                    const QString& message )
0126 {
0127     K3b::ThreadJobCommunicationEvent* event = new K3b::ThreadJobCommunicationEvent( WaitForMedium );
0128     event->m_data->m_device = device;
0129     event->m_data->m_wantedMediaState = mediaState;
0130     event->m_data->m_wantedMediaType = mediaType;
0131     event->m_data->m_wantedMediaSize = minMediaSize;
0132     event->m_data->m_text = message;
0133     return event;
0134 }
0135 
0136 
0137 K3b::ThreadJobCommunicationEvent* K3b::ThreadJobCommunicationEvent::questionYesNo( const QString& text,
0138                                                                                    const QString& caption,
0139                                                                                    const KGuiItem& buttonYes,
0140                                                                                    const KGuiItem& buttonNo )
0141 {
0142     K3b::ThreadJobCommunicationEvent* event = new K3b::ThreadJobCommunicationEvent( QuestionYesNo );
0143     event->m_data->m_text = text;
0144     event->m_data->m_caption = caption;
0145     event->m_data->m_buttonYes = buttonYes;
0146     event->m_data->m_buttonNo = buttonNo;
0147     return event;
0148 }
0149 
0150 
0151 K3b::ThreadJobCommunicationEvent* K3b::ThreadJobCommunicationEvent::blockingInformation( const QString& text,
0152                                                                                          const QString& caption )
0153 {
0154     K3b::ThreadJobCommunicationEvent* event = new K3b::ThreadJobCommunicationEvent( BlockingInfo );
0155     event->m_data->m_text = text;
0156     event->m_data->m_caption = caption;
0157     return event;
0158 }