File indexing completed on 2024-06-16 07:42:27

0001 /*
0002     SPDX-FileCopyrightText: 2005-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef _K3B_THREAD_WIDGET_H_
0009 #define _K3B_THREAD_WIDGET_H_
0010 
0011 #include <QObject>
0012 #include <QHash>
0013 
0014 namespace K3b {
0015     namespace Device {
0016         class Device;
0017     }
0018 
0019     /**
0020      * This class allows a thread other than the GUI thread to perform simple GUI
0021      * operations. Mainly creating some simple K3b Dialogs like Device selection.
0022      *
0023      * Since the calling thread cannot create the ThreadWidget by himself there exists
0024      * exactly one instance created by Core which is used by all threads.
0025      */
0026     class ThreadWidget : public QObject
0027     {
0028         Q_OBJECT
0029 
0030     public:
0031         ~ThreadWidget() override;
0032 
0033         static ThreadWidget* instance();
0034 
0035         /**
0036          * Call this from a thread to show a device selection dialog.
0037          */
0038         static Device::Device* selectDevice( QWidget* parent,
0039                                                   const QString& text = QString() );
0040 
0041     protected:
0042         /**
0043          * communication between the threads
0044          */
0045         void customEvent( QEvent* ) override;
0046 
0047     private:
0048         /**
0049          * used internally
0050          */
0051         class DeviceSelectionEvent;
0052         class Data;
0053 
0054         ThreadWidget();
0055 
0056         /**
0057          * Get unique id
0058          */
0059         int getNewId();
0060         void clearId( int id );
0061         Data* data( int id );
0062 
0063         int m_idCounter;
0064         QHash<int, Data*> m_dataMap;
0065 
0066         static ThreadWidget* s_instance;
0067     };
0068 }
0069 
0070 #endif