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>
29 #include "MediaDeviceCache.h"
32 MediaDeviceCache
* MediaDeviceCache::s_instance
= 0;
34 MediaDeviceCache::MediaDeviceCache() : QObject()
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()
51 MediaDeviceCache::refreshCache()
55 QList
<Solid::Device
> deviceList
= Solid::Device::listFromType( Solid::DeviceInterface::PortableMediaPlayer
);
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
;
75 MediaDeviceCache::addSolidDevice( const QString
&udi
)
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
;
86 m_type
[udi
] = MediaDeviceCache::SolidType
;
87 emit
deviceAdded( udi
);
91 MediaDeviceCache::removeSolidDevice( const QString
&udi
)
94 debug() << "udi is: " << udi
;
95 if( m_type
.contains( udi
) )
98 emit
deviceRemoved( udi
);
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
)
108 if( m_type
.contains( udi
) )
112 return MediaDeviceCache::InvalidType
;
115 #include "MediaDeviceCache.moc"