Update of /cvsroot/mahogany/M/src/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17107/src/gui

Modified Files:
        wxSubfoldersDialog.cpp 
Log Message:
compare folder paths case insensitively

Index: wxSubfoldersDialog.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxSubfoldersDialog.cpp,v
retrieving revision 1.83
retrieving revision 1.84
diff -b -u -2 -r1.83 -r1.84
--- wxSubfoldersDialog.cpp      1 Jul 2005 15:04:24 -0000       1.83
+++ wxSubfoldersDialog.cpp      1 Jul 2005 17:51:05 -0000       1.84
@@ -42,10 +42,4 @@
 #include "gui/wxDialogLayout.h"
 
-// this gets rid of the assert warning, but not of the real problem: we should
-// be able to redraw the window without calling wxYield() at all
-#if wxCHECK_VERSION(2, 2, 6)
-   #define wxYield wxYieldIfNeeded
-#endif // wxWin 2.2.6+
-
 // TODO: this code doesn't work yet, finish it
 //#define USE_SELECT_BUTTONS
@@ -98,4 +92,55 @@
 }
 
+/// Values for StringStartsWith() last argument
+enum CaseSensitivity
+{
+   Case_Exact,
+   Case_Ignore
+};
+
+/**
+   Compare two characaters either case sensitively or not.
+ */
+static inline bool IsSame(wxChar ch1, wxChar ch2, CaseSensitivity cs)
+{
+   return cs == Case_Ignore ? wxToupper(ch1) == wxToupper(ch2) : ch1 == ch2;
+}
+
+/**
+   Checks whether the given string starts with the prefix and returns the
+   remainder of the string in this case.
+
+   @param str the string to examine
+   @param prefix the prefix to detect and possibly remove
+   @param cs case sensitivity: if Case_Ignore, prefix is matched ignoring case
+   @param rest if non-NULL is filled with the remaining part of the string
+               (after prefix) if the return value is true and becomes empty
+               otherwise
+   @return true if str starts with prefix
+ */
+static bool
+StringStartsWith(const String& str,
+                 const wxChar *prefix,
+                 CaseSensitivity cs = Case_Exact,
+                 String *rest = NULL)
+{
+   const wxChar *p = str.c_str();
+   while ( *prefix )
+   {
+      if ( !IsSame(*prefix++, *p++, cs) )
+      {
+         // no match
+         if ( rest )
+            rest->clear();
+         return false;
+      }
+   }
+
+   if ( rest )
+      *rest = p;
+
+   return true;
+}
+
 // ----------------------------------------------------------------------------
 // private classes
@@ -142,4 +187,5 @@
    wxString GetRelativePath(wxTreeItemId id) const;
 
+
    // the progress meter
    MProgressInfo *m_progressInfo;
@@ -176,4 +222,19 @@
 };
 
+struct SubfoldersTreeItemData : public wxTreeItemData
+{
+   SubfoldersTreeItemData(long attr_, const String& name_)
+      : name(name_),
+        attr(attr_)
+   {
+   }
+
+   const String name;
+   const long attr;
+
+
+   DECLARE_NO_COPY_CLASS(SubfoldersTreeItemData)
+};
+
 class wxSubscriptionDialog : public wxManuallyLaidOutDialog
 {
@@ -369,7 +430,8 @@
    // just 'inbox' for #mh/inbox
    m_folderPath = m_folder->GetPath();
-   if ( m_folderType == MF_MH )
+   switch ( m_folderType )
    {
-      if ( !!m_folderPath )
+      case MF_MH:
+         if ( !m_folderPath.empty() )
       {
          if ( m_folderPath[0u] == '/' )
@@ -383,4 +445,14 @@
          m_folderPath = m_folderPath.AfterLast('/');
       }
+         break;
+
+      case MF_FILE:
+      case MF_IMAP:
+         {
+            MailFolder_obj mf(m_mailFolder->GetMailFolder());
+            if ( mf )
+               m_folderPath = mf->GetLogicalMailboxName(m_folderPath);
+         }
+         break;
    }
 
@@ -484,5 +556,5 @@
 
 void
-wxSubfoldersTree::OnListFolder(const String& spec, wxChar delim, long attr)
+wxSubfoldersTree::OnListFolder(const String& path, wxChar delim, long attr)
 {
    if ( m_chDelimiter == '\0' )
@@ -503,21 +575,38 @@
    // we're passed a folder path -- extract the folder name from it
    wxString name;
-   if ( spec.StartsWith(m_reference, &name) )
+   if ( !StringStartsWith(path, m_reference, Case_Ignore, &name) )
    {
+      wxLogDebug(_T("Folder specification '%s' unexpected."), path.c_str());
+      return;
+   }
+
       if ( m_chDelimiter )
       {
          if ( *name.c_str() == m_chDelimiter )
-         {
             name.erase(0, 1);
          }
-      }
 
+   if ( name.empty() || (m_chDelimiter && wxStrchr(name, m_chDelimiter)) )
+   {
       // ignore the folder itself and any grand children - we only want the
       // direct children here
-      if ( !!name && (!m_chDelimiter || !wxStrchr(name, m_chDelimiter)) )
-      {
+      return;
+   }
+
+   // ignore "messages" part of the dual use mailboxes if we had already had
+   // the "subfolders" one
+   MailFolder_obj mf(m_mailFolder->GetMailFolder());
+   if ( !mf )
+      return;
+
+   String namePhysical = name;
+   name = mf->GetLogicalMailboxName(name);
+
+
+   // do add new folder to the tree
          wxTreeItemId id = OnNewFolder(name);
-         if ( id.IsOk() )
-         {
+   if ( !id.IsOk() )
+      return;
+
             if ( !(attr & ASMailFolder::ATT_NOINFERIORS) )
             {
@@ -526,8 +615,5 @@
             }
 
-            if ( attr & ASMailFolder::ATT_NOSELECT )
-            {
-               SetItemData(id, new wxTreeItemData());
-            }
+   SetItemData(id, new SubfoldersTreeItemData(attr, namePhysical));
 
             // show the folders not already present in the tree in bold
@@ -536,17 +622,9 @@
             // note that if the parent folder is not in the tree, its children
             // don't risk to be there neither
-            MFolder_obj folder(m_folderCur ? m_folderCur->GetSubfolder(name)
-                                           : NULL);
+   MFolder_obj folder(m_folderCur ? m_folderCur->GetSubfolder(name) : NULL);
             if ( !folder )
             {
                SetItemBold(id);
             }
-         }
-      }
-   }
-   else
-   {
-      wxLogDebug(_T("Folder specification '%s' unexpected."), spec.c_str());
-   }
 }
 
@@ -571,5 +649,5 @@
    }
 
-   if ( m_chDelimiter )
+   if ( m_chDelimiter != '\0' )
       RemoveTrailingDelimiters(&name, m_chDelimiter);
 
@@ -589,4 +667,7 @@
    Enable();
 
+   // we lose focus during expansion because we're disabled, restore it now
+   SetFocus();
+
    if ( !m_nFoldersRetrieved && m_idParent.IsOk() )
    {
@@ -595,5 +676,5 @@
    }
 
-   m_idParent = wxTreeItemId(); // invalid
+   m_idParent.Unset();
 }
 
@@ -602,9 +683,5 @@
 {
    // insert in alphabetic order under the parent
-#if wxCHECK_VERSION(2, 5, 0)
    wxTreeItemIdValue cookie;
-#else
-   long cookie;
-#endif
    wxTreeItemId childPrev,
                 child = GetFirstChild(parent, cookie);
@@ -735,5 +812,5 @@
    m_treectrl = new wxSubfoldersTree(this, folder, mailFolder);
    c = new wxLayoutConstraints;
-   c->top.SameAs(m_box, wxTop, 4*LAYOUT_Y_MARGIN);
+   c->top.SameAs(m_box, wxTop, 5*LAYOUT_Y_MARGIN);
    c->left.SameAs(m_box, wxLeft, 2*LAYOUT_X_MARGIN);
    c->right.SameAs(m_box, wxRight, 2*LAYOUT_X_MARGIN);
@@ -823,9 +900,5 @@
          wxString subStr = component.Left(n + 1);
 
-#if wxCHECK_VERSION(2, 5, 0)
          wxTreeItemIdValue cookie;
-#else
-         long cookie;
-#endif
          wxTreeItemId child = m_treectrl->GetFirstChild(item, cookie);
          while ( child.IsOk() )
@@ -1025,20 +1098,18 @@
       int flagsParent = parent->GetFlags();
 
-      wxString fullpath = m_folder->GetPath();
+      wxString fullpath = m_folderPath;
       for ( int level = levelMax - 1; level >= 0; level-- )
       {
-         wxString name = components[level];
+         const String name = components[level];
 
          // the idea for this test is to avoid creating MH folders named
          // /inbox (fullpath is empty for the root MH folder)
-         if ( !!fullpath )
+         if ( !fullpath.empty() )
          {
             fullpath += GetFolderNameSeparator();
          }
-         fullpath += name;
 
-         // to create a a/b/c, we must first create a, then b and then c, so
-         // we create a folder during each loop iteration - unless it already
-         // exists
+         // to create a/b/c, we must first create a, then b and then c, so we
+         // create a folder during each loop iteration if it doesn't exist yet
          MFolder *folderNew = parent->GetSubfolder(name);
          if ( !folderNew )
@@ -1049,5 +1120,6 @@
             if ( !folderNew )
             {
-               wxLogError(_("Failed to create folder '%s'."), 
fullpath.c_str());
+               wxLogError(_("Failed to create folder '%s'."),
+                          (fullpath + name).c_str());
 
                // can't create children if parent creation failed...
@@ -1055,7 +1127,16 @@
             }
 
+            SubfoldersTreeItemData *
+               data = static_cast<SubfoldersTreeItemData *>(
+                                          m_treectrl->GetItemData(ids[level]));
+
             // set up the just created folder
             Profile_obj profile(folderNew->GetProfile());
-            profile->writeEntry(MP_FOLDER_PATH, fullpath);
+
+            // notice the use of data->name: this is important as for emulated
+            // dual use mailboxes it may be different than name and here we
+            // need the real path pointing to the mailbox containing the
+            // messages, not the path in the folders hierarchy
+            profile->writeEntry(MP_FOLDER_PATH, fullpath + data->name);
 
             // copy folder flags from its parent handling MF_FLAGS_GROUP
@@ -1070,7 +1151,5 @@
             }
 
-            // the item data is only set by the tree for non selectable
-            // folders, so a folder with item data has NOSELECT flag
-            if ( m_treectrl->GetItemData(ids[level]) )
+            if ( data && (data->attr & ASMailFolder::ATT_NOSELECT) )
             {
                flags |= MF_FLAGS_NOSELECT;
@@ -1087,4 +1166,6 @@
          }
 
+         fullpath += name;
+
          parent->DecRef();
          parent = folderNew;
@@ -1127,5 +1208,5 @@
    m_progressInfo = new MProgressInfo(NULL,
                                       _("Retrieving the folder list: "));
-   wxYield(); // to show the frame
+   wxYieldIfNeeded(); // to show the frame
 
    (void)mailFolder->ListFolders
@@ -1171,5 +1252,5 @@
 
 void
-ListFolderEventReceiver::OnListFolder(const String& spec,
+ListFolderEventReceiver::OnListFolder(const String& path,
                                       wxChar chDelimiter,
                                       long attr)
@@ -1188,5 +1269,5 @@
    // we're passed a folder specification - extract the folder name from it
    wxString name;
-   if ( spec.StartsWith(m_reference, &name) )
+   if ( StringStartsWith(path, m_reference, Case_Ignore, &name) )
    {
       // remove the leading delimiter to get a relative name
@@ -1197,6 +1278,10 @@
    }
 
-   if ( !name.empty() )
+   if ( name.empty() )
    {
+      wxLogDebug(_T("Folder specification '%s' unexpected."), path.c_str());
+      return;
+   }
+
       wxString relpath = name;
       if ( chDelimiter != '\0' )
@@ -1265,9 +1350,4 @@
          wxLogError(_("Failed to create the folder '%s'"), name.c_str());
       }
-   }
-   else
-   {
-      wxLogDebug(_T("Folder specification '%s' unexpected."), spec.c_str());
-   }
 }
 



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to