]> git.decadent.org.uk Git - videolink.git/blob - null_prompt_service.cpp
Disabled prompts in batch processing mode.
[videolink.git] / null_prompt_service.cpp
1 // Copyright 2006 Ben Hutchings <ben@decadentplace.org.uk>.
2 // See the file "COPYING" for licence details.
3
4 #include <nsCOMPtr.h>
5 #include <nsIComponentManager.h>
6 #include <nsIFactory.h>
7
8 #include "null_prompt_service.hpp"
9 #include "xpcom_support.hpp"
10
11 using xpcom_support::check;
12
13 namespace
14 {
15     NS_DEFINE_IID(prompt_service_iid, NS_IPROMPTSERVICE_IID);
16
17     class null_prompt_service_factory : public nsIFactory
18     {
19         NS_DECL_ISUPPORTS
20         NS_DECL_NSIFACTORY
21     };
22
23     NS_IMPL_ISUPPORTS1(null_prompt_service_factory, nsIFactory)
24
25     NS_IMETHODIMP null_prompt_service_factory::CreateInstance(
26         nsISupports *, const nsIID & iid, void ** result)
27     {
28         if (!iid.Equals(prompt_service_iid))
29             return NS_ERROR_NO_INTERFACE;
30
31         try
32         {
33             *result = new null_prompt_service;
34             return NS_OK;
35         }
36         catch (std::bad_alloc &)
37         {
38             return NS_ERROR_OUT_OF_MEMORY;
39         }
40     }
41
42     NS_IMETHODIMP null_prompt_service_factory::LockFactory(PRBool lock)
43     {
44         return NS_ERROR_NOT_IMPLEMENTED;
45     }
46 }
47
48 NS_IMPL_ISUPPORTS1(null_prompt_service, nsIPromptService)
49
50 NS_IMETHODIMP null_prompt_service::Alert(
51     nsIDOMWindow *, const PRUnichar *, const PRUnichar *)
52 {
53     return NS_OK;
54 }
55
56 NS_IMETHODIMP null_prompt_service::AlertCheck(
57     nsIDOMWindow *, const PRUnichar *, const PRUnichar *, const PRUnichar *,
58     PRBool *)
59 {
60     return NS_OK;
61 }
62
63 NS_IMETHODIMP null_prompt_service::Confirm(
64     nsIDOMWindow *, const PRUnichar *, const PRUnichar *, PRBool * result)
65 {
66     // Cancel
67     *result = false;
68     return NS_OK;
69 }
70
71 NS_IMETHODIMP null_prompt_service::ConfirmCheck(
72     nsIDOMWindow *, const PRUnichar *, const PRUnichar *,
73     const PRUnichar *, PRBool *, PRBool * result)
74 {
75     // Cancel
76     *result = false;
77     return NS_OK;
78 }
79
80 NS_IMETHODIMP null_prompt_service::ConfirmEx(
81     nsIDOMWindow *, const PRUnichar *, const PRUnichar *,
82     PRUint32 flags, const PRUnichar *, const PRUnichar *, const PRUnichar *,
83     const PRUnichar *, PRBool *, PRInt32 * result)
84 {
85     // Accept the default
86     if (flags & BUTTON_POS_1_DEFAULT)
87         *result = 1;
88     else if (flags & BUTTON_POS_2_DEFAULT)
89         *result = 2;
90     else
91         *result = 0;
92     return NS_OK;
93 }
94
95 NS_IMETHODIMP null_prompt_service::Prompt(
96     nsIDOMWindow *, const PRUnichar *, const PRUnichar *, PRUnichar **,
97     const PRUnichar *, PRBool *, PRBool * result)
98 {
99     // Cancel
100     *result = false;
101     return NS_OK;
102 }
103
104 NS_IMETHODIMP null_prompt_service::PromptUsernameAndPassword(
105     nsIDOMWindow *, const PRUnichar *, const PRUnichar *,
106     PRUnichar **, PRUnichar **, const PRUnichar *, PRBool *, PRBool * result)
107 {
108     // Cancel
109     *result = false;
110     return NS_OK;
111 }
112
113 NS_IMETHODIMP null_prompt_service::PromptPassword(
114     nsIDOMWindow *, const PRUnichar *, const PRUnichar *, PRUnichar **,
115     const PRUnichar *, PRBool *, PRBool * result)
116 {
117     // Cancel
118     *result = false;
119     return NS_OK;
120 }
121
122 NS_IMETHODIMP null_prompt_service::Select(
123     nsIDOMWindow *, const PRUnichar *, const PRUnichar *, PRUint32,
124     const PRUnichar **, PRInt32 *, PRBool * result)
125 {
126     // Cancel
127     *result = false;
128     return NS_OK;
129 }
130
131 void null_prompt_service::install()
132 {
133     static const nsCID prompt_service_cid = {
134         0xa2112d6a, 0x0e28, 0x421f,
135         {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}
136     };
137     nsCOMPtr<nsIFactory> prompt_factory(new null_prompt_service_factory);
138     check(nsComponentManager::RegisterFactory(
139               prompt_service_cid,
140               "Prompt Service",
141               "@mozilla.org/embedcomp/prompt-service;1",
142               prompt_factory,
143               PR_TRUE)); // replace existing
144 }