26 #ifndef __SBBASEDEVICE__H__
27 #define __SBBASEDEVICE__H__
34 #include "sbIDevice.h"
39 #include <nsArrayUtils.h>
40 #include <nsAutoPtr.h>
41 #include <nsClassHashtable.h>
43 #include <nsCOMArray.h>
44 #include <nsDataHashtable.h>
45 #include <nsIRunnable.h>
46 #include <nsISupportsImpl.h>
53 #include <sbILibraryChangeset.h>
54 #include <sbIMediaItem.h>
55 #include <sbIMediaList.h>
58 #include <sbITemporaryFileFactory.h>
59 #include <sbITranscodeManager.h>
62 #include <nsComponentManagerUtils.h>
67 class nsIMutableArray;
85 #define SB_DEVICE_PROPERTY_NS "http://songbirdnest.com/device/1.0"
87 #define SB_SYNC_PARTNER_PREF NS_LITERAL_STRING("SyncPartner")
108 friend class sbDevieEnsureSpaceForWrite;
149 REQUESTBATCH_UNKNOWN = 0,
150 REQUESTBATCH_AUDIO = 1,
151 REQUESTBATCH_VIDEO = 2,
152 REQUESTBATCH_IMAGE = 4
178 COMPAT_NEEDS_TRANSCODING
199 PRBool IsPlaylist()
const;
205 PRBool IsCountable()
const;
211 PRUint32 aOtherIndex,
223 NS_IMETHOD Connect();
224 NS_IMETHOD Disconnect();
225 NS_IMETHOD GetPreference(
const nsAString & aPrefName, nsIVariant **_retval);
226 NS_IMETHOD SetPreference(
const nsAString & aPrefName, nsIVariant *aPrefValue);
227 NS_IMETHOD GetIsDirectTranscoding(PRBool *aIsDirect);
228 NS_IMETHOD GetIsBusy(PRBool *aIsBusy);
229 NS_IMETHOD GetCanDisconnect(PRBool *aCanDisconnect);
230 NS_IMETHOD GetState(PRUint32 *
aState);
231 NS_IMETHOD SetState(PRUint32
aState);
232 NS_IMETHOD GetPreviousState(PRUint32 *
aState);
233 NS_IMETHOD SyncLibraries(
void);
238 NS_IMETHOD Eject(
void);
239 NS_IMETHOD Format(
void);
240 NS_IMETHOD GetSupportsReformat(PRBool *_retval);
246 NS_IMETHOD SubmitRequest(PRUint32 aRequest,
247 nsIPropertyBag2 *aRequestParameters);
248 NS_IMETHOD CancelRequests();
250 NS_IMETHOD ImportFromDevice(
sbILibrary * aImportToLibrary,
264 nsresult PushRequest(
const PRUint32 aType,
274 nsresult BatchBegin();
283 nsresult ClearRequests();
296 nsresult GetRequestTemporaryFileFactory
309 PRUint32 aBatchCount,
326 const nsAString& aPrefName,
327 nsIVariant* aPrefValue,
328 PRBool* aHasChanged);
336 nsresult HasPreference(nsAString& aPrefName,
337 PRBool* aHasPreference);
342 virtual nsresult ProcessBatch(
Batch & aBatch) = 0;
348 nsresult SetPreviousState(PRUint32
aState);
357 nsresult CreateDeviceLibrary(
const nsAString& aId,
358 nsIURI* aLibraryLocation,
369 const nsAString& aId,
370 nsIURI* aLibraryLocation);
412 nsresult UpdateLibraryProperty(
sbILibrary* aLibrary,
413 const nsAString& aPropertyID,
414 const nsAString& aPropertyValue);
425 virtual nsresult OnDefaultLibraryChanged();
438 static NS_HIDDEN_(PLDHashOperator)
439 EnumerateFinalizeMediaListListeners
444 static NS_HIDDEN_(PLDHashOperator) EnumerateIgnoreMediaListListeners(
nsISupports* aKey,
453 nsresult SetIgnoreMediaListListeners(PRBool aIgnoreListener);
460 nsresult SetIgnoreLibraryListener(PRBool aIgnoreListener);
468 nsresult SetMediaListsHidden(
sbIMediaList *aLibrary, PRBool aHidden);
498 virtual nsresult GetItemContentType(
sbIMediaItem* aMediaItem,
499 PRUint32* aContentType);
513 nsresult CreateTransferRequest(PRUint32 aRequestType,
514 nsIPropertyBag2 *aRequestParameters,
524 nsresult CreateAndDispatchEvent(PRUint32 aType,
526 PRBool aAsync = PR_TRUE,
541 PRBool aAsync = PR_TRUE);
547 nsresult RegenerateMediaURL(
sbIMediaItem *aItem, nsIURI **_retval);
559 nsACString & aFilename);
572 nsresult CreateUniqueMediaFile(nsIURI *aFileURI,
573 nsIFile **aUniqueFile,
574 nsIURI **aUniqueFileURI);
579 nsresult ReqProcessingStart();
584 nsresult ReqProcessingStop(nsIRunnable * aShutdownAction);
590 bool CheckAndResetRequestAbort();
594 bool GetEnsureSpaceChecked()
const {
595 return mEnsureSpaceChecked;
602 mEnsureSpaceChecked = aChecked;
605 NS_SCRIPTABLE NS_IMETHOD SetWarningDialogEnabled(
const nsAString & aWarning, PRBool aEnabled);
606 NS_SCRIPTABLE NS_IMETHOD GetWarningDialogEnabled(
const nsAString & aWarning, PRBool *_retval);
607 NS_SCRIPTABLE NS_IMETHOD ResetWarningDialogs(
void);
608 NS_SCRIPTABLE NS_IMETHOD OpenInputStream(nsIURI* aURI,
609 nsIInputStream** retval);
617 virtual PRBool IsRequestAborted();
620 return mDeviceTranscoding;
639 return mDeviceImages;
646 friend class sbDeviceReqAddedEvent;
668 virtual nsresult ChangeState(PRUint32
aState);
675 virtual nsresult DeviceSpecificDisconnect() = 0;
679 nsresult GetFirstRequest(
bool aRemove, TransferRequest** _retval);
705 CAN_TRANSCODE_UNKNOWN = 0,
706 CAN_TRANSCODE_YES = 1,
747 static const PRUint32 DEFAULT_PER_TRACK_OVERHEAD = 10000;
752 static const PRUint32 SYNC_PLAYLIST_AVAILABLE_PCT = 95;
758 static const PRUint32 DEFER_DEVICE_SETUP_DELAY = 2000;
781 nsresult WaitForBatchEnd();
786 static void WaitForBatchEndCallback(nsITimer* aTimer,
792 void WaitForBatchEndCallback();
802 nsresult GetMusicFreeSpace(
sbILibrary* aLibrary,
803 PRInt64* aFreeMusicSpace);
810 nsresult GetMusicAvailableSpace(
sbILibrary* aLibrary,
811 PRInt64* aMusicAvailableSpace);
830 PRBool aReportErrors,
841 nsresult UpdateStreamingItemSupported(
Batch & aBatch);
854 virtual nsresult SupportsMediaItemDRM(
sbIMediaItem* aMediaItem,
855 PRBool aReportErrors,
875 nsInterfaceHashtableMT<nsStringHashKey,
877 nsInterfaceHashtableMT<nsStringHashKey,
925 virtual nsresult GetDeviceSettingsDocument
926 (
class nsIDOMDocument** aDeviceSettingsDocument);
936 nsresult GetDeviceSettingsDocument
937 (nsIFile* aDeviceSettingsFile,
938 class nsIDOMDocument** aDeviceSettingsDocument);
947 nsresult GetDeviceSettingsDocument
948 (nsTArray<PRUint8>& aDeviceSettingsContent,
949 class nsIDOMDocument** aDeviceSettingsDocument);
953 virtual nsresult ApplyDeviceSettingsDocument();
961 virtual nsresult ApplyDeviceSettings
962 (
class nsIDOMDocument* aDeviceSettingsDocument);
974 nsresult ApplyDeviceSettingsToProperty
975 (
class nsIDOMDocument* aDeviceSettingsDocument,
976 const nsAString& aPropertyName);
985 virtual nsresult ApplyDeviceSettingsToProperty
986 (
const nsAString& aPropertyName,
987 nsIVariant* aPropertyValue);
995 nsresult ApplyDeviceSettingsDeviceInfo
996 (
class nsIDOMDocument* aDeviceSettingsDocument);
1004 nsresult ApplyDeviceSettingsToCapabilities
1005 (
class nsIDOMDocument* aDeviceSettingsDocument);
1017 virtual nsresult InitializeProperties();
1022 virtual nsresult UpdateProperties();
1029 virtual nsresult UpdateProperty(
const nsAString&
aName);
1034 virtual nsresult UpdateStatisticsProperties();
1039 nsresult UpdateVolumeNames();
1056 nsresult GetPrefBranchRoot(nsACString& aRoot);
1066 nsresult GetPrefBranch(
const char *aPrefBranchName,
1071 const nsAString & aPrefName,
1072 nsIVariant **_retval);
1076 const nsAString & aPrefName,
1077 nsIVariant *aPrefValue);
1080 nsresult SetPreferenceInternalNoNotify(
const nsAString & aPrefName,
1081 nsIVariant *aPrefValue,
1082 PRBool *aPrefChanged);
1093 virtual nsresult ApplyPreference(
const nsAString& aPrefName,
1094 nsIVariant* aPrefValue);
1103 PRBool GetIsLibraryPreference(
const nsAString& aPrefName);
1117 nsresult GetPreferenceLibrary(
const nsAString& aPrefName,
1119 nsAString& aLibraryPrefBase);
1132 const nsAString& aLibraryPrefName,
1133 nsIVariant** aPrefValue);
1144 nsresult GetLibraryPreference(
const nsAString& aLibraryPrefBase,
1145 const nsAString& aLibraryPrefName,
1146 nsIVariant** aPrefValue);
1160 const nsAString& aLibraryPrefName,
1161 nsIVariant* aPrefValue);
1176 virtual nsresult ApplyLibraryOrganizePreference(
sbIDeviceLibrary* aLibrary,
1177 const nsAString& aLibraryPrefName,
1178 const nsAString& aLibraryPrefBase,
1179 nsIVariant* aPrefValue);
1188 nsresult GetLibraryPreferenceName(
const nsAString& aPrefName,
1189 nsAString& aLibraryPrefName);
1200 nsresult GetLibraryPreferenceName(
const nsAString& aPrefName,
1201 const nsAString& aLibraryPrefBase,
1202 nsAString& aLibraryPrefName);
1212 nsAString& aPrefBase);
1220 nsresult GetCapabilitiesPreference(nsIVariant** aCapabilities);
1228 nsresult GetLocalDeviceDir(nsIFile** aLocalDeviceDir);
1240 nsresult SendSyncCompleteRequest();
1268 PRBool* aCapacityExceeded,
1285 nsresult SyncCreateAndSyncToList
1288 PRInt64 aAvailableSpace);
1303 nsresult SyncCreateSyncMediaList(
sbILibrary* aSrcLib,
1305 PRInt64 aAvailableSpace,
1342 PRInt64 aAvailableSpace,
1343 PRUint32& aLastChangeThatFit,
1344 PRInt64& aTotalSyncSize);
1354 nsresult SyncGetSyncAvailableSpace(
sbILibrary* aLibrary,
1355 PRInt64* aAvailableSpace);
1377 nsresult SyncMainLibraryFlag(
sbIMediaItem * aMediaItem);
1385 nsresult PromptForEjectDuringPlayback(PRBool* aEject);
1390 virtual nsresult UpdateMediaFolders();
1404 nsresult GetDeviceWriteDestURI(
sbIMediaItem* aWriteDstItem,
1405 nsIURI* aContentSrcBaseURI,
1406 nsIURI* aWriteSrcURI,
1407 nsIURI ** aDestinationURI);
1414 nsresult ListenToMediaLists(
sbILibrary * aLibrary);
1419 nsresult SetupDevice();
1425 static void DeferredSetupDevice(nsITimer* aTimer,
1428 nsresult DeferredSetupDevice();
1433 nsresult RegisterDeviceInfo();
1443 nsresult ProcessInfoRegistrars();
1451 virtual nsresult GetSupportedTranscodeProfiles(PRUint32 aType,
1452 nsIArray **aSupportedProfiles);
1464 nsresult GetDeviceTranscodingProperty(PRUint32 aTranscodeType,
1465 const nsAString& aPropertyName,
1466 nsIVariant** aPropertyValue);
1475 nsresult DispatchTranscodeErrorEvent(
sbIMediaItem* aMediaItem,
1476 const nsAString& aErrorMessage);
1484 nsresult GetSupportedAlbumArtFormats(nsIArray * *aFormats);
1493 nsresult GetShouldLimitMusicSpace(
const nsAString & aPrefBase,
1494 PRBool *aOutShouldLimitSpace);
1504 nsresult GetMusicLimitSpacePercent(
const nsAString & aPrefBase,
1505 PRUint32 *aOutLimitPercentage);
1510 static PLDHashOperator RemoveLibraryEnumerator(
1512 nsCOMPtr<nsIMutableArray> & aItems,
1542 nsInterfaceHashtable<nsISupportsHashKey, nsIMutableArray> groupedItems;
1543 groupedItems.Init();
1545 while (iter != end) {
1547 PRUint32 type = request->
GetType();
1554 if (request->
list && request->
item) {
1555 nsCOMPtr<nsIMutableArray> items;
1556 groupedItems.Get(request->
list, getter_AddRefs(items));
1558 items = do_CreateInstance(
1559 "@songbirdnest.com/moz/xpcom/threadsafe-array;1",
1561 NS_ENSURE_TRUE(groupedItems.Put(request->
list, items),
1562 NS_ERROR_OUT_OF_MEMORY);
1564 rv = items->AppendElement(request->
item, PR_FALSE);
1565 NS_ENSURE_SUCCESS(rv, rv);
1573 groupedItems.Enumerate(RemoveLibraryEnumerator,
this);
1581 nsresult GetNameBase(nsAString&
aName);
1589 nsresult GetProductNameBase(
char const * aDefaultModelNumberString,
1590 nsAString& aProductName);
1597 IgnoreWatchFolderPath(nsIURI * aURI,
1602 void LogDeviceFolders();
1606 static PLDHashOperator LogDeviceFoldersEnum(
const unsigned int& aKey,
1609 nsresult GetExcludedFolders(nsTArray<nsString> & aExcludedFolders);
1615 nsresult UpdateMediaLists(nsIArray * aMediaLists);
1622 nsresult AddMediaLists(
sbILibrary * aLibrary,
1623 nsIArray * aMediaLists);
1632 PRBool * aImportAudio,
1633 PRBool * aImportVideo);
nsCOMPtr< nsIFile > downloadedFile
nsresult CreateAndDispatchDeviceManagerEvent(PRUint32 aType, nsIVariant *aData, nsISupports *aOrigin, PRUint32 aDeviceState, PRBool aAsync)
void SBWriteRequestSplitBatches(const sbBaseDevice::Batch &aInput, sbBaseDevice::Batch &aNonTranscodeItems, sbBaseDevice::Batch &aTrancodeItems, sbBaseDevice::Batch &aPlaylistItems)
nsAutoPtr< sbDeviceStatusHelper > mStatus
const unsigned long REQUEST_SYNC
[UNIMPLEMENTED UNTIL AFTER 0.3]
PRLock * mPreviousStateLock
nsRefPtr< sbDeviceRequestThreadQueue > mRequestThreadQueue
PRBool destinationMediaPresent
const unsigned long REQUEST_WIPE
nsRefPtr< sbBaseDeviceVolume > mPrimaryVolume
nsCOMPtr< sbIDeviceLibrary > mDefaultLibrary
sbDeviceImages * GetDeviceImages() const
Songbird Base Device Volume Definitions.
nsCOMPtr< sbILibrary > mMainLibrary
CompatibilityType destinationCompatibility
An object defining a transcoding profile.
PRUint32 mCanTranscodeAudio
nsRefPtr< sbBaseDeviceLibraryListener > mLibraryListener
nsRefPtr< sbBaseDeviceVolume > mDefaultVolume
PRUint32 mInfoRegistrarType
sbDeviceTranscoding * mDeviceTranscoding
const unsigned long REQUEST_SUSPEND
const unsigned long REQUEST_READ
sbDeviceTranscoding * GetDeviceTranscoding() const
nsRefPtr< sbDeviceBaseLibraryCopyListener > mLibraryCopyListener
const unsigned long REQUEST_FLAG_USER
const unsigned long REQUEST_WRITE
const unsigned long REQUEST_DELETE
virtual nsresult InitDevice()
const unsigned long REQUEST_EJECT
nsresult RemoveLibraryItems(T iter, T end)
const unsigned long REQUEST_WRITE_FILE
void SetEnsureSpaceChecked(bool aChecked)
const unsigned long REQUEST_SYNC_COMPLETE
nsCOMPtr< nsITimer > mDeferredSetupDeviceTimer
nsInterfaceHashtableMT< nsStringHashKey, sbBaseDeviceVolume > mVolumeGUIDTable
nsDataHashtableMT< nsISupportsHashKey, nsRefPtr< sbBaseDeviceMediaListListener > > mMediaListListeners
PRUint32 mMusicLimitPercent
nsCOMPtr< sbIDeviceInfoRegistrar > mInfoRegistrar
PRUint32 mPerTrackOverhead
sbITranscodeProfile * transcodeProfile
Media library abstraction.
SB_AUTO_NULL_CLASS(sbAutoResetEnsureSpaceChecked, sbBaseDevice *, mValue->SetEnsureSpaceChecked(false))
const unsigned long REQUEST_FLAG_WRITE
const unsigned long REQUEST_DELETE_FILE
nsClassHashtable< nsUint32HashKey, nsString > mMediaFolderURLTable
const unsigned long REQUEST_MOVE
nsTArray< nsRefPtr< sbBaseDeviceVolume > > mVolumeList
Songbird Device Statistics Definitions.
sbRequestThreadQueue::Batch Batch
const unsigned long REQUEST_IMAGESYNC
const unsigned long REQUEST_FORMAT
nsDataHashtableMT< nsStringHashKey, PRBool > mTrackSourceTable
nsCOMPtr< sbIDeviceCapabilities > mCapabilities
sbDeviceImages * mDeviceImages
const unsigned long REQUEST_NEW_PLAYLIST
nsCOMPtr< sbIMediaItem > item
PRUint32 GetDeviceState()
nsCOMPtr< sbITemporaryFileFactory > temporaryFileFactory
nsClassHashtableMT< nsIDHashKey, OrganizeData > mOrganizeLibraryPrefs
nsInterfaceHashtableMT< nsStringHashKey, sbBaseDeviceVolume > mVolumeLibraryGUIDTable
const unsigned long REQUEST_MOUNT
nsCOMPtr< sbIMediaList > list
nsCOMPtr< sbITranscodeAlbumArt > albumArt
const unsigned long REQUEST_UPDATE
PRUint32 mCanTranscodeVideo
PRInt32 mIgnoreMediaListCount
_updateTextAndScrollDataForFrame aData
nsCOMPtr< nsISupports > data