Bug 597811: Make mozJSComponentLoader use JSVERSION_LATEST. (r=sayrer)
[mozilla-central.git] / toolkit / xre / nsNativeAppSupportQt.cpp
blobfe9b9075c17f381c1d19c335cba878c359f2a586
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 et sw=2 tw=80: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Corporation code.
18 * The Initial Developer of the Original Code is Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Oleg Romashin <romaxa@gmail.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include <stdlib.h>
40 #include "nsNativeAppSupportBase.h"
41 #include "nsString.h"
43 #ifdef MOZ_ENABLE_LIBCONIC
44 #include <glib-object.h>
45 #endif
47 #if (MOZ_PLATFORM_MAEMO == 5)
48 #include <libosso.h>
49 #endif
51 class nsNativeAppSupportQt : public nsNativeAppSupportBase
53 public:
54 NS_IMETHOD Start(PRBool* aRetVal);
55 NS_IMETHOD Stop(PRBool* aResult);
56 #if (MOZ_PLATFORM_MAEMO == 5)
57 // Osso context must be initialized for maemo5 otherwise we will be killed in ~20 seconds
58 osso_context_t *m_osso_context;
59 #endif
62 NS_IMETHODIMP
63 nsNativeAppSupportQt::Start(PRBool* aRetVal)
65 NS_ASSERTION(gAppData, "gAppData must not be null.");
67 *aRetVal = PR_TRUE;
68 #ifdef MOZ_ENABLE_LIBCONIC
69 g_type_init();
70 #endif
72 #if (MOZ_PLATFORM_MAEMO == 5)
73 /* Initialize maemo application
75 The initalization name will be of the form "Vendor.Name".
76 If a Vendor isn't given, then we will just use "Name".
78 Note that this value must match your X-Osso-Service name
79 defined in your desktop file. If it doesn't, the OSSO
80 system will happily kill your process.
82 nsCAutoString applicationName;
83 if (gAppData->vendor) {
84 applicationName.Append(gAppData->vendor);
85 applicationName.Append(".");
87 applicationName.Append(gAppData->name);
88 ToLowerCase(applicationName);
90 m_osso_context = osso_initialize(applicationName.get(),
91 gAppData->version ? gAppData->version : "1.0",
92 PR_TRUE,
93 nsnull);
95 /* Check that initilialization was ok */
96 if (m_osso_context == nsnull) {
97 return NS_ERROR_FAILURE;
99 #endif
101 return NS_OK;
104 NS_IMETHODIMP
105 nsNativeAppSupportQt::Stop(PRBool* aResult)
107 NS_ENSURE_ARG(aResult);
108 *aResult = PR_TRUE;
110 #if (MOZ_PLATFORM_MAEMO == 5)
111 if (m_osso_context) {
112 osso_deinitialize(m_osso_context);
113 m_osso_context = nsnull;
115 #endif
117 return NS_OK;
120 nsresult
121 NS_CreateNativeAppSupport(nsINativeAppSupport** aResult)
123 nsNativeAppSupportBase* native = new nsNativeAppSupportQt();
124 if (!native)
125 return NS_ERROR_OUT_OF_MEMORY;
127 *aResult = native;
128 NS_ADDREF(*aResult);
130 return NS_OK;