+auth_response_cb (GtkWidget *dialog,
+ int response,
+ MilkAuth *auth)
+
+{
+ MilkAuthPrivate *priv;
+ GError *error = NULL;
+ gchar *auth_token;
+ gchar *username;
+ MilkAuthState previous_state;
+
+ priv = MILK_AUTH_PRIVATE (auth);
+
+ previous_state = priv->state;
+ auth_token = rtm_glib_auth_get_token (priv->rtm_glib, priv->frob,
+ &error);
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ goto auth_response_cb_error_OUT;
+ }
+
+ if (!rtm_glib_auth_check_token (priv->rtm_glib, auth_token, NULL)) {
+ g_error ("auth_token not valid!\n");
+ goto auth_response_cb_error_OUT;
+ }
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ goto auth_response_cb_error_OUT;
+ }
+ username = rtm_glib_test_login (priv->rtm_glib, auth_token, &error);
+
+ g_free (auth_token);
+
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ goto auth_response_cb_error_OUT;
+ }
+
+ priv->state = MILK_AUTH_STATE_CONNECTED;
+ goto auth_response_cb_OUT;
+
+auth_response_cb_error_OUT:
+ priv->state = MILK_AUTH_STATE_DISCONNECTED;
+
+auth_response_cb_OUT:
+ if (priv->state != previous_state)
+ g_object_notify (G_OBJECT (auth), "state");
+
+ gtk_widget_destroy (dialog);
+}
+
+GList *
+milk_auth_get_tasks (MilkAuth *auth)
+{
+ MilkAuthPrivate *priv;
+ GError *error = NULL;
+ GList *rtm_tasks;
+
+ g_return_val_if_fail (auth, NULL);
+ g_return_val_if_fail (MILK_IS_AUTH (auth), NULL);
+ g_return_val_if_fail (
+ milk_auth_get_state (auth) == MILK_AUTH_STATE_CONNECTED,
+ NULL);
+
+ priv = MILK_AUTH_PRIVATE (auth);
+
+ /* FIXME: cache this */
+ rtm_tasks = rtm_glib_tasks_get_list (priv->rtm_glib, NULL, NULL, NULL,
+ &error);
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ return NULL;
+ }
+
+ return rtm_tasks;
+}
+
+void
+milk_auth_log_in (MilkAuth *auth)
+{
+ MilkAuthPrivate *priv;
+ GError *error = NULL;
+ gchar *url;
+ GtkDialog *dialog;
+
+ g_return_if_fail (auth);
+ g_return_if_fail (MILK_IS_AUTH (auth));
+
+ priv = MILK_AUTH_PRIVATE (auth);
+
+ if (rtm_glib_test_echo (priv->rtm_glib, &error)) {
+ g_print ("Test echo OK!\n");
+ } else {
+ g_print ("Test echo FAIL!\n");
+ return;
+ }
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ return;
+ }
+
+ /* FIXME: relocate this */
+ if (priv->frob)
+ g_free (priv->frob);
+
+ priv->frob = rtm_glib_auth_get_frob (priv->rtm_glib, &error);
+ if (error != NULL) {
+ g_error ("%s", rtm_error_get_message (error));
+ return;
+ }
+ g_print ("Frob: %s\n", priv->frob);
+
+ url = rtm_glib_auth_get_login_url (priv->rtm_glib, priv->frob,
+ "delete");
+ g_print ("URL: %s\n", url);
+
+ dialog = milk_dialogs_auth_prompt (NULL, url);
+
+ g_signal_connect (dialog, "response", G_CALLBACK (auth_response_cb),
+ auth);
+}
+
+static void