you can launch addressbook with -addressbook

now using the nsICmdLineHander interface and categories to do this the right way
r=alecf
This commit is contained in:
sspitzer%netscape.com 2000-02-06 11:04:10 +00:00
Родитель 6bf6c95062
Коммит f96cfa11e8
3 изменённых файлов: 98 добавлений и 6 удалений

Просмотреть файл

@ -64,7 +64,9 @@ static nsModuleComponentInfo components[] =
{ "Address Book",
NS_ADDRESSBOOK_CID,
NS_ADDRESSBOOK_PROGID,
nsAddressBookConstructor },
nsAddressBookConstructor,
nsAddressBook::RegisterProc,
nsAddressBook::UnregisterProc },
{ "Address Book Directory Datasource",
NS_ABDIRECTORYDATASOURCE_CID,
NS_ABDIRECTORYDATASOURCE_PROGID,

Просмотреть файл

@ -48,7 +48,8 @@
#include "nsIDOMWindow.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsXPIDLString.h"
#include "nsICategoryManager.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@ -116,7 +117,10 @@ nsAddressBook::~nsAddressBook()
{
}
NS_IMPL_ISUPPORTS(nsAddressBook, NS_GET_IID(nsIAddressBook));
NS_IMPL_THREADSAFE_ADDREF(nsAddressBook);
NS_IMPL_THREADSAFE_RELEASE(nsAddressBook);
NS_IMPL_QUERY_INTERFACE2(nsAddressBook, nsIAddressBook, nsICmdLineHandler);
//
// nsIAddressBook
@ -1266,3 +1270,77 @@ NS_IMETHODIMP nsAddressBook::ImportAddressBook()
return rv;
}
NS_IMETHODIMP
nsAddressBook::GetCommandLineArgument(char **aCommandLineArgument)
{
if (!aCommandLineArgument) return NS_ERROR_FAILURE;
*aCommandLineArgument = PL_strdup("-addressbook");
return NS_OK;
}
NS_IMETHODIMP
nsAddressBook::GetPrefNameForStartup(char **aPrefNameForStartup)
{
if (!aPrefNameForStartup) return NS_ERROR_FAILURE;
*aPrefNameForStartup = PL_strdup("general.startup.addressbook");
return NS_OK;
}
NS_IMETHODIMP
nsAddressBook::GetChromeUrlForTask(char **aChromeUrlForTask)
{
if (!aChromeUrlForTask) return NS_ERROR_FAILURE;
*aChromeUrlForTask = PL_strdup("chrome://addressbook/content/");
return NS_OK;
}
NS_IMETHODIMP
nsAddressBook::GetHelpText(char **aHelpText)
{
if (!aHelpText) return NS_ERROR_FAILURE;
*aHelpText = PL_strdup("Start with the addressbook.");
return NS_OK;
}
NS_METHOD nsAddressBook::RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
{
// Register ourselves into the COMMAND_LINE_ARGUMENT_HANDLERS
nsresult rv;
nsCOMPtr<nsICategoryManager> catman = do_GetService("mozilla.categorymanager.1", &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString prevEntry;
rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, NS_ADDRESSBOOK_PROGID, "Addressbook Cmd Line Handler", PR_TRUE, PR_TRUE, getter_Copies(prevEntry));
return NS_OK;
}
NS_METHOD nsAddressBook::UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman = do_GetService("mozilla.categorymanager.1", &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString prevEntry;
rv = catman->DeleteCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, NS_ADDRESSBOOK_PROGID, PR_TRUE, getter_Copies(prevEntry));
// Return value is not used from this function.
return NS_OK;
}

Просмотреть файл

@ -30,13 +30,15 @@
#include "nsIWebShell.h"
#include "nsIScriptGlobalObject.h"
#include "nsIFileSpecWithUI.h"
#include "nsICmdLineHandler.h"
#include "nsIComponentManager.h"
#include "nsIFileSpec.h"
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewCard"
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
#define NC_RDF_NEWDIRECTORY "http://home.netscape.com/NC-rdf#NewDirectory"
class nsAddressBook : public nsIAddressBook
class nsAddressBook : public nsIAddressBook, nsICmdLineHandler
{
public:
@ -44,7 +46,17 @@ public:
virtual ~nsAddressBook();
NS_DECL_ISUPPORTS
NS_DECL_NSIADDRESSBOOK
NS_DECL_NSIADDRESSBOOK
NS_DECL_NSICMDLINEHANDLER
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType);
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation);
protected:
nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray,