sbDeviceMediaItemDecorator.cpp
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2011 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
26 #include "sbStandardProperties.h"
27 #include "sbStringBundle.h"
28 
29 #include "nsCOMPtr.h"
30 #include "nsIURI.h"
31 
32 
33 /* static */ nsresult
35  sbIMediaItem * aMediaItem,
36  const nsAString & aImportType)
37 {
38  NS_ENSURE_ARG_POINTER(aDevice);
39  NS_ENSURE_ARG_POINTER(aMediaItem);
40 
41  nsresult rv;
42 
43 #if DEBUG
44  // Get media item info for viewing in debugger:
45  nsAutoString mi;
46  aMediaItem->ToString(mi);
47 
48  nsCOMPtr<nsIURI> contentUri;
49  rv = aMediaItem->GetContentSrc(getter_AddRefs(contentUri));
50  NS_ENSURE_SUCCESS(rv, rv);
51 
52  nsCAutoString contentSpec;
53  rv = contentUri->GetSpec(contentSpec);
54  NS_ENSURE_SUCCESS(rv, rv);
55 #endif // #if DEBUG
56 
57  // Do nothing if no import type:
58  if (aImportType.IsEmpty()) {
59  return NS_OK;
60  }
61 
62  // Save the import type to the media item properties to track
63  // how the file was classified at mount time and how it has
64  // been and should be processed on import:
65  nsAutoString importType(aImportType);
66  rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_IMPORTTYPE),
67  importType);
68  NS_ENSURE_SUCCESS(rv, rv);
69 
70  // Dispatch on import type and adjust the media item properties as
71  // specified at
72  // http://wiki.songbirdnest.com/Releases/Ratatat/Device_Import_and_Sync#Sync_Logic
73  if (importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_FM_RECORDING) ||
74  importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_VIDEO_RECORDING) ||
75  importType == NS_LITERAL_STRING(SB_VALUE_IMPORTTYPE_VOICE_RECORDING))
76  {
77  // A recording. Set the genre to identify it as such. Localizable
78  // strings reside in the default bundle and use the device.sync. prefix:
80  nsAutoString genreKey(NS_LITERAL_STRING("device.sync.import_type."));
81  genreKey.Append(importType);
82  nsAutoString genre = bundle.Get(genreKey);
83 
84  rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_GENRE), genre);
85  NS_ENSURE_SUCCESS(rv, rv);
86 
87  // Set the artist name to the device name:
88  nsAutoString deviceName;
89  rv = aDevice->GetName(deviceName);
90  NS_ENSURE_SUCCESS(rv, rv);
91  rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_ARTISTNAME),
92  deviceName);
93  NS_ENSURE_SUCCESS(rv, rv);
94 
97  }
98 
99  return NS_OK;
100 }
#define SB_PROPERTY_IMPORTTYPE
#define SB_VALUE_IMPORTTYPE_VIDEO_RECORDING
return NS_OK
#define SB_VALUE_IMPORTTYPE_VOICE_RECORDING
nsString Get(const nsAString &aKey, const nsAString &aDefault=SBVoidString())
static nsresult DecorateMediaItem(sbIDevice *aDevice, sbIMediaItem *aMediaItem, const nsAString &aImportType)
var bundle
#define SB_PROPERTY_GENRE
#define SB_PROPERTY_ARTISTNAME
Songbird String Bundle Definitions.
Interface that defines a single item of media in the system.
#define SB_VALUE_IMPORTTYPE_FM_RECORDING