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"
22 #include <solid/device.h>
23 #include <solid/deviceinterface.h>
24 #include <solid/devicenotifier.h>
25 #include <solid/portablemediaplayer.h>
31 #include "MediaDeviceCache.h"
34 MediaDeviceCache
* MediaDeviceCache::s_instance
= 0;
36 MediaDeviceCache::MediaDeviceCache() : QObject()
42 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceAdded( const QString
& ) ),
43 this, SLOT( addSolidDevice( const QString
& ) ) );
44 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceRemoved( const QString
& ) ),
45 this, SLOT( removeSolidDevice( const QString
& ) ) );
48 MediaDeviceCache::~MediaDeviceCache()
54 MediaDeviceCache::refreshCache()
59 QList
<Solid::Device
> deviceList
= Solid::Device::listFromType( Solid::DeviceInterface::PortableMediaPlayer
);
61 foreach( Solid::Device device
, deviceList
)
63 debug() << "Found Solid::DeviceInterface::PortableMediaPlayer with udi = " << device
.udi();
64 debug() << "Device name is = " << device
.product() << " and was made by " << device
.vendor();
65 m_type
[device
.udi()] = MediaDeviceCache::SolidType
;
66 m_name
[device
.udi()] = device
.vendor() + " - " + device
.product();
68 KConfigGroup config
= Amarok::config( "PortableDevices" );
69 QMap
<QString
, QString
> manualDevices
= config
.entryMap();
70 foreach( QString udi
, manualDevices
.keys() )
72 if( udi
.startsWith( "manual" ) )
74 debug() << "Found manual device with udi = " << udi
;
75 m_type
[udi
] = MediaDeviceCache::ManualType
;
76 m_name
[udi
] = udi
.split( '|' )[2];
82 MediaDeviceCache::addSolidDevice( const QString
&udi
)
85 Solid::Device
device( udi
);
86 debug() << "Found new Solid device with udi = " << device
.udi();
87 debug() << "Device name is = " << device
.product() << " and was made by " << device
.vendor();
88 Solid::PortableMediaPlayer
* pmp
= dynamic_cast<Solid::PortableMediaPlayer
*>( device
.asDeviceInterface( Solid::DeviceInterface::PortableMediaPlayer
) );
89 if( m_type
.contains( udi
) )
91 debug() << "Duplicate UDI trying to be added: " << udi
;
94 // if( !device.isDeviceInterface( Solid::DeviceInterface::PortableMediaPlayer ) );
97 debug() << "udi " << udi
<< " does not describe a portable media player";
100 m_type
[udi
] = MediaDeviceCache::SolidType
;
101 m_name
[udi
] = device
.vendor() + " - " + device
.product();
102 emit
deviceAdded( udi
);
106 MediaDeviceCache::removeSolidDevice( const QString
&udi
)
109 debug() << "udi is: " << udi
;
110 if( m_type
.contains( udi
) )
112 m_type
.remove( udi
);
113 m_name
.remove( udi
);
114 emit
deviceRemoved( udi
);
117 debug() << "Odd, got a deviceRemoved at udi " << udi
<< " but it didn't seem to exist in the first place...";
120 MediaDeviceCache::DeviceType
121 MediaDeviceCache::deviceType( const QString
&udi
)
124 if( m_type
.contains( udi
) )
128 return MediaDeviceCache::InvalidType
;
132 MediaDeviceCache::deviceName( const QString
&udi
)
135 if( m_name
.contains( udi
) )
139 return "ERR_NO_NAME"; //Should never happen!
142 #include "MediaDeviceCache.moc"