Update of /cvsroot/mahogany/M/src/classes
In directory usw-pr-cvs1:/tmp/cvs-serv20231/src/classes
Modified Files:
MApplication.cpp Profile.cpp
Log Message:
added a few useful command line options
Index: MApplication.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/MApplication.cpp,v
retrieving revision 1.243
retrieving revision 1.244
diff -b -u -2 -r1.243 -r1.244
--- MApplication.cpp 18 Mar 2002 22:42:13 -0000 1.243
+++ MApplication.cpp 29 Mar 2002 20:42:22 -0000 1.244
@@ -31,10 +31,7 @@
# include <wx/dynarray.h>
-# include <wx/dir.h>
# include <wx/file.h>
#endif // USE_PCH
-#include <errno.h>
-
#include "MPython.h"
@@ -61,4 +58,6 @@
#include "MFCache.h" // for MfStatusCache::CleanUp
+#include "CmdLineOpts.h"
+
#include <wx/confbase.h> // wxExpandEnvVars
#include <wx/mimetype.h> // wxMimeTypesManager
@@ -68,10 +67,4 @@
#include "wx/persctrl.h" // for wxPControls::SetSettingsPath
-#ifdef OS_UNIX
-# include <unistd.h>
-# include <sys/stat.h>
-# include <fcntl.h>
-#endif //Unix
-
// ----------------------------------------------------------------------------
// options we use here
@@ -121,20 +114,4 @@
// ----------------------------------------------------------------------------
-// constants
-// ----------------------------------------------------------------------------
-
-// VZ: Karsten, if this is really not used any more, please remove all code
-// inside USE_ICON_SUBDIRS
-#ifdef USE_ICON_SUBDIRS
-
-// to map icon subdirs to numbers
-static const char *gs_IconSubDirs[] =
-{
- "default", "GNOME", "KDE", "small"
-};
-
-#endif // USE_ICON_SUBDIRS
-
-// ----------------------------------------------------------------------------
// private types
// ----------------------------------------------------------------------------
@@ -182,4 +159,6 @@
m_autoAwayOn = FALSE;
+ m_cmdLineOptions = new CmdLineOptions;
+
mApplication = this;
@@ -194,162 +173,161 @@
}
-bool
-MAppBase::OnStartup()
+void
+MAppBase::ContinueStartup()
{
- // initialise the profile(s)
- // -------------------------
+ // open all windows we open initially
+ // ----------------------------------
- // TODO: all this should probably go into some static Profile function
- // or at least a separate MAppBase method!
+ // open any interrupted composer windows we may have
+ Composer::RestoreAll();
- String strConfFile;
-#ifdef OS_UNIX
- strConfFile = wxGetHomeDir();
- if ( strConfFile.empty() )
- {
- // don't create our files in the root directory, try the current one
- // instead
- strConfFile = wxGetCwd();
- }
+ // open the remembered folder in the main frame unless disabled: note that
+ // specifying a folder on the command line still overrides this
+ String foldername = m_cmdLineOptions->folder;
- if ( !strConfFile.empty() )
+ // if an empty folder was explicitly given, don't open anything
+ if ( foldername.empty() && !m_cmdLineOptions->useFolder )
+ {
+ if ( !READ_APPCONFIG(MP_DONTOPENSTARTUP) )
{
- strConfFile << '/';
+ foldername = READ_APPCONFIG_TEXT(MP_MAINFOLDER);
+ }
}
- //else: it will be in the current one, what else can we do?
-
- strConfFile << "/." << M_APPLICATIONNAME;
- if ( !wxDir::Exists(strConfFile) )
+ if ( !foldername.empty() )
{
- if ( !wxMkdir(strConfFile, 0700) )
+ MFolder *folder = MFolder::Get(foldername);
+ if ( folder )
{
- wxLogError(_("Cannot create the directory for configuration "
- "files '%s'."), strConfFile.c_str());
-
- return FALSE;
+ // make sure it doesn't go away after OpenFolder()
+ folder->IncRef();
+ ((wxMainFrame *)m_topLevelFrame)->OpenFolder(folder);
+ folder->DecRef();
}
- else
+ else // invalid folder name
{
- wxLogInfo(_("Created directory '%s' for configuration files."),
- strConfFile.c_str());
+ wxLogWarning(_("Failed to open folder '%s' in the main window."),
+ foldername.c_str());
+ }
}
- // also create an empty config file with the right permissions:
- String filename = strConfFile + "/config";
+ // update status of outbox once:
+ UpdateOutboxStatus();
- // pass false to Create() to avoid overwriting the existing file
- wxFile file;
- if ( !file.Create(filename, false, wxS_IRUSR | wxS_IWUSR) &&
- !wxFile::Exists(filename) )
+ // open all default mailboxes
+ // --------------------------
+
+ if ( !READ_APPCONFIG(MP_DONTOPENSTARTUP) )
{
- wxLogError(_("Could not create initial configuration file."));
- }
- }
+ char *folders = strutil_strdup(READ_APPCONFIG(MP_OPENFOLDERS));
+ kbStringList openFoldersList;
+ strutil_tokenise(folders,";",openFoldersList);
+ delete [] folders;
- // Check whether other users can write our config dir.
- //
- // This must not be allowed as they could change the behaviour of the
- // program unknowingly to the user!
- struct stat st;
- if ( stat(strConfFile, &st) == 0 )
- {
- if ( st.st_mode & (S_IWGRP | S_IWOTH) )
- {
- // No other user must have write access to the config dir.
- String msg;
- msg.Printf(_("Configuration directory '%s' was writable for other users.\n"
- "The programs settings might have been changed without "
- "your knowledge and the passwords stored in your config\n"
- "file (if any) could have been compromised!\n\n"),
- strConfFile.c_str());
+ bool ok = true;
- if ( chmod(strConfFile, st.st_mode & ~(S_IWGRP | S_IWOTH)) == 0 )
+ kbStringList::iterator i;
+ for(i = openFoldersList.begin(); i != openFoldersList.end(); i++)
{
- msg += _("This has been fixed now, the directory is no longer writable
for others.");
- }
- else
+ String *name = *i;
+
+ if ( name->empty() )
{
- msg << String::Format(_("Failed to correct the directory access (%s)"
- "rights, please do it manually and "
- "restart the program!"),
- strerror(errno));
+ FAIL_MSG( "empty folder name in the list of folders to open?" );
+ continue;
}
- wxLogError(msg);
+ MFolder_obj folder(*name);
+ if ( folder.IsOk() )
+ {
+ if ( !OpenFolderViewFrame(folder, m_topLevelFrame) )
+ {
+ // error message must be already given by OpenFolderViewFrame
+ ok = false;
}
}
else
{
- wxLogSysError(_("Failed to access the directory '%s' containing "
- "the configuration files."),
- strConfFile.c_str());
+ wxLogWarning(_("Failed to reopen folder '%s', it doesn't seem "
+ "to exist any more."), name->c_str());
+
+ ok = false;
+ }
}
- strConfFile += "/config";
-#else // Windows
- // no such concerns here, just use the registry
- strConfFile = M_APPLICATIONNAME;
-#endif // Win/Unix
+ if ( !ok )
+ {
+ wxLogWarning(_("Not all folders could be reopened."));
+ }
+ }
- m_profile = Profile::CreateGlobalConfig(strConfFile);
+ // initialise collector object for incoming mails
+ // ----------------------------------------------
- // disable the use of environment variables if configured like this (this
- // speeds up things relatively significantly under Windows - and as few
- // people use evironment variables there, it is disabled for Windows by
- // default)
- m_profile->SetExpandEnvVars(READ_CONFIG_BOOL(m_profile, MP_EXPAND_ENV_VARS));
+ // TODO: only do it if we are using the NewMail folder at all?
+ m_FolderMonitor = FolderMonitor::Create();
-#ifdef OS_UNIX
- // Check whether other users can read our config file.
- //
- // This must not be allowed as we store passwords in it!
- if ( stat(strConfFile, &st) == 0 )
- {
- if ( st.st_mode & (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH) )
- {
- // No other user must have access to the config file.
- String msg;
- if ( st.st_mode & (S_IWGRP | S_IWOTH) )
- {
- msg.Printf(_("Configuration file %s was writable by other users.\n"
- "The program settings could have been changed without\n"
- "your knowledge, please consider reinstalling the "
- "program!"),
- strConfFile.c_str());
- }
+ // also start the mail auto collection timer
+ StartTimer(MAppBase::Timer_PollIncoming);
- if ( st.st_mode & (S_IRGRP | S_IROTH) )
- {
- if ( !msg.empty() )
- msg += "\n\n";
+ // show the ADB editor if it had been shown the last time when we ran
+ // ------------------------------------------------------------------
- msg += String::Format
- (
- _("Configuration file '%s' was readable for other users.\n"
- "Passwords may have been compromised, please "
- "consider changing them!"),
- strConfFile.c_str()
- );
+ if ( READ_APPCONFIG(MP_SHOWADBEDITOR) )
+ {
+ ShowAdbFrame(TopLevelFrame());
}
- msg += "\n\n";
+ // open the composer if requested on command line
+ // ----------------------------------------------
- if ( chmod(strConfFile, S_IRUSR | S_IWUSR) == 0 )
+ Composer *composer;
+ if ( !m_cmdLineOptions->composer.to.empty() )
{
- msg += _("This has been fixed now, the file is no longer readable for
others.");
+ composer = Composer::CreateNewMessage();
+ }
+ else if ( !m_cmdLineOptions->composer.newsgroups.empty() )
+ {
+ composer = Composer::CreateNewArticle();
}
else
{
- msg << String::Format(_("The attempt to make the file unreadable "
- "for others has failed: %s"),
- strerror(errno));
+ composer = NULL;
}
- wxLogError(msg);
- }
+ 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);
+ composer->AddRecipients(m_cmdLineOptions->composer.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();
}
- //else: not an error, file may be simply not there yet
-#endif // OS_UNIX
+}
+
+bool
+MAppBase::OnStartup()
+{
+ // initialise the profile(s)
+ // -------------------------
+
+ m_profile = Profile::CreateGlobalConfig(m_cmdLineOptions->configFile);
+
+ // disable the use of environment variables if configured like this (this
+ // speeds up things relatively significantly under Windows - and as few
+ // people use evironment variables there, it is disabled for Windows by
+ // default)
+ m_profile->SetExpandEnvVars(READ_CONFIG_BOOL(m_profile, MP_EXPAND_ENV_VARS));
#ifdef DEBUG
@@ -406,28 +384,25 @@
InitDirectories();
-#ifdef USE_ICON_SUBDIRS
- // KB: we no longer use different subdirs:
- // We need to set this before wxWindows has a chance to process
- // idle events (splash screen), in case there was any problem with
- // the config file, or it will show the unknown icon.
- {
- unsigned long idx = (unsigned long) READ_APPCONFIG(MP_ICONSTYLE);
- if(idx < sizeof gs_IconSubDirs)
- GetIconManager()->SetSubDirectory(gs_IconSubDirs[idx]);
- }
-#endif // USE_ICON_SUBDIRS
-
- // do it first to avoid any interactive stuff from popping up if configured
- // to start up in the unattended mode
+ // safe mode implies interactive
+ if ( !m_cmdLineOptions->safe )
+ {
+ // do it first to avoid any interactive stuff from popping up if
+ // configured to start up in the unattended mode
SetAwayMode(READ_APPCONFIG_BOOL(MP_AWAY_STATUS));
+ }
// show the splash screen (do it as soon as we have profile to read
// MP_SHOWSPLASH from) unless this is our first run in which case it will
- // disappear any how - not showing it avoids some ugly flicker on screen
+ // disappear anyhow - not showing it avoids some ugly flicker on screen
if ( !READ_APPCONFIG(MP_FIRSTRUN) && READ_APPCONFIG(MP_SHOWSPLASH) )
{
+ // don't show splash in safe mode as it might be a source of the problems
+ // as well
+ if ( !m_cmdLineOptions->safe )
+ {
// no parent because no frames created yet
MDialog_AboutDialog(NULL);
}
+ }
// verify (and upgrade if needed) our settings
@@ -441,15 +416,4 @@
}
-#ifdef OS_WIN
- // cclient extra initialization under Windows
- wxString strHome;
- mail_parameters((MAILSTREAM *)NULL, SET_HOMEDIR, (void *)wxGetHomeDir(&strHome));
-#endif // OS_WIN
-
-#ifdef USE_DIALUP
- // must be done before using the network
- SetupOnlineManager();
-#endif // USE_DIALUP
-
// extend path for commands, look in M's dirs first
String pathEnv;
@@ -488,8 +452,12 @@
#endif //USE_PYTHON
+ // the modules can contain bugs, don't load in safe mode
+ if ( !m_cmdLineOptions->safe )
+ {
// load any modules requested: notice that this must be done as soon as
// possible as filters module is already used by the folder opening code
// below
LoadModules();
+ }
// create and show the main program window
@@ -505,4 +473,7 @@
{
ShowLog();
+
+ // we want the main window to be above the log frame
+ m_topLevelFrame->Raise();
}
@@ -514,8 +485,4 @@
m_cycle = Running;
- // and as we have the main window, we can initialize the modules which
- // use it
- InitModules();
-
// register with the event subsystem
// ---------------------------------
@@ -531,101 +498,26 @@
"failed to register event handler for folder status event " );
- // open all windows we open initially
+ // finish non critical initialization
// ----------------------------------
- // open any composer windows we may have
- Composer::RestoreAll();
-
- // open the remembered folder in the main frame unless disabled
- if ( !READ_APPCONFIG(MP_DONTOPENSTARTUP) )
- {
- String foldername = READ_APPCONFIG(MP_MAINFOLDER);
- if ( !foldername.empty() )
- {
- MFolder *folder = MFolder::Get(foldername);
- if ( folder )
- {
- // make sure it doesn't go away after OpenFolder()
- folder->IncRef();
- ((wxMainFrame *)m_topLevelFrame)->OpenFolder(folder);
- folder->DecRef();
- }
- else // huh?
- {
- wxLogWarning(_("Failed to reopen folder '%s', it doesn't seem "
- "to exist any more."), foldername.c_str());
- }
- }
- }
-
- // update status of outbox once:
- UpdateOutboxStatus();
-
- // open all default mailboxes
- // --------------------------
-
- if ( !READ_APPCONFIG(MP_DONTOPENSTARTUP) )
+ if ( !m_cmdLineOptions->safe )
{
- char *folders = strutil_strdup(READ_APPCONFIG(MP_OPENFOLDERS));
- kbStringList openFoldersList;
- strutil_tokenise(folders,";",openFoldersList);
- delete [] folders;
+ ContinueStartup();
- bool ok = true;
-
- kbStringList::iterator i;
- for(i = openFoldersList.begin(); i != openFoldersList.end(); i++)
- {
- String *name = *i;
-
- if ( name->empty() )
- {
- FAIL_MSG( "empty folder name in the list of folders to open?" );
- continue;
- }
-
- MFolder_obj folder(*name);
- if ( folder.IsOk() )
- {
- if ( !OpenFolderViewFrame(folder, m_topLevelFrame) )
- {
- // error message must be already given by OpenFolderViewFrame
- ok = false;
- }
- }
- else
- {
- wxLogWarning(_("Failed to reopen folder '%s', it doesn't seem "
- "to exist any more."), name->c_str());
-
- ok = false;
- }
- }
+ // as we now have the main window, we can initialize the modules which
+ // use it
+ InitModules();
- if ( !ok )
- {
- wxLogWarning(_("Not all folders could be reopened."));
- }
+ // cache the auto away flag as it will be checked often in UpdateAwayMode
+ m_autoAwayOn = READ_APPCONFIG_BOOL(MP_AWAY_AUTO_ENTER);
}
-
- // initialise collector object for incoming mails
- // ----------------------------------------------
-
- // TODO: only do it if we are using the NewMail folder at all?
- m_FolderMonitor = FolderMonitor::Create();
-
- // also start the mail auto collection timer
- StartTimer(MAppBase::Timer_PollIncoming);
-
- // show the ADB editor if it had been shown the last time when we ran
- // ------------------------------------------------------------------
-
- if ( READ_APPCONFIG(MP_SHOWADBEDITOR) )
+ else // safe mode
{
- ShowAdbFrame(TopLevelFrame());
+ m_autoAwayOn = false;
}
- // cache the auto away flag as it will be checked often in UpdateAwayMode
- m_autoAwayOn = READ_APPCONFIG_BOOL(MP_AWAY_AUTO_ENTER);
+ // we won't need the command line options any more
+ delete m_cmdLineOptions;
+ m_cmdLineOptions = NULL;
return TRUE;
@@ -853,12 +745,4 @@
SetupOnlineManager(); // make options change effective
#endif // USE_DIALUP
-
-#ifdef USE_ICON_SUBDIRS
- {
- unsigned long idx = (unsigned long) READ_APPCONFIG(MP_ICONSTYLE);
- if(idx < sizeof gs_IconSubDirs)
- GetIconManager()->SetSubDirectory(gs_IconSubDirs[idx]);
- }
-#endif // USE_ICON_SUBDIRS
}
else if (event.GetId() == MEventId_FolderUpdate)
Index: Profile.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/classes/Profile.cpp,v
retrieving revision 1.125
retrieving revision 1.126
diff -b -u -2 -r1.125 -r1.126
--- Profile.cpp 4 Dec 2001 21:49:08 -0000 1.125
+++ Profile.cpp 29 Mar 2002 20:42:22 -0000 1.126
@@ -36,5 +36,7 @@
# include <wx/fileconf.h>
# endif
+
# include <wx/config.h>
+# include <wx/dir.h>
#endif
@@ -44,9 +46,13 @@
#include <ctype.h>
+#include <errno.h>
#ifdef OS_UNIX
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+#endif //Unix
+
// ----------------------------------------------------------------------------
@@ -773,8 +779,155 @@
Profile *
-Profile::CreateGlobalConfig(const String & filename)
+Profile::CreateGlobalConfig(const String& filename)
{
- ASSERT( ! strutil_isempty(filename) );
-# ifdef OS_WIN
+ // if the filename is empty, use the default one
+ String strConfFile = filename;
+
+#ifdef OS_UNIX
+ if ( strConfFile.empty() )
+ {
+ strConfFile = wxGetHomeDir();
+ if ( strConfFile.empty() )
+ {
+ // don't create our files in the root directory, try the current one
+ // instead
+ strConfFile = wxGetCwd();
+ }
+
+ if ( !strConfFile.empty() )
+ {
+ strConfFile << '/';
+ }
+ //else: it will be in the current one, what else can we do?
+
+ strConfFile << "/." << M_APPLICATIONNAME;
+
+ if ( !wxDir::Exists(strConfFile) )
+ {
+ if ( !wxMkdir(strConfFile, 0700) )
+ {
+ wxLogError(_("Cannot create the directory for configuration "
+ "files '%s'."), strConfFile.c_str());
+
+ return FALSE;
+ }
+ else
+ {
+ wxLogInfo(_("Created directory '%s' for configuration files."),
+ strConfFile.c_str());
+ }
+
+ // also create an empty config file with the right permissions:
+ String filename = strConfFile + "/config";
+
+ // pass false to Create() to avoid overwriting the existing file
+ wxFile file;
+ if ( !file.Create(filename, false, wxS_IRUSR | wxS_IWUSR) &&
+ !wxFile::Exists(filename) )
+ {
+ wxLogError(_("Could not create initial configuration file."));
+ }
+ }
+
+ // Check whether other users can write our config dir.
+ //
+ // This must not be allowed as they could change the behaviour of the
+ // program unknowingly to the user!
+ struct stat st;
+ if ( stat(strConfFile, &st) == 0 )
+ {
+ if ( st.st_mode & (S_IWGRP | S_IWOTH) )
+ {
+ // No other user must have write access to the config dir.
+ String msg;
+ msg.Printf(_("Configuration directory '%s' was writable for other
+users.\n"
+ "The programs settings might have been changed without "
+ "your knowledge and the passwords stored in your config\n"
+ "file (if any) could have been compromised!\n\n"),
+ strConfFile.c_str());
+
+ if ( chmod(strConfFile, st.st_mode & ~(S_IWGRP | S_IWOTH)) == 0 )
+ {
+ msg += _("This has been fixed now, the directory is no longer writable
+for others.");
+ }
+ else
+ {
+ msg << String::Format(_("Failed to correct the directory access (%s)"
+ "rights, please do it manually and "
+ "restart the program!"),
+ strerror(errno));
+ }
+
+ wxLogError(msg);
+ }
+ }
+ else
+ {
+ wxLogSysError(_("Failed to access the directory '%s' containing "
+ "the configuration files."),
+ strConfFile.c_str());
+ }
+
+ strConfFile += "/config";
+
+ // Check whether other users can read our config file.
+ //
+ // This must not be allowed as we store passwords in it!
+ if ( stat(strConfFile, &st) == 0 )
+ {
+ if ( st.st_mode & (S_IWGRP | S_IWOTH | S_IRGRP | S_IROTH) )
+ {
+ // No other user must have access to the config file.
+ String msg;
+ if ( st.st_mode & (S_IWGRP | S_IWOTH) )
+ {
+ msg.Printf(_("Configuration file %s was writable by other users.\n"
+ "The program settings could have been changed without\n"
+ "your knowledge, please consider reinstalling the "
+ "program!"),
+ strConfFile.c_str());
+ }
+
+ if ( st.st_mode & (S_IRGRP | S_IROTH) )
+ {
+ if ( !msg.empty() )
+ msg += "\n\n";
+
+ msg += String::Format
+ (
+ _("Configuration file '%s' was readable for other users.\n"
+ "Passwords may have been compromised, please "
+ "consider changing them!"),
+ strConfFile.c_str()
+ );
+ }
+
+ msg += "\n\n";
+
+ if ( chmod(strConfFile, S_IRUSR | S_IWUSR) == 0 )
+ {
+ msg += _("This has been fixed now, the file is no longer readable for
+others.");
+ }
+ else
+ {
+ msg << String::Format(_("The attempt to make the file unreadable "
+ "for others has failed: %s"),
+ strerror(errno));
+ }
+
+ wxLogError(msg);
+ }
+ }
+ //else: not an error, file may be simply not there yet
+ }
+#else // Windows
+ // no such concerns here, just use the registry
+ if ( strConfFile.empty() )
+ {
+ strConfFile = M_APPLICATIONNAME;
+ }
+#endif // Win/Unix
+
+#ifdef OS_WIN
// don't give explicit name, but rather use the default logic (it's
// perfectly ok, for the registry case our keys are under
@@ -785,5 +938,5 @@
wxCONFIG_USE_LOCAL_FILE |
wxCONFIG_USE_GLOBAL_FILE);
-# else // Unix
+#else // Unix
// look for the global config file in the following places in order:
// 1. compile-time specified installation dir
@@ -811,5 +964,5 @@
// we don't need the config file manager for this profile
ms_GlobalConfig = new wxConfig(M_APPLICATIONNAME, M_VENDORNAME,
- filename, globalFile,
+ strConfFile, globalFile,
wxCONFIG_USE_LOCAL_FILE|
wxCONFIG_USE_GLOBAL_FILE);
@@ -818,5 +971,5 @@
// among other things, the passwords
((wxFileConfig *)ms_GlobalConfig)->SetUmask(0077);
-# endif // Unix/Windows
+#endif // Unix/Windows
Profile *p = ProfileImpl::CreateProfile("",NULL);
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates