53 #include <sbIDeviceEvent.h>
54 #include <sbIPropertyArray.h>
55 #include <sbIPropertyInfo.h>
62 #include <nsArrayUtils.h>
63 #include <nsILocalFile.h>
64 #include <nsIMutableArray.h>
71 #include <glib/gstdio.h>
84 #define IPOD_DEVICE_BATCH_SIZE 100
98 sbIPDDevice::ImportTracks()
101 Itdb_Track** trackBatch =
102 static_cast<Itdb_Track**
>
104 NS_ENSURE_TRUE(trackBatch, NS_ERROR_OUT_OF_MEMORY);
108 int trackCount = itdb_tracks_number(mITDB);
109 GList* trackList = mITDB->tracks;
110 PRUint32 trackNum = 0;
111 PRUint32 batchCount = 0;
117 Itdb_Track* track = (Itdb_Track*) trackList->data;
118 trackList = trackList->next;
121 mIPDStatus->
ItemStart(track, trackNum, trackCount);
124 trackBatch[batchCount] = track;
129 ImportTrackBatch(trackBatch, batchCount);
151 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
158 rv = AddTrack(aMediaItem, &track);
159 NS_ENSURE_SUCCESS(rv, rv);
163 nsCOMPtr<nsIURI> trackURI;
164 rv = GetTrackURI(track, getter_AddRefs(trackURI));
165 NS_ENSURE_SUCCESS(rv, rv);
166 rv = aMediaItem->SetContentSrc(trackURI);
167 NS_ENSURE_SUCCESS(rv, rv);
171 NS_LITERAL_STRING(
"0"));
172 NS_ENSURE_SUCCESS(rv, rv);
192 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
193 NS_ASSERTION(aTrack,
"aTrack is null");
196 GError *gError = NULL;
200 if (!IsMediaSupported(aMediaItem)) {
201 AddUnsupportedMediaItem(aMediaItem);
202 return NS_ERROR_ILLEGAL_VALUE;
206 Itdb_Track* track = itdb_track_new();
207 NS_ENSURE_TRUE(track, NS_ERROR_OUT_OF_MEMORY);
211 SetTrackProperties(track, aMediaItem);
214 nsCOMPtr<nsIURI> trackURI;
215 nsCAutoString trackSpec;
216 nsCOMPtr<nsIFile> trackFile;
217 rv = aMediaItem->GetContentSrc(getter_AddRefs(trackURI));
218 NS_ENSURE_SUCCESS(rv, rv);
219 rv = trackURI->GetSpec(trackSpec);
220 NS_ENSURE_SUCCESS(rv, rv);
221 rv = mFileProtocolHandler->GetFileFromURLSpec(trackSpec,
222 getter_AddRefs(trackFile));
223 NS_ENSURE_SUCCESS(rv, rv);
226 rv = FPSetupTrackInfo(trackFile, track);
227 NS_ENSURE_SUCCESS(rv, rv);
230 nsCAutoString trackPath;
231 rv = trackFile->GetNativePath(trackPath);
232 NS_ENSURE_SUCCESS(rv, rv);
235 FIELD_LOG((
"1: sbIPDDevice::CreateTrack %s\n", trackPath.get()));
239 rv = trackFile->GetFileSize(&fileSize);
240 NS_ENSURE_SUCCESS(rv, rv);
241 if (fileSize > (1 << 30)) {
242 AddUnsupportedMediaItem(aMediaItem);
243 return NS_ERROR_ILLEGAL_VALUE;
245 track->size = (guint32) (fileSize & 0xFFFFFFFF);
248 itdb_track_add(mITDB, track, -1);
251 itdb_playlist_add_track(mMasterPlaylist, track, -1);
254 if (!itdb_cp_track_to_ipod(track, (gchar *) trackPath.get(), &gError)) {
258 g_error_free(gError);
261 NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
267 rv = aMediaItem->SetProperty
271 NS_ENSURE_SUCCESS(rv, rv);
276 FPCheckTrackAuth(track);
279 StatsUpdate(PR_FALSE);
282 mITDBDirty = PR_TRUE;
301 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
308 rv = GetTrack(aMediaItem, &track);
309 NS_ENSURE_SUCCESS(rv, rv);
312 return DeleteTrack(track);
323 sbIPDDevice::DeleteTrack(Itdb_Track* aTrack)
326 NS_ASSERTION(aTrack,
"aTrack is null");
329 Itdb_iTunesDB* itdb = aTrack->itdb;
332 RemoveTrackFromAllPlaylists(aTrack);
337 gchar* fileName = itdb_filename_on_ipod(aTrack);
344 itdb_track_remove(aTrack);
348 StatsUpdate(PR_FALSE);
351 mITDBDirty = PR_TRUE;
363 sbIPDDevice::WipeDevice() {
366 int trackCount = itdb_tracks_number(mITDB);
367 GList* trackList = mITDB->tracks;
368 PRUint32 trackNum = 0;
374 Itdb_Track* track = (Itdb_Track*) trackList->data;
375 trackList = trackList->next;
378 mIPDStatus->
ItemStart(track, trackNum, trackCount);
402 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
403 NS_ASSERTION(aTrack,
"aTrack is null");
411 rv = GetIPodID(aMediaItem, &iPodID);
412 NS_ENSURE_SUCCESS(rv, rv);
415 track = itdb_track_by_dbid(mITDB, iPodID);
416 NS_ENSURE_TRUE(track, NS_ERROR_NOT_AVAILABLE);
440 sbIPDDevice::SetTrackProperties(Itdb_Track* aTrack,
444 NS_ASSERTION(aTrack,
"aTrack is null");
445 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
462 GetTrackPropFileType(aMediaItem, &(aTrack->filetype));
475 sbIPDDevice::SetTrackProperties(
sbIMediaItem* aMediaItem,
479 NS_ASSERTION(aTrack,
"aTrack is null");
480 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
486 nsCOMPtr<sbIPropertyArray> props;
487 rv = GetTrackProperties(aTrack, getter_AddRefs(props));
488 NS_ENSURE_SUCCESS(rv, );
492 rv = aMediaItem->SetProperties(props);
494 NS_ENSURE_SUCCESS(rv, );
507 sbIPDDevice::GetTrackProperties(Itdb_Track* aTrack,
511 NS_ASSERTION(aTrack,
"aTrack is null");
512 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
518 nsCOMPtr<sbIMutablePropertyArray>
519 props = do_CreateInstance
520 (
"@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1",
522 NS_ENSURE_SUCCESS(rv, rv);
545 NS_ADDREF(*aPropertyArray = props);
560 sbIPDDevice::GetTrackProperties(Itdb_Track* aTrack,
561 nsIMutableArray* aPropertiesArrayArray)
564 NS_ASSERTION(aTrack,
"aTrack is null");
565 NS_ASSERTION(aPropertiesArrayArray,
"aPropertiesArrayArray is null");
571 nsCOMPtr<sbIPropertyArray> props;
572 rv = GetTrackProperties(aTrack, getter_AddRefs(props));
573 NS_ENSURE_SUCCESS(rv, rv);
576 rv = aPropertiesArrayArray->AppendElement(props, PR_FALSE);
577 NS_ENSURE_SUCCESS(rv, rv);
593 sbIPDDevice::TrackUpdateProperties(
sbIMediaItem* aMediaItem,
597 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
603 Itdb_Track* track = aTrack;
605 rv = GetTrack(aMediaItem, &track);
606 NS_ENSURE_SUCCESS(rv, rv);
610 SetTrackProperties(track, aMediaItem);
613 mITDBDirty = PR_TRUE;
631 const char* aPropName,
635 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
636 NS_ASSERTION(aPropName,
"aPropName is null");
637 NS_ASSERTION(aProp,
"aProp is null");
645 propName.AssignLiteral(aPropName);
646 rv = aMediaItem->GetProperty(propName, nsProp);
647 NS_ENSURE_SUCCESS(rv, rv);
651 if (!nsProp.IsEmpty()) {
652 prop = g_strdup(NS_ConvertUTF16toUTF8(nsProp).
get());
653 NS_ENSURE_TRUE(prop, NS_ERROR_OUT_OF_MEMORY);
674 const char* aPropName,
678 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
679 NS_ASSERTION(aPropName,
"aPropName is null");
687 propName.AssignLiteral(aPropName);
689 prop.Assign(NS_ConvertUTF8toUTF16(aProp));
691 prop.SetIsVoid(PR_TRUE);
692 rv = aMediaItem->SetProperty(propName, prop);
693 NS_ENSURE_SUCCESS(rv, rv);
710 const char* aPropName,
711 const nsAString& aProp)
714 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
715 NS_ASSERTION(aPropName,
"aPropName is null");
722 nsCOMPtr<sbIPropertyInfo> propertyInfo;
723 propName.AssignLiteral(aPropName);
724 rv = mPropertyManager->GetPropertyInfo(propName,
725 getter_AddRefs(propertyInfo));
726 NS_ENSURE_SUCCESS(rv, rv);
730 rv = propertyInfo->Validate(aProp, &valid);
731 NS_ENSURE_SUCCESS(rv, rv);
732 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
735 rv = aPropertyArray->AppendProperty(propName, aProp);
736 NS_ENSURE_SUCCESS(rv, rv);
753 const char* aPropName,
757 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
758 NS_ASSERTION(aPropName,
"aPropName is null");
769 nsCOMPtr<sbIPropertyInfo> propertyInfo;
770 propName.AssignLiteral(aPropName);
771 rv = mPropertyManager->GetPropertyInfo(propName,
772 getter_AddRefs(propertyInfo));
773 NS_ENSURE_SUCCESS(rv, rv);
779 prop.Assign(NS_ConvertUTF8toUTF16(aProp));
780 rv = propertyInfo->Validate(prop, &valid);
781 NS_ENSURE_SUCCESS(rv, rv);
782 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
784 prop.SetIsVoid(PR_TRUE);
788 rv = aPropertyArray->AppendProperty(propName, prop);
789 NS_ENSURE_SUCCESS(rv, rv);
807 const char* aPropName,
811 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
812 NS_ASSERTION(aPropName,
"aPropName is null");
813 NS_ASSERTION(aProp,
"aProp is null");
820 nsAutoString propStr;
821 propName.AssignLiteral(aPropName);
822 rv = aMediaItem->GetProperty(propName, propStr);
823 NS_ENSURE_SUCCESS(rv, rv);
826 if (!propStr.IsEmpty()) {
829 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(propStr).
get(),
"%d", &prop);
849 const char* aPropName,
853 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
854 NS_ASSERTION(aPropName,
"aPropName is null");
861 propName.AssignLiteral(aPropName);
862 rv = aMediaItem->SetProperty(propName,
sbAutoString(aProp));
863 NS_ENSURE_SUCCESS(rv, rv);
880 const char* aPropName,
884 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
885 NS_ASSERTION(aPropName,
"aPropName is null");
892 nsCOMPtr<sbIPropertyInfo> propertyInfo;
893 propName.AssignLiteral(aPropName);
894 rv = mPropertyManager->GetPropertyInfo(propName,
895 getter_AddRefs(propertyInfo));
896 NS_ENSURE_SUCCESS(rv, rv);
902 rv = propertyInfo->Validate(prop, &valid);
903 NS_ENSURE_SUCCESS(rv, rv);
908 rv = aPropertyArray->AppendProperty(propName, prop);
909 NS_ENSURE_SUCCESS(rv, rv);
928 const char* aPropName,
932 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
933 NS_ASSERTION(aPropName,
"aPropName is null");
934 NS_ASSERTION(aProp,
"aProp is null");
941 nsAutoString propStr;
942 propName.AssignLiteral(aPropName);
943 rv = aMediaItem->GetProperty(propName, propStr);
944 NS_ENSURE_SUCCESS(rv, rv);
947 if (!propStr.IsEmpty()) {
950 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(propStr).
get(),
"%u", &prop);
971 const char* aPropName,
975 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
976 NS_ASSERTION(aPropName,
"aPropName is null");
983 propName.AssignLiteral(aPropName);
984 rv = aMediaItem->SetProperty(propName,
sbAutoString(aProp));
985 NS_ENSURE_SUCCESS(rv, rv);
1003 const char* aPropName,
1007 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
1008 NS_ASSERTION(aPropName,
"aPropName is null");
1015 nsCOMPtr<sbIPropertyInfo> propertyInfo;
1016 propName.AssignLiteral(aPropName);
1017 rv = mPropertyManager->GetPropertyInfo(propName,
1018 getter_AddRefs(propertyInfo));
1019 NS_ENSURE_SUCCESS(rv, rv);
1024 rv = propertyInfo->Validate(prop, &valid);
1025 NS_ENSURE_SUCCESS(rv, rv);
1026 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
1029 rv = aPropertyArray->AppendProperty(propName, prop);
1030 NS_ENSURE_SUCCESS(rv, rv);
1049 const char* aPropName,
1053 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1054 NS_ASSERTION(aPropName,
"aPropName is null");
1055 NS_ASSERTION(aProp,
"aProp is null");
1062 nsAutoString propStr;
1063 propName.AssignLiteral(aPropName);
1064 rv = aMediaItem->GetProperty(propName, propStr);
1065 NS_ENSURE_SUCCESS(rv, rv);
1068 if (!propStr.IsEmpty()) {
1071 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(propStr).
get(),
"%llu", &prop);
1072 if (numScanned >= 1)
1092 const char* aPropName,
1096 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1097 NS_ASSERTION(aPropName,
"aPropName is null");
1104 propName.AssignLiteral(aPropName);
1105 rv = aMediaItem->SetProperty(propName,
sbAutoString(aProp));
1106 NS_ENSURE_SUCCESS(rv, rv);
1124 const char* aPropName,
1128 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
1129 NS_ASSERTION(aPropName,
"aPropName is null");
1136 nsCOMPtr<sbIPropertyInfo> propertyInfo;
1137 propName.AssignLiteral(aPropName);
1138 rv = mPropertyManager->GetPropertyInfo(propName,
1139 getter_AddRefs(propertyInfo));
1140 NS_ENSURE_SUCCESS(rv, rv);
1145 rv = propertyInfo->Validate(prop, &valid);
1146 NS_ENSURE_SUCCESS(rv, rv);
1147 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
1150 rv = aPropertyArray->AppendProperty(propName, prop);
1151 NS_ENSURE_SUCCESS(rv, rv);
1170 const char* aPropName,
1174 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1175 NS_ASSERTION(aPropName,
"aPropName is null");
1176 NS_ASSERTION(aProp,
"aProp is null");
1183 nsAutoString propStr;
1184 propName.AssignLiteral(aPropName);
1185 rv = aMediaItem->GetProperty(propName, propStr);
1186 NS_ENSURE_SUCCESS(rv, rv);
1189 if (!propStr.IsEmpty()) {
1192 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(propStr).
get(),
"%lld", &prop);
1193 if (numScanned >= 1) {
1194 gint64
dur = prop / 1000;
1195 NS_ENSURE_TRUE(prop < (1 << 30), NS_ERROR_FAILURE);
1196 *aProp = (gint) (dur & 0xFFFFFFFF);
1216 const char* aPropName,
1220 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1221 NS_ASSERTION(aPropName,
"aPropName is null");
1227 PRUint64
duration = ((PRUint64) aProp) * 1000;
1228 char durationStr[32];
1229 PRUint32 printCount;
1230 printCount = PR_snprintf(durationStr,
sizeof(durationStr),
"%lld", duration);
1231 NS_ENSURE_TRUE(printCount > 0, NS_ERROR_UNEXPECTED);
1236 propName.AssignLiteral(aPropName);
1237 prop.AssignLiteral(durationStr);
1238 rv = aMediaItem->SetProperty(propName, prop);
1239 NS_ENSURE_SUCCESS(rv, rv);
1256 const char* aPropName,
1260 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
1261 NS_ASSERTION(aPropName,
"aPropName is null");
1268 nsCOMPtr<sbIPropertyInfo> propertyInfo;
1269 propName.AssignLiteral(aPropName);
1270 rv = mPropertyManager->GetPropertyInfo(propName,
1271 getter_AddRefs(propertyInfo));
1272 NS_ENSURE_SUCCESS(rv, rv);
1275 PRUint64 duration = ((PRUint64) aProp) * 1000;
1276 char durationStr[32];
1277 PRUint32 printCount;
1278 printCount = PR_snprintf(durationStr,
sizeof(durationStr),
"%lld", duration);
1279 NS_ENSURE_TRUE(printCount > 0, NS_ERROR_UNEXPECTED);
1284 prop.AssignLiteral(durationStr);
1285 rv = propertyInfo->Validate(prop, &valid);
1286 NS_ENSURE_SUCCESS(rv, rv);
1287 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
1290 rv = aPropertyArray->AppendProperty(propName, prop);
1291 NS_ENSURE_SUCCESS(rv, rv);
1309 sbIPDDevice::GetTrackPropRating(
sbIMediaItem* aMediaItem,
1310 const char* aPropName,
1314 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1315 NS_ASSERTION(aPropName,
"aPropName is null");
1316 NS_ASSERTION(aProp,
"aProp is null");
1323 nsAutoString propStr;
1324 propName.AssignLiteral(aPropName);
1325 rv = aMediaItem->GetProperty(propName, propStr);
1326 NS_ENSURE_SUCCESS(rv, rv);
1329 if (!propStr.IsEmpty()) {
1332 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(propStr).
get(),
"%lu", &prop);
1333 if (numScanned >= 1) {
1334 guint32
rating = prop * 20;
1354 sbIPDDevice::SetTrackPropRating(
sbIMediaItem* aMediaItem,
1355 const char* aPropName,
1359 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1360 NS_ASSERTION(aPropName,
"aPropName is null");
1366 PRUint32
rating = (aProp + 10) / 20;
1368 PRUint32 printCount;
1369 printCount = PR_snprintf(ratingStr,
sizeof(ratingStr),
"%lu", rating);
1370 NS_ENSURE_TRUE(printCount > 0, NS_ERROR_UNEXPECTED);
1375 propName.AssignLiteral(aPropName);
1376 prop.AssignLiteral(ratingStr);
1377 rv = aMediaItem->SetProperty(propName, prop);
1378 NS_ENSURE_SUCCESS(rv, rv);
1396 const char* aPropName,
1400 NS_ASSERTION(aPropertyArray,
"aPropertyArray is null");
1401 NS_ASSERTION(aPropName,
"aPropName is null");
1408 nsCOMPtr<sbIPropertyInfo> propertyInfo;
1409 propName.AssignLiteral(aPropName);
1410 rv = mPropertyManager->GetPropertyInfo(propName,
1411 getter_AddRefs(propertyInfo));
1412 NS_ENSURE_SUCCESS(rv, rv);
1415 PRUint32 rating = (aProp + 10) / 20;
1417 PRUint32 printCount;
1418 printCount = PR_snprintf(ratingStr,
sizeof(ratingStr),
"%lu", rating);
1419 NS_ENSURE_TRUE(printCount > 0, NS_ERROR_UNEXPECTED);
1424 prop.AssignLiteral(ratingStr);
1425 rv = propertyInfo->Validate(prop, &valid);
1426 NS_ENSURE_SUCCESS(rv, rv);
1427 NS_ENSURE_TRUE(valid, NS_ERROR_INVALID_ARG);
1430 rv = aPropertyArray->AppendProperty(propName, prop);
1431 NS_ENSURE_SUCCESS(rv, rv);
1447 sbIPDDevice::GetTrackPropFileType(
sbIMediaItem* aMediaItem,
1451 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1452 NS_ASSERTION(aProp,
"aProp is null");
1458 nsCOMPtr<nsIURI> trackURI;
1459 rv = aMediaItem->GetContentSrc(getter_AddRefs(trackURI));
1460 NS_ENSURE_SUCCESS(rv, rv);
1461 nsCOMPtr<nsIURL> trackURL = do_QueryInterface(trackURI, &rv);
1462 NS_ENSURE_SUCCESS(rv, rv);
1465 nsCAutoString fileExtension;
1466 rv = trackURL->GetFileExtension(fileExtension);
1467 NS_ENSURE_SUCCESS(rv, rv);
1470 if (!fileExtension.IsEmpty()) {
1471 gchar* prop = g_strdup(fileExtension.get());
1472 NS_ENSURE_TRUE(prop, NS_ERROR_OUT_OF_MEMORY);
1496 sbIPDDevice::GetTrackURI(Itdb_Track* aTrack,
1500 NS_ASSERTION(aTrack,
"aTrack is null");
1501 NS_ASSERTION(aTrackURI,
"aTrackURI is null");
1507 nsCOMPtr<nsIFile> trackFile;
1508 rv = TrackGetFile(aTrack, getter_AddRefs(trackFile));
1509 NS_ENSURE_SUCCESS(rv, rv);
1512 nsCOMPtr<nsIURI> trackURI;
1513 rv = mFileProtocolHandler->NewFileURI(trackFile,
1514 getter_AddRefs(trackURI));
1515 NS_ENSURE_SUCCESS(rv, rv);
1518 NS_ADDREF(*aTrackURI = trackURI);
1533 sbIPDDevice::TrackGetFile(Itdb_Track* aTrack,
1534 nsIFile** aTrackFile)
1537 NS_ASSERTION(aTrack,
"aTrack is null");
1538 NS_ASSERTION(aTrackFile,
"aTrackFile is null");
1544 gchar* trackFilePath = itdb_filename_on_ipod(aTrack);
1545 NS_ENSURE_TRUE(trackFilePath, NS_ERROR_FAILURE);
1546 sbAutoGMemPtr autoTrackFilePath(trackFilePath);
1547 nsCAutoString nsTrackFilePath(trackFilePath);
1550 nsCOMPtr<nsILocalFile> trackLocalFile =
1551 do_CreateInstance(
"@mozilla.org/file/local;1", &rv);
1552 NS_ENSURE_SUCCESS(rv, rv);
1553 rv = trackLocalFile->InitWithNativePath(nsTrackFilePath);
1554 NS_ENSURE_SUCCESS(rv, rv);
1557 NS_ADDREF(*aTrackFile = trackLocalFile);
1596 sbIPDDevice::ImportTrackBatch(Itdb_Track** aTrackBatch,
1597 PRUint32 aBatchCount)
1600 NS_ASSERTION(aTrackBatch,
"aTrackBatch is null");
1606 nsCOMPtr<sbIMediaListBatchCallback>
1608 NS_ENSURE_TRUE(batchCallback, NS_ERROR_OUT_OF_MEMORY);
1611 nsRefPtr<ImportTrackBatchParams> importTrackBatchParams =
1613 NS_ENSURE_TRUE(importTrackBatchParams, NS_ERROR_OUT_OF_MEMORY);
1614 importTrackBatchParams->ipdDevice =
this;
1615 importTrackBatchParams->trackBatch = aTrackBatch;
1616 importTrackBatchParams->batchCount = aBatchCount;
1619 rv = mDeviceLibraryML->RunInBatchMode(batchCallback,
1620 importTrackBatchParams);
1621 NS_ENSURE_SUCCESS(rv, rv);
1628 sbIPDDevice::ImportTrackBatch1(
nsISupports* aUserData)
1631 NS_ENSURE_ARG_POINTER(aUserData);
1639 nsRefPtr<sbIPDDevice> ipdDevice = importTrackBatchParams->
ipdDevice;
1640 Itdb_Track** trackBatch = importTrackBatchParams->
trackBatch;
1641 int batchCount = importTrackBatchParams->
batchCount;
1644 rv = ipdDevice->ImportTrackBatch2(trackBatch, batchCount);
1645 NS_ENSURE_SUCCESS(rv, rv);
1651 sbIPDDevice::ImportTrackBatch2(Itdb_Track** aTrackBatch,
1652 PRUint32 aBatchCount)
1655 NS_ASSERTION(aTrackBatch,
"aTrackBatch is null");
1661 nsTArray<PRUint32> trackArrayIndexMap(aBatchCount);
1662 nsCOMPtr<nsIMutableArray> trackURIArray =
1663 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1664 NS_ENSURE_SUCCESS(rv, rv);
1665 nsCOMPtr<nsIMutableArray> propsArray =
1666 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1667 NS_ENSURE_SUCCESS(rv, rv);
1674 PRUint32 trackCount = 0;
1675 for (PRUint32
i = 0;
i < aBatchCount;
i++) {
1678 Itdb_Track* track = aTrackBatch[
i];
1679 FIELD_LOG((
"1: ImportTrack %s\n", itdb_filename_on_ipod(track)));
1680 nsCOMPtr<nsIURI> trackURI;
1681 rv = GetTrackURI(track, getter_AddRefs(trackURI));
1682 if (NS_FAILED(rv)) {
1683 FIELD_LOG((
"2: ImportTrack failed to get track URI.\n"));
1688 nsCOMPtr<sbIMediaItem> mediaItem;
1692 getter_AddRefs(mediaItem));
1693 if (NS_SUCCEEDED(rv)) {
1694 SetTrackProperties(mediaItem, track);
1695 rv = mediaItem->SetContentSrc(trackURI);
1696 NS_ENSURE_SUCCESS(rv, rv);
1699 NS_ENSURE_TRUE(rv == NS_ERROR_NOT_AVAILABLE, rv);
1703 trackArrayIndexMap[trackCount] =
i;
1706 rv = GetTrackProperties(track, propsArray);
1707 NS_ENSURE_SUCCESS(rv, rv);
1710 rv = trackURIArray->AppendElement(trackURI, PR_FALSE);
1711 NS_ENSURE_SUCCESS(rv, rv);
1718 nsCOMPtr<nsIArray> trackMediaItemArray;
1719 rv = mDeviceLibrary->BatchCreateMediaItems
1723 getter_AddRefs(trackMediaItemArray));
1724 NS_ENSURE_SUCCESS(rv, rv);
1737 sbIPDDevice::RemoveTrackFromAllPlaylists(Itdb_Track* aTrack)
1740 GList* playlistList = mITDB->playlists;
1741 while (playlistList) {
1743 Itdb_Playlist* playlist = (Itdb_Playlist *) playlistList->data;
1744 playlistList = playlistList->next;
1747 itdb_playlist_remove_track(playlist, aTrack);
1762 sbIPDDevice::IsMediaSupported(
sbIMediaItem* aMediaItem)
1765 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
1771 nsCOMPtr<nsIURI> itemURI;
1772 nsCOMPtr<nsIURL> itemURL;
1773 nsCAutoString fileExtension;
1774 rv = aMediaItem->GetContentSrc(getter_AddRefs(itemURI));
1775 NS_ENSURE_SUCCESS(rv, PR_FALSE);
1776 itemURL = do_QueryInterface(itemURI, &rv);
1777 NS_ENSURE_SUCCESS(rv, PR_FALSE);
1778 rv = itemURL->GetFileExtension(fileExtension);
1779 NS_ENSURE_SUCCESS(rv, PR_FALSE);
1785 CaseInsensitiveCompare)) {
1803 sbIPDDevice::AddUnsupportedMediaItem(
sbIMediaItem* aMediaItem)
1806 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
#define SB_PROPERTY_TOTALDISCS
friend class sbIPDAutoTrack
nsresult CreateAndDispatchEvent(PRUint32 aType, nsIVariant *aData, PRBool aAsync=PR_TRUE, sbIDeviceEventTarget *aTarget=nsnull)
#define SB_PROPERTY_PLAYCOUNT
dataSBHighestRatedArtists SBProperties rating
Songbird iPod Device Utility Definitions.
#define SB_PROPERTY_RATING
void ItemStart(PRInt32 aItemNum=-1, PRInt32 aItemCount=-1)
#define SB_PROPERTY_HIDDEN
PRUint32 sbIPDSupportedMediaListLength
#define SB_PROPERTY_DEVICE_PERSISTENT_ID
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
#define SB_PROPERTY_TOTALTRACKS
virtual PRBool IsRequestAborted()
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
NS_DECL_ISUPPORTS nsRefPtr< sbIPDDevice > ipdDevice
#define SB_PROPERTY_GENRE
Songbird iPod Device Definitions.
#define SB_PROPERTY_DURATION
#define SB_PROPERTY_DISCNUMBER
Songbird iPod Device Logging Definitions.
#define SB_PROPERTY_ARTISTNAME
const unsigned long EVENT_DEVICE_MEDIA_WRITE_UNSUPPORTED_TYPE
static nsresult GetMediaItemByDevicePersistentId(sbILibrary *aLibrary, const nsAString &aDevicePersistentId, sbIMediaItem **aItem)
void ItemProgress(double aProgress)
#define IPOD_DEVICE_BATCH_SIZE
#define SB_PROPERTY_ALBUMNAME
#define SB_PROPERTY_COMPOSERNAME
const char * sbIPDSupportedMediaList[]
#define SB_PROPERTY_TRACKNAME
#define SB_PROPERTY_AVAILABILITY
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
_getSelectedPageStyle s i
#define SB_PROPERTY_TRACKNUMBER