milk_SOURCES = \
milk-auth.c \
milk-auth.h \
+ milk-dialogs.c \
+ milk-dialogs.h \
milk-main.c \
milk-main.h \
milk-main-window.c \
#include <rtm-glib/rtm-glib.h>
#include "milk-auth.h"
+#include "milk-dialogs.h"
G_DEFINE_TYPE (MilkAuth, milk_auth, G_TYPE_OBJECT);
RtmGlib *rtm_glib;
char *api_key;
char *shared_secret;
+ char *frob;
};
enum {
}
}
-void
-milk_auth_run_demo (MilkAuth *auth)
+static void
+auth_response_cb (GtkWidget *dialog,
+ int response,
+ MilkAuth *auth)
+
{
MilkAuthPrivate *priv;
- /* FIXME: clean this up */
GError *error = NULL;
- /* FIXME: cut this
- RtmGlib *rtm;
- */
- gchar *frob;
- gchar *url;
gchar *auth_token;
gchar *username;
- /* FIXME: cut this
- GList *glist;
- GList *item;
- RtmTask *task;
- RtmList *rtm_list;
- gchar *timeline;
- gchar *transaction_id;
- RtmLocation *location;
- gchar *list_id_sent = NULL;
- RtmTimeZone *time_zone;
- gchar *time;
- */
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");
- }
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
-
- /* FIXME: cut this
- glist = rtm_glib_time_zones_get_list (priv->rtm_glib, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- for (item = glist; item; item = g_list_next (item)) {
- time_zone = (RtmTimeZone *) item->data;
- g_print ("%s", rtm_time_zone_to_string (time_zone));
- }
- g_list_free (glist);
-
- time = rtm_glib_time_parse (priv->rtm_glib, "02/10/2009 10:25", NULL, FALSE, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- g_print ("Time: %s\n", time);
- g_free (time);
-
- time = rtm_glib_time_convert (priv->rtm_glib, "Europe/Madrid", NULL, NULL, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- g_print ("Time: %s\n", time);
- g_free (time);
- */
-
- frob = rtm_glib_auth_get_frob (priv->rtm_glib, &error);
- if (error != NULL) {
- g_error ("%s", rtm_error_get_message (error));
- }
- g_print ("Frob: %s\n", frob);
-
- url = rtm_glib_auth_get_login_url (priv->rtm_glib, frob, "delete");
- g_print ("URL: %s\n", url);
-
- getchar ();
-
- auth_token = rtm_glib_auth_get_token (priv->rtm_glib, frob, &error);
+ 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;
}
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;
}
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;
}
/* FIXME: work this in where appropriate */
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;
task = rtm_glib_tasks_add (priv->rtm_glib, timeline, "test-rtm-glib", NULL, FALSE, &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;
}
#endif
+
+auth_response_cb_OUT:
+ gtk_widget_destroy (dialog);
+}
+
+void
+milk_auth_run_demo (MilkAuth *auth)
+{
+ MilkAuthPrivate *priv;
+
+ GError *error = NULL;
+ gchar *url;
+ GtkDialog *dialog;
+
+ 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);
}
g_free (priv->api_key);
g_free (priv->shared_secret);
+ g_free (priv->frob);
}
static void
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors: Travis Reitter <treitter@gmail.com>
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+#include <hildon-uri.h>
+
+#include "milk-dialogs.h"
+#include "milk-main-window.h"
+
+typedef struct {
+ const char *uri;
+ GtkWidget *finish_button;
+} LinkClickedClosure;
+
+static void
+link_clicked_cb (GtkButton *link,
+ LinkClickedClosure *closure)
+{
+ gtk_widget_set_sensitive (closure->finish_button, TRUE);
+
+ hildon_uri_open (closure->uri, NULL, NULL);
+
+ g_free (closure);
+}
+
+static void
+finish_button_clicked_cb (GtkButton *finish_button,
+ GtkDialog *dialog)
+{
+ gtk_dialog_response (dialog, GTK_RESPONSE_OK);
+}
+
+GtkDialog*
+milk_dialogs_auth_prompt (GtkWindow *parent,
+ const char *uri)
+{
+ HildonDialog *dialog;
+ GtkWidget *label;
+ GtkWidget *link;
+ GtkWidget *finish_button;
+ LinkClickedClosure *closure;
+
+ if (!parent)
+ parent = GTK_WINDOW (milk_main_window_get_default ());
+
+ dialog = HILDON_DIALOG (hildon_dialog_new ());
+ gtk_window_set_title (GTK_WINDOW (dialog),
+ _("Log in to Remember The Milk"));
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+ label = gtk_label_new (_("Log in, then tap Finish"));
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
+
+ finish_button = hildon_button_new_with_text (HILDON_SIZE_FINGER_HEIGHT,
+ HILDON_BUTTON_ARRANGEMENT_VERTICAL, _("Finish"), NULL);
+ gtk_widget_set_sensitive (finish_button, FALSE);
+ g_signal_connect (finish_button, "clicked",
+ G_CALLBACK (finish_button_clicked_cb), dialog);
+
+ link = gtk_link_button_new_with_label (uri, _("Log in"));
+ closure = g_new0 (LinkClickedClosure, 1);
+ closure->uri = uri;
+ closure->finish_button = finish_button;
+ g_signal_connect (link, "clicked", G_CALLBACK (link_clicked_cb),
+ closure);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
+ link);
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area),
+ finish_button);
+
+ gtk_widget_show_all (GTK_WIDGET (dialog));
+
+ return GTK_DIALOG (dialog);
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors: Travis Reitter <treitter@gmail.com>
+ */
+
+#ifndef _MILK_DIALOGS_H
+#define _MILK_DIALOGS_H
+
+GtkDialog* milk_dialogs_auth_prompt (GtkWindow *parent, const char *uri);
+
+#endif /* _MILK_DIALOGS_H */
/* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
#define MILK_MAIN_WINDOW_PRIVATE(o) ((MILK_MAIN_WINDOW ((o)))->priv)
+static GtkWidget *default_window = NULL;
+
struct _MilkMainWindowPrivate
{
MilkAuth *auth;
g_object_unref (task);
}
+static gboolean
+begin_auth_idle (MilkMainWindow *window)
+{
+ MilkMainWindowPrivate *priv;
+
+ priv = MILK_MAIN_WINDOW_PRIVATE (window);
+
+ /* FIXME: is there a better place for this? */
+ priv->auth = milk_auth_get_default ();
+ /* FIXME: plug this into the task model */
+
+ /* FIXME: cut this */
+ g_debug ("trying to run the milk auth demo");
+ /* FIXME: cut this */
+ milk_auth_run_demo (priv->auth);
+
+ return FALSE;
+}
+
static void
milk_main_window_constructed (GObject* object)
{
hildon_window_set_app_menu (
HILDON_WINDOW (self), HILDON_APP_MENU (priv->app_menu));
- /* FIXME: is there a better place for this? */
- priv->auth = milk_auth_get_default ();
- /* FIXME: plug this into the task model */
-
- /* FIXME: cut this */
- g_debug ("trying to run the milk auth demo");
- /* FIXME: cut this */
- milk_auth_run_demo (priv->auth);
+ /* break a cyclical dependency by doing this after the window is
+ * constructed */
+ g_idle_add ((GSourceFunc) begin_auth_idle, self);
}
static void
}
GtkWidget*
-milk_main_window_new ()
+milk_main_window_get_default ()
{
- return g_object_new (MILK_TYPE_MAIN_WINDOW,
- NULL);
+ if (!default_window) {
+ default_window = g_object_new (MILK_TYPE_MAIN_WINDOW, NULL);
+ }
+
+ return default_window;
}
GType milk_main_window_get_type (void);
-GtkWidget* milk_main_window_new (void);
+GtkWidget* milk_main_window_get_default (void);
#endif /* _MILK_MAIN_WINDOW_H */
hildon_gtk_init (&argc, &argv);
memset (&app, 0, sizeof (app));
- app.main_window = milk_main_window_new ();
+ app.main_window = milk_main_window_get_default ();
+
+ /* FIXME: cut this */
+ g_debug ("in main(), main window: %p", app.main_window);
gtk_widget_show_all (app.main_window);