Back to index

unity  6.0.0
MusicPreviews.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #include "MusicPreviews.h"
00021 
00022 namespace unity
00023 {
00024 namespace dash
00025 {
00026 
00027 TrackPreview::TrackPreview(Preview::Properties& properties)
00028   : number(PropertyToUnsignedInt(properties, "number"))
00029   , title(PropertyToString(properties, "title"))
00030   , artist(PropertyToString(properties, "artist"))
00031   , album(PropertyToString(properties, "album"))
00032   , length(PropertyToUnsignedInt(properties, "length"))
00033   , genres(PropertyToStringVector(properties, "genres"))
00034   , album_cover(PropertyToString(properties, "album-cover"))
00035   , primary_action_name(PropertyToString(properties, "primary-action-name"))
00036   , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint"))
00037   , primary_action_uri(PropertyToString(properties, "primary-action-uri"))
00038   , play_action_uri(PropertyToString(properties, "play-action-uri"))
00039   , pause_action_uri(PropertyToString(properties, "pause-action-uri"))
00040 {
00041  renderer_name = "preview-track";
00042 }
00043 
00044 AlbumPreview::AlbumPreview(Preview::Properties& properties)
00045   : name(PropertyToString(properties, "name"))
00046   , artist(PropertyToString(properties, "artist"))
00047   , year(PropertyToString(properties, "year"))
00048   , genres(PropertyToStringVector(properties, "genres"))
00049   , album_cover(PropertyToString(properties, "album-cover"))
00050   , primary_action_name(PropertyToString(properties, "primary-action-name"))
00051   , primary_action_icon_hint(PropertyToString(properties, "primary-action-icon-hint"))
00052   , primary_action_uri(PropertyToString(properties, "primary-action-uri"))
00053 {
00054   renderer_name = "preview-album";
00055   LoadTracks(properties);
00056 }
00057 
00058 void AlbumPreview::LoadTracks(Properties& properties)
00059 {
00060   GVariantIter *iter = NULL;
00061   unsigned int track_number = 0;
00062   char* track_title;
00063   unsigned int track_length = 0;
00064   char* track_play_uri;
00065   char* track_pause_uri;
00066 
00067   if (properties.find("tracks") == properties.end())
00068     return;
00069 
00070   g_variant_get(properties["tracks"], "(ususs)", &iter);
00071 
00072   while (g_variant_iter_loop(iter, "ususs",
00073                              &track_number,
00074                              &track_title,
00075                              &track_length,
00076                              &track_play_uri,
00077                              &track_pause_uri))
00078   {
00079     Track track(track_number, track_title, track_length, track_play_uri, track_pause_uri);
00080     tracks.push_back(track);
00081 
00082     length += track_length;
00083   }
00084 
00085   g_variant_iter_free(iter);
00086 }
00087 
00088 }
00089 }