sbIPDSync.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 
27 //------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------
29 //
30 // iPod device sync services.
31 //
32 // These services may only be used within both the connect and request locks.
33 //
34 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 
42 //------------------------------------------------------------------------------
43 //
44 // iPod device sync imported services.
45 //
46 //------------------------------------------------------------------------------
47 
48 // Local imports.
49 #include "sbIPDDevice.h"
50 
51 // Songbird imports.
52 #include <sbDeviceUtils.h>
53 #include <sbStandardProperties.h>
54 #include <sbStringUtils.h>
55 
56 #include <sbIDeviceLibraryMediaSyncSettings.h>
57 #include <sbIDeviceLibrarySyncSettings.h>
58 
59 //------------------------------------------------------------------------------
60 //
61 // iPod device sync track services.
62 //
63 //------------------------------------------------------------------------------
64 
69 nsresult
70 sbIPDDevice::SyncFromIPodTracks()
71 {
72  // Sync from all of the iPod tracks.
73  GList* trackList = mITDB->tracks;
74  while (trackList) {
75  // Check for abort.
76  NS_ENSURE_FALSE(IsRequestAborted(), NS_ERROR_ABORT);
77 
78  // Get the track.
79  Itdb_Track* track = (Itdb_Track*) trackList->data;
80  trackList = trackList->next;
81 
82  // Synchronize from the iPod track.
83  SyncFromIPodTrack(track);
84  }
85 
86  return NS_OK;
87 }
88 
89 
97 nsresult
98 sbIPDDevice::SyncFromIPodTrack(Itdb_Track* aTrack)
99 {
100  // Validate arguments.
101  NS_ASSERTION(aTrack, "aTrack is null");
102 
103  // Function variables.
104  nsresult rv;
105 
106  // Search for a matching Songbird media item.
107  nsCOMPtr<sbIMediaItem> mediaItem;
109  (mDeviceLibrary,
110  sbAutoString(aTrack->dbid),
111  getter_AddRefs(mediaItem));
112  NS_ENSURE_SUCCESS(rv, rv);
113 
114  // Synchronize the playcount metadata.
115  if (aTrack->playcount2 > 0) {
116  // Get the Songbird track playcount.
117  guint32 playcount = 0;
118  rv = GetTrackProp(mediaItem, SB_PROPERTY_PLAYCOUNT, &playcount);
119  NS_ENSURE_SUCCESS(rv, rv);
120 
121  // Add and clear the device playcount.
122  playcount += aTrack->playcount2;
123  aTrack->playcount2 = 0;
124 
125  // Write the Songbird track playcount.
126  rv = SetTrackProp(mediaItem, SB_PROPERTY_PLAYCOUNT, playcount);
127  NS_ENSURE_SUCCESS(rv, rv);
128  }
129 
130  return NS_OK;
131 }
132 
133 
134 //------------------------------------------------------------------------------
135 //
136 // iPod device sync services.
137 //
138 //------------------------------------------------------------------------------
139 
144 nsresult
145 sbIPDDevice::SyncFromDevice()
146 {
147  nsresult rv;
148 
149  // Set the SyncPartner preference.
151  NS_ENSURE_SUCCESS(rv, rv);
152 
153  // Synchronize from device tracks.
154  rv = SyncFromIPodTracks();
155  NS_ENSURE_SUCCESS(rv, rv);
156 
157  // Synchronize from on-the-go playlists.
158  rv = SyncFromOTGPlaylists();
159  NS_ENSURE_SUCCESS(rv, rv);
160 
161  return NS_OK;
162 }
163 
164 
169 nsresult
170 sbIPDDevice::SyncFromOTGPlaylists()
171 {
172  nsresult rv;
173 
174  // Synchronize from each on-the-go playlist.
175  GList* playlistList = mITDB->playlists;
176  while (playlistList) {
177  // Check for abort.
178  NS_ENSURE_FALSE(IsRequestAborted(), NS_ERROR_ABORT);
179 
180  // Get the playlist.
181  Itdb_Playlist* playlist = (Itdb_Playlist*) playlistList->data;
182  playlistList = playlistList->next;
183 
184  // If the playlist is an on-the-go playlist, sync it to the Songbird
185  // main library.
186  if (playlist->is_otg) {
187  // Import on-the-go playlists into the main Songbird library.
188  nsCOMPtr<sbIMediaList> mediaList;
189  rv = ImportPlaylist(mSBMainLib, playlist, getter_AddRefs(mediaList));
190  NS_ENSURE_SUCCESS(rv, rv);
191 
192  nsCOMPtr<sbIDeviceLibrarySyncSettings> syncSettings;
193  rv = mDeviceLibrary->GetSyncSettings(getter_AddRefs(syncSettings));
194  NS_ENSURE_SUCCESS(rv, rv);
195 
196  nsCOMPtr<sbIDeviceLibraryMediaSyncSettings> mediaSyncSettings;
197  rv = syncSettings->GetMediaSettings(sbIDeviceLibrary::MEDIATYPE_AUDIO,
198  getter_AddRefs(mediaSyncSettings));
199  NS_ENSURE_SUCCESS(rv, rv);
200 
201  // If the device is set to sync to a list of playlists, add the
202  // on-the-go playlist to the sync list.
203  PRUint32 mgmtType;
204  rv = mediaSyncSettings->GetMgmtType(&mgmtType);
205  if (NS_SUCCEEDED(rv) &&
207  // Add the on-the-go playlist to the sync list.
208  mediaSyncSettings->SetPlaylistSelected(mediaList, PR_TRUE);
209  }
210  }
211  }
212 
213  return NS_OK;
214 }
215 
static nsresult GetOriginMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
return NS_OK
#define SB_PROPERTY_PLAYCOUNT
static nsresult SetLinkedSyncPartner(sbIDevice *aDevice)
const NS_ERROR_ABORT
const unsigned long MEDIATYPE_AUDIO
virtual PRBool IsRequestAborted()
Songbird iPod Device Definitions.
if(DEBUG_DATAREMOTES)