File indexing completed on 2024-04-21 04:50:12

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 "k3bmediacontentsview.h"
0008 
0009 #include "k3bmediacache.h"
0010 #include "k3bapplication.h"
0011 
0012 #include <QLabel>
0013 #include <QLayout>
0014 
0015 
0016 class K3b::MediaContentsView::Private
0017 {
0018 public:
0019     K3b::Medium medium;
0020     int supportedMediumContent;
0021     int supportedMediumTypes;
0022     int supportedMediumStates;
0023 
0024     bool autoReload;
0025 };
0026 
0027 
0028 K3b::MediaContentsView::MediaContentsView( bool withHeader,
0029                                            int mediumContent,
0030                                            int mediumTypes,
0031                                            int mediumState,
0032                                            QWidget* parent )
0033     : K3b::ContentsView( withHeader, parent )
0034 {
0035     d = new Private;
0036     d->supportedMediumContent = mediumContent;
0037     d->supportedMediumTypes = mediumTypes;
0038     d->supportedMediumStates = mediumState;
0039     d->autoReload = true;
0040 
0041     connect( k3bappcore->mediaCache(), SIGNAL(mediumChanged(K3b::Device::Device*)),
0042              this, SLOT(slotMediumChanged(K3b::Device::Device*)) );
0043 }
0044 
0045 
0046 K3b::MediaContentsView::~MediaContentsView()
0047 {
0048     delete d;
0049 }
0050 
0051 
0052 void K3b::MediaContentsView::setAutoReload( bool b )
0053 {
0054     d->autoReload = b;
0055 }
0056 
0057 
0058 int K3b::MediaContentsView::supportedMediumContent() const
0059 {
0060     return d->supportedMediumContent;
0061 }
0062 
0063 
0064 int K3b::MediaContentsView::supportedMediumTypes() const
0065 {
0066     return d->supportedMediumTypes;
0067 }
0068 
0069 
0070 int K3b::MediaContentsView::supportedMediumStates() const
0071 {
0072     return d->supportedMediumStates;
0073 }
0074 
0075 
0076 K3b::Medium K3b::MediaContentsView::medium() const
0077 {
0078     return d->medium;
0079 }
0080 
0081 
0082 K3b::Device::Device* K3b::MediaContentsView::device() const
0083 {
0084     return medium().device();
0085 }
0086 
0087 
0088 void K3b::MediaContentsView::setMedium( const K3b::Medium& m )
0089 {
0090     d->medium = m;
0091 }
0092 
0093 
0094 void K3b::MediaContentsView::reload( K3b::Device::Device* dev )
0095 {
0096     reload( k3bappcore->mediaCache()->medium( dev ) );
0097 }
0098 
0099 
0100 void K3b::MediaContentsView::reload( const K3b::Medium& m )
0101 {
0102     setMedium( m );
0103     reload();
0104 }
0105 
0106 
0107 void K3b::MediaContentsView::reload()
0108 {
0109     enableInteraction( true );
0110     reloadMedium();
0111 }
0112 
0113 
0114 void K3b::MediaContentsView::enableInteraction( bool enable )
0115 {
0116     mainWidget()->setEnabled( enable );
0117 }
0118 
0119 
0120 void K3b::MediaContentsView::slotMediumChanged( K3b::Device::Device* dev )
0121 {
0122     if( !d->autoReload || !isActive() )
0123         return;
0124 
0125     if( dev == device() ) {
0126         K3b::Medium m = k3bappcore->mediaCache()->medium( dev );
0127 
0128         // no need to reload if the medium did not change (this is even
0129         // important since K3b blocks the devices in action and after
0130         // the release they are signalled as changed)
0131         if( m == medium() ) {
0132             qDebug() << " medium did not change";
0133             enableInteraction( true );
0134         }
0135         else if( ( m.diskInfo().mediaType() == Device::MEDIA_NONE ||
0136                    m.content() & supportedMediumContent() ) &&
0137                  m.diskInfo().mediaType() & supportedMediumTypes() &&
0138                  m.diskInfo().diskState() & supportedMediumStates() ) {
0139             qDebug() << " new supported medium found";
0140             reload( m );
0141         }
0142         else {
0143             qDebug() << " unsupported medium found";
0144             enableInteraction( false );
0145         }
0146     }
0147 }
0148 
0149 #include "moc_k3bmediacontentsview.cpp"