Bumping manifests a=b2g-bump
[gecko.git] / toolkit / xre / nsNativeAppSupportQt.cpp
blob98ea4805e72575bba5e8cddf0410cd411a32bfd6
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 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include <stdlib.h>
8 #include <QTimer>
9 #include "mozilla/ipc/GeckoChildProcessHost.h"
10 #include "nsNativeAppSupportQt.h"
11 #include "nsCOMPtr.h"
12 #include "nsIObserverService.h"
13 #include "mozilla/Services.h"
15 #ifdef MOZ_ENABLE_QMSYSTEM2
16 void
17 nsNativeAppSupportQt::activityChanged(MeeGo::QmActivity::Activity activity)
19 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
20 if (!os)
21 return;
23 if (MeeGo::QmActivity::Inactive == activity) {
24 os->NotifyObservers(nullptr, "system-idle", nullptr);
25 } else {
26 os->NotifyObservers(nullptr, "system-active", nullptr);
30 void
31 nsNativeAppSupportQt::displayStateChanged(MeeGo::QmDisplayState::DisplayState state)
33 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
34 if (!os)
35 return;
37 switch (state) {
38 case MeeGo::QmDisplayState::On:
39 os->NotifyObservers(nullptr, "system-display-on", nullptr);
40 break;
41 case MeeGo::QmDisplayState::Off:
42 os->NotifyObservers(nullptr, "system-display-off", nullptr);
43 break;
44 case MeeGo::QmDisplayState::Dimmed:
45 os->NotifyObservers(nullptr, "system-display-dimmed", nullptr);
46 break;
47 default:
48 NS_WARNING("Unknown display state");
49 break;
53 void nsNativeAppSupportQt::deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode mode)
55 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
56 if (!os)
57 return;
59 switch (mode) {
60 case MeeGo::QmDeviceMode::DeviceMode::Normal:
61 os->NotifyObservers(nullptr, "profile-change-net-restore", nullptr);
62 break;
63 case MeeGo::QmDeviceMode::DeviceMode::Flight:
64 os->NotifyObservers(nullptr, "profile-change-net-teardown", nullptr);
65 break;
66 case MeeGo::QmDeviceMode::DeviceMode::Error:
67 default:
68 NS_WARNING("Unknown DeviceMode");
69 break;
73 void nsNativeAppSupportQt::RefreshStates()
75 activityChanged(mActivity.get());
76 displayStateChanged(mDisplayState.get());
77 deviceModeChanged(mDeviceMode.getMode());
79 #endif
81 NS_IMETHODIMP
82 nsNativeAppSupportQt::Start(bool* aRetVal)
84 NS_ASSERTION(gAppData, "gAppData must not be null.");
86 #ifdef MOZ_ENABLE_QMSYSTEM2
87 connect(&mActivity, SIGNAL(activityChanged(MeeGo::QmActivity::Activity)), this, SLOT(activityChanged(MeeGo::QmActivity::Activity)));
88 connect(&mDeviceMode, SIGNAL(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode)), this, SLOT(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode)));
89 connect(&mDisplayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(displayStateChanged(MeeGo::QmDisplayState::DisplayState)));
90 // Init states withing next event loop iteration
91 QTimer::singleShot(0, this, SLOT(RefreshStates()));
92 #endif
94 *aRetVal = true;
95 return NS_OK;
98 NS_IMETHODIMP
99 nsNativeAppSupportQt::Stop(bool* aResult)
101 NS_ENSURE_ARG(aResult);
102 *aResult = true;
104 return NS_OK;
107 nsresult
108 NS_CreateNativeAppSupport(nsINativeAppSupport** aResult)
110 nsNativeAppSupportBase* native = new nsNativeAppSupportQt();
111 if (!native)
112 return NS_ERROR_OUT_OF_MEMORY;
114 *aResult = native;
115 NS_ADDREF(*aResult);
117 return NS_OK;