Solid
webcamwatcher.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 Copyright (C) 2007 Will Stephenson <wstephenson@kde.org> 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License or ( at 00007 your option ) version 3 or, at the discretion of KDE e.V. ( which shall 00008 act as a proxy as in section 14 of the GPLv3 ), any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 00020 #include "webcamwatcher.h" 00021 00022 #include <solid/device.h> 00023 #include <solid/devicenotifier.h> 00024 #include <solid/deviceinterface.h> 00025 #include <solid/video.h> 00026 00027 #include <klocale.h> 00028 #include <kdebug.h> 00029 00030 WebcamWatcher::WebcamWatcher( QObject * parent ) : QObject( parent ) 00031 { 00032 // get a list of all the webcams in the system 00033 int found = 0; 00034 foreach (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Video, QString())) 00035 { 00036 m_videoDevices << device.udi(); 00037 getDetails( device ); 00038 found++; 00039 } 00040 if ( found == 0 ) 00041 { 00042 kDebug() << "No video devices found"; 00043 } 00044 // on deviceAdded, check to see if the device was added 00045 connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceAdded(const QString&)), SLOT(deviceAdded(const QString &)) ); 00046 // likewise if removed 00047 connect( Solid::DeviceNotifier::instance(), SIGNAL(deviceRemoved(const QString&)), SLOT(deviceRemoved(const QString &)) ); 00048 } 00049 00050 WebcamWatcher::~WebcamWatcher() 00051 { 00052 00053 } 00054 00055 void WebcamWatcher::deviceAdded( const QString & udi ) 00056 { 00057 Solid::Device dev( udi ); 00058 if ( dev.is<Solid::Video>() ) 00059 { 00060 m_videoDevices << udi; 00061 getDetails( dev ); 00062 } 00063 } 00064 00065 void WebcamWatcher::getDetails( const Solid::Device & dev ) 00066 { 00067 kDebug() << "New video device at " << dev.udi(); 00068 const Solid::Device * vendorDevice = &dev; 00069 while ( vendorDevice->isValid() && vendorDevice->vendor().isEmpty() ) 00070 { 00071 vendorDevice = new Solid::Device( vendorDevice->parentUdi() ); 00072 } 00073 if ( vendorDevice->isValid() ) 00074 { 00075 kDebug() << "vendor: " << vendorDevice->vendor() << ", product: " << vendorDevice->product(); 00076 } 00077 QStringList protocols = dev.as<Solid::Video>()->supportedProtocols(); 00078 if ( protocols.contains( "video4linux" ) ) 00079 { 00080 QStringList drivers = dev.as<Solid::Video>()->supportedDrivers( "video4linux" ); 00081 if ( drivers.contains( "video4linux" ) ) 00082 { 00083 kDebug() << "V4L device path is" << dev.as<Solid::Video>()->driverHandle( "video4linux" ).toString(); 00084 } 00085 } 00086 } 00087 00088 void WebcamWatcher::deviceRemoved( const QString & udi ) 00089 { 00090 Solid::Device dev = Solid::Device( udi ); 00091 int i; 00092 if ( ( i = m_videoDevices.indexOf( udi ) ) != - 1 ) { 00093 kDebug() << udi; 00094 m_videoDevices.removeAt( i ); 00095 } 00096 }