toolkit/xre/nsNativeAppSupportQt.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/xre/nsNativeAppSupportQt.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=8 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include <stdlib.h>
    1.11 +#include <QTimer>
    1.12 +#include "mozilla/ipc/GeckoChildProcessHost.h"
    1.13 +#include "nsNativeAppSupportQt.h"
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsIObserverService.h"
    1.16 +#include "mozilla/Services.h"
    1.17 +
    1.18 +#ifdef MOZ_ENABLE_QMSYSTEM2
    1.19 +void
    1.20 +nsNativeAppSupportQt::activityChanged(MeeGo::QmActivity::Activity activity)
    1.21 +{
    1.22 +    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
    1.23 +    if (!os)
    1.24 +        return;
    1.25 +
    1.26 +    if (MeeGo::QmActivity::Inactive == activity) {
    1.27 +        os->NotifyObservers(nullptr, "system-idle", nullptr);
    1.28 +    } else {
    1.29 +        os->NotifyObservers(nullptr, "system-active", nullptr);
    1.30 +    }
    1.31 +}
    1.32 +
    1.33 +void
    1.34 +nsNativeAppSupportQt::displayStateChanged(MeeGo::QmDisplayState::DisplayState state)
    1.35 +{
    1.36 +    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
    1.37 +    if (!os)
    1.38 +        return;
    1.39 +
    1.40 +    switch (state) {
    1.41 +    case MeeGo::QmDisplayState::On:
    1.42 +        os->NotifyObservers(nullptr, "system-display-on", nullptr);
    1.43 +        break;
    1.44 +    case MeeGo::QmDisplayState::Off:
    1.45 +        os->NotifyObservers(nullptr, "system-display-off", nullptr);
    1.46 +        break;
    1.47 +    case MeeGo::QmDisplayState::Dimmed:
    1.48 +        os->NotifyObservers(nullptr, "system-display-dimmed", nullptr);
    1.49 +        break;
    1.50 +    default:
    1.51 +        NS_WARNING("Unknown display state");
    1.52 +        break;
    1.53 +    }
    1.54 +}
    1.55 +
    1.56 +void nsNativeAppSupportQt::deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode mode)
    1.57 +{
    1.58 +    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
    1.59 +    if (!os)
    1.60 +        return;
    1.61 +
    1.62 +    switch (mode) {
    1.63 +    case MeeGo::QmDeviceMode::DeviceMode::Normal:
    1.64 +        os->NotifyObservers(nullptr, "profile-change-net-restore", nullptr);
    1.65 +        break;
    1.66 +    case MeeGo::QmDeviceMode::DeviceMode::Flight:
    1.67 +        os->NotifyObservers(nullptr, "profile-change-net-teardown", nullptr);
    1.68 +        break;
    1.69 +    case MeeGo::QmDeviceMode::DeviceMode::Error:
    1.70 +    default:
    1.71 +        NS_WARNING("Unknown DeviceMode");
    1.72 +        break;
    1.73 +    }
    1.74 +}
    1.75 +
    1.76 +void nsNativeAppSupportQt::RefreshStates()
    1.77 +{
    1.78 +  activityChanged(mActivity.get());
    1.79 +  displayStateChanged(mDisplayState.get());
    1.80 +  deviceModeChanged(mDeviceMode.getMode());
    1.81 +}
    1.82 +#endif
    1.83 +
    1.84 +NS_IMETHODIMP
    1.85 +nsNativeAppSupportQt::Start(bool* aRetVal)
    1.86 +{
    1.87 +  NS_ASSERTION(gAppData, "gAppData must not be null.");
    1.88 +
    1.89 +#ifdef MOZ_ENABLE_QMSYSTEM2
    1.90 +  connect(&mActivity, SIGNAL(activityChanged(MeeGo::QmActivity::Activity)), this, SLOT(activityChanged(MeeGo::QmActivity::Activity)));
    1.91 +  connect(&mDeviceMode, SIGNAL(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode)), this, SLOT(deviceModeChanged(MeeGo::QmDeviceMode::DeviceMode)));
    1.92 +  connect(&mDisplayState, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)), this, SLOT(displayStateChanged(MeeGo::QmDisplayState::DisplayState)));
    1.93 +  // Init states withing next event loop iteration
    1.94 +  QTimer::singleShot(0, this, SLOT(RefreshStates()));
    1.95 +#endif
    1.96 +
    1.97 +  *aRetVal = true;
    1.98 +  return NS_OK;
    1.99 +}
   1.100 +
   1.101 +NS_IMETHODIMP
   1.102 +nsNativeAppSupportQt::Stop(bool* aResult)
   1.103 +{
   1.104 +  NS_ENSURE_ARG(aResult);
   1.105 +  *aResult = true;
   1.106 +
   1.107 +  return NS_OK;
   1.108 +}
   1.109 +
   1.110 +nsresult
   1.111 +NS_CreateNativeAppSupport(nsINativeAppSupport** aResult)
   1.112 +{
   1.113 +  nsNativeAppSupportBase* native = new nsNativeAppSupportQt();
   1.114 +  if (!native)
   1.115 +    return NS_ERROR_OUT_OF_MEMORY;
   1.116 +
   1.117 +  *aResult = native;
   1.118 +  NS_ADDREF(*aResult);
   1.119 +
   1.120 +  return NS_OK;
   1.121 +}

mercurial