示例#1
0
static void
ensure_credentials_cb (GoaProvider   *provider,
                       GAsyncResult  *res,
                       gpointer       user_data)
{
  EnsureData *data = user_data;
  gint expires_in;
  GError *error;

  error= NULL;
  if (!goa_provider_ensure_credentials_finish (provider, &expires_in, res, &error))
    {
      /* Set AttentionNeeded only if the error is an authorization error */
      if (is_authorization_error (error))
        {
          GoaAccount *account;
          account = goa_object_peek_account (data->object);
          if (!goa_account_get_attention_needed (account))
            {
              goa_account_set_attention_needed (account, TRUE);
              g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (account));
              g_message ("%s: Setting AttentionNeeded to TRUE because EnsureCredentials() failed with: %s (%s, %d)",
                         g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object)),
                         error->message, g_quark_to_string (error->domain), error->code);
            }
        }
      g_dbus_method_invocation_return_gerror (data->invocation, error);
      g_error_free (error);
    }
  else
    {
      GoaAccount *account;
      account = goa_object_peek_account (data->object);

      /* Clear AttentionNeeded flag if set */
      if (goa_account_get_attention_needed (account))
        {
          goa_account_set_attention_needed (account, FALSE);
          g_dbus_interface_skeleton_flush (G_DBUS_INTERFACE_SKELETON (account));
          g_message ("%s: Setting AttentionNeeded to FALSE because EnsureCredentials() succeded\n",
                     g_dbus_object_get_object_path (G_DBUS_OBJECT (data->object)));
        }
      goa_account_complete_ensure_credentials (goa_object_peek_account (data->object),
                                               data->invocation,
                                               expires_in);
    }
  ensure_data_unref (data);
}
static void
set_values (GoaPanelAccountsModel  *model,
            GoaObject              *object,
            GtkTreeIter            *iter)
{
  GoaAccount *account;
  GIcon *icon;
  gchar *markup;
  GError *error;

  account = goa_object_peek_account (object);

  error = NULL;
  icon = g_icon_new_for_string (goa_account_get_provider_icon (account), &error);
  if (icon == NULL)
    {
      goa_warning ("Error creating GIcon for account: %s (%s, %d)",
                   error->message, g_quark_to_string (error->domain), error->code);
      g_error_free (error);
    }

  markup = g_strdup_printf ("<b>%s</b>\n<small>%s</small>",
                            goa_account_get_provider_name (account),
                            goa_account_get_presentation_identity (account));

  gtk_list_store_set (GTK_LIST_STORE (model),
                      iter,
                      GOA_PANEL_ACCOUNTS_MODEL_COLUMN_SORT_KEY, goa_account_get_id (account),
                      GOA_PANEL_ACCOUNTS_MODEL_COLUMN_OBJECT, object,
                      GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ATTENTION_NEEDED, goa_account_get_attention_needed (account),
                      GOA_PANEL_ACCOUNTS_MODEL_COLUMN_MARKUP, markup,
                      GOA_PANEL_ACCOUNTS_MODEL_COLUMN_ICON, icon,
                      -1);

  g_free (markup);
  g_clear_object (&icon);
}
示例#3
0
static void
goa_daemon_update_notifications (GoaDaemon *daemon)
{
  gboolean show_notification;
  GList *objects;
  GList *l;

  show_notification = FALSE;
  objects = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (daemon->object_manager));
  for (l = objects; l != NULL; l = l->next)
    {
      GoaObject *object = GOA_OBJECT (l->data);
      GoaAccount *account;
      account = goa_object_peek_account (object);
      if (account != NULL)
        {
          if (goa_account_get_attention_needed (account))
            {
              show_notification = TRUE;
              break;
            }
        }
    }

  if (show_notification)
    {
      if (daemon->notification == NULL)
        {
          GError *error;

          daemon->notification = notify_notification_new (_("An online account needs attention"),
                                                          NULL,
                                                          NULL);
          notify_notification_set_timeout (daemon->notification, NOTIFY_EXPIRES_NEVER);
          g_object_set (daemon->notification, "icon-name", "gtk-dialog-error", NULL);
          notify_notification_add_action (daemon->notification,
                                          "open-online-accounts",
                                          _("Open Online Accounts..."),
                                          notification_cb,
                                          daemon,
                                          NULL); /* GFreeFunc */

          error = NULL;
          if (!notify_notification_show (daemon->notification, &error))
            {
              goa_warning ("Error showing notification: %s (%s, %d)",
                           error->message, g_quark_to_string (error->domain), error->code);
              g_error_free (error);
              g_object_unref (daemon->notification);
              daemon->notification = NULL;
            }
          else
            {
              g_signal_connect (daemon->notification,
                                "closed",
                                G_CALLBACK (on_notification_closed),
                                daemon);
            }
        }
    }
  else
    {
      if (daemon->notification != NULL)
        {
          GError *error;
          error = NULL;
          if (!notify_notification_close (daemon->notification, &error))
            {
              goa_warning ("Error closing notification: %s (%s, %d)",
                           error->message, g_quark_to_string (error->domain), error->code);
              g_error_free (error);
            }
          g_signal_handlers_disconnect_by_func (daemon->notification,
                                                G_CALLBACK (on_notification_closed),
                                                daemon);
          g_object_unref (daemon->notification);
          daemon->notification = NULL;
        }
    }

  g_list_foreach (objects, (GFunc) g_object_unref, NULL);
  g_list_free (objects);
}
static void
show_page_account (GoaPanel  *panel,
                   GoaObject *object)
{
  GList *children;
  GList *l;
  GtkWidget *box;
  GtkWidget *grid;
  GtkWidget *left_grid;
  GtkWidget *right_grid;
  GtkWidget *bar;
  GtkWidget *label;
  GoaProvider *provider;
  GoaAccount *account;
  const gchar *provider_type;

  provider = NULL;

  show_page (panel, 1);
  box = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-box"));
  gtk_widget_set_sensitive (box, TRUE);

  label = GTK_WIDGET (gtk_builder_get_object (panel->builder, "accounts-tree-label"));
  gtk_widget_hide (label);

  /* Out with the old */
  children = gtk_container_get_children (GTK_CONTAINER (panel->accounts_vbox));
  for (l = children; l != NULL; l = l->next)
    gtk_container_remove (GTK_CONTAINER (panel->accounts_vbox), GTK_WIDGET (l->data));
  g_list_free (children);

  account = goa_object_peek_account (object);
  provider_type = goa_account_get_provider_type (account);
  provider = goa_provider_get_for_provider_type (provider_type);

  /* And in with the new */
  if (goa_account_get_attention_needed (account))
    {
      bar = gtk_info_bar_new ();
      label = gtk_label_new (_("Expired credentials. Please log in again."));
      gtk_container_add (GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))), label);
      if (provider != NULL)
        gtk_info_bar_add_button (GTK_INFO_BAR (bar), _("_Log In"), GTK_RESPONSE_OK);
      gtk_box_pack_start (GTK_BOX (panel->accounts_vbox), bar, FALSE, TRUE, 0);
      g_signal_connect (bar, "response", G_CALLBACK (on_info_bar_response), panel);
    }

  left_grid = gtk_grid_new ();
  gtk_widget_set_halign (left_grid, GTK_ALIGN_END);
  gtk_widget_set_hexpand (left_grid, TRUE);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (left_grid), GTK_ORIENTATION_VERTICAL);
  gtk_grid_set_row_spacing (GTK_GRID (left_grid), 0);

  right_grid = gtk_grid_new ();
  gtk_widget_set_hexpand (right_grid, TRUE);
  gtk_orientable_set_orientation (GTK_ORIENTABLE (right_grid), GTK_ORIENTATION_VERTICAL);
  gtk_grid_set_row_spacing (GTK_GRID (right_grid), 0);

  if (provider != NULL)
    {
      goa_provider_show_account (provider,
                                 panel->client,
                                 object,
                                 GTK_BOX (panel->accounts_vbox),
                                 GTK_GRID (left_grid),
                                 GTK_GRID (right_grid));
    }

  grid = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_HORIZONTAL);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
  gtk_container_add (GTK_CONTAINER (grid), left_grid);
  gtk_container_add (GTK_CONTAINER (grid), right_grid);
  gtk_box_pack_start (GTK_BOX (panel->accounts_vbox), grid, FALSE, TRUE, 0);

  gtk_widget_show_all (panel->accounts_vbox);

  if (provider != NULL)
    g_object_unref (provider);
}