char *api_key;
char *shared_secret;
char *frob;
+ MilkAuthState state;
};
enum {
PROP_API_KEY = 1,
PROP_SHARED_SECRET,
+ PROP_STATE,
};
static MilkAuth *default_auth = NULL;
+MilkAuthState
+milk_auth_get_state (MilkAuth *auth)
+{
+ g_return_val_if_fail (auth, MILK_AUTH_STATE_DISCONNECTED);
+ g_return_val_if_fail (MILK_IS_AUTH (auth),
+ MILK_AUTH_STATE_DISCONNECTED);
+
+ return MILK_AUTH_PRIVATE (auth)->state;
+}
+
static void
milk_auth_get_property (GObject *object,
guint property_id,
g_value_set_string (value, priv->shared_secret);
break;
+ case PROP_STATE:
+ g_value_set_int (value, priv->state);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
pspec);
priv->shared_secret = g_value_dup_string (value);
break;
+ case PROP_STATE:
+ priv->state = g_value_get_int (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
pspec);
{
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_OUT;
+ goto auth_response_cb_error_OUT;
}
if (!rtm_glib_auth_check_token (priv->rtm_glib, auth_token, NULL)) {
}
if (error != NULL) {
g_error ("%s", rtm_error_get_message (error));
- goto auth_response_cb_OUT;
+ goto auth_response_cb_error_OUT;
}
username = rtm_glib_test_login (priv->rtm_glib, auth_token, &error);
if (error != NULL) {
g_error ("%s", rtm_error_get_message (error));
- goto auth_response_cb_OUT;
+ goto auth_response_cb_error_OUT;
}
- /* FIXME: work this in where appropriate */
-#if 0
- glist = rtm_glib_tasks_get_list (priv->rtm_glib, NULL, NULL, NULL, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- for (item = glist; item; item = g_list_next (item)) {
- task = (RtmTask *) item->data;
- g_print ("%s", rtm_task_to_string (task));
- }
- g_list_free (glist);
+ priv->state = MILK_AUTH_STATE_CONNECTED;
+ goto auth_response_cb_OUT;
- glist = rtm_glib_lists_get_list (priv->rtm_glib, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- goto auth_response_cb_OUT;
- }
- for (item = glist; item; item = g_list_next (item)) {
- rtm_list = (RtmList *) item->data;
- if (g_strcmp0 (rtm_list_get_name (rtm_list), "Sent") == 0) {
- list_id_sent = rtm_list_get_id (rtm_list);
- }
- g_print ("%s", rtm_list_to_string (rtm_list));
- }
- g_list_free (glist);
+auth_response_cb_error_OUT:
+ priv->state = MILK_AUTH_STATE_DISCONNECTED;
- timeline = rtm_glib_timelines_create (priv->rtm_glib, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- g_print ("timeline: %s", timeline);
+auth_response_cb_OUT:
+ if (priv->state != previous_state)
+ g_object_notify (G_OBJECT (auth), "state");
- task = rtm_glib_tasks_add (priv->rtm_glib, timeline, "test-rtm-glib", NULL, FALSE, &error);
+ 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));
- goto auth_response_cb_OUT;
- }
- if (task != NULL) {
- g_print ("First task added! task_id: %s\n", rtm_task_get_id (task));
- } else {
- g_print ("First task NOT added!\n");
- goto auth_response_cb_OUT;
+ return NULL;
}
-
-#endif
-
-auth_response_cb_OUT:
- gtk_widget_destroy (dialog);
+
+ 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)) {
auth);
}
-
static void
milk_auth_constructed (GObject *object)
{
RTM_SHARED_SECRET,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
+ (object_class,
+ PROP_STATE,
+ g_param_spec_int
+ ("state",
+ "Authentication state",
+ "Authentication/connection state with the server.",
+ 0, (NUM_MILK_AUTH_STATES-1),
+ MILK_AUTH_STATE_DISCONNECTED,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
}
static void