|
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/. */ |
|
6 |
|
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" |
|
14 |
|
15 #ifdef MOZ_ENABLE_QMSYSTEM2 |
|
16 void |
|
17 nsNativeAppSupportQt::activityChanged(MeeGo::QmActivity::Activity activity) |
|
18 { |
|
19 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
|
20 if (!os) |
|
21 return; |
|
22 |
|
23 if (MeeGo::QmActivity::Inactive == activity) { |
|
24 os->NotifyObservers(nullptr, "system-idle", nullptr); |
|
25 } else { |
|
26 os->NotifyObservers(nullptr, "system-active", nullptr); |
|
27 } |
|
28 } |
|
29 |
|
30 void |
|
31 nsNativeAppSupportQt::displayStateChanged(MeeGo::QmDisplayState::DisplayState state) |
|
32 { |
|
33 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
|
34 if (!os) |
|
35 return; |
|
36 |
|
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; |
|
50 } |
|
51 } |
|
52 |
|
53 void nsNativeAppSupportQt::deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode mode) |
|
54 { |
|
55 nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
|
56 if (!os) |
|
57 return; |
|
58 |
|
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; |
|
70 } |
|
71 } |
|
72 |
|
73 void nsNativeAppSupportQt::RefreshStates() |
|
74 { |
|
75 activityChanged(mActivity.get()); |
|
76 displayStateChanged(mDisplayState.get()); |
|
77 deviceModeChanged(mDeviceMode.getMode()); |
|
78 } |
|
79 #endif |
|
80 |
|
81 NS_IMETHODIMP |
|
82 nsNativeAppSupportQt::Start(bool* aRetVal) |
|
83 { |
|
84 NS_ASSERTION(gAppData, "gAppData must not be null."); |
|
85 |
|
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 |
|
93 |
|
94 *aRetVal = true; |
|
95 return NS_OK; |
|
96 } |
|
97 |
|
98 NS_IMETHODIMP |
|
99 nsNativeAppSupportQt::Stop(bool* aResult) |
|
100 { |
|
101 NS_ENSURE_ARG(aResult); |
|
102 *aResult = true; |
|
103 |
|
104 return NS_OK; |
|
105 } |
|
106 |
|
107 nsresult |
|
108 NS_CreateNativeAppSupport(nsINativeAppSupport** aResult) |
|
109 { |
|
110 nsNativeAppSupportBase* native = new nsNativeAppSupportQt(); |
|
111 if (!native) |
|
112 return NS_ERROR_OUT_OF_MEMORY; |
|
113 |
|
114 *aResult = native; |
|
115 NS_ADDREF(*aResult); |
|
116 |
|
117 return NS_OK; |
|
118 } |