40 #include "nsIServiceManager.h"
41 #include "nsILocalFile.h"
42 #include "nsIProperties.h"
43 #include "nsDirectoryServiceDefs.h"
44 #include "nsIPrefService.h"
46 #include "nsStringAPI.h"
47 #include "nsIGConfService.h"
48 #include "nsIGnomeVFSService.h"
49 #include "nsIStringBundle.h"
50 #include "nsIOutputStream.h"
51 #include "nsIProcess.h"
52 #include "nsNetUtil.h"
53 #include "nsIDOMHTMLImageElement.h"
54 #include "nsIImageLoadingContent.h"
55 #include "imgIRequest.h"
56 #include "imgIContainer.h"
58 #ifdef MOZ_WIDGET_GTK2
59 #include "nsIImageToPixbuf.h"
63 #include <glib-object.h>
66 #include <gdk-pixbuf/gdk-pixbuf.h>
86 {
"chrome", PR_FALSE }
90 {
"text/html",
"htm html shtml" },
91 {
"application/xhtml+xml",
"xhtml xht" }
97 #define DG_BACKGROUND "/desktop/gnome/background"
112 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
113 nsCOMPtr<nsIGnomeVFSService> vfs =
114 do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
117 return NS_ERROR_NOT_AVAILABLE;
121 mUseLocaleFilenames = PR_GetEnv(
"G_BROKEN_FILENAMES") != nsnull;
123 nsCOMPtr<nsIProperties>
dirSvc
124 (do_GetService(
"@mozilla.org/file/directory_service;1"));
125 NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE);
127 nsCOMPtr<nsILocalFile> appPath;
128 rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile),
129 getter_AddRefs(appPath));
130 NS_ENSURE_SUCCESS(rv, rv);
132 rv = appPath->AppendNative(NS_LITERAL_CSTRING(MOZ_APP_NAME));
133 NS_ENSURE_SUCCESS(rv, rv);
135 return appPath->GetNativePath(mAppPath);
145 if (mUseLocaleFilenames) {
146 gchar *nativePath = g_filename_from_utf8(aKeyValue, -1, NULL, NULL, NULL);
148 NS_ERROR(
"Error converting path to filesystem encoding");
152 commandPath = g_find_program_in_path(nativePath);
155 commandPath = g_find_program_in_path(aKeyValue);
161 PRBool matches = mAppPath.Equals(commandPath);
167 nsGNOMEShellService::IsDefaultBrowser(PRBool aStartupCheck,
168 PRBool* aIsDefaultBrowser)
170 *aIsDefaultBrowser = PR_FALSE;
172 mCheckedThisSession = PR_TRUE;
174 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
179 for (
unsigned int i = 0;
i < NS_ARRAY_LENGTH(appProtocols); ++
i) {
180 if (!appProtocols[
i].essential)
184 gconf->GetAppForProtocol(nsDependentCString(appProtocols[
i].
name),
193 if (g_shell_parse_argv(handler.get(), &argc, &argv, NULL) && argc > 0) {
194 handler.Assign(argv[0]);
198 if (!KeyMatchesAppName(handler.get()) || !enabled)
202 *aIsDefaultBrowser = PR_TRUE;
208 nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes,
213 NS_WARNING(
"Setting the default browser for all users is not yet supported");
216 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
218 nsCAutoString schemeList;
219 nsCAutoString appKeyValue(mAppPath);
220 appKeyValue.Append(
" \"%s\"");
223 for (i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++
i) {
224 schemeList.Append(nsDependentCString(appProtocols[i].name));
225 schemeList.Append(
',');
227 if (appProtocols[i].essential || aClaimAllTypes) {
228 gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name),
233 if (aClaimAllTypes) {
234 nsCOMPtr<nsIGnomeVFSService> vfs =
235 do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID);
237 nsCOMPtr<nsIStringBundleService> bundleService =
238 do_GetService(NS_STRINGBUNDLE_CONTRACTID);
239 NS_ENSURE_TRUE(bundleService, NS_ERROR_OUT_OF_MEMORY);
243 NS_ENSURE_TRUE(brandBundle, NS_ERROR_FAILURE);
245 nsString brandShortName, brandFullName;
246 brandBundle->GetStringFromName(NS_LITERAL_STRING(
"brandShortName").
get(),
247 getter_Copies(brandShortName));
248 brandBundle->GetStringFromName(NS_LITERAL_STRING(
"brandFullName").
get(),
249 getter_Copies(brandFullName));
252 NS_ConvertUTF16toUTF8
id(brandShortName);
254 vfs->SetAppStringKey(
id, nsIGnomeVFSService::APP_KEY_COMMAND, mAppPath);
255 vfs->SetAppStringKey(
id, nsIGnomeVFSService::APP_KEY_NAME,
256 NS_ConvertUTF16toUTF8(brandFullName));
262 schemeList.Append(
"file");
264 vfs->SetAppStringKey(
id, nsIGnomeVFSService::APP_KEY_SUPPORTED_URI_SCHEMES,
267 vfs->SetAppStringKey(
id, nsIGnomeVFSService::APP_KEY_EXPECTS_URIS,
268 NS_LITERAL_CSTRING(
"true"));
270 vfs->SetAppBoolKey(
id, nsIGnomeVFSService::APP_KEY_CAN_OPEN_MULTIPLE,
273 vfs->SetAppBoolKey(
id, nsIGnomeVFSService::APP_KEY_REQUIRES_TERMINAL,
277 nsCAutoString iconFilePath(mAppPath);
278 PRInt32 lastSlash = iconFilePath.RFindChar(PRUnichar(
'/'));
279 if (lastSlash == -1) {
280 NS_ERROR(
"no slash in executable path?");
282 iconFilePath.SetLength(lastSlash);
283 nsCOMPtr<nsILocalFile> iconFile;
284 NS_NewNativeLocalFile(iconFilePath, PR_FALSE, getter_AddRefs(iconFile));
286 iconFile->AppendRelativeNativePath(NS_LITERAL_CSTRING(
"icons/document.png"));
288 nsCOMPtr<nsILocalFile> userIconPath;
289 NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv(
"HOME")), PR_FALSE,
290 getter_AddRefs(userIconPath));
292 userIconPath->AppendNative(NS_LITERAL_CSTRING(
".icons"));
293 iconFile->CopyToNative(userIconPath,
299 for (i = 0; i < NS_ARRAY_LENGTH(appTypes); ++
i) {
300 vfs->AddMimeType(
id, nsDependentCString(appTypes[i].mimeType));
301 vfs->SetMimeExtensions(nsDependentCString(appTypes[i].mimeType),
302 nsDependentCString(appTypes[i].extensions));
303 vfs->SetAppForMimeType(nsDependentCString(appTypes[i].mimeType),
id);
304 vfs->SetIconForMimeType(nsDependentCString(appTypes[i].mimeType),
308 vfs->SyncAppRegistry();
315 nsGNOMEShellService::GetShouldCheckDefaultBrowser(PRBool* aResult)
319 if (mCheckedThisSession) {
324 nsCOMPtr<nsIPrefBranch>
prefs;
327 pserve->GetBranch(
"", getter_AddRefs(prefs));
336 nsGNOMEShellService::SetShouldCheckDefaultBrowser(PRBool aShouldCheck)
338 nsCOMPtr<nsIPrefBranch>
prefs;
341 pserve->GetBranch(
"", getter_AddRefs(prefs));
352 #ifndef MOZ_WIDGET_GTK2
353 return NS_ERROR_NOT_AVAILABLE;
355 nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
356 do_GetService(
"@mozilla.org/widget/image-to-gdk-pixbuf;1");
358 return NS_ERROR_NOT_AVAILABLE;
360 GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(aImage);
362 return NS_ERROR_NOT_AVAILABLE;
364 gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(),
"png", NULL, NULL);
366 g_object_unref(pixbuf);
367 return res ?
NS_OK : NS_ERROR_FAILURE;
372 nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement,
376 nsCOMPtr<nsIImageLoadingContent> imageContent = do_QueryInterface(aElement, &rv);
377 if (!imageContent)
return rv;
380 nsCOMPtr<imgIRequest> request;
381 rv = imageContent->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
382 getter_AddRefs(request));
383 if (!request)
return rv;
384 nsCOMPtr<imgIContainer> container;
385 rv = request->GetImage(getter_AddRefs(container));
386 if (!container)
return rv;
389 nsCAutoString filePath(PR_GetEnv(
"HOME"));
393 nsCID bundleCID = NS_STRINGBUNDLESERVICE_CID;
394 nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(bundleCID));
398 getter_AddRefs(brandBundle));
399 if (NS_SUCCEEDED(rv) && brandBundle) {
400 rv = brandBundle->GetStringFromName(NS_LITERAL_STRING(
"brandShortName").
get(),
401 getter_Copies(brandName));
402 NS_ENSURE_SUCCESS(rv, rv);
407 filePath.Append(
'/');
408 filePath.Append(NS_ConvertUTF16toUTF8(brandName));
409 filePath.Append(
"_wallpaper.png");
415 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
419 options.Assign(
"wallpaper");
421 options.Assign(
"stretched");
423 options.Assign(
"centered");
439 #define COLOR_16_TO_8_BIT(_c) ((_c) >> 8)
440 #define COLOR_8_TO_16_BIT(_c) ((_c) << 8 | (_c))
443 nsGNOMEShellService::GetDesktopBackgroundColor(PRUint32 *aColor)
445 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
447 nsCAutoString background;
450 if (background.IsEmpty()) {
456 gboolean success = gdk_color_parse(background.get(), &color);
458 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
470 char *buf = aResult.BeginWriting(13);
478 PR_snprintf(buf, 14,
"#%04x%04x%04x", red, green, blue);
482 nsGNOMEShellService::SetDesktopBackgroundColor(PRUint32 aColor)
484 NS_ASSERTION(aColor <= 0xffffff,
"aColor has extra bits");
485 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
487 nsCAutoString colorString;
496 nsGNOMEShellService::OpenApplication(PRInt32 aApplication)
498 nsCAutoString scheme;
500 scheme.Assign(
"mailto");
502 scheme.Assign(
"news");
504 return NS_ERROR_NOT_AVAILABLE;
506 nsCOMPtr<nsIGConfService> gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
509 nsCAutoString appCommand;
510 gconf->GetAppForProtocol(scheme, &enabled, appCommand);
513 return NS_ERROR_FAILURE;
517 PRBool requiresTerminal;
518 gconf->HandlerRequiresTerminal(scheme, &requiresTerminal);
519 if (requiresTerminal)
520 return NS_ERROR_FAILURE;
525 if (!g_shell_parse_argv(appCommand.get(), &argc, &argv, NULL))
526 return NS_ERROR_FAILURE;
528 char **newArgv =
new char*[argc + 1];
533 for (
int i = 0; i < argc; ++
i) {
534 if (strcmp(argv[i],
"%s") != 0)
535 newArgv[newArgc++] = argv[i];
538 newArgv[newArgc] = nsnull;
540 gboolean err = g_spawn_async(NULL, newArgv, NULL, G_SPAWN_SEARCH_PATH,
541 NULL, NULL, NULL, NULL);
546 return err ?
NS_OK : NS_ERROR_FAILURE;
550 nsGNOMEShellService::OpenApplicationWithURI(nsILocalFile* aApplication,
const nsACString& aURI)
553 nsCOMPtr<nsIProcess> process =
554 do_CreateInstance(
"@mozilla.org/process/util;1", &rv);
558 rv = process->Init(aApplication);
562 const nsCString spec(aURI);
563 const char* specStr = spec.get();
564 return process->Run(PR_FALSE, &specStr, 1);
568 nsGNOMEShellService::GetDefaultFeedReader(nsILocalFile** _retval)
570 return NS_ERROR_NOT_IMPLEMENTED;
#define COLOR_16_TO_8_BIT(_c)
NS_DECL_ISUPPORTS NS_DECL_NSISHELLSERVICE nsresult Init() NS_HIDDEN
const long APPLICATION_NEWS
static const char kDocumentIconPath[]
static const char kDesktopDrawBGKey[]
const long APPLICATION_MAIL
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
const NS_PREFSERVICE_CONTRACTID
#define COLOR_8_TO_16_BIT(_c)
#define PREF_CHECKDEFAULTBROWSER
const long BACKGROUND_TILE
static const char kDesktopColorKey[]
static const char kDesktopOptionsKey[]
static const ProtocolAssociation appProtocols[]
static const MimeTypeAssociation appTypes[]
static void ColorToCString(PRUint32 aColor, nsCString &aResult)
_getSelectedPageStyle s i
static const char kDesktopImageKey[]
static nsresult WriteImage(const nsCString &aPath, imgIContainer *aImage)
const long BACKGROUND_STRETCH