Skip to content

Commit

Permalink
asynchronous tag update working, fixup for future mozStorage interfac…
Browse files Browse the repository at this point in the history
…e layout
  • Loading branch information
buffered committed Jun 7, 2006
1 parent 984b9c0 commit a1f0370
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .cvsignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
danbooruup.xpi
*.xpi
platform

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*.xpi
chrome/danbooruup.jar
components/danbooru/*.ilk
components/danbooru/*.obj
components/danbooru/*.pdb
components/danbooru/.deps
components/danbooru/Makefile
components/danbooru/_xpidlgen
Expand All @@ -9,5 +12,4 @@ components/danbooru/fake-import
components/danbooru/libdanbooruac.so
components/danbooru/module.rc
components/danbooru/module.res
/danbooruup.xpi
/platform
2 changes: 2 additions & 0 deletions components/danbooru/.cvsignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Makefile
dependentLibs.h
*.obj
*.pdb
*.ilk
module.rc
module.res
fake-import
Expand Down
1 change: 1 addition & 0 deletions components/danbooru/Makefile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ endif

include $(topsrcdir)/config/rules.mk

DEFINES += -DDANBOORUUP_BRANCH_STORAGE
#DEFINES += -DDANBOORUUP_TESTING

libs:: $(TARGETS)
Expand Down
1 change: 1 addition & 0 deletions components/danbooru/Makefile.release
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ endif

include $(topsrcdir)/config/rules.mk

DEFINES += -DDANBOORUUP_BRANCH_STORAGE
#DEFINES += -DDANBOORUUP_TESTING

libs:: $(TARGETS)
Expand Down
43 changes: 34 additions & 9 deletions components/danbooru/nsDanbooruTagHistoryService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
#include "nsIScriptSecurityManager.h"
#include "nsIPrincipal.h"
// Update/Process
#include "nsIXMLHttpRequest.h"
#include "nsNetUtil.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMEventTarget.h"

#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
Expand Down Expand Up @@ -100,9 +100,10 @@ static const char *kTagTableName = "tags";

NS_INTERFACE_MAP_BEGIN(nsDanbooruTagHistoryService)
NS_INTERFACE_MAP_ENTRY(nsIDanbooruTagHistoryService)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDanbooruTagHistoryService)
NS_INTERFACE_MAP_END_THREADSAFE

NS_IMPL_THREADSAFE_ADDREF(nsDanbooruTagHistoryService)
Expand Down Expand Up @@ -270,8 +271,16 @@ nsDanbooruTagHistoryService::ProcessTagXML(void *document)
nodeList->GetLength(&length);
} else {
// no tags?
#ifdef DANBOORUUP_TESTING
fprintf(stderr,"no tags\n", rv);
#endif
return NS_OK;
}
#if defined(DANBOORUUP_TESTING) || defined(DEBUG)
{
fprintf(stderr, "got %d nodes\n", length);
}
#endif

nsCOMPtr<nsIDOMNode> child;
//nsDanbooruTagHistoryService *history = nsDanbooruTagHistoryService::GetInstance();
Expand Down Expand Up @@ -310,6 +319,9 @@ nsDanbooruTagHistoryService::HandleEvent(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMElement> element;
document->GetDocumentElement(getter_AddRefs(element));
if (element) {
#ifdef DANBOORUUP_TESTING
fprintf(stderr,"processing\n", rv);
#endif
ProcessTagXML(element);
rv = NS_OK;
} else {
Expand All @@ -329,14 +341,17 @@ nsDanbooruTagHistoryService::UpdateTagListFromURI(const nsAString &aXmlURI)
}
nsCAutoString spec;
resolvedURI->GetSpec(spec);
#ifdef DANBOORUUP_TESTING
fprintf(stderr,"using %s\n", spec.get());
#endif

mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_CONTRACTID, &rv);
if (!mRequest) {
return rv;
}

const nsAString& empty = EmptyString();
rv = mRequest->OpenRequest(NS_LITERAL_CSTRING("GET"), spec, PR_FALSE, empty, empty);
rv = mRequest->OpenRequest(NS_LITERAL_CSTRING("GET"), spec, PR_TRUE, empty, empty);
if (NS_FAILED(rv)) {
return rv;
}
Expand Down Expand Up @@ -393,7 +408,11 @@ nsDanbooruTagHistoryService::GetRowCount(PRUint32 *aRowCount)
if (type == mozIStorageValueArray::VALUE_TYPE_NULL)
*aRowCount = 0;
else
*aRowCount = mRowCountStmt->AsInt32(0);
#ifdef DANBOORUUP_BRANCH_STORAGE
mRowCountStmt->GetAsInt32(0, (PRInt32 *)aRowCount);
#else
mRowCountStmt->GetInt32(0, (PRInt32 *)aRowCount);
#endif
mRowCountStmt->Reset();
} else {
return NS_ERROR_FAILURE;
Expand All @@ -417,7 +436,11 @@ nsDanbooruTagHistoryService::GetMaxID(PRUint32 *aRowCount)
if (type == mozIStorageValueArray::VALUE_TYPE_NULL)
*aRowCount = -1;
else
*aRowCount = mMaxIDStmt->AsInt32(0);
#ifdef DANBOORUUP_BRANCH_STORAGE
mMaxIDStmt->GetAsInt32(0, (PRInt32 *)aRowCount);
#else
mMaxIDStmt->GetInt32(0, (PRInt32 *)aRowCount);
#endif
mMaxIDStmt->Reset();
} else {
return NS_ERROR_FAILURE;
Expand Down Expand Up @@ -854,7 +877,7 @@ nsDanbooruTagHistoryService::OpenDatabase()
historyFile->GetFileSize(&mFileSizeOnDisk);

return NS_OK;
#endif
#endif //ifndef DANBOORUUP_MORK
}

nsresult
Expand Down Expand Up @@ -1294,13 +1317,17 @@ nsDanbooruTagHistoryService::AutoCompleteSearch(const nsAString &aInputName,
mSearchStmt->ExecuteStep(&row);
while (row)
{
#ifdef DANBOORUUP_BRANCH_STORAGE
mSearchStmt->GetAsString(0, name);
#else
// schema: tags.name varchar(255)
name = mSearchStmt->AsSharedWString(0, nsnull);
#endif
result->AddRow(name);
mSearchStmt->ExecuteStep(&row);
}
mSearchStmt->Reset();
#endif
#endif //DANBOORUUP_MORK
PRUint32 matchCount;
result->GetMatchCount(&matchCount);
if (matchCount > 0) {
Expand Down Expand Up @@ -1394,9 +1421,7 @@ if (console)

return PR_FALSE;
}
#endif

#if 0 || defined(DANBOORUUP_MORK)
nsresult
nsDanbooruTagHistoryService::EntriesExistInternal(const nsAString *aName, const PRInt32 aValue, PRBool *_retval)
{
Expand Down
8 changes: 5 additions & 3 deletions components/danbooru/nsDanbooruTagHistoryService.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "nsIXMLHttpRequest.h"
#include "nsIPrefBranch.h"
#include "nsWeakReference.h"
#include "mozIStorageConnection.h"
Expand All @@ -68,12 +70,13 @@ class nsDanbooruTagHistoryService : public nsIDanbooruTagHistoryService,
NS_DECL_ISUPPORTS
NS_DECL_NSIDANBOORUTAGHISTORYSERVICE
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTLISTENER

// nsIFormSubmitObserver
//NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit);

// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
//NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);

nsDanbooruTagHistoryService();
virtual ~nsDanbooruTagHistoryService();
Expand Down Expand Up @@ -138,15 +141,14 @@ class nsDanbooruTagHistoryService : public nsIDanbooruTagHistoryService,

nsresult ProcessTagXML(void *);
#endif
nsCOMPtr<nsIXMLHttpRequest> mRequest;

static PRBool TagHistoryEnabled();

static nsDanbooruTagHistoryService *gTagHistory;

static PRBool gTagHistoryEnabled;
static PRBool gPrefsInitialized;

nsCOMPtr<nsIXMLHttpRequest> mRequest;
nsCOMPtr<nsIPrefBranch> mPrefBranch;
};

Expand Down

0 comments on commit a1f0370

Please sign in to comment.