Example #1
0
void
mex_screensaver_uninhibit (MexScreensaver *self)
{
  MexScreensaverPrivate *priv = MEX_SCREENSAVER (self)->priv;

  GDBusProxy *proxy;
  GError *error = NULL;

  /* we're not inhibiting */
  if (priv->cookie == 0)
    return;

  if (priv->cookie)
    {
      proxy = connect_gnome_screensaverd (self);

      if (!proxy)
        return;

      if (priv->gnome_version == 2)
        {
          g_dbus_proxy_call_sync (proxy, "UnInhibit",
                                  g_variant_new ("(u)", priv->cookie),
                                  G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                  &error);
        }

      if (priv->gnome_version == 3)
        {
          g_dbus_proxy_call_sync (proxy, "Uninhibit",
                                  g_variant_new ("(u)", priv->cookie),
                                  G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                  &error);
        }

      if (error)
        {
          g_warning ("Problem uninhibiting screensaver: %s",
                     error->message);
          g_error_free (error);
        }
      else
        {
          /* reset the cookie */
          priv->cookie = 0;
        }
      g_object_unref (proxy);
    }
}
Example #2
0
void
mex_screensaver_uninhibit (MexScreensaver *self)
{
  MexScreensaverPrivate *priv = MEX_SCREENSAVER (self)->priv;

  DBusGProxy *proxy;
  GError *error = NULL;

  /* we're not inhibiting */
  if (priv->cookie == 0)
    return;

  if (priv->cookie)
    {
      proxy = connect_gnome_screensaverd (self);

      if (!proxy)
        return;

      if (priv->gnome_version == 2)
        {
          dbus_g_proxy_call (proxy, "UnInhibit", &error,
                             G_TYPE_UINT, priv->cookie,
                             G_TYPE_INVALID,
                             G_TYPE_INVALID);
        }

      if (priv->gnome_version == 3)
        {
          dbus_g_proxy_call (proxy, "Uninhibit", &error,
                             G_TYPE_UINT, priv->cookie,
                             G_TYPE_INVALID,
                             G_TYPE_INVALID);
        }

      if (error)
        {
          g_warning ("Problem uninhibiting screensaver: %s",
                     error->message);
          g_error_free (error);
        }
      else
        {
          /* reset the cookie */
          priv->cookie = 0;
        }
      g_object_unref (proxy);
    }
}
Example #3
0
void
mex_screensaver_inhibit (MexScreensaver *self)
{
  MexScreensaverPrivate *priv = MEX_SCREENSAVER (self)->priv;

  GDBusProxy *proxy;
  GError *error = NULL;
  GVariant *variant;

  /* If we're already inhibited don't inhibit again */
  if (priv->cookie > 0)
    return;

  if (priv->gnome_version == -1)
    return;

  proxy = connect_gnome_screensaverd (self);

  if (!proxy)
    return;

  /* gnome_version will be 0 if the current version has not been determined */
  if (priv->gnome_version == 0 || priv->gnome_version == 2)
    {

      if ((variant = g_dbus_proxy_call_sync (proxy, "Inhibit",
                                            g_variant_new ("(ss)",
                                                           "Media Explorer",
                                                           "Playing media"),
                                            G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                            &error)))
        {
          priv->gnome_version = 2;
          g_variant_get (variant, "(u)", &priv->cookie);
          g_object_unref (proxy);
          g_variant_unref (variant);
        }
      else
        {
          if (error->domain == G_DBUS_ERROR &&
              error->code == G_DBUS_ERROR_UNKNOWN_METHOD)
            {
              g_clear_error (&error);
              priv->gnome_version = 3;
              /* the current proxy is useless to us */
              g_object_unref (proxy);
              proxy = NULL;
            }
        }
    }
  /* The code path may originate from the bail out on G_DBUS_ERROR_UNKNOWN_METHOD
   * or if the version has been set by a previous call of the inhibit function
   * which has worked out the version.
   */
  if (priv->gnome_version == 3)
    {
      /* proxy maybe null if the proxy was a gnome 2 proxy */
      if (!proxy)
        proxy = connect_gnome_screensaverd (self);

      /* 8 = GSM_INHIBITOR_FLAG_IDLE */
      if ((variant = g_dbus_proxy_call_sync (proxy, "Inhibit",
                                            g_variant_new ("(susu)",
                                                           "MediaExplorer",
                                                           0, "Playing media", 8),
                                            G_DBUS_CALL_FLAGS_NONE, -1, NULL,
                                            &error)))
        {
          priv->gnome_version = 3;
          g_variant_get (variant, "(u)", &priv->cookie);
          g_object_unref (proxy);
          g_variant_unref (variant);
        }
      else
        {
          if (error->domain == G_DBUS_ERROR &&
              error->code == G_DBUS_ERROR_UNKNOWN_METHOD)
            {
              g_clear_error (&error);
              priv->gnome_version = -1;
              g_object_unref (proxy);
              proxy = NULL;
            }
        }
    }

  if (error)
    {
      g_warning ("Problem inhibiting screensaver: %s", error->message);
      g_error_free (error);
    }
}
Example #4
0
void
mex_screensaver_inhibit (MexScreensaver *self)
{
  MexScreensaverPrivate *priv = MEX_SCREENSAVER (self)->priv;

  DBusGProxy *proxy;
  GError *error = NULL;

  /* If we're already inhibited don't inhibit again */
  if (priv->cookie > 0)
    return;

  if (priv->gnome_version == -1)
    return;

    proxy = connect_gnome_screensaverd (self);

  if (!proxy)
    return;

  /* gnome_version will be 0 if the current version has not been determined */
  if (priv->gnome_version == 0 || priv->gnome_version == 2)
    {
      if(dbus_g_proxy_call (proxy, "Inhibit", &error,
                            G_TYPE_STRING, "Media Explorer",
                            G_TYPE_STRING , "Playing media",
                            G_TYPE_INVALID,
                            G_TYPE_UINT, &priv->cookie,
                            G_TYPE_INVALID))
        {
          priv->gnome_version = 2;
          g_object_unref (proxy);
        }
      else
        {
          if (error->domain == DBUS_GERROR &&
              error->code == DBUS_GERROR_UNKNOWN_METHOD)
            {
              g_clear_error (&error);
              priv->gnome_version = 3;
              /* the current proxy is useless to us */
              g_object_unref (proxy);
              proxy = NULL;
            }
        }
    }
  /* The code path may originate from the bail out on DBUS_GERROR_UNKNOWN_METHOD
   * or if the version has been set by a previous call of the inhibit function
   * which has worked out the version.
   */
  if (priv->gnome_version == 3)
    {
      /* proxy maybe null if the proxy was a gnome 2 proxy */
      if (!proxy)
        proxy = connect_gnome_screensaverd (self);

      /* 8 = GSM_INHIBITOR_FLAG_IDLE */
      if (dbus_g_proxy_call (proxy, "Inhibit", &error,
                             G_TYPE_STRING, "MediaExplorer",
                             G_TYPE_UINT, 0,
                             G_TYPE_STRING , "Playing media",
                             G_TYPE_UINT, 8,
                             G_TYPE_INVALID,
                             G_TYPE_UINT, &priv->cookie,
                             G_TYPE_INVALID))
        {
          priv->gnome_version = 3;
        }
      else
        {
          if (error->domain == DBUS_GERROR &&
              error->code == DBUS_GERROR_UNKNOWN_METHOD)
            {
              g_clear_error (&error);
              priv->gnome_version = -1;
              g_object_unref (proxy);
              proxy = NULL;
            }
        }
    }

  if (error)
    {
      g_warning ("Problem inhibiting screensaver: %s", error->message);
      g_error_free (error);
    }
}