2 // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 // Copyright (C) 2004 Imendio AB
5 // Copyright (C) 2004 Marco Pesenti Gritti
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 #include <gtkmozembed.h>
32 #include <nsEmbedString.h>
33 #include <nsIPrefService.h>
34 #include <nsIServiceManager.h>
36 #if defined (HAVE_CHROME_NSICHROMEREGISTRYSEA_H)
37 #include <chrome/nsIChromeRegistrySea.h>
38 #elif defined(MOZ_NSIXULCHROMEREGISTRY_SELECTSKIN)
39 #include <nsIChromeRegistry.h>
42 #ifdef ALLOW_PRIVATE_API
43 // FIXME: For setting the locale. hopefully gtkmozembed will do itself soon
44 #include <nsILocaleService.h>
48 #include "gecko-utils.h"
51 blam_util_split_font_string (const gchar
*font_name
, gchar
**name
, gint
*size
)
55 tmp_name
= g_strdup (font_name
);
57 ch
= g_utf8_strrchr (tmp_name
, -1, ' ');
58 if (!ch
|| ch
== tmp_name
) {
64 *name
= g_strdup (tmp_name
);
65 *size
= strtol (ch
+ 1, (char **) NULL
, 10);
67 /* Temporary hack to make the font a bit bigger ;) */
68 /* *size = *size + 3; */
74 gecko_prefs_set_string (const gchar
*key
, const gchar
*value
)
76 nsCOMPtr
<nsIPrefService
> prefService
=
77 do_GetService (NS_PREFSERVICE_CONTRACTID
);
78 nsCOMPtr
<nsIPrefBranch
> pref
;
79 prefService
->GetBranch ("", getter_AddRefs (pref
));
82 nsresult rv
= pref
->SetCharPref (key
, value
);
83 return NS_SUCCEEDED (rv
) ? TRUE
: FALSE
;
91 gecko_prefs_set_int (const gchar
*key
, gint value
)
93 nsCOMPtr
<nsIPrefService
> prefService
=
94 do_GetService (NS_PREFSERVICE_CONTRACTID
);
95 nsCOMPtr
<nsIPrefBranch
> pref
;
96 prefService
->GetBranch ("", getter_AddRefs (pref
));
99 nsresult rv
= pref
->SetIntPref (key
, value
);
100 return NS_SUCCEEDED (rv
) ? TRUE
: FALSE
;
107 blam_gecko_utils_set_font (gint type
, const gchar
*fontname
)
113 if (!blam_util_split_font_string (fontname
, &name
, &size
)) {
119 case BLAM_GECKO_PREF_FONT_VARIABLE
:
120 gecko_prefs_set_string ("font.name.variable.x-western",
122 gecko_prefs_set_int ("font.size.variable.x-western",
125 case BLAM_GECKO_PREF_FONT_FIXED
:
126 gecko_prefs_set_string ("font.name.fixed.x-western",
128 gecko_prefs_set_int ("font.size.fixed.x-western",
137 getUILang (nsAString
& aUILang
)
141 nsCOMPtr
<nsILocaleService
> localeService
= do_GetService (NS_LOCALESERVICE_CONTRACTID
);
144 g_warning ("Could not get locale service!\n");
145 return NS_ERROR_FAILURE
;
148 rv
= localeService
->GetLocaleComponentForUserAgent (aUILang
);
152 g_warning ("Could not determine locale!\n");
153 return NS_ERROR_FAILURE
;
160 gecko_utils_init_chrome (void)
162 /* FIXME: can we just omit this on new-toolkit ? */
163 #if defined(MOZ_NSIXULCHROMEREGISTRY_SELECTSKIN) || defined(HAVE_CHROME_NSICHROMEREGISTRYSEA_H)
165 nsEmbedString uiLang
;
167 #ifdef HAVE_CHROME_NSICHROMEREGISTRYSEA_H
168 nsCOMPtr
<nsIChromeRegistrySea
> chromeRegistry
= do_GetService (NS_CHROMEREGISTRY_CONTRACTID
);
170 nsCOMPtr
<nsIXULChromeRegistry
> chromeRegistry
= do_GetService (NS_CHROMEREGISTRY_CONTRACTID
);
172 NS_ENSURE_TRUE (chromeRegistry
, NS_ERROR_FAILURE
);
174 // Set skin to 'classic' so we get native scrollbars.
175 rv
= chromeRegistry
->SelectSkin (nsEmbedCString("classic/1.0"), PR_FALSE
);
176 NS_ENSURE_SUCCESS (rv
, NS_ERROR_FAILURE
);
179 rv
= chromeRegistry
->SetRuntimeProvider(PR_TRUE
);
180 NS_ENSURE_SUCCESS (rv
, NS_ERROR_FAILURE
);
182 rv
= getUILang(uiLang
);
183 NS_ENSURE_SUCCESS (rv
, NS_ERROR_FAILURE
);
185 nsEmbedCString cUILang
;
186 NS_UTF16ToCString (uiLang
, NS_CSTRING_ENCODING_UTF8
, cUILang
);
188 return chromeRegistry
->SelectLocale (cUILang
, PR_FALSE
);
195 blam_gecko_utils_init_services (void)
199 gtk_moz_embed_set_comp_path (MOZILLA_HOME
);
201 profile_dir
= g_build_filename (g_getenv ("HOME"),
206 gtk_moz_embed_set_profile_path (profile_dir
, "blam");
207 g_free (profile_dir
);
209 gtk_moz_embed_push_startup ();
211 gecko_prefs_set_string ("font.size.unit", "pt");
212 gecko_utils_init_chrome ();
216 blam_gecko_utils_set_proxy (gboolean use_proxy
, gchar
*host
, gint port
)
219 gecko_prefs_set_int ("network.proxy.type", 0);
221 gecko_prefs_set_int ("network.proxy.type", 1);
222 gecko_prefs_set_string ("network.proxy.http", host
);
223 gecko_prefs_set_int ("network.proxy.http_port", port
);