Back to index

unity  6.0.0
Preview.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 "Preview.h"
00021 
00022 #include "ApplicationPreview.h"
00023 #include "GenericPreview.h"
00024 #include "MusicPreviews.h"
00025 
00026 namespace unity
00027 {
00028 namespace dash
00029 {
00030 
00031 Preview::Ptr Preview::PreviewForProperties(std::string const& renderer_name_,
00032                                            Properties& properties)
00033 {
00034   if (renderer_name_ == "preview-application")
00035   {
00036     return Preview::Ptr(new ApplicationPreview(properties));
00037   }
00038   else if (renderer_name_ == "preview-generic")
00039   {
00040     return Preview::Ptr(new GenericPreview(properties));
00041   }
00042   else if (renderer_name_ == "preview-track")
00043   {
00044     return Preview::Ptr(new TrackPreview(properties));
00045   }
00046   else if (renderer_name_ == "preview-album")
00047   {
00048     return Preview::Ptr(new AlbumPreview(properties));
00049   }
00050   else
00051   {
00052     return Preview::Ptr(new NoPreview());
00053   }
00054 }
00055 
00056 Preview::~Preview()
00057 {}
00058 
00059 unsigned int Preview::PropertyToUnsignedInt (Properties& properties, const char* key)
00060 {
00061   return g_variant_get_uint32(properties[key]);
00062 }
00063 
00064 std::string Preview::PropertyToString(Properties& properties, const char *key)
00065 {
00066   if (properties.find(key) == properties.end())
00067    return "";
00068   return g_variant_get_string(properties[key], NULL);
00069 }
00070 
00071 std::vector<std::string> Preview::PropertyToStringVector(Properties& properties, const char *key)
00072 {
00073   GVariantIter* iter = NULL;
00074   char* value = NULL;
00075   std::vector<std::string> property;
00076 
00077   if (properties.find(key) == properties.end())
00078     return property;
00079 
00080   g_variant_get(properties[key], "as", &iter);
00081 
00082   while (g_variant_iter_loop(iter, "s", &value))
00083     property.push_back(value);
00084 
00085   g_variant_iter_free(iter);
00086 
00087   return property;
00088 }
00089 
00090 float Preview::PropertyToFloat(Properties& properties, const char* key)
00091 {
00092   if (properties.find(key) == properties.end())
00093     return 0.0f;
00094 
00095   return (float)g_variant_get_double(properties[key]);
00096 }
00097 
00098 NoPreview::NoPreview()
00099 {
00100   renderer_name = "preview-none";
00101 }
00102 
00103 }
00104 }