SF.net SVN: mahogany:[7531] trunk/M/src/gui/wxComposeView.cpp

[email protected] Thu, 07 Aug 2008 20:04:53 +0000
Newsgroups gmane.mail.mahogany.cvs
Message-ID <[email protected]>
Revision: 7531
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7531&view=rev
Author:   vadz
Date:     2008-08-07 20:04:52 +0000 (Thu, 07 Aug 2008)

Log Message:
-----------
improvements to error handling during autosave

Modified Paths:
--------------
    trunk/M/src/gui/wxComposeView.cpp

Modified: trunk/M/src/gui/wxComposeView.cpp
===================================================================
--- trunk/M/src/gui/wxComposeView.cpp	2008-08-07 18:57:53 UTC (rev 7530)
+++ trunk/M/src/gui/wxComposeView.cpp	2008-08-07 20:04:52 UTC (rev 7531)
@@ -1986,6 +1986,8 @@
       }
    }
 
+   // clean up the autosave file: if m_filenameAutoSave is set we must have it,
+   // otherwise AutoSave() wouldn't have initialized it
    if ( !m_filenameAutoSave.empty() )
    {
       if ( !wxRemoveFile(m_filenameAutoSave) )
@@ -5388,6 +5390,12 @@
 bool
 wxComposeView::AutoSave()
 {
+   // we disable autosave if we don't have a directory to save files to
+   static bool s_autosaveEnabled = true;
+
+   if ( !s_autosaveEnabled )
+      return true;
+
    if ( !m_editor )
       return true;
 
@@ -5401,7 +5409,8 @@
    if ( !msg )
       return false;
 
-   if ( m_filenameAutoSave.empty() )
+   String fname = m_filenameAutoSave;  // reuse the last file name
+   if ( fname.empty() )                // but initialize if it's the first time
    {
       // make sure the directory we use for these scratch files exists
       String name = GetComposerAutosaveDir();
@@ -5411,6 +5420,14 @@
          {
             wxLogSysError(_("Failed to create the directory '%s' for the "
                             "temporary composer files"), name.c_str());
+
+            wxLogError(_("Composer messages won't be saved automatically "
+                         "for the duration of this session.\n"
+                         "Please make sure that Mahogany can create the "
+                         "directory \"%s\" and restart the program."),
+                       name.c_str());
+            s_autosaveEnabled = false;
+
             return false;
          }
       }
@@ -5418,7 +5435,7 @@
       // we need a unique file name during the life time of this object as this
       // file is always going to be deleted if we're destroyed correctly, it
       // can only be left if the program crashes
-      m_filenameAutoSave = name + String::Format(_T("%05d%p"), (int)getpid(), this);
+      fname = name + String::Format(_T("%05d%p"), (int)getpid(), this);
    }
 
    String contents;
@@ -5430,15 +5447,26 @@
       return false;
    }
 
-   if ( !MailFolder::SaveMessageAsMBOX(m_filenameAutoSave, contents) )
+   if ( !MailFolder::SaveMessageAsMBOX(fname, contents) )
    {
-      // TODO: disable autosaving? we risk to give many such messages if
-      //       something is wrong...
-      wxLogError(_("Failed to automatically save the message."));
+      // don't make this a wxLogError() as it would result in a message box
+      // which is a wrong thing to do for a background operation
+      wxLogStatus(_("Failed to automatically save the message."));
 
+      // if we did manage to create the file, leave it even if saving failed,
+      // it might still contain something useful for recovery
+      if ( wxFileName::FileExists(fname) )
+         m_filenameAutoSave = fname;
+
       return false;
    }
 
+   if ( m_filenameAutoSave.empty() )
+   {
+      // remember the file name for the subsequent calls of this function
+      m_filenameAutoSave = fname;
+   }
+
    // mark the editor as not modified to avoid resaving it the next time
    // unnecessary but remember internally that it was modified (we didn't
    // really save it)


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=/