Update of /cvsroot/mahogany/M/src/adb
In directory usw-pr-cvs1:/tmp/cvs-serv9870/src/adb

Modified Files:
        AdbEntry.cpp AdbManager.cpp ProvDummy.cpp 
Log Message:
use only the nick names matches when expanding an address using the address
book if there were any such expansions, only fallback to the matches elsewhere
if no nicknames could be matched


Index: AdbEntry.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/AdbEntry.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -b -u -2 -r1.6 -r1.7
--- AdbEntry.cpp        21 Mar 2000 20:48:20 -0000      1.6
+++ AdbEntry.cpp        14 Apr 2002 09:03:57 -0000      1.7
@@ -98,5 +98,6 @@
 }
 
-bool AdbEntryStoredInMemory::Matches(const char *szWhat, int where, int how)
+int
+AdbEntryStoredInMemory::Matches(const char *szWhat, int where, int how) const
 {
   wxString strWhat;
@@ -123,5 +124,5 @@
         strField.MakeLower();                                       \
       if ( strField.Matches(strWhat) )                              \
-        return TRUE;                                                \
+        return AdbLookup_##field;                                   \
     }
 
@@ -138,5 +139,5 @@
       strField.MakeLower();
       if ( strField.Matches(strWhat) )
-        return TRUE;
+        return AdbLookup_EMail;
     }
 
@@ -147,8 +148,9 @@
       strField.MakeLower();
       if ( strField.Matches(strWhat) )
-        return TRUE;
+        return AdbLookup_EMail;
     }
   }
 
-  return FALSE;
+  // not found
+  return 0;
 }

Index: AdbManager.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/AdbManager.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -b -u -2 -r1.31 -r1.32
--- AdbManager.cpp      15 Feb 2002 21:29:11 -0000      1.31
+++ AdbManager.cpp      14 Apr 2002 09:03:57 -0000      1.32
@@ -60,4 +60,5 @@
 static void GroupLookup(
                         ArrayAdbEntries& aEntries,
+                        ArrayAdbEntries *aMoreEntries,
                         AdbEntryGroup *pGroup,
                         const String& what,
@@ -68,10 +69,21 @@
 
 // search in the books specified or in all loaded books otherwise
-static bool AdbLookupForEntriesOrGroups(ArrayAdbEntries& aEntries,
+static bool AdbLookupForEntriesOrGroups(
+                                        ArrayAdbEntries& aEntries,
+                                        ArrayAdbEntries *aMoreEntries,
                                         const String& what,
                                         int where,
                                         int how,
                                         const ArrayAdbBooks *paBooks,
-                                        ArrayAdbGroups *aGroups = NULL);
+                                        ArrayAdbGroups *aGroups = NULL
+                                       );
+
+#define CLEAR_ADB_ARRAY(entries)            \
+  {                                         \
+    size_t nCount = entries.GetCount();     \
+    for ( size_t n = 0; n < nCount; n++ ) { \
+      entries[n]->DecRef();                 \
+    }                                       \
+  }
 
 // ============================================================================
@@ -85,4 +97,5 @@
 // recursive (depth first) search
 static void GroupLookup(ArrayAdbEntries& aEntries,
+                        ArrayAdbEntries *aMoreEntries,
                         AdbEntryGroup *pGroup,
                         const String& what,
@@ -115,5 +128,5 @@
     AdbEntryGroup *pSubGroup = pGroup->GetGroup(aNames[nGroup]);
 
-    GroupLookup(aEntries, pSubGroup, what, where, how);
+    GroupLookup(aEntries, aMoreEntries, pSubGroup, what, where, how);
 
     // groups are matched by name only (case-insensitive)
@@ -131,14 +144,29 @@
     AdbEntry *pEntry = pGroup->GetEntry(aNames[nEntry]);
 
-    if ( pEntry->Matches(what, where, how) ) {
-      aEntries.Add(pEntry);
+    // we put the entries which match with their nick name in one array and
+    // the entries which match anywhere else in the other one: see AdbExpand()
+    // to see why
+    switch ( pEntry->Matches(what, where, how) ) {
+      default:                  // matches elsewhere
+        if ( aMoreEntries ) {
+          aMoreEntries->Add(pEntry);
+          break;
     }
-    else {
+        // else: fall through
+
+      case AdbLookup_NickName:  // match in the entry name
+        aEntries.Add(pEntry);
+        break;
+
+      case 0:                   // not found at all
       pEntry->DecRef();
+        break;
     }
   }
 }
 
-static bool AdbLookupForEntriesOrGroups(ArrayAdbEntries& aEntries,
+static bool
+AdbLookupForEntriesOrGroups(ArrayAdbEntries& aEntries,
+                            ArrayAdbEntries *aMoreEntries,
                                         const String& what,
                                         int where,
@@ -154,5 +182,6 @@
   size_t nBookCount = paBooks->Count();
   for ( size_t nBook = 0; nBook < nBookCount; nBook++ ) {
-    GroupLookup(aEntries, (*paBooks)[nBook], what, where, how, aGroups);
+    GroupLookup(aEntries, aMoreEntries,
+                (*paBooks)[nBook], what, where, how, aGroups);
   }
 
@@ -168,14 +197,14 @@
 {
    if ( !group )
-      return AdbLookupForEntriesOrGroups(aEntries, what, where, how, NULL);
+      return AdbLookupForEntriesOrGroups(aEntries, NULL, what, where, how, NULL);
 
    // look just in this group
-   GroupLookup(aEntries, group, what, where, how);
+   GroupLookup(aEntries, NULL, group, what, where, how);
 
    return !aEntries.IsEmpty();
 }
 
-bool AdbExpand(wxArrayString& results, const String& what,
-               int how, wxFrame *frame)
+bool
+AdbExpand(wxArrayString& results, const String& what, int how, wxFrame *frame)
 {
   AdbManager_obj manager;
@@ -195,5 +224,6 @@
   // check for a group match too
   ArrayAdbGroups aGroups;
-  ArrayAdbEntries aEntries;
+  ArrayAdbEntries aEntries,
+                  aMoreEntries;
 
   // expansion may take a long time ...
@@ -207,6 +237,16 @@
   wxBusyCursor bc;
 
-  if ( AdbLookupForEntriesOrGroups(aEntries, what, lookupMode,
+  if ( AdbLookupForEntriesOrGroups(aEntries, &aMoreEntries, what, lookupMode,
                                    how, NULL, &aGroups ) ) {
+    // first of all, if we had any nick name matches, ignore all the other ones
+    // but otherwise use them as well
+    if ( aEntries.IsEmpty() ) {
+      aEntries = aMoreEntries;
+    }
+    else {
+      // we don't need them at all
+      CLEAR_ADB_ARRAY(aMoreEntries);
+    }
+
     // merge both arrays into one big one: notice that the order is important,
     // the groups should come first (see below)
@@ -278,9 +318,5 @@
 
     // free all entries and groups
-    size_t nCount = aEverything.Count();
-    for ( n = 0; n < nCount; n++ )
-    {
-      aEverything[n]->DecRef();
-    }
+    CLEAR_ADB_ARRAY(aEverything);
   }
   else {
@@ -517,4 +553,5 @@
 // AdbManager debugging support
 // ----------------------------------------------------------------------------
+
 #ifdef DEBUG
 
@@ -527,3 +564,5 @@
 }
 
-#endif
+#endif // DEBUG
+
+/* vi: set ts=2 sw=2: */

Index: ProvDummy.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/adb/ProvDummy.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -b -u -2 -r1.18 -r1.19
--- ProvDummy.cpp       15 Feb 2002 21:29:11 -0000      1.18
+++ ProvDummy.cpp       14 Apr 2002 09:03:57 -0000      1.19
@@ -78,5 +78,5 @@
   virtual void ClearExtraEMails();
 
-  virtual bool Matches(const char *str, int where, int how);
+  virtual int Matches(const char *str, int where, int how) const;
 
   // an easier to use GetName()
@@ -269,7 +269,7 @@
 }
 
-bool DummyEntry::Matches(const char *what, int where, int how)
+int DummyEntry::Matches(const char *what, int where, int how) const
 {
-  return FALSE;
+  return 0;
 }
 


_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to