diff --git a/mailnews/addrbook/public/nsIAddressBook.idl b/mailnews/addrbook/public/nsIAddressBook.idl
index b5f33548974e..576ac5a415a6 100644
--- a/mailnews/addrbook/public/nsIAddressBook.idl
+++ b/mailnews/addrbook/public/nsIAddressBook.idl
@@ -27,11 +27,16 @@
#include "nsIDOMXULElement.h"
%}
+interface nsIDOMWindow;
+
[scriptable, uuid(D60B84F1-2A8C-11d3-9E07-00A0C92B5F0D)]
interface nsIAddressBook : nsISupports {
void DeleteCards(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node);
void NewAddressBook(in nsIRDFCompositeDataSource db, in nsIDOMXULElement srcDir, in string name);
void DeleteAddressBook(in nsIDOMXULElement tree, in nsIDOMXULElement srcDir, in nsIDOMNodeList node);
+ void PrintCard();
+ void PrintAddressbook();
+ void SetWebShellWindow(in nsIDOMWindow win);
};
diff --git a/mailnews/addrbook/resources/content/addressbook.js b/mailnews/addrbook/resources/content/addressbook.js
index da2fc626d7ab..3e4c1334ca9e 100644
--- a/mailnews/addrbook/resources/content/addressbook.js
+++ b/mailnews/addrbook/resources/content/addressbook.js
@@ -9,6 +9,13 @@ function OnLoadAddressBook()
top.addressbook = Components.classes["component://netscape/addressbook"].createInstance();
top.addressbook = top.addressbook.QueryInterface(Components.interfaces.nsIAddressBook);
+
+ try {
+ top.addressbook.SetWebShellWindow(window)
+ }
+ catch (ex) {
+ dump("failed to set webshell window\n");
+ }
}
@@ -56,4 +63,24 @@ function AbCreateNewAddressBook(name)
top.addressbook.NewAddressBook(document.getElementById('dirTree').database, document.getElementById('resultsTree'), name);
}
+function AbPrintCard()
+{
+ dump("print card\n");
+ try {
+ addressbook.PrintCard();
+ }
+ catch (ex) {
+ dump("failed to print card\n");
+ }
+}
+function AbPrintAddressBook()
+{
+ dump("print address book \n");
+ try {
+ addressbook.PrintAddressbook();
+ }
+ catch (ex) {
+ dump("failed to print address book\n");
+ }
+}
diff --git a/mailnews/addrbook/resources/content/addressbook.xul b/mailnews/addrbook/resources/content/addressbook.xul
index 067fe54bd605..854b6a2531c0 100644
--- a/mailnews/addrbook/resources/content/addressbook.xul
+++ b/mailnews/addrbook/resources/content/addressbook.xul
@@ -65,7 +65,7 @@ Rights Reserved.
-
+
diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp
index 55ee179045f3..118bc3ba4fd7 100644
--- a/mailnews/addrbook/src/nsAddressBook.cpp
+++ b/mailnews/addrbook/src/nsAddressBook.cpp
@@ -37,6 +37,8 @@
#include "nsFileLocations.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
+#include "nsIDOMWindow.h"
+#include "nsIContentViewer.h"
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@@ -264,3 +266,61 @@ nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, char *command,
}
+nsresult nsAddressBook::PrintCard()
+{
+#ifdef DEBUG_seth
+ printf("nsAddressBook::PrintCard()\n");
+#endif
+
+ nsresult rv = NS_ERROR_FAILURE;
+ nsCOMPtr viewer;
+
+ if (!mWebShell) {
+#ifdef DEBUG_seth
+ printf("can't print, there is no webshell\n");
+#endif
+ return rv;
+ }
+
+ mWebShell->GetContentViewer(getter_AddRefs(viewer));
+
+ if (viewer) {
+ rv = viewer->Print();
+ }
+#ifdef DEBUG_seth
+ else {
+ printf("failed to get the viewer for printing\n");
+ }
+#endif
+
+ return rv;
+}
+
+nsresult nsAddressBook::PrintAddressbook()
+{
+#ifdef DEBUG_seth
+ printf("nsAddressBook::PrintAddressbook()\n");
+#endif
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+nsresult nsAddressBook::SetWebShellWindow(nsIDOMWindow *aWin)
+{
+ NS_PRECONDITION(aWin != nsnull, "null ptr");
+ if (!aWin)
+ return NS_ERROR_NULL_POINTER;
+
+ nsCOMPtr globalObj( do_QueryInterface(aWin) );
+ if (!globalObj) {
+ return NS_ERROR_FAILURE;
+ }
+
+ nsCOMPtr webShell;
+ globalObj->GetWebShell(getter_AddRefs(webShell));
+ if (!webShell)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ mWebShell = webShell;
+
+ return NS_OK;
+}
diff --git a/mailnews/addrbook/src/nsAddressBook.h b/mailnews/addrbook/src/nsAddressBook.h
index 5562eadc2fa6..0f4782bd3c02 100644
--- a/mailnews/addrbook/src/nsAddressBook.h
+++ b/mailnews/addrbook/src/nsAddressBook.h
@@ -23,7 +23,8 @@
#include "nsIAbCard.h"
#include "nsCOMPtr.h"
#include "nsIAddrDatabase.h"
-
+#include "nsIWebShell.h"
+#include "nsIScriptGlobalObject.h"
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewCard"
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
@@ -42,12 +43,15 @@ public:
NS_IMETHOD DeleteCards(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList);
NS_IMETHOD NewAddressBook(nsIRDFCompositeDataSource* db, nsIDOMXULElement *srcDirectory, const char *name);
NS_IMETHOD DeleteAddressBook(nsIDOMXULElement *tree, nsIDOMXULElement *srcDirectory, nsIDOMNodeList *nodeList);
+ NS_IMETHOD PrintCard();
+ NS_IMETHOD PrintAddressbook();
+ NS_IMETHOD SetWebShellWindow(nsIDOMWindow *win);
protected:
nsresult DoCommand(nsIRDFCompositeDataSource *db, char * command, nsISupportsArray *srcArray,
nsISupportsArray *arguments);
private:
-
+ nsIWebShell *mWebShell; // weak reference
};
#endif