File indexing completed on 2024-04-28 04:49:50

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 
0007 
0008 #include "k3bdeviceselectiondialog.h"
0009 #include "k3bdevice.h"
0010 #include "k3bdevicecombobox.h"
0011 #include "k3bcore.h"
0012 #include "k3bdevicemanager.h"
0013 #include "k3b_i18n.h"
0014 
0015 #include <QString>
0016 #include <QComboBox>
0017 #include <QDialogButtonBox>
0018 #include <QLayout>
0019 #include <QLabel>
0020 #include <QVBoxLayout>
0021 
0022 
0023 class K3b::DeviceSelectionDialog::Private
0024 {
0025 public:
0026     K3b::DeviceComboBox* comboDevices;
0027 };
0028 
0029 
0030 K3b::DeviceSelectionDialog::DeviceSelectionDialog( QWidget* parent,
0031                             const QString& text )
0032     : QDialog( parent ),
0033       d( new Private() )
0034 {
0035     setWindowTitle( i18n("Device Selection") );
0036 
0037     QVBoxLayout* lay = new QVBoxLayout( this );
0038 
0039     QLabel* label = new QLabel( text.isEmpty() ? i18n("Please select a device:") : text, this );
0040     d->comboDevices = new K3b::DeviceComboBox( this );
0041 
0042     QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this );
0043     connect( buttonBox, SIGNAL(accepted()), this, SLOT(accept()) );
0044     connect( buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
0045 
0046     lay->addWidget( label );
0047     lay->addWidget( d->comboDevices );
0048     lay->addWidget( buttonBox );
0049 }
0050 
0051 
0052 K3b::DeviceSelectionDialog::~DeviceSelectionDialog()
0053 {
0054     delete d;
0055 }
0056 
0057 
0058 void K3b::DeviceSelectionDialog::addDevice( K3b::Device::Device* dev )
0059 {
0060     d->comboDevices->addDevice( dev );
0061 }
0062 
0063 
0064 void K3b::DeviceSelectionDialog::addDevices( const QList<K3b::Device::Device*>& list )
0065 {
0066     d->comboDevices->addDevices( list );
0067 }
0068 
0069 
0070 K3b::Device::Device* K3b::DeviceSelectionDialog::selectedDevice() const
0071 {
0072     return d->comboDevices->selectedDevice();
0073 }
0074 
0075 
0076 void K3b::DeviceSelectionDialog::setSelectedDevice( K3b::Device::Device* dev )
0077 {
0078     d->comboDevices->setSelectedDevice( dev );
0079 }
0080 
0081 
0082 K3b::Device::Device* K3b::DeviceSelectionDialog::selectDevice( QWidget* parent,
0083                                                            const QList<K3b::Device::Device*>& devices,
0084                                                            const QString& text )
0085 {
0086     if( devices.isEmpty() )
0087         return 0;
0088     if( devices.count() == 1 )
0089         return devices[0];
0090 
0091     K3b::DeviceSelectionDialog dlg( parent, text );
0092     dlg.addDevices( devices );
0093 
0094     if( dlg.exec() == Accepted )
0095         return dlg.selectedDevice();
0096     else
0097         return 0;
0098 }
0099 
0100 K3b::Device::Device* K3b::DeviceSelectionDialog::selectDevice( QWidget* parent,
0101                                                            const QString& text )
0102 {
0103     return selectDevice( parent, k3bcore->deviceManager()->allDevices(), text );
0104 
0105 
0106 }
0107 
0108 
0109 K3b::Device::Device* K3b::DeviceSelectionDialog::selectWriter( QWidget* parent, const QString& text )
0110 {
0111     return selectDevice( parent, k3bcore->deviceManager()->burningDevices(), text );
0112 }
0113 
0114 #include "moc_k3bdeviceselectiondialog.cpp"