michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include "mozilla/ipc/GeckoChildProcessHost.h" michael@0: #include "nsNativeAppSupportQt.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIObserverService.h" michael@0: #include "mozilla/Services.h" michael@0: michael@0: #ifdef MOZ_ENABLE_QMSYSTEM2 michael@0: void michael@0: nsNativeAppSupportQt::activityChanged(MeeGo::QmActivity::Activity activity) michael@0: { michael@0: nsCOMPtr os = mozilla::services::GetObserverService(); michael@0: if (!os) michael@0: return; michael@0: michael@0: if (MeeGo::QmActivity::Inactive == activity) { michael@0: os->NotifyObservers(nullptr, "system-idle", nullptr); michael@0: } else { michael@0: os->NotifyObservers(nullptr, "system-active", nullptr); michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsNativeAppSupportQt::displayStateChanged(MeeGo::QmDisplayState::DisplayState state) michael@0: { michael@0: nsCOMPtr os = mozilla::services::GetObserverService(); michael@0: if (!os) michael@0: return; michael@0: michael@0: switch (state) { michael@0: case MeeGo::QmDisplayState::On: michael@0: os->NotifyObservers(nullptr, "system-display-on", nullptr); michael@0: break; michael@0: case MeeGo::QmDisplayState::Off: michael@0: os->NotifyObservers(nullptr, "system-display-off", nullptr); michael@0: break; michael@0: case MeeGo::QmDisplayState::Dimmed: michael@0: os->NotifyObservers(nullptr, "system-display-dimmed", nullptr); michael@0: break; michael@0: default: michael@0: NS_WARNING("Unknown display state"); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: void nsNativeAppSupportQt::deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode mode) michael@0: { michael@0: nsCOMPtr os = mozilla::services::GetObserverService(); michael@0: if (!os) michael@0: return; michael@0: michael@0: switch (mode) { michael@0: case MeeGo::QmDeviceMode::DeviceMode::Normal: michael@0: os->NotifyObservers(nullptr, "profile-change-net-restore", nullptr); michael@0: break; michael@0: case MeeGo::QmDeviceMode::DeviceMode::Flight: michael@0: os->NotifyObservers(nullptr, "profile-change-net-teardown", nullptr); michael@0: break; michael@0: case MeeGo::QmDeviceMode::DeviceMode::Error: michael@0: default: michael@0: NS_WARNING("Unknown DeviceMode"); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: void nsNativeAppSupportQt::RefreshStates() michael@0: { michael@0: activityChanged(mActivity.get()); michael@0: displayStateChanged(mDisplayState.get()); michael@0: deviceModeChanged(mDeviceMode.getMode()); michael@0: } michael@0: #endif michael@0: michael@0: NS_IMETHODIMP michael@0: nsNativeAppSupportQt::Start(bool* aRetVal) michael@0: { michael@0: NS_ASSERTION(gAppData, "gAppData must not be null."); michael@0: michael@0: #ifdef MOZ_ENABLE_QMSYSTEM2 michael@0: connect(&mActivity, SIGNAL(activityChanged(MeeGo::QmActivity::Activity)), this, SLOT(activityChanged(MeeGo::QmActivity::Activity))); michael@0: connect(&mDeviceMode, SIGNAL(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode)), this, SLOT(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode))); michael@0: connect(&mDisplayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(displayStateChanged(MeeGo::QmDisplayState::DisplayState))); michael@0: // Init states withing next event loop iteration michael@0: QTimer::singleShot(0, this, SLOT(RefreshStates())); michael@0: #endif michael@0: michael@0: *aRetVal = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsNativeAppSupportQt::Stop(bool* aResult) michael@0: { michael@0: NS_ENSURE_ARG(aResult); michael@0: *aResult = true; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: NS_CreateNativeAppSupport(nsINativeAppSupport** aResult) michael@0: { michael@0: nsNativeAppSupportBase* native = new nsNativeAppSupportQt(); michael@0: if (!native) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: *aResult = native; michael@0: NS_ADDREF(*aResult); michael@0: michael@0: return NS_OK; michael@0: }