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

Modified Files:
        ComposeTemplate.cpp MessageTemplate.cpp 
Log Message:
added $signature template macro (bug 460)

Index: ComposeTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/ComposeTemplate.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -b -u -2 -r1.23 -r1.24
--- ComposeTemplate.cpp 4 Mar 2002 18:01:07 -0000       1.23
+++ ComposeTemplate.cpp 4 Mar 2002 18:24:35 -0000       1.24
@@ -40,11 +40,16 @@
 #include "MessageView.h"
 
+#include "Mpers.h"
+
 #include <wx/confbase.h>      // for wxExpandEnvVars()
 #include <wx/file.h>
 #include <wx/ffile.h>
+#include <wx/textfile.h>
 #include <wx/tokenzr.h>
 
 #include <wx/regex.h>
 
+#include "wx/persctrl.h"
+
 // ----------------------------------------------------------------------------
 // options we use here
@@ -54,4 +59,7 @@
 extern const MOption MP_COMPOSETEMPLATEPATH_GLOBAL;
 extern const MOption MP_COMPOSETEMPLATEPATH_USER;
+extern const MOption MP_COMPOSE_SIGNATURE;
+extern const MOption MP_COMPOSE_USE_SIGNATURE;
+extern const MOption MP_COMPOSE_USE_SIGNATURE_SEPARATOR;
 extern const MOption MP_DATE_FMT;
 extern const MOption MP_REPLY_DETECT_SIG;
@@ -162,18 +170,19 @@
    enum Variable
    {
-      Var_Date,            // insert the date in the default format
-      Var_Cursor,          // position the cursor here after template expansion
-      Var_To,              // the recipient name
-      Var_Subject,         // the message subject (without any "Re"s)
+      MiscVar_Date,        // insert the date in the default format
+      MiscVar_Cursor,      // position the cursor here after template expansion
+      MiscVar_To,          // the recipient name
+      MiscVar_Subject,     // the message subject (without any "Re"s)
 
       // all entries from here only apply to the reply/forward/followup
       // templates because they work with the original message
-      Var_Quote,           // quote the original text
-      Var_Quote822,        // include the original msg as a RFC822 attachment
-      Var_Text,            // include the original text as is
-      Var_Sender,          // the fullname of the sender
+      MiscVar_Quote,       // quote the original text
+      MiscVar_Quote822,    // include the original msg as a RFC822 attachment
+      MiscVar_Text,        // include the original text as is
+      MiscVar_Sender,      // the fullname of the sender
+      MiscVar_Signature,   // the signature
 
-      Var_Invalid,
-      Var_Max = Var_Invalid
+      MiscVar_Invalid,
+      MiscVar_Max = MiscVar_Invalid
    };
 
@@ -219,9 +228,9 @@
 
    // get the variable id from the string (works for misc variables only, will
-   // return Var_Invalid if variable is unknown)
+   // return MiscVar_Invalid if variable is unknown)
    static Variable GetVariable(const String& variable)
    {
-      return (Variable)FindStringInArray(ms_templateVarNames,
-                                         Var_Max, variable);
+      return (Variable)FindStringInArray(ms_templateMiscVars,
+                                         MiscVar_Max, variable);
    }
 
@@ -302,4 +311,7 @@
    bool ExpandOriginal(const String& name, String *value) const;
 
+   // get the signature to use (including the signature separator, if any)
+   String GetSignature() const;
+
    // return the reply prefix to use for message quoting when replying
    String GetReplyPrefix() const;
@@ -342,5 +354,5 @@
 
    // this array contains the list of all variables without category
-   static const char *ms_templateVarNames[Var_Max];
+   static const char *ms_templateMiscVars[MiscVar_Max];
 
    // this array contains the variable names from "message" category
@@ -364,4 +376,5 @@
 {
    TemplatePopupMenuItem(_("Put &cursor here"), "$cursor"),
+   TemplatePopupMenuItem(_("Insert &signature"), "$signature"),
    TemplatePopupMenuItem(),
    TemplatePopupMenuItem(_("Insert current &date"), "$date"),
@@ -544,5 +557,5 @@
 };
 
-const char *VarExpander::ms_templateVarNames[] =
+const char *VarExpander::ms_templateMiscVars[] =
 {
    "date",
@@ -554,4 +567,5 @@
    "text",
    "sender",
+   "signature",
 };
 
@@ -693,5 +707,5 @@
    switch ( GetVariable(name.Lower()) )
    {
-      case Var_Date:
+      case MiscVar_Date:
          {
             time_t ltime;
@@ -708,17 +722,21 @@
          break;
 
-      case Var_Cursor:
+      case MiscVar_Cursor:
          m_sink.RememberCursorPosition();
          break;
 
          // some shortcuts for the values of the "original:" category
-      case Var_To:
-      case Var_Subject:
-      case Var_Quote:
-      case Var_Quote822:
-      case Var_Text:
-      case Var_Sender:
+      case MiscVar_To:
+      case MiscVar_Subject:
+      case MiscVar_Quote:
+      case MiscVar_Quote822:
+      case MiscVar_Text:
+      case MiscVar_Sender:
          return ExpandOriginal(name, value);
 
+      case MiscVar_Signature:
+         *value = GetSignature();
+         break;
+
       default:
          // unknown name
@@ -1078,4 +1096,118 @@
 
    return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// ExpandMisc("signature") helper
+// ----------------------------------------------------------------------------
+
+String VarExpander::GetSignature() const
+{
+   String signature;
+
+   // first check if we want to insert it at all: this setting overrides the
+   // $signature in the template because the latter is there by default and
+   // it's simpler (especially for a novice user who might not know about the
+   // templates at all) to just uncheck the checkbox "Use signature" in the
+   // options dialog instead of editing all templates
+   if ( READ_CONFIG(m_profile, MP_COMPOSE_USE_SIGNATURE) )
+   {
+      wxTextFile fileSig;
+
+      // loop until we have a valid file to read the signature from
+      bool hasSign = false;
+      while ( !hasSign )
+      {
+         String strSignFile = READ_CONFIG(m_profile, MP_COMPOSE_SIGNATURE);
+         if ( !strSignFile.empty() )
+            hasSign = fileSig.Open(strSignFile);
+
+         if ( !hasSign )
+         {
+            // no signature at all or sig file not found, propose to choose or
+            // change it now
+            wxString msg;
+            if ( strSignFile.empty() )
+            {
+               msg = _("You haven't configured your signature file.");
+            }
+            else
+            {
+               // to show message from wxTextFile::Open()
+               wxLog *log = wxLog::GetActiveTarget();
+               if ( log )
+                  log->Flush();
+
+               msg.Printf(_("Signature file '%s' couldn't be opened."),
+                          strSignFile.c_str());
+            }
+
+            msg += _("\n\nWould you like to choose your signature "
+                     "right now (otherwise no signature will be used)?");
+            if ( MDialog_YesNoDialog(msg, m_cv.GetFrame(), MDIALOG_YESNOTITLE,
+                                     true, "AskForSig") )
+            {
+               strSignFile = wxPFileSelector("sig",
+                                             _("Choose signature file"),
+                                             NULL, ".signature", NULL,
+                                             _(wxALL_FILES),
+                                             0, m_cv.GetFrame());
+            }
+            else
+            {
+               // user doesn't want to use signature file
+               break;
+            }
+
+            if ( strSignFile.empty() )
+            {
+               // user canceled "choose signature" dialog
+               break;
+            }
+
+            m_profile->writeEntry(MP_COMPOSE_SIGNATURE, strSignFile);
+         }
+      }
+
+      if ( hasSign )
+      {
+         // the signature must be on its own line(s)
+         signature = '\n';
+
+         // insert separator optionally
+         if ( READ_CONFIG(m_profile, MP_COMPOSE_USE_SIGNATURE_SEPARATOR) )
+         {
+            signature += "--\n";
+         }
+
+         // read the whole file
+         size_t nLineCount = fileSig.GetLineCount();
+         for ( size_t nLine = 0; nLine < nLineCount; nLine++ )
+         {
+            signature << fileSig[nLine] << '\n';
+         }
+
+         // let's respect the netiquette
+         static const size_t nMaxSigLines = 4;
+         if ( nLineCount > nMaxSigLines )
+         {
+            wxString msg;
+            msg.Printf(_("Your signature is %stoo long: it should "
+                         "not be more than %d lines."),
+                       nLineCount > 10 ? _("way ") : "", nMaxSigLines);
+            MDialog_Message(msg, m_cv.GetFrame(),
+                            _("Signature is too long"),
+                            GetPersMsgBoxName(M_MSGBOX_SIGNATURE_LENGTH));
+
+         }
+      }
+      else
+      {
+         // don't ask the next time
+         m_profile->writeEntry(MP_COMPOSE_USE_SIGNATURE, false);
+      }
+   }
+
+   return signature;
 }
 

Index: MessageTemplate.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MessageTemplate.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -b -u -2 -r1.24 -r1.25
--- MessageTemplate.cpp 17 Dec 2001 14:46:19 -0000      1.24
+++ MessageTemplate.cpp 4 Mar 2002 18:24:35 -0000       1.25
@@ -548,5 +548,5 @@
 
    String value = config->Read(GetTemplateValuePath(kind, name), "");
-   if ( !value )
+   if ( value.empty() )
    {
       // we have the default templates for reply, follow-up and forward
@@ -580,7 +580,10 @@
          case MessageTemplate_NewMessage:
          case MessageTemplate_NewArticle:
-            // nothing to do, but put it here to silence gcc warnings
-            ;
+            // put the cursor before the signature
+            value = "$CURSOR";
       }
+
+      // all default templates include the signature
+      value += "$SIGNATURE";
    }
 


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

Reply via email to