qtmobility/plugins/multimedia/wmp/qwmpmetadata.cpp
changeset 5 453da2cfceef
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
4:90517678cc4f 5:453da2cfceef
    55 #include <QtCore/qvariant.h>
    55 #include <QtCore/qvariant.h>
    56 
    56 
    57 
    57 
    58 struct QWmpMetaDataKeyLookup
    58 struct QWmpMetaDataKeyLookup
    59 {
    59 {
    60     QtMedia::MetaData key;
    60     QtMediaServices::MetaData key;
    61     const wchar_t *token;
    61     const wchar_t *token;
    62 };
    62 };
    63 
    63 
    64 static const QWmpMetaDataKeyLookup qt_wmpMetaDataKeys[] =
    64 static const QWmpMetaDataKeyLookup qt_wmpMetaDataKeys[] =
    65 {
    65 {
    66     { QtMedia::Title, L"Title" },
    66     { QtMediaServices::Title, L"Title" },
    67     { QtMedia::SubTitle, L"WM/SubTitle" },
    67     { QtMediaServices::SubTitle, L"WM/SubTitle" },
    68     { QtMedia::Author, L"Author" },
    68     { QtMediaServices::Author, L"Author" },
    69     { QtMedia::Comment, L"Comment" },
    69     { QtMediaServices::Comment, L"Comment" },
    70     { QtMedia::Description, L"Description" },
    70     { QtMediaServices::Description, L"Description" },
    71     { QtMedia::Category, L"WM/Category" },
    71     { QtMediaServices::Category, L"WM/Category" },
    72     { QtMedia::Genre, L"WM/Genre" },
    72     { QtMediaServices::Genre, L"WM/Genre" },
    73     //{ QtMedia::Date, 0 },
    73     //{ QtMediaServices::Date, 0 },
    74     { QtMedia::Year, L"WM/Year" },
    74     { QtMediaServices::Year, L"WM/Year" },
    75     { QtMedia::UserRating, L"UserRating" },
    75     { QtMediaServices::UserRating, L"UserRating" },
    76     //{ QtMedia::MetaDatawords, 0 },
    76     //{ QtMediaServices::MetaDatawords, 0 },
    77     { QtMedia::Language, L"Language" },
    77     { QtMediaServices::Language, L"Language" },
    78     { QtMedia::Publisher, L"WM/Publisher" },
    78     { QtMediaServices::Publisher, L"WM/Publisher" },
    79     { QtMedia::Copyright, L"Copyright" },
    79     { QtMediaServices::Copyright, L"Copyright" },
    80     { QtMedia::ParentalRating, L"ParentalRating" },
    80     { QtMediaServices::ParentalRating, L"ParentalRating" },
    81     { QtMedia::RatingOrganisation, L"RatingOrganisation" },
    81     { QtMediaServices::RatingOrganisation, L"RatingOrganisation" },
    82 
    82 
    83     // Media
    83     // Media
    84     { QtMedia::Size, L"FileSize" },
    84     { QtMediaServices::Size, L"FileSize" },
    85     { QtMedia::MediaType, L"MediaType" },
    85     { QtMediaServices::MediaType, L"MediaType" },
    86     { QtMedia::Duration, L"Duration" },
    86     { QtMediaServices::Duration, L"Duration" },
    87 
    87 
    88     // Audio
    88     // Audio
    89     { QtMedia::AudioBitRate, L"AudioBitrate" },
    89     { QtMediaServices::AudioBitRate, L"AudioBitrate" },
    90     { QtMedia::AudioCodec, L"AudioCodec" },
    90     { QtMediaServices::AudioCodec, L"AudioCodec" },
    91     { QtMedia::ChannelCount, L"Channels" },
    91     { QtMediaServices::ChannelCount, L"Channels" },
    92     { QtMedia::SampleRate, L"Frequency" },
    92     { QtMediaServices::SampleRate, L"Frequency" },
    93 
    93 
    94     // Music
    94     // Music
    95     { QtMedia::AlbumTitle, L"WM/AlbumTitle" },
    95     { QtMediaServices::AlbumTitle, L"WM/AlbumTitle" },
    96     { QtMedia::AlbumArtist, L"WM/AlbumArtist" },
    96     { QtMediaServices::AlbumArtist, L"WM/AlbumArtist" },
    97     { QtMedia::ContributingArtist, L"Author" },
    97     { QtMediaServices::ContributingArtist, L"Author" },
    98     { QtMedia::Composer, L"WM/Composer" },
    98     { QtMediaServices::Composer, L"WM/Composer" },
    99     { QtMedia::Conductor, L"WM/Conductor" },
    99     { QtMediaServices::Conductor, L"WM/Conductor" },
   100     { QtMedia::Lyrics, L"WM/Lyrics" },
   100     { QtMediaServices::Lyrics, L"WM/Lyrics" },
   101     { QtMedia::Mood, L"WM/Mood" },
   101     { QtMediaServices::Mood, L"WM/Mood" },
   102     { QtMedia::TrackNumber, L"WM/TrackNumber" },
   102     { QtMediaServices::TrackNumber, L"WM/TrackNumber" },
   103     //{ QtMedia::TrackCount, 0 },
   103     //{ QtMediaServices::TrackCount, 0 },
   104     //{ QtMedia::CoverArtUrlSmall, 0 },
   104     //{ QtMediaServices::CoverArtUrlSmall, 0 },
   105     //{ QtMedia::CoverArtUrlLarge, 0 },
   105     //{ QtMediaServices::CoverArtUrlLarge, 0 },
   106 
   106 
   107     // Image/Video
   107     // Image/Video
   108     //{ QtMedia::Resolution, 0 },
   108     //{ QtMediaServices::Resolution, 0 },
   109     //{ QtMedia::PixelAspectRatio, 0 },
   109     //{ QtMediaServices::PixelAspectRatio, 0 },
   110 
   110 
   111     // Video
   111     // Video
   112     //{ QtMedia::FrameRate, 0 },
   112     //{ QtMediaServices::FrameRate, 0 },
   113     { QtMedia::VideoBitRate, L"VideoBitRate" },
   113     { QtMediaServices::VideoBitRate, L"VideoBitRate" },
   114     { QtMedia::VideoCodec, L"VideoCodec" },
   114     { QtMediaServices::VideoCodec, L"VideoCodec" },
   115 
   115 
   116     //{ QtMedia::PosterUrl, 0 },
   116     //{ QtMediaServices::PosterUrl, 0 },
   117 
   117 
   118     // Movie
   118     // Movie
   119     { QtMedia::ChapterNumber, L"ChapterNumber" },
   119     { QtMediaServices::ChapterNumber, L"ChapterNumber" },
   120     { QtMedia::Director, L"WM/Director" },
   120     { QtMediaServices::Director, L"WM/Director" },
   121     { QtMedia::LeadPerformer, L"LeadPerformer" },
   121     { QtMediaServices::LeadPerformer, L"LeadPerformer" },
   122     { QtMedia::Writer, L"WM/Writer" },
   122     { QtMediaServices::Writer, L"WM/Writer" },
   123 
   123 
   124     // Photos
   124     // Photos
   125     { QtMedia::CameraManufacturer, L"CameraManufacturer" },
   125     { QtMediaServices::CameraManufacturer, L"CameraManufacturer" },
   126     { QtMedia::CameraModel, L"CameraModel" },
   126     { QtMediaServices::CameraModel, L"CameraModel" },
   127     { QtMedia::Event, L"Event" },
   127     { QtMediaServices::Event, L"Event" },
   128     { QtMedia::Subject, L"Subject" }
   128     { QtMediaServices::Subject, L"Subject" }
   129 };
   129 };
   130 
   130 
   131 QWmpMetaData::QWmpMetaData(IWMPCore3 *player, QWmpEvents *events, QObject *parent)
   131 QWmpMetaData::QWmpMetaData(IWMPCore3 *player, QWmpEvents *events, QObject *parent)
   132     : QMetaDataControl(parent)
   132     : QMetaDataControl(parent)
   133     , m_media(0)
   133     , m_media(0)
   153 bool QWmpMetaData::isWritable() const
   153 bool QWmpMetaData::isWritable() const
   154 {
   154 {
   155     return m_media != 0;
   155     return m_media != 0;
   156 }
   156 }
   157 
   157 
   158 QVariant QWmpMetaData::metaData(QtMedia::MetaData key) const
   158 QVariant QWmpMetaData::metaData(QtMediaServices::MetaData key) const
   159 {
   159 {
   160     static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   160     static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   161 
   161 
   162     switch (key) {
   162     switch (key) {
   163     case QtMedia::Date:
   163     case QtMediaServices::Date:
   164         {
   164         {
   165             QVariant day = value(m_media, QAutoBStr(L"ReleaseDateDay"));
   165             QVariant day = value(m_media, QAutoBStr(L"ReleaseDateDay"));
   166             QVariant month = value(m_media, QAutoBStr(L"ReleaseDateMonth"));
   166             QVariant month = value(m_media, QAutoBStr(L"ReleaseDateMonth"));
   167             QVariant year = value(m_media, QAutoBStr(L"ReleaseDateYear"));
   167             QVariant year = value(m_media, QAutoBStr(L"ReleaseDateYear"));
   168 
   168 
   169             if (!day.isNull() && !month.isNull() && !year.isNull())
   169             if (!day.isNull() && !month.isNull() && !year.isNull())
   170                 return QDate(year.toInt(), month.toInt(), day.toInt());
   170                 return QDate(year.toInt(), month.toInt(), day.toInt());
   171         }
   171         }
   172         break;
   172         break;
   173     case QtMedia::CoverArtUrlSmall:
   173     case QtMediaServices::CoverArtUrlSmall:
   174         return albumArtUrl(m_media, "_Small.jpg");
   174         return albumArtUrl(m_media, "_Small.jpg");
   175     case QtMedia::CoverArtUrlLarge:
   175     case QtMediaServices::CoverArtUrlLarge:
   176         return albumArtUrl(m_media, "_Large.jpg");
   176         return albumArtUrl(m_media, "_Large.jpg");
   177     case QtMedia::Resolution:
   177     case QtMediaServices::Resolution:
   178         {
   178         {
   179             QVariant width = value(m_media, QAutoBStr(L"WM/VideoWidth"));
   179             QVariant width = value(m_media, QAutoBStr(L"WM/VideoWidth"));
   180             QVariant height = value(m_media, QAutoBStr(L"WM/VideoHeight"));
   180             QVariant height = value(m_media, QAutoBStr(L"WM/VideoHeight"));
   181 
   181 
   182             if (!width.isNull() && !height.isNull())
   182             if (!width.isNull() && !height.isNull())
   183                 return QSize(width.toInt(), height.toInt());
   183                 return QSize(width.toInt(), height.toInt());
   184         }
   184         }
   185         break;
   185         break;
   186     case QtMedia::PixelAspectRatio:
   186     case QtMediaServices::PixelAspectRatio:
   187         {
   187         {
   188             QVariant x = value(m_media, QAutoBStr(L"PixelAspectRatioX"));
   188             QVariant x = value(m_media, QAutoBStr(L"PixelAspectRatioX"));
   189             QVariant y = value(m_media, QAutoBStr(L"PixelAspectRatioY"));
   189             QVariant y = value(m_media, QAutoBStr(L"PixelAspectRatioY"));
   190 
   190 
   191             if (!x.isNull() && !y.isNull())
   191             if (!x.isNull() && !y.isNull())
   192                 return QSize(x.toInt(), y.toInt());
   192                 return QSize(x.toInt(), y.toInt());
   193         }
   193         }
   194         break;
   194         break;
   195     case QtMedia::VideoFrameRate:
   195     case QtMediaServices::VideoFrameRate:
   196         break;
   196         break;
   197     default:
   197     default:
   198         for (int i = 0; i < count; ++i) {
   198         for (int i = 0; i < count; ++i) {
   199             if (qt_wmpMetaDataKeys[i].key == key)
   199             if (qt_wmpMetaDataKeys[i].key == key)
   200                 return value(m_media, QAutoBStr(qt_wmpMetaDataKeys[i].token));
   200                 return value(m_media, QAutoBStr(qt_wmpMetaDataKeys[i].token));
   202         break;
   202         break;
   203     }
   203     }
   204     return QVariant();
   204     return QVariant();
   205 }
   205 }
   206 
   206 
   207 void QWmpMetaData::setMetaData(QtMedia::MetaData key, const QVariant &value)
   207 void QWmpMetaData::setMetaData(QtMediaServices::MetaData key, const QVariant &value)
   208 {
   208 {
   209     static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   209     static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   210 
   210 
   211     for (int i = 0; i < count; ++i) {
   211     for (int i = 0; i < count; ++i) {
   212         if (qt_wmpMetaDataKeys[i].key == key) {
   212         if (qt_wmpMetaDataKeys[i].key == key) {
   214             return;
   214             return;
   215         }
   215         }
   216     }
   216     }
   217 }
   217 }
   218 
   218 
   219 QList<QtMedia::MetaData> QWmpMetaData::availableMetaData() const
   219 QList<QtMediaServices::MetaData> QWmpMetaData::availableMetaData() const
   220 {
   220 {
   221     QList<QtMedia::MetaData> keys;
   221     QList<QtMediaServices::MetaData> keys;
   222 
   222 
   223     if (m_media) {
   223     if (m_media) {
   224         // WMP will return a list of all possible keys so there's no point in filtering the keys
   224         // WMP will return a list of all possible keys so there's no point in filtering the keys
   225         // in the lookup table.
   225         // in the lookup table.
   226         static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   226         static const int  count = sizeof(qt_wmpMetaDataKeys) / sizeof(QWmpMetaDataKeyLookup);
   240                 QString albumArtSmall = QLatin1String("AlbumArt_") + uuid + QLatin1String("_Small.jpg");
   240                 QString albumArtSmall = QLatin1String("AlbumArt_") + uuid + QLatin1String("_Small.jpg");
   241 
   241 
   242                 QDir dir = QFileInfo(url).absoluteDir();
   242                 QDir dir = QFileInfo(url).absoluteDir();
   243 
   243 
   244                 if (dir.exists(albumArtLarge))
   244                 if (dir.exists(albumArtLarge))
   245                     keys.append(QtMedia::CoverArtUrlLarge);
   245                     keys.append(QtMediaServices::CoverArtUrlLarge);
   246                 if (dir.exists(albumArtSmall))
   246                 if (dir.exists(albumArtSmall))
   247                     keys.append(QtMedia::CoverArtUrlSmall);
   247                     keys.append(QtMediaServices::CoverArtUrlSmall);
   248             }
   248             }
   249         }
   249         }
   250     }
   250     }
   251     return keys;
   251     return keys;
   252 }
   252 }