50 #include <sbIDatabaseResult.h>
53 #include <nsComponentManagerUtils.h>
68 sbIPDDevice::MapInitialize()
73 nsCOMPtr<sbIDatabaseQuery> idQuery;
74 rv = IDMapCreateDBQuery(getter_AddRefs(idQuery));
75 NS_ENSURE_SUCCESS(rv, rv);
78 rv = ExecuteQuery(idQuery,
79 "CREATE TABLE IF NOT EXISTS ipod_id_map "
80 "(ipod_id BLOB NOT NULL, songbird_id BLOB NOT NULL)",
82 NS_ENSURE_SUCCESS(rv, rv);
93 sbIPDDevice::MapFinalize()
117 sbIPDDevice::IDMapAdd(nsAString& aSBID,
124 PR_snprintf(queryStr,
126 "INSERT OR REPLACE INTO ipod_id_map"
127 "(songbird_id, ipod_id) VALUES"
128 "(\"%s\", \"%08x:%08x\")",
129 NS_ConvertUTF16toUTF8(aSBID).
get(),
130 (PRUint32) ((aIPodID >> 32) & 0xFFFFFFFF),
131 (PRUint32) (aIPodID & 0xFFFFFFFF));
134 nsCOMPtr<sbIDatabaseQuery> idQuery;
135 rv = IDMapCreateDBQuery(getter_AddRefs(idQuery));
136 NS_ENSURE_SUCCESS(rv, rv);
139 rv = ExecuteQuery(idQuery, queryStr, nsnull);
140 NS_ENSURE_SUCCESS(rv, rv);
153 sbIPDDevice::IDMapRemove(guint64 aIPodID)
159 PR_snprintf(queryStr,
161 "DELETE FROM ipod_id_map WHERE ipod_id = \"%08x:%08x\"",
162 (PRUint32) ((aIPodID >> 32) & 0xFFFFFFFF),
163 (PRUint32) (aIPodID & 0xFFFFFFFF));
166 nsCOMPtr<sbIDatabaseQuery> idQuery;
167 rv = IDMapCreateDBQuery(getter_AddRefs(idQuery));
168 NS_ENSURE_SUCCESS(rv, rv);
171 rv = ExecuteQuery(idQuery, queryStr, nsnull);
172 NS_ENSURE_SUCCESS(rv, rv);
187 sbIPDDevice::IDMapGet(nsAString& aSBID,
188 nsTArray<guint64>& aIPodIDList)
194 PR_snprintf(queryStr,
196 "SELECT ipod_id FROM ipod_id_map WHERE songbird_id = \"%s\"",
197 NS_ConvertUTF16toUTF8(aSBID).
get());
200 nsCOMPtr<sbIDatabaseQuery> idQuery;
201 rv = IDMapCreateDBQuery(getter_AddRefs(idQuery));
202 NS_ENSURE_SUCCESS(rv, rv);
205 nsCOMPtr<sbIDatabaseResult> dbResult;
206 rv = ExecuteQuery(idQuery, queryStr, getter_AddRefs(dbResult));
207 NS_ENSURE_SUCCESS(rv, rv);
211 rv = dbResult->GetRowCount(&rowCount);
213 for (PRUint32
i = 0;
i < rowCount;
i++) {
215 nsAutoString iPodIDStr;
216 rv = dbResult->GetRowCell(
i, 0, iPodIDStr);
217 NS_ENSURE_SUCCESS(rv, rv);
220 guint32 iPodIDHi, iPodIDLo;
222 numScanned = PR_sscanf(NS_ConvertUTF16toUTF8(iPodIDStr).
get(),
226 if (numScanned >= 2) {
227 guint64 iPodID = (((guint64) iPodIDHi) << 32) | ((guint64) iPodIDLo);
228 aIPodIDList.AppendElement(iPodID);
248 sbIPDDevice::IDMapGet(nsAString& aSBID,
252 NS_ASSERTION(aIPodID,
"aIPodID is null");
258 nsTArray<guint64> iPodIDList;
259 rv = IDMapGet(aSBID, iPodIDList);
260 if (NS_FAILED(rv) || (iPodIDList.Length() == 0))
261 return NS_ERROR_NOT_AVAILABLE;
264 *aIPodID = iPodIDList[0];
281 sbIPDDevice::IDMapGet(guint64 aIPodID,
288 PR_snprintf(queryStr,
290 "SELECT songbird_id FROM ipod_id_map "
291 "WHERE ipod_id = \"%08x:%08x\"",
292 (PRUint32) ((aIPodID >> 32) & 0xFFFFFFFF),
293 (PRUint32) (aIPodID & 0xFFFFFFFF));
296 nsCOMPtr<sbIDatabaseQuery> idQuery;
297 rv = IDMapCreateDBQuery(getter_AddRefs(idQuery));
298 NS_ENSURE_SUCCESS(rv, rv);
301 nsCOMPtr<sbIDatabaseResult> dbResult;
302 rv = ExecuteQuery(idQuery, queryStr, getter_AddRefs(dbResult));
303 NS_ENSURE_SUCCESS(rv, rv);
307 rv = dbResult->GetRowCount(&rowCount);
309 return NS_ERROR_NOT_AVAILABLE;
310 rv = dbResult->GetRowCell(0, 0, aSBID);
311 NS_ENSURE_SUCCESS(rv, rv);
330 sbIPDDevice::IDMapGet(guint64 aIPodID,
331 nsAString& aLibraryGUID,
332 nsAString& aResourceGUID)
338 rv = IDMapGet(aIPodID, sbID);
340 return NS_ERROR_NOT_AVAILABLE;
343 rv = DecodeSBID(sbID, aLibraryGUID, aResourceGUID);
344 NS_ENSURE_SUCCESS(rv, rv);
362 sbIPDDevice::IDMapGet(guint64 aIPodID,
366 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
372 nsAutoString libraryGUID;
373 nsAutoString itemGUID;
374 rv = IDMapGet(aIPodID, libraryGUID, itemGUID);
375 NS_ENSURE_SUCCESS(rv, rv);
378 nsCOMPtr<sbILibrary> library;
379 nsCOMPtr<sbIMediaItem> mediaItem;
380 rv = mLibraryManager->GetLibrary(libraryGUID, getter_AddRefs(library));
382 return NS_ERROR_NOT_AVAILABLE;
383 rv = library->GetItemByGuid(itemGUID, getter_AddRefs(mediaItem));
385 return NS_ERROR_NOT_AVAILABLE;
388 NS_ADDREF(*aMediaItem = mediaItem);
404 NS_ASSERTION(aQuery,
"aQuery is null");
410 nsCOMPtr<sbIDatabaseQuery>
411 query = do_CreateInstance(
"@songbirdnest.com/Songbird/DatabaseQuery;1",
413 NS_ENSURE_SUCCESS(rv, rv);
416 rv = query->SetAsyncQuery(PR_FALSE);
417 NS_ENSURE_SUCCESS(rv, rv);
418 rv = query->SetDatabaseGUID(NS_LITERAL_STRING(
"iPod"));
419 NS_ENSURE_SUCCESS(rv, rv);
422 NS_ADDREF(*aQuery = query);
440 NS_ASSERTION(aMediaItem,
"aMediaItem is null");
446 nsCOMPtr<sbILibrary> library;
447 rv = aMediaItem->GetLibrary(getter_AddRefs(library));
448 NS_ENSURE_SUCCESS(rv, rv);
451 nsAutoString libraryGUID;
452 nsAutoString itemGUID;
453 rv = library->GetGuid(libraryGUID);
454 NS_ENSURE_SUCCESS(rv, rv);
455 rv = aMediaItem->GetGuid(itemGUID);
456 NS_ENSURE_SUCCESS(rv, rv);
459 rv = EncodeSBID(aSBID, libraryGUID, itemGUID);
460 NS_ENSURE_SUCCESS(rv, rv);
481 sbIPDDevice::IPodItemGetID(
void* aIPodItem,
486 NS_ASSERTION(aIPodItem,
"aIPodItem is null");
487 NS_ASSERTION(aIPodID,
"aIPodID is null");
491 if (aType == TypePlaylist) {
492 Itdb_Playlist* playlist = (Itdb_Playlist*) aIPodItem;
493 iPodID = playlist->id;
495 Itdb_Track* track = (Itdb_Track*) aIPodItem;
496 iPodID = track->dbid;
516 sbIPDDevice::DecodeSBID(
const nsAString& aSBID,
517 nsAString& aLibraryGUID,
518 nsAString& aResourceGUID)
521 PRInt32
pos = aSBID.RFindChar(SBIDDelimiter);
522 NS_ENSURE_TRUE(pos != -1, NS_ERROR_INVALID_ARG);
523 aLibraryGUID.Assign(Substring(aSBID, 0, pos));
524 aResourceGUID.Assign(Substring(aSBID, pos + 1));
540 sbIPDDevice::EncodeSBID(nsAString& aSBID,
541 const nsAString& aLibraryGUID,
542 const nsAString& aResourceGUID)
545 aSBID.Assign(aLibraryGUID);
546 nsCAutoString nsDelimiter;
548 delimiter[0] = SBIDDelimiter;
550 aSBID.AppendLiteral(delimiter);
551 aSBID.Append(aResourceGUID);
569 const char* aQueryStr,
573 NS_ASSERTION(aDBQuery,
"aDBQuery is null");
574 NS_ASSERTION(aQueryStr,
"aQueryStr is null");
581 rv = aDBQuery->ResetQuery();
582 NS_ENSURE_SUCCESS(rv, rv);
583 rv = aDBQuery->AddQuery(NS_ConvertUTF8toUTF16(aQueryStr));
584 NS_ENSURE_SUCCESS(rv, rv);
587 rv = aDBQuery->Execute(&dbError);
588 NS_ENSURE_SUCCESS(rv, rv);
589 NS_ENSURE_FALSE(dbError, NS_ERROR_FAILURE);
593 nsCOMPtr<sbIDatabaseResult> dbResult;
594 rv = aDBQuery->GetResultObject(getter_AddRefs(dbResult));
595 NS_ENSURE_TRUE(dbResult, NS_ERROR_FAILURE);
596 NS_ADDREF(*aDBResult = dbResult);
598 rv = aDBQuery->ResetQuery();
599 NS_ENSURE_SUCCESS(rv, rv);
Songbird iPod Device Definitions.
An object containing the results of a database SELECT query.
An object responsible for executing SQL queries on the database.
_getSelectedPageStyle s i