27 #include <sbIDatabaseResult.h>
29 #include <nsAutoLock.h>
30 #include <nsICategoryManager.h>
31 #include <nsComponentManagerUtils.h>
33 #include <nsIIOService.h>
34 #include <nsIMutableArray.h>
35 #include <nsIObserverService.h>
36 #include <nsIProperties.h>
37 #include <nsIRunnable.h>
38 #include <nsIThread.h>
39 #include <nsIThreadManager.h>
40 #include <nsIThreadPool.h>
42 #include <nsNetUtil.h>
43 #include <nsServiceManagerUtils.h>
44 #include <nsThreadUtils.h>
53 nsString
c2h( PRUnichar dec )
55 char dig1 = (dec&0xF0)>>4;
56 char dig2 = (dec&0x0F);
57 if ( 0<= dig1 && dig1<= 9) dig1+=48;
58 if (10<= dig1 && dig1<=15) dig1+=97-10;
59 if ( 0<= dig2 && dig2<= 9) dig2+=48;
60 if (10<= dig2 && dig2<=15) dig2+=97-10;
73 for (
int i=0;
i<max;
i++) {
74 if ((48 <= c[
i] && c[
i] <= 57) ||
75 (65 <= c[
i] && c[
i] <= 90) ||
76 (97 <= c[
i] && c[
i] <= 122) ||
77 (c[
i]==
'~' || c[
i]==
'!' || c[
i]==
'*' || c[
i]==
'(' || c[
i]==
')' || c[
i]==
'\'')
83 escaped.AppendLiteral(
"%");
84 escaped.Append(
c2h(c[
i]) );
102 NS_DECL_NSISIMPLEENUMERATOR
134 NS_ENSURE_ARG_POINTER(aResult);
135 NS_ENSURE_ARG_POINTER(aQuery);
139 PRUint32 rowCount = 0;
140 rv = aResult->GetRowCount(&rowCount);
141 NS_ENSURE_SUCCESS(rv, rv);
143 for (PRUint32
i = 0;
i < rowCount;
i++) {
145 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"id"),
id);
146 NS_ENSURE_SUCCESS(rv, rv);
149 PRBool hasRecord = PR_FALSE;
151 if (NS_FAILED(rv) || hasRecord) {
156 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"name"), artistName);
157 NS_ENSURE_SUCCESS(rv, rv);
161 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"artistURL"), artistURL);
162 NS_ENSURE_SUCCESS(rv, rv);
165 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"timestamp"), ts);
166 NS_ENSURE_SUCCESS(rv, rv);
169 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"venue"), venue);
170 NS_ENSURE_SUCCESS(rv, rv);
174 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"city"), city);
175 NS_ENSURE_SUCCESS(rv, rv);
178 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"title"), title);
179 NS_ENSURE_SUCCESS(rv, rv);
183 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"concertURL"), url);
184 NS_ENSURE_SUCCESS(rv, rv);
187 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"libraryArtist"), lib);
188 NS_ENSURE_SUCCESS(rv, rv);
191 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"venueURL"), venueURL);
192 NS_ENSURE_SUCCESS(rv, rv);
195 rv = aResult->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"tickets"), tickets);
196 NS_ENSURE_SUCCESS(rv, rv);
199 rv = aQuery->ResetQuery();
200 NS_ENSURE_SUCCESS(rv, rv);
204 "select * from artists join playing_at on playing_at.concertid=");
206 stmt.AppendLiteral(
" and playing_at.artistid = artists.ROWID");
208 rv = aQuery->AddQuery(stmt);
209 NS_ENSURE_SUCCESS(rv, rv);
212 rv = aQuery->Execute(&queryResult);
213 NS_ENSURE_SUCCESS(rv, rv);
214 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
216 nsCOMPtr<sbIDatabaseResult> playingAtResult;
217 rv = aQuery->GetResultObject(getter_AddRefs(playingAtResult));
218 NS_ENSURE_SUCCESS(rv, rv);
220 PRUint32 playingAtCount = 0;
221 rv = playingAtResult->GetRowCount(&playingAtCount);
222 NS_ENSURE_SUCCESS(rv, rv);
224 nsCOMPtr<nsIMutableArray> artistConcertInfoArray =
225 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
226 NS_ENSURE_SUCCESS(rv, rv);
228 for (PRUint32
i = 0;
i < playingAtCount;
i++) {
229 nsRefPtr<sbSongkickArtistConcertInfo> curArtistInfo =
231 NS_ENSURE_TRUE(curArtistInfo, NS_ERROR_OUT_OF_MEMORY);
234 playingAtResult->GetRowCellByColumn(
235 i, NS_LITERAL_STRING(
"name"), artistName);
239 playingAtResult->GetRowCellByColumn(
240 i, NS_LITERAL_STRING(
"artistURL"), artistURL);
242 rv = curArtistInfo->Init(artistName, artistURL);
243 NS_ENSURE_SUCCESS(rv, rv);
245 rv = artistConcertInfoArray->AppendElement(curArtistInfo, PR_FALSE);
246 NS_ENSURE_SUCCESS(rv, rv);
249 nsRefPtr<sbSongkickConcertInfo> curInfo =
251 NS_ENSURE_TRUE(curInfo, NS_ERROR_OUT_OF_MEMORY);
253 rv = curInfo->Init(artistName,
263 artistConcertInfoArray,
265 NS_ENSURE_SUCCESS(rv, rv);
277 const nsAString & aID,
281 NS_ENSURE_ARG_POINTER(aHasEntry);
282 *aHasEntry = PR_FALSE;
287 for (next = begin; next != end && !*aHasEntry; ++
next) {
288 if ((*next)->mID.Equals(aID)) {
289 *aHasEntry = PR_TRUE;
297 sbSongkickResultEnumerator::HasMoreElements(PRBool *aHasMore)
299 NS_ENSURE_ARG_POINTER(aHasMore);
305 sbSongkickResultEnumerator::GetNext(
nsISupports **aOutNext)
307 NS_ENSURE_ARG_POINTER(aOutNext);
310 nsCOMPtr<nsISupports> curConcertInfo =
313 curConcertInfo.forget(aOutNext);
348 nsCOMPtr<sbIDatabaseQuery> mDBQuery;
349 nsRefPtr<sbSongkickDBService> mDBService;
356 : mGotLocationInfo(PR_FALSE)
367 NS_ENSURE_ARG_POINTER(aService);
368 mDBService = aService;
372 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
373 NS_ENSURE_SUCCESS(rv, rv);
376 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
377 NS_ENSURE_SUCCESS(rv, rv);
380 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
381 NS_ENSURE_SUCCESS(rv, rv);
387 sbSongkickDBInfo::Run()
389 NS_ENSURE_TRUE(mDBService, NS_ERROR_UNEXPECTED);
392 rv = mDBService->GetDatabaseQuery(getter_AddRefs(mDBQuery));
393 if (rv == NS_ERROR_NOT_AVAILABLE) {
397 NS_ENSURE_SUCCESS(rv, rv);
400 NS_ENSURE_SUCCESS(rv, rv);
403 NS_ENSURE_SUCCESS(rv, rv);
406 NS_ENSURE_SUCCESS(rv, rv);
409 NS_ENSURE_SUCCESS(rv, rv);
418 rv = mDBQuery->ResetQuery();
419 NS_ENSURE_SUCCESS(rv, rv);
422 stmt.AssignLiteral(
"select count(*) from cities");
424 rv = mDBQuery->AddQuery(stmt);
425 NS_ENSURE_SUCCESS(rv, rv);
428 rv = mDBQuery->Execute(&queryResult);
429 NS_ENSURE_SUCCESS(rv, rv);
430 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
432 nsCOMPtr<sbIDatabaseResult> results;
433 rv = mDBQuery->GetResultObject(getter_AddRefs(results));
434 NS_ENSURE_SUCCESS(rv, rv);
436 nsString rowCountStr;
437 rv = results->GetRowCell(0, 0, rowCountStr);
438 NS_ENSURE_SUCCESS(rv, rv);
440 PRUint32 rowCount = rowCountStr.ToInteger(&rv);
441 NS_ENSURE_SUCCESS(rv, rv);
452 rv = mDBQuery->ResetQuery();
453 NS_ENSURE_SUCCESS(rv, rv);
455 rv = mDBQuery->AddQuery(NS_LITERAL_STRING(
"select * from countries"));
456 NS_ENSURE_SUCCESS(rv, rv);
459 rv = mDBQuery->Execute(&queryResult);
460 NS_ENSURE_SUCCESS(rv, rv);
461 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
463 nsCOMPtr<sbIDatabaseResult> results;
464 rv = mDBQuery->GetResultObject(getter_AddRefs(results));
465 NS_ENSURE_SUCCESS(rv, rv);
467 PRUint32 rowCount = 0;
468 rv = results->GetRowCount(&rowCount);
469 NS_ENSURE_SUCCESS(rv, rv);
471 for (PRUint32
i = 0;
i < rowCount;
i++) {
473 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"id"),
id);
474 NS_ENSURE_SUCCESS(rv, rv);
475 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"name"), name);
476 NS_ENSURE_SUCCESS(rv, rv);
479 NS_ENSURE_TRUE(curProp, NS_ERROR_OUT_OF_MEMORY);
481 rv = curProp->Init(name,
id, EmptyString());
482 NS_ENSURE_SUCCESS(rv, rv);
485 NS_ENSURE_SUCCESS(rv, rv);
495 rv = mDBQuery->ResetQuery();
496 NS_ENSURE_SUCCESS(rv, rv);
498 rv = mDBQuery->AddQuery(NS_LITERAL_STRING(
"select * from states"));
499 NS_ENSURE_SUCCESS(rv, rv);
502 rv = mDBQuery->Execute(&queryResult);
503 NS_ENSURE_SUCCESS(rv, rv);
504 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
506 nsCOMPtr<sbIDatabaseResult> results;
507 rv = mDBQuery->GetResultObject(getter_AddRefs(results));
508 NS_ENSURE_SUCCESS(rv, rv);
510 PRUint32 rowCount = 0;
511 rv = results->GetRowCount(&rowCount);
512 NS_ENSURE_SUCCESS(rv, rv);
514 for (PRUint32
i = 0;
i < rowCount;
i++) {
515 nsString
id,
name, country;
516 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"id"),
id);
517 NS_ENSURE_SUCCESS(rv, rv);
518 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"name"), name);
519 NS_ENSURE_SUCCESS(rv, rv);
520 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"country"), country);
521 NS_ENSURE_SUCCESS(rv, rv);
524 NS_ENSURE_TRUE(curProp, NS_ERROR_OUT_OF_MEMORY);
526 rv = curProp->Init(name,
id, country);
527 NS_ENSURE_SUCCESS(rv, rv);
529 rv =
mStateProps->AppendElement(curProp, PR_FALSE);
530 NS_ENSURE_SUCCESS(rv, rv);
540 rv = mDBQuery->ResetQuery();
541 NS_ENSURE_SUCCESS(rv, rv);
543 rv = mDBQuery->AddQuery(NS_LITERAL_STRING(
"select * from cities"));
544 NS_ENSURE_SUCCESS(rv, rv);
547 rv = mDBQuery->Execute(&queryResult);
548 NS_ENSURE_SUCCESS(rv, rv);
549 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
551 nsCOMPtr<sbIDatabaseResult> results;
552 rv = mDBQuery->GetResultObject(getter_AddRefs(results));
553 NS_ENSURE_SUCCESS(rv, rv);
555 PRUint32 rowCount = 0;
556 rv = results->GetRowCount(&rowCount);
557 NS_ENSURE_SUCCESS(rv, rv);
559 for (PRUint32
i = 0;
i < rowCount;
i++) {
561 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"id"),
id);
562 NS_ENSURE_SUCCESS(rv, rv);
563 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"name"), name);
564 NS_ENSURE_SUCCESS(rv, rv);
565 rv = results->GetRowCellByColumn(
i, NS_LITERAL_STRING(
"state"), state);
566 NS_ENSURE_SUCCESS(rv, rv);
569 NS_ENSURE_TRUE(curProp, NS_ERROR_OUT_OF_MEMORY);
571 rv = curProp->Init(name,
id, state);
572 NS_ENSURE_SUCCESS(rv, rv);
574 rv =
mCityProps->AppendElement(curProp, PR_FALSE);
575 NS_ENSURE_SUCCESS(rv, rv);
594 nsresult
Init(
const nsAString & aQueryStmt,
602 nsCOMPtr<sbISongkickEnumeratorCallback> mCallback;
603 nsCOMPtr<nsIThread> mCallingThread;
604 nsRefPtr<sbSongkickResultEnumerator> mResultsEnum;
605 nsRefPtr<sbSongkickDBService> mDBService;
621 sbSongkickQuery::Run()
623 NS_ENSURE_TRUE(mDBService, NS_ERROR_UNEXPECTED);
627 nsCOMPtr<nsIRunnable> runnable =
629 NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE);
630 rv = mCallingThread->Dispatch(runnable, NS_DISPATCH_SYNC);
633 nsCOMPtr<sbIDatabaseQuery> db;
634 rv = mDBService->GetDatabaseQuery(getter_AddRefs(db));
635 NS_ENSURE_SUCCESS(rv, rv);
637 rv = db->AddQuery(mQueryStmt);
638 NS_ENSURE_SUCCESS(rv, rv);
641 nsAutoLock lock(mDBService->mQueryRunningLock);
645 rv = db->Execute(&queryResult);
646 NS_ENSURE_SUCCESS(rv, rv);
647 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
651 nsCOMPtr<sbIDatabaseResult> results;
652 rv = db->GetResultObject(getter_AddRefs(results));
653 NS_ENSURE_SUCCESS(rv, rv);
657 nsCOMPtr<sbIDatabaseQuery> artistDB;
658 rv = mDBService->GetDatabaseQuery(getter_AddRefs(artistDB));
659 NS_ENSURE_SUCCESS(rv, rv);
662 NS_ENSURE_TRUE(mResultsEnum, NS_ERROR_OUT_OF_MEMORY);
663 rv = mResultsEnum->Init(results, artistDB);
664 NS_ENSURE_SUCCESS(rv, rv);
669 NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE);
670 rv = mCallingThread->Dispatch(runnable, NS_DISPATCH_SYNC);
671 NS_ENSURE_SUCCESS(rv, rv);
681 NS_ENSURE_ARG_POINTER(aCallback);
682 NS_ENSURE_ARG_POINTER(aDBService);
684 mQueryStmt = aQueryStmt;
685 mDBService = aDBService;
686 mCallback = aCallback;
690 nsCOMPtr<nsIThreadManager> threadMgr =
691 do_GetService(
"@mozilla.org/thread-manager;1", &rv);
692 NS_ENSURE_SUCCESS(rv, rv);
693 rv = threadMgr->GetCurrentThread(getter_AddRefs(mCallingThread));
694 NS_ENSURE_SUCCESS(rv, rv);
702 NS_ENSURE_TRUE(mCallback, );
703 mCallback->OnEnumerationStart();
709 NS_ENSURE_TRUE(mCallback, );
712 nsCOMPtr<nsISimpleEnumerator> outEnum = do_QueryInterface(
715 NS_ENSURE_SUCCESS(rv, );
717 mCallback->OnEnumerationEnd(outEnum);
733 nsresult
Init(
const nsAString & aQueryStmt,
740 nsCOMPtr<sbISongkickConcertCountCallback> mCallback;
741 nsCOMPtr<nsIThread> mCallingThread;
742 nsRefPtr<sbSongkickDBService> mDBService;
764 NS_ENSURE_ARG_POINTER(aCallback);
765 NS_ENSURE_ARG_POINTER(aDBService);
767 mDBService = aDBService;
768 mCallback = aCallback;
769 mQueryStmt = aQueryStmt;
773 rv = NS_GetCurrentThread(getter_AddRefs(mCallingThread));
774 NS_ENSURE_SUCCESS(rv, rv);
780 sbSongkickCountQuery::Run()
785 nsCOMPtr<sbIDatabaseQuery> db;
786 rv = mDBService->GetDatabaseQuery(getter_AddRefs(db));
787 NS_ENSURE_SUCCESS(rv, rv);
789 rv = db->AddQuery(mQueryStmt);
790 NS_ENSURE_SUCCESS(rv, rv);
794 rv = db->Execute(&queryResult);
795 NS_ENSURE_SUCCESS(rv, rv);
796 NS_ENSURE_TRUE(queryResult == 0, NS_ERROR_FAILURE);
799 nsCOMPtr<sbIDatabaseResult> results;
800 rv = db->GetResultObject(getter_AddRefs(results));
801 NS_ENSURE_SUCCESS(rv, rv);
803 nsString rowCountStr;
804 rv = results->GetRowCell(0, 0, rowCountStr);
805 NS_ENSURE_SUCCESS(rv, rv);
807 mCount = rowCountStr.ToInteger(&rv);
808 NS_ENSURE_SUCCESS(rv, rv);
810 nsCOMPtr<nsIRunnable> runnable =
812 NS_ENSURE_TRUE(runnable, NS_ERROR_FAILURE);
813 rv = mCallingThread->Dispatch(runnable, NS_DISPATCH_SYNC);
814 NS_ENSURE_SUCCESS(rv, rv);
822 NS_ENSURE_TRUE(mCallback, );
823 mCallback->OnConcertCountEnd(mCount);
836 NS_ASSERTION(mQueryRunningLock,
"Failed to create mQueryRunningLock");
852 rv = mDBInfo->Init(
this);
853 NS_ENSURE_SUCCESS(rv, rv);
856 do_GetService(
"@mozilla.org/observer-service;1", &rv);
857 NS_ENSURE_SUCCESS(rv, rv);
859 rv = observerService->AddObserver(
this,
862 NS_ENSURE_SUCCESS(rv, rv);
870 NS_ENSURE_TRUE(mDBInfo, NS_ERROR_UNEXPECTED);
874 nsCOMPtr<nsIThreadPool> threadPoolService =
875 do_GetService(
"@songbirdnest.com/Songbird/ThreadPoolService;1", &rv);
876 NS_ENSURE_SUCCESS(rv, rv);
878 rv = threadPoolService->Dispatch(mDBInfo, NS_DISPATCH_NORMAL);
879 NS_ENSURE_SUCCESS(rv, rv);
887 NS_ENSURE_ARG_POINTER(aOutDBQuery);
892 do_GetService(
"@mozilla.org/network/io-service;1", &rv);
893 NS_ENSURE_SUCCESS(rv, rv);
895 nsCOMPtr<nsIProperties> dirService =
896 do_GetService(
"@mozilla.org/file/directory_service;1", &rv);
897 NS_ENSURE_SUCCESS(rv, rv);
899 nsCOMPtr<nsIFile> profileFile;
900 rv = dirService->Get(
"ProfD",
902 getter_AddRefs(profileFile));
905 nsCOMPtr<nsIFile> dbFile;
906 rv = profileFile->Clone(getter_AddRefs(dbFile));
907 NS_ENSURE_SUCCESS(rv, rv);
909 rv = dbFile->Append(NS_LITERAL_STRING(
"concerts.db"));
910 NS_ENSURE_SUCCESS(rv, rv);
912 PRBool exists = PR_FALSE;
913 rv = dbFile->Exists(&exists);
914 NS_ENSURE_SUCCESS(rv, rv);
917 return NS_ERROR_NOT_AVAILABLE;
920 nsCOMPtr<nsIURI> dbLocationURI;
921 rv = NS_NewFileURI(getter_AddRefs(dbLocationURI),
924 NS_ENSURE_SUCCESS(rv, rv);
926 nsCOMPtr<sbIDatabaseQuery> db =
927 do_CreateInstance(
"@songbirdnest.com/Songbird/DatabaseQuery;1", &rv);
928 NS_ENSURE_SUCCESS(rv, rv);
929 rv = db->SetDatabaseLocation(dbLocationURI);
930 NS_ENSURE_SUCCESS(rv, rv);
931 rv = db->SetDatabaseGUID(NS_LITERAL_STRING(
"concerts"));
932 NS_ENSURE_SUCCESS(rv, rv);
934 db.forget(aOutDBQuery);
944 const char *aLoaderStr,
946 const nsModuleComponentInfo *aInfo)
948 NS_ENSURE_ARG_POINTER(aCompMgr);
949 NS_ENSURE_ARG_POINTER(aPath);
950 NS_ENSURE_ARG_POINTER(aLoaderStr);
951 NS_ENSURE_ARG_POINTER(aType);
952 NS_ENSURE_ARG_POINTER(aInfo);
954 nsresult rv = NS_ERROR_UNEXPECTED;
955 nsCOMPtr<nsICategoryManager> catMgr =
956 do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
957 NS_ENSURE_SUCCESS(rv, rv);
959 rv = catMgr->AddCategoryEntry(
"app-startup",
963 PR_TRUE, PR_TRUE, nsnull);
964 NS_ENSURE_SUCCESS(rv, rv);
973 sbSongkickDBService::GetHasLocationInfo(PRBool *aOutHasLocationInfo)
975 NS_ENSURE_ARG_POINTER(aOutHasLocationInfo);
976 NS_ENSURE_TRUE(mDBInfo, NS_ERROR_UNEXPECTED);
978 *aOutHasLocationInfo = mDBInfo->mGotLocationInfo;
983 sbSongkickDBService::GetLocationCountries(nsIArray **aOutArray)
985 NS_ENSURE_ARG_POINTER(aOutArray);
986 NS_ENSURE_TRUE(mDBInfo, NS_ERROR_NOT_AVAILABLE);
988 NS_IF_ADDREF(*aOutArray = mDBInfo->mCountriesProps);
993 sbSongkickDBService::ReloadLocationInfo(
void)
995 NS_ENSURE_TRUE(mDBInfo, NS_ERROR_UNEXPECTED);
999 NS_ENSURE_SUCCESS(rv, rv);
1005 sbSongkickDBService::GetLocationStates(
const nsAString & aCountry,
1006 nsIArray **aOutArray)
1008 NS_ENSURE_ARG_POINTER(aOutArray);
1013 nsCOMPtr<nsIMutableArray> statesArray =
1014 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1016 nsCOMPtr<nsISimpleEnumerator> statesEnum;
1017 rv = mDBInfo->mStateProps->Enumerate(getter_AddRefs(statesEnum));
1018 NS_ENSURE_SUCCESS(rv, rv);
1021 while (NS_SUCCEEDED(statesEnum->HasMoreElements(&hasMore)) && hasMore) {
1022 nsCOMPtr<nsISupports> curItem;
1023 rv = statesEnum->GetNext(getter_AddRefs(curItem));
1024 NS_ENSURE_SUCCESS(rv, rv);
1026 nsCOMPtr<sbISongkickProperty> curProp =
1027 do_QueryInterface(curItem, &rv);
1028 NS_ENSURE_SUCCESS(rv, rv);
1030 nsString curCountry;
1031 rv = curProp->GetKey(curCountry);
1032 NS_ENSURE_SUCCESS(rv, rv);
1034 if (curCountry.Equals(aCountry)) {
1035 rv = statesArray->AppendElement(curProp, PR_FALSE);
1036 NS_ENSURE_SUCCESS(rv, rv);
1040 rv = CallQueryInterface(statesArray, aOutArray);
1041 NS_ENSURE_SUCCESS(rv, rv);
1047 sbSongkickDBService::GetLocationCities(
const nsAString &
aState,
1048 nsIArray **aOutArray)
1050 NS_ENSURE_ARG_POINTER(aOutArray);
1055 nsCOMPtr<nsIMutableArray> citiesArray =
1056 do_CreateInstance(
"@songbirdnest.com/moz/xpcom/threadsafe-array;1", &rv);
1058 nsCOMPtr<nsISimpleEnumerator> cityEnum;
1059 rv = mDBInfo->mCityProps->Enumerate(getter_AddRefs(cityEnum));
1060 NS_ENSURE_SUCCESS(rv, rv);
1062 PRBool hasMore = PR_FALSE;
1063 while (NS_SUCCEEDED(cityEnum->HasMoreElements(&hasMore)) && hasMore) {
1064 nsCOMPtr<nsISupports> curItem;
1065 rv = cityEnum->GetNext(getter_AddRefs(curItem));
1066 NS_ENSURE_SUCCESS(rv, rv);
1068 nsCOMPtr<sbISongkickProperty> curProp =
1069 do_QueryInterface(curItem, &rv);
1070 NS_ENSURE_SUCCESS(rv, rv);
1073 rv = curProp->GetKey(curState);
1074 NS_ENSURE_SUCCESS(rv, rv);
1076 if (curState.Equals(aState)) {
1077 rv = citiesArray->AppendElement(curProp, PR_FALSE);
1078 NS_ENSURE_SUCCESS(rv, rv);
1082 rv = CallQueryInterface(citiesArray, aOutArray);
1083 NS_ENSURE_SUCCESS(rv, rv);
1089 sbSongkickDBService::StartAristConcertLookup(
1093 NS_ENSURE_ARG_POINTER(aCallback);
1096 stmt.AppendLiteral(
"SELECT * FROM playing_at");
1097 stmt.AppendLiteral(
" JOIN artists ON playing_at.artistid = artists.ROWID");
1098 stmt.AppendLiteral(
" JOIN concerts ON playing_at.concertid = concerts.id");
1100 stmt.AppendLiteral(
" WHERE playing_at.libraryArtist = 1");
1102 stmt.AppendLiteral(
" ORDER BY artists.name COLLATE NOCASE");
1105 NS_ENSURE_TRUE(skQuery, NS_ERROR_OUT_OF_MEMORY);
1108 rv = skQuery->Init(stmt,
this, aCallback);
1109 NS_ENSURE_SUCCESS(rv, rv);
1111 nsCOMPtr<nsIThreadPool> threadPoolService =
1112 do_GetService(
"@songbirdnest.com/Songbird/ThreadPoolService;1", &rv);
1113 NS_ENSURE_SUCCESS(rv, rv);
1115 rv = threadPoolService->Dispatch(skQuery, NS_DISPATCH_NORMAL);
1116 NS_ENSURE_SUCCESS(rv, rv);
1122 sbSongkickDBService::StartConcertLookup(
1123 const nsAString & aSort,
1127 NS_ENSURE_ARG_POINTER(aCallback);
1130 stmt.AppendLiteral(
"SELECT * FROM concerts");
1131 stmt.AppendLiteral(
" JOIN playing_at ON playing_at.concertid = concerts.id");
1132 stmt.AppendLiteral(
" JOIN artists ON playing_at.artistid = artists.ROWID");
1135 stmt.AppendLiteral(
" WHERE playing_at.anyLibraryArtist = 1");
1139 stmt.AppendLiteral(
" ORDER BY ");
1140 if (aSort.EqualsLiteral(
"date")) {
1141 stmt.AppendLiteral(
"timestamp");
1143 else if (aSort.EqualsLiteral(
"venue")) {
1144 stmt.AppendLiteral(
"venue");
1148 stmt.AppendLiteral(
"title");
1152 NS_ENSURE_TRUE(skQuery, NS_ERROR_OUT_OF_MEMORY);
1155 rv = skQuery->Init(stmt,
this, aCallback);
1156 NS_ENSURE_SUCCESS(rv, rv);
1158 nsCOMPtr<nsIThreadPool> threadPoolService =
1159 do_GetService(
"@songbirdnest.com/Songbird/ThreadPoolService;1", &rv);
1160 NS_ENSURE_SUCCESS(rv, rv);
1162 rv = threadPoolService->Dispatch(skQuery, NS_DISPATCH_NORMAL);
1163 NS_ENSURE_SUCCESS(rv, rv);
1169 sbSongkickDBService::StartConcertCountLookup(
1171 PRBool aGroupByArtist,
1172 const nsAString & aDateProperty,
1173 const nsAString & aCeilingProperty,
1176 NS_ENSURE_ARG_POINTER(aCallback);
1181 if (aGroupByArtist) {
1182 stmt.AppendLiteral(
"SELECT COUNT(distinct concertid) FROM playing_at");
1183 stmt.AppendLiteral(
" JOIN concerts ON playing_at.concertid = concerts.id");
1184 stmt.AppendLiteral(
" WHERE concerts.timestamp >= ");
1185 stmt.Append(aDateProperty);
1187 stmt.AppendLiteral(
" AND playing_at.libraryArtist = 1");
1191 stmt.AppendLiteral(
"SELECT COUNT(distinct id) FROM playing_at");
1192 stmt.AppendLiteral(
" JOIN concerts ON playing_at.concertid = concerts.id");
1193 stmt.AppendLiteral(
" WHERE concerts.timestamp >= ");
1194 stmt.Append(aDateProperty);
1195 stmt.AppendLiteral(
" AND concerts.timestamp < ");
1196 stmt.Append(aCeilingProperty);
1198 stmt.AppendLiteral(
" AND playing_at.anyLibraryArtist = 1");
1203 NS_ENSURE_TRUE(skQuery, NS_ERROR_OUT_OF_MEMORY);
1205 rv = skQuery->Init(stmt,
this, aCallback);
1206 NS_ENSURE_SUCCESS(rv, rv);
1208 nsCOMPtr<nsIThreadPool> threadPoolService =
1209 do_GetService(
"@songbirdnest.com/Songbird/ThreadPoolService;1", &rv);
1210 NS_ENSURE_SUCCESS(rv, rv);
1212 rv = threadPoolService->Dispatch(skQuery, NS_DISPATCH_NORMAL);
1213 NS_ENSURE_SUCCESS(rv, rv);
1222 sbSongkickDBService::Observe(
nsISupports *aSubject,
1224 const PRUnichar *
aData)
1226 NS_ENSURE_ARG_POINTER(aTopic);
1228 if (strcmp(aTopic,
"final-ui-startup") == 0) {
1231 do_GetService(
"@mozilla.org/observer-service;1", &rv);
1232 NS_ENSURE_SUCCESS(rv, rv);
1234 rv = observerService->RemoveObserver(
this, aTopic);
1235 NS_ENSURE_SUCCESS(rv, rv);
1238 NS_ENSURE_SUCCESS(rv, rv);
1261 const nsAString & aArtistURL,
1262 const nsAString & aID,
1263 const nsAString & aTS,
1264 const nsAString & aVenue,
1265 const nsAString & aCity,
1266 const nsAString & aTitle,
1267 const nsAString & aURL,
1268 const nsAString & aVenueURL,
1269 const nsAString & aTickets,
1270 nsIArray *aArtistsConcertInfo,
1271 const nsAString & aLibartist)
1289 sbSongkickConcertInfo::GetArtistname(nsAString & aArtistname)
1296 sbSongkickConcertInfo::GetArtisturl(nsAString & aArtisturl)
1303 sbSongkickConcertInfo::GetId(nsAString & aId)
1310 sbSongkickConcertInfo::GetTs(nsAString & aTs)
1317 sbSongkickConcertInfo::GetVenue(nsAString & aVenue)
1324 sbSongkickConcertInfo::GetCity(nsAString & aCity)
1331 sbSongkickConcertInfo::GetTitle(nsAString & aTitle)
1338 sbSongkickConcertInfo::GetUrl(nsAString & aUrl)
1345 sbSongkickConcertInfo::GetVenueURL(nsAString & aVenueURL)
1352 sbSongkickConcertInfo::GetTickets(nsAString & aTickets)
1359 sbSongkickConcertInfo::GetArtistsConcertInfo(nsIArray **aArtistsConcertInfo)
1361 NS_ENSURE_ARG_POINTER(aArtistsConcertInfo);
1367 sbSongkickConcertInfo::GetLibartist(nsAString & aLibartist)
1390 const nsAString & aArtistURL)
1392 mArtistName = aArtistName;
1393 mArtistURL = aArtistURL;
1398 sbSongkickArtistConcertInfo::GetArtistname(nsAString & aArtistname)
1400 aArtistname = mArtistName;
1405 sbSongkickArtistConcertInfo::GetArtisturl(nsAString & aArtisturl)
1407 aArtisturl = mArtistURL;
1427 const nsAString & aID,
1428 const nsAString & aKey)
1437 sbSongkickProperty::GetName(nsAString &
aName)
1444 sbSongkickProperty::GetId(nsAString & aID)
1451 sbSongkickProperty::GetKey(nsAString & aKey)
virtual ~sbSongkickProperty()
virtual ~sbSongkickQuery()
nsCOMPtr< nsIMutableArray > mStateProps
nsresult LoadLocationCityInfo()
nsString encodeURIComponent(const nsString &c)
static nsCOMPtr< nsIObserverService > observerService
static nsresult ContainsConcertList(const nsAString &aID, const sbConcertInfoList &aConcertList, PRBool *aHasEntry)
NS_DECL_ISUPPORTS NS_DECL_SBISONGKICKPROPERTY nsresult Init(const nsAString &aName, const nsAString &aID, const nsAString &aKey)
nsresult LoadLocationCountryInfo()
nsresult LoadLocationStateInfo()
nsresult GetDatabaseQuery(sbIDatabaseQuery **aOutDBQuery)
void RunEnumCallbackStart()
sbSongkickResultEnumerator()
NS_DECL_ISUPPORTS NS_DECL_SBISONGKICKARTISTCONCERTINFO nsresult Init(const nsAString &aArtistName, const nsAString &aArtistURL)
NS_DECL_ISUPPORTS NS_DECL_NSISIMPLEENUMERATOR nsresult Init(sbIDatabaseResult *aResult, sbIDatabaseQuery *aQuery)
NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE nsresult Init(const nsAString &aQueryStmt, sbSongkickDBService *aDBService, sbISongkickEnumeratorCallback *aCallback)
virtual ~sbSongkickConcertInfo()
NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE nsresult Init(const nsAString &aQueryStmt, sbSongkickDBService *aDBService, sbISongkickConcertCountCallback *aCallback)
sbConcertInfoList mConcertInfoList
nsCOMPtr< nsIArray > mArtistConcertInfoArray
NS_IMPL_THREADSAFE_ISUPPORTS1(sbSongkickArtistConcertInfo, sbISongkickArtistConcertInfo) sbSongkickArtistConcertInfo
NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE nsresult Init(sbSongkickDBService *aDBService)
NS_DECL_ISUPPORTS NS_DECL_SBPISONGKICKDBSERVICE static NS_DECL_NSIOBSERVER NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
#define SONGBIRD_SONGKICKDBSERVICE_CLASSNAME
virtual ~sbSongkickCountQuery()
nsCOMPtr< nsIMutableArray > mCityProps
void RunEnumCountCallback()
virtual ~sbSongkickResultEnumerator()
An object containing the results of a database SELECT query.
StringArrayEnumerator prototype hasMore
sbConcertInfoList::const_iterator sbConcertInfoListIter
PRLock * mQueryRunningLock
virtual ~sbSongkickDBInfo()
nsString c2h(PRUnichar dec)
An object responsible for executing SQL queries on the database.
sbConcertInfoListIter mConcertInfoListIter
std::list< nsRefPtr< sbSongkickConcertInfo > > sbConcertInfoList
#define SONGBIRD_SONGKICKDBSERVICE_CONTRACTID
NS_DECL_ISUPPORTS NS_DECL_SBISONGKICKCONCERTINFO nsresult Init(const nsAString &aArtistname, const nsAString &aArtistURL, const nsAString &aID, const nsAString &aTS, const nsAString &aVenue, const nsAString &aCity, const nsAString &aTitle, const nsAString &aURL, const nsAString &aVenueURL, const nsAString &aTickets, nsIArray *aArtistsConcertInfo, const nsAString &aLibartist)
virtual ~sbSongkickDBService()
_getSelectedPageStyle s i
nsCOMPtr< nsIMutableArray > mCountriesProps
virtual ~sbSongkickArtistConcertInfo()
nsresult LoadGotLocationInfo()
_updateTextAndScrollDataForFrame aData
void RunEnumCallbackEnd()