File indexing completed on 2024-10-06 04:26:03

0001 /*
0002     SPDX-FileCopyrightText: 1998-2007 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3burlnavigator.h"
0007 #include "k3bcore.h"
0008 #include "k3bdevice.h"
0009 #include "k3bdevicemanager.h"
0010 #include "k3bglobals.h"
0011 #include "k3bmediacache.h"
0012 #include "k3bmedium.h"
0013 
0014 #include <KMountPoint>
0015 #include <QDir>
0016 
0017 K3b::UrlNavigator::UrlNavigator( KFilePlacesModel* model, QWidget* parent )
0018     : KUrlNavigator( model, QUrl::fromLocalFile(QDir::home().absolutePath()), parent )
0019 {
0020     // Currently we don't support burning from custom protocols so let's filter them out
0021     KUrlNavigator::setSupportedSchemes( QStringList() << "file" << "audiocd" );
0022     
0023     connect( this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlActivated(QUrl)) );
0024 }
0025 
0026 K3b::UrlNavigator::~UrlNavigator()
0027 {
0028 }
0029 
0030 void K3b::UrlNavigator::setDevice( K3b::Device::Device* dev )
0031 {
0032     // Check if device is mounted. If so, switch to the mount path
0033     if( KMountPoint::Ptr mountPoint = KMountPoint::currentMountPoints().findByDevice( dev->blockDeviceName() ) )
0034     {
0035         QString mntPath = mountPoint->mountPoint();
0036         if( !mntPath.isEmpty() ) {
0037             setLocationUrl( QUrl::fromLocalFile( mntPath ) );
0038             return;
0039         }
0040     }
0041     
0042     const Medium& medium = k3bcore->mediaCache()->medium( dev );
0043     if( medium.content() & Medium::ContentAudio )
0044     {
0045         setLocationUrl( QUrl( "audiocd:/" ) );
0046     }
0047 }
0048 
0049 void K3b::UrlNavigator::urlActivated( const QUrl& url )
0050 {
0051     if( url.scheme() == "audiocd" )
0052     {
0053         Q_FOREACH( Device::Device* device, k3bcore->deviceManager()->cdReader() )
0054         {
0055             const Medium& medium = k3bcore->mediaCache()->medium( device );
0056             if( medium.content() & Medium::ContentAudio )
0057             {
0058                 emit activated( device );
0059                 return;
0060             }
0061         }
0062     }
0063     
0064     emit activated( url );
0065 }
0066 
0067 #include "moc_k3burlnavigator.cpp"