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

Modified Files:
        wxMainFrame.cpp 
Log Message:
close all opened folders when the machine is suspended and reopen them on resume

Index: wxMainFrame.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/gui/wxMainFrame.cpp,v
retrieving revision 1.194
retrieving revision 1.195
diff -b -u -2 -r1.194 -r1.195
--- wxMainFrame.cpp     16 Jan 2006 20:32:27 -0000      1.194
+++ wxMainFrame.cpp     27 May 2006 16:27:12 -0000      1.195
@@ -550,4 +550,11 @@
 
    EVT_CHOICE(IDC_IDENT_COMBO, wxMainFrame::OnIdentChange)
+
+#ifdef wxHAS_POWER_EVENTS
+   EVT_POWER_SUSPENDING(wxMainFrame::OnPowerSuspending)
+   EVT_POWER_SUSPENDED(wxMainFrame::OnPowerSuspended)
+   EVT_POWER_SUSPEND_CANCEL(wxMainFrame::OnPowerSuspendCancel)
+   EVT_POWER_RESUME(wxMainFrame::OnPowerResume)
+#endif // wxHAS_POWER_EVENTS
 END_EVENT_TABLE()
 
@@ -567,4 +574,7 @@
    m_FolderTree = NULL;
    m_FolderView = NULL;
+#ifdef wxHAS_POWER_EVENTS
+   m_foldersToReopen = NULL;
+#endif // wxHAS_POWER_EVENTS
 
    // set frame icon/title, create status bar
@@ -1072,4 +1082,90 @@
 }
 
+// ----------------------------------------------------------------------------
+// power events
+// ----------------------------------------------------------------------------
+
+#ifdef wxHAS_POWER_EVENTS
+
+void wxMainFrame::OnPowerSuspending(wxPowerEvent& event)
+{
+   ASSERT_MSG( !m_foldersToReopen, _T("didn't resume from last suspend?") );
+
+   m_folderToReopenHere = m_folderName;
+   m_foldersToReopen = new MFolderList;
+   int nClosed = MailFolder::CloseAll(m_foldersToReopen);
+   if ( nClosed < 0 )
+   {
+      DoResume();
+
+      wxLogError(_("The system cannot be suspended because some folders "
+                   "are still opened."));
+      event.Veto();
+   }
+   else if ( nClosed )
+   {
+      wxLogStatus(_("Closed %lu folders which will be reopened on resume."),
+                  (unsigned long)m_foldersToReopen->size());
+   }
+   else // no open folders
+   {
+      delete m_foldersToReopen;
+      m_foldersToReopen = NULL;
+   }
+}
+
+void wxMainFrame::OnPowerSuspended(wxPowerEvent& WXUNUSED(event))
+{
+   // save all options
+   Profile::FlushAll();
+}
+
+void wxMainFrame::DoResume()
+{
+   if ( m_foldersToReopen )
+   {
+      wxLogStatus(_("Reopening %lu folders"),
+                  (unsigned long)m_foldersToReopen->size());
+
+      for ( MFolderList::iterator i = m_foldersToReopen->begin();
+            i != m_foldersToReopen->end();
+            ++i )
+      {
+         MFolder *folder = *i;
+         if ( folder->GetFullName() == m_folderToReopenHere )
+         {
+            OpenFolder(folder);
+         }
+         else // a folder opened elsewhere
+         {
+            // only reopen it this folder should be permanently opened,
+            // otherwise it will be reopened from the folder view which uses it
+            if ( folder->GetFlags() & MF_FLAGS_KEEPOPEN )
+            {
+               MailFolder *mf = MailFolder::OpenFolder(folder);
+               if ( !mf )
+               {
+                  ERRORMESSAGE((_("Failed to reopen folder \"%s\""),
+                                folder->GetFullName().c_str()));
+               }
+               else
+               {
+                  // it won't be really closed but will be kept open in the
+                  // background
+                  mf->DecRef();
+               }
+            }
+         }
+      }
+
+      delete m_foldersToReopen;
+      m_foldersToReopen = NULL;
+
+      m_folderToReopenHere.clear();
+   }
+}
+
+#endif // wxHAS_POWER_EVENTS
+
 void wxMainFrame::DoFolderSearch()
 {



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to