Line 0
Link Here
|
|
|
1 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 |
/* ***** BEGIN LICENSE BLOCK ***** |
3 |
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 |
* |
5 |
* The contents of this file are subject to the Mozilla Public License Version |
6 |
* 1.1 (the "License"); you may not use this file except in compliance with |
7 |
* the License. You may obtain a copy of the License at |
8 |
* http://www.mozilla.org/MPL/ |
9 |
* |
10 |
* Software distributed under the License is distributed on an "AS IS" basis, |
11 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
12 |
* for the specific language governing rights and limitations under the |
13 |
* License. |
14 |
* |
15 |
* The Original Code is Shell Service. |
16 |
* |
17 |
* The Initial Developer of the Original Code is mozilla.org. |
18 |
* Portions created by the Initial Developer are Copyright (C) 2004 |
19 |
* the Initial Developer. All Rights Reserved. |
20 |
* |
21 |
* Contributor(s): |
22 |
* |
23 |
* Alternatively, the contents of this file may be used under the terms of |
24 |
* either the GNU General Public License Version 2 or later (the "GPL"), or |
25 |
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
26 |
* in which case the provisions of the GPL or the LGPL are applicable instead |
27 |
* of those above. If you wish to allow use of your version of this file only |
28 |
* under the terms of either the GPL or the LGPL, and not to allow others to |
29 |
* use your version of this file under the terms of the MPL, indicate your |
30 |
* decision by deleting the provisions above and replace them with the notice |
31 |
* and other provisions required by the GPL or the LGPL. If you do not delete |
32 |
* the provisions above, a recipient may use your version of this file under |
33 |
* the terms of any one of the MPL, the GPL or the LGPL. |
34 |
* |
35 |
* ***** END LICENSE BLOCK ***** */ |
36 |
|
37 |
#include "nsKDEShellService.h" |
38 |
#include "nsShellService.h" |
39 |
#include "nsKDEUtils.h" |
40 |
#include "nsCOMPtr.h" |
41 |
#include "nsIPrefService.h" |
42 |
#include "nsIProcess.h" |
43 |
#include "nsILocalFile.h" |
44 |
#include "nsServiceManagerUtils.h" |
45 |
#include "nsComponentManagerUtils.h" |
46 |
|
47 |
nsresult |
48 |
nsKDEShellService::Init() |
49 |
{ |
50 |
if( !nsKDEUtils::kdeSupport()) |
51 |
return NS_ERROR_NOT_AVAILABLE; |
52 |
return NS_OK; |
53 |
} |
54 |
|
55 |
NS_IMPL_ISUPPORTS1(nsKDEShellService, nsIShellService) |
56 |
|
57 |
NS_IMETHODIMP |
58 |
nsKDEShellService::IsDefaultBrowser(PRBool aStartupCheck, |
59 |
PRBool* aIsDefaultBrowser) |
60 |
{ |
61 |
*aIsDefaultBrowser = PR_FALSE; |
62 |
if (aStartupCheck) |
63 |
mCheckedThisSession = PR_TRUE; |
64 |
nsCStringArray command; |
65 |
command.AppendCString( NS_LITERAL_CSTRING( "ISDEFAULTBROWSER" )); |
66 |
if( nsKDEUtils::command( command )) |
67 |
*aIsDefaultBrowser = PR_TRUE; |
68 |
return NS_OK; |
69 |
} |
70 |
|
71 |
NS_IMETHODIMP |
72 |
nsKDEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, |
73 |
PRBool aForAllUsers) |
74 |
{ |
75 |
nsCStringArray command; |
76 |
command.AppendCString( NS_LITERAL_CSTRING( "SETDEFAULTBROWSER" )); |
77 |
command.AppendCString( aClaimAllTypes ? NS_LITERAL_CSTRING( "ALLTYPES" ) : NS_LITERAL_CSTRING( "NORMAL" )); |
78 |
return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE; |
79 |
} |
80 |
|
81 |
NS_IMETHODIMP |
82 |
nsKDEShellService::GetShouldCheckDefaultBrowser(PRBool* aResult) |
83 |
{ |
84 |
// If we've already checked, the browser has been started and this is a |
85 |
// new window open, and we don't want to check again. |
86 |
if (mCheckedThisSession) { |
87 |
*aResult = PR_FALSE; |
88 |
return NS_OK; |
89 |
} |
90 |
|
91 |
nsCOMPtr<nsIPrefBranch> prefs; |
92 |
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); |
93 |
if (pserve) |
94 |
pserve->GetBranch("", getter_AddRefs(prefs)); |
95 |
|
96 |
if (prefs) |
97 |
prefs->GetBoolPref(PREF_CHECKDEFAULTBROWSER, aResult); |
98 |
|
99 |
return NS_OK; |
100 |
} |
101 |
|
102 |
NS_IMETHODIMP |
103 |
nsKDEShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck) |
104 |
{ |
105 |
nsCOMPtr<nsIPrefBranch> prefs; |
106 |
nsCOMPtr<nsIPrefService> pserve(do_GetService(NS_PREFSERVICE_CONTRACTID)); |
107 |
if (pserve) |
108 |
pserve->GetBranch("", getter_AddRefs(prefs)); |
109 |
|
110 |
if (prefs) |
111 |
prefs->SetBoolPref(PREF_CHECKDEFAULTBROWSER, aShouldCheck); |
112 |
|
113 |
return NS_OK; |
114 |
} |
115 |
|
116 |
NS_IMETHODIMP |
117 |
nsKDEShellService::SetDesktopBackground(nsIDOMElement* aElement, |
118 |
PRInt32 aPosition) |
119 |
{ |
120 |
return NS_ERROR_NOT_IMPLEMENTED; |
121 |
} |
122 |
|
123 |
NS_IMETHODIMP |
124 |
nsKDEShellService::GetDesktopBackgroundColor(PRUint32 *aColor) |
125 |
{ |
126 |
return NS_ERROR_NOT_IMPLEMENTED; |
127 |
} |
128 |
|
129 |
NS_IMETHODIMP |
130 |
nsKDEShellService::SetDesktopBackgroundColor(PRUint32 aColor) |
131 |
{ |
132 |
return NS_ERROR_NOT_IMPLEMENTED; |
133 |
} |
134 |
|
135 |
NS_IMETHODIMP |
136 |
nsKDEShellService::OpenApplication(PRInt32 aApplication) |
137 |
{ |
138 |
nsCStringArray command; |
139 |
if( aApplication == APPLICATION_MAIL ) |
140 |
command.AppendCString( NS_LITERAL_CSTRING( "OPENMAIL" )); |
141 |
else if( aApplication == APPLICATION_NEWS ) |
142 |
command.AppendCString( NS_LITERAL_CSTRING( "OPENNEWS" )); |
143 |
else |
144 |
return NS_ERROR_NOT_IMPLEMENTED; |
145 |
return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE; |
146 |
} |
147 |
|
148 |
NS_IMETHODIMP |
149 |
nsKDEShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI) |
150 |
{ |
151 |
nsCStringArray command; |
152 |
command.AppendCString( NS_LITERAL_CSTRING( "RUN" )); |
153 |
nsCString app; |
154 |
nsresult rv = aApplication->GetNativePath( app ); |
155 |
NS_ENSURE_SUCCESS( rv, rv ); |
156 |
command.AppendCString( app ); |
157 |
command.AppendCString( aURI ); |
158 |
return nsKDEUtils::command( command ) ? NS_OK : NS_ERROR_FAILURE; |
159 |
} |
160 |
|
161 |
NS_IMETHODIMP |
162 |
nsKDEShellService::GetDefaultFeedReader(nsILocalFile** _retval) |
163 |
{ |
164 |
*_retval = nsnull; |
165 |
|
166 |
nsCStringArray command; |
167 |
command.AppendCString( NS_LITERAL_CSTRING( "GETDEFAULTFEEDREADER" )); |
168 |
nsCStringArray output; |
169 |
if( !nsKDEUtils::command( command, &output ) || output.Count() != 1 ) |
170 |
return NS_ERROR_FAILURE; |
171 |
|
172 |
nsCString path; |
173 |
path = *output[ 0 ]; |
174 |
if (path.IsEmpty()) |
175 |
return NS_ERROR_FAILURE; |
176 |
|
177 |
nsresult rv; |
178 |
nsCOMPtr<nsILocalFile> defaultReader = |
179 |
do_CreateInstance("@mozilla.org/file/local;1", &rv); |
180 |
NS_ENSURE_SUCCESS(rv, rv); |
181 |
|
182 |
rv = defaultReader->InitWithNativePath(path); |
183 |
NS_ENSURE_SUCCESS(rv, rv); |
184 |
|
185 |
PRBool exists; |
186 |
rv = defaultReader->Exists(&exists); |
187 |
NS_ENSURE_SUCCESS(rv, rv); |
188 |
if (!exists) |
189 |
return NS_ERROR_FAILURE; |
190 |
|
191 |
NS_ADDREF(*_retval = defaultReader); |
192 |
return NS_OK; |
193 |
} |