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

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "k3bdevicecombobox.h"
0008 #include "k3bdevicemodel.h"
0009 #include "k3bdevice.h"
0010 #include "k3bdevicemanager.h"
0011 #include "k3bcore.h"
0012 #include "k3b_i18n.h"
0013 
0014 #include <QMap>
0015 
0016 
0017 class K3b::DeviceComboBox::Private
0018 {
0019 public:
0020     K3b::DeviceModel* model;
0021 };
0022 
0023 
0024 K3b::DeviceComboBox::DeviceComboBox( QWidget* parent )
0025     : KComboBox( parent )
0026 {
0027     d = new Private();
0028     d->model = new K3b::DeviceModel( this );
0029     setModel( d->model );
0030 
0031     connect( this, SIGNAL(activated(int)),
0032              this, SLOT(slotActivated(int)) );
0033 }
0034 
0035 
0036 K3b::DeviceComboBox::~DeviceComboBox()
0037 {
0038     delete d;
0039 }
0040 
0041 
0042 K3b::Device::Device* K3b::DeviceComboBox::selectedDevice() const
0043 {
0044     int index = currentIndex();
0045     if ( index >= 0 ) {
0046         return d->model->deviceForIndex( d->model->index( index, 0 ) );
0047     }
0048     else {
0049         return 0;
0050     }
0051 }
0052 
0053 
0054 void K3b::DeviceComboBox::addDevice( K3b::Device::Device* dev )
0055 {
0056     d->model->addDevice( dev );
0057 }
0058 
0059 
0060 void K3b::DeviceComboBox::removeDevice( K3b::Device::Device* dev )
0061 {
0062     d->model->removeDevice( dev );
0063 }
0064 
0065 
0066 void K3b::DeviceComboBox::addDevices( const QList<K3b::Device::Device*>& list )
0067 {
0068     d->model->addDevices( list );
0069 }
0070 
0071 
0072 void K3b::DeviceComboBox::refreshDevices( const QList<K3b::Device::Device*>& list )
0073 {
0074     d->model->setDevices( list );}
0075 
0076 
0077 void K3b::DeviceComboBox::setSelectedDevice( K3b::Device::Device* dev )
0078 {
0079     setCurrentIndex( d->model->indexForDevice( dev ).row() );
0080 }
0081 
0082 
0083 void K3b::DeviceComboBox::slotActivated( int i )
0084 {
0085     emit selectionChanged( d->model->deviceForIndex( d->model->index( i, 0 ) ) );
0086 }
0087 
0088 #include "moc_k3bdevicecombobox.cpp"