From: <svn...@op...> - 2009-03-17 11:10:29
|
Author: henrik Date: Tue Mar 17 12:10:16 2009 New Revision: 5292 URL: http://www.opensync.org/changeset/5292 Log: Updates for Thunderbird 3. It compiles, but a lot more work is needed in order to get to work. Added: plugins/mozilla-sync/trunk/tests/storage.sdb_10 (contents, props changed) Modified: plugins/mozilla-sync/trunk/CMakeLists.txt plugins/mozilla-sync/trunk/src/calendar-event.cpp plugins/mozilla-sync/trunk/src/mozilla-calendar.cpp plugins/mozilla-sync/trunk/src/mozilla-headers.h plugins/mozilla-sync/trunk/src/mozilla-utils.cpp plugins/mozilla-sync/trunk/src/mozilla-utils.h plugins/mozilla-sync/trunk/src/mozilla-xpcom.cpp plugins/mozilla-sync/trunk/src/thunderbird-addressbook.cpp plugins/mozilla-sync/trunk/src/thunderbird-addressbook.h plugins/mozilla-sync/trunk/src/thunderbird-card.cpp plugins/mozilla-sync/trunk/src/thunderbird-card.h plugins/mozilla-sync/trunk/tests/unit_test_abook.cpp plugins/mozilla-sync/trunk/tests/unit_test_xpcom.cpp Modified: plugins/mozilla-sync/trunk/CMakeLists.txt ============================================================================== --- plugins/mozilla-sync/trunk/CMakeLists.txt Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/CMakeLists.txt Tue Mar 17 12:10:16 2009 (r5292) @@ -44,7 +44,8 @@ FIND_PACKAGE( OpenSync REQUIRED ) FIND_PACKAGE( ThunderbirdXpcom REQUIRED ) -STRING (REGEX REPLACE "[0-9]*\\.([0-9])*" "\\1" CALENDAR_VERSION "${SUNBIRD_VERSION}" ) +STRING (REGEX REPLACE "^([0-9]+)\\.([0-9]+)$" "\\1\\2" _CALENDAR_VERSION "${SUNBIRD_VERSION}" ) +STRING (REGEX REPLACE "^0*([0-9]+)$" "\\1" CALENDAR_VERSION "${_CALENDAR_VERSION}" ) MESSAGE ( "CALENDAR_VERSION=[${CALENDAR_VERSION}]" ) ### SEEMS THAT WE CANNOT LINK TO GLUE SINCE IT IS NOT THREAD SAFE, AND WE WILL SEGFAULT Modified: plugins/mozilla-sync/trunk/src/calendar-event.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/calendar-event.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/calendar-event.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -7,7 +7,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -51,6 +51,9 @@ #elif CALENDAR_VERSION==9 #include <calbase/calITimezone.h> #include <calbase/calITimezoneProvider.h> +#elif CALENDAR_VERSION==10 +#include <calbase/calITimezone.h> +#include <calbase/calITimezoneProvider.h> #endif #include "mozilla-sync-utils.h" @@ -95,17 +98,14 @@ **/ nsCOMPtr<calIICSService> globalIcsService; -#if CALENDAR_VERSION==8 // ---------------------------------------- /** @brief Global holding Mozilla TimeZone service **/ +#if CALENDAR_VERSION==8 nsCOMPtr<calITimezoneService> globalTimezoneService; -#endif - -#if CALENDAR_VERSION==9 -// ---------------------------------------- -/** @brief Global holding Mozilla TimeZone service -**/ +#elif CALENDAR_VERSION==9 +nsCOMPtr<calITimezoneService> globalTimezoneService; +#elif CALENDAR_VERSION==10 nsCOMPtr<calITimezoneService> globalTimezoneService; #endif @@ -253,8 +253,15 @@ MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone"); \ rv=calTimezone->ToString(acsTZ); \ MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone->ToString"); +#elif CALENDAR_VERSION==10 +#define GET_TZ \ + nsCOMPtr<calITimezone> calTimezone; \ + rv=calDateTime->GetTimezone(getter_AddRefs(calTimezone)); \ + MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone"); \ + rv=calTimezone->ToString(acsTZ); \ + MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone->ToString"); #else -#error Only CALENDAR_VERSION 0.7, 0.8 and 0.9 are supported +#error Only CALENDAR_VERSION 0.7, 0.8, 0.9, and 1.0 are supported #endif // ---------------------------------------- @@ -334,8 +341,10 @@ rv=globalIcsService->ParseICS(acICS, NULL, getter_AddRefs(icsCalendar)); #elif CALENDAR_VERSION==9 rv=globalIcsService->ParseICS(acICS, NULL, getter_AddRefs(icsCalendar)); +#elif CALENDAR_VERSION==10 + rv=globalIcsService->ParseICS(acICS, NULL, getter_AddRefs(icsCalendar)); #else -#error Only CALENDAR_VERSION 0.7, 0.8, and 0.9 are supported +#error Only CALENDAR_VERSION 0.7, 0.8, 0.9, and 1.0 are supported #endif MOZ_ERROR_CHECK_FALSE(rv, "parseICS"); @@ -514,8 +523,14 @@ rv=globalTimezoneService->GetUTC(getter_AddRefs(calTimezone)); \ MOZ_ERROR_CHECK_FALSE(rv, "GetUTC"); \ rv=calDateTimeUTC->SetTimeInTimezone(statement->AsInt64(IDX), calTimezone); +#elif CALENDAR_VERSION==10 +#define SET_IN_TZ(IDX) \ + nsCOMPtr<calITimezone> calTimezone; \ + rv=globalTimezoneService->GetUTC(getter_AddRefs(calTimezone)); \ + MOZ_ERROR_CHECK_FALSE(rv, "GetUTC"); \ + rv=calDateTimeUTC->SetTimeInTimezone(statement->AsInt64(IDX), calTimezone); #else -#error Only CALENDAR_VERSION 0.7, 0.8 and 0.9 are supported +#error Only CALENDAR_VERSION 0.7, 0.8, 0.9 and 1.0 are supported #endif @@ -536,8 +551,13 @@ rv=globalTimezoneService->GetTimezone(NS_ConvertUTF16toUTF8(asTZ), getter_AddRefs(calTimezone)); \ MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone"); \ rv=calDateTimeUTC->GetInTimezone(calTimezone, getter_AddRefs(calDateTimeTZ)); +#elif CALENDAR_VERSION==10 +#define GET_IN_TZ \ + rv=globalTimezoneService->GetTimezone(NS_ConvertUTF16toUTF8(asTZ), getter_AddRefs(calTimezone)); \ + MOZ_ERROR_CHECK_FALSE(rv, "GetTimezone"); \ + rv=calDateTimeUTC->GetInTimezone(calTimezone, getter_AddRefs(calDateTimeTZ)); #else -#error Only CALENDAR_VERSION 0.7, 0.8 and 0.9 are supported +#error Only CALENDAR_VERSION 0.7, 0.8, 0.9, and 1.0 are supported #endif @@ -567,8 +587,15 @@ rv=icsCalendar->AddTimezoneReference(calTimezone); \ MOZ_ERROR_CHECK_FALSE(rv, "AddTimezoneReference"); \ } +#elif CALENDAR_VERSION==10 +#define ADD_TZ_REF \ + rv=globalTimezoneService->GetTimezone(NS_ConvertUTF16toUTF8(asTZ), getter_AddRefs(calTimezone)); \ + if (NS_SUCCEEDED(rv)) { \ + rv=icsCalendar->AddTimezoneReference(calTimezone); \ + MOZ_ERROR_CHECK_FALSE(rv, "AddTimezoneReference"); \ + } #else -#error Only CALENDAR_VERSION 0.7, 0.8 and 0.9 are supported +#error Only CALENDAR_VERSION 0.7, 0.8, 0.9 and 1.0 are supported #endif @@ -643,9 +670,13 @@ globalTimezoneService=do_GetService("@mozilla.org/calendar/timezone-service;1", &rv); MOZ_ERROR_CHECK_FALSE(rv, "@mozilla.org/calendar/timezone-service;1"); } -#endif - -#if CALENDAR_VERSION==9 +#elif CALENDAR_VERSION==9 + if (!globalTimezoneService) { + LOG(10, "Getting TimeZone service"); + globalTimezoneService=do_GetService("@mozilla.org/calendar/timezone-service;1", &rv); + MOZ_ERROR_CHECK_FALSE(rv, "@mozilla.org/calendar/timezone-service;1"); + } +#elif CALENDAR_VERSION==10 if (!globalTimezoneService) { LOG(10, "Getting TimeZone service"); globalTimezoneService=do_GetService("@mozilla.org/calendar/timezone-service;1", &rv); Modified: plugins/mozilla-sync/trunk/src/mozilla-calendar.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/mozilla-calendar.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/mozilla-calendar.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -8,7 +8,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,7 +31,6 @@ #include <nsEmbedString.h> #include <nsIArray.h> -#include <nsIURI.h> #include <nsIServiceManager.h> #include <nsServiceManagerUtils.h> Modified: plugins/mozilla-sync/trunk/src/mozilla-headers.h ============================================================================== --- plugins/mozilla-sync/trunk/src/mozilla-headers.h Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/mozilla-headers.h Tue Mar 17 12:10:16 2009 (r5292) @@ -10,7 +10,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -37,7 +37,14 @@ #include <nsCOMPtr.h> #include <nsXPCOM.h> -#if 1 +/* Poor man's way of testing for Thunderbird 3 */ +#ifdef DECL_CLASS +#define TBIRD_3 3 +#endif + +#ifdef TBIRD_3 +#include <nsStringAPI.h> +#else #include <nsStringAPI.h> /** nsIABDirectory pulls in xpcom_obsolete/nsFileSpec.h. @@ -50,13 +57,6 @@ #define nsString_h___ #define nsReadableUtils_h___ // #define nsAString_h___ - -#else - -#define MOZILLA_INTERNAL_API -#include <string.h> -#include <nsStringAPI.h> - #endif Modified: plugins/mozilla-sync/trunk/src/mozilla-utils.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/mozilla-utils.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/mozilla-utils.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -55,6 +55,13 @@ #include "mozilla-utils.h" +// The string functions below are defined in libxpcomglue, +// which is not linked by default. +// So we define them here. +// However, for Thunderbird 3 it seems we must link to libxpcomglue, +// so do NOT define them for Thunderbird 3 + +#ifndef TBIRD_3 PRUnichar* NS_strdup(const PRUnichar *aString) { @@ -84,3 +91,4 @@ return end - aString; } +#endif Modified: plugins/mozilla-sync/trunk/src/mozilla-utils.h ============================================================================== --- plugins/mozilla-sync/trunk/src/mozilla-utils.h Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/mozilla-utils.h Tue Mar 17 12:10:16 2009 (r5292) @@ -10,7 +10,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -29,6 +29,15 @@ #include "mozilla-headers.h" + +// The string functions below are defined in libxpcomglue, +// which is not linked by default. +// So we define them here. +// However, for Thunderbird 3 it seems we must link to libxpcomglue, +// so do NOT define them for Thunderbird 3 + +#ifndef TB3 + /** * "strlen" for PRUnichar strings */ @@ -51,3 +60,4 @@ NS_strndup(const PRUnichar *aString, PRUint32 aLen); #endif +#endif Modified: plugins/mozilla-sync/trunk/src/mozilla-xpcom.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/mozilla-xpcom.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/mozilla-xpcom.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -9,7 +9,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -43,7 +43,9 @@ #include <nsDirectoryServiceDefs.h> #include <nsISimpleEnumerator.h> #include <nsISupportsPrimitives.h> +#ifndef TBIRD_3 #include <nsIEventQueueService.h> +#endif #include <nsIXULAppInfo.h> #include <nsIExtensionManager.h> #include "nsProfileDirServiceProvider.h" @@ -56,29 +58,37 @@ void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) { nsresult rv; - LOG(10, "Getting version info"); + LOG(10, "Getting XULAppInfo"); nsCOMPtr<nsIXULAppInfo> xulAppInfo = do_GetService("@mozilla.org/xre/app-info;1", &rv); if (NS_SUCCEEDED(rv)) { LOG(10, "Got XULAppInfo"); - nsCString appName; - rv=xulAppInfo->GetName(appName); - LOG(10, "XULApp name [%s]", appName.get()); - nsCString appID; - rv=xulAppInfo->GetID(appID); - LOG(10, "XULApp ID [%s]", appID.get()); - nsCString appVersion; - rv=xulAppInfo->GetVersion(appVersion); - LOG(10, "XULApp version [%s]", appVersion.get()); - nsCString appPlatformVersion; - rv=xulAppInfo->GetVersion(appPlatformVersion); - LOG(10, "XULApp PlatformVersion [%s]", appPlatformVersion.get()); + nsCString cs; + const char *sz; + PRBool f; + rv=xulAppInfo->GetName(cs); + if (NS_SUCCEEDED(rv)) { + NS_CStringGetData(cs, &sz, &f); + LOG(10, "XULApp Name [%s]", sz); } + rv=xulAppInfo->GetID(cs); + if (NS_SUCCEEDED(rv)) { + NS_CStringGetData(cs, &sz, &f); + LOG(10, "XULApp ID [%s]", sz); } + rv=xulAppInfo->GetVersion(cs); + if (NS_SUCCEEDED(rv)) { + NS_CStringGetData(cs, &sz, &f); + LOG(10, "XULApp Version [%s]", sz); } + rv=xulAppInfo->GetVersion(cs); + if (NS_SUCCEEDED(rv)) { + NS_CStringGetData(cs, &sz, &f); + LOG(10, "XULApp PlatformVersion [%s]", sz); } } else { LOG(10, "Unable to get XULAppInfo"); //return FALSE; } + LOG(10, "Getting Version for Lightning"); nsCOMPtr<nsIExtensionManager> extensionManager = do_GetService("@mozilla.org/extensions/manager;1", &rv); if (NS_SUCCEEDED(rv)) { @@ -86,13 +96,19 @@ NS_NAMED_LITERAL_STRING(lightGUID, "{e2fda1a4-762b-4020-b5ad-a41df1933103}"); rv=extensionManager->GetItemForID(lightGUID, getter_AddRefs(updateItem)); if (NS_SUCCEEDED(rv)) { + LOG(10, "Got Version for Lightning"); nsString lightningVersion; rv=updateItem->GetVersion(lightningVersion); - LOG(10, "Lightning Version [%s]", lightningVersion.get()); + if (NS_SUCCEEDED(rv)) { + nsCString cs; + const char* sz; + PRBool f; + cs=NS_ConvertUTF16toUTF8(lightningVersion); + NS_CStringGetData(cs, &sz, &f); + LOG(10, "Lightning Version [%s]", sz); } } else { LOG(10, "No lightning extension"); } - } else { LOG(10, "Unable to get ExtensionManager"); //return FALSE; @@ -124,6 +140,15 @@ // (This may happen e.g. if called from within a thunderbird extension) // It seems that many things are initialized partly even before NS_InitXPCOM2 is called // But it looks like the event queue service is not, so we can use that + + // + // *** TODO Thunderbird 3 + // + // This trick does not work for Thunderbird 3. + // Need to find another trick! + // + +#ifndef TBIRD_3 nsCOMPtr<nsIEventQueueService> eventQService = do_GetService("@mozilla.org/event-queue-service;1", &rv); @@ -133,6 +158,8 @@ mozilla_getversion(pLogFunction); return TRUE; } +#endif + #ifdef XPCOM_GLUE LOG(10, "Starting up XPCOMGlue"); rv = XPCOMGlueStartup(nsnull); @@ -162,9 +189,14 @@ MOZ_ERROR_CHECK_FALSE(rv, "NS_NewNativeLocalFile for localFileGreDir"); nsString s; + nsCString cs; rv=localFileGreDir->GetPath(s); - MOZ_ERROR_CHECK_FALSE(rv, "GetPath"); - LOG(10, "GRE path: [%s]", NS_ConvertUTF16toUTF8(s).get()); + MOZ_ERROR_CHECK_FALSE(rv, "localFileGreDir->GetPath"); + cs=NS_ConvertUTF16toUTF8(s); + const char *sz; + PRBool f; + NS_CStringGetData(cs, &sz, &f); + LOG(10, "GRE path: [%s]", sz); LOG(10, "ProfileDir: [%s]", szProfileDirectory); nsCString csProfileDir; @@ -203,10 +235,12 @@ rv=registrar->AutoRegister(localFileGreComponents); //MOZ_ERROR_CHECK_FALSE(rv, "AutoRegister"); if (NS_FAILED(rv)) LOG(0, "AutoRegister failed. Continuing anyway..."); - nsString ss; - rv=localFileGreComponents->GetPath(ss); - LOG(10, "GRE component path: [%s]", NS_ConvertUTF16toUTF8(ss).get()); - MOZ_ERROR_CHECK_FALSE(rv, "NS_StringContainerInit"); + + rv=localFileGreComponents->GetPath(s); + MOZ_ERROR_CHECK_FALSE(rv, "localFileGreComponents->GetPath"); + cs=NS_ConvertUTF16toUTF8(s); + NS_CStringGetData(cs, &sz, &f); + LOG(10, "GRE component path: [%s]", sz); LOG(10, "GRE services registered"); Modified: plugins/mozilla-sync/trunk/src/thunderbird-addressbook.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/thunderbird-addressbook.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/thunderbird-addressbook.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -9,7 +9,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,7 +36,15 @@ #include <nsServiceManagerUtils.h> #include <nsComponentManagerUtils.h> +#ifdef TBIRD_3 +#include <nsIFile.h> +#include <nsILocalFile.h> +#include <nsIAbManager.h> +#else +#include <nsIAddressBook.h> #include <nsIAbMDBCard.h> +#include <nsIFileSpec.h> +#endif #include "mozilla-sync-utils.h" #include "thunderbird-addressbook.h" @@ -56,8 +64,54 @@ void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) { nsresult rv; + PRBool f; + +#ifdef TBIRD_3 + + // See http://groups.google.com/group/mozilla.dev.apps.thunderbird/browse_thread/thread/39036007fed1c4ea# + + LOG(10, "Getting addressbook"); + + nsCOMPtr<nsIAbManager> abMgr(do_GetService("@mozilla.org/abmanager;1", &rv)); + MOZ_ERROR_CHECK_FALSE(rv, "do_GetService @mozilla.org/abmanager;1"); + + // This gets all address books which also forces an initialisation. + nsCOMPtr<nsISimpleEnumerator> directories; + + // + // *** TODO Thunderbird 3 + // + // Currently this fails with 0x080004005 (NS_ERROR_FAILURE) + // Still no answer on http://groups.google.com/group/mozilla.dev.apps.thunderbird/browse_thread/thread/39036007fed1c4ea# + // + + rv = abMgr->GetDirectories(getter_AddRefs(directories)); + MOZ_ERROR_CHECK_FALSE(rv, "nsIAbManager->GetDirectories"); + + gchar *szAB=g_strconcat("moz-abmdbdirectory://", szThunderbirdAddressbookFile, NULL); + nsCString csc; + rv = NS_CStringSetData(csc, szAB); + MOZ_ERROR_CHECK_FALSE(rv, "NS_CStringSetData"); + //nsCOMPtr<nsIAbDirectory> myAbDirectory; + rv = abMgr->GetDirectory(csc, getter_AddRefs(myAbDirectory)); + MOZ_ERROR_CHECK_FALSE(rv, "nsIAbManager->GetDirectory"); + + nsCString csURI; + rv=myAbDirectory->GetURI(csURI); + MOZ_ERROR_CHECK_FALSE(rv, "GetURI for nsIAbDirectory"); + const char *szURI; + NS_CStringGetData(csURI, &szURI, &f); + LOG(10, "AbDirectory URI [%s]", szURI); + + nsCString csFn; + rv=myAbDirectory->GetFileName(csFn); + MOZ_ERROR_CHECK_FALSE(rv, "GetFileName for nsIAbDirectory"); + const char *szFn; + NS_CStringGetData(csFn, &szFn, &f); + LOG(10, "AbDirectory filename [%s]", szFn); +#else LOG(10, "Getting addressbook"); nsCOMPtr<nsIRDFService> rdfService; rdfService=do_GetService("@mozilla.org/rdf/rdf-service;1", &rv); @@ -69,10 +123,12 @@ MOZ_ERROR_CHECK_FALSE(rv, "NS_CStringSetData"); rv=rdfService->GetResource(csc, getter_AddRefs(rs)); MOZ_ERROR_CHECK_FALSE(rv, "GetResource"); - mySzURI=csc.get(); + NS_CStringGetData(csc, &mySzURI, &f); LOG(10, "Resource URI [%s]", mySzURI); + myAbDirectory = do_QueryInterface(rs, &rv); MOZ_ERROR_CHECK_FALSE(rv, "do_QueryInterface for nsIAbDirectory"); +#endif // It seems that we can query the interface, // and also ask for all kinds of information @@ -81,6 +137,21 @@ // even if there is no addressbook at the specified URI. // So let's see if we can get child cards. // (Better to fail already now) + +#ifdef TBIRD_3 + nsCOMPtr<nsISimpleEnumerator> cards; + rv=myAbDirectory->GetChildCards(getter_AddRefs(cards)); + if (NS_FAILED(rv)) { + *pSzError=g_strdup_printf("%s(%d): Unable to get child cards. Address book is not valid [0x0%x]", __func__, __LINE__, rv ); + return FALSE; } + PRBool more; + rv=cards->HasMoreElements(&more); + if (NS_FAILED(rv)) { + *pSzError=g_strdup_printf("%s(%d): Unable to enumerate child cards. Address book is not valid [0x0%x]", __func__, __LINE__, rv ); + return FALSE; } + if (!more) + LOG(1, "WARNING: No address cards in address book"); +#else nsCOMPtr<nsIEnumerator> cards; rv=myAbDirectory->GetChildCards(getter_AddRefs(cards)); if (NS_FAILED(rv)) { @@ -92,14 +163,44 @@ rv=NS_OK; } else MOZ_ERROR_CHECK_FALSE(rv, "cards->First"); - +#endif + +#ifdef TBIRD_3 + + nsString sAB; + sAB=NS_ConvertUTF8toUTF16(szAB); + + nsCOMPtr<nsILocalFile> localFile; + localFile=do_CreateInstance("@mozilla.org/file/local;1", &rv); + MOZ_ERROR_CHECK_FALSE(rv, "do_CreateInstance for nsILocalFile"); + rv=localFile->InitWithPath(sAB); + MOZ_ERROR_CHECK_FALSE(rv, "init nsILocalFile"); + + nsCOMPtr<nsIFile> file; + rv=localFile->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(file)); + MOZ_ERROR_CHECK_FALSE(rv, "do_QueryInterface for nsIFile"); + + LOG(10, "Getting DB1"); + myAddrDatabase=do_CreateInstance("@mozilla.org/carddatabase;1", &rv); + MOZ_ERROR_CHECK_FALSE(rv, "do_CreateInstance for nsIAddrDatabase"); + + LOG(10, "Getting database"); + rv=myAddrDatabase->OpenMDB(file, (PRBool) PR_FALSE); + MOZ_ERROR_CHECK_FALSE(rv, "database"); + +#else + nsCOMPtr<nsIAddressBook> addressBook; LOG(10, "Getting addressbook"); - myAddressBook=do_CreateInstance("@mozilla.org/addressbook;1", &rv); + addressBook=do_CreateInstance("@mozilla.org/addressbook;1", &rv); MOZ_ERROR_CHECK_FALSE(rv, "do_CreateInstance for nsIAddressBook"); LOG(10, "Getting database"); - rv=myAddressBook->GetAbDatabaseFromURI(szAB, getter_AddRefs(myAddrDatabase)); + rv=addressBook->GetAbDatabaseFromURI(szAB, getter_AddRefs(myAddrDatabase)); MOZ_ERROR_CHECK_FALSE(rv, "database"); + + +#endif + GFREE(szAB); LOG(10, "Addressbook initialized"); @@ -161,6 +262,20 @@ myPCurrentCard=NULL; nsCOMPtr<nsISupports> supp; nsCOMPtr<nsIAbCard> aCard; + +#ifdef TBIRD_3 + rv=myAbDirectory->GetChildCards(getter_AddRefs(myCards)); + MOZ_ERROR_CHECK_FALSE(rv, "nsIAbDirectory::GetChildCards"); + PRBool more; + rv=myCards->HasMoreElements(&more); + MOZ_ERROR_CHECK_FALSE(rv, "nsISimpleEnumerator::HasMoreElements"); + if (!more) { + LOG(1, "WARNING: No address cards in address book"); + return TRUE; + } + rv=myCards->GetNext(getter_AddRefs(supp)); + MOZ_ERROR_CHECK_FALSE(rv, "nsISimpleEnumerator::GetNext"); +#else rv=myAbDirectory->GetChildCards(getter_AddRefs(myCards)); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbDirectory::GetChildCards"); rv=myCards->First(); @@ -170,6 +285,8 @@ MOZ_ERROR_CHECK_FALSE(rv, "nsIEnumerator::First"); rv=myCards->CurrentItem(getter_AddRefs(supp)); MOZ_ERROR_CHECK_FALSE(rv, "nsIEnumerator::CurrentItem"); +#endif + rv=supp->QueryInterface(NS_GET_IID(nsIAbCard), getter_AddRefs(aCard)); MOZ_ERROR_CHECK_FALSE(rv, "nsISupportsQueryInterface"); myPCurrentCard = new ThunderbirdCard(aCard); @@ -192,11 +309,21 @@ myPCurrentCard=NULL; nsCOMPtr<nsISupports> supp; nsCOMPtr<nsIAbCard> aCard; + +#ifdef TBIRD_3 + PRBool more; + rv=myCards->HasMoreElements(&more); + MOZ_ERROR_CHECK_FALSE(rv, "nsISimpleEnumerator::HasMoreElements"); + if (!more) return TRUE; // No more cards + rv=myCards->GetNext(getter_AddRefs(supp)); + MOZ_ERROR_CHECK_FALSE(rv, "nsISimpleEnumerator::GetNext"); +#else rv=myCards->Next(); if (rv==NS_ERROR_INVALID_POINTER) return TRUE; // No more cards MOZ_ERROR_CHECK_FALSE(rv, "nsIEnumerator::Next"); rv=myCards->CurrentItem(getter_AddRefs(supp)); MOZ_ERROR_CHECK_FALSE(rv, "nsIEnumerator::CurrentItem"); +#endif rv=supp->QueryInterface(NS_GET_IID(nsIAbCard), getter_AddRefs(aCard)); MOZ_ERROR_CHECK_FALSE(rv, "nsISupportsQueryInterface"); myPCurrentCard = new ThunderbirdCard(aCard); @@ -242,9 +369,16 @@ rv=myAbDirectory->AddCard(pCard->myCard, getter_AddRefs(newCard)); MOZ_ERROR_CHECK_FALSE(rv, "AddCard"); +// +// *** TODO Thunderbird 3 +// +// We need to figure out how to put the card back in the database! +// + +#ifndef TBIRD_3 rv=newCard->EditCardToDatabase(mySzURI); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::EditCardToDatabase"); - +#endif // For some reason Commit here results in segmentation fault // rv=myAddrDatabase->Commit(nsAddrDBCommitType::kSmallCommit); // MOZ_ERROR_CHECK(rv, "Commit"); @@ -268,15 +402,32 @@ LOG(10, "Deleting card [%s]", szKey); nsresult rv; nsCOMPtr<nsIAbCard> theCard; +#ifdef TBIRD_3 + nsCString cs; + rv = NS_CStringSetData(cs, szKey); + MOZ_ERROR_CHECK_FALSE(rv, "NS_CStringSetData"); + rv=myAddrDatabase->GetCardFromAttribute(myAbDirectory, OPEN_SYNC_KEY, cs, PR_FALSE, getter_AddRefs(theCard)); +#else rv=myAddrDatabase->GetCardFromAttribute(myAbDirectory, OPEN_SYNC_KEY, szKey, PR_FALSE, getter_AddRefs(theCard)); +#endif MOZ_ERROR_CHECK_FALSE(rv, "GetCardFromAttribute"); if (!theCard) ERROR("Could not find card with key [%s] in Thunderbird Address-book", szKey); +#ifdef TBIRD_3 + rv=myAddrDatabase->DeleteCard(theCard, PR_FALSE, myAbDirectory); + MOZ_ERROR_CHECK_FALSE(rv, "DeleteCard"); +#else rv=myAddrDatabase->DeleteCard(theCard, PR_FALSE); - MOZ_ERROR_CHECK_FALSE(rv, "DropCard"); + MOZ_ERROR_CHECK_FALSE(rv, "DeleteCard"); +#endif +#ifdef TBIRD_3 + rv=myAbDirectory->ModifyCard(theCard); + MOZ_ERROR_CHECK_FALSE(rv, "modifyCard"); +#else rv=theCard->EditCardToDatabase(mySzURI); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::EditCardToDatabase"); +#endif rv=myAddrDatabase->Commit(nsAddrDBCommitType::kSmallCommit); MOZ_ERROR_CHECK_FALSE(rv, "Commit"); @@ -306,7 +457,16 @@ LOG(10, "Modifying card [%s]", szKey); nsresult rv; nsCOMPtr<nsIAbCard> theCard; + +#ifdef TBIRD_3 + nsCString cs; + rv = NS_CStringSetData(cs, szKey); + MOZ_ERROR_CHECK_FALSE(rv, "NS_CStringSetData"); + rv=myAddrDatabase->GetCardFromAttribute(myAbDirectory, OPEN_SYNC_KEY, cs, PR_FALSE, getter_AddRefs(theCard)); +#else rv=myAddrDatabase->GetCardFromAttribute(myAbDirectory, OPEN_SYNC_KEY, szKey, PR_FALSE, getter_AddRefs(theCard)); +#endif + MOZ_ERROR_CHECK_FALSE(rv, "GetCardFromAttribute"); if (!theCard) ERROR("Could not find card with key [%s] in Thunderbird Address-book", szKey); @@ -323,8 +483,15 @@ gboolean f; f=pCard->ResetFromXML(szXML, pSzError, pLogFunction); if (!f) return FALSE; + +#ifdef TBIRD_3 + rv=myAbDirectory->ModifyCard(theCard); + MOZ_ERROR_CHECK_FALSE(rv, "modifyCard"); +#else rv=theCard->EditCardToDatabase(mySzURI); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::EditCardToDatabase"); +#endif + rv=myAddrDatabase->Commit(nsAddrDBCommitType::kSmallCommit); MOZ_ERROR_CHECK_FALSE(rv, "Commit"); @@ -336,85 +503,3 @@ return TRUE; } - - -// ------------------------------------------------------------ -/** @brief Log contents of address book - just for debugging and fun - - @param pSzError Pointer to string, into which we shall write an error message if we return false - @param pLogFunction Function used to log information text - @return TRUE on success; FALSE on error -**/ -gboolean ThunderbirdAddressbook::LogInfo( - char **pSzError, - void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) -{ - nsresult rv; - LOG(10, "Listing first (up to) 10 address cards"); - if (!CardFirst(pSzError, pLogFunction)) return FALSE; - int i=0; - if (CardDone()) { - LOG(10, "No address cards in address book"); - } else { - while(!CardDone()) { - i++; - if (i>10) { - if (!CardNext(pSzError, pLogFunction)) return FALSE; - continue; } - ThunderbirdCard *pCard=CardCurrent(); - char *szKey=pCard->GetKey(myAddrDatabase, pSzError, pLogFunction); - if (!szKey) return FALSE; - char *szHash=pCard->GetHash(pSzError, pLogFunction); - if (!szHash) return FALSE; - char *szLongName=pCard->GetLongName(pSzError, pLogFunction); - if (!szLongName) return FALSE; - LOG(10, "%s [%s]: %s", szKey, szHash, szLongName); - free(szKey); free(szHash); free(szLongName); - char *szXML=pCard->GetXML(pSzError, pLogFunction); - if (!szXML) return FALSE; - LOG(10, szXML); - g_free(szXML); - if (!CardNext(pSzError, pLogFunction)) return FALSE; - } - } - LOG(10, "%d address cards listed", i); - // It does not seem that any of the below returns any usefull information !! - // Why? - LOG(10, "Getting AbDirectoryProperties"); - nsCOMPtr<nsIAbDirectoryProperties> directoryProperties; - rv=myAbDirectory->GetDirectoryProperties(getter_AddRefs(directoryProperties)); - MOZ_ERROR_CHECK_FALSE(rv, "GetDirectoryProperties"); - char *sz; - rv=directoryProperties->GetFileName(&sz); - MOZ_ERROR_CHECK_FALSE(rv, "directoryProperties->GetFileName"); - LOG(10, "File Name [%s]", sz); // Gennerally seems to be _nonascii - rv=directoryProperties->GetURI(&sz); - MOZ_ERROR_CHECK_FALSE(rv, "directoryProperties->GetURI"); - LOG(10, "URI [%s]", sz); // Gennerally seems to be _nonascii - rv=directoryProperties->GetPrefName(&sz); - MOZ_ERROR_CHECK_FALSE(rv, "directoryProperties->GetPrefName"); - LOG(10, "Pref Name [%s]", sz); // Gennerally seems to be _nonascii - nsString sc; - MOZ_ERROR_CHECK_FALSE(rv, "NS_StringContainerInit"); - rv=directoryProperties->GetDescription(sc); - MOZ_ERROR_CHECK_FALSE(rv, "directoryProperties->GetDescription"); - LOG(10, "Description [%s]", sc.get()); // Generally seems to be empty - directoryProperties=nsnull; - LOG(10, "Got AbDirectoryProperties"); - - LOG(10, "Address book info"); - PRUnichar *c16; - nsCString csc; - rv=myAbDirectory->GetDirName(&c16); - MOZ_ERROR_CHECK_FALSE(rv, "abDirectory->GetDirName"); - LOG(10, "DirName [%s]", NS_ConvertUTF16toUTF8(c16).get()); - rv=myAbDirectory->GetDescription(&c16); // Generally seems to be empty - MOZ_ERROR_CHECK_FALSE(rv, "abDirectory->GetDescription"); - LOG(10, "Description [%s]", NS_ConvertUTF16toUTF8(c16).get()); // Generally seems to be empty - rv=myAbDirectory->GetDirPrefId(csc); - MOZ_ERROR_CHECK_FALSE(rv, "abDirectory->GetDirPrefId"); - LOG(10, "DirPrefId [%s]", csc.get()); - LOG(10, "End of address book info"); - - return TRUE; -} Modified: plugins/mozilla-sync/trunk/src/thunderbird-addressbook.h ============================================================================== --- plugins/mozilla-sync/trunk/src/thunderbird-addressbook.h Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/thunderbird-addressbook.h Tue Mar 17 12:10:16 2009 (r5292) @@ -10,7 +10,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -32,7 +32,6 @@ #include "mozilla-headers.h" #include <nsIAbDirectory.h> -#include <nsIAddressBook.h> #include <nsIAddrDatabase.h> #include "thunderbird-card.h" @@ -42,9 +41,12 @@ public: nsCOMPtr<nsIAbDirectory> myAbDirectory; - nsCOMPtr<nsIAddressBook> myAddressBook; nsCOMPtr<nsIAddrDatabase> myAddrDatabase; +#ifdef TBIRD_3 + nsCOMPtr<nsISimpleEnumerator> myCards; +#else nsCOMPtr<nsIEnumerator> myCards; +#endif public: Modified: plugins/mozilla-sync/trunk/src/thunderbird-card.cpp ============================================================================== --- plugins/mozilla-sync/trunk/src/thunderbird-card.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/thunderbird-card.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -9,7 +9,7 @@ See http://www.KaarPoSoft.dk/bluezync/ $Id$ - Copyright (C) 2007 Henrik Kaare Poulsen /KaarPoSoft + Copyright (C) 2007, 2008, 2009 Henrik Kaare Poulsen /KaarPoSoft This plugin is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,7 +36,10 @@ #include "mozilla-headers.h" #include <nsComponentManagerUtils.h> + +#ifndef TBIRD_3 #include <nsIAbMDBCard.h> +#endif #include "mozilla-sync-utils.h" #include "thunderbird-card.h" @@ -55,6 +58,37 @@ #define ATTRIBUTE_EQUAL ((void*) 1) //!< Attribute value shall match specified value #define ATTRIBUTE_NOTEQUAL ((void*) 2) //!< Attribute muat be absent or NOT match specified value +#ifdef TBIRD_3 +#define SET_PROPERTY(card, property, sz) { \ + nsString s; \ + s=NS_ConvertUTF8toUTF16(sz); \ + rv=card->SetPropertyAsAString(property, s); \ + MOZ_ERROR_CHECK_FALSE(rv, "SetPropertyAsAString"); \ + /* free? */ } +#else +#define SET_PROPERTY(card, property, sz) { \ + PRUnichar *c16=NS_strdup(NS_ConvertUTF8toUTF16(sz).get()); \ + rv=card->SetCardValue(property, c16); \ + NS_Free(c16); } +#endif + +#ifdef TBIRD_3 +#define GET_PROPERTY(card, property, sz) { \ + nsString s; \ + s=NS_ConvertUTF8toUTF16(sz); \ + rv=card->GetPropertyAsAString(property, s); \ + /* free? */ } +#else +#define GET_PROPERTY(card, property, sz) { \ + PRUnichar *u16; \ + rv=card->GetCardValue(property, &u16); \ + MOZ_ERROR_CHECK(rv, "nsIAbCard::GetCardValue"); \ + sz=g_strdup(NS_ConvertUTF16toUTF8(u16).get()); \ + NS_Free(u16); } +#endif + + + /** One attribute to set or check in xmlformat-card **/ typedef struct _XMLAttributeDef { @@ -379,9 +413,17 @@ char *sz0=(char*)xmlNodeGetContent(xNode); char *sz=g_strstrip(sz0); LOG_SENSITIVE(1000, "Value %s", sz); +#ifdef TBIRD_3 + nsString s; + s=NS_ConvertUTF8toUTF16(sz); + MOZ_ERROR_CHECK_FALSE(rv, "NS_ConvertUTF8toUTF16"); + rv=myCard->SetPropertyAsAString(pXmlEntryDef->szProperty, s); +#else PRUnichar *c16=NS_strdup(NS_ConvertUTF8toUTF16(sz).get()); rv=myCard->SetCardValue(pXmlEntryDef->szProperty, c16); NS_Free(c16); +#endif + SET_PROPERTY(myCard, pXmlEntryDef->szProperty, sz); xmlFree(sz0); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::SetCardValue"); @@ -419,11 +461,7 @@ LOG(1000, "Setting %s", pXmlEntryDef->szProperty); char *sz=g_strstrip((char*)xmlNodeGetContent(pChildNode)); LOG_SENSITIVE(1000, "Value %s", sz); - PRUnichar *c16=NS_strdup(NS_ConvertUTF8toUTF16(sz).get()); - rv=myCard->SetCardValue(pXmlEntryDef->szProperty, c16); - MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::SetCardValue"); - NS_Free(c16); - + SET_PROPERTY(myCard, pXmlEntryDef->szProperty, sz); goto next_node; } } @@ -442,6 +480,24 @@ // if it is not already set if (!g_hash_table_lookup(pHashTableProperties, (void*)"DisplayName")) { LOG(30, "Setting DisplayName"); +#ifdef TBIRD_3 + + nsString fn; + rv=myCard->GetPropertyAsAString("FirstName", fn); + MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::GetPropertyAsAString FirstName"); + nsString ln; + rv=myCard->GetPropertyAsAString("LastName", ln); + MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::GetPropertyAsAString LastName"); + + nsString dn; + dn.Assign(fn); + dn.Append(0x20); + dn.Append(ln); + + rv=myCard->SetPropertyAsAString("DisplayName", dn); + MOZ_ERROR_CHECK_FALSE(rv, "SetPropertyAsAString"); \ + +#else PRUnichar *pruFirstName; rv=myCard->GetCardValue("FirstName", &pruFirstName); MOZ_ERROR_CHECK_FALSE(rv, "nsIAbCard::GetCardValue First Name"); @@ -460,6 +516,7 @@ NS_Free(pruFirstName); NS_Free(pruLastName); NS_Free(pruDisplayName); +#endif } g_hash_table_destroy(pHashTableNodes); @@ -508,7 +565,8 @@ void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) { nsresult rv; - nsCOMPtr<nsIAbMDBCard> abMDBCard; + + nsCOMPtr<nsIAbCard> abCard; LOG(10, "Creating nsIAbCard from xmlformat-card\n"); myCard=do_CreateInstance("@mozilla.org/addressbook/moz-abmdbcard;1", &rv); @@ -544,6 +602,24 @@ char **pSzError, void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) { + +// +// *** TODO Thunderbird 3 +// +// Need to figure out a way to get key in Thunderbird 3 +// Watch https://bugzilla.mozilla.org/show_bug.cgi?id=444093 +// + + +#ifdef TBIRD_3 + + nsresult rv; + nsCString cs; + rv=myCard->GetPropertyAsAUTF8String(OPEN_SYNC_KEY, cs); + MOZ_ERROR_CHECK(rv, "nsIAbMDBCard::GetStringAttribute"); + +#else + nsresult rv; char *c8; @@ -582,6 +658,7 @@ LOG(30, "Key=[%s]", c8); return c8; +#endif } @@ -600,41 +677,15 @@ void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) { nsresult rv; +#ifdef TBIRD_3 + gchar *sz; + GET_PROPERTY(myCard, "LastModifiedDate", sz) +#else PRUint32 kk; rv=myCard->GetLastModifiedDate(&kk); MOZ_ERROR_CHECK(rv, "nsIAbCard::GetLastModifiedDate"); return g_strdup_printf("%d", kk); -} - - -// ---------------------------------------- -/** @brief Get a strange name, only useful for debugging... - - @param pSzError Pointer to string, into which we shall write an error message if we return false - @param pLogFunction Function used to log information text - @return string on success; NULL on error -**/ -gchar* ThunderbirdCard::GetLongName( - char **pSzError, - void (*pLogFunction)(int level, bool sensitive, const char* szFile, int iLine, const char *szFunc, const char* szFormat, ...)) -{ - nsresult rv; - PRUnichar *dn16; - rv=myCard->GetDisplayName(&dn16); - MOZ_ERROR_CHECK(rv, "nsIAbCard::GetDisplayName"); - char *dn8=strdup(NS_ConvertUTF16toUTF8(dn16).get()); - PRUnichar *ln16; - rv=myCard->GetLastName(&ln16); - MOZ_ERROR_CHECK(rv, "nsIAbCard::GetLastName"); - char *ln8=strdup(NS_ConvertUTF16toUTF8(ln16).get()); - PRUnichar *fn16; - rv=myCard->GetFirstName(&fn16); - MOZ_ERROR_CHECK(rv, "nsIAbCard::GetFirstName"); - char *fn8=strdup(NS_ConvertUTF16toUTF8(fn16).get()); - - gchar* szResult=g_strdup_printf("[%s] [%s, %s]", dn8, ln8, fn8); - free(dn8); free(ln8); free(fn8); - return szResult; +#endif } @@ -684,11 +735,11 @@ gboolean groupWritten=FALSE; XMLEntryDef *pXmlEntryDef; for (pXmlEntryDef=&(pXmlGroupDef->xmlEntryDef[0]); pXmlEntryDef->szEntry; pXmlEntryDef++) { - PRUnichar *u16; - rv=myCard->GetCardValue(pXmlEntryDef->szProperty, &u16); - MOZ_ERROR_CHECK(rv, "nsIAbCard::GetCardValue"); - char *sz=g_strdup(NS_ConvertUTF16toUTF8(u16).get()); - if (*u16) { + + char *sz; + GET_PROPERTY(myCard, pXmlEntryDef->szProperty, sz); + + if (*sz) { if (!groupWritten) { rc = xmlTextWriterStartElement(writer, BAD_CAST pXmlGroupDef->szGroup); RC_ERROR_CHECK(buf,"xmlTextWriterStartElement: Error at xmlTextWriterStartElement\n"); Modified: plugins/mozilla-sync/trunk/src/thunderbird-card.h ============================================================================== --- plugins/mozilla-sync/trunk/src/thunderbird-card.h Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/src/thunderbird-card.h Tue Mar 17 12:10:16 2009 (r5292) @@ -32,6 +32,7 @@ #include "mozilla-headers.h" +#include <nsIAddrDatabase.h> #include <nsIAbCard.h> Added: plugins/mozilla-sync/trunk/tests/storage.sdb_10 ============================================================================== Binary file. No diff available. Modified: plugins/mozilla-sync/trunk/tests/unit_test_abook.cpp ============================================================================== --- plugins/mozilla-sync/trunk/tests/unit_test_abook.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/tests/unit_test_abook.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -30,17 +30,19 @@ #include <mozilla-headers.h> #include <mozilla-xpcom.h> -#if 0 -#include <nsServiceManagerUtils.h> -#include <nsIDirectoryService.h> #include <nsIProperties.h> -#include <nsAppDirectoryServiceDefs.h> -#include <nsIComponentRegistrar.h> -#endif +#include <nsIDirectoryService.h> #include <nsComponentManagerUtils.h> +#ifdef TBIRD_3 +#include <nsServiceManagerUtils.h> +#include <nsAppDirectoryServiceDefs.h> +#include <nsIFile.h> +#include <nsILocalFile.h> +#else #include <nsDirPrefs.h> #include <nsIAddressBook.h> +#endif #include "thunderbird-addressbook.h" #include "thunderbird-card.h" @@ -76,6 +78,52 @@ f=mozilla_startup(szTmp, &fWasStarted, &szError, &logFunction); fail_unless(f, "mozilla_startup failed: %s", szError); + +#ifdef TBIRD_3 + +/* + nsCOMPtr<nsILocalFile> localFile; + localFile=do_CreateInstance("@mozilla.org/file/local;1", &rv); + fail_unless(NS_SUCCEEDED(rv), "do_CreateInstance for nsILocalFile returned [0x0%x]", rv); + rv=localFile->InitWithPath(NS_LITERAL_STRING("moz-abmdbdirectory://test.mab")); + fail_unless(NS_SUCCEEDED(rv), "InitWithPath for nsILocalFile returned [0x0%x]", rv); + + rv=localFile->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(file)); + fail_unless(NS_SUCCEEDED(rv), "QueryInterface for nsILocalFile to nsIFile returned [0x0%x]", rv); +*/ +/* + nsCOMPtr<nsIFile> file; + nsCOMPtr<nsIDirectoryServiceProvider> dirService; + PRBool persistent; + dirService=do_GetService("@mozilla.org/file/directory_service;1", &rv); + fail_unless(NS_SUCCEEDED(rv), "do_GetService for nsIDirectoryServiceProvider returned [0x0%x]", rv); + +// rv=dirService->GetFile(NS_APP_USER_PROFILE_50_DIR, &persistent, getter_AddRefs(file)); + rv=dirService->GetFile("GreD", &persistent, getter_AddRefs(file)); + fail_unless(NS_SUCCEEDED(rv), "GetFile for nsIDirectoryServiceProvider returned [0x0%x]", rv); +*/ + + char *szAbook = g_strconcat(szTmp, G_DIR_SEPARATOR_S, "abook.mab", NULL); + nsCString csAbook; + rv = NS_CStringSetData(csAbook, szAbook); + fail_unless(NS_SUCCEEDED(rv), "NS_CStringSetData for csAbook returned [0x0%x]", rv); + nsCOMPtr<nsILocalFile> localFileAbook; + rv = NS_NewNativeLocalFile(csAbook, PR_FALSE, getter_AddRefs(localFileAbook)); + + nsCOMPtr<nsIFile> file; + rv=localFileAbook->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(file)); + fail_unless(NS_SUCCEEDED(rv), "QueryInterface for nsILocalFile to nsIFile returned [0x0%x]", rv); + + + nsCOMPtr<nsIAddrDatabase> addrDatabase; + addrDatabase=do_CreateInstance("@mozilla.org/addressbook/carddatabase;1", &rv); + fail_unless(NS_SUCCEEDED(rv), "do_CreateInstance for nsIAddrDatabase returned [0x0%x]", rv); + + rv=addrDatabase->OpenMDB(file, (PRBool) PR_TRUE); + fail_unless(NS_SUCCEEDED(rv), "OpenMDB for nsIAddrDatabase returned [0x0%x]", rv); + +#else + nsCOMPtr<nsIAddressBook> ab=do_CreateInstance("@mozilla.org/addressbook;1", &rv); fail_unless(NS_SUCCEEDED(rv), "do_CreateInstance for nsIAddressBook returned [0x0%x]", rv); @@ -91,6 +139,8 @@ rv=ab->NewAddressBook(abDirProps); fail_unless(NS_SUCCEEDED(rv), "NewAddressBook returned [0x0%x]", rv); +#endif + f=mozilla_shutdown(&szError, &logFunction); fail_unless(f, "mozilla_shutdown failed: %s", szError); } END_TEST @@ -108,8 +158,11 @@ f=mozilla_startup(szTmp, &fWasStarted, &szError, &logFunction); fail_unless(f, "mozilla_startup failed: %s", szError); +printf("===========================================\n"); ThunderbirdAddressbook *pAb=new ThunderbirdAddressbook(); +printf("===========================================\n"); f=pAb->Init("abook.mab", &szError, &logFunction); +printf("===========================================\n"); fail_unless(f, "could not open addressbook: %s", szError); f=mozilla_shutdown(&szError, &logFunction); @@ -197,7 +250,7 @@ tcase_add_test (tc_core, test_abook_open); tcase_add_test (tc_core, test_abook_findnonexistent); tcase_add_test (tc_core, test_abook_addcard); - tcase_add_test (tc_core, test_abook_cleanup); + //tcase_add_test (tc_core, test_abook_cleanup); suite_add_tcase (s, tc_core); return s; } Modified: plugins/mozilla-sync/trunk/tests/unit_test_xpcom.cpp ============================================================================== --- plugins/mozilla-sync/trunk/tests/unit_test_xpcom.cpp Fri Mar 13 13:38:53 2009 (r5291) +++ plugins/mozilla-sync/trunk/tests/unit_test_xpcom.cpp Tue Mar 17 12:10:16 2009 (r5292) @@ -35,6 +35,8 @@ #include <nsIProperties.h> #include <nsAppDirectoryServiceDefs.h> #include <nsIComponentRegistrar.h> +#include <nsISimpleEnumerator.h> +#include "nsISupportsPrimitives.h" #define MOZ_ERROR_CHECK(rv, str) \ @@ -59,6 +61,8 @@ nsresult rv; nsString sc; + nsCString cs; + PRBool f; const char *sz; nsCOMPtr<nsIProperties> directoryService; nsCOMPtr<nsIFile> file; @@ -71,7 +75,10 @@ rv=file->GetPath(sc); MOZ_ERROR_CHECK(rv, "GetPath for Profile"); - sz=NS_ConvertUTF16toUTF8(sc).get(); + //sz=NS_ConvertUTF16toUTF8(sc).get(); + cs=NS_ConvertUTF16toUTF8(sc); + NS_CStringGetData(cs, &sz, &f); + if ( strcmp(sz, szExpectedProfile) != 0) { *pSzError=g_strdup_printf( \ "%s(%d): Got Profile path [%s]; expected [%s]", __func__, __LINE__, sz, szExpectedProfile); @@ -83,7 +90,8 @@ rv=file->GetPath(sc); MOZ_ERROR_CHECK(rv, "GetPath for Preferences"); - sz=NS_ConvertUTF16toUTF8(sc).get(); + cs=NS_ConvertUTF16toUTF8(sc); + NS_CStringGetData(cs, &sz, &f); if ( strcmp(sz, szExpectedPreferences) != 0) { *pSzError=g_strdup_printf( \ "%s(%d): Got Preference path [%s]; expected [%s]", __func__, __LINE__, sz, szExpectedPreferences); @@ -117,11 +125,21 @@ // Some of the contract IDs we need. // Guess that if those are there, probably the rest are as well... const char *aszContractIDs[] = { + +// +// *** *** Todo Thunderbird 3 +// + +#ifdef TBIRD_3 +// "@mozilla.org/carddatabase;1", + "@mozilla.org/file/local;1", +#else "@mozilla.org/rdf/rdf-service;1", "@mozilla.org/addressbook;1", "@mozilla.org/addressbook/carddatabase;1", - "@mozilla.org/addressbook/moz-abmdbcard;1", "@mozilla.org/rdf/resource-factory;1?name=moz-abmdbdirectory", + "@mozilla.org/addressbook/moz-abmdbcard;1", +#endif NULL }; // ------------------------------------------------------------ @@ -156,6 +174,58 @@ } END_TEST // ------------------------------------------------------------ +START_TEST (test_xpcom_allcomponents) { + + fail_unless(szTmp!=NULL, "unable to create temporary directory"); + + nsresult rv; + char *szError=NULL; + gboolean f; + + gboolean fWasStarted; + f=mozilla_startup(szTmp, &fWasStarted, &szError, &logFunction); + fail_unless(f, "mozilla_startup failed: %s", szError); + + nsCOMPtr<nsIServiceManager> servMan; + rv = NS_GetServiceManager(getter_AddRefs(servMan)); + fail_unless(NS_SUCCEEDED(rv), "NS_GetServiceManager returned [0x0%x]", rv); + nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan, &rv); + fail_unless(NS_SUCCEEDED(rv), "do_QueryInterface for nsIComponentRegistrar returned [0x0%x]", rv); + + printf("Enumerating component ContractIDs\n"); + + nsCOMPtr<nsISimpleEnumerator> e; + rv=registrar->EnumerateContractIDs(getter_AddRefs(e)); + fail_unless(NS_SUCCEEDED(rv), "enumerateContractIDs returned [0x0%x]", rv); + + int n=0; + PRBool fm; + rv=e->HasMoreElements(&fm); + fail_unless(NS_SUCCEEDED(rv), "nsISimpleEnumerator::HasMoreElements returned [0x0%x]", rv); + while (fm) { + n++; + nsCOMPtr<nsISupports> s; + rv=e->GetNext(getter_AddRefs(s)); + fail_unless(NS_SUCCEEDED(rv), "nsISimpleEnumerator::GetNext returned [0x0%x]", rv); + nsCOMPtr<nsISupportsCString> scs = do_QueryInterface(s, &rv); + char* sz; + rv=scs->ToString(&sz); + fail_unless(NS_SUCCEEDED(rv), "ToString returned [0x0%x]", rv); + printf("\t%s\n", sz); + rv=e->HasMoreElements(&fm); + fail_unless(NS_SUCCEEDED(rv), "nsISimpleEnumerator::HasMoreElements returned [0x0%x]", rv); + } + + printf("Found %d component ContractIDs\n", n); + + int m=500; + fail_unless(n>m, "Only found %d components; expected at least %d", n, m); + + f=mozilla_shutdown(&szError, &logFunction); + fail_unless(f, "mozilla_shutdown failed: %s", szError); +} END_TEST + +// ------------------------------------------------------------ START_TEST (test_xpcom_cleanup) { // put it here instead of in teardown, so signals will be trapped // no error checking. If it does not work, what can we do anyway? @@ -170,6 +240,7 @@ tcase_add_unchecked_fixture (tc_core, fixture_setup, fixture_teardown); tcase_add_test (tc_core, test_xpcom_connect); tcase_add_test (tc_core, test_xpcom_components); + tcase_add_test (tc_core, test_xpcom_allcomponents); tcase_add_test (tc_core, test_xpcom_cleanup); suite_add_tcase (s, tc_core); return s; |