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

Modified Files:
        MApplication.cpp Moptions.cpp 
Log Message:
implemented "alweays run only one instance" option and the remote control:
launching Mahogany will simply pass control and the command line options to
the previous instance, if any (and if this option is on)


Index: MApplication.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MApplication.cpp,v
retrieving revision 1.246
retrieving revision 1.247
diff -b -u -2 -r1.246 -r1.247
--- MApplication.cpp    11 Apr 2002 23:15:49 -0000      1.246
+++ MApplication.cpp    13 Apr 2002 23:34:31 -0000      1.247
@@ -85,4 +85,5 @@
 extern const MOption MP_OUTBOX_NAME;
 extern const MOption MP_REOPENLASTFOLDER;
+extern const MOption MP_RUNONEONLY;
 extern const MOption MP_SHOWADBEDITOR;
 extern const MOption MP_SHOWLOG;
@@ -173,4 +174,49 @@
 }
 
+bool
+MAppBase::ProcessSendCmdLineOptions(const CmdLineOptions& cmdLineOpts)
+{
+   Composer *composer;
+   if ( !cmdLineOpts.composer.to.empty() )
+   {
+      composer = Composer::CreateNewMessage();
+   }
+   else if ( !cmdLineOpts.composer.newsgroups.empty() )
+   {
+      composer = Composer::CreateNewArticle();
+   }
+   else
+   {
+      composer = NULL;
+   }
+
+   if ( composer )
+   {
+      composer->AddRecipients(cmdLineOpts.composer.bcc,
+                              Composer::Recipient_Bcc);
+      composer->AddRecipients(cmdLineOpts.composer.cc,
+                              Composer::Recipient_Cc);
+      composer->AddRecipients(cmdLineOpts.composer.newsgroups,
+                              Composer::Recipient_Newsgroup);
+
+      // the "to" parameter may be a mailto: URL, pass it through our expansion
+      // function first
+      String to = cmdLineOpts.composer.to;
+      composer->ExpandRecipient(&to);
+
+      composer->AddRecipients(to, Composer::Recipient_To);
+
+      composer->SetSubject(cmdLineOpts.composer.subject);
+
+      composer->InsertText(cmdLineOpts.composer.body);
+      composer->ResetDirty();
+
+      // the composer should be in front of everything
+      composer->GetFrame()->Raise();
+   }
+
+   return composer != NULL;
+}
+
 void
 MAppBase::ContinueStartup()
@@ -282,42 +328,5 @@
    // ----------------------------------------------
 
-   Composer *composer;
-   if ( !m_cmdLineOptions->composer.to.empty() )
-   {
-      composer = Composer::CreateNewMessage();
-   }
-   else if ( !m_cmdLineOptions->composer.newsgroups.empty() )
-   {
-      composer = Composer::CreateNewArticle();
-   }
-   else
-   {
-      composer = NULL;
-   }
-
-   if ( composer )
-   {
-      composer->AddRecipients(m_cmdLineOptions->composer.bcc,
-                              Composer::Recipient_Bcc);
-      composer->AddRecipients(m_cmdLineOptions->composer.cc,
-                              Composer::Recipient_Cc);
-      composer->AddRecipients(m_cmdLineOptions->composer.newsgroups,
-                              Composer::Recipient_Newsgroup);
-
-      // the "to" parameter may be a mailto: URL, pass it through our expansion
-      // function first
-      String to = m_cmdLineOptions->composer.to;
-      composer->ExpandRecipient(&to);
-
-      composer->AddRecipients(to, Composer::Recipient_To);
-
-      composer->SetSubject(m_cmdLineOptions->composer.subject);
-
-      composer->InsertText(m_cmdLineOptions->composer.body);
-      composer->ResetDirty();
-
-      // the composer should be in front of everything
-      composer->GetFrame()->Raise();
-   }
+   ProcessSendCmdLineOptions(*m_cmdLineOptions);
 }
 
@@ -347,4 +356,37 @@
 #endif // DEBUG
 
+   // safe mode disables remote calls
+   if ( !m_cmdLineOptions->safe )
+   {
+      // before doing anything else, if the corresponding option is set, check
+      // if another program instance is not already running
+      if ( READ_APPCONFIG_BOOL(MP_RUNONEONLY) )
+      {
+         if ( IsAnotherRunning() )
+         {
+            // try to defer to it
+            if ( CallAnother() )
+            {
+               // succeeded, nothing more to do in this process
+
+               // set the error to indicate that our false return code wasn't, in
+               // fact, an error
+               SetLastError(M_ERROR_CANCEL);
+
+               return false;
+            }
+         }
+
+         // set up a server to listen for the remote calls
+         if ( !SetupRemoteCallServer() )
+         {
+            wxLogError(_("Communication between different Mahogany processes "
+                         "won't work, please disable the \"Always run only "
+                         "one instance\" option if you don't use it to avoid "
+                         "this error message in the future."));
+         }
+      }
+   }
+
    // NB: although this shouldn't normally be here (it's GUI-dependent code),
    //     it's really impossible to put it into wxMApp because some dialogs
@@ -544,6 +586,10 @@
 MAppBase::OnShutDown()
 {
+   bool initialized = m_cycle != Initializing;
+
    m_cycle = ShuttingDown;
 
+   if ( initialized )
+   {
    // do we need to save the away mode state?
    if ( READ_APPCONFIG(MP_AWAY_REMEMBER) )
@@ -579,4 +625,5 @@
    AdbManager::Delete();
    Profile::FlushAll();
+   }
 
    // The following little hack allows us to decref and delete the
@@ -587,4 +634,6 @@
    p->DecRef();
 
+   if ( initialized )
+   {
    // misc cleanup
    delete m_mimeManager;
@@ -611,4 +660,5 @@
    FreePythonDll();
 #endif // USE_PYTHON_DYNAMIC
+   }
 }
 

Index: Moptions.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/Moptions.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -b -u -2 -r1.39 -r1.40
--- Moptions.cpp        18 Mar 2002 14:20:06 -0000      1.39
+++ Moptions.cpp        13 Apr 2002 23:34:31 -0000      1.40
@@ -118,4 +118,5 @@
 
 const MOption MP_GLOBALDIR;
+const MOption MP_RUNONEONLY;
 
 #ifdef OS_UNIX
@@ -501,4 +502,5 @@
 
     DEFINE_OPTION(MP_GLOBALDIR),
+    DEFINE_OPTION(MP_RUNONEONLY),
 
 #ifdef OS_UNIX


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

Reply via email to