SF.net SVN: mahogany:[7518] trunk/M

[email protected] Tue, 05 Aug 2008 22:48:58 +0000
Newsgroups gmane.mail.mahogany.cvs
Message-ID <[email protected]>
Revision: 7518
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7518&view=rev
Author:   vadz
Date:     2008-08-05 22:48:57 +0000 (Tue, 05 Aug 2008)

Log Message:
-----------
ask the user for the location of PGP command if it's not configured or not found

Modified Paths:
--------------
    trunk/M/include/MpersIds.h
    trunk/M/src/classes/Mpers.cpp
    trunk/M/src/classes/PGPClickInfo.cpp
    trunk/M/src/modules/crypt/PGPEngine.cpp

Modified: trunk/M/include/MpersIds.h
===================================================================
--- trunk/M/include/MpersIds.h	2008-08-05 22:47:59 UTC (rev 7517)
+++ trunk/M/include/MpersIds.h	2008-08-05 22:48:57 UTC (rev 7518)
@@ -110,6 +110,7 @@
 DECL_OR_DEF(ZAP_SPAM);
 
 DECL_OR_DEF(REMEMBER_PGP_PASSPHRASE);
+DECL_OR_DEF(CONFIGURE_PGP_PATH);
 
 DECL_OR_DEF(SEARCH_AGAIN_IF_NO_MATCH);
 

Modified: trunk/M/src/classes/Mpers.cpp
===================================================================
--- trunk/M/src/classes/Mpers.cpp	2008-08-05 22:47:59 UTC (rev 7517)
+++ trunk/M/src/classes/Mpers.cpp	2008-08-05 22:48:57 UTC (rev 7518)
@@ -158,6 +158,7 @@
    { "ConfirmZap",               gettext_noop("confirm permanently deleting messages") },
    { "ZapSpam",                  gettext_noop("permanently delete message after marking them as spam") },
    { "RememberPGPPassphrase",    gettext_noop("remember PGP/GPG passphrase in memory") },
+   { "ConfigurePGPPath",         gettext_noop("specify PGP/GPG location if the program was not found") },
    { "SearchAgainIfNoMatch",     gettext_noop("propose to search again if no matches were found") },
    { "UseCreateFolderWizard",    gettext_noop("use wizard when creating a new folder") },
    { "FormatParagraphBeforeExit",gettext_noop("format all paragraphs in composer before exit") },

Modified: trunk/M/src/classes/PGPClickInfo.cpp
===================================================================
--- trunk/M/src/classes/PGPClickInfo.cpp	2008-08-05 22:47:59 UTC (rev 7517)
+++ trunk/M/src/classes/PGPClickInfo.cpp	2008-08-05 22:48:57 UTC (rev 7518)
@@ -142,11 +142,12 @@
          break;
 
       case MCryptoEngine::OPERATION_CANCELED_BY_USER:
+      case MCryptoEngine::CANNOT_EXEC_PROGRAM:
          pgpInfo = new PGPSignatureInfo
                        (
                         msgView,
                         _("Unverified PGP signature"),
-                        _T("pgpsig_bad"),
+                        "pgpsig_bad",
                         *wxLIGHT_GREY
                        );
          break;

Modified: trunk/M/src/modules/crypt/PGPEngine.cpp
===================================================================
--- trunk/M/src/modules/crypt/PGPEngine.cpp	2008-08-05 22:47:59 UTC (rev 7517)
+++ trunk/M/src/modules/crypt/PGPEngine.cpp	2008-08-05 22:48:57 UTC (rev 7518)
@@ -50,6 +50,7 @@
 // ----------------------------------------------------------------------------
 
 extern const MPersMsgBox *M_MSGBOX_REMEMBER_PGP_PASSPHRASE;
+extern const MPersMsgBox *M_MSGBOX_CONFIGURE_PGP_PATH;
 
 // ----------------------------------------------------------------------------
 // miscellaneous helper functions
@@ -216,41 +217,82 @@
                        String& messageOut,
                        MCryptoEngineOutputLog *log)
 {
+   PGPProcess process;
+   long pid = 0;
+
    // check if we have a PGP command: it can be set to nothing to disable pgp
    // support
-   const String pgp = READ_APPCONFIG_TEXT(MP_PGP_COMMAND);
-   if ( pgp.empty() )
+   String pgp = READ_APPCONFIG_TEXT(MP_PGP_COMMAND);
+   bool pgpChanged = false;
+
+   while ( !pid )
    {
-      if ( log )
+      if ( !pgp.empty() )
       {
-         log->AddMessage(_("PGP command not configured, set its value in "
-                           "the \"Helpers\" page of the preferences dialog "
-                           "to enable PGP support"));
+         const String
+            command = wxString::Format
+                      (
+                       _T("%s --status-fd=2 --command-fd 0 --output - -a %s"),
+                       pgp.c_str(),
+                       options.c_str()
+                      );
+
+         if ( log )
+            log->AddMessage(String::Format(_("Executing \"%s\""), command.c_str()));
+
+         pid = wxExecute(command, wxEXEC_ASYNC, &process);
       }
 
-      return OPERATION_CANCELED_BY_USER;
-   }
+      if ( pid )
+         break;
 
-   PGPProcess process;
-   String command = wxString::Format
-               (
-                _T("%s --status-fd=2 --command-fd 0 --output - -a %s"),
-                pgp.c_str(),
-                options.c_str()
-               );
+      wxString msg;
+      if ( pgp.empty() )
+      {
+         msg = _("PGP/GPG program location is not configured.");
+      }
+      else // have command but executing it failed
+      {
+         msg = String::Format(_("Failed to execute \"%s\"."), pgp.c_str());
+      }
 
-#ifdef DEBUG
-   if ( log )
-      log->AddMessage(command);
-#endif
+      msg += "\n";
+      msg += _("If you have PGP/GPG installed on this system, would you "
+               "like to specify its location now?"
+               "\n"
+               "If you don't, the current operation will be cancelled.");
 
-   long pid = wxExecute(command, wxEXEC_ASYNC, &process);
+      wxWindow * const parent = log ? log->GetParent() : NULL;
+      if ( !MDialog_YesNoDialog
+            (
+               msg,
+               parent,
+               MDIALOG_YESNOTITLE,
+               M_DLG_YES_DEFAULT,
+               M_MSGBOX_CONFIGURE_PGP_PATH
+            ) )
+      {
+         return CANNOT_EXEC_PROGRAM;
+      }
 
-   if ( !pid )
-   {
-      return CANNOT_EXEC_PROGRAM;
+      pgp = MDialog_FileRequester(_("Please choose PGP/GPG program"), parent);
+      if ( pgp.empty() )
+      {
+         // cancelled by user
+         return CANNOT_EXEC_PROGRAM;
+      }
+
+      pgpChanged = true;
    }
 
+   // if we get here, we managed to launch the PGP subprocess successfully
+
+   // if we had to change the PGP path in order to do it, remember the value
+   // that worked for us
+   if ( pgpChanged )
+      mApplication->GetProfile()->writeEntry(MP_PGP_COMMAND, pgp);
+
+
    wxOutputStream *in = process.GetOutputStream();
    wxInputStream *out = process.GetInputStream(),
                  *err = process.GetErrorStream();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/