add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / MediaDeviceCache.cpp
blobee165ac9333936f78df7194d377ecc02a578731d
1 /*
2 * Copyright (c) 2007 Jeff Mitchell <kde-dev@emailgoeshere.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #define DEBUG_PREFIX "MediaDeviceCache"
21 #include <solid/device.h>
22 #include <solid/deviceinterface.h>
23 #include <solid/devicenotifier.h>
24 #include <solid/portablemediaplayer.h>
26 #include <QList>
28 #include "debug.h"
29 #include "MediaDeviceCache.h"
32 MediaDeviceCache* MediaDeviceCache::s_instance = 0;
34 MediaDeviceCache::MediaDeviceCache() : QObject()
35 , m_type()
37 DEBUG_BLOCK
38 s_instance = this;
39 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceAdded( const QString & ) ),
40 this, SLOT( addSolidDevice( const QString & ) ) );
41 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceRemoved( const QString & ) ),
42 this, SLOT( removeSolidDevice( const QString & ) ) );
45 MediaDeviceCache::~MediaDeviceCache()
47 s_instance = 0;
50 void
51 MediaDeviceCache::refreshCache()
53 DEBUG_BLOCK
54 m_type.clear();
55 QList<Solid::Device> deviceList = Solid::Device::listFromType( Solid::DeviceInterface::PortableMediaPlayer );
56 Solid::Device temp;
57 foreach( Solid::Device device, deviceList )
59 debug() << "Found Solid::DeviceInterface::PortableMediaPlayer with udi = " << device.udi();
60 debug() << "Device name is = " << device.product() << " and was made by " << device.vendor();
61 m_type[device.udi()] = MediaDeviceCache::SolidType;
63 QMap<QString, QString> manualDevices = KGlobal::config()->entryMap( "PortableDevices" );
64 foreach( QString udi, manualDevices.keys() )
66 if( udi.startsWith( "manual" ) )
68 debug() << "Found manual device with udi = " << udi;
69 m_type[udi] = MediaDeviceCache::ManualType;
74 void
75 MediaDeviceCache::addSolidDevice( const QString &udi )
77 DEBUG_BLOCK
78 Solid::Device device( udi );
79 debug() << "Found Solid::DeviceInterface::PortableMediaPlayer with udi = " << device.udi();
80 debug() << "Device name is = " << device.product() << " and was made by " << device.vendor();
81 if( m_type.contains( udi ) )
83 debug() << "Duplicate UDI trying to be added: " << udi;
84 return;
86 m_type[udi] = MediaDeviceCache::SolidType;
87 emit deviceAdded( udi );
90 void
91 MediaDeviceCache::removeSolidDevice( const QString &udi )
93 DEBUG_BLOCK
94 debug() << "udi is: " << udi;
95 if( m_type.contains( udi ) )
97 m_type.remove( udi );
98 emit deviceRemoved( udi );
99 return;
101 debug() << "Odd, got a deviceRemoved at udi " << udi << " but it didn't seem to exist in the first place...";
104 MediaDeviceCache::DeviceType
105 MediaDeviceCache::deviceType( const QString &udi )
107 DEBUG_BLOCK
108 if( m_type.contains( udi ) )
110 return m_type[udi];
112 return MediaDeviceCache::InvalidType;
115 #include "MediaDeviceCache.moc"