Update of /cvsroot/mahogany/M/src/adb
In directory sc8-pr-cvs1:/tmp/cvs-serv25496/src/adb
Modified Files:
AdbManager.cpp ProvBbdb.cpp ProvFC.cpp ProvLine.cpp
ProvPalm.cpp ProvPasswd.cpp
Log Message:
Tolerate addressbooks that don't support autodetection
Index: AdbManager.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/AdbManager.cpp,v
retrieving revision 1.38
retrieving revision 1.39
diff -b -u -2 -r1.38 -r1.39
--- AdbManager.cpp 28 Dec 2002 02:28:33 -0000 1.38
+++ AdbManager.cpp 13 Sep 2003 16:03:15 -0000 1.39
@@ -427,24 +427,21 @@
// no, must create a new one
- AdbDataProvider *prov = provider;
- if ( prov == NULL ) {
- // try to find it
- AdbDataProvider::AdbProviderInfo *info = AdbDataProvider::ms_listProviders;
- while ( info ) {
- prov = info->CreateProvider();
- if ( prov->TestBookAccess(name, AdbDataProvider::Test_OpenReadOnly) ||
- prov->TestBookAccess(name, AdbDataProvider::Test_Create) ) {
- if ( providerName ) {
- // return the provider name if asked for it
- *providerName = info->szName;
- }
- break;
- }
+ AdbDataProvider *prov = NULL;
+ if ( provider )
+ {
+ prov = provider;
+ prov->IncRef();
+ }
+ if ( prov == NULL )
+ prov = AutodetectFormat(name);
+ if ( prov == NULL )
+ prov = CreateNative(name);
+ if ( prov == NULL )
+ prov = MatchBookName(name);
- prov->DecRef();
- prov = NULL;
-
- info = info->pNext;
- }
+ if ( providerName && prov )
+ {
+ // return the provider name if asked for it
+ *providerName = prov->GetProviderName();
}
@@ -462,10 +459,56 @@
}
- if ( prov && !provider ) {
- // only if it's the one we created, not the one which was passed in!
+ if ( prov )
prov->DecRef();
- }
return book;
+}
+
+/*static*/ AdbDataProvider *AdbManager::AutodetectFormat(const String& name)
+{
+ for ( AdbDataProvider::AdbProviderInfo *info
+ = AdbDataProvider::ms_listProviders; info; info = info->pNext )
+ {
+ AdbDataProvider *prov = info->CreateProvider();
+
+ if ( prov->TestBookAccess(name,
+ AdbDataProvider::Test_AutodetectCapable)
+ && prov->TestBookAccess(name, AdbDataProvider::Test_OpenReadOnly) )
+ {
+ return prov;
+ }
+
+ prov->DecRef();
+ }
+
+ return NULL;
+}
+
+/*static*/ AdbDataProvider *AdbManager::CreateNative(const String& name)
+{
+ AdbDataProvider *prov = AdbDataProvider::GetNativeProvider();
+
+ if ( prov->TestBookAccess(name, AdbDataProvider::Test_Create) )
+ return prov;
+
+ prov->DecRef();
+ return NULL;
+}
+
+/*static*/ AdbDataProvider *AdbManager::MatchBookName(const String& name)
+{
+ for ( AdbDataProvider::AdbProviderInfo *info
+ = AdbDataProvider::ms_listProviders; info; info = info->pNext )
+ {
+ AdbDataProvider *prov = info->CreateProvider();
+
+ if ( prov->TestBookAccess(name, AdbDataProvider::Test_RecognizesName)
+ && prov->TestBookAccess(name, AdbDataProvider::Test_Create) )
+ return prov;
+
+ prov->DecRef();
+ }
+
+ return NULL;
}
Index: ProvBbdb.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvBbdb.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -b -u -2 -r1.32 -r1.33
--- ProvBbdb.cpp 22 Aug 2003 09:53:42 -0000 1.32
+++ ProvBbdb.cpp 13 Sep 2003 16:03:15 -0000 1.33
@@ -1057,4 +1057,11 @@
BbdbDataProvider::TestBookAccess(const String& name, AdbTests test)
{
+ switch ( test )
+ {
+ case Test_Create:
+ case Test_OpenReadOnly:
+ case Test_Open:
+ // FIXME: Different code for Test_OpenReadOnly, Test_Open,
+ // and Test_Create
if(wxFileExists(name))
{
@@ -1063,4 +1070,10 @@
strutil_getstrline(file, line);
return BbdbEntry::ReadHeader(NULL, &line);
+ }
+ return false;
+ case Test_AutodetectCapable:
+ return true;
+ case Test_RecognizesName:
+ return false;
}
return false;
Index: ProvFC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvFC.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -b -u -2 -r1.40 -r1.41
--- ProvFC.cpp 22 Aug 2003 09:53:42 -0000 1.40
+++ ProvFC.cpp 13 Sep 2003 16:03:15 -0000 1.41
@@ -839,4 +839,12 @@
break;
+ case Test_AutodetectCapable:
+ ok = true;
+ break;
+
+ case Test_RecognizesName:
+ ok = false;
+ break;
+
default:
FAIL_MSG(_T("invalid test in TestBookAccess"));
Index: ProvLine.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvLine.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -b -u -2 -r1.3 -r1.4
--- ProvLine.cpp 4 Sep 2003 13:03:40 -0000 1.3
+++ ProvLine.cpp 13 Sep 2003 16:03:15 -0000 1.4
@@ -623,4 +623,9 @@
}
break;
+
+ case Test_AutodetectCapable:
+ case Test_RecognizesName:
+ ok = false;
+ break;
default:
Index: ProvPalm.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvPalm.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -b -u -2 -r1.20 -r1.21
--- ProvPalm.cpp 22 Aug 2003 09:53:42 -0000 1.20
+++ ProvPalm.cpp 13 Sep 2003 16:03:15 -0000 1.21
@@ -380,4 +380,7 @@
case Test_Create:
return FALSE;
+ case Test_AutodetectCapable:
+ case Test_RecognizesName:
+ return true;
default:
FAIL_MSG(_T("invalid test in TestBookAccess"));
Index: ProvPasswd.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvPasswd.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -b -u -2 -r1.13 -r1.14
--- ProvPasswd.cpp 22 Aug 2003 09:53:42 -0000 1.13
+++ ProvPasswd.cpp 13 Sep 2003 16:03:15 -0000 1.14
@@ -473,4 +473,8 @@
case Test_OpenReadOnly:
+ return name.empty();
+
+ case Test_AutodetectCapable:
+ case Test_RecognizesName:
return true;
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates