Ejemplo n.º 1
0
static void
session_proxy_signal (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data)
{
  if (g_str_equal (signal_name, "StatusChanged"))
    {
      guint status;
      g_variant_get (parameters, "(u)", &status);
      on_session_status_changed (proxy, status, SHELL_APP_USAGE (user_data));
    }
}
Ejemplo n.º 2
0
static void
shell_app_usage_finalize (GObject *object)
{
  ShellAppUsage *self = SHELL_APP_USAGE (object);

  if (self->save_id > 0)
    g_source_remove (self->save_id);

  g_object_unref (self->privacy_settings);

  g_object_unref (self->configfile);

  g_object_unref (self->session_proxy);

  G_OBJECT_CLASS (shell_app_usage_parent_class)->finalize(object);
}
Ejemplo n.º 3
0
static void
on_app_state_changed (ShellAppSystem *app_system,
                      ShellApp       *app,
                      gpointer        user_data)
{
  ShellAppUsage *self = SHELL_APP_USAGE (user_data);
  UsageData *usage;
  gboolean running;

  if (shell_app_is_window_backed (app))
    return;

  usage = get_usage_for_app (self, app);

  running = shell_app_get_state (app) == SHELL_APP_STATE_RUNNING;

  if (running)
    usage->last_seen = get_time ();
}
Ejemplo n.º 4
0
static void
shell_app_usage_finalize (GObject *object)
{
  ShellGlobal *global;
  ShellAppUsage *self = SHELL_APP_USAGE (object);

  if (self->save_id > 0)
    g_source_remove (self->save_id);

  global = shell_global_get ();
  g_signal_handler_disconnect (shell_global_get_settings (global),
                               self->settings_notify);

  g_object_unref (self->configfile);

  g_object_unref (self->session_proxy);

  G_OBJECT_CLASS (shell_app_usage_parent_class)->finalize(object);
}
Ejemplo n.º 5
0
/* Save app data lists to file */
static gboolean
idle_save_application_usage (gpointer data)
{
  ShellAppUsage *self = SHELL_APP_USAGE (data);
  UsageIterator iter;
  const char *current_context;
  const char *context;
  const char *id;
  UsageData *usage;
  GFileOutputStream *output;
  GOutputStream *buffered_output;
  GDataOutputStream *data_output;
  GError *error = NULL;

  self->save_id = 0;

  /* Parent directory is already created by shell-global */
  output = g_file_replace (self->configfile, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error);
  if (!output)
    {
      g_debug ("Could not save applications usage data: %s", error->message);
      g_error_free (error);
      return FALSE;
    }
  buffered_output = g_buffered_output_stream_new (G_OUTPUT_STREAM (output));
  g_object_unref (output);
  data_output = g_data_output_stream_new (G_OUTPUT_STREAM (buffered_output));
  g_object_unref (buffered_output);

  if (!g_data_output_stream_put_string (data_output, "<?xml version=\"1.0\"?>\n<application-state>\n", NULL, &error))
    goto out;

  usage_iterator_init (self, &iter);

  current_context = NULL;
  while (usage_iterator_next (self, &iter, &context, &id, &usage))
    {
      ShellApp *app;

      app = shell_app_system_lookup_app (shell_app_system_get_default(), id);

      if (!app)
        continue;

      if (context != current_context)
        {
          if (current_context != NULL)
            {
              if (!g_data_output_stream_put_string (data_output, "  </context>", NULL, &error))
                goto out;
            }
          current_context = context;
          if (!g_data_output_stream_put_string (data_output, "  <context", NULL, &error))
            goto out;
          if (!write_attribute_string (data_output, "id", context, &error))
            goto out;
          if (!g_data_output_stream_put_string (data_output, ">\n", NULL, &error))
            goto out;
        }
      if (!g_data_output_stream_put_string (data_output, "    <application", NULL, &error))
        goto out;
      if (!write_attribute_string (data_output, "id", id, &error))
        goto out;
      if (!write_attribute_uint (data_output, "open-window-count", shell_app_get_n_windows (app), &error))
        goto out;

      if (!write_attribute_double (data_output, "score", usage->score, &error))
        goto out;
      if (!write_attribute_uint (data_output, "last-seen", usage->last_seen, &error))
        goto out;
      if (!g_data_output_stream_put_string (data_output, "/>\n", NULL, &error))
        goto out;
    }
  if (current_context != NULL)
    {
      if (!g_data_output_stream_put_string (data_output, "  </context>\n", NULL, &error))
        goto out;
    }
  if (!g_data_output_stream_put_string (data_output, "</application-state>\n", NULL, &error))
    goto out;

out:
  if (!error)
    g_output_stream_close_async (G_OUTPUT_STREAM (data_output), 0, NULL, NULL, NULL);
  g_object_unref (data_output);
  if (error)
    {
      g_debug ("Could not save applications usage data: %s", error->message);
      g_error_free (error);
    }
  return FALSE;
}