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

Modified Files:
        MessageView.cpp 
Log Message:
use MAction instead of int for the flags taking M_ACTION_XXX value

Index: MessageView.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageView.cpp,v
retrieving revision 1.161
retrieving revision 1.162
diff -b -u -2 -r1.161 -r1.162
--- MessageView.cpp     16 Nov 2004 14:22:25 -0000      1.161
+++ MessageView.cpp     15 May 2005 21:16:51 -0000      1.162
@@ -472,5 +472,5 @@
    showExtImages = false;
 
-   autocollect = false;
+   autocollect = M_ACTION_NEVER;
 }
 
@@ -637,13 +637,26 @@
 }
 
-void
-MessageView::CreateViewer(wxWindow *parent)
+/**
+   Load the viewer by name.
+
+   If the viewer with this name can't be loaded and another viewer is
+   available, return its name in nameAlt parameter if it's not NULL: this
+   allows to use a fallback viewer to show at least something if the configured
+   viewer is not available.
+
+   @param name of the viewer to load
+   @param nameAlt output parameter for the available viewer name if the given
+                  one couldn't be loaded
+   @return the viewer (to be DecRef()'d by caller) or NULL
+ */
+static MessageViewer *LoadViewer(const String& name, String *nameAlt = NULL)
 {
    MessageViewer *viewer = NULL;
 
-   MModuleListing *listing =
-      MModule::ListAvailableModules(MESSAGE_VIEWER_INTERFACE);
+   MModuleListing *
+      listing = MModule::ListAvailableModules(MESSAGE_VIEWER_INTERFACE);
 
-   if ( !listing || !listing->Count() )
+   const size_t countViewers = listing ? listing->Count() : 0;
+   if ( !countViewers )
    {
       wxLogError(_("No message viewer plugins found. It will be "
@@ -651,52 +664,63 @@
                    "\n"
                    "Please check that Mahogany plugins are available."));
-
-      if ( listing )
-          listing->DecRef();
    }
-   else // have at least one viewer, load it
+   else // got listing of viewer factories
    {
-      String name = m_ProfileValues.msgViewer;
-      if ( name.empty() )
-         name = GetStringDefault(MP_MSGVIEW_VIEWER);
-
       MModule *viewerFactory = MModule::LoadModule(name);
-      if ( !viewerFactory ) // failed to load the configured viewer
-      {
-         // try any other
-         String nameFirst = (*listing)[0].GetName();
 
-         if ( name != nameFirst )
+      // failed to load the configured viewer
+      if ( !viewerFactory )
          {
-            wxLogWarning(_("Failed to load the configured message viewer 
'%s'.\n"
-                           "\n"
-                           "Reverting to the default message viewer."),
-                         name.c_str());
-
-            viewerFactory = MModule::LoadModule(nameFirst);
-
-            if ( viewerFactory )
+         // try to find alternative
+         if ( nameAlt )
+         {
+            for ( size_t n = 0; n < countViewers; n++ )
+            {
+               String nameViewer = (*listing)[n].GetName();
+               if ( nameViewer != name )
             {
-               // remember this one as our real viewer or the code reacting to
-               // the options change would break down
-               m_ProfileValues.msgViewer = nameFirst;
+                  *nameAlt = nameViewer;
+                  break;
             }
          }
-
-         if ( !viewerFactory )
-         {
-            wxLogError(_("Failed to load the default message viewer '%s'.\n"
-                         "\n"
-                         "Message preview will not work!"), nameFirst.c_str());
          }
       }
-
-      if ( viewerFactory )
+      else // loaded ok
       {
          viewer = ((MessageViewerFactory *)viewerFactory)->Create();
          viewerFactory->DecRef();
       }
+   }
 
+   if ( listing )
       listing->DecRef();
+
+   return viewer;
+}
+
+void
+MessageView::CreateViewer(wxWindow *parent)
+{
+   String name = m_ProfileValues.msgViewer;
+   if ( name.empty() )
+      name = GetStringDefault(MP_MSGVIEW_VIEWER);
+
+   String nameAlt;
+   MessageViewer *viewer = LoadViewer(name, &nameAlt);
+   if ( !viewer )
+   {
+      wxLogWarning(_("Failed to load the configured message viewer '%s'.\n"
+                     "\n"
+                     "Reverting to the available message viewer '%s'."),
+                   name.c_str(), nameAlt.c_str());
+
+      viewer = LoadViewer(nameAlt);
+   }
+
+   if ( !viewer )
+   {
+      wxLogError(_("Failed to load any message viewer.\n"
+                   "\n"
+                   "Message preview will not work!"));
    }
 
@@ -1131,5 +1155,5 @@
    }
 
-   settings->autocollect =  READ_CONFIG(profile, MP_AUTOCOLLECT);
+   settings->autocollect = (MAction)(long)READ_CONFIG(profile, MP_AUTOCOLLECT);
    settings->autocollectSenderOnly =  READ_CONFIG(profile, 
MP_AUTOCOLLECT_SENDER);
    settings->autocollectNamed =  READ_CONFIG(profile, MP_AUTOCOLLECT_NAMED);
@@ -2296,4 +2320,90 @@
 }
 
+// ----------------------------------------------------------------------------
+// finding the best viewer for the current message
+// ----------------------------------------------------------------------------
+
+#if 0
+String
+MessageView::FindViewerForNestedPart(const MimePart *mimepart)
+{
+   const MimePart *partChild = mimepart->GetNested();
+   while ( partChild )
+   {
+      ProcessPart(partChild);
+
+      partChild = partChild->GetNext();
+   }
+}
+
+String
+MessageView::FindViewerForMultiPart(const MimePart *mimepart,
+                                    const String& subtype)
+{
+   String name;
+
+   if ( subtype == _T("ALTERNATIVE") )
+   {
+      ProcessAlternativeMultiPart(mimepart);
+   }
+   else // process all unknown as MIXED (according to the RFC 2047)
+   {
+      ProcessAllNestedParts(mimepart);
+   }
+
+   return name;
+}
+
+String
+MessageView::FindViewerForPart(const MimePart *mimepart)
+{
+   CHECK_RET( mimepart, _T("NULL mimepart") );
+
+   String name;
+
+   const MimeType type = mimepart->GetType();
+   switch ( type.GetPrimary() )
+   {
+      case MimeType::MULTIPART:
+         name = FindViewerForMultiPart(mimepart, type.GetSubType());
+         break;
+
+      case MimeType::MESSAGE:
+         if ( m_ProfileValues.inlineRFC822 )
+         {
+            name = FindViewerForNestedPart(mimepart);
+            break;
+         }
+         //else: fall through and show it as attachment
+
+      case MimeType::TEXT:
+      case MimeType::APPLICATION:
+      case MimeType::AUDIO:
+      case MimeType::IMAGE:
+      case MimeType::VIDEO:
+      case MimeType::MODEL:
+      case MimeType::OTHER:
+      case MimeType::CUSTOM1:
+      case MimeType::CUSTOM2:
+      case MimeType::CUSTOM3:
+      case MimeType::CUSTOM4:
+      case MimeType::CUSTOM5:
+      case MimeType::CUSTOM6:
+         // a simple part, check 
+         ShowPart(mimepart);
+         break;
+
+      default:
+         FAIL_MSG( _T("unknown MIME type") );
+   }
+
+   return name;
+}
+#endif
+
+// ----------------------------------------------------------------------------
+// showing a new message
+// ----------------------------------------------------------------------------
+
 void
 MessageView::Update()
@@ -3203,5 +3313,5 @@
 
       // autocollect the addresses from it if configured
-      if ( m_ProfileValues.autocollect )
+      if ( m_ProfileValues.autocollect != M_ACTION_NEVER )
       {
          AutoCollectAddresses(m_mailMessage,



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to