qtmobility/plugins/multimedia/v4l/camera/v4lvideodevicecontrol.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QFile>
       
    43 #include <QtGui/QIcon>
       
    44 #include "v4lvideodevicecontrol.h"
       
    45 #include "v4lcamerasession.h"
       
    46 
       
    47 V4LVideoDeviceControl::V4LVideoDeviceControl(QObject *parent)
       
    48     : QVideoDeviceControl(parent)
       
    49 {
       
    50     m_session = qobject_cast<V4LCameraSession*>(parent);
       
    51 
       
    52     QString name;
       
    53     QFile video0("/sys/class/video4linux/video0/name");
       
    54     if (video0.exists()) {
       
    55         devices.append("v4l:/dev/video0");
       
    56         char str[31];
       
    57         memset(str,0,31);
       
    58         video0.open(QIODevice::ReadOnly);
       
    59         video0.read(str,30);
       
    60         name = QString(str);
       
    61         descriptions.append(name.simplified());
       
    62         video0.close();
       
    63     }
       
    64 
       
    65     QFile video1("/sys/class/video4linux/video1/name");
       
    66     if (video0.exists()) {
       
    67         devices.append("v4l:/dev/video1");
       
    68         char str[31];
       
    69         memset(str,0,31);
       
    70         video1.open(QIODevice::ReadOnly);
       
    71         video1.read(str,30);
       
    72         name = QString(str);
       
    73         descriptions.append(name.simplified());
       
    74         video1.close();
       
    75     }
       
    76     selected = 0;
       
    77 }
       
    78 
       
    79 int V4LVideoDeviceControl::deviceCount() const
       
    80 {
       
    81     return devices.count();
       
    82 }
       
    83 
       
    84 QString V4LVideoDeviceControl::deviceName(int index) const
       
    85 {
       
    86     if(index >= 0 && index <= devices.count())
       
    87         return devices.at(index);
       
    88 
       
    89     return QString();
       
    90 }
       
    91 
       
    92 QString V4LVideoDeviceControl::deviceDescription(int index) const
       
    93 {
       
    94     if(index >= 0 && index <= descriptions.count())
       
    95         return descriptions.at(index);
       
    96 
       
    97     return QString();
       
    98 }
       
    99 
       
   100 QIcon V4LVideoDeviceControl::deviceIcon(int index) const
       
   101 {
       
   102     Q_UNUSED(index)
       
   103 
       
   104     return QIcon();
       
   105 }
       
   106 
       
   107 int V4LVideoDeviceControl::defaultDevice() const
       
   108 {
       
   109     return 0;
       
   110 }
       
   111 
       
   112 int V4LVideoDeviceControl::selectedDevice() const
       
   113 {
       
   114     return selected;
       
   115 }
       
   116 
       
   117 void V4LVideoDeviceControl::setSelectedDevice(int index)
       
   118 {
       
   119     if(index >= 0 && index <= devices.count()) {
       
   120         if (m_session) {
       
   121             QString device = devices.at(index);
       
   122             if (device.startsWith("v4l:"))
       
   123                 device.remove(0,4);
       
   124             m_session->setDevice(device);
       
   125         }
       
   126         selected = index;
       
   127     }
       
   128 }
       
   129