sbIPDLibrary.cpp
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //=BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2011 POTI, Inc.
9 // http://www.songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the GPL).
13 //
14 // Software distributed under the License is distributed
15 // on an AS IS basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 //=END SONGBIRD GPL
25 */
26 
32 //------------------------------------------------------------------------------
33 //
34 // iPod device library imported services.
35 //
36 //------------------------------------------------------------------------------
37 
38 // Self import.
39 #include "sbIPDLibrary.h"
40 
41 // Local imports.
42 #include "sbIPDDevice.h"
43 
44 #include <sbIDeviceLibraryMediaSyncSettings.h>
45 #include <sbIDeviceLibrarySyncSettings.h>
46 
47 //------------------------------------------------------------------------------
48 //
49 // iPod device library sbIDeviceLibrary implementation.
50 //
51 //------------------------------------------------------------------------------
52 
61 NS_IMETHODIMP
63 {
64  NS_ENSURE_ARG_POINTER(aSyncSettings);
65 
66  nsresult rv;
67 
68  rv = InitializePrefs();
69  NS_ENSURE_SUCCESS(rv, rv);
70 
71  rv = sbDeviceLibrary::GetSyncSettings(aSyncSettings);
72  NS_ENSURE_SUCCESS(rv, rv);
73 
74  return NS_OK;
75 }
76 
77 NS_IMETHODIMP
79 {
80  NS_ENSURE_ARG_POINTER(aSyncSettings);
81 
82  nsresult rv;
83 
84  rv = InitializePrefs();
85  NS_ENSURE_SUCCESS(rv, rv);
86 
87  rv = sbDeviceLibrary::SetSyncSettings(aSyncSettings);
88  NS_ENSURE_SUCCESS(rv, rv);
89 
90  return NS_OK;
91 }
92 
93 NS_IMETHODIMP
95  nsIArray ** aFolderList)
96 {
97  NS_ENSURE_ARG_POINTER(aFolderList);
98 
99  nsresult rv;
100 
101  rv = InitializePrefs();
102  NS_ENSURE_SUCCESS(rv, rv);
103 
104  rv = sbDeviceLibrary::GetSyncFolderListByType(aContentType,
105  aFolderList);
106  NS_ENSURE_SUCCESS(rv, rv);
107 
108  return NS_OK;
109 }
110 
111 NS_IMETHODIMP
113  nsIArray *aFolderList)
114 {
115  NS_ENSURE_ARG_POINTER(aFolderList);
116 
117  nsresult rv;
118 
119  rv = InitializePrefs();
120  NS_ENSURE_SUCCESS(rv, rv);
121 
122  rv = sbDeviceLibrary::SetSyncFolderListByType(aContentType,
123  aFolderList);
124  NS_ENSURE_SUCCESS(rv, rv);
125 
126  return NS_OK;
127 }
128 
129 //------------------------------------------------------------------------------
130 //
131 // iPod device library services.
132 //
133 //------------------------------------------------------------------------------
134 
140  sbDeviceLibrary(aDevice),
141  mDevice(aDevice),
142  mPrefsInitialized(PR_FALSE)
143 {
144 }
145 
146 
152 {
153 }
154 
155 
156 //------------------------------------------------------------------------------
157 //
158 // Internal iPod device library services.
159 //
160 //------------------------------------------------------------------------------
161 
167 nsresult
168 sbIPDLibrary::InitializePrefs()
169 {
170  nsresult rv;
171 
172  // Do nothing if preferences are already initialized.
173  if (mPrefsInitialized)
174  return NS_OK;
175 
176  // Set the device management type preference.
177  PRUint32 mgmtType;
178  rv = mDevice->GetMgmtType(&mgmtType);
179  NS_ENSURE_SUCCESS(rv, rv);
180 
181  nsCOMPtr<sbIDeviceLibrarySyncSettings> syncSettings;
182  rv = GetSyncSettings(getter_AddRefs(syncSettings));
183  NS_ENSURE_SUCCESS(rv, rv);
184 
185  nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
186  rv = syncSettings->GetMediaSettings(sbIDeviceLibrary::MEDIATYPE_AUDIO,
187  getter_AddRefs(mediaSyncSettings));
188  NS_ENSURE_SUCCESS(rv, rv);
189 
190  rv = mediaSyncSettings->SetMgmtType(mgmtType);
191  NS_ENSURE_SUCCESS(rv, rv);
192 
193  // Set the sync playlist list preference.
194  nsCOMPtr<nsIArray> syncPlaylistList;
195  rv = mDevice->GetSyncPlaylistList(getter_AddRefs(syncPlaylistList));
196  NS_ENSURE_SUCCESS(rv, rv);
197 
198  rv = mediaSyncSettings->SetSelectedPlaylists(syncPlaylistList);
199  NS_ENSURE_SUCCESS(rv, rv);
200 
201  rv = SetSyncSettings(syncSettings);
202  NS_ENSURE_SUCCESS(rv, rv);
203 
204  // Preferences are now initialized.
205  mPrefsInitialized = PR_TRUE;
206 
207  return NS_OK;
208 }
209 
return NS_OK
NS_IMETHOD GetSyncFolderListByType(PRUint32 aContentType, nsIArray **_retval)
NS_IMETHOD SetSyncSettings(sbIDeviceLibrarySyncSettings *aSyncSettings)
sbIPDLibrary(sbIPDDevice *aDevice)
const unsigned long MEDIATYPE_AUDIO
NS_IMETHOD SetSyncFolderListByType(PRUint32 aContentType, nsIArray *aFolderList)
NS_IMETHOD GetSyncSettings(sbIDeviceLibrarySyncSettings **aSyncSettings)
Return the list of playlists the user wants to sync from the main library to the device.
Songbird iPod Device Library Definitions.
Songbird iPod Device Definitions.
attribute sbIDeviceLibrarySyncSettings syncSettings
virtual ~sbIPDLibrary()