I am trying to open and enumerate an addressbook in TB3 out of mozilla
comm-central hg (aka TB3):
nsCOMPtr<nsIAbDirectory> myAbDirectory;
nsCOMPtr<nsIRDFService> rdfService;
rdfService=do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
nsCOMPtr<nsIRDFResource> rs;
gchar *szAB=g_strconcat("moz-abmdbdirectory://", sz, NULL);
nsCString csc;
rv = NS_CStringSetData(csc, szAB);
rv=rdfService->GetResource(csc, getter_AddRefs(rs));
myAbDirectory = do_QueryInterface(rs, &rv);
nsCOMPtr<nsISimpleEnumerator> cards;
rv=myAbDirectory->GetChildCards(getter_AddRefs(cards));
if (NS_FAILED(rv)) ...
Here I get rv = 0x0c1f30001
In TB2 this worked, but with
nsCOMPtr<nsIEnumerator> cards;
Does anyone have clue what the error message means,
and why this would work in TB2 but not TB3 ?
/Henrik
This is: NS_ERROR_NOT_INITIALIZED
For future reference see:
http://silver.warwickcompsoc.co.uk/mozilla/misc/nserror?0xC1F30001
(although I think this site is out of date)
http://mxr.mozilla.org/comm-central/source/mozilla/xpcom/base/nsError.h
http://mxr.mozilla.org/comm-central/source/mailnews/base/public/msgCore.h
> In TB2 this worked, but with
> nsCOMPtr<nsIEnumerator> cards;
>
> Does anyone have clue what the error message means,
> and why this would work in TB2 but not TB3 ?
It failed because the myAbDirectory hasn't been initialised correctly
because of the way the rdf sources are currently working. I thought I
had a bug on it but I can't find it at the moment.
The issue is really we're half-way through removing rdf from the address
book. If we had completely removed it, then we wouldn't have the problem.
To resolve your issue what you need to do is:
nsCOMPtr<nsIAbManager> abMgr(do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
// This gets all address books which also forces an initialisation.
nsCOMPtr<nsISimpleEnumerator> directories;
rv = abMgr->GetDirectories(getter_AddRefs(directories));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectory> myAbDirectory;
rv = abMgr->GetDirectory(csc, getter_AddRefs(myAbDirectory));
NS_ENSURE_SUCCESS(rv, rv);
Note: using nsIAbManager (available in 3.x) hides you from the rdf
interfaces and will probably help future-proof a little bit (though I'm
not guaranteeing those interfaces will stay the same post 3.x).
Standard8
Thanks for your quick answer!
It is most appreciated by a wannabe-newbe like me...
> For future reference see:http://silver.warwickcompsoc.co.uk/mozilla/misc/nserror?0xC1F30001
> (although I think this site is out of date)
Indeed it is out of date. This was my reference in the past, but I
guess it is of no use these days...
>http://mxr.mozilla.org/comm-central/source/mozilla/xpcom/base/nsError.hhttp://mxr.mozilla.org/comm-central/source/mailnews/base/public/msgCo...
Will try to look at those in the future
> It failed because the myAbDirectory hasn't been initialised correctly
> because of the way the rdf sources are currently working. I thought I
> had a bug on it but I can't find it at the moment.
>
> The issue is really we're half-way through removing rdf from the address
> book. If we had completely removed it, then we wouldn't have the problem.
Great, I will try to stay away from RDF in the future...
> To resolve your issue what you need to do is:
> nsCOMPtr<nsIAbManager> abMgr(do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
> // This gets all address books which also forces an initialisation.
> nsCOMPtr<nsISimpleEnumerator> directories;
> rv = abMgr->GetDirectories(getter_AddRefs(directories));
Unfortunatly, here I get a 0x80004005.
Guess this is the very general NS_ERROR_FAILURE.
Any suggestions?
/Henrik
nsCOMPtr<nsIAbManager> abMgr(do_GetService("@mozilla.org/abmanager;1",
&rv));
MOZ_ERROR_CHECK_FALSE(rv, "do_GetService @mozilla.org/abmanager;1");
nsCOMPtr<nsISimpleEnumerator> directories;
rv = abMgr->GetDirectories(getter_AddRefs(directories));
MOZ_ERROR_CHECK_FALSE(rv, "nsIAbManager->GetDirectories");
Fails with 0x080004005 (NS_ERROR_FAILURE)
Any suggestions would be much appreciated!
/Henrik
Have you tried with a fresh profile?
That code is pretty much the same as other examples we have in the code
that you're running:
http://hg.mozilla.org/comm-central/annotate/d9fef5145cba/mailnews/base/src/nsMsgContentPolicy.cpp#l159
http://hg.mozilla.org/comm-central/annotate/d9fef5145cba/mailnews/addrbook/src/nsAbAddressCollector.cpp#l78
Therefore I'm thinking there is something in your profile that is
causing the directory initialisation to fail.
Standard8
Hi Henrik, i got the same error when compiling mozilla-sync with TB3
(shredder).
I think the causes is prefs.js which should be in thunderbird
profile.
You can rename the file XXX/mailnews/mailnews.js as prefs.js and move
it to thunderbird profile.
Then everything will fine, have a try.
When running TB3, it will always rewrite the prefs.js.
prefs.js is created by Thunderbird on first run if it doesn't exist.
Copying mailnews.js over prefs.js will overwrite whatever settings you
have. It is also entirely unnecessary, mailnews.js is included in the
build so Thunderbird has those settings by default.
Standard8