qtmobility/src/multimedia/qmetadatacontrolmetaobject.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 "qmetadatacontrolmetaobject_p.h"
       
    43 
       
    44 #include "qmetadatacontrol.h"
       
    45 
       
    46 QTM_BEGIN_NAMESPACE
       
    47 
       
    48 namespace
       
    49 {
       
    50     struct MetaDataKey
       
    51     {
       
    52         QtMedia::MetaData key;
       
    53         const char *name;
       
    54     };
       
    55 
       
    56     const MetaDataKey qt_metaDataKeys[] =
       
    57     {
       
    58         { QtMedia::Title, "title" },
       
    59         { QtMedia::SubTitle, "subTitle" },
       
    60         { QtMedia::Author, "author" },
       
    61         { QtMedia::Comment, "comment" },
       
    62         { QtMedia::Description, "description" },
       
    63         { QtMedia::Category, "category" },
       
    64         { QtMedia::Genre, "genre" },
       
    65         { QtMedia::Year, "year" },
       
    66         { QtMedia::Date, "date" },
       
    67         { QtMedia::UserRating, "userRating" },
       
    68         { QtMedia::Keywords, "keywords" },
       
    69         { QtMedia::Language, "language" },
       
    70         { QtMedia::Publisher, "publisher" },
       
    71         { QtMedia::Copyright, "copyright" },
       
    72         { QtMedia::ParentalRating, "parentalRating" },
       
    73         { QtMedia::RatingOrganisation, "ratingOrganisation" },
       
    74 
       
    75         // Media
       
    76         { QtMedia::Size, "size" },
       
    77         { QtMedia::MediaType, "mediaType" },
       
    78         { QtMedia::Duration, "duration" },
       
    79 
       
    80         // Audio
       
    81         { QtMedia::AudioBitRate, "audioBitRate" },
       
    82         { QtMedia::AudioCodec, "audioCodec" },
       
    83         { QtMedia::AverageLevel, "averageLevel" },
       
    84         { QtMedia::ChannelCount, "channelCount" },
       
    85         { QtMedia::PeakValue, "peakValue" },
       
    86         { QtMedia::SampleRate, "frequency" },
       
    87 
       
    88         // Music
       
    89         { QtMedia::AlbumTitle, "albumTitle" },
       
    90         { QtMedia::AlbumArtist, "albumArtist" },
       
    91         { QtMedia::ContributingArtist, "contributingArtist" },
       
    92         { QtMedia::Composer, "composer" },
       
    93         { QtMedia::Conductor, "conductor" },
       
    94         { QtMedia::Lyrics, "lyrics" },
       
    95         { QtMedia::Mood, "mood" },
       
    96         { QtMedia::TrackNumber, "trackNumber" },
       
    97         { QtMedia::TrackCount, "trackCount" },
       
    98 
       
    99         { QtMedia::CoverArtUrlSmall, "coverArtUrlSmall" },
       
   100         { QtMedia::CoverArtUrlLarge, "coverArtUrlLarge" },
       
   101 
       
   102         // Image/Video
       
   103         { QtMedia::Resolution, "resolution" },
       
   104         { QtMedia::PixelAspectRatio, "pixelAspectRatio" },
       
   105 
       
   106         // Video
       
   107         { QtMedia::VideoFrameRate, "videoFrameRate" },
       
   108         { QtMedia::VideoBitRate, "videoBitRate" },
       
   109         { QtMedia::VideoCodec, "videoCodec" },
       
   110 
       
   111         { QtMedia::PosterUrl, "posterUrl" },
       
   112 
       
   113         // Movie
       
   114         { QtMedia::ChapterNumber, "chapterNumber" },
       
   115         { QtMedia::Director, "director" },
       
   116         { QtMedia::LeadPerformer, "leadPerformer" },
       
   117         { QtMedia::Writer, "writer" },
       
   118 
       
   119         // Photos
       
   120         { QtMedia::CameraManufacturer, "cameraManufacturer" },
       
   121         { QtMedia::CameraModel, "cameraModel" },
       
   122         { QtMedia::Event, "event" },
       
   123         { QtMedia::Subject, "subject" },
       
   124         { QtMedia::Orientation, "orientation" },
       
   125         { QtMedia::ExposureTime, "exposureTime" },
       
   126         { QtMedia::FNumber, "fNumber" },
       
   127         { QtMedia::ExposureProgram, "exposureProgram" },
       
   128         { QtMedia::ISOSpeedRatings, "isoSpeedRatings" },
       
   129         { QtMedia::ExposureBiasValue, "exposureBiasValue" },
       
   130         { QtMedia::DateTimeOriginal, "dateTimeOriginal" },
       
   131         { QtMedia::DateTimeDigitized, "dateTimeDigitized" },
       
   132         { QtMedia::SubjectDistance, "subjectDistance" },
       
   133         { QtMedia::MeteringMode, "meteringMode" },
       
   134         { QtMedia::LightSource, "lightSource" },
       
   135         { QtMedia::Flash, "flash" },
       
   136         { QtMedia::FocalLength, "focalLength" },
       
   137         { QtMedia::ExposureMode, "exposureMode" },
       
   138         { QtMedia::WhiteBalance, "whiteBalance" },
       
   139         { QtMedia::DigitalZoomRatio, "digitalZoomRatio" },
       
   140         { QtMedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" },
       
   141         { QtMedia::SceneCaptureType, "sceneCaptureType" },
       
   142         { QtMedia::GainControl, "gainControl" },
       
   143         { QtMedia::Contrast, "contrast" },
       
   144         { QtMedia::Saturation, "saturation" },
       
   145         { QtMedia::Sharpness, "sharpness" },
       
   146         { QtMedia::DeviceSettingDescription, "deviceSettingDescription" }
       
   147     };
       
   148 }
       
   149 
       
   150 QMetaDataControlMetaObject::QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object)
       
   151     : m_control(control)
       
   152     , m_object(object)
       
   153     , m_mem(0)
       
   154     , m_propertyOffset(0)
       
   155     , m_signalOffset(0)
       
   156 {
       
   157     m_builder.setSuperClass(m_object->metaObject());
       
   158     m_builder.setClassName(m_object->metaObject()->className());
       
   159     m_builder.setFlags(QMetaObjectBuilder::DynamicMetaObject);
       
   160 
       
   161     QObjectPrivate *op = QObjectPrivate::get(m_object);
       
   162     if (op->metaObject)
       
   163         m_builder.setSuperClass(op->metaObject);
       
   164 
       
   165     m_mem = m_builder.toMetaObject();
       
   166     *static_cast<QMetaObject *>(this) = *m_mem;
       
   167 
       
   168     op->metaObject = this;
       
   169     m_propertyOffset = propertyOffset();
       
   170     m_signalOffset = methodOffset();
       
   171 }
       
   172 
       
   173 QMetaDataControlMetaObject::~QMetaDataControlMetaObject()
       
   174 {
       
   175     qFree(m_mem);
       
   176 
       
   177     QObjectPrivate *op = QObjectPrivate::get(m_object);
       
   178     op->metaObject = 0;
       
   179 }
       
   180 
       
   181 int QMetaDataControlMetaObject::metaCall(QMetaObject::Call c, int id, void **a)
       
   182 {
       
   183     if (c == QMetaObject::ReadProperty && id >= m_propertyOffset) {
       
   184         int propId = id - m_propertyOffset;
       
   185 
       
   186         *reinterpret_cast<QVariant *>(a[0]) = m_control->metaData(m_keys.at(propId));
       
   187 
       
   188         return -1;
       
   189     } else if (c == QMetaObject::WriteProperty && id >= m_propertyOffset) {
       
   190         int propId = id - m_propertyOffset;
       
   191 
       
   192         m_control->setMetaData(m_keys.at(propId), *reinterpret_cast<QVariant *>(a[0]));
       
   193 
       
   194         activate(m_object, m_signalOffset + propId, 0);
       
   195 
       
   196         return -1;
       
   197     } else {
       
   198         return m_object->qt_metacall(c, id, a);
       
   199     }
       
   200 }
       
   201 
       
   202 int QMetaDataControlMetaObject::createProperty(const char *name, const char *)
       
   203 {
       
   204     const int count = sizeof(qt_metaDataKeys) / sizeof(MetaDataKey);
       
   205 
       
   206     for (int i = 0; i < count; ++i) {
       
   207         if (qstrcmp(name, qt_metaDataKeys[i].name) == 0) {
       
   208             int id = m_keys.count();
       
   209             m_keys.append(qt_metaDataKeys[i].key);
       
   210 
       
   211             m_builder.addSignal("__" + QByteArray::number(id) + "()");
       
   212 
       
   213             QMetaPropertyBuilder build = m_builder.addProperty(name, "QVariant", id);
       
   214             build.setDynamic(true);
       
   215 
       
   216             qFree(m_mem);
       
   217             m_mem = m_builder.toMetaObject();
       
   218             *static_cast<QMetaObject *>(this) = *m_mem;
       
   219 
       
   220             return m_propertyOffset + id;
       
   221         }
       
   222     }
       
   223 
       
   224     return -1;
       
   225 }
       
   226 
       
   227 void QMetaDataControlMetaObject::metaDataChanged()
       
   228 {
       
   229     for (int i = 0; i < m_keys.count(); ++i)
       
   230         activate(m_object, m_signalOffset + i, 0);
       
   231 }
       
   232 
       
   233 QTM_END_NAMESPACE