Support Command Line Parsing
git-svn-id: svn://10.0.0.236/trunk@12895 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
684148cae8
commit
c08f341ef8
@ -60,6 +60,8 @@ public:
|
||||
NS_METHOD Logoff();
|
||||
NS_METHOD LoadUI();
|
||||
NS_METHOD LoadPreferences();
|
||||
NS_METHOD ParseCommandLine();
|
||||
|
||||
NS_METHOD EnsureUserPath( JulianString& sPath );
|
||||
|
||||
NS_IMETHOD SetCAPISession(CAPISession aCAPISession);
|
||||
|
||||
@ -42,6 +42,7 @@ public:
|
||||
NS_IMETHOD Logoff() = 0;
|
||||
NS_IMETHOD LoadUI() = 0;
|
||||
NS_IMETHOD LoadPreferences() = 0;
|
||||
NS_IMETHOD ParseCommandLine() = 0;
|
||||
|
||||
NS_IMETHOD SetCAPISession(CAPISession aCAPISession) = 0;
|
||||
NS_IMETHOD_(CAPISession) GetCAPISession() = 0;
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
#include "nsCalendarModel.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "plgetopt.h"
|
||||
|
||||
/* for CAPI to work in general form */
|
||||
#include "nsCapiCallbackReader.h"
|
||||
@ -184,11 +185,23 @@ NS_IMPL_RELEASE(nsCalendarShell)
|
||||
|
||||
nsresult nsCalendarShell::Init()
|
||||
{
|
||||
/*
|
||||
* Get the shell instance
|
||||
*/
|
||||
|
||||
nsresult res = nsApplicationManager::GetShellInstance(this, &mShellInstance);
|
||||
|
||||
/*
|
||||
* Parse command Line
|
||||
*/
|
||||
|
||||
|
||||
ParseCommandLine();
|
||||
|
||||
/*
|
||||
* Register class factrories needed for application
|
||||
*/
|
||||
RegisterFactories() ;
|
||||
|
||||
InitFactoryObjs();
|
||||
|
||||
/*
|
||||
@ -206,7 +219,7 @@ nsresult nsCalendarShell::Init()
|
||||
*/
|
||||
LoadUI();
|
||||
|
||||
return NS_OK;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,6 +243,42 @@ nsresult nsCalendarShell::InitFactoryObjs()
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsCalendarShell::ParseCommandLine()
|
||||
{
|
||||
PLOptStatus os;
|
||||
PLOptState *opt;
|
||||
|
||||
mShellInstance->GetCommandLineOptions(&opt,"Gdl:c:");
|
||||
|
||||
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
|
||||
{
|
||||
if (PL_OPT_BAD == os)
|
||||
continue;
|
||||
|
||||
switch (opt->option)
|
||||
{
|
||||
case 'G': /* GLOBAL threads */
|
||||
//thread_scope = PR_GLOBAL_THREAD;
|
||||
break;
|
||||
|
||||
case 'd': /* debug mode */
|
||||
break;
|
||||
|
||||
case 'l': /* loop count */
|
||||
//loops = atoi(opt->value);
|
||||
break;
|
||||
|
||||
case 'c': /* concurrency limit */
|
||||
//cpus = atoi(opt->value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method establishes a logged in user and opens a connection to
|
||||
* the calendar server (or local database file if they're working offline).
|
||||
@ -460,11 +509,9 @@ nsresult nsCalendarShell::EnvVarsToValues(JulianString& s)
|
||||
*/
|
||||
nsresult nsCalendarShell::LoadPreferences()
|
||||
{
|
||||
nsresult res = nsApplicationManager::GetShellInstance(this, &mShellInstance);
|
||||
nsCurlParser curl;
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (NS_OK != res)
|
||||
return res ;
|
||||
nsCurlParser curl;
|
||||
|
||||
/*
|
||||
* Load the overriding user preferences
|
||||
|
||||
@ -144,6 +144,8 @@ public:
|
||||
|
||||
NS_IMETHOD LaunchApplication(nsString& aApplication) ;
|
||||
|
||||
NS_IMETHOD GetCommandLineOptions(PLOptState** aOptState, const char * aOptions) ;
|
||||
|
||||
|
||||
private:
|
||||
nsNativeApplicationInstance mNativeInstance ;
|
||||
@ -151,9 +153,14 @@ private:
|
||||
nsIWidget * mApplicationWindow ;
|
||||
nsIPref * mPref;
|
||||
nsIStreamManager * mStreamManager;
|
||||
nsIXPFCToolbarManager * mToolbarManager;
|
||||
nsIXPFCToolbarManager * mToolbarManager;
|
||||
nsIDeviceContext * mDeviceContext;
|
||||
|
||||
public:
|
||||
PLOptState * mOptState;
|
||||
PRInt32 mArgc;
|
||||
char ** mArgv;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -20,10 +20,12 @@
|
||||
#define nsIShellInstance_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nspr.h"
|
||||
#include "nsxpfc.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIApplicationShell.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "plgetopt.h"
|
||||
|
||||
class nsIApplicationShell;
|
||||
class nsIPref;
|
||||
@ -133,6 +135,14 @@ public:
|
||||
*/
|
||||
NS_IMETHOD_(nsIXPFCToolbarManager *) GetToolbarManager() = 0;
|
||||
|
||||
PLOptState *opt;
|
||||
|
||||
/**
|
||||
* Get Command Line Options
|
||||
* @result NS_OK
|
||||
*/
|
||||
NS_IMETHOD GetCommandLineOptions(PLOptState** aOptState, const char * aOptions) = 0;
|
||||
|
||||
/**
|
||||
* Launch an application
|
||||
* @result nsresult NS_OK upon succcessful completion
|
||||
|
||||
@ -82,12 +82,18 @@ nsShellInstance::nsShellInstance()
|
||||
mStreamManager = nsnull;
|
||||
mToolbarManager = nsnull;
|
||||
mDeviceContext = nsnull;
|
||||
mOptState = nsnull;
|
||||
mArgc = 0;
|
||||
mArgv = nsnull;
|
||||
}
|
||||
|
||||
nsShellInstance::~nsShellInstance()
|
||||
{
|
||||
//NS_ShutdownINetService();
|
||||
|
||||
if (nsnull != mOptState)
|
||||
PL_DestroyOptState(mOptState);
|
||||
|
||||
NS_IF_RELEASE(mDeviceContext);
|
||||
NS_IF_RELEASE(mApplicationWindow);
|
||||
|
||||
@ -189,6 +195,15 @@ nsIPref * nsShellInstance::GetPreferences()
|
||||
return (mPref) ;
|
||||
}
|
||||
|
||||
nsresult nsShellInstance::GetCommandLineOptions(PLOptState** aOptState, const char * aOptions)
|
||||
{
|
||||
mOptState = PL_CreateOptState(mArgc, mArgv, aOptions);
|
||||
|
||||
*aOptState = mOptState;
|
||||
|
||||
return (NS_OK) ;
|
||||
}
|
||||
|
||||
nsIStreamManager * nsShellInstance::GetStreamManager()
|
||||
{
|
||||
return (mStreamManager) ;
|
||||
|
||||
@ -74,7 +74,7 @@ void main(int argc, char **argv)
|
||||
{
|
||||
nsresult result = NS_OK ;
|
||||
|
||||
nsIShellInstance * pShellInstance ;
|
||||
nsShellInstance * pShellInstance ;
|
||||
nsIApplicationShell * pApplicationShell ;
|
||||
|
||||
XtSetLanguageProc(NULL, NULL, NULL);
|
||||
@ -141,6 +141,9 @@ void main(int argc, char **argv)
|
||||
// Initialize the system
|
||||
|
||||
pShellInstance->Init();
|
||||
pShellInstance->mArgc = argc;
|
||||
pShellInstance->mArgv = argv;
|
||||
|
||||
pApplicationShell->Init();
|
||||
|
||||
// Now, let actually start dispatching events.
|
||||
|
||||
@ -67,9 +67,9 @@ static NS_DEFINE_IID(kCListLayoutCID, NS_LISTLAYOUT_CID);
|
||||
|
||||
int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, int nCmdShow)
|
||||
{
|
||||
nsresult result = NS_OK ;
|
||||
nsresult result = NS_OK ;
|
||||
|
||||
nsIShellInstance * pShellInstance ;
|
||||
nsShellInstance * pShellInstance ;
|
||||
nsIApplicationShell * pApplicationShell ;
|
||||
|
||||
PL_InitializeEventsLib("");
|
||||
@ -77,83 +77,83 @@ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam,
|
||||
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
|
||||
PR_STDIO_INIT();
|
||||
|
||||
|
||||
|
||||
|
||||
// Let get a ShellInstance for this Application instance
|
||||
nsRepository::RegisterFactory(kCShellInstanceCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuBarCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuContainerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCMenuManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuItemCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCToolbarCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCDialogCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCUserCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCButtonCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPButtonCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPItemCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCTextWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCTabWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCToolbarManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCStreamManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCStreamObjectCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCVectorCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCVectorIteratorCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCstackCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCBoxLayoutCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCListLayoutCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
// Let get a ShellInstance for this Application instance
|
||||
nsRepository::RegisterFactory(kCShellInstanceCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuBarCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuContainerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCMenuManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCMenuItemCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCToolbarCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCDialogCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCUserCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCButtonCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPButtonCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPItemCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCTextWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCTabWidgetCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCXPFCToolbarManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCStreamManagerCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCStreamObjectCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCVectorCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCVectorIteratorCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCstackCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCBoxLayoutCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
nsRepository::RegisterFactory(kCListLayoutCID, XPFC_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
result = nsRepository::CreateInstance(kCShellInstanceCID,
|
||||
NULL,
|
||||
kIShellInstanceIID,
|
||||
(void **) &pShellInstance) ;
|
||||
NULL,
|
||||
kIShellInstanceIID,
|
||||
(void **) &pShellInstance) ;
|
||||
|
||||
if (result != NS_OK)
|
||||
return result ;
|
||||
|
||||
// Let's instantiate the Application's Shell
|
||||
NS_RegisterApplicationShellFactory() ;
|
||||
NS_RegisterApplicationShellFactory() ;
|
||||
|
||||
result = nsRepository::CreateInstance(kIXPCOMApplicationShellCID,
|
||||
NULL,
|
||||
kIXPCOMApplicationShellCID,
|
||||
(void **) &pApplicationShell) ;
|
||||
NULL,
|
||||
kIXPCOMApplicationShellCID,
|
||||
(void **) &pApplicationShell) ;
|
||||
|
||||
if (result != NS_OK)
|
||||
return result ;
|
||||
|
||||
// Let the the State know who it's Application Instance is
|
||||
pShellInstance->SetNativeInstance((nsNativeApplicationInstance) instance);
|
||||
pShellInstance->SetApplicationShell(pApplicationShell);
|
||||
// Let the the State know who it's Application Instance is
|
||||
pShellInstance->SetNativeInstance((nsNativeApplicationInstance) instance);
|
||||
pShellInstance->SetApplicationShell(pApplicationShell);
|
||||
|
||||
// Tell the application manager to store away the association so the
|
||||
// Application can look up its State
|
||||
nsApplicationManager::SetShellAssociation(pApplicationShell, pShellInstance);
|
||||
// Tell the application manager to store away the association so the
|
||||
// Application can look up its State
|
||||
nsApplicationManager::SetShellAssociation(pApplicationShell, pShellInstance);
|
||||
|
||||
// Initialize the system
|
||||
pShellInstance->Init();
|
||||
// Initialize the system
|
||||
pShellInstance->mArgc = __argc;
|
||||
pShellInstance->mArgv = __argv;
|
||||
|
||||
pShellInstance->Init();
|
||||
pApplicationShell->Init();
|
||||
|
||||
// Now, let actually start dispatching events.
|
||||
nsIAppShell * app_shell = nsnull;
|
||||
// Now, let actually start dispatching events.
|
||||
nsIAppShell * app_shell = nsnull;
|
||||
|
||||
result = pApplicationShell->QueryInterface(kIAppShellIID,(void**)&app_shell);
|
||||
result = pApplicationShell->QueryInterface(kIAppShellIID,(void**)&app_shell);
|
||||
|
||||
if (result == NS_OK)
|
||||
{
|
||||
result = app_shell->Run();
|
||||
NS_RELEASE(app_shell);
|
||||
}
|
||||
if (result == NS_OK)
|
||||
{
|
||||
result = app_shell->Run();
|
||||
NS_RELEASE(app_shell);
|
||||
}
|
||||
|
||||
// We're done, clean up
|
||||
nsApplicationManager::DeleteShellAssociation(pApplicationShell, pShellInstance);
|
||||
// We're done, clean up
|
||||
nsApplicationManager::DeleteShellAssociation(pApplicationShell, pShellInstance);
|
||||
|
||||
NS_RELEASE(pApplicationShell);
|
||||
NS_RELEASE(pShellInstance);
|
||||
|
||||
//PR_Cleanup();
|
||||
NS_RELEASE(pApplicationShell);
|
||||
NS_RELEASE(pShellInstance);
|
||||
|
||||
//PR_Cleanup();
|
||||
|
||||
// book out of here
|
||||
// book out of here
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user