Revert previous commit, was incorrect
[amarok.git] / src / portabledevices / SolidHandler.cpp
blob02e1a36af6599e0962d7e7a670054bf99bf4832c
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 #include "solid/device.h"
20 #include "solid/devicenotifier.h"
22 #include <QList>
24 #include "debug.h"
25 #include "SolidHandler.h"
28 using namespace PortableDevicesNS;
30 SolidHandler* SolidHandler::s_instance = 0;
32 SolidHandler*
33 SolidHandler::instance()
35 static SolidHandler sh;
36 return &sh;
39 SolidHandler::SolidHandler() : QObject()
40 , m_portableList()
42 DEBUG_BLOCK
43 s_instance = this;
46 SolidHandler::~SolidHandler()
50 void
51 SolidHandler::Initialize()
53 DEBUG_BLOCK
54 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceAdded( const QString & ) ),
55 this, SLOT( deviceAdded( const QString & ) ) );
56 connect( Solid::DeviceNotifier::instance(), SIGNAL( deviceRemoved( const QString & ) ),
57 this, SLOT( deviceRemoved( const QString & ) ) );
58 QList<Solid::Device> deviceList = Solid::Device::listFromQuery( "is PortableMediaPlayer" );
59 Solid::Device temp;
60 foreach( const Solid::Device &device, deviceList )
62 debug() << "Found Solid::DeviceInterface::PortableMediaPlayer with udi = " << device.udi();
63 debug() << "Device name is = " << device.product() << " and was made by " << device.vendor();
64 m_portableList << device.udi();
68 void
69 SolidHandler::deviceAdded( const QString &udi )
71 if( m_portableList.contains( udi ) )
73 debug() << "Error: duplicate UDI trying to be added from Solid.";
74 return;
76 m_portableList << udi;
77 emit addDevice( udi );
80 void
81 SolidHandler::deviceRemoved( const QString &udi )
83 if( m_portableList.contains( udi ) )
85 m_portableList.removeAll( udi );
86 emit removeDevice( udi );
87 return;
91 namespace The {
92 PortableDevicesNS::SolidHandler* SolidHandler() { return PortableDevicesNS::SolidHandler::instance(); }
95 #include "SolidHandler.moc"